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

  1 karl  1.39 //%2005////////////////////////////////////////////////////////////////////////
  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 mday  1.1  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13            // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16            // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18 david.dillard 1.42 //
 19 mday          1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20                    // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21                    // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22                    // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23                    // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24                    // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25                    // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26                    // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                    //
 28                    //==============================================================================
 29                    //
 30                    // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>
 31                    //
 32 a.arora       1.37 // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
 33 david.dillard 1.42 //              David Dillard, VERITAS Software Corp.
 34                    //                  (david.dillard@veritas.com)
 35 mday          1.1  //
 36                    //%/////////////////////////////////////////////////////////////////////////////
 37                    
 38                    #ifndef Pegasus_Module_Controller_h
 39                    #define Pegasus_Module_Controller_h
 40                    
 41                    #include <Pegasus/Common/Config.h>
 42 mday          1.19 #include <Pegasus/Common/Constants.h>
 43 mday          1.1  #include <Pegasus/Common/Message.h>
 44 kumpf         1.33 #include <Pegasus/Common/InternalException.h>
 45 mday          1.1  #include <Pegasus/Common/IPC.h>
 46                    #include <Pegasus/Common/Thread.h>
 47                    #include <Pegasus/Common/AsyncOpNode.h>
 48                    #include <Pegasus/Common/Cimom.h>
 49                    #include <Pegasus/Common/CimomMessage.h>
 50                    #include <Pegasus/Common/MessageQueueService.h>
 51 mday          1.14 #include <Pegasus/Common/peg_authorization.h>
 52 kumpf         1.32 #include <Pegasus/Common/Linkage.h>
 53 david.dillard 1.42 #include <Pegasus/Common/AutoPtr.h>
 54 mday          1.11 
 55                    
 56 mday          1.1  PEGASUS_NAMESPACE_BEGIN
 57                    
 58                    class ModuleController;
 59                    
 60 mday          1.9  
 61 david.dillard 1.42 class PEGASUS_COMMON_LINKAGE pegasus_module
 62 mday          1.9  {
 63 david.dillard 1.42 private:
 64                        class module_rep : public pegasus_auth_handle
 65                        {
 66                        public:
 67                            typedef pegasus_auth_handle Base;
 68                    
 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                            Boolean operator==(const module_rep *rep) const
 79                            {
 80                                return(rep == this);
 81                            }
 82                    
 83                            Boolean operator==(const module_rep &rep) const
 84 david.dillard 1.42         {
 85                                return(rep == *this);
 86                            }
 87                    
 88                            Boolean operator==(void *rep) const
 89                            {
 90                                return(reinterpret_cast<const void *>(this) == rep);
 91                            }
 92                    
 93                            void reference()
 94                            {
 95                                _reference_count++;
 96                            }
 97                    
 98                            void dereference()
 99                            {
100                                _reference_count--;
101                            }
102                    
103                            Uint32 reference_count() const
104                            {
105 mike          1.43             return _reference_count.get();
106 david.dillard 1.42         }
107                    
108                            const String& get_name() const throw()
109                            {
110                                return _name;
111                            }
112                    
113                            void *get_module_address() const
114                            {
115                                return _module_address;
116                            }
117                    
118                            Message * module_receive_message(Message *msg);
119                    
120                            void _send_async_callback(Uint32 msg_handle, Message *msg, void *parm);
121                    
122                            void _send_shutdown_notify();
123                    
124                            void lock()
125                            {
126                                _thread_safety.lock(pegasus_thread_self());
127 david.dillard 1.42         }
128                    
129                            void unlock()
130                            {
131                                _thread_safety.unlock();
132                            }
133                    
134                            Boolean authorized();
135                            Boolean authorized(Uint32);
136                            Boolean authorized(Uint32, Uint32);
137                    
138                        private:
139                            module_rep();
140                            module_rep(const module_rep&);
141                            module_rep & operator=(const module_rep & rep);
142                    
143                            Mutex _thread_safety;
144                            // Don't make this an AutoPtr. Refer to bug 3502
145                            ModuleController* _controller;
146                            String _name;
147                            AtomicInt _reference_count;
148 david.dillard 1.42         AtomicInt _shutting_down;
149                    
150                            void *_module_address;
151                            Message * (*_receive_message)(Message *, void *);
152                            void (*_async_callback)(Uint32, Message *, void *);
153                            void (*_shutdown_notify)(Uint32 code, void *);
154                    
155                            static Message * default_receive_message(Message *msg, void *inst)
156                            {
157                                throw NotImplemented("Module Receive");
158                                return 0;
159                            }
160                    
161                            static void default_async_callback(Uint32 handle, Message *msg, void *inst)
162                            {
163                                throw NotImplemented("Module Async Receive");
164                            }
165                    
166                            static void default_shutdown_notify(Uint32 code, void *inst)
167                            {
168                                // Intentionally left blank
169 david.dillard 1.42         }
170                    
171                            static Message * closed_receive_message(Message *msg, void *inst)
172                            {
173                                throw ModuleClosed();
174                                return 0;
175                            }
176                    
177                            static void closed_async_callback(Uint32 handle, Message *msg, void *inst)
178                            {
179                                throw ModuleClosed();
180                            }
181                    
182                            friend class ModuleController;
183                        };
184                    
185                    public:
186                        pegasus_module(ModuleController *controller,
187                                 const String &id,
188                                 void *module_address,
189                                 Message * (*receive_message)(Message *, void *),
190 david.dillard 1.42              void (*async_callback)(Uint32, Message *, void *),
191                                 void (*shutdown_notify)(Uint32 code, void *));
192                    
193                        pegasus_module(const pegasus_module & mod);
194                        pegasus_module & operator= (const pegasus_module & mod);
195                    
196                        virtual ~pegasus_module();
197                    
198                        virtual Boolean authorized(Uint32 operation);
199                        virtual Boolean authorized();
200                    
201                        Boolean operator == (const pegasus_module & mod) const;
202                        Boolean operator == (const String &  mod) const;
203                        Boolean operator == (const void *mod) const;
204                    
205                        const String & get_name() const;
206                    
207                        // introspection interface
208                        Boolean query_interface(const String & class_id, void **object_ptr) const;
209                    
210                    private:
211 david.dillard 1.42 
212                        AutoPtr<module_rep> _rep;//PEP101
213                    
214                        pegasus_module()
215                        {
216                        }
217                    
218                        Boolean _rcv_msg(Message *);
219                        Message * _receive_message(Message *msg);
220                        void _send_async_callback(Uint32 msg_handle, Message *msg, void *);
221                        void _send_shutdown_notify();
222                        Boolean _shutdown();
223                        PEGASUS_STD(bitset<32>) _allowed_operations;
224                    
225                        void reference()
226                        {
227                            _rep->reference();
228                        }
229                    
230                        void dereference()
231                        {
232 david.dillard 1.42         _rep->dereference();
233                        }
234                    
235                        friend class ModuleController;
236 mday          1.5  };
237 mday          1.4  
238                    
239 mday          1.1  class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
240                    {
241 david.dillard 1.42 public:
242                        typedef MessageQueueService Base;
243 mday          1.1  
244 david.dillard 1.42     static const Uint32 GET_CLIENT_HANDLE;
245                        static const Uint32 REGISTER_MODULE;
246                        static const Uint32 DEREGISTER_MODULE;
247                        static const Uint32 FIND_SERVICE;
248                        static const Uint32 FIND_MODULE_IN_SERVICE;
249                        static const Uint32 GET_MODULE_REFERENCE;
250                        static const Uint32 MODULE_SEND_WAIT;
251                        static const Uint32 MODULE_SEND_WAIT_MODULE;
252                        static const Uint32 MODULE_SEND_ASYNC;
253                        static const Uint32 MODULE_SEND_ASYNC_MODULE;
254                        static const Uint32 BLOCKING_THREAD_EXEC;
255                        static const Uint32 ASYNC_THREAD_EXEC;
256                        static const Uint32 CLIENT_SEND_WAIT;
257                        static const Uint32 CLIENT_SEND_WAIT_MODULE;
258                        static const Uint32 CLIENT_SEND_ASYNC;
259                        static const Uint32 CLIENT_SEND_ASYNC_MODULE;
260                        static const Uint32 CLIENT_BLOCKING_THREAD_EXEC;
261                        static const Uint32 CLIENT_ASYNC_THREAD_EXEC;
262                        static const Uint32 CLIENT_SEND_FORGET;
263                        static const Uint32 CLIENT_SEND_FORGET_MODULE;
264                        static const Uint32 MODULE_SEND_FORGET;
265 david.dillard 1.42     static const Uint32 MODULE_SEND_FORGET_MODULE;
266 mday          1.11 
267 kumpf         1.20 // ATTN-DME-P2-20020406 Removed private declaration.  client_handle is
268                    //          currently used in Pegasus/Provider/CIMOMHandle.cpp
269 mday          1.14 
270 david.dillard 1.42 //   private:
271                        class client_handle : public pegasus_auth_handle
272                        {
273                        public:
274                            typedef pegasus_auth_handle Base;
275                    
276                            client_handle(const pegasus_identity & id)
277                               :Base(id) ,
278                            allowed_operations( GET_CLIENT_HANDLE |
279                                        FIND_SERVICE |
280                                        FIND_MODULE_IN_SERVICE |
281                                        GET_MODULE_REFERENCE |
282                                        CLIENT_SEND_WAIT |
283                                        CLIENT_SEND_WAIT_MODULE |
284                                        CLIENT_SEND_ASYNC |
285                                        CLIENT_SEND_ASYNC_MODULE |
286                                        CLIENT_BLOCKING_THREAD_EXEC |
287                                        CLIENT_ASYNC_THREAD_EXEC),
288                            reference_count(1)
289                            {
290                            }
291 david.dillard 1.42 
292                            ~client_handle()
293                            {
294                            }
295                    
296                            client_handle & operator=(const client_handle & handle)
297                            {
298                                if (this == &handle)
299                                    return *this;
300                               reference_count++;
301                               return *this;
302                            }
303                    
304                    
305                            virtual Boolean authorized(Uint32, Uint32);
306                            virtual Boolean authorized(Uint32 operation);
307                            virtual Boolean authorized();
308                            PEGASUS_STD(bitset<32>) allowed_operations;
309                            AtomicInt reference_count;
310                        };
311                    
312 david.dillard 1.42     class callback_handle
313                        {
314                            public:
315                            static void * operator new(size_t );
316                            static void operator delete(void *, size_t);
317                        private:
318                            static callback_handle *_head;
319                            static const int BLOCK_SIZE;
320                            static Mutex _alloc_mut;
321                    
322                        public:
323                            callback_handle(pegasus_module * module, void *parm)
324                               : _module(module), _parm(parm)
325                            {
326                            }
327                    
328                            ~callback_handle()
329                            {
330                                if( _module->get_name() == String(PEGASUS_MODULENAME_TEMP) )
331                                    // delete _module;
332                                    _module.reset();
333 david.dillard 1.42         }
334                    
335                            AutoPtr<pegasus_module> _module;//PEP101
336                            void *_parm;
337                        };
338 mday          1.11 
339 david.dillard 1.42 public:
340                        ModuleController(const char *name);
341 mday          1.30 /*       ModuleController(const char *name,  */
342 david.dillard 1.42 /*             Sint16 min_threads,  */
343                    /*             Sint16 max_threads, */
344                    /*             struct timeval & create_thread, */
345                    /*             struct timeval & destroy_thread); */
346                    
347                        ~ModuleController();
348                    
349                        // module api
350                        // @exception AlreadyExistsException
351                        // @exception IncompatibleTypesException
352                        static ModuleController & register_module(const String & controller_name,
353                                        const String & module_name,
354                                        void *module_address,
355                                        Message * (*receive_message)(Message *, void *),
356                                        void (*async_callback)(Uint32, Message *, void *),
357                                        void (*shutdown_notify)(Uint32, void *),
358                                        pegasus_module **instance = NULL);
359                    
360                        // @exception Permission
361                        Boolean deregister_module(const String & module_name);
362                    
363 david.dillard 1.42     // @exception Permission
364                        Uint32 find_service(const pegasus_module & handle, const String & name);
365                    
366                        // @exception Permission
367                        // @exception IPCException
368                        Uint32 find_module_in_service(const pegasus_module & handle,
369                                        const String & module_name);
370                    
371                        // @exception Permission
372                        pegasus_module * get_module_reference(const pegasus_module & my_handle,
373                                        const String & module_name);
374                    
375                        // send a message to another service
376                        // @exception Permission
377                        // @exception IPCException
378                        AsyncReply *ModuleSendWait(const pegasus_module & handle,
379                                        Uint32 destination_q,
380                                        AsyncRequest *request);
381                    
382                        // send a message to another module via another service
383                        // @exception Permission
384 david.dillard 1.42     // @exception DeadLock
385                        // @exception IPCException
386                        AsyncReply *ModuleSendWait(const pegasus_module & handle,
387                                        Uint32 destination_q,
388                                        const String & destination_module,
389                                        AsyncRequest *message);
390                    
391                        // send an async message to another service
392                        // @exception Permission
393                        // @exception DeadLock
394                        // @exception IPCException
395                        Boolean ModuleSendAsync(const pegasus_module & handle,
396                                        Uint32 msg_handle,
397                                        Uint32 destination_q,
398                                        AsyncRequest *message,
399                                        void *callback_parm);
400                    
401                        // send an async message to another module via another service
402                        // @exception Permission
403                        // @exception IPCException
404                        Boolean ModuleSendAsync(const pegasus_module & handle,
405 david.dillard 1.42                     Uint32 msg_handle,
406                                        Uint32 destination_q,
407                                        const String & destination_module,
408                                        AsyncRequest *message,
409                                        void *callback_parm);
410                    
411                        // @exception Permission
412                        // @exception IPCException
413                        Boolean ModuleSendForget(const pegasus_module & handle,
414                                        Uint32 destination_q,
415                                        AsyncRequest *message);
416                    
417                        // @exception Permission
418                        // @exception IPCException
419                        Boolean ModuleSendForget(const pegasus_module & handle,
420                                        Uint32 destination_q,
421                                        const String & destination_module,
422                                        AsyncRequest *message);
423                    
424                        // @exception Permission
425                        // @exception Deadlock
426 david.dillard 1.42     // @exception IPCException
427                        void blocking_thread_exec(const pegasus_module & handle,
428                                        PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
429                                        void *parm);
430                    
431                        // @exception Permission
432                        // @exception Deadlock
433                        // @exception IPCException
434                        void async_thread_exec(const pegasus_module & handle,
435                                        PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
436                                        void *parm);
437                    
438                        Boolean verify_handle(pegasus_module *);
439                    
440                        // @exception IncompatibleTypesException
441                        static ModuleController & get_client_handle(const pegasus_identity & id,
442                                        client_handle **handle);
443                    
444                        // @exception IncompatibleTypesException
445                        static ModuleController & get_client_handle(const char *controller,
446                                        const pegasus_identity & id,
447 david.dillard 1.42                     client_handle **handle);
448                    
449                    
450                        void return_client_handle(client_handle *handle);
451                    
452                        // send a message to another service
453                        // @exception Permission
454                        // @exception IPCException
455                        AsyncReply *ClientSendWait(const client_handle & handle,
456                                        Uint32 destination_q, AsyncRequest *request);
457                    
458                        // send a message to another module via another service
459                        // @exception Permission
460                        // @exception Deadlock
461                        // @exception IPCException
462                        AsyncReply *ClientSendWait(const client_handle & handle,
463                                     Uint32 destination_q,
464                                     String & destination_module,
465                                     AsyncRequest *message);
466                    
467                        // send an async message to another service
468 david.dillard 1.42     // @exception Permission
469                        // @exception IPCException
470                        Boolean ClientSendAsync(const client_handle & handle,
471                                    Uint32 msg_handle,
472                                    Uint32 destination_q,
473                                    AsyncRequest *message,
474                                    void (*async_callback)(Uint32, Message *, void *) ,
475                                    void *callback_parm);
476                    
477                        // send an async message to another module via another service
478                        // @exception Permission
479                        // @exception IPCException
480                        Boolean ClientSendAsync(const client_handle & handle,
481                                    Uint32 msg_handle,
482                                    Uint32 destination_q,
483                                    const String & destination_module,
484                                    AsyncRequest *message,
485                                    void (*async_callback)(Uint32, Message *, void *),
486                                    void *callback_parm);
487                    
488                        // @exception Permission
489 david.dillard 1.42     // @exception IPCException
490                        Boolean ClientSendForget(const client_handle & handle,
491                                    Uint32 destination_q,
492                                    AsyncRequest *message);
493                    
494                        // @exception Permission
495                        // @exception IPCException
496                        Boolean ClientSendForget(const client_handle & handle,
497                                    Uint32 destination_q,
498                                    const String & destination_module,
499                                    AsyncRequest *message);
500                    
501                        // @exception Permission
502                        // @exception Deadlock
503                        // @exception IPCException
504                        void client_blocking_thread_exec(const client_handle & handle,
505                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
506                                    void *parm);
507                    
508                        // @exception Permission
509                        // @exception Deadlock
510 david.dillard 1.42     // @exception IPCException
511                        void client_async_thread_exec(const client_handle & handle,
512                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
513                                    void *parm);
514                    
515                    protected:
516                        // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
517                        virtual void handleEnqueue() {}
518                        virtual void handleEnqueue(Message *) {}
519                        virtual void _handle_async_request(AsyncRequest *rq);
520                        virtual void _handle_async_callback(AsyncOpNode *op);
521                    
522                    private:
523                        class _module_lock
524                        {
525                        public:
526                            _module_lock(DQueue<pegasus_module> * list)
527                               :_list(list)
528                            {
529                               _list->lock();
530                            }
531 david.dillard 1.42 
532                            ~_module_lock()
533                            {
534                               _list->unlock();
535                            }
536                    
537                        private:
538                            _module_lock();
539                            DQueue<pegasus_module> * _list;
540                        };
541                    
542                    
543                    
544                        static void _async_handleEnqueue(AsyncOpNode *h, MessageQueue *q, void *parm);
545                        DQueue<pegasus_module> _modules;
546                        AsyncReply *_send_wait(Uint32, AsyncRequest *);
547                        AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
548                    
549                        // @exception IPCException
550                        Boolean _send_forget(Uint32, AsyncRequest *);
551                    
552 david.dillard 1.42     // @exception IPCException
553                        Boolean _send_forget(Uint32, const String &, AsyncRequest *);
554                    
555                        void _blocking_thread_exec(
556                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
557                                    void *parm);
558                    
559                        void _async_thread_exec(
560                                    PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),
561                                    void *parm);
562 mday          1.2  };
563 mday          1.35 
564 mday          1.1  PEGASUS_NAMESPACE_END
565                    
566 mday          1.4  #endif // Pegasus_Module_Controller_H

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2