1 mday 1.1 //%////-*-c++-*-////////////////////////////////////////////////////////////////
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 mday 1.1 //
23 // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #ifndef Pegasus_Module_Controller_h
30 #define Pegasus_Module_Controller_h
31
32 #include <Pegasus/Common/Config.h>
|
33 mday 1.19 #include <Pegasus/Common/Constants.h>
|
34 mday 1.1 #include <Pegasus/Common/Message.h>
35 #include <Pegasus/Common/Exception.h>
36 #include <Pegasus/Common/IPC.h>
37 #include <Pegasus/Common/Thread.h>
38 #include <Pegasus/Common/AsyncOpNode.h>
39 #include <Pegasus/Common/Cimom.h>
40 #include <Pegasus/Common/CimomMessage.h>
41 #include <Pegasus/Common/MessageQueueService.h>
|
42 mday 1.14 #include <Pegasus/Common/peg_authorization.h>
|
43 mday 1.11
44
|
45 mday 1.1 PEGASUS_NAMESPACE_BEGIN
46
47 class ModuleController;
48
|
49 mday 1.9
|
50 mday 1.18 class PEGASUS_COMMON_LINKAGE pegasus_module
|
51 mday 1.9 {
52 private:
|
53 mday 1.18 class module_rep : public pegasus_auth_handle
|
54 mday 1.5 {
55 public:
|
56 mday 1.18 typedef pegasus_auth_handle Base;
57
|
58 mday 1.5 module_rep(ModuleController *controller,
59 const String & name,
60 void *module_address,
|
61 mday 1.10 Message * (*receive_message)(Message *, void *),
62 void (*async_callback)(Uint32, Message *, void *),
63 void (*shutdown_notify)(Uint32 code, void *));
|
64 mday 1.5
|
65 mday 1.9 ~module_rep(void) ;
66
|
67 mday 1.17 Boolean operator == (const module_rep *rep) const
|
68 mday 1.9 { if (rep == this ) return true; return false; }
|
69 mday 1.5
70 Boolean operator == (const module_rep &rep) const
|
71 mday 1.9 { if (rep == *this) return true; return false; }
|
72 mday 1.5
73 Boolean operator == (void *rep) const
|
74 mday 1.9 { if ( (void *)this == rep ) return true; return false; }
|
75 mday 1.5
76 void reference(void) { _reference_count++; }
77 void dereference(void) { _reference_count--; }
78 Uint32 reference_count(void) { return _reference_count.value(); }
79 const String & get_name(void) const { return _name; }
80 void *get_module_address(void) const { return _module_address; }
|
81 mday 1.9
82 Message * module_receive_message(Message *msg);
|
83 mday 1.5
|
84 mday 1.19 void _send_async_callback(Uint32 msg_handle, Message *msg, void *parm);
|
85 mday 1.5
|
86 mday 1.9 void _send_shutdown_notify(void);
87 void lock(void) { _thread_safety.lock(pegasus_thread_self()); }
88 void unlock(void) { _thread_safety.unlock(); }
|
89 mday 1.18
90 Boolean authorized(void) ;
91 Boolean authorized(Uint32);
92 Boolean authorized(Uint32, Uint32);
93
|
94 mday 1.9 private:
|
95 mday 1.5 module_rep(void);
96 module_rep(const module_rep & );
|
97 mday 1.17 module_rep & operator= (const module_rep & rep);
|
98 mday 1.9
|
99 mday 1.17
|
100 mday 1.5 Mutex _thread_safety;
101 ModuleController *_controller;
102 String _name;
103 AtomicInt _reference_count;
|
104 mday 1.9 AtomicInt _shutting_down;
|
105 mday 1.6
|
106 mday 1.5 void *_module_address;
|
107 mday 1.10 Message * (*_receive_message)(Message *, void *);
108 void (*_async_callback)(Uint32, Message *, void *);
109 void (*_shutdown_notify)(Uint32 code, void *);
|
110 mday 1.5
|
111 mday 1.10 static Message * default_receive_message(Message *msg, void *inst)
|
112 kumpf 1.23 { throw NotImplemented("Module Receive"); return 0; }
|
113 mday 1.5
|
114 mday 1.10 static void default_async_callback(Uint32 handle, Message *msg, void *inst)
|
115 mday 1.9 { throw NotImplemented("Module Async Receive"); }
|
116 mday 1.5
|
117 mday 1.10 static void default_shutdown_notify(Uint32 code, void *inst)
|
118 mday 1.9 { return; }
119
|
120 mday 1.10 static Message * closed_receive_message(Message *msg, void *inst)
|
121 kumpf 1.23 { throw ModuleClosed(); return 0; }
|
122 mday 1.9
|
123 mday 1.10 static void closed_async_callback(Uint32 handle, Message *msg, void *inst)
|
124 mday 1.9 { throw ModuleClosed(); }
|
125 mday 1.5
126 friend class ModuleController;
127 };
|
128 mday 1.7
|
129 mday 1.1 public:
|
130 mday 1.3 pegasus_module(ModuleController *controller,
131 const String &id,
132 void *module_address,
|
133 mday 1.10 Message * (*receive_message)(Message *, void *),
134 void (*async_callback)(Uint32, Message *, void *),
135 void (*shutdown_notify)(Uint32 code, void *)) ;
|
136 mday 1.5
|
137 mday 1.17 pegasus_module(const pegasus_module & mod);
138 pegasus_module & operator= (const pegasus_module & mod);
139
|
140 mday 1.18 virtual ~pegasus_module(void);
|
141 mday 1.3
|
142 mday 1.18 virtual Boolean authorized(Uint32 operation);
143 virtual Boolean authorized(void);
|
144 mday 1.16
|
145 mday 1.4 Boolean operator == (const pegasus_module & mod) const ;
146 Boolean operator == (const String & mod) const;
147 Boolean operator == (const void *mod) const;
148
|
149 mday 1.5 const String & get_name(void) const;
|
150 mday 1.3
|
151 mday 1.2 // introspection interface
|
152 mday 1.5 Boolean query_interface(const String & class_id, void **object_ptr) const;
|
153 mday 1.16
|
154 mday 1.1
155 private:
|
156 mday 1.18
|
157 mday 1.17 module_rep *_rep;
|
158 mday 1.3
|
159 mday 1.19 pegasus_module(void)
160 {
161 }
162
|
163 mday 1.6 Boolean _rcv_msg(Message *) ;
|
164 mday 1.9 Message * _receive_message(Message *msg);
|
165 mday 1.19 void _send_async_callback(Uint32 msg_handle, Message *msg, void *) ;
|
166 mday 1.9 void _send_shutdown_notify(void);
167 Boolean _shutdown(void);
|
168 kumpf 1.24 PEGASUS_STD(bitset<32>) _allowed_operations;
|
169 mday 1.6
170 void reference(void) { _rep->reference(); }
171 void dereference(void) { _rep->dereference(); }
|
172 mday 1.5 friend class ModuleController;
173 };
|
174 mday 1.4
175
|
176 mday 1.1 class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
177 {
178
|
179 mday 1.11
|
180 mday 1.1 public:
|
181 mday 1.5 typedef MessageQueueService Base;
|
182 mday 1.1
|
183 mday 1.14 static const Uint32 GET_CLIENT_HANDLE;
184 static const Uint32 REGISTER_MODULE;
185 static const Uint32 DEREGISTER_MODULE;
186 static const Uint32 FIND_SERVICE;
187 static const Uint32 FIND_MODULE_IN_SERVICE;
188 static const Uint32 GET_MODULE_REFERENCE;
189 static const Uint32 MODULE_SEND_WAIT;
190 static const Uint32 MODULE_SEND_WAIT_MODULE;
191 static const Uint32 MODULE_SEND_ASYNC;
192 static const Uint32 MODULE_SEND_ASYNC_MODULE;
193 static const Uint32 BLOCKING_THREAD_EXEC;
194 static const Uint32 ASYNC_THREAD_EXEC;
195 static const Uint32 CLIENT_SEND_WAIT;
196 static const Uint32 CLIENT_SEND_WAIT_MODULE;
197 static const Uint32 CLIENT_SEND_ASYNC;
198 static const Uint32 CLIENT_SEND_ASYNC_MODULE;
|
199 mday 1.15 static const Uint32 CLIENT_BLOCKING_THREAD_EXEC;
200 static const Uint32 CLIENT_ASYNC_THREAD_EXEC;
|
201 mday 1.22 static const Uint32 CLIENT_SEND_FORGET;
202 static const Uint32 CLIENT_SEND_FORGET_MODULE;
203 static const Uint32 MODULE_SEND_FORGET;
204 static const Uint32 MODULE_SEND_FORGET_MODULE;
|
205 mday 1.15
|
206 kumpf 1.20 // ATTN-DME-P2-20020406 Removed private declaration. client_handle is
207 // currently used in Pegasus/Provider/CIMOMHandle.cpp
|
208 mday 1.14
|
209 kumpf 1.20 // private:
|
210 mday 1.18 class client_handle : public pegasus_auth_handle
|
211 mday 1.11 {
212 public:
|
213 mday 1.18 typedef pegasus_auth_handle Base;
|
214 mday 1.14
|
215 mday 1.18 client_handle(const pegasus_identity & id)
216 :Base(id) ,
|
217 mday 1.16 allowed_operations( GET_CLIENT_HANDLE |
218 FIND_SERVICE |
219 FIND_MODULE_IN_SERVICE |
220 GET_MODULE_REFERENCE |
221 CLIENT_SEND_WAIT |
222 CLIENT_SEND_WAIT_MODULE |
223 CLIENT_SEND_ASYNC |
224 CLIENT_SEND_ASYNC_MODULE |
225 CLIENT_BLOCKING_THREAD_EXEC |
226 CLIENT_ASYNC_THREAD_EXEC)
227 {
228 }
229
|
230 mday 1.17 ~client_handle(void)
231 {
232 }
233
|
234 mday 1.18 virtual Boolean authorized(Uint32, Uint32);
|
235 mday 1.14 virtual Boolean authorized(Uint32 operation);
236 virtual Boolean authorized(void);
|
237 kumpf 1.24 PEGASUS_STD(bitset<32>) allowed_operations;
|
238 mday 1.11 };
239
|
240 mday 1.19 class callback_handle
241 {
242 public:
|
243 mday 1.26 static void * operator new(size_t );
244 static void operator delete(void *, size_t);
245 private:
246 static callback_handle *_head;
247 static const int BLOCK_SIZE;
248 static Mutex _alloc_mut;
249
250 public:
|
251 mday 1.19 callback_handle(pegasus_module * module, void *parm)
252 : _module(module), _parm(parm)
253 {
254 }
255
256 ~callback_handle()
257 {
|
258 kumpf 1.21 if( _module->get_name() == String(PEGASUS_MODULENAME_TEMP) )
|
259 mday 1.19 delete _module;
260 }
261
262 pegasus_module * _module;
263 void *_parm;
264 };
265
266
|
267 mday 1.11 public:
268
269
|
270 mday 1.6 ModuleController(const char *name);
271 ModuleController(const char *name,
272 Sint16 min_threads,
273 Sint16 max_threads,
274 struct timeval & create_thread,
275 struct timeval & destroy_thread,
276 struct timeval & deadlock);
277
278
|
279 mday 1.7 ~ModuleController(void);
|
280 mday 1.1
|
281 mday 1.19
|
282 mday 1.11
283
|
284 mday 1.1 // module api
|
285 mday 1.9 static ModuleController & register_module(const String & controller_name,
286 const String & module_name,
287 void *module_address,
|
288 mday 1.10 Message * (*receive_message)(Message *, void *),
289 void (*async_callback)(Uint32, Message *, void *),
290 void (*shutdown_notify)(Uint32, void *),
291 pegasus_module **instance = NULL)
|
292 mday 1.19
|
293 mday 1.9 throw(AlreadyExists, IncompatibleTypes);
|
294 mday 1.3
|
295 mday 1.11 Boolean deregister_module(const String & module_name)
296 throw(Permission);
|
297 mday 1.2
|
298 mday 1.22 Uint32 find_service(const pegasus_module & handle, const String & name) throw(Permission);
|
299 mday 1.2
|
300 mday 1.22 Uint32 find_module_in_service(const pegasus_module & handle,
|
301 mday 1.7 const String & module_name)
302 throw(Permission, IPCException);
303
304
|
305 mday 1.22 pegasus_module * get_module_reference(const pegasus_module & my_handle,
|
306 mday 1.7 const String & module_name)
307 throw(Permission);
|
308 mday 1.1
|
309 mday 1.2 // send a message to another service
|
310 mday 1.22 AsyncReply *ModuleSendWait(const pegasus_module & handle,
311 Uint32 destination_q,
312 AsyncRequest *request) throw(Permission, IPCException);
|
313 mday 1.1
|
314 mday 1.2 // send a message to another module via another service
|
315 mday 1.22 AsyncReply *ModuleSendWait(const pegasus_module & handle,
316 Uint32 destination_q,
317 const String & destination_module,
318 AsyncRequest *message) throw(Permission, Deadlock, IPCException);
|
319 mday 1.2
|
320 mday 1.11 // send an async message to another service
|
321 mday 1.22 Boolean ModuleSendAsync(const pegasus_module & handle,
|
322 mday 1.1 Uint32 msg_handle,
|
323 mday 1.2 Uint32 destination_q,
|
324 mday 1.19 AsyncRequest *message,
325 void *callback_parm) throw(Permission, IPCException);
|
326 mday 1.1
|
327 mday 1.11 // send an async message to another module via another service
|
328 mday 1.22 Boolean ModuleSendAsync(const pegasus_module & handle,
|
329 mday 1.1 Uint32 msg_handle,
|
330 mday 1.2 Uint32 destination_q,
|
331 mday 1.22 const String & destination_module,
|
332 mday 1.19 AsyncRequest *message,
333 void *callback_parm) throw(Permission, IPCException);
|
334 mday 1.1
|
335 mday 1.22 Boolean ModuleSendForget(const pegasus_module & handle,
336 Uint32 destination_q,
337 AsyncRequest *message)
338 throw(Permission, IPCException);
339
340 Boolean ModuleSendForget(const pegasus_module & handle,
341 Uint32 destination_q,
342 const String & destination_module,
343 AsyncRequest *message)
344 throw(Permission, IPCException);
345
346 void blocking_thread_exec(const pegasus_module & handle,
|
347 mday 1.7 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
348 void *parm) throw(Permission, Deadlock, IPCException);
|
349 mday 1.22 void async_thread_exec(const pegasus_module & handle,
|
350 mday 1.7 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
351 void *parm) throw(Permission, Deadlock, IPCException);
|
352 mday 1.14
|
353 mday 1.7 Boolean verify_handle(pegasus_module *);
|
354 mday 1.19
355 static ModuleController & get_client_handle(const pegasus_identity & id,
356 client_handle **handle)
357 throw(IncompatibleTypes);
358
|
359 mday 1.25 static ModuleController & get_client_handle(char *controller,
360 const pegasus_identity & id,
361 client_handle **handle)
362 throw(IncompatibleTypes);
363
364
|
365 mday 1.19 void return_client_handle(client_handle *handle);
366
367 // send a message to another service
368 AsyncReply *ClientSendWait(const client_handle & handle,
369 Uint32 destination_q,
370 AsyncRequest *request)
371 throw(Permission, IPCException);
372
373 // send a message to another module via another service
374 AsyncReply *ClientSendWait(const client_handle & handle,
375 Uint32 destination_q,
376 String & destination_module,
377 AsyncRequest *message)
378 throw(Permission, Deadlock, IPCException);
379
380 // send an async message to another service
381 Boolean ClientSendAsync(const client_handle & handle,
382 Uint32 msg_handle,
383 Uint32 destination_q,
384 AsyncRequest *message,
385 void (*async_callback)(Uint32, Message *, void *) ,
386 mday 1.19 void *callback_parm)
387 throw(Permission, IPCException);
388
389 // send an async message to another module via another service
390 Boolean ClientSendAsync(const client_handle & handle,
391 Uint32 msg_handle,
392 Uint32 destination_q,
|
393 mday 1.26 const String & destination_module,
|
394 mday 1.19 AsyncRequest *message,
395 void (*async_callback)(Uint32, Message *, void *),
396 void *callback_parm )
397 throw(Permission, IPCException);
398
|
399 mday 1.22 Boolean ClientSendForget(const client_handle & handle,
400 Uint32 destination_q,
401 AsyncRequest *message)
402 throw(Permission, IPCException);
403
404 Boolean ClientSendForget(const client_handle & handle,
405 Uint32 destination_q,
406 String & destination_module,
407 AsyncRequest *message)
408 throw(Permission, IPCException);
409
|
410 mday 1.19 void client_blocking_thread_exec(const client_handle & handle,
411 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
412 void *parm)
413 throw(Permission, Deadlock, IPCException);
414 void client_async_thread_exec(const client_handle & handle,
415 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
416 void *parm)
417 throw(Permission, Deadlock, IPCException);
418
|
419 mday 1.1 protected:
|
420 kumpf 1.8 // ATTN-RK-P2-20010322: These methods are pure virtual in superclass
421 virtual void handleEnqueue(void) {}
422 virtual void handleEnqueue(Message *) {}
|
423 mday 1.9 virtual void _handle_async_request(AsyncRequest *rq);
424 virtual void _handle_async_callback(AsyncOpNode *op);
|
425 mday 1.1
|
426 mday 1.19
427
428
|
429 mday 1.1 private:
|
430 mday 1.7 static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
|
431 mday 1.2 DQueue<pegasus_module> _modules;
|
432 mday 1.1 ThreadPool _thread_pool;
|
433 mday 1.19 pegasus_module _internal_module;
434 AsyncReply *_send_wait(Uint32, AsyncRequest *);
|
435 mday 1.22 AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
436 Boolean _send_forget(Uint32, AsyncRequest *) throw(IPCException);
437 Boolean _send_forget(Uint32, const String &, AsyncRequest *) throw(IPCException);
438
|
439 mday 1.19 void _blocking_thread_exec(
440 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
441 void *parm) ;
442 void _async_thread_exec(
443 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
444 void *parm) ;
|
445 mday 1.2 };
|
446 mday 1.1
447
|
448 mday 1.4
449
450
451
452
|
453 mday 1.1 PEGASUS_NAMESPACE_END
454
455
|
456 mday 1.4 #endif // Pegasus_Module_Controller_H
|