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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2