67 } 68 69 AccessBridgeMessageQueue::~AccessBridgeMessageQueue() { 70 // empty queue, then exit 71 } 72 73 /** 74 * getEventsWaiting - gets the number of events waiting to fire 75 */ 76 int 77 AccessBridgeMessageQueue::getEventsWaiting() { 78 return size; 79 } 80 81 /** 82 * add - add an element to the queue, which is locked with semaphores 83 * 84 */ 85 QueueReturns 86 AccessBridgeMessageQueue::add(AccessBridgeQueueElement *element) { 87 PrintDebugString(" in AccessBridgeMessageQueue::add()"); 88 PrintDebugString(" queue size = %d", size); 89 90 QueueReturns returnVal = cElementPushedOK; 91 if (queueLocked) { 92 PrintDebugString(" queue was locked; returning cQueueInUse!"); 93 return cQueueInUse; 94 } 95 queueLocked = TRUE; 96 { 97 PrintDebugString(" adding element to queue!"); 98 if (end == (AccessBridgeQueueElement *) 0) { 99 if (start == (AccessBridgeQueueElement *) 0 && size == 0) { 100 start = element; 101 end = element; 102 element->previous = (AccessBridgeQueueElement *) 0; 103 element->next = (AccessBridgeQueueElement *) 0; 104 size++; 105 } else { 106 returnVal = cQueueBroken; // bad voodo! 107 } 108 } else { 109 element->previous = end; 110 element->next = (AccessBridgeQueueElement *) 0; 111 end->next = element; 112 end = element; 113 size++; 114 } 115 } 116 queueLocked = FALSE; 117 PrintDebugString(" returning from AccessBridgeMessageQueue::add()"); 118 return returnVal; 119 } 120 121 122 /** 123 * remove - remove an element from the queue, which is locked with semaphores 124 * 125 */ 126 QueueReturns 127 AccessBridgeMessageQueue::remove(AccessBridgeQueueElement **element) { 128 PrintDebugString(" in AccessBridgeMessageQueue::remove()"); 129 PrintDebugString(" queue size = %d", size); 130 131 QueueReturns returnVal = cMoreMessages; 132 if (queueLocked) { 133 PrintDebugString(" queue was locked; returning cQueueInUse!"); 134 return cQueueInUse; 135 } 136 queueLocked = TRUE; 137 { 138 PrintDebugString(" removing element from queue!"); 139 if (size > 0) { 140 if (start != (AccessBridgeQueueElement *) 0) { 141 *element = start; 142 start = start->next; 143 if (start != (AccessBridgeQueueElement *) 0) { 144 start->previous = (AccessBridgeQueueElement *) 0; 145 } else { 146 end = (AccessBridgeQueueElement *) 0; 147 if (size != 1) { 148 returnVal = cQueueBroken; // bad voodo, should only be 1 in this situation 149 } 150 } 151 size--; 152 } else { 153 returnVal = cQueueBroken; // bad voodo! 154 } 155 } else { 156 returnVal = cQueueEmpty; 157 } 158 } 159 queueLocked = FALSE; 160 PrintDebugString(" returning from AccessBridgeMessageQueue::remove()"); 161 return returnVal; 162 } 163 164 165 /** 166 * setRemoveLock - set the state of the removeLock (TRUE or FALSE) 167 * 168 */ 169 QueueReturns 170 AccessBridgeMessageQueue::setRemoveLock(BOOL removeLockSetting) { 171 if (queueLocked) { 172 return cQueueInUse; 173 } 174 queueRemoveLocked = removeLockSetting; 175 176 return cQueueOK; 177 } 178 179 /** 180 * setRemoveLock - set the state of the removeLock (TRUE or FALSE) | 67 } 68 69 AccessBridgeMessageQueue::~AccessBridgeMessageQueue() { 70 // empty queue, then exit 71 } 72 73 /** 74 * getEventsWaiting - gets the number of events waiting to fire 75 */ 76 int 77 AccessBridgeMessageQueue::getEventsWaiting() { 78 return size; 79 } 80 81 /** 82 * add - add an element to the queue, which is locked with semaphores 83 * 84 */ 85 QueueReturns 86 AccessBridgeMessageQueue::add(AccessBridgeQueueElement *element) { 87 PrintDebugString("[INFO]: in AccessBridgeMessageQueue::add()"); 88 PrintDebugString("[INFO]: queue size = %d", size); 89 90 QueueReturns returnVal = cElementPushedOK; 91 if (queueLocked) { 92 PrintDebugString("[WARN]: queue was locked; returning cQueueInUse!"); 93 return cQueueInUse; 94 } 95 queueLocked = TRUE; 96 { 97 PrintDebugString("[INFO]: adding element to queue!"); 98 if (end == (AccessBridgeQueueElement *) 0) { 99 if (start == (AccessBridgeQueueElement *) 0 && size == 0) { 100 start = element; 101 end = element; 102 element->previous = (AccessBridgeQueueElement *) 0; 103 element->next = (AccessBridgeQueueElement *) 0; 104 size++; 105 } else { 106 returnVal = cQueueBroken; // bad voodo! 107 } 108 } else { 109 element->previous = end; 110 element->next = (AccessBridgeQueueElement *) 0; 111 end->next = element; 112 end = element; 113 size++; 114 } 115 } 116 queueLocked = FALSE; 117 PrintDebugString("[INFO]: returning from AccessBridgeMessageQueue::add()"); 118 return returnVal; 119 } 120 121 122 /** 123 * remove - remove an element from the queue, which is locked with semaphores 124 * 125 */ 126 QueueReturns 127 AccessBridgeMessageQueue::remove(AccessBridgeQueueElement **element) { 128 PrintDebugString("[INFO]: in AccessBridgeMessageQueue::remove()"); 129 PrintDebugString("[INFO]: queue size = %d", size); 130 131 QueueReturns returnVal = cMoreMessages; 132 if (queueLocked) { 133 PrintDebugString("[WARN]: queue was locked; returning cQueueInUse!"); 134 return cQueueInUse; 135 } 136 queueLocked = TRUE; 137 { 138 PrintDebugString("[INFO]: removing element from queue!"); 139 if (size > 0) { 140 if (start != (AccessBridgeQueueElement *) 0) { 141 *element = start; 142 start = start->next; 143 if (start != (AccessBridgeQueueElement *) 0) { 144 start->previous = (AccessBridgeQueueElement *) 0; 145 } else { 146 end = (AccessBridgeQueueElement *) 0; 147 if (size != 1) { 148 returnVal = cQueueBroken; // bad voodo, should only be 1 in this situation 149 } 150 } 151 size--; 152 } else { 153 returnVal = cQueueBroken; // bad voodo! 154 } 155 } else { 156 returnVal = cQueueEmpty; 157 } 158 } 159 queueLocked = FALSE; 160 PrintDebugString("[INFO]: returning from AccessBridgeMessageQueue::remove()"); 161 return returnVal; 162 } 163 164 165 /** 166 * setRemoveLock - set the state of the removeLock (TRUE or FALSE) 167 * 168 */ 169 QueueReturns 170 AccessBridgeMessageQueue::setRemoveLock(BOOL removeLockSetting) { 171 if (queueLocked) { 172 return cQueueInUse; 173 } 174 queueRemoveLocked = removeLockSetting; 175 176 return cQueueOK; 177 } 178 179 /** 180 * setRemoveLock - set the state of the removeLock (TRUE or FALSE) |