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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2