(file) Return to MessageQueue.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.4 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a copy
  6           // of this software and associated documentation files (the "Software"), to 
  7           // deal in the Software without restriction, including without limitation the 
  8           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
  9           // sell copies of the Software, and to permit persons to whom the Software is
 10           // furnished to do so, subject to the following conditions:
 11           // 
 12           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 13           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 16           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 17           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 18           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20           //
 21           //==============================================================================
 22 mike  1.4 //
 23           // Author: Mike Brasher (mbrasher@bmc.com)
 24           //
 25           // Modified By:
 26           //
 27           //%/////////////////////////////////////////////////////////////////////////////
 28           
 29           #include "MessageQueue.h"
 30           
 31           PEGASUS_USING_STD;
 32           
 33           PEGASUS_NAMESPACE_BEGIN
 34           
 35           void MessageQueue::enqueue(Message* message)
 36           {
 37               if (!message)
 38           	throw NullPointer();
 39           
 40               if (_back)
 41               {
 42           	_back->_next = message;
 43 mike  1.4 	message->_prev = _back;
 44           	message->_next = 0;
 45           	_back = message;
 46               }
 47               else
 48               {
 49           	_front = message;
 50           	_back = message;
 51           	message->_prev = 0;
 52           	message->_next = 0;
 53               }
 54               message->_owner = this;
 55               _count++;
 56           }
 57           
 58           Message* MessageQueue::dequeue()
 59           {
 60               if (_front)
 61               {
 62           	Message* message = _front;
 63           	_front = _front->_next;
 64 mike  1.4 	if (_front)
 65           	    _front->_prev = 0;
 66           
 67           	if (_back == message)
 68           	    _back = 0;
 69           	
 70           	message->_next = 0;
 71           	message->_prev = 0;
 72           	message->_owner = 0;
 73           	_count--;
 74           	return message;
 75               }
 76               return 0;
 77           }
 78           
 79           void MessageQueue::remove(Message* message)
 80           {
 81               if (!message)
 82           	throw NullPointer();
 83           
 84               if (message->_owner != this)
 85 mike  1.4 	throw NoSuchMessageOnQueue();
 86           
 87               if (message->_next)
 88           	message->_next->_prev = message->_prev;
 89               else
 90           	_back = message->_prev;
 91           
 92               if (message->_prev)
 93           	message->_prev->_next = message->_next;
 94               else
 95           	_front = message->_next;
 96           
 97               message->_prev = 0;
 98               message->_next = 0;
 99               message->_owner = 0;
100               _count--;
101           }
102           
103           Message* MessageQueue::findByType(Uint32 type)
104           {
105               for (Message* m = front(); m; m = m->getNext())
106 mike  1.4     {
107           	if (m->getType() == type)
108           	    return m;
109               }
110           
111               return 0;
112           }
113           
114           Message* MessageQueue::findByKey(Uint32 key)
115           {
116               for (Message* m = front(); m; m = m->getNext())
117               {
118           	if (m->getKey() == key)
119           	    return m;
120               }
121           
122               return 0;
123           }
124           
125           void MessageQueue::print(ostream& os) const
126           {
127 mike  1.4     for (const Message* m = front(); m; m = m->getNext())
128           	m->print(os);
129           }
130           
131           Message* MessageQueue::find(Uint32 type, Uint32 key)
132           {
133               for (Message* m = front(); m; m = m->getNext())
134               {
135           	if (m->getType() == type && m->getKey() == key)
136           	    return m;
137               }
138           
139               return 0;
140           }
141           
142           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2