xrootd
XrdClPoller.hh
Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef __XRD_CL_POLLER_HH__
00020 #define __XRD_CL_POLLER_HH__
00021 
00022 #include <stdint.h>
00023 #include <string>
00024 
00025 namespace XrdCl
00026 {
00027   class Socket;
00028   class Poller;
00029 
00030   //----------------------------------------------------------------------------
00032   //----------------------------------------------------------------------------
00033   class SocketHandler
00034   {
00035     public:
00036       //------------------------------------------------------------------------
00038       //------------------------------------------------------------------------
00039       enum EventType
00040       {
00041         ReadyToRead  = 0x01,  
00042         ReadTimeOut  = 0x02,  
00043         ReadyToWrite = 0x04,  
00044         WriteTimeOut = 0x08   
00045       };
00046 
00047       //------------------------------------------------------------------------
00048       // Destructor
00049       //------------------------------------------------------------------------
00050       virtual ~SocketHandler() {}
00051 
00052       //------------------------------------------------------------------------
00054       //------------------------------------------------------------------------
00055       virtual void Initialize( Poller * ) {}
00056 
00057       //------------------------------------------------------------------------
00059       //------------------------------------------------------------------------
00060       virtual void Finalize() {};
00061 
00062       //------------------------------------------------------------------------
00064       //------------------------------------------------------------------------
00065       virtual void Event( uint8_t  type,
00066                           Socket  *socket ) = 0;
00067 
00068       //------------------------------------------------------------------------
00070       //------------------------------------------------------------------------
00071       static std::string EventTypeToString( uint8_t event )
00072       {
00073         std::string ev;
00074         if( event & ReadyToRead )  ev += "ReadyToRead|";
00075         if( event & ReadTimeOut )  ev += "ReadTimeOut|";
00076         if( event & ReadyToWrite ) ev += "ReadyToWrite|";
00077         if( event & WriteTimeOut ) ev += "WriteTimeOut|";
00078         ev.erase( ev.length()-1, 1) ;
00079         return ev;
00080       }
00081   };
00082 
00083   //----------------------------------------------------------------------------
00085   //----------------------------------------------------------------------------
00086   class Poller
00087   {
00088     public:
00089       //------------------------------------------------------------------------
00091       //------------------------------------------------------------------------
00092       virtual ~Poller() {}
00093 
00094       //------------------------------------------------------------------------
00096       //------------------------------------------------------------------------
00097       virtual bool Initialize() = 0;
00098 
00099       //------------------------------------------------------------------------
00101       //------------------------------------------------------------------------
00102       virtual bool Finalize() = 0;
00103 
00104       //------------------------------------------------------------------------
00106       //------------------------------------------------------------------------
00107       virtual bool Start() = 0;
00108 
00109       //------------------------------------------------------------------------
00111       //------------------------------------------------------------------------
00112       virtual bool Stop() = 0;
00113 
00114       //------------------------------------------------------------------------
00119       //------------------------------------------------------------------------
00120       virtual bool AddSocket( Socket        *socket,
00121                               SocketHandler *handler ) = 0;
00122 
00123       //------------------------------------------------------------------------
00125       //------------------------------------------------------------------------
00126       virtual bool RemoveSocket( Socket *socket ) = 0;
00127 
00128       //------------------------------------------------------------------------
00135       //------------------------------------------------------------------------
00136       virtual bool EnableReadNotification( Socket  *socket,
00137                                            bool     notify,
00138                                            uint16_t timeout = 60 ) = 0;
00139 
00140       //------------------------------------------------------------------------
00146       //------------------------------------------------------------------------
00147       virtual bool EnableWriteNotification( Socket  *socket,
00148                                             bool     notify,
00149                                             uint16_t timeout = 60 ) = 0;
00150 
00151       //------------------------------------------------------------------------
00153       //------------------------------------------------------------------------
00154       virtual bool IsRegistered( Socket *socket )  = 0;
00155 
00156       //------------------------------------------------------------------------
00158       //------------------------------------------------------------------------
00159       virtual bool IsRunning() const = 0;
00160   };
00161 }
00162 
00163 #endif // __XRD_CL_POLLER_HH__