Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PeerFinderH
00033 #define PeerFinderH
00034
00035 #include <zeusbase/System/SingleLinkedList.hpp>
00036 #include <zeusbase/System/Thread.h>
00037 #include <zeusbase/System/Interfaces/ISubject.hpp>
00038
00039 BEGIN_NAMESPACE_Zeus
00040
00041 class TDatagramSocket;
00042 class TDatagramPacket;
00043 class TCriticalSection;
00044 class IPeerFinderObserver;
00045
00046
00050
00051 zeusbase_class TPeerFinder : public TThread, public ISubject
00052 {
00053 public:
00054 TPeerFinder(Uint uiListeningPort, Uint uiProviderPort);
00055 TPeerFinder(const TString& rListeningAddress, Uint uiListeningPort, Uint uiProviderPort);
00056
00057 void setContinueSearching(bool bMode);
00058 void startSearch();
00059 void stopSearch();
00060 void setProviderAddress(const TString& rProviderAddress);
00061 void setQueryTimeout(const Float& rfTimeout);
00062 void setReceivingTimeout(const Float& rfTimeout);
00063
00064
00065 virtual bool signalizeStop(Float64 dTimeOut=5.0);
00066
00067
00068 virtual Retval MQUALIFIER attach(IObserver& rObserver);
00069 virtual Retval MQUALIFIER detach(IObserver& rObserver);
00070
00071
00072 MEMORY_MANAGER_DECL
00073
00074 protected:
00075 virtual ~TPeerFinder();
00076 virtual void execute();
00077
00078 void notifyPeerFound(TDatagramPacket& rPacket);
00079
00080 private:
00082 TDatagramSocket& m_rDatagramSocket;
00084 Uint m_uiProviderPort;
00086 Float m_fReceiveTimeout;
00088 Float m_fQueryTimeout;
00090 TSingleLinkedList<IPeerFinderObserver*> m_lstObserver;
00092 TString m_strProviderAddress;
00094 TCriticalSection& m_rLock;
00096 bool m_bContinueSearch;
00097
00098 void create();
00099 void releaseInstances();
00100 };
00101
00102
00105
00106 inline void TPeerFinder::setContinueSearching(bool bMode)
00107 {
00108 m_bContinueSearch = bMode;
00109 }
00110
00111
00114
00115 inline void TPeerFinder::setQueryTimeout(const Float& rfTimeout)
00116 {
00117 m_fQueryTimeout = rfTimeout;
00118 }
00119
00120
00123
00124 inline void TPeerFinder::setReceivingTimeout(const Float& rfTimeout)
00125 {
00126 m_fReceiveTimeout = rfTimeout;
00127 }
00128
00129
00132
00133 inline void TPeerFinder::startSearch()
00134 {
00135 this->start();
00136 }
00137
00138
00141
00142 inline void TPeerFinder::stopSearch()
00143 {
00144 this->signalizeStop(m_fReceiveTimeout);
00145 }
00146
00147 END_NAMESPACE_Zeus
00148
00149
00150 #endif