(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                        // @exception Permission
324                        // @exception Deadlock
325 david.dillard 1.42     // @exception IPCException
326                        void blocking_thread_exec(const pegasus_module & handle,
327                                        PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
328                                        void *parm);
329                    
330                        // @exception Permission
331                        // @exception Deadlock
332                        // @exception IPCException
333                        void async_thread_exec(const pegasus_module & handle,
334                                        PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
335                                        void *parm);
336                    
337                        Boolean verify_handle(pegasus_module *);
338                    
339 kumpf         1.47     static ModuleController* getModuleController();
340 david.dillard 1.42 
341                        // send a message to another service
342                        // @exception Permission
343                        // @exception IPCException
344 kumpf         1.47     AsyncReply *ClientSendWait(
345 david.dillard 1.42                     Uint32 destination_q, AsyncRequest *request);
346                    
347                        // send a message to another module via another service
348                        // @exception Permission
349                        // @exception Deadlock
350                        // @exception IPCException
351 kumpf         1.47     AsyncReply *ClientSendWait(
352 david.dillard 1.42                  Uint32 destination_q,
353                                     String & destination_module,
354                                     AsyncRequest *message);
355                    
356                        // send an async message to another service
357                        // @exception Permission
358                        // @exception IPCException
359 kumpf         1.47     Boolean ClientSendAsync(
360 david.dillard 1.42                 Uint32 msg_handle,
361                                    Uint32 destination_q,
362                                    AsyncRequest *message,
363                                    void (*async_callback)(Uint32, Message *, void *) ,
364                                    void *callback_parm);
365                    
366                        // send an async message to another module via another service
367                        // @exception Permission
368                        // @exception IPCException
369 kumpf         1.47     Boolean ClientSendAsync(
370 david.dillard 1.42                 Uint32 msg_handle,
371                                    Uint32 destination_q,
372                                    const String & destination_module,
373                                    AsyncRequest *message,
374                                    void (*async_callback)(Uint32, Message *, void *),
375                                    void *callback_parm);
376                    
377                        // @exception Permission
378                        // @exception IPCException
379 kumpf         1.47     Boolean ClientSendForget(
380 david.dillard 1.42                 Uint32 destination_q,
381                                    AsyncRequest *message);
382                    
383                        // @exception Permission
384                        // @exception IPCException
385 kumpf         1.47     Boolean ClientSendForget(
386 david.dillard 1.42                 Uint32 destination_q,
387                                    const String & destination_module,
388                                    AsyncRequest *message);
389                    
390                        // @exception Permission
391                        // @exception Deadlock
392                        // @exception IPCException
393 kumpf         1.47     void client_blocking_thread_exec(
394 david.dillard 1.42                 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
395                                    void *parm);
396                    
397                        // @exception Permission
398                        // @exception Deadlock
399                        // @exception IPCException
400 kumpf         1.47     void client_async_thread_exec(
401 david.dillard 1.42                 PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
402                                    void *parm);
403                    
404                    protected:
405                        // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
406                        virtual void handleEnqueue() {}
407                        virtual void handleEnqueue(Message *) {}
408                        virtual void _handle_async_request(AsyncRequest *rq);
409                        virtual void _handle_async_callback(AsyncOpNode *op);
410                    
411                    private:
412                        class _module_lock
413                        {
414                        public:
415 mike          1.45         _module_lock(List<pegasus_module, RecursiveMutex> * list)
416 david.dillard 1.42            :_list(list)
417                            {
418                               _list->lock();
419                            }
420                    
421                            ~_module_lock()
422                            {
423                               _list->unlock();
424                            }
425                    
426                        private:
427                            _module_lock();
428 mike          1.45         List<pegasus_module, RecursiveMutex> * _list;
429 david.dillard 1.42     };
430                    
431                    
432                    
433                        static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
434 mike          1.45     List<pegasus_module, RecursiveMutex> _modules;
435 david.dillard 1.42     AsyncReply *_send_wait(Uint32, AsyncRequest *);
436                        AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
437                    
438                        // @exception IPCException
439                        Boolean _send_forget(Uint32, AsyncRequest *);
440                    
441                        // @exception IPCException
442                        Boolean _send_forget(Uint32, const String &, AsyncRequest *);
443                    
444                        void _blocking_thread_exec(
445                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
446                                    void *parm);
447                    
448                        void _async_thread_exec(
449                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
450                                    void *parm);
451 mday          1.2  };
452 mday          1.35 
453 mday          1.1  PEGASUS_NAMESPACE_END
454                    
455 mday          1.4  #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2