(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 kumpf   1.40 /* 		       struct timeval & destroy_thread); */
298 mday    1.6        
299              
300 mday    1.7        ~ModuleController(void);
301 mday    1.1  
302 mday    1.19 
303 mday    1.11       
304              
305 mday    1.1        // module api 
306 mday    1.9        static ModuleController & register_module(const String & controller_name,
307              						const String & module_name, 
308              						void *module_address, 
309 mday    1.10 						Message * (*receive_message)(Message *, void *),
310              						void (*async_callback)(Uint32, Message *, void *),
311              						void (*shutdown_notify)(Uint32, void *), 
312              						pegasus_module **instance = NULL) 
313 mday    1.19 
314 kumpf   1.34 	 throw(AlreadyExistsException, IncompatibleTypesException);
315 mday    1.3  
316 mday    1.11       Boolean deregister_module(const String & module_name)
317              	 throw(Permission);
318 mday    1.2        
319 mday    1.22       Uint32 find_service(const pegasus_module & handle, const String & name) throw(Permission);
320 mday    1.2  
321 mday    1.22       Uint32 find_module_in_service(const pegasus_module & handle, 
322 mday    1.7  				    const String & module_name) 
323              	 throw(Permission, IPCException);
324              				    
325              
326 mday    1.22       pegasus_module * get_module_reference(const pegasus_module & my_handle, 
327 mday    1.7  					    const String & module_name)
328              	 throw(Permission);
329 mday    1.1        
330 mday    1.2        // send a message to another service
331 mday    1.22       AsyncReply *ModuleSendWait(const pegasus_module & handle,
332              				 Uint32 destination_q, 
333              				 AsyncRequest *request) throw(Permission, IPCException);
334 mday    1.1  
335 mday    1.2        // send a message to another module via another service
336 mday    1.22       AsyncReply *ModuleSendWait(const pegasus_module & handle,
337              				 Uint32 destination_q,
338              				 const String & destination_module,
339              				 AsyncRequest *message) throw(Permission, Deadlock, IPCException);
340 mday    1.2  
341 mday    1.11       // send an async message to another service
342 mday    1.22       Boolean ModuleSendAsync(const pegasus_module & handle,
343 mday    1.1  			      Uint32 msg_handle, 
344 mday    1.2  			      Uint32 destination_q, 
345 mday    1.19 			      AsyncRequest *message, 
346              			      void *callback_parm) throw(Permission, IPCException);
347 mday    1.1  
348 mday    1.11       // send an async message to another module via another service
349 mday    1.22       Boolean ModuleSendAsync(const pegasus_module & handle,
350 mday    1.1  			      Uint32 msg_handle, 
351 mday    1.2  			      Uint32 destination_q, 
352 mday    1.22 			      const String & destination_module,
353 mday    1.19 			      AsyncRequest *message, 
354              			      void *callback_parm) throw(Permission, IPCException);
355 mday    1.1  
356 mday    1.22       Boolean ModuleSendForget(const pegasus_module & handle, 
357              			       Uint32 destination_q, 
358              			       AsyncRequest *message)
359              	 throw(Permission, IPCException);
360                    
361                    Boolean ModuleSendForget(const pegasus_module & handle, 
362              			       Uint32 destination_q, 
363              			       const String & destination_module, 
364              			       AsyncRequest *message)
365              	 throw(Permission, IPCException);
366                    
367                    void blocking_thread_exec(const pegasus_module & handle,
368 mday    1.7  				PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
369              				void *parm) throw(Permission, Deadlock, IPCException);
370 mday    1.22       void async_thread_exec(const pegasus_module & handle, 
371 mday    1.7  			     PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
372              			     void *parm) throw(Permission, Deadlock, IPCException);
373 mday    1.14 
374 mday    1.7        Boolean verify_handle(pegasus_module *);
375 mday    1.19 
376                    static ModuleController & get_client_handle(const pegasus_identity & id, 
377              						  client_handle **handle)
378 kumpf   1.34 	 throw(IncompatibleTypesException);
379 mday    1.19 
380 kumpf   1.29       static ModuleController & get_client_handle(const char *controller,
381 mday    1.25 						  const pegasus_identity & id, 
382              						  client_handle **handle)
383 kumpf   1.34 	 throw(IncompatibleTypesException);
384 mday    1.25       						  
385              
386 mday    1.19       void return_client_handle(client_handle *handle);
387                    
388                    // send a message to another service
389                    AsyncReply *ClientSendWait(const client_handle & handle,
390              				 Uint32 destination_q, 
391              				 AsyncRequest *request) 
392              	 throw(Permission, IPCException);
393                    
394                    // send a message to another module via another service
395                    AsyncReply *ClientSendWait(const client_handle & handle,
396              				 Uint32 destination_q,
397              				 String & destination_module,
398              				 AsyncRequest *message) 
399              	 throw(Permission, Deadlock, IPCException);
400              
401                    // send an async message to another service
402                    Boolean ClientSendAsync(const client_handle & handle,
403              			      Uint32 msg_handle, 
404              			      Uint32 destination_q, 
405              			      AsyncRequest *message,
406              			      void (*async_callback)(Uint32, Message *, void *) ,
407 mday    1.19 			      void *callback_parm)
408              	 throw(Permission, IPCException);
409              
410                    // send an async message to another module via another service
411                    Boolean ClientSendAsync(const client_handle & handle,
412              			      Uint32 msg_handle, 
413              			      Uint32 destination_q, 
414 mday    1.26 			      const String & destination_module,
415 mday    1.19 			      AsyncRequest *message, 
416              			      void (*async_callback)(Uint32, Message *, void *),
417              			      void *callback_parm )
418              	 throw(Permission, IPCException);
419              
420 mday    1.22       Boolean ClientSendForget(const client_handle & handle, 
421              			       Uint32 destination_q, 
422              			       AsyncRequest *message)
423              	 throw(Permission, IPCException);
424              
425                    Boolean ClientSendForget(const client_handle & handle, 
426              			       Uint32 destination_q, 
427 mday    1.27 			       const String & destination_module, 
428 mday    1.22 			       AsyncRequest *message)
429              	 throw(Permission, IPCException);
430              
431 mday    1.19       void client_blocking_thread_exec(const client_handle & handle,
432              				       PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
433              				       void *parm) 
434              	 throw(Permission, Deadlock, IPCException);
435                    void client_async_thread_exec(const client_handle & handle, 
436              				    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
437              				    void *parm) 
438              	 throw(Permission, Deadlock, IPCException);
439                    
440 mday    1.1     protected:
441 kumpf   1.8        // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
442                    virtual void handleEnqueue(void) {}
443                    virtual void handleEnqueue(Message *) {}
444 mday    1.9        virtual void _handle_async_request(AsyncRequest *rq);
445                    virtual void _handle_async_callback(AsyncOpNode *op);
446 mday    1.1  
447                 private:
448 mday    1.35 
449              
450                    class _module_lock 
451                    {
452              	 public:
453              	    _module_lock(DQueue<pegasus_module> * list)
454              	       :_list(list)
455              	    {
456              	       _list->lock();
457              	       
458              	    }
459              	    ~_module_lock(void)
460              	    {
461              	       _list->unlock();
462              	    }
463              	    
464              	    
465              	 private:
466              	    _module_lock();
467              	    DQueue<pegasus_module> * _list;
468                    };
469 mday    1.35       
470                    
471              
472 mday    1.7        static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
473 mday    1.2        DQueue<pegasus_module> _modules;
474 mday    1.19       pegasus_module _internal_module;
475                    AsyncReply *_send_wait(Uint32, AsyncRequest *);
476 mday    1.22       AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
477                    Boolean _send_forget(Uint32, AsyncRequest *) throw(IPCException);
478                    Boolean _send_forget(Uint32, const String &, AsyncRequest *) throw(IPCException);
479                    
480 mday    1.19       void _blocking_thread_exec(
481              	 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
482              	 void *parm) ;
483                    void _async_thread_exec(
484              	 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
485              	 void *parm) ;
486 mday    1.2  };
487 mday    1.35 
488              
489 mday    1.1  
490              
491 mday    1.4  
492              
493              
494              
495              
496 mday    1.1  PEGASUS_NAMESPACE_END
497              
498              
499 mday    1.4  #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2