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

  1 mike  1.6 //%///-*-c++-*-/////////////////////////////////////////////////////////////////
  2 mike  1.4 //
  3 mike  1.6 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
  4           // The Open Group, Tivoli Systems
  5 mike  1.4 //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7           // of this software and associated documentation files (the "Software"), to 
  8           // deal in the Software without restriction, including without limitation the 
  9           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 10           // sell copies of the Software, and to permit persons to whom the Software is
 11           // furnished to do so, subject to the following conditions:
 12           // 
 13           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 14           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 17           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 18           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 19           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21           //
 22           //==============================================================================
 23           //
 24           // Author: Mike Brasher (mbrasher@bmc.com)
 25           //
 26 mike  1.6 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 27           // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company 
 28           //              (carolann_graves@hp.com)
 29 mday  1.9 // Modified By: Mike Day (mdday@us.ibm.com)
 30 mike  1.4 //
 31           //%/////////////////////////////////////////////////////////////////////////////
 32           
 33           #ifndef Pegasus_Message_h
 34           #define Pegasus_Message_h
 35           
 36 mike  1.6 #include <Pegasus/Common/Config.h>
 37 mike  1.4 #include <iostream>
 38 mike  1.6 #include <cstring>
 39           #include <Pegasus/Common/Exception.h>
 40           #include <Pegasus/Common/IPC.h>
 41 mike  1.4 
 42           PEGASUS_NAMESPACE_BEGIN
 43           
 44 mike  1.11 // REVIEW: could class be renamed to MessageMask (coding standard)?
 45            
 46 mike  1.6  class PEGASUS_COMMON_LINKAGE message_mask 
 47            {
 48               public:
 49 mike  1.11 
 50 mike  1.6        static Uint32 type_legacy;
 51 mday  1.9        static Uint32 type_CIMOperation;
 52                  static Uint32 type_CIMAsyncOperation;
 53                  static Uint32 type_export;
 54                  static Uint32 type_lifetime;
 55 mike  1.6        static Uint32 type_socket;
 56                  static Uint32 type_connection;
 57                  static Uint32 type_http;
 58                  static Uint32 type_cimom;
 59 mday  1.9        static Uint32 type_control;
 60                  static Uint32 type_service;
 61                  static Uint32 type_broadcast;
 62 mike  1.6        
 63 mday  1.9        static Uint32 ha_no_delete;
 64                  static Uint32 ha_request;
 65                  static Uint32 ha_reply;
 66 mday  1.10       static Uint32 ha_synchronous;
 67 mday  1.13       static Uint32 ha_async;
 68                  
 69 mike  1.7        // more for documentation than for use 
 70            
 71 mday  1.9        inline Uint32 get_type(Uint32 flags)
 72 mike  1.6        {
 73            	 return (flags & 0x000fffff);
 74                  }
 75            
 76                  inline Uint32 get_handling(Uint32 flags)
 77                  {
 78            	 return( flags & 0xfff00000);
 79                  }
 80            };
 81            
 82 mike  1.4  class MessageQueue;
 83            
 84            /** The Message class and derived classes are used to pass messages between 
 85                modules. Messages are passed between modules using the message queues
 86                (see MessageQueue class). Derived classes may add their own fields.
 87                This base class defines two common fields: type, which is the type of
 88                the message, and key which is a key value whose meaning is defined by
 89                the derived class. The MessageQueue class provides methods for finding
 90                messages by both type and key.
 91            
 92                The Message class also provides previous and next pointers which are
 93                used to place the messages on a queue by the MessageQueue class.
 94            */
 95 mike  1.5  class PEGASUS_COMMON_LINKAGE Message
 96 mike  1.4  {
 97 mday  1.8     public:
 98 mike  1.4  
 99 mday  1.8        Message(
100            	 Uint32 type, 
101            	 Uint32 key = getNextKey(), 
102            	 Uint32 routing_code = 0,
103            	 Uint32 mask = message_mask::type_legacy) 
104            	 : 
105            	 _type(type), 
106            	 _key(key), 
107            	 _routing_code(routing_code), 
108            	 _mask(mask),
109            	 _next(0), 
110            	 _prev(0) 
111                  { 
112            
113                  }
114 mike  1.6  
115 mday  1.8        virtual ~Message(); 
116 mike  1.4  
117 mday  1.8        Uint32 getType() const { return _type; }
118 mike  1.4  
119 mday  1.8        void setType(Uint32 type) { _type = type; }
120 mike  1.4  
121 mday  1.8        Uint32 getKey() const { return _key; }
122 mike  1.4  
123 mday  1.8        void setKey(Uint32 key) { _key = key; }
124 mike  1.4  
125 mday  1.8        Uint32 getRouting() const { return _routing_code; }
126                  void setRouting(Uint32 routing) { _routing_code = routing; }
127 mike  1.4  
128 mday  1.8        Uint32 getMask() const { return _mask; }
129 mike  1.6        
130 mday  1.8        void setMask(Uint32 mask) { _mask = mask; }
131 mike  1.6        
132 mday  1.8        Message* getNext() { return _next; }
133 mike  1.4  
134 mday  1.8        const Message* getNext() const { return _next; }
135 mike  1.4  
136 mday  1.8        Message* getPrevious() { return _prev; }
137 mike  1.4  
138 mday  1.8        const Message* getPrevious() const { return _prev; }
139 mike  1.4  
140 mday  1.8        static Uint32 getNextKey() 
141 mike  1.6        { 
142            	 
143            	 _mut.lock( pegasus_thread_self() ) ; 
144            	 Uint32 ret = _nextKey++;
145            	 _mut.unlock();
146            	 return ret;
147                  }
148                  
149 mday  1.8        virtual void print(PEGASUS_STD(ostream)& os) const;
150 mike  1.4  
151 mday  1.13       // << Thu Dec 27 10:46:04 2001 mdd >> for use with DQueue container 
152                  // as used by AsyncOpNode 
153                  Boolean operator == (void *msg )
154                  {
155 mday  1.16 	 if (reinterpret_cast<void *>(this) == msg )
156 mday  1.13 	    return true;
157            	 return false;
158                  }
159                  
160            
161 mday  1.8     private:
162 mike  1.6        Uint32 _type;
163                  Uint32 _key;
164 mday  1.8        Uint32 _routing_code;
165 mike  1.6        Uint32 _mask;
166                  Message* _next;
167                  Message* _prev;
168                  MessageQueue* _owner;
169                  static Uint32 _nextKey;
170                  static Mutex _mut;
171                  friend class MessageQueue;
172 mike  1.4  };
173 mike  1.5  
174 mike  1.6  
175 mike  1.5  enum MessageType
176            {
177                DUMMY_MESSAGE,
178            
179                // CIM Message types:
180            
181                CIM_GET_CLASS_REQUEST_MESSAGE,
182                CIM_GET_INSTANCE_REQUEST_MESSAGE,
183 mike  1.6      CIM_EXPORT_INDICATION_REQUEST_MESSAGE,
184 mike  1.5      CIM_DELETE_CLASS_REQUEST_MESSAGE,
185                CIM_DELETE_INSTANCE_REQUEST_MESSAGE,
186                CIM_CREATE_CLASS_REQUEST_MESSAGE,
187                CIM_CREATE_INSTANCE_REQUEST_MESSAGE,
188                CIM_MODIFY_CLASS_REQUEST_MESSAGE,
189                CIM_MODIFY_INSTANCE_REQUEST_MESSAGE,
190                CIM_ENUMERATE_CLASSES_REQUEST_MESSAGE,
191                CIM_ENUMERATE_CLASS_NAMES_REQUEST_MESSAGE,
192                CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE,
193                CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE,
194                CIM_EXEC_QUERY_REQUEST_MESSAGE,
195                CIM_ASSOCIATORS_REQUEST_MESSAGE,
196                CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE,
197                CIM_REFERENCES_REQUEST_MESSAGE,
198                CIM_REFERENCE_NAMES_REQUEST_MESSAGE,
199                CIM_GET_PROPERTY_REQUEST_MESSAGE,
200                CIM_SET_PROPERTY_REQUEST_MESSAGE,
201                CIM_GET_QUALIFIER_REQUEST_MESSAGE,
202                CIM_SET_QUALIFIER_REQUEST_MESSAGE,
203                CIM_DELETE_QUALIFIER_REQUEST_MESSAGE,
204                CIM_ENUMERATE_QUALIFIERS_REQUEST_MESSAGE,
205 mike  1.5      CIM_INVOKE_METHOD_REQUEST_MESSAGE,
206 mike  1.6      CIM_ENABLE_INDICATION_SUBSCRIPTION_REQUEST_MESSAGE,
207                CIM_MODIFY_INDICATION_SUBSCRIPTION_REQUEST_MESSAGE,
208                CIM_DISABLE_INDICATION_SUBSCRIPTION_REQUEST_MESSAGE,
209 kumpf 1.15     CIM_PROCESS_INDICATION_REQUEST_MESSAGE,
210                CIM_NOTIFY_PROVIDER_REGISTRATION_REQUEST_MESSAGE,
211                CIM_NOTIFY_PROVIDER_TERMINATION_REQUEST_MESSAGE,
212 mike  1.5      CIM_GET_CLASS_RESPONSE_MESSAGE,
213                CIM_GET_INSTANCE_RESPONSE_MESSAGE,
214 mike  1.6      CIM_EXPORT_INDICATION_RESPONSE_MESSAGE,
215 mike  1.5      CIM_DELETE_CLASS_RESPONSE_MESSAGE,
216                CIM_DELETE_INSTANCE_RESPONSE_MESSAGE,
217                CIM_CREATE_CLASS_RESPONSE_MESSAGE,
218                CIM_CREATE_INSTANCE_RESPONSE_MESSAGE,
219                CIM_MODIFY_CLASS_RESPONSE_MESSAGE,
220                CIM_MODIFY_INSTANCE_RESPONSE_MESSAGE,
221                CIM_ENUMERATE_CLASSES_RESPONSE_MESSAGE,
222                CIM_ENUMERATE_CLASS_NAMES_RESPONSE_MESSAGE,
223                CIM_ENUMERATE_INSTANCES_RESPONSE_MESSAGE,
224                CIM_ENUMERATE_INSTANCE_NAMES_RESPONSE_MESSAGE,
225                CIM_EXEC_QUERY_RESPONSE_MESSAGE,
226                CIM_ASSOCIATORS_RESPONSE_MESSAGE,
227                CIM_ASSOCIATOR_NAMES_RESPONSE_MESSAGE,
228                CIM_REFERENCES_RESPONSE_MESSAGE,
229                CIM_REFERENCE_NAMES_RESPONSE_MESSAGE,
230                CIM_GET_PROPERTY_RESPONSE_MESSAGE,
231                CIM_SET_PROPERTY_RESPONSE_MESSAGE,
232                CIM_GET_QUALIFIER_RESPONSE_MESSAGE,
233                CIM_SET_QUALIFIER_RESPONSE_MESSAGE,
234                CIM_DELETE_QUALIFIER_RESPONSE_MESSAGE,
235                CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE,
236 mike  1.5      CIM_INVOKE_METHOD_RESPONSE_MESSAGE,
237 mike  1.6      CIM_ENABLE_INDICATION_SUBSCRIPTION_RESPONSE_MESSAGE,
238                CIM_MODIFY_INDICATION_SUBSCRIPTION_RESPONSE_MESSAGE,
239                CIM_DISABLE_INDICATION_SUBSCRIPTION_RESPONSE_MESSAGE,
240 kumpf 1.15     CIM_PROCESS_INDICATION_RESPONSE_MESSAGE,
241                CIM_NOTIFY_PROVIDER_REGISTRATION_RESPONSE_MESSAGE,
242                CIM_NOTIFY_PROVIDER_TERMINATION_RESPONSE_MESSAGE,
243 mike  1.6  
244                // Monitor-related messages:
245            
246                SOCKET_MESSAGE,
247            
248                // Connection-oriented messages:
249            
250                CLOSE_CONNECTION_MESSAGE,
251            
252                // HTTP messages:
253            
254                HTTP_MESSAGE,
255 mike  1.5  
256                NUMBER_OF_MESSAGES
257            };
258            
259            PEGASUS_COMMON_LINKAGE const char* MessageTypeToString(Uint32 messageType);
260 mike  1.6  
261            /** This class implements a stack of queue-ids. Many messages must keep a
262                stack of queue-ids of queues which they must be returned to. This provides
263                a light efficient stack for this purpose.
264            */
265            class QueueIdStack
266            {
267            public:
268            
269                QueueIdStack() : _size(0) 
270                { 
271                }
272            
273                QueueIdStack(const QueueIdStack& x) : _size(x._size) 
274                {
275            	memcpy(_items, x._items, sizeof(_items));
276                }
277            
278                PEGASUS_EXPLICIT QueueIdStack(Uint32 x) : _size(0) 
279                { 
280            	push(x); 
281 mike  1.6      }
282            
283                PEGASUS_EXPLICIT QueueIdStack(Uint32 x1, Uint32 x2) : _size(0) 
284                {
285            	push(x1); 
286            	push(x2); 
287                }
288            
289                ~QueueIdStack() 
290                { 
291                }
292            
293                QueueIdStack& operator=(const QueueIdStack& x) 
294                {
295            	if (this != &x)
296            	{
297            	    memcpy(_items, x._items, sizeof(_items));
298            	    _size = x._size;
299            	}
300            	return *this;
301                }
302 mike  1.6  
303                Uint32 size() const 
304                { 
305            	return _size; 
306                }
307            
308                Boolean isEmpty() const 
309                { 
310            	return _size == 0; 
311                }
312            
313                void push(Uint32 x) 
314                {
315            	if (_size == MAX_SIZE)
316            	    throw StackOverflow();
317            
318            	_items[_size++] = x;
319                }
320            
321                Uint32& top()
322                {
323 mike  1.6  	if (_size == 0)
324            	    throw StackUnderflow();
325            
326            	return _items[_size-1];
327                }
328            
329                Uint32 top() const 
330                {
331            	return ((QueueIdStack*)this)->top(); 
332                }
333            
334                void pop() 
335                {
336            	if (_size == 0)
337            	    throw StackUnderflow();
338            
339            	_size--;
340                }
341            
342                /** Make a copy of this stack and then pop the top element. */
343                QueueIdStack copyAndPop() const
344 mike  1.6      {
345            	return QueueIdStack(*this, 0);
346                }
347            
348            private:
349            
350                // Copy the given stack but then pop the top element:
351                QueueIdStack(const QueueIdStack& x, int) : _size(x._size) 
352                {
353            	memcpy(_items, x._items, sizeof(_items));
354            	pop();
355                }
356            
357                enum { MAX_SIZE = 5 };
358                Uint32 _items[MAX_SIZE];
359                Uint32 _size;
360            };
361 mike  1.4  
362            PEGASUS_NAMESPACE_END
363            
364            #endif /* Pegasus_Message_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2