------------------------------------------------------------------ -- -- NAME: TEK_DEVICE_STATE_LISTS - BODY -- DISCREPANCY REPORTS: -- ------------------------------------------------------------------ -- file : TEK_DEVICE_STATE_LISTS_B.ADA -- level: ALL LEVELS with GKS_ERRORS; with UNCHECKED_DEALLOCATION; package body TEK_DEVICE_STATE_LISTS is type DEVICE_STATE_LISTS_ENTRY_TYPE; -- This type is a node in the list of device state lists. It contains -- a pointer to a device state list and a pointer to the next node. type DEVICE_STATE_LISTS_ENTRY_TYPE_PTR is access DEVICE_STATE_LISTS_ENTRY_TYPE; -- This type points to a node in the list of device state lists. type DEVICE_STATE_LISTS_ENTRY_TYPE is record LINK : DEVICE_STATE_LISTS_ENTRY_TYPE_PTR; STATE_LIST : DEVICE_STATE_LIST_TYPE_PTR; end record; -- This type is a node in the list of device state lists. It contains -- a pointer to a device state list and a pointer to the next node. DEVICE_STATE_LISTS : DEVICE_STATE_LISTS_ENTRY_TYPE_PTR; -- Contains the last state list that was added to the list. function GET_DEVICE_STATE_LIST_PTR (WS_ID : in GKS_TYPES.WS_ID) return TEK_DEVICE_STATE_LISTS.DEVICE_STATE_LIST_TYPE_PTR is -- This procedure returns a pointer to the device state list -- specified by a workstation id. -- The following parameter is used in this function: -- WS_ID - The workstation id for the specified device state list -- to be returned. STATE_LISTS_ENTRY : DEVICE_STATE_LISTS_ENTRY_TYPE_PTR; -- Used to traverse the list of state lists. begin STATE_LISTS_ENTRY := DEVICE_STATE_LISTS; while STATE_LISTS_ENTRY /= null loop -- If the WS_ID is equal to the requested WS_ID return the -- DEVICE_STATE_LIST. If not, get the next -- DEVICE_STATE_LIST. if STATE_LISTS_ENTRY.STATE_LIST.WORKSTATION_ID = WS_ID then return STATE_LISTS_ENTRY.STATE_LIST; else STATE_LISTS_ENTRY := STATE_LISTS_ENTRY.LINK; end if; end loop; -- If no state list is found with the requested id, NULL is -- returned. return NULL; end GET_DEVICE_STATE_LIST_PTR; procedure ADD_DEVICE_STATE_LIST (WS_ID : in GKS_TYPES.WS_ID) is -- The following procedure adds a device state list to the list -- -- The following parameters are used in this procedure: -- WS_ID - The workstation id for the workstation. OLD_DEVICE_STATE_LISTS : DEVICE_STATE_LISTS_ENTRY_TYPE_PTR; -- Used as a temporary for linking the lists together. begin -- Get a new DEVICE_STATE_LIST. -- Sets the OLD_DEVICE_STATE_LISTS equal to the current state list. -- It gets a new state list and links the new state list to the -- OLD_DEVICE_STATE_LISTS. The first time a state list is allocated -- DEVICE_STATE_LISTS is NULL, therefore it sets OLD_DEVICE_ST_ -- LSTS to NULL. It gets a new state list, and sets the -- LINK to OLD_DEVICE_STATE_LISTS which is NULL; OLD_DEVICE_STATE_LISTS := DEVICE_STATE_LISTS; DEVICE_STATE_LISTS := new DEVICE_STATE_LISTS_ENTRY_TYPE; DEVICE_STATE_LISTS.LINK := OLD_DEVICE_STATE_LISTS; -- Get a new state list and add it to the list. DEVICE_STATE_LISTS.STATE_LIST:= new DEVICE_STATE_LIST_TYPE; -- Initialize the DEVICE_STATE_LISTS.STATE_LIST. -- The following are parameters passed in to the procedure. DEVICE_STATE_LISTS.STATE_LIST.WORKSTATION_ID := WS_ID; end ADD_DEVICE_STATE_LIST; procedure DELETE_DEVICE_STATE_LIST (WS_ID : in GKS_TYPES.WS_ID) is -- This procedure deletes the device state list specified by the -- WS_ID from the list of device state lists. -- -- The following parameter is used in this procedure: -- WS_ID - The workstation id for the device state list to delete. -- This procedure deallocates the specified device state list. procedure FREE_STATE_LIST is new UNCHECKED_DEALLOCATION (DEVICE_STATE_LIST_TYPE, DEVICE_STATE_LIST_TYPE_PTR); -- This procedure deallocates a component of the DEVICE_STATE_LISTS. procedure FREE_DEVICE_STATE_LISTS_ENTRY is new UNCHECKED_DEALLOCATION (DEVICE_STATE_LISTS_ENTRY_TYPE, DEVICE_STATE_LISTS_ENTRY_TYPE_PTR); PREV_TEMP, STATE_LISTS_ENTRY : DEVICE_STATE_LISTS_ENTRY_TYPE_PTR := DEVICE_STATE_LISTS; --Temporary variables for deleting the state list. begin while STATE_LISTS_ENTRY /= null loop if STATE_LISTS_ENTRY.STATE_LIST.WORKSTATION_ID = WS_ID then -- If the temporary is equal to the first element in the -- list then the list can just be freed. if STATE_LISTS_ENTRY = DEVICE_STATE_LISTS then DEVICE_STATE_LISTS := STATE_LISTS_ENTRY.LINK; FREE_STATE_LIST(STATE_LISTS_ENTRY.STATE_LIST); FREE_DEVICE_STATE_LISTS_ENTRY(STATE_LISTS_ENTRY); exit; else -- Set the previous state list's 'next' pointer equal to -- next state list after the temporary. Then free the -- state list. PREV_TEMP.LINK := STATE_LISTS_ENTRY.LINK; FREE_STATE_LIST(STATE_LISTS_ENTRY.STATE_LIST); FREE_DEVICE_STATE_LISTS_ENTRY(STATE_LISTS_ENTRY); exit; end if; else -- Set the temporary state list equal to the previous state -- list and get the next state list. PREV_TEMP := STATE_LISTS_ENTRY; STATE_LISTS_ENTRY := STATE_LISTS_ENTRY.LINK; end if; end loop; end DELETE_DEVICE_STATE_LIST; end TEK_DEVICE_STATE_LISTS;