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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2