(file) Return to Message.h 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           #ifndef Pegasus_Message_h
 30           #define Pegasus_Message_h
 31           
 32           #include <iostream>
 33 mike  1.5.2.5 #include <cstring>
 34 mike  1.4     #include <Pegasus/Common/Config.h>
 35 mike  1.5.2.5 #include <Pegasus/Common/Exception.h>
 36 mike  1.4     
 37               PEGASUS_NAMESPACE_BEGIN
 38               
 39               class MessageQueue;
 40               
 41               /** The Message class and derived classes are used to pass messages between 
 42                   modules. Messages are passed between modules using the message queues
 43                   (see MessageQueue class). Derived classes may add their own fields.
 44                   This base class defines two common fields: type, which is the type of
 45                   the message, and key which is a key value whose meaning is defined by
 46                   the derived class. The MessageQueue class provides methods for finding
 47                   messages by both type and key.
 48               
 49                   The Message class also provides previous and next pointers which are
 50                   used to place the messages on a queue by the MessageQueue class.
 51               */
 52 mike  1.5     class PEGASUS_COMMON_LINKAGE Message
 53 mike  1.4     {
 54               public:
 55               
 56                   Message(Uint32 type, Uint32 key = getNextKey()) 
 57               	: _type(type), _key(key), _next(0), _prev(0) { }
 58               
 59                   virtual ~Message(); 
 60               
 61                   Uint32 getType() const { return _type; }
 62               
 63                   void setType(Uint32 type) { _type = type; }
 64               
 65                   Uint32 getKey() const { return _key; }
 66               
 67                   void setKey(Uint32 key) { _key = key; }
 68               
 69                   Message* getNext() { return _next; }
 70               
 71                   const Message* getNext() const { return _next; }
 72               
 73                   Message* getPrevious() { return _prev; }
 74 mike  1.4     
 75                   const Message* getPrevious() const { return _prev; }
 76               
 77                   static Uint32 getNextKey() { return ++_nextKey; }
 78               
 79 mike  1.5         virtual void print(PEGASUS_STD(ostream)& os) const;
 80 mike  1.4     
 81               private:
 82                   Uint32 _type;
 83                   Uint32 _key;
 84                   Message* _next;
 85                   Message* _prev;
 86                   MessageQueue* _owner;
 87                   static Uint32 _nextKey;
 88                   friend class MessageQueue;
 89               };
 90 mike  1.5     
 91               enum MessageType
 92               {
 93                   DUMMY_MESSAGE,
 94               
 95                   // CIM Message types:
 96               
 97                   CIM_GET_CLASS_REQUEST_MESSAGE,
 98                   CIM_GET_INSTANCE_REQUEST_MESSAGE,
 99                   CIM_DELETE_CLASS_REQUEST_MESSAGE,
100                   CIM_DELETE_INSTANCE_REQUEST_MESSAGE,
101                   CIM_CREATE_CLASS_REQUEST_MESSAGE,
102                   CIM_CREATE_INSTANCE_REQUEST_MESSAGE,
103                   CIM_MODIFY_CLASS_REQUEST_MESSAGE,
104                   CIM_MODIFY_INSTANCE_REQUEST_MESSAGE,
105                   CIM_ENUMERATE_CLASSES_REQUEST_MESSAGE,
106                   CIM_ENUMERATE_CLASS_NAMES_REQUEST_MESSAGE,
107                   CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE,
108                   CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE,
109                   CIM_EXEC_QUERY_REQUEST_MESSAGE,
110                   CIM_ASSOCIATORS_REQUEST_MESSAGE,
111 mike  1.5         CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE,
112                   CIM_REFERENCES_REQUEST_MESSAGE,
113                   CIM_REFERENCE_NAMES_REQUEST_MESSAGE,
114                   CIM_GET_PROPERTY_REQUEST_MESSAGE,
115                   CIM_SET_PROPERTY_REQUEST_MESSAGE,
116                   CIM_GET_QUALIFIER_REQUEST_MESSAGE,
117                   CIM_SET_QUALIFIER_REQUEST_MESSAGE,
118                   CIM_DELETE_QUALIFIER_REQUEST_MESSAGE,
119                   CIM_ENUMERATE_QUALIFIERS_REQUEST_MESSAGE,
120                   CIM_INVOKE_METHOD_REQUEST_MESSAGE,
121                   CIM_GET_CLASS_RESPONSE_MESSAGE,
122                   CIM_GET_INSTANCE_RESPONSE_MESSAGE,
123                   CIM_DELETE_CLASS_RESPONSE_MESSAGE,
124                   CIM_DELETE_INSTANCE_RESPONSE_MESSAGE,
125                   CIM_CREATE_CLASS_RESPONSE_MESSAGE,
126                   CIM_CREATE_INSTANCE_RESPONSE_MESSAGE,
127                   CIM_MODIFY_CLASS_RESPONSE_MESSAGE,
128                   CIM_MODIFY_INSTANCE_RESPONSE_MESSAGE,
129                   CIM_ENUMERATE_CLASSES_RESPONSE_MESSAGE,
130                   CIM_ENUMERATE_CLASS_NAMES_RESPONSE_MESSAGE,
131                   CIM_ENUMERATE_INSTANCES_RESPONSE_MESSAGE,
132 mike  1.5         CIM_ENUMERATE_INSTANCE_NAMES_RESPONSE_MESSAGE,
133                   CIM_EXEC_QUERY_RESPONSE_MESSAGE,
134                   CIM_ASSOCIATORS_RESPONSE_MESSAGE,
135                   CIM_ASSOCIATOR_NAMES_RESPONSE_MESSAGE,
136                   CIM_REFERENCES_RESPONSE_MESSAGE,
137                   CIM_REFERENCE_NAMES_RESPONSE_MESSAGE,
138                   CIM_GET_PROPERTY_RESPONSE_MESSAGE,
139                   CIM_SET_PROPERTY_RESPONSE_MESSAGE,
140                   CIM_GET_QUALIFIER_RESPONSE_MESSAGE,
141                   CIM_SET_QUALIFIER_RESPONSE_MESSAGE,
142                   CIM_DELETE_QUALIFIER_RESPONSE_MESSAGE,
143                   CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE,
144                   CIM_INVOKE_METHOD_RESPONSE_MESSAGE,
145               
146 mike  1.5.2.2     // Monitor-related messages:
147 mike  1.5.2.1 
148                   SOCKET_MESSAGE,
149 mike  1.5.2.2 
150                   // Connection-oriented messages:
151               
152                   CLOSE_CONNECTION_MESSAGE,
153 mike  1.5.2.4 
154                   // HTTP messages:
155               
156 mike  1.5.2.3     HTTP_MESSAGE,
157 mike  1.5.2.1 
158 mike  1.5         NUMBER_OF_MESSAGES
159               };
160               
161               PEGASUS_COMMON_LINKAGE const char* MessageTypeToString(Uint32 messageType);
162 mike  1.5.2.5 
163               /** This class implements a stack of queue-ids. Many messages must keep a
164                   stack of queue-ids of queues which they must be returned to. This provides
165                   a light efficient stack for this purpose.
166               */
167               class QueueIdStack
168               {
169               public:
170               
171                   QueueIdStack() : _size(0) 
172                   { 
173                   }
174               
175                   QueueIdStack(const QueueIdStack& x) : _size(x._size) 
176                   {
177               	memcpy(_items, x._items, sizeof(_items));
178                   }
179               
180                   PEGASUS_EXPLICIT QueueIdStack(Uint32 x) : _size(0) 
181                   { 
182               	push(x); 
183 mike  1.5.2.5     }
184               
185                   PEGASUS_EXPLICIT QueueIdStack(Uint32 x1, Uint32 x2) : _size(0) 
186                   {
187               	push(x1); 
188               	push(x2); 
189                   }
190               
191                   ~QueueIdStack() 
192                   { 
193                   }
194               
195                   QueueIdStack& operator=(const QueueIdStack& x) 
196                   {
197               	if (this != &x)
198               	{
199               	    memcpy(_items, x._items, sizeof(_items));
200               	    _size = x._size;
201               	}
202               	return *this;
203                   }
204 mike  1.5.2.5 
205                   Uint32 size() const 
206                   { 
207               	return _size; 
208                   }
209               
210                   Boolean isEmpty() const 
211                   { 
212               	return _size == 0; 
213                   }
214               
215                   void push(Uint32 x) 
216                   {
217               	if (_size == MAX_SIZE)
218               	    throw StackOverflow();
219               
220               	_items[_size++] = x;
221                   }
222               
223                   Uint32& top()
224                   {
225 mike  1.5.2.5 	if (_size == 0)
226               	    throw StackUnderflow();
227               
228               	return _items[_size-1];
229                   }
230               
231                   Uint32 top() const 
232                   {
233               	return ((QueueIdStack*)this)->top(); 
234                   }
235               
236                   void pop() 
237                   {
238               	if (_size == 0)
239               	    throw StackUnderflow();
240               
241               	_size--;
242                   }
243               
244                   /** Make a copy of this stack and then pop the top element. */
245                   QueueIdStack copyAndPop() const
246 mike  1.5.2.5     {
247               	return QueueIdStack(*this, 0);
248                   }
249               
250               private:
251               
252                   // Copy the given stack but then pop the top element:
253                   QueueIdStack(const QueueIdStack& x, int) : _size(x._size) 
254                   {
255               	memcpy(_items, x._items, sizeof(_items));
256               	pop();
257                   }
258               
259                   enum { MAX_SIZE = 5 };
260                   Uint32 _items[MAX_SIZE];
261                   Uint32 _size;
262               };
263 mike  1.4     
264               PEGASUS_NAMESPACE_END
265               
266               #endif /* Pegasus_Message_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2