(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            class PEGASUS_COMMON_LINKAGE pegasus_module
 50            {
 51               private: 
 52 mday  1.5        class PEGASUS_COMMON_LINKAGE module_rep 
 53                  {
 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            	    module_rep& operator= (const module_rep & );
 91 mday  1.9  	    
 92 mday  1.5  	    Mutex _thread_safety;
 93            	    ModuleController *_controller;
 94            	    String _name;
 95            	    AtomicInt _reference_count;
 96 mday  1.9  	    AtomicInt _shutting_down;
 97 mday  1.6  	    
 98 mday  1.5  	    void *_module_address;
 99 mday  1.10 	    Message * (*_receive_message)(Message *, void *);
100            	    void (*_async_callback)(Uint32, Message *, void *);
101            	    void (*_shutdown_notify)(Uint32 code, void *);
102 mday  1.5  
103 mday  1.10 	    static Message * default_receive_message(Message *msg, void *inst)
104 mday  1.9  	    { throw NotImplemented("Module Receive");}
105 mday  1.5  
106 mday  1.10 	    static void default_async_callback(Uint32 handle, Message *msg, void *inst)
107 mday  1.9  	    { throw NotImplemented("Module Async Receive"); }
108 mday  1.5  	    
109 mday  1.10 	    static void default_shutdown_notify(Uint32 code, void *inst)
110 mday  1.9  	    { return; }
111            
112 mday  1.10 	    static Message * closed_receive_message(Message *msg, void *inst)
113 mday  1.9  	    { throw ModuleClosed();}
114            
115 mday  1.10 	    static void closed_async_callback(Uint32 handle, Message *msg, void *inst)
116 mday  1.9  	    { throw ModuleClosed(); }
117 mday  1.5  
118            	    friend class ModuleController;
119                  };
120 mday  1.7  
121 mday  1.1     public:
122            
123 mday  1.3        pegasus_module(ModuleController *controller, 
124            		     const String &id, 
125            		     void *module_address,
126 mday  1.10 		     Message * (*receive_message)(Message *, void *),
127            		     void (*async_callback)(Uint32, Message *, void *),
128            		     void (*shutdown_notify)(Uint32 code, void *)) ;
129 mday  1.5        
130 mday  1.9        ~pegasus_module(void);
131 mday  1.3        
132 mday  1.4        pegasus_module & operator= (const pegasus_module & mod);
133                  Boolean operator == (const pegasus_module *mod) const;
134                  Boolean operator == (const pegasus_module & mod) const ; 
135                  Boolean operator == (const String &  mod) const;
136                  Boolean operator == (const void *mod) const;
137            
138 mday  1.5        const String & get_name(void) const;
139 mday  1.3              
140 mday  1.2        // introspection interface
141 mday  1.5        Boolean query_interface(const String & class_id, void **object_ptr) const;
142 mday  1.1  
143               private:
144 mday  1.3  
145                  module_rep *_rep;
146                  pegasus_module(void);
147 mday  1.5        pegasus_module(const pegasus_module & mod);
148 mday  1.6        Boolean _rcv_msg(Message *) ;
149 mday  1.9        Message * _receive_message(Message *msg);
150                  void _send_async_callback(Uint32 msg_handle, Message *msg) ;
151                  void _send_shutdown_notify(void);
152                  Boolean _shutdown(void);
153 mday  1.6        
154                  void reference(void) { _rep->reference(); }
155                  void dereference(void)  { _rep->dereference(); }
156 mday  1.5        friend class ModuleController;
157            };
158 mday  1.4  
159            
160 mday  1.1  class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
161            {
162            
163 mday  1.11 
164 mday  1.1     public:
165 mday  1.5        typedef MessageQueueService Base;
166 mday  1.1        
167 mday  1.14       static const Uint32 GET_CLIENT_HANDLE;
168                  static const Uint32 REGISTER_MODULE;
169                  static const Uint32 DEREGISTER_MODULE;
170                  static const Uint32 FIND_SERVICE;
171                  static const Uint32 FIND_MODULE_IN_SERVICE;
172                  static const Uint32 GET_MODULE_REFERENCE;
173                  static const Uint32 MODULE_SEND_WAIT;
174                  static const Uint32 MODULE_SEND_WAIT_MODULE;
175                  static const Uint32 MODULE_SEND_ASYNC;
176                  static const Uint32 MODULE_SEND_ASYNC_MODULE;
177                  static const Uint32 BLOCKING_THREAD_EXEC;
178                  static const Uint32 ASYNC_THREAD_EXEC;
179                  static const Uint32 CLIENT_SEND_WAIT;
180                  static const Uint32 CLIENT_SEND_WAIT_MODULE;
181                  static const Uint32 CLIENT_SEND_ASYNC;
182                  static const Uint32 CLIENT_SEND_ASYNC_MODULE;
183            
184 mday  1.11    private: 
185 mday  1.14       class PEGASUS_COMMON_LINKAGE client_handle : pegasus_authorization_handle
186 mday  1.11       {
187            	 public:
188 mday  1.14 	    typedef pegasus_authorization_handle Base;
189            	    
190            	    client_handle(pegasus_base_identity & id)
191            	       :Base(id)
192 mday  1.11 	    {
193            	    }
194 mday  1.14 	    ~client_handle(void);
195            	    virtual Boolean authorized(Uint32 operation);
196            	    virtual Boolean authorized(void);
197 mday  1.11 	    
198            	 private:
199 mday  1.14 	    bitset<32> allowed_operations;
200 mday  1.11       };
201                  
202               public:
203                  
204            
205 mday  1.6        ModuleController(const char *name);
206                  ModuleController(const char *name, 
207            		       Sint16 min_threads, 
208            		       Sint16 max_threads,
209            		       struct timeval & create_thread,
210            		       struct timeval & destroy_thread,
211            		       struct timeval & deadlock);
212                  
213            
214 mday  1.7        ~ModuleController(void);
215 mday  1.1  
216 mday  1.11       static ModuleController & get_client_handle(const String & controller_name, 
217            						  void **handle);
218                  
219            
220 mday  1.1        // module api 
221 mday  1.9        static ModuleController & register_module(const String & controller_name,
222            						const String & module_name, 
223            						void *module_address, 
224 mday  1.10 						Message * (*receive_message)(Message *, void *),
225            						void (*async_callback)(Uint32, Message *, void *),
226            						void (*shutdown_notify)(Uint32, void *), 
227            						pegasus_module **instance = NULL) 
228 mday  1.9  	 throw(AlreadyExists, IncompatibleTypes);
229 mday  1.3  
230 mday  1.11       Boolean deregister_module(const String & module_name)
231            	 throw(Permission);
232 mday  1.2        
233 mday  1.7        Uint32 find_service(pegasus_module & handle, const String & name) throw(Permission);
234 mday  1.2  
235 mday  1.7        Uint32 find_module_in_service(pegasus_module & handle, 
236            				    const String & module_name) 
237            	 throw(Permission, IPCException);
238            				    
239            
240                  pegasus_module * get_module_reference(pegasus_module & my_handle, 
241            					    const String & module_name)
242            	 throw(Permission);
243 mday  1.1        
244 mday  1.2        // send a message to another service
245 mday  1.7        AsyncReply *ModuleSendWait(pegasus_module & handle,
246 mday  1.2  			      Uint32 destination_q, 
247 mday  1.7  			      AsyncRequest *request) throw(Permission, IPCException);
248 mday  1.1  
249 mday  1.2        // send a message to another module via another service
250 mday  1.7        AsyncReply *ModuleSendWait(pegasus_module & handle,
251 mday  1.2  			      Uint32 destination_q,
252            			      String & destination_module,
253 mday  1.7  			      AsyncRequest *message) throw(Permission, Deadlock, IPCException);
254 mday  1.2  
255 mday  1.11       // send an async message to another service
256 mday  1.2        Boolean ModuleSendAsync(pegasus_module & handle,
257 mday  1.1  			      Uint32 msg_handle, 
258 mday  1.2  			      Uint32 destination_q, 
259 mday  1.9  			      AsyncRequest *message) throw(Permission, IPCException);
260 mday  1.1  
261 mday  1.11       // send an async message to another module via another service
262 mday  1.2        Boolean ModuleSendAsync(pegasus_module & handle,
263 mday  1.1  			      Uint32 msg_handle, 
264 mday  1.2  			      Uint32 destination_q, 
265            			      String & destination_module,
266 mday  1.9  			      AsyncRequest *message) throw(Permission, IPCException);
267 mday  1.1  
268 mday  1.7        void blocking_thread_exec(pegasus_module & handle,
269            				PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
270            				void *parm) throw(Permission, Deadlock, IPCException);
271                  void async_thread_exec(pegasus_module & handle, 
272            			     PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
273            			     void *parm) throw(Permission, Deadlock, IPCException);
274 mday  1.14 
275 mday  1.7        Boolean verify_handle(pegasus_module *);
276 mday  1.1     protected:
277 kumpf 1.8        // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
278                  virtual void handleEnqueue(void) {}
279                  virtual void handleEnqueue(Message *) {}
280 mday  1.9        virtual void _handle_async_request(AsyncRequest *rq);
281                  virtual void _handle_async_callback(AsyncOpNode *op);
282 mday  1.1  
283               private:
284 mday  1.7        static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
285 mday  1.2        DQueue<pegasus_module> _modules;
286 mday  1.1        ThreadPool _thread_pool;
287 mday  1.2  };
288 mday  1.1  
289            
290 mday  1.4  
291            
292            
293            
294            
295 mday  1.1  PEGASUS_NAMESPACE_END
296            
297            
298 mday  1.4  #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2