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

Diff for /pegasus/src/Pegasus/Common/ModuleController.h between version 1.6 and 1.53

version 1.6, 2002/03/21 22:53:10 version 1.53, 2008/08/15 23:14:01
Line 1 
Line 1 
 //%////-*-c++-*-////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 20 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Day (mdday@us.ibm.com) <<< Wed Mar 13 20:49:40 2002 mdd >>>  
 //  
 // Modified By:  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifndef Pegasus_Module_Controller_h  #ifndef Pegasus_ModuleController_h
 #define Pegasus_Module_Controller_h  #define Pegasus_ModuleController_h
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/Linkage.h>
   #include <Pegasus/Common/Constants.h>
   #include <Pegasus/Common/List.h>
 #include <Pegasus/Common/Message.h> #include <Pegasus/Common/Message.h>
 #include <Pegasus/Common/Exception.h>  
 #include <Pegasus/Common/IPC.h>  
 #include <Pegasus/Common/Thread.h>  
 #include <Pegasus/Common/AsyncOpNode.h>  
 #include <Pegasus/Common/Cimom.h>  
 #include <Pegasus/Common/CimomMessage.h>  
 #include <Pegasus/Common/MessageQueueService.h> #include <Pegasus/Common/MessageQueueService.h>
 PEGASUS_NAMESPACE_BEGIN  #include <Pegasus/Common/AsyncOpNode.h>
   #include <Pegasus/Common/AutoPtr.h>
 class ModuleController;  
   
  
   PEGASUS_NAMESPACE_BEGIN
  
 class PEGASUS_COMMON_LINKAGE pegasus_module  class PEGASUS_COMMON_LINKAGE RegisteredModuleHandle : public Linkable
 {  
       class PEGASUS_COMMON_LINKAGE module_rep  
       {       {
          public:          public:
             module_rep(ModuleController *controller,      RegisteredModuleHandle(
                        const String & name,                        const String & name,
                        void *module_address,                        void *module_address,
                        Boolean (*receive_message)(Message *),          Message* (*receive_message)(Message *, void *),
                        void (*async_callback)(Uint32, Message *),          void (*async_callback)(Uint32, Message *, void *));
                        void (*shutdown_notify)(Uint32 code))  
                : _thread_safety(),  
                  _controller(controller),  
                  _name(name),  
                  _reference_count(1),  
                  _shutting_down(0),  
                  _module_address(module_address)  
   
             {  
                if(receive_message != NULL)  
                   _receive_message = receive_message;  
                else  
                   _receive_message = default_receive_message;  
                if(async_callback != NULL)  
                   _async_callback = async_callback;  
                else  
                   _async_callback = default_async_callback;  
                if(shutdown_notify != NULL)  
                   _shutdown_notify = shutdown_notify;  
                else  
                   _shutdown_notify = default_shutdown_notify;  
             }  
   
             virtual ~module_rep(void)  
             {  
  
             }      virtual ~RegisteredModuleHandle();
   
             Boolean operator == (const module_rep *rep) const  
             {  
                if (rep == this )  
                   return true;  
                return false;  
             }  
   
             Boolean operator == (const module_rep &rep) const  
             {  
                if (rep == *this)  
                   return true;  
                return false;  
             }  
  
             Boolean operator == (void *rep) const      const String& get_name() const;
             {  
                if ( (void *)this == rep )  
                   return true;  
                return false;  
             }  
   
             void reference(void) { _reference_count++; }  
             void dereference(void) { _reference_count--; }  
             Uint32 reference_count(void)  { return _reference_count.value(); }  
             const String & get_name(void) const { return _name; }  
             void *get_module_address(void) const { return _module_address; }  
             Boolean module_receive_message(Message *msg)  
             {  
                Boolean ret;  
                _thread_safety.lock(pegasus_thread_self());  
                try {  ret = _receive_message(msg); }  
                catch(...) { _thread_safety.unlock(); throw; }  
                _thread_safety.unlock();  
                return ret;  
             }  
   
             void _send_async_callback(Uint32 msg_handle, Message *msg)  
             {  
                _thread_safety.lock(pegasus_thread_self());  
                try  { _async_callback(msg_handle, msg); }  
                catch(...) { _thread_safety.unlock(); throw; }  
  
             }  private:
             void _send_shutdown_notify(Uint32 code)  
             {  
                _thread_safety.lock(pegasus_thread_self());  
                if( _shutting_down == 0 )  
                {  
                   _shutting_down++;  
                   _shutdown_notify(code);  
                }  
                _thread_safety.unlock();  
             }  
             void lock(void)  
             {  
                _thread_safety.lock(pegasus_thread_self());  
             }  
  
             void unlock(void)      RegisteredModuleHandle();
             {      RegisteredModuleHandle(const RegisteredModuleHandle&);
                _thread_safety.unlock();      RegisteredModuleHandle& operator=(const RegisteredModuleHandle&);
             }  
  
          private:      Message* _receive_message(Message* msg);
             module_rep(void);      void _send_async_callback(Uint32 msg_handle, Message* msg, void* parm);
             module_rep(const module_rep & );  
             module_rep& operator= (const module_rep & );  
  
             Mutex _thread_safety;  
             ModuleController *_controller;  
             String _name;             String _name;
             AtomicInt _reference_count;  
             Uint32 _shutting_down;  
   
             void *_module_address;             void *_module_address;
             Boolean (*_receive_message)(Message *);      Message* (*_module_receive_message)(Message *, void *);
             void (*_async_callback)(Uint32, Message *);      void (*_async_callback)(Uint32, Message *, void *);
             void (*_shutdown_notify)(Uint32 code);  
   
             static Boolean default_receive_message(Message *msg)  
             {  
                throw NotImplemented("Module Receive");  
             }  
   
             static void default_async_callback(Uint32 handle, Message *msg)  
             {  
                throw NotImplemented("Module Async Receive");  
             }  
   
             static void default_shutdown_notify(Uint32 code)  
             {  
                return;  
             }  
  
             friend class ModuleController;             friend class ModuleController;
       };       };
  
    public:  
   
       pegasus_module(ModuleController *controller,  
                      const String &id,  
                      void *module_address,  
                      Boolean (*receive_message)(Message *),  
                      void (*async_callback)(Uint32, Message *),  
                      void (*shutdown_notify)(Uint32 code)) ;  
  
       ~pegasus_module(void)  class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService
       {       {
          _rep->dereference();  public:
          if( 0 == _rep->reference_count())      typedef MessageQueueService Base;
             delete _rep;  
       }  
   
       pegasus_module & operator= (const pegasus_module & mod);  
       Boolean operator == (const pegasus_module *mod) const;  
       Boolean operator == (const pegasus_module & mod) const ;  
       Boolean operator == (const String &  mod) const;  
       Boolean operator == (const void *mod) const;  
   
       const String & get_name(void) const;  
   
       // introspection interface  
       Boolean query_interface(const String & class_id, void **object_ptr) const;  
   
    private:  
   
       module_rep *_rep;  
  
       pegasus_module(void);      class callback_handle
       pegasus_module(const pegasus_module & mod);  
       Boolean _rcv_msg(Message *) ;  
       Boolean _receive_message(Message *msg)  
       {       {
          return _rep->module_receive_message(msg);      public:
       }          callback_handle(RegisteredModuleHandle* module, void* parm)
              : _module(module), _parm(parm)
       void _send_async_callback(Uint32 msg_handle, Message *msg)  
       {       {
          _rep->_send_async_callback(msg_handle, msg);  
       }       }
       void _send_shutdown_notify(Uint32 code)  
           ~callback_handle()
       {       {
          _rep->_send_shutdown_notify(code);              if (_module->get_name() == String(PEGASUS_MODULENAME_TEMP))
                   _module.reset();
       }       }
  
       Boolean _shutdown(Uint32 code) { _send_shutdown_notify(code); return true; }          AutoPtr<RegisteredModuleHandle> _module;
           void* _parm;
       void reference(void) { _rep->reference(); }  
       void dereference(void)  { _rep->dereference(); }  
   
       friend class ModuleController;  
 }; };
  
   public:
       ModuleController(const char *name);
  
       ~ModuleController();
  
       // module api
       // @exception AlreadyExistsException
       // @exception IncompatibleTypesException
       static ModuleController& register_module(
           const String & controller_name,
           const String& module_name,
           void* module_address,
           Message* (*receive_message)(Message *, void *),
           void (*async_callback)(Uint32, Message *, void *),
           RegisteredModuleHandle** instance = 0);
  
 class PEGASUS_COMMON_LINKAGE ModuleController : public MessageQueueService      // @exception Permission
 {      Boolean deregister_module(const String& module_name);
  
    public:      // @exception Permission
       typedef MessageQueueService Base;      Uint32 find_service(
           const RegisteredModuleHandle& handle,
           const String& name);
   
       // @exception Permission
       // @exception IPCException
       Uint32 find_module_in_service(
           const RegisteredModuleHandle& handle,
           const String& module_name);
  
       ModuleController(const char *name);      // send a message to another service
       ModuleController(const char *name,      // @exception Permission
                        Sint16 min_threads,      // @exception IPCException
                        Sint16 max_threads,      AsyncReply* ModuleSendWait(
                        struct timeval & create_thread,          const RegisteredModuleHandle& handle,
                        struct timeval & destroy_thread,          Uint32 destination_q,
                        struct timeval & deadlock);          AsyncRequest* request);
  
       // send a message to another module via another service
       // @exception Permission
       // @exception IPCException
       AsyncReply* ModuleSendWait(
           const RegisteredModuleHandle& handle,
           Uint32 destination_q,
           const String& destination_module,
           AsyncRequest* message);
  
       virtual ~ModuleController(void);      // send an async message to another service
       // @exception Permission
       // @exception IPCException
       Boolean ModuleSendAsync(
           const RegisteredModuleHandle& handle,
           Uint32 msg_handle,
           Uint32 destination_q,
           AsyncRequest* message,
           void* callback_parm);
  
       // module api      // send an async message to another module via another service
       ModuleController & register_module(const String & module_name,      // @exception Permission
                                          void *module_address,      // @exception IPCException
                                          Boolean (*receive_message)(Message *),      Boolean ModuleSendAsync(
                                          void (*async_callback)(Uint32, Message *),          const RegisteredModuleHandle& handle,
                                          void (*shutdown_notify)(Uint32)) throw(AlreadyExists);          Uint32 msg_handle,
           Uint32 destination_q,
           const String& destination_module,
           AsyncRequest* message,
           void* callback_parm);
   
       // @exception Permission
       // @exception IPCException
       Boolean ModuleSendForget(
           const RegisteredModuleHandle& handle,
           Uint32 destination_q,
           AsyncRequest* message);
  
       Boolean deregister_module(const String & module_name);      // @exception Permission
       // @exception IPCException
       Boolean ModuleSendForget(
           const RegisteredModuleHandle & handle,
           Uint32 destination_q,
           const String & destination_module,
           AsyncRequest* message);
  
       Uint32 find_service(pegasus_module & handle, String & name);      Boolean verify_handle(RegisteredModuleHandle *);
       String & find_service(pegasus_module & handle, Uint32 queue_id);  
  
       pegasus_module & get_module_reference(pegasus_module & handle, String & name);      static ModuleController* getModuleController();
  
       // send a message to another service       // send a message to another service
       Message *ModuleSendWait(pegasus_module & handle,      // @exception Permission
       // @exception IPCException
       AsyncReply* ClientSendWait(
                               Uint32 destination_q,                               Uint32 destination_q,
                               Message *message);          AsyncRequest* request);
  
       // send a message to another module via another service       // send a message to another module via another service
       Message *ModuleSendWait(pegasus_module & handle,      // @exception Permission
       // @exception IPCException
       AsyncReply* ClientSendWait(
                               Uint32 destination_q,                               Uint32 destination_q,
                               String & destination_module,                               String & destination_module,
                               Message *message);          AsyncRequest* message);
  
       // send a message to another service      // send an async message to another service
       Boolean ModuleSendAsync(pegasus_module & handle,      // @exception Permission
       // @exception IPCException
       Boolean ClientSendAsync(
                               Uint32 msg_handle,                               Uint32 msg_handle,
                               Uint32 destination_q,                               Uint32 destination_q,
                               Message *message);          AsyncRequest* message,
           void (*async_callback)(Uint32, Message *, void *),
       // send a message to another module via another service          void* callback_parm);
       Boolean ModuleSendAsync(pegasus_module & handle,  
       // send an async message to another module via another service
       // @exception Permission
       // @exception IPCException
       Boolean ClientSendAsync(
                               Uint32 msg_handle,                               Uint32 msg_handle,
                               Uint32 destination_q,                               Uint32 destination_q,
                               String & destination_module,          const String& destination_module,
                               Message *message);          AsyncRequest* message,
           void (*async_callback)(Uint32, Message *, void *),
           void* callback_parm);
   
       // @exception Permission
       // @exception IPCException
       Boolean ClientSendForget(
           Uint32 destination_q,
           AsyncRequest* message);
  
       Uint32 blocking_thread_exec(pegasus_module & handle,      // @exception Permission
                                   PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),      // @exception IPCException
                                   void *parm);      Boolean ClientSendForget(
       Uint32 async_thread_exec(pegasus_module & handle,          Uint32 destination_q,
                                PEGASUS_THREAD_RETURN (PEGASUS_THREAD_CDECL *thread_func)(void *),          const String& destination_module,
                                void *parm);          AsyncRequest* message);
  
    protected:    protected:
       // ATTN-RK-P2-20010322:  These methods are pure virtual in superclass
       virtual void handleEnqueue() {}
       virtual void handleEnqueue(Message *) {}
       virtual void _handle_async_request(AsyncRequest *rq);
       virtual void _handle_async_callback(AsyncOpNode *op);
  
    private:    private:
       class _module_lock
       {
       public:
           _module_lock(List<RegisteredModuleHandle, Mutex> * list)
              :_list(list)
           {
              _list->lock();
           }
  
       DQueue<pegasus_module> _modules;          ~_module_lock()
       ThreadPool _thread_pool;          {
 };             _list->unlock();
           }
  
       private:
           _module_lock();
           List<RegisteredModuleHandle, Mutex> * _list;
       };
  
  
       static void _async_handleEnqueue(
           AsyncOpNode* h,
           MessageQueue* q,
           void* parm);
  
       List<RegisteredModuleHandle, Mutex> _modules;
       AsyncReply *_send_wait(Uint32, AsyncRequest *);
       AsyncReply *_send_wait(Uint32, const String &, AsyncRequest *);
  
       // @exception IPCException
       Boolean _send_forget(Uint32, AsyncRequest *);
  
       // @exception IPCException
       Boolean _send_forget(Uint32, const String &, AsyncRequest *);
   };
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  
   #endif // Pegasus_ModuleController_h
 #endif // Pegasus_Module_Controller_H  


Legend:
Removed from v.1.6  
changed lines
  Added in v.1.53

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2