ARPDAS_QNX6 1.0
DG_Resmgr.h
Go to the documentation of this file.
00001 #ifndef RESMGR_H_
00002 #define RESMGR_H_
00003 
00004 #include <sys/iofunc.h>
00005 #include <sys/dispatch.h>
00006 #include <sys/resmgr.h>
00007 #include <list>
00008 
00009 class DG_dispatch;
00010 
00011 /**
00012   DG_dispatch_client is a virtual base class for clients of DG_dispatch. The main service provided is quit coordination.
00013   ready_to_quit() virtual function should return true if client is ready to quit. This will remove the client from the
00014   DG_dispatch's list, so a subsequent detach() is unnecessary. Hence ready_to_quit() should set the dispatch member to
00015   NULL before returning a non-zero value.
00016   As a rule, clients should shut down all of their functions prior to returning. For devices, that means resmgr_detach()
00017   
00018   As written, this is probably a bad design, since DG_dispatch::client_add is called with a partially constructed client.
00019   In a multi-threaded environment, there is a potential for harm.
00020 */
00021 class DG_dispatch_client {
00022   public:
00023     DG_dispatch_client();
00024     virtual ~DG_dispatch_client(); // calls detach() if necessary
00025     void attach(DG_dispatch *disp); // add to dispatch list
00026     void detach(); // remove from dispatch list
00027     virtual int ready_to_quit()= 0;
00028     DG_dispatch *dispatch;
00029 };
00030 
00031 class DG_dispatch {
00032   public:
00033     dispatch_t *dpp;
00034     DG_dispatch();
00035     ~DG_dispatch();
00036     void client_add(DG_dispatch_client *clt);
00037     void client_rm(DG_dispatch_client *clt);
00038     void Loop();
00039     void ready_to_quit();
00040   private:
00041     int quit_received;
00042     int all_closed();
00043     dispatch_context_t *single_ctp;
00044     std::list<DG_dispatch_client *> clients;
00045 };
00046 
00047 #endif /*RESMGR_H_*/
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines