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

  1 mday  1.1 //%////-*-c++-*-////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a copy
  6           // of this software and associated documentation files (the "Software"), to
  7           // deal in the Software without restriction, including without limitation the
  8           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9           // sell copies of the Software, and to permit persons to whom the Software is
 10           // furnished to do so, subject to the following conditions:
 11           //
 12           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 13           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 16           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 17           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 18           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20           //
 21           //==============================================================================
 22 mday  1.1 //
 23           // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>
 24           //
 25           // Modified By:
 26           //
 27           //%/////////////////////////////////////////////////////////////////////////////
 28           
 29           #ifndef Pegasus_Module_Controller_h
 30           #define Pegasus_Module_Controller_h
 31           
 32           #include <Pegasus/Common/Config.h>
 33           #include <Pegasus/Common/Message.h>
 34           #include <Pegasus/Common/Exception.h>
 35           #include <Pegasus/Common/IPC.h>
 36           #include <Pegasus/Common/Thread.h>
 37           #include <Pegasus/Common/AsyncOpNode.h>
 38           #include <Pegasus/Common/Cimom.h>
 39           #include <Pegasus/Common/CimomMessage.h>
 40           #include <Pegasus/Common/MessageQueueService.h>
 41 mday  1.14 #include <Pegasus/Common/peg_authorization.h>
 42 mday  1.11 
 43            
 44 mday  1.1  PEGASUS_NAMESPACE_BEGIN
 45            
 46            class ModuleController;
 47            
 48 mday  1.9  
 49 mday  1.16 class PEGASUS_COMMON_LINKAGE pegasus_module : pegasus_authorization_handle
 50 mday  1.9  {
 51               private: 
 52 mday  1.16       class module_rep 
 53 mday  1.5        {
 54            	 public:
 55            	    module_rep(ModuleController *controller, 
 56            		       const String & name,
 57            		       void *module_address, 
 58 mday  1.10 		       Message * (*receive_message)(Message *, void *),
 59            		       void (*async_callback)(Uint32, Message *, void *),
 60            		       void (*shutdown_notify)(Uint32 code, void *));
 61 mday  1.5        
 62 mday  1.9  	    ~module_rep(void) ;
 63            	    
 64 mday  1.5        
 65            	    Boolean operator == (const module_rep *rep) const
 66 mday  1.9  	    { if (rep == this ) return true; return false; }
 67 mday  1.5        
 68            	    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 == (void *rep) const 
 72 mday  1.9  	    { if ( (void *)this == rep ) return true; return false; }
 73 mday  1.5        
 74            	    void reference(void) { _reference_count++; } 
 75            	    void dereference(void) { _reference_count--; } 
 76            	    Uint32 reference_count(void)  { return _reference_count.value(); }  
 77            	    const String & get_name(void) const { return _name; }
 78            	    void *get_module_address(void) const { return _module_address; }
 79 mday  1.9  
 80            	    Message * module_receive_message(Message *msg);
 81 mday  1.5  	    
 82 mday  1.9  	    void _send_async_callback(Uint32 msg_handle, Message *msg);
 83 mday  1.5  	    
 84 mday  1.9  	    void _send_shutdown_notify(void);
 85            	    void lock(void) { _thread_safety.lock(pegasus_thread_self()); }
 86            	    void unlock(void) { _thread_safety.unlock(); }
 87            	 private:
 88 mday  1.5  	    module_rep(void);
 89            	    module_rep(const module_rep & );
 90 mday  1.16 	    module_rep& operator= (const module_rep & rep)
 91            	    {
 92            	       if( this != &rep )
 93            	       {
 94            		  _reference_count++;
 95            	       }
 96            	       return *this;
 97            	    }
 98 mday  1.9  	    
 99 mday  1.16 	    module_rep *operator=(const module_rep *rep)
100            	    {
101            	       if( this != rep)
102            	       {
103            		  _reference_count++;
104            	       }
105            	       return this;
106            	    }
107            	    
108            	    	    
109 mday  1.5  	    Mutex _thread_safety;
110            	    ModuleController *_controller;
111            	    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 mday  1.9  	    { throw NotImplemented("Module Receive");}
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 mday  1.9  	    { throw ModuleClosed();}
131            
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.16       typedef pegasus_authorization_handle Base;
140                  
141 mday  1.3        pegasus_module(ModuleController *controller, 
142            		     const String &id, 
143            		     void *module_address,
144 mday  1.10 		     Message * (*receive_message)(Message *, void *),
145            		     void (*async_callback)(Uint32, Message *, void *),
146            		     void (*shutdown_notify)(Uint32 code, void *)) ;
147 mday  1.5        
148 mday  1.9        ~pegasus_module(void);
149 mday  1.3        
150 mday  1.16       virtual Boolean authorized(Uint32 operation);
151                  virtual Boolean authorized(void);
152                  
153 mday  1.4        pegasus_module & operator= (const pegasus_module & mod);
154 mday  1.16       pegasus_module * operator= (const pegasus_module * mod);
155                  
156 mday  1.4        Boolean operator == (const pegasus_module *mod) const;
157                  Boolean operator == (const pegasus_module & mod) const ; 
158                  Boolean operator == (const String &  mod) const;
159                  Boolean operator == (const void *mod) const;
160            
161 mday  1.5        const String & get_name(void) const;
162 mday  1.3              
163 mday  1.2        // introspection interface
164 mday  1.5        Boolean query_interface(const String & class_id, void **object_ptr) const;
165 mday  1.16             
166 mday  1.1  
167               private:
168 mday  1.3  
169                  module_rep *_rep;
170                  pegasus_module(void);
171 mday  1.5        pegasus_module(const pegasus_module & mod);
172 mday  1.6        Boolean _rcv_msg(Message *) ;
173 mday  1.9        Message * _receive_message(Message *msg);
174                  void _send_async_callback(Uint32 msg_handle, Message *msg) ;
175                  void _send_shutdown_notify(void);
176                  Boolean _shutdown(void);
177 mday  1.16       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                  
211 mday  1.14 
212 mday  1.11    private: 
213 mday  1.16       class client_handle : pegasus_authorization_handle
214 mday  1.11       {
215            	 public:
216 mday  1.14 	    typedef pegasus_authorization_handle Base;
217            	    
218 mday  1.16 	    client_handle(void)
219            	       :Base(new pegasus_internal_identity(peg_credential_types::SERVICE)),
220            		allowed_operations( GET_CLIENT_HANDLE | 
221            				    FIND_SERVICE | 
222            				    FIND_MODULE_IN_SERVICE | 
223            				    GET_MODULE_REFERENCE | 
224            				    CLIENT_SEND_WAIT | 
225            				    CLIENT_SEND_WAIT_MODULE | 
226            				    CLIENT_SEND_ASYNC | 
227            				    CLIENT_SEND_ASYNC_MODULE | 
228            				    CLIENT_BLOCKING_THREAD_EXEC | 
229            				    CLIENT_ASYNC_THREAD_EXEC) 
230            	    {
231            
232            	    }
233            	    
234            	    client_handle(pegasus_base_identity *id)
235 mday  1.14 	       :Base(id)
236 mday  1.11 	    {
237 mday  1.16 	       if( id && (id->get_base_id_type() == peg_identity_types::INTERNAL ))
238            	       {
239            		  if (id->get_base_cred_type() == peg_credential_types::SERVICE )
240            		     allowed_operations = ModuleController::CLIENT_SEND_WAIT | 
241            					  ModuleController::CLIENT_SEND_WAIT_MODULE | 
242            					  ModuleController::CLIENT_SEND_ASYNC | 
243            					  ModuleController::CLIENT_SEND_ASYNC_MODULE | 
244            					  ModuleController::CLIENT_BLOCKING_THREAD_EXEC | 
245            					  ModuleController::CLIENT_ASYNC_THREAD_EXEC;
246            		  else 
247            		     allowed_operations = 0;
248            	       }
249            	       
250 mday  1.11 	    }
251 mday  1.14 	    ~client_handle(void);
252            	    virtual Boolean authorized(Uint32 operation);
253            	    virtual Boolean authorized(void);
254 mday  1.11 	    
255            	 private:
256 mday  1.16 	    bitset<64> allowed_operations;
257 mday  1.11       };
258                  
259               public:
260                  
261            
262 mday  1.6        ModuleController(const char *name);
263                  ModuleController(const char *name, 
264            		       Sint16 min_threads, 
265            		       Sint16 max_threads,
266            		       struct timeval & create_thread,
267            		       struct timeval & destroy_thread,
268            		       struct timeval & deadlock);
269                  
270            
271 mday  1.7        ~ModuleController(void);
272 mday  1.1  
273 mday  1.11       static ModuleController & get_client_handle(const String & controller_name, 
274            						  void **handle);
275                  
276            
277 mday  1.1        // module api 
278 mday  1.9        static ModuleController & register_module(const String & controller_name,
279            						const String & module_name, 
280            						void *module_address, 
281 mday  1.10 						Message * (*receive_message)(Message *, void *),
282            						void (*async_callback)(Uint32, Message *, void *),
283            						void (*shutdown_notify)(Uint32, void *), 
284            						pegasus_module **instance = NULL) 
285 mday  1.9  	 throw(AlreadyExists, IncompatibleTypes);
286 mday  1.3  
287 mday  1.11       Boolean deregister_module(const String & module_name)
288            	 throw(Permission);
289 mday  1.2        
290 mday  1.7        Uint32 find_service(pegasus_module & handle, const String & name) throw(Permission);
291 mday  1.2  
292 mday  1.7        Uint32 find_module_in_service(pegasus_module & handle, 
293            				    const String & module_name) 
294            	 throw(Permission, IPCException);
295            				    
296            
297                  pegasus_module * get_module_reference(pegasus_module & my_handle, 
298            					    const String & module_name)
299            	 throw(Permission);
300 mday  1.1        
301 mday  1.2        // send a message to another service
302 mday  1.7        AsyncReply *ModuleSendWait(pegasus_module & handle,
303 mday  1.2  			      Uint32 destination_q, 
304 mday  1.7  			      AsyncRequest *request) throw(Permission, IPCException);
305 mday  1.1  
306 mday  1.2        // send a message to another module via another service
307 mday  1.7        AsyncReply *ModuleSendWait(pegasus_module & handle,
308 mday  1.2  			      Uint32 destination_q,
309            			      String & destination_module,
310 mday  1.7  			      AsyncRequest *message) throw(Permission, Deadlock, IPCException);
311 mday  1.2  
312 mday  1.11       // send an async message to another service
313 mday  1.2        Boolean ModuleSendAsync(pegasus_module & handle,
314 mday  1.1  			      Uint32 msg_handle, 
315 mday  1.2  			      Uint32 destination_q, 
316 mday  1.9  			      AsyncRequest *message) throw(Permission, IPCException);
317 mday  1.1  
318 mday  1.11       // send an async message to another module via another service
319 mday  1.2        Boolean ModuleSendAsync(pegasus_module & handle,
320 mday  1.1  			      Uint32 msg_handle, 
321 mday  1.2  			      Uint32 destination_q, 
322            			      String & destination_module,
323 mday  1.9  			      AsyncRequest *message) throw(Permission, IPCException);
324 mday  1.1  
325 mday  1.7        void blocking_thread_exec(pegasus_module & handle,
326            				PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
327            				void *parm) throw(Permission, Deadlock, IPCException);
328                  void async_thread_exec(pegasus_module & handle, 
329            			     PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
330            			     void *parm) throw(Permission, Deadlock, IPCException);
331 mday  1.14 
332 mday  1.7        Boolean verify_handle(pegasus_module *);
333 mday  1.1     protected:
334 kumpf 1.8        // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
335                  virtual void handleEnqueue(void) {}
336                  virtual void handleEnqueue(Message *) {}
337 mday  1.9        virtual void _handle_async_request(AsyncRequest *rq);
338                  virtual void _handle_async_callback(AsyncOpNode *op);
339 mday  1.1  
340               private:
341 mday  1.7        static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
342 mday  1.2        DQueue<pegasus_module> _modules;
343 mday  1.1        ThreadPool _thread_pool;
344 mday  1.2  };
345 mday  1.1  
346            
347 mday  1.4  
348            
349            
350            
351            
352 mday  1.1  PEGASUS_NAMESPACE_END
353            
354            
355 mday  1.4  #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2