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_BUILT_IN_HH__ 00020 #define __XRD_CL_POLLER_BUILT_IN_HH__ 00021 00022 #include "XrdSys/XrdSysPthread.hh" 00023 #include "XrdCl/XrdClPoller.hh" 00024 #include <map> 00025 #include <vector> 00026 00027 00028 namespace XrdSys { namespace IOEvents 00029 { 00030 class Poller; 00031 }; }; 00032 00033 namespace XrdCl 00034 { 00035 class AnyObject; 00036 00037 //---------------------------------------------------------------------------- 00039 //---------------------------------------------------------------------------- 00040 class PollerBuiltIn: public Poller 00041 { 00042 public: 00043 //------------------------------------------------------------------------ 00045 //------------------------------------------------------------------------ 00046 PollerBuiltIn() : pNbPoller( GetNbPollerInit() ){} 00047 00048 ~PollerBuiltIn() {} 00049 00050 //------------------------------------------------------------------------ 00052 //------------------------------------------------------------------------ 00053 virtual bool Initialize(); 00054 00055 //------------------------------------------------------------------------ 00057 //------------------------------------------------------------------------ 00058 virtual bool Finalize(); 00059 00060 //------------------------------------------------------------------------ 00062 //------------------------------------------------------------------------ 00063 virtual bool Start(); 00064 00065 //------------------------------------------------------------------------ 00067 //------------------------------------------------------------------------ 00068 virtual bool Stop(); 00069 00070 //------------------------------------------------------------------------ 00075 //------------------------------------------------------------------------ 00076 virtual bool AddSocket( Socket *socket, 00077 SocketHandler *handler ); 00078 00079 00080 //------------------------------------------------------------------------ 00082 //------------------------------------------------------------------------ 00083 virtual bool RemoveSocket( Socket *socket ); 00084 00085 //------------------------------------------------------------------------ 00092 //------------------------------------------------------------------------ 00093 virtual bool EnableReadNotification( Socket *socket, 00094 bool notify, 00095 uint16_t timeout = 60 ); 00096 00097 //------------------------------------------------------------------------ 00104 //------------------------------------------------------------------------ 00105 virtual bool EnableWriteNotification( Socket *socket, 00106 bool notify, 00107 uint16_t timeout = 60); 00108 00109 //------------------------------------------------------------------------ 00111 //------------------------------------------------------------------------ 00112 virtual bool IsRegistered( Socket *socket ); 00113 00114 //------------------------------------------------------------------------ 00116 //------------------------------------------------------------------------ 00117 virtual bool IsRunning() const 00118 { 00119 return !pPollerPool.empty(); 00120 } 00121 00122 private: 00123 00124 //------------------------------------------------------------------------ 00126 //------------------------------------------------------------------------ 00127 XrdSys::IOEvents::Poller* GetNextPoller(); 00128 00129 //------------------------------------------------------------------------ 00131 //------------------------------------------------------------------------ 00132 XrdSys::IOEvents::Poller* RegisterAndGetPoller(const Socket *socket); 00133 00134 //------------------------------------------------------------------------ 00136 //------------------------------------------------------------------------ 00137 void UnregisterFromPoller( const Socket *socket); 00138 00139 //------------------------------------------------------------------------ 00141 //------------------------------------------------------------------------ 00142 XrdSys::IOEvents::Poller* GetPoller(const Socket *socket); 00143 00144 //------------------------------------------------------------------------ 00146 //------------------------------------------------------------------------ 00147 static int GetNbPollerInit(); 00148 00149 // associates channel ID to a pair: poller and count (how many sockets where mapped to this poller) 00150 typedef std::map<const AnyObject *, std::pair<XrdSys::IOEvents::Poller *, size_t> > PollerMap; 00151 00152 typedef std::map<Socket *, void *> SocketMap; 00153 typedef std::vector<XrdSys::IOEvents::Poller *> PollerPool; 00154 00155 SocketMap pSocketMap; 00156 PollerMap pPollerMap; 00157 PollerPool pPollerPool; 00158 PollerPool::iterator pNext; 00159 const int pNbPoller; 00160 XrdSysMutex pMutex; 00161 }; 00162 } 00163 00164 #endif // __XRD_CL_POLLER_BUILT_IN_HH__