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 00033 00034 00035 00036 00037 00038 00039 00040 #ifndef __JAUS_CORE_TRANSPORT_TCP_SERVER__H 00041 #define __JAUS_CORE_TRANSPORT_TCP_SERVER__H 00042 00043 #include "jaus/core/transport/transport.h" 00044 #include <cxutils/networking/tcpserver.h> 00045 00046 namespace JAUS 00047 { 00048 class TransportManager; 00049 typedef CxUtils::IP4Address IP4Address; 00050 00060 class JAUS_CORE_DLL JTCP 00061 { 00062 public: 00063 const static unsigned short Port = 3794; 00064 const static unsigned int OverheadSizeBytes = 61; 00065 const static Byte Version = 0x02; 00066 JTCP(); 00067 virtual ~JTCP(); 00068 // Initializes, creating a thread for receiving TCP data. 00069 virtual bool Initialize(TransportManager* manager, CxUtils::Socket* socket); 00070 // Shutsdown the transport service. 00071 virtual void Shutdown(); 00072 // Sets the delay time in ms for stream polling loop. 00073 virtual void SetPacketPollingDelayMs(const unsigned int delayTimeMs = 0); 00074 // Gets a pointer to the socket. 00075 CxUtils::Socket* GetSocket() { return mpSocket; } 00076 // Gets a pointer to the socket. 00077 const CxUtils::Socket* GetSocket() const { return mpSocket; } 00078 // Gets the update time (when last message was received). 00079 JAUS::Time GetUpdateTime() const; 00080 // Gets the address of the component that last sent a message. 00081 JAUS::Address GetLastSourceID() const; 00082 // Flag set if connection is on the current machine. 00083 bool IsLocalConnection() const { return mLocalConnectionFlag; } 00084 protected: 00085 virtual void ProcessPacket(Packet& packet, 00086 Header& header, 00087 const IP4Address& ipAddress, 00088 const unsigned short sourcePort); 00089 virtual bool ExitThread() const { return false; } 00090 static void ReceiveThread(void* args); 00091 Mutex mDataMutex; 00092 Thread mRecvThread; 00093 unsigned int mDelayTimeMs; 00094 CxUtils::Socket* mpSocket; 00095 TransportManager* mpManager; 00096 Time mUpdateTime; 00097 volatile bool mReceivedValidDataFlag; 00098 Address mLastSourceID; 00099 bool mLocalConnectionFlag; 00100 }; 00101 } 00102 00103 #endif 00104 /* End of File */