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 kumpf 1.17 CIM_HANDLE_INDICATION_REQUEST_MESSAGE,
|
211 kumpf 1.15 CIM_NOTIFY_PROVIDER_REGISTRATION_REQUEST_MESSAGE,
212 CIM_NOTIFY_PROVIDER_TERMINATION_REQUEST_MESSAGE,
|
213 mike 1.5 CIM_GET_CLASS_RESPONSE_MESSAGE,
214 CIM_GET_INSTANCE_RESPONSE_MESSAGE,
|
215 mike 1.6 CIM_EXPORT_INDICATION_RESPONSE_MESSAGE,
|
216 mike 1.5 CIM_DELETE_CLASS_RESPONSE_MESSAGE,
217 CIM_DELETE_INSTANCE_RESPONSE_MESSAGE,
218 CIM_CREATE_CLASS_RESPONSE_MESSAGE,
219 CIM_CREATE_INSTANCE_RESPONSE_MESSAGE,
220 CIM_MODIFY_CLASS_RESPONSE_MESSAGE,
221 CIM_MODIFY_INSTANCE_RESPONSE_MESSAGE,
222 CIM_ENUMERATE_CLASSES_RESPONSE_MESSAGE,
223 CIM_ENUMERATE_CLASS_NAMES_RESPONSE_MESSAGE,
224 CIM_ENUMERATE_INSTANCES_RESPONSE_MESSAGE,
225 CIM_ENUMERATE_INSTANCE_NAMES_RESPONSE_MESSAGE,
226 CIM_EXEC_QUERY_RESPONSE_MESSAGE,
227 CIM_ASSOCIATORS_RESPONSE_MESSAGE,
228 CIM_ASSOCIATOR_NAMES_RESPONSE_MESSAGE,
229 CIM_REFERENCES_RESPONSE_MESSAGE,
230 CIM_REFERENCE_NAMES_RESPONSE_MESSAGE,
231 CIM_GET_PROPERTY_RESPONSE_MESSAGE,
232 CIM_SET_PROPERTY_RESPONSE_MESSAGE,
233 CIM_GET_QUALIFIER_RESPONSE_MESSAGE,
234 CIM_SET_QUALIFIER_RESPONSE_MESSAGE,
235 CIM_DELETE_QUALIFIER_RESPONSE_MESSAGE,
236 CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE,
237 mike 1.5 CIM_INVOKE_METHOD_RESPONSE_MESSAGE,
|
238 mike 1.6 CIM_ENABLE_INDICATION_SUBSCRIPTION_RESPONSE_MESSAGE,
239 CIM_MODIFY_INDICATION_SUBSCRIPTION_RESPONSE_MESSAGE,
240 CIM_DISABLE_INDICATION_SUBSCRIPTION_RESPONSE_MESSAGE,
|
241 kumpf 1.15 CIM_PROCESS_INDICATION_RESPONSE_MESSAGE,
242 CIM_NOTIFY_PROVIDER_REGISTRATION_RESPONSE_MESSAGE,
243 CIM_NOTIFY_PROVIDER_TERMINATION_RESPONSE_MESSAGE,
|
244 kumpf 1.17 CIM_HANDLE_INDICATION_RESPONSE_MESSAGE,
|
245 mike 1.6
246 // Monitor-related messages:
247
248 SOCKET_MESSAGE,
249
250 // Connection-oriented messages:
251
252 CLOSE_CONNECTION_MESSAGE,
253
254 // HTTP messages:
255
256 HTTP_MESSAGE,
|
257 mike 1.5
258 NUMBER_OF_MESSAGES
259 };
260
261 PEGASUS_COMMON_LINKAGE const char* MessageTypeToString(Uint32 messageType);
|
262 mike 1.6
263 /** This class implements a stack of queue-ids. Many messages must keep a
264 stack of queue-ids of queues which they must be returned to. This provides
265 a light efficient stack for this purpose.
266 */
267 class QueueIdStack
268 {
269 public:
270
271 QueueIdStack() : _size(0)
272 {
273 }
274
275 QueueIdStack(const QueueIdStack& x) : _size(x._size)
276 {
277 memcpy(_items, x._items, sizeof(_items));
278 }
279
280 PEGASUS_EXPLICIT QueueIdStack(Uint32 x) : _size(0)
281 {
282 push(x);
283 mike 1.6 }
284
285 PEGASUS_EXPLICIT QueueIdStack(Uint32 x1, Uint32 x2) : _size(0)
286 {
287 push(x1);
288 push(x2);
289 }
290
291 ~QueueIdStack()
292 {
293 }
294
295 QueueIdStack& operator=(const QueueIdStack& x)
296 {
297 if (this != &x)
298 {
299 memcpy(_items, x._items, sizeof(_items));
300 _size = x._size;
301 }
302 return *this;
303 }
304 mike 1.6
305 Uint32 size() const
306 {
307 return _size;
308 }
309
310 Boolean isEmpty() const
311 {
312 return _size == 0;
313 }
314
315 void push(Uint32 x)
316 {
317 if (_size == MAX_SIZE)
318 throw StackOverflow();
319
320 _items[_size++] = x;
321 }
322
323 Uint32& top()
324 {
325 mike 1.6 if (_size == 0)
326 throw StackUnderflow();
327
328 return _items[_size-1];
329 }
330
331 Uint32 top() const
332 {
333 return ((QueueIdStack*)this)->top();
334 }
335
336 void pop()
337 {
338 if (_size == 0)
339 throw StackUnderflow();
340
341 _size--;
342 }
343
344 /** Make a copy of this stack and then pop the top element. */
345 QueueIdStack copyAndPop() const
346 mike 1.6 {
347 return QueueIdStack(*this, 0);
348 }
349
350 private:
351
352 // Copy the given stack but then pop the top element:
353 QueueIdStack(const QueueIdStack& x, int) : _size(x._size)
354 {
355 memcpy(_items, x._items, sizeof(_items));
356 pop();
357 }
358
359 enum { MAX_SIZE = 5 };
360 Uint32 _items[MAX_SIZE];
361 Uint32 _size;
362 };
|
363 mike 1.4
364 PEGASUS_NAMESPACE_END
365
366 #endif /* Pegasus_Message_h */
|