xrootd
XrdClPollerLibEvent.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_LIBEVENT_HH__
00020 #define __XRD_CL_POLLER_LIBEVENT_HH__
00021 
00022 #include "XrdSys/XrdSysPthread.hh"
00023 
00024 #include "XrdCl/XrdClPoller.hh"
00025 #include <pthread.h>
00026 #include <map>
00027 
00028 struct event_base;
00029 struct event;
00030 
00031 namespace XrdCl
00032 {
00033 
00034   //----------------------------------------------------------------------------
00036   //----------------------------------------------------------------------------
00037   class PollerLibEvent: public Poller
00038   {
00039     public:
00040       //------------------------------------------------------------------------
00042       //------------------------------------------------------------------------
00043       PollerLibEvent(): pEventBase( 0 ), pPollerThreadRunning( false ) {}
00044 
00045       //------------------------------------------------------------------------
00047       //------------------------------------------------------------------------
00048       virtual bool Initialize();
00049 
00050       //------------------------------------------------------------------------
00052       //------------------------------------------------------------------------
00053       virtual bool Finalize();
00054 
00055       //------------------------------------------------------------------------
00057       //------------------------------------------------------------------------
00058       virtual bool Start();
00059 
00060       //------------------------------------------------------------------------
00062       //------------------------------------------------------------------------
00063       virtual bool Stop();
00064 
00065       //------------------------------------------------------------------------
00070       //------------------------------------------------------------------------
00071       virtual bool AddSocket( Socket        *socket,
00072                               SocketHandler *handler );
00073 
00074 
00075       //------------------------------------------------------------------------
00077       //------------------------------------------------------------------------
00078       virtual bool RemoveSocket( Socket *socket );
00079 
00080       //------------------------------------------------------------------------
00087       //------------------------------------------------------------------------
00088       virtual bool EnableReadNotification( Socket  *socket,
00089                                            bool     notify,
00090                                            uint16_t timeout = 60 );
00091 
00092       //------------------------------------------------------------------------
00099       //------------------------------------------------------------------------
00100       virtual bool EnableWriteNotification( Socket  *socket,
00101                                             bool     notify,
00102                                             uint16_t timeout = 60);
00103 
00104       //------------------------------------------------------------------------
00106       //------------------------------------------------------------------------
00107       virtual bool IsRegistered( Socket *socket );
00108 
00109       //------------------------------------------------------------------------
00111       //------------------------------------------------------------------------
00112       virtual bool IsRunning() const
00113       {
00114         return pPollerThreadRunning;
00115       }
00116 
00117       //------------------------------------------------------------------------
00119       //------------------------------------------------------------------------
00120       int RunEventLoop();
00121 
00122     private:
00123       typedef std::map<const Socket *, void *> SocketMap;
00124       SocketMap   pSocketMap;
00125       XrdSysMutex pMutex;
00126       event_base *pEventBase;
00127       pthread_t   pPollerThread;
00128       bool        pPollerThreadRunning;
00129   };
00130 }
00131 
00132 #endif // __XRD_CL_POLLER_LIBEVENT_HH__