L:/channel/cvm/include/CvmBaseChannel.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 
00018 #ifndef _CVM_BASE_CHANNEL_H_
00019 #define _CVM_BASE_CHANNEL_H_
00020 
00021 #include "ace/Dynamic_Service.h"
00022 
00023 #include <Channel.h>
00024 #include <CvmService.h>
00025 
00026 #include <iostream>
00027 #include <vector>
00028 #include <string>
00029 
00030 
00031 namespace cvm {
00032 
00035   template <class Channel>
00036   class CvmBaseChannel : public CvmService {
00037   public:
00038     Channel ch_;
00039     Channel * chan(void) { return &ch_; }
00040     // Constructor.
00042     virtual int init (int argc, ACE_TCHAR *argv[])
00043       {
00044         ACE_UNUSED_ARG(argc);
00045         ACE_UNUSED_ARG(argv);
00046         //-------------- Channel init -----------------
00047         ACE_DEBUG((LM_DEBUG, "### Channel is up and running ... ###\n"));
00048         return 0;
00049       }
00050     virtual int close (u_long)
00051       {
00052         //do nothing
00053         return 0;
00054       }
00055     virtual int fini ()
00056       {
00057         ACE_DEBUG((LM_DEBUG, "### Channel [%s] is shuting down ... ###\n", name().c_str()));
00058 
00059         ACE_DEBUG((LM_DEBUG, "Channel/Connector shutdown and ask all reader/writer threads exit...\n"));
00060         ACE_DEBUG((LM_DEBUG, "all reader/writeer threads exit...\n"));
00061         ACE_DEBUG((LM_DEBUG, "shutdown clock thread now...\n"));
00062         channel::Clock::instance()->stop();
00063         ACE_DEBUG((LM_DEBUG, "clock thread exit...\n"));
00064         //ACE_Reactor::end_event_loop ();
00065         ACE_OS::sleep(1);  //sleep 1 sec to give other threads another chance
00066         return 0;
00067       }
00068     virtual int info (ACE_TCHAR **strp, size_t length = 0) const
00069       {
00070         char buf[256];
00071 
00072         ACE_OS::sprintf (buf,
00073                          "CvmBaseChannel coming up ... \n");
00074 
00075         if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
00076           return -1;
00077         else
00078           ACE_OS::strncpy (*strp, buf, length);
00079         return ACE_OS::strlen (buf);
00080       }
00081     //virtual int suspend ();
00082     //virtual int resume ();
00083 
00084     static Channel *find_chan(const char* name) //find dynamic instantied channels
00085       {
00086         CvmBaseChannel<Channel> *d = ACE_Dynamic_Service<CvmBaseChannel<Channel> >::instance(ACE_TEXT(name));
00087         if (d==NULL)
00088           return NULL;
00089         else
00090           return d->chan();
00091       }
00092   };
00093 
00094 };
00095 
00096 #endif

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