1 karl 1.44 //%2006////////////////////////////////////////////////////////////////////////
|
2 mday 1.1 //
|
3 karl 1.38 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.36 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.38 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.39 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.44 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mday 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.44 //
|
21 mday 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>
33 //
|
34 a.arora 1.37 // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
|
35 david.dillard 1.42 // David Dillard, VERITAS Software Corp.
36 // (david.dillard@veritas.com)
|
37 mday 1.1 //
38 //%/////////////////////////////////////////////////////////////////////////////
39
40 #ifndef Pegasus_Module_Controller_h
41 #define Pegasus_Module_Controller_h
42
43 #include <Pegasus/Common/Config.h>
|
44 mday 1.19 #include <Pegasus/Common/Constants.h>
|
45 mday 1.1 #include <Pegasus/Common/Message.h>
|
46 kumpf 1.33 #include <Pegasus/Common/InternalException.h>
|
47 mday 1.1 #include <Pegasus/Common/IPC.h>
48 #include <Pegasus/Common/Thread.h>
49 #include <Pegasus/Common/AsyncOpNode.h>
50 #include <Pegasus/Common/Cimom.h>
51 #include <Pegasus/Common/CimomMessage.h>
52 #include <Pegasus/Common/MessageQueueService.h>
|
53 mday 1.14 #include <Pegasus/Common/peg_authorization.h>
|
54 kumpf 1.32 #include <Pegasus/Common/Linkage.h>
|
55 david.dillard 1.42 #include <Pegasus/Common/AutoPtr.h>
|
56 mike 1.45 #include <Pegasus/Common/List.h>
|
57 mday 1.11
58
|
59 mday 1.1 PEGASUS_NAMESPACE_BEGIN
60
61 class ModuleController;
62
|
63 mday 1.9
|
64 mike 1.45 class PEGASUS_COMMON_LINKAGE pegasus_module : public Linkable
|
65 mday 1.9 {
|
66 david.dillard 1.42 private:
67 class module_rep : public pegasus_auth_handle
68 {
69 public:
70 typedef pegasus_auth_handle Base;
71
72 module_rep(ModuleController *controller,
73 const String & name,
74 void *module_address,
75 Message * (*receive_message)(Message *, void *),
76 void (*async_callback)(Uint32, Message *, void *),
77 void (*shutdown_notify)(Uint32 code, void *));
78
79 ~module_rep();
80
81 void reference()
82 {
83 _reference_count++;
84 }
85
86 void dereference()
87 david.dillard 1.42 {
88 _reference_count--;
89 }
90
91 Uint32 reference_count() const
92 {
|
93 mike 1.43 return _reference_count.get();
|
94 david.dillard 1.42 }
95
96 const String& get_name() const throw()
97 {
98 return _name;
99 }
100
101 void *get_module_address() const
102 {
103 return _module_address;
104 }
105
106 Message * module_receive_message(Message *msg);
107
108 void _send_async_callback(Uint32 msg_handle, Message *msg, void *parm);
109
110 void _send_shutdown_notify();
111
112 void lock()
113 {
114 _thread_safety.lock(pegasus_thread_self());
115 david.dillard 1.42 }
116
117 void unlock()
118 {
119 _thread_safety.unlock();
120 }
121
122 Boolean authorized();
123 Boolean authorized(Uint32);
124 Boolean authorized(Uint32, Uint32);
125
126 private:
127 module_rep();
128 module_rep(const module_rep&);
129 module_rep & operator=(const module_rep & rep);
130
131 Mutex _thread_safety;
132 // Don't make this an AutoPtr. Refer to bug 3502
133 ModuleController* _controller;
134 String _name;
135 AtomicInt _reference_count;
136 david.dillard 1.42 AtomicInt _shutting_down;
137
138 void *_module_address;
139 Message * (*_receive_message)(Message *, void *);
140 void (*_async_callback)(Uint32, Message *, void *);
141 void (*_shutdown_notify)(Uint32 code, void *);
142
143 static Message * default_receive_message(Message *msg, void *inst)
144 {
145 throw NotImplemented("Module Receive");
146 return 0;
147 }
148
149 static void default_async_callback(Uint32 handle, Message *msg, void *inst)
150 {
151 throw NotImplemented("Module Async Receive");
152 }
153
154 static void default_shutdown_notify(Uint32 code, void *inst)
155 {
156 // Intentionally left blank
157 david.dillard 1.42 }
158
159 static Message * closed_receive_message(Message *msg, void *inst)
160 {
161 throw ModuleClosed();
162 return 0;
163 }
164
165 static void closed_async_callback(Uint32 handle, Message *msg, void *inst)
166 {
167 throw ModuleClosed();
168 }
169
170 friend class ModuleController;
171 };
172
173 public:
174 pegasus_module(ModuleController *controller,
175 const String &id,
176 void *module_address,
177 Message * (*receive_message)(Message *, void *),
178 david.dillard 1.42 void (*async_callback)(Uint32, Message *, void *),
179 void (*shutdown_notify)(Uint32 code, void *));
180
181 pegasus_module(const pegasus_module & mod);
182 pegasus_module & operator= (const pegasus_module & mod);
183
184 virtual ~pegasus_module();
185
186 virtual Boolean authorized(Uint32 operation);
187 virtual Boolean authorized();
188
189 Boolean operator == (const String & mod) const;
190
191 const String & get_name() const;
192
193 // introspection interface
194 Boolean query_interface(const String & class_id, void **object_ptr) const;
195
196 private:
197
198 AutoPtr<module_rep> _rep;//PEP101
199 david.dillard 1.42
200 pegasus_module()
201 {
202 }
203
204 Boolean _rcv_msg(Message *);
205 Message * _receive_message(Message *msg);
206 void _send_async_callback(Uint32 msg_handle, Message *msg, void *);
207 void _send_shutdown_notify();
208 Boolean _shutdown();
209 PEGASUS_STD(bitset<32>) _allowed_operations;
210
211 void reference()
212 {
213 _rep->reference();
214 }
215
216 void dereference()
217 {
218 _rep->dereference();
219 }
220 david.dillard 1.42
221 friend class ModuleController;
|
222 mday 1.5 };
|
223 mday 1.4
224
|
225 mday 1.1 class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
226 {
|
227 david.dillard 1.42 public:
228 typedef MessageQueueService Base;
|
229 mday 1.1
|
230 david.dillard 1.42 static const Uint32 GET_CLIENT_HANDLE;
231 static const Uint32 REGISTER_MODULE;
232 static const Uint32 DEREGISTER_MODULE;
233 static const Uint32 FIND_SERVICE;
234 static const Uint32 FIND_MODULE_IN_SERVICE;
235 static const Uint32 GET_MODULE_REFERENCE;
236 static const Uint32 MODULE_SEND_WAIT;
237 static const Uint32 MODULE_SEND_WAIT_MODULE;
238 static const Uint32 MODULE_SEND_ASYNC;
239 static const Uint32 MODULE_SEND_ASYNC_MODULE;
240 static const Uint32 BLOCKING_THREAD_EXEC;
241 static const Uint32 ASYNC_THREAD_EXEC;
242 static const Uint32 CLIENT_SEND_WAIT;
243 static const Uint32 CLIENT_SEND_WAIT_MODULE;
244 static const Uint32 CLIENT_SEND_ASYNC;
245 static const Uint32 CLIENT_SEND_ASYNC_MODULE;
246 static const Uint32 CLIENT_BLOCKING_THREAD_EXEC;
247 static const Uint32 CLIENT_ASYNC_THREAD_EXEC;
248 static const Uint32 CLIENT_SEND_FORGET;
249 static const Uint32 CLIENT_SEND_FORGET_MODULE;
250 static const Uint32 MODULE_SEND_FORGET;
251 david.dillard 1.42 static const Uint32 MODULE_SEND_FORGET_MODULE;
|
252 mday 1.11
|
253 kumpf 1.20 // ATTN-DME-P2-20020406 Removed private declaration. client_handle is
254 // currently used in Pegasus/Provider/CIMOMHandle.cpp
|
255 mday 1.14
|
256 david.dillard 1.42 // private:
257 class client_handle : public pegasus_auth_handle
258 {
259 public:
260 typedef pegasus_auth_handle Base;
261
262 client_handle(const pegasus_identity & id)
263 :Base(id) ,
264 allowed_operations( GET_CLIENT_HANDLE |
265 FIND_SERVICE |
266 FIND_MODULE_IN_SERVICE |
267 GET_MODULE_REFERENCE |
268 CLIENT_SEND_WAIT |
269 CLIENT_SEND_WAIT_MODULE |
270 CLIENT_SEND_ASYNC |
271 CLIENT_SEND_ASYNC_MODULE |
272 CLIENT_BLOCKING_THREAD_EXEC |
273 CLIENT_ASYNC_THREAD_EXEC),
274 reference_count(1)
275 {
276 }
277 david.dillard 1.42
278 ~client_handle()
279 {
280 }
281
282 client_handle & operator=(const client_handle & handle)
283 {
284 if (this == &handle)
285 return *this;
286 reference_count++;
287 return *this;
288 }
289
290
291 virtual Boolean authorized(Uint32, Uint32);
292 virtual Boolean authorized(Uint32 operation);
293 virtual Boolean authorized();
294 PEGASUS_STD(bitset<32>) allowed_operations;
295 AtomicInt reference_count;
296 };
297
298 david.dillard 1.42 class callback_handle
299 {
300 public:
301 callback_handle(pegasus_module * module, void *parm)
302 : _module(module), _parm(parm)
303 {
304 }
305
306 ~callback_handle()
307 {
308 if( _module->get_name() == String(PEGASUS_MODULENAME_TEMP) )
309 // delete _module;
310 _module.reset();
311 }
312
313 AutoPtr<pegasus_module> _module;//PEP101
314 void *_parm;
315 };
|
316 mday 1.11
|
317 david.dillard 1.42 public:
318 ModuleController(const char *name);
|
319 mday 1.30 /* ModuleController(const char *name, */
|
320 david.dillard 1.42 /* Sint16 min_threads, */
321 /* Sint16 max_threads, */
322 /* struct timeval & create_thread, */
323 /* struct timeval & destroy_thread); */
324
325 ~ModuleController();
326
327 // module api
328 // @exception AlreadyExistsException
329 // @exception IncompatibleTypesException
330 static ModuleController & register_module(const String & controller_name,
331 const String & module_name,
332 void *module_address,
333 Message * (*receive_message)(Message *, void *),
334 void (*async_callback)(Uint32, Message *, void *),
335 void (*shutdown_notify)(Uint32, void *),
336 pegasus_module **instance = NULL);
337
338 // @exception Permission
339 Boolean deregister_module(const String & module_name);
340
341 david.dillard 1.42 // @exception Permission
342 Uint32 find_service(const pegasus_module & handle, const String & name);
343
344 // @exception Permission
345 // @exception IPCException
346 Uint32 find_module_in_service(const pegasus_module & handle,
347 const String & module_name);
348
349 // @exception Permission
350 pegasus_module * get_module_reference(const pegasus_module & my_handle,
351 const String & module_name);
352
353 // send a message to another service
354 // @exception Permission
355 // @exception IPCException
356 AsyncReply *ModuleSendWait(const pegasus_module & handle,
357 Uint32 destination_q,
358 AsyncRequest *request);
359
360 // send a message to another module via another service
361 // @exception Permission
362 david.dillard 1.42 // @exception DeadLock
363 // @exception IPCException
364 AsyncReply *ModuleSendWait(const pegasus_module & handle,
365 Uint32 destination_q,
366 const String & destination_module,
367 AsyncRequest *message);
368
369 // send an async message to another service
370 // @exception Permission
371 // @exception DeadLock
372 // @exception IPCException
373 Boolean ModuleSendAsync(const pegasus_module & handle,
374 Uint32 msg_handle,
375 Uint32 destination_q,
376 AsyncRequest *message,
377 void *callback_parm);
378
379 // send an async message to another module via another service
380 // @exception Permission
381 // @exception IPCException
382 Boolean ModuleSendAsync(const pegasus_module & handle,
383 david.dillard 1.42 Uint32 msg_handle,
384 Uint32 destination_q,
385 const String & destination_module,
386 AsyncRequest *message,
387 void *callback_parm);
388
389 // @exception Permission
390 // @exception IPCException
391 Boolean ModuleSendForget(const pegasus_module & handle,
392 Uint32 destination_q,
393 AsyncRequest *message);
394
395 // @exception Permission
396 // @exception IPCException
397 Boolean ModuleSendForget(const pegasus_module & handle,
398 Uint32 destination_q,
399 const String & destination_module,
400 AsyncRequest *message);
401
402 // @exception Permission
403 // @exception Deadlock
404 david.dillard 1.42 // @exception IPCException
405 void blocking_thread_exec(const pegasus_module & handle,
406 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
407 void *parm);
408
409 // @exception Permission
410 // @exception Deadlock
411 // @exception IPCException
412 void async_thread_exec(const pegasus_module & handle,
413 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
414 void *parm);
415
416 Boolean verify_handle(pegasus_module *);
417
418 // @exception IncompatibleTypesException
419 static ModuleController & get_client_handle(const pegasus_identity & id,
420 client_handle **handle);
421
422 // @exception IncompatibleTypesException
423 static ModuleController & get_client_handle(const char *controller,
424 const pegasus_identity & id,
425 david.dillard 1.42 client_handle **handle);
426
427
428 void return_client_handle(client_handle *handle);
429
430 // send a message to another service
431 // @exception Permission
432 // @exception IPCException
433 AsyncReply *ClientSendWait(const client_handle & handle,
434 Uint32 destination_q, AsyncRequest *request);
435
436 // send a message to another module via another service
437 // @exception Permission
438 // @exception Deadlock
439 // @exception IPCException
440 AsyncReply *ClientSendWait(const client_handle & handle,
441 Uint32 destination_q,
442 String & destination_module,
443 AsyncRequest *message);
444
445 // send an async message to another service
446 david.dillard 1.42 // @exception Permission
447 // @exception IPCException
448 Boolean ClientSendAsync(const client_handle & handle,
449 Uint32 msg_handle,
450 Uint32 destination_q,
451 AsyncRequest *message,
452 void (*async_callback)(Uint32, Message *, void *) ,
453 void *callback_parm);
454
455 // send an async message to another module via another service
456 // @exception Permission
457 // @exception IPCException
458 Boolean ClientSendAsync(const client_handle & handle,
459 Uint32 msg_handle,
460 Uint32 destination_q,
461 const String & destination_module,
462 AsyncRequest *message,
463 void (*async_callback)(Uint32, Message *, void *),
464 void *callback_parm);
465
466 // @exception Permission
467 david.dillard 1.42 // @exception IPCException
468 Boolean ClientSendForget(const client_handle & handle,
469 Uint32 destination_q,
470 AsyncRequest *message);
471
472 // @exception Permission
473 // @exception IPCException
474 Boolean ClientSendForget(const client_handle & handle,
475 Uint32 destination_q,
476 const String & destination_module,
477 AsyncRequest *message);
478
479 // @exception Permission
480 // @exception Deadlock
481 // @exception IPCException
482 void client_blocking_thread_exec(const client_handle & handle,
483 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
484 void *parm);
485
486 // @exception Permission
487 // @exception Deadlock
488 david.dillard 1.42 // @exception IPCException
489 void client_async_thread_exec(const client_handle & handle,
490 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
491 void *parm);
492
493 protected:
494 // ATTN-RK-P2-20010322: These methods are pure virtual in superclass
495 virtual void handleEnqueue() {}
496 virtual void handleEnqueue(Message *) {}
497 virtual void _handle_async_request(AsyncRequest *rq);
498 virtual void _handle_async_callback(AsyncOpNode *op);
499
500 private:
501 class _module_lock
502 {
503 public:
|
504 mike 1.45 _module_lock(List<pegasus_module, RecursiveMutex> * list)
|
505 david.dillard 1.42 :_list(list)
506 {
507 _list->lock();
508 }
509
510 ~_module_lock()
511 {
512 _list->unlock();
513 }
514
515 private:
516 _module_lock();
|
517 mike 1.45 List<pegasus_module, RecursiveMutex> * _list;
|
518 david.dillard 1.42 };
519
520
521
522 static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
|
523 mike 1.45 List<pegasus_module, RecursiveMutex> _modules;
|
524 david.dillard 1.42 AsyncReply *_send_wait(Uint32, AsyncRequest *);
525 AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
526
527 // @exception IPCException
528 Boolean _send_forget(Uint32, AsyncRequest *);
529
530 // @exception IPCException
531 Boolean _send_forget(Uint32, const String &, AsyncRequest *);
532
533 void _blocking_thread_exec(
534 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
535 void *parm);
536
537 void _async_thread_exec(
538 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
539 void *parm);
|
540 mday 1.2 };
|
541 mday 1.35
|
542 mday 1.1 PEGASUS_NAMESPACE_END
543
|
544 mday 1.4 #endif // Pegasus_Module_Controller_H
|