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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2