(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           PEGASUS_NAMESPACE_BEGIN
 42           
 43 mday  1.1 class ModuleController;
 44           
 45           
 46 mday  1.5 
 47 mday  1.2 class PEGASUS_COMMON_LINKAGE pegasus_module
 48 mday  1.1 {
 49 mday  1.5       class PEGASUS_COMMON_LINKAGE module_rep 
 50                 {
 51           	 public:
 52           	    module_rep(ModuleController *controller, 
 53           		       const String & name,
 54           		       void *module_address, 
 55           		       Boolean (*receive_message)(Message *),
 56           		       void (*async_callback)(Uint32, Message *),
 57           		       void (*shutdown_notify)(Uint32 code))
 58           	       : _thread_safety(),
 59           		 _controller(controller), 
 60           		 _name(name), 
 61           		 _reference_count(1), 
 62           		 _module_address(module_address)
 63           
 64           	    {
 65           	       if(receive_message != NULL)
 66           		  _receive_message = receive_message;
 67           	       else
 68           		  _receive_message = default_receive_message;
 69           	       if(async_callback != NULL)
 70 mday  1.5 		  _async_callback = async_callback;
 71           	       else
 72           		  _async_callback = default_async_callback;
 73           	       if(shutdown_notify != NULL)
 74           		  _shutdown_notify = shutdown_notify;
 75           	       else
 76           		  _shutdown_notify = default_shutdown_notify;
 77           	    }
 78                 
 79           	    virtual ~module_rep(void) 
 80           	    {
 81           
 82           	    }
 83                 
 84           
 85           	    Boolean operator == (const module_rep *rep) const
 86           	    {
 87           	       if (rep == this )
 88           		  return true;
 89           	       return false;
 90           	    }
 91 mday  1.5       
 92           	    Boolean operator == (const module_rep &rep) const
 93           	    {
 94           	       if (rep == *this)
 95           		  return true;
 96           	       return false;
 97           	    }
 98                 
 99           	    Boolean operator == (void *rep) const 
100           	    {
101           	       if ( (void *)this == rep )
102           		  return true;
103           	       return false;
104           	    }
105                 
106           	    void reference(void) { _reference_count++; } 
107           	    void dereference(void) { _reference_count--; } 
108           	    Uint32 reference_count(void)  { return _reference_count.value(); }  
109           	    const String & get_name(void) const { return _name; }
110           	    void *get_module_address(void) const { return _module_address; }
111           	    Boolean module_receive_message(Message *msg)
112 mday  1.5 	    {
113           
114           	       _thread_safety.lock(pegasus_thread_self());
115           	       try {  _receive_message(msg); }
116           	       catch(...) { _thread_safety.unlock(); throw; }
117           	       _thread_safety.unlock();
118           	    }
119           	    
120           	    void _send_async_callback(Uint32 msg_handle, Message *msg)
121           	    {
122           	       _thread_safety.lock(pegasus_thread_self());
123           	       try  { _async_callback(msg_handle, msg); }
124           	       catch(...) { _thread_safety.unlock(); throw; }
125           	       
126           	    }
127           	    void _send_shutdown_notify(Uint32 code)
128           	    {
129           	       _shutdown_notify(code);
130           	    }
131           	    void lock(void) 
132           	    {
133 mday  1.5 	       _thread_safety.lock(pegasus_thread_self());
134           	    }
135           	    
136           	    void unlock(void)
137           	    {
138           	       _thread_safety.unlock();
139           	    }
140           	    
141           	 private: 
142           	    module_rep(void);
143           	    module_rep(const module_rep & );
144           	    module_rep& operator= (const module_rep & );
145                 
146           	    Mutex _thread_safety;
147           	    ModuleController *_controller;
148           	    String _name;
149           	    AtomicInt _reference_count;
150           	    void *_module_address;
151           	    Boolean (*_receive_message)(Message *);
152           	    void (*_async_callback)(Uint32, Message *);
153           	    void (*_shutdown_notify)(Uint32 code);
154 mday  1.5 
155           	    static Boolean default_receive_message(Message *msg)
156           	    {
157           	       throw NotImplemented("Module Receive");
158           	    }
159           
160           	    static void default_async_callback(Uint32 handle, Message *msg)
161           	    {
162           	       throw NotImplemented("Module Async Receive");
163           	    }
164           	    
165           	    static void default_shutdown_notify(Uint32 code)
166           	    {
167           	       return;
168           	    }
169           
170           	    friend class ModuleController;
171                 };
172 mday  1.3       
173 mday  1.1    public:
174           
175 mday  1.3       pegasus_module(ModuleController *controller, 
176           		     const String &id, 
177           		     void *module_address,
178 mday  1.5 		     Boolean (*receive_message)(Message *),
179           		     void (*async_callback)(Uint32, Message *),
180           		     void (*shutdown_notify)(Uint32 code)) ;
181                 
182                 virtual ~pegasus_module(void)
183                 {
184           	 _rep->dereference();
185           	 if( 0 == _rep->reference_count())
186           	    delete _rep;
187                 }
188 mday  1.3       
189 mday  1.4       pegasus_module & operator= (const pegasus_module & mod);
190                 Boolean operator == (const pegasus_module *mod) const;
191                 Boolean operator == (const pegasus_module & mod) const ; 
192                 Boolean operator == (const String &  mod) const;
193                 Boolean operator == (const void *mod) const;
194           
195 mday  1.5       const String & get_name(void) const;
196 mday  1.3             
197 mday  1.2       // introspection interface
198 mday  1.5       Boolean query_interface(const String & class_id, void **object_ptr) const;
199 mday  1.1 
200              private:
201 mday  1.3 
202                 module_rep *_rep;
203                 
204                 pegasus_module(void);
205 mday  1.5       pegasus_module(const pegasus_module & mod);
206                 virtual Boolean _rcv_msg(Message *) ;
207                 Boolean _receive_message(Message *msg)
208 mday  1.3       {
209 mday  1.5 	 _rep->module_receive_message(msg);
210 mday  1.3       }
211                 
212 mday  1.5       void _send_async_callback(Uint32 msg_handle, Message *msg) 
213 mday  1.3       {
214 mday  1.5 	 _rep->_send_async_callback(msg_handle, msg);
215 mday  1.3       }
216 mday  1.5       void _send_shutdown_notify(Uint32 code)
217 mday  1.3       {
218 mday  1.5 	 _rep->_send_shutdown_notify(code);
219 mday  1.3       }
220                 
221 mday  1.5       virtual Boolean _shutdown(Uint32) ;
222                 virtual void reference(void) { _rep->reference(); }
223                 virtual void dereference(void)  { _rep->dereference(); }
224 mday  1.3 
225 mday  1.5       friend class ModuleController;
226           };
227 mday  1.4 
228           
229 mday  1.1 
230           
231           class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
232           {
233           
234              public:
235 mday  1.5       typedef MessageQueueService Base;
236 mday  1.1       
237                 ModuleController(const char *name, Uint32 queueID);
238 mday  1.3       virtual ~ModuleController(void);
239 mday  1.1 
240                 // module api 
241 mday  1.3       ModuleController & register_module(const String & module_name, 
242           					 void *module_address, 
243           					 void (*async_callback)(Uint32, Message *));
244           
245 mday  1.5       Boolean deregister_module(const String & module_name);
246 mday  1.2       
247                 Uint32 find_service(pegasus_module & handle, String & name);
248                 String & find_service(pegasus_module & handle, Uint32 queue_id);
249           
250                 pegasus_module & get_module_reference(pegasus_module & handle, String & name);
251 mday  1.1       
252 mday  1.2       // send a message to another service
253                 Message *ModuleSendWait(pegasus_module & handle,
254           			      Uint32 destination_q, 
255 mday  1.1 			      Message *message);
256           
257 mday  1.2       // send a message to another module via another service
258                 Message *ModuleSendWait(pegasus_module & handle,
259           			      Uint32 destination_q,
260           			      String & destination_module,
261 mday  1.1 			      Message *message);
262 mday  1.2 
263                 // send a message to another service
264                 Boolean ModuleSendAsync(pegasus_module & handle,
265 mday  1.1 			      Uint32 msg_handle, 
266 mday  1.2 			      Uint32 destination_q, 
267 mday  1.1 			      Message *message);
268           
269 mday  1.2       // send a message to another module via another service
270                 Boolean ModuleSendAsync(pegasus_module & handle,
271 mday  1.1 			      Uint32 msg_handle, 
272 mday  1.2 			      Uint32 destination_q, 
273           			      String & destination_module,
274 mday  1.1 			      Message *message);
275           
276 mday  1.2       Uint32 blocking_thread_exec(pegasus_module & handle,
277           				  PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
278           				  void *parm);
279                 Uint32 async_thread_exec(pegasus_module & handle, 
280           			       PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *), 
281           			       void *parm);
282                 
283 mday  1.1    protected:
284           
285              private:
286           
287 mday  1.2       DQueue<pegasus_module> _modules;
288 mday  1.1       ThreadPool _thread_pool;
289 mday  1.2 };
290 mday  1.1 
291           
292 mday  1.4 
293           
294           
295           
296           
297 mday  1.1 PEGASUS_NAMESPACE_END
298           
299           
300 mday  1.4 #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2