L:/channel/cvm/examples/cvm_instance/tasks/ctrl/CtrlTask.h

Go to the documentation of this file.
00001 
00002 // Copyright (c) 2005, 2006 Yigong Liu
00003 // Permission to use, copy, modify, distribute and sell this software for any 
00004 //     purpose is hereby granted without fee, provided that the above copyright 
00005 //     notice appear in all copies and that both that copyright notice and this 
00006 //     permission notice appear in supporting documentation.
00007 // The author makes no representations about the 
00008 //     suitability of this software for any purpose. It is provided "as is" 
00009 //     without express or implied warranty.
00011 
00012 
00013 #include <Cvm.h>
00014 
00015 class Quit_Handler : public ACE_Event_Handler {
00016   friend class ace_dewarn_gplusplus;
00017  public:
00018   Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {}
00019 
00020   virtual int handle_exception (ACE_HANDLE) {
00021     ACE_DEBUG((LM_DEBUG, "Channel Reactor shutting down now...\n"));
00022     reactor ()->end_reactor_event_loop ();
00023     //ACE_OS::sleep(1);  //sleep 2 seconds to allow reader threads to exit
00024     return -1; // Trigger call to handle_close() method.
00025   }
00026 
00027   virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)
00028     { delete this; return 0; }
00029 
00030  private:
00031 
00032   // Private destructor ensures dynamic allocation.
00033   virtual ~Quit_Handler () {}
00034 };
00035 
00036 class Ctrl_Task : public cvm::CvmTask {
00037  public:
00038   //Each app should implement the following 3 methods
00039   //to get app control flow going
00040   Status prepare(void); //initialization before thread starts
00041   Status cleanup(void); //cleanup before threads exit
00042   int work (void);       //main processing loop
00043   int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
00044   //test menu
00045   void showTestMenu();
00046 
00047   //need to overwrite fini() since we are not recving msgs
00048   int fini ();
00049 };
00050 
00051 

Generated on Mon Feb 27 19:59:22 2006 for channel by  doxygen 1.4.6-NO