Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00008 #ifndef vlistenerthread_h 00009 #define vlistenerthread_h 00010 00013 #include "vsocketthread.h" 00014 #include "vsocket.h" 00015 #include "vmutex.h" 00016 00017 class VSocketFactory; 00018 class VSocketThreadFactory; 00019 class VClientSessionFactory; 00020 00050 class VListenerThread : public VThread { 00051 public: 00052 00081 VListenerThread(const VString& threadBaseName, bool deleteSelfAtEnd, bool createDetached, VManagementInterface* manager, int portNumber, const VString& bindAddress, VSocketFactory* socketFactory, VSocketThreadFactory* threadFactory, VClientSessionFactory* sessionFactory = NULL, bool initiallyListening = true); 00085 virtual ~VListenerThread(); 00086 00092 virtual void stop(); 00099 virtual void run(); 00100 00106 void socketThreadEnded(VSocketThread* socketThread); 00107 00112 int getPortNumber() const; 00113 00122 VSocketInfoVector enumerateActiveSockets(); 00123 00133 void stopSocketThread(VSocketID socketID, int localPortNumber); 00134 00139 void stopAllSocketThreads(); 00145 void startListening() { mShouldListen = true; } 00152 void stopListening() { mShouldListen = false; } 00159 bool isListening() const { return mShouldListen; } 00160 00161 private: 00162 00163 // Prevent copy construction and assignment since there is no provision for sharing the underlying thread 00164 // or the pointer instance variables. 00165 VListenerThread(const VListenerThread& other); 00166 VListenerThread& operator=(const VListenerThread& other); 00167 00172 void _runListening(); 00173 00174 int mPortNumber; 00175 VString mBindAddress; 00176 bool mShouldListen; 00177 VSocketFactory* mSocketFactory; 00178 VSocketThreadFactory* mThreadFactory; 00179 VClientSessionFactory* mSessionFactory; 00180 VSocketThreadPtrVector mSocketThreads; 00181 VMutex mSocketThreadsMutex; 00182 00183 }; 00184 00188 typedef std::vector<VListenerThread*> VListenerThreadPtrVector; 00189 00190 #endif /* vlistenerthread_h */