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

  1 karl  1.44 //%2006////////////////////////////////////////////////////////////////////////
  2 mday  1.1  //
  3 karl  1.38 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.36 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.38 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.39 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.44 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mday  1.1  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 karl  1.44 // 
 21 mday  1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>
 33            //
 34 a.arora 1.37 // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
 35 david.dillard 1.42 //              David Dillard, VERITAS Software Corp.
 36                    //                  (david.dillard@veritas.com)
 37 mday          1.1  //
 38                    //%/////////////////////////////////////////////////////////////////////////////
 39                    
 40                    #ifndef Pegasus_Module_Controller_h
 41                    #define Pegasus_Module_Controller_h
 42                    
 43                    #include <Pegasus/Common/Config.h>
 44 mday          1.19 #include <Pegasus/Common/Constants.h>
 45 mday          1.1  #include <Pegasus/Common/Message.h>
 46 kumpf         1.33 #include <Pegasus/Common/InternalException.h>
 47 mday          1.1  #include <Pegasus/Common/IPC.h>
 48                    #include <Pegasus/Common/Thread.h>
 49                    #include <Pegasus/Common/AsyncOpNode.h>
 50                    #include <Pegasus/Common/Cimom.h>
 51                    #include <Pegasus/Common/CimomMessage.h>
 52                    #include <Pegasus/Common/MessageQueueService.h>
 53 kumpf         1.32 #include <Pegasus/Common/Linkage.h>
 54 david.dillard 1.42 #include <Pegasus/Common/AutoPtr.h>
 55 mike          1.45 #include <Pegasus/Common/List.h>
 56 mday          1.11 
 57                    
 58 mday          1.1  PEGASUS_NAMESPACE_BEGIN
 59                    
 60                    class ModuleController;
 61                    
 62 mday          1.9  
 63 mike          1.45 class PEGASUS_COMMON_LINKAGE pegasus_module : public Linkable
 64 mday          1.9  {
 65 david.dillard 1.42 private:
 66 kumpf         1.47     class module_rep
 67 david.dillard 1.42     {
 68                        public:
 69                            module_rep(ModuleController *controller,
 70                                   const String & name,
 71                                   void *module_address,
 72                                   Message * (*receive_message)(Message *, void *),
 73                                   void (*async_callback)(Uint32, Message *, void *),
 74                                   void (*shutdown_notify)(Uint32 code, void *));
 75                    
 76                            ~module_rep();
 77                    
 78                            void reference()
 79                            {
 80                                _reference_count++;
 81                            }
 82                    
 83                            void dereference()
 84                            {
 85                                _reference_count--;
 86                            }
 87                    
 88 david.dillard 1.42         Uint32 reference_count() const
 89                            {
 90 mike          1.43             return _reference_count.get();
 91 david.dillard 1.42         }
 92                    
 93                            const String& get_name() const throw()
 94                            {
 95                                return _name;
 96                            }
 97                    
 98                            void *get_module_address() const
 99                            {
100                                return _module_address;
101                            }
102                    
103                            Message * module_receive_message(Message *msg);
104                    
105                            void _send_async_callback(Uint32 msg_handle, Message *msg, void *parm);
106                    
107                            void _send_shutdown_notify();
108                    
109                            void lock()
110                            {
111                                _thread_safety.lock(pegasus_thread_self());
112 david.dillard 1.42         }
113                    
114                            void unlock()
115                            {
116                                _thread_safety.unlock();
117                            }
118                    
119                        private:
120                            module_rep();
121                            module_rep(const module_rep&);
122                            module_rep & operator=(const module_rep & rep);
123                    
124                            Mutex _thread_safety;
125                            // Don't make this an AutoPtr. Refer to bug 3502
126                            ModuleController* _controller;
127                            String _name;
128                            AtomicInt _reference_count;
129                            AtomicInt _shutting_down;
130                    
131                            void *_module_address;
132                            Message * (*_receive_message)(Message *, void *);
133 david.dillard 1.42         void (*_async_callback)(Uint32, Message *, void *);
134                            void (*_shutdown_notify)(Uint32 code, void *);
135                    
136                            static Message * default_receive_message(Message *msg, void *inst)
137                            {
138                                throw NotImplemented("Module Receive");
139                                return 0;
140                            }
141                    
142                            static void default_async_callback(Uint32 handle, Message *msg, void *inst)
143                            {
144                                throw NotImplemented("Module Async Receive");
145                            }
146                    
147                            static void default_shutdown_notify(Uint32 code, void *inst)
148                            {
149                                // Intentionally left blank
150                            }
151                    
152                            static Message * closed_receive_message(Message *msg, void *inst)
153                            {
154 david.dillard 1.42             throw ModuleClosed();
155                                return 0;
156                            }
157                    
158                            static void closed_async_callback(Uint32 handle, Message *msg, void *inst)
159                            {
160                                throw ModuleClosed();
161                            }
162                    
163                            friend class ModuleController;
164                        };
165                    
166                    public:
167                        pegasus_module(ModuleController *controller,
168                                 const String &id,
169                                 void *module_address,
170                                 Message * (*receive_message)(Message *, void *),
171                                 void (*async_callback)(Uint32, Message *, void *),
172                                 void (*shutdown_notify)(Uint32 code, void *));
173                    
174                        pegasus_module(const pegasus_module & mod);
175 david.dillard 1.42     pegasus_module & operator= (const pegasus_module & mod);
176                    
177                        virtual ~pegasus_module();
178                    
179                        Boolean operator == (const String &  mod) const;
180                    
181                        const String & get_name() const;
182                    
183                        // introspection interface
184                        Boolean query_interface(const String & class_id, void **object_ptr) const;
185                    
186                    private:
187                    
188                        AutoPtr<module_rep> _rep;//PEP101
189                    
190                        pegasus_module()
191                        {
192                        }
193                    
194                        Boolean _rcv_msg(Message *);
195                        Message * _receive_message(Message *msg);
196 david.dillard 1.42     void _send_async_callback(Uint32 msg_handle, Message *msg, void *);
197                        void _send_shutdown_notify();
198                        Boolean _shutdown();
199                    
200                        void reference()
201                        {
202                            _rep->reference();
203                        }
204                    
205                        void dereference()
206                        {
207                            _rep->dereference();
208                        }
209                    
210                        friend class ModuleController;
211 mday          1.5  };
212 mday          1.4  
213                    
214 mday          1.1  class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
215                    {
216 david.dillard 1.42 public:
217                        typedef MessageQueueService Base;
218 mday          1.1  
219 david.dillard 1.42     class callback_handle
220                        {
221                        public:
222                            callback_handle(pegasus_module * module, void *parm)
223                               : _module(module), _parm(parm)
224                            {
225                            }
226                    
227                            ~callback_handle()
228                            {
229                                if( _module->get_name() == String(PEGASUS_MODULENAME_TEMP) )
230                                    // delete _module;
231                                    _module.reset();
232                            }
233                    
234                            AutoPtr<pegasus_module> _module;//PEP101
235                            void *_parm;
236                        };
237 mday          1.11 
238 david.dillard 1.42 public:
239                        ModuleController(const char *name);
240 mday          1.30 /*       ModuleController(const char *name,  */
241 david.dillard 1.42 /*             Sint16 min_threads,  */
242                    /*             Sint16 max_threads, */
243                    /*             struct timeval & create_thread, */
244                    /*             struct timeval & destroy_thread); */
245                    
246                        ~ModuleController();
247                    
248                        // module api
249                        // @exception AlreadyExistsException
250                        // @exception IncompatibleTypesException
251                        static ModuleController & register_module(const String & controller_name,
252                                        const String & module_name,
253                                        void *module_address,
254                                        Message * (*receive_message)(Message *, void *),
255                                        void (*async_callback)(Uint32, Message *, void *),
256                                        void (*shutdown_notify)(Uint32, void *),
257                                        pegasus_module **instance = NULL);
258                    
259                        // @exception Permission
260                        Boolean deregister_module(const String & module_name);
261                    
262 david.dillard 1.42     // @exception Permission
263                        Uint32 find_service(const pegasus_module & handle, const String & name);
264                    
265                        // @exception Permission
266                        // @exception IPCException
267                        Uint32 find_module_in_service(const pegasus_module & handle,
268                                        const String & module_name);
269                    
270                        // @exception Permission
271                        pegasus_module * get_module_reference(const pegasus_module & my_handle,
272                                        const String & module_name);
273                    
274                        // send a message to another service
275                        // @exception Permission
276                        // @exception IPCException
277                        AsyncReply *ModuleSendWait(const pegasus_module & handle,
278                                        Uint32 destination_q,
279                                        AsyncRequest *request);
280                    
281                        // send a message to another module via another service
282                        // @exception Permission
283 david.dillard 1.42     // @exception DeadLock
284                        // @exception IPCException
285                        AsyncReply *ModuleSendWait(const pegasus_module & handle,
286                                        Uint32 destination_q,
287                                        const String & destination_module,
288                                        AsyncRequest *message);
289                    
290                        // send an async message to another service
291                        // @exception Permission
292                        // @exception DeadLock
293                        // @exception IPCException
294                        Boolean ModuleSendAsync(const pegasus_module & handle,
295                                        Uint32 msg_handle,
296                                        Uint32 destination_q,
297                                        AsyncRequest *message,
298                                        void *callback_parm);
299                    
300                        // send an async message to another module via another service
301                        // @exception Permission
302                        // @exception IPCException
303                        Boolean ModuleSendAsync(const pegasus_module & handle,
304 david.dillard 1.42                     Uint32 msg_handle,
305                                        Uint32 destination_q,
306                                        const String & destination_module,
307                                        AsyncRequest *message,
308                                        void *callback_parm);
309                    
310                        // @exception Permission
311                        // @exception IPCException
312                        Boolean ModuleSendForget(const pegasus_module & handle,
313                                        Uint32 destination_q,
314                                        AsyncRequest *message);
315                    
316                        // @exception Permission
317                        // @exception IPCException
318                        Boolean ModuleSendForget(const pegasus_module & handle,
319                                        Uint32 destination_q,
320                                        const String & destination_module,
321                                        AsyncRequest *message);
322                    
323                        Boolean verify_handle(pegasus_module *);
324                    
325 kumpf         1.47     static ModuleController* getModuleController();
326 david.dillard 1.42 
327                        // send a message to another service
328                        // @exception Permission
329                        // @exception IPCException
330 kumpf         1.47     AsyncReply *ClientSendWait(
331 david.dillard 1.42                     Uint32 destination_q, AsyncRequest *request);
332                    
333                        // send a message to another module via another service
334                        // @exception Permission
335                        // @exception Deadlock
336                        // @exception IPCException
337 kumpf         1.47     AsyncReply *ClientSendWait(
338 david.dillard 1.42                  Uint32 destination_q,
339                                     String & destination_module,
340                                     AsyncRequest *message);
341                    
342                        // send an async message to another service
343                        // @exception Permission
344                        // @exception IPCException
345 kumpf         1.47     Boolean ClientSendAsync(
346 david.dillard 1.42                 Uint32 msg_handle,
347                                    Uint32 destination_q,
348                                    AsyncRequest *message,
349                                    void (*async_callback)(Uint32, Message *, void *) ,
350                                    void *callback_parm);
351                    
352                        // send an async message to another module via another service
353                        // @exception Permission
354                        // @exception IPCException
355 kumpf         1.47     Boolean ClientSendAsync(
356 david.dillard 1.42                 Uint32 msg_handle,
357                                    Uint32 destination_q,
358                                    const String & destination_module,
359                                    AsyncRequest *message,
360                                    void (*async_callback)(Uint32, Message *, void *),
361                                    void *callback_parm);
362                    
363                        // @exception Permission
364                        // @exception IPCException
365 kumpf         1.47     Boolean ClientSendForget(
366 david.dillard 1.42                 Uint32 destination_q,
367                                    AsyncRequest *message);
368                    
369                        // @exception Permission
370                        // @exception IPCException
371 kumpf         1.47     Boolean ClientSendForget(
372 david.dillard 1.42                 Uint32 destination_q,
373                                    const String & destination_module,
374                                    AsyncRequest *message);
375                    
376                    protected:
377                        // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
378                        virtual void handleEnqueue() {}
379                        virtual void handleEnqueue(Message *) {}
380                        virtual void _handle_async_request(AsyncRequest *rq);
381                        virtual void _handle_async_callback(AsyncOpNode *op);
382                    
383                    private:
384                        class _module_lock
385                        {
386                        public:
387 mike          1.45         _module_lock(List<pegasus_module, RecursiveMutex> * list)
388 david.dillard 1.42            :_list(list)
389                            {
390                               _list->lock();
391                            }
392                    
393                            ~_module_lock()
394                            {
395                               _list->unlock();
396                            }
397                    
398                        private:
399                            _module_lock();
400 mike          1.45         List<pegasus_module, RecursiveMutex> * _list;
401 david.dillard 1.42     };
402                    
403                    
404                    
405                        static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
406 mike          1.45     List<pegasus_module, RecursiveMutex> _modules;
407 david.dillard 1.42     AsyncReply *_send_wait(Uint32, AsyncRequest *);
408                        AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
409                    
410                        // @exception IPCException
411                        Boolean _send_forget(Uint32, AsyncRequest *);
412                    
413                        // @exception IPCException
414                        Boolean _send_forget(Uint32, const String &, AsyncRequest *);
415 mday          1.2  };
416 mday          1.35 
417 mday          1.1  PEGASUS_NAMESPACE_END
418                    
419 mday          1.4  #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2