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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2