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 00041 #ifndef __JAUS_CORE_TRANSPORT_TRANSPORT_TransportManager__H 00042 #define __JAUS_CORE_TRANSPORT_TRANSPORT_TransportManager__H 00043 00044 00045 #include "jaus/core/message.h" 00046 #include "jaus/core/transport/jtcpclient.h" 00047 #include <cxutils/networking/udpclient.h> 00048 #include <cxutils/networking/tcpserver.h> 00049 00050 namespace JAUS 00051 { 00061 class JAUS_CORE_DLL TransportManager 00062 { 00063 public: 00064 static const int TCP = 0; 00065 static const int UDP = 1; 00066 static const int Serial = 2; 00067 TransportManager(); 00068 virtual ~TransportManager(); 00069 // Check if this TransportManager is active. 00070 bool IsInitialized() const { return mTcpListenThread.IsThreadActive(); } 00071 // Loads settings from a JAUS file. 00072 virtual bool LoadSettings(const std::string& filename); 00073 // Initializes using loaded/pre-defines settings. 00074 virtual bool Initialize(); 00075 // Shutsdown all transport comms. 00076 virtual void Shutdown(); 00077 // Method called periodically by Component or other Services, can be used for periodic udpdates. 00078 virtual void CheckServiceStatus(const unsigned int timeSinceLastCheckMs); 00079 // Process packet data that needs to be routed 00080 void ProcessPacket(Packet& packet, 00081 Header& header, 00082 const IP4Address& ipAddress, 00083 const unsigned short sourcePort, 00084 const int transport); 00085 // Turns on debug messages to console window. 00086 virtual void EnableDebugMessages(const bool on) { mDebugMessagesFlag = true; } 00087 // Adds a connection to a specific IP address. 00088 bool AddConnection(const IP4Address& networkIP, 00089 const Address& jausID); 00090 // Gets the number of internal local connections. 00091 unsigned int GetNumLocalClients() const; 00092 protected: 00093 static void TcpListenThread(void* args); 00094 static void UdpReceiveThread(void* args); 00095 bool mUseTcpFlag; 00096 IP4Address mHostIP; 00097 Mutex mDebugMessagesMutex; 00098 volatile bool mDebugMessagesFlag; 00099 unsigned int mDelayTimeMs; 00100 // JUDP Data 00101 CxUtils::Mutex mUdpMutex; 00102 CxUtils::UdpClient mUdpSocket; 00103 unsigned int mMaxPayloadSize; 00104 unsigned char mTimeToLive; 00105 CxUtils::IP4Address mMulticastIP; 00106 bool mUseBroadcastingFlag; 00107 Time::Stamp mDisconnectTimeMs; 00108 CxUtils::Thread mUdpReceiveThread; 00109 std::map<Address, CxUtils::UdpClient*> mUdpConnections; 00110 std::map<Address, Time::Stamp> mUpdateTimes; 00111 // JTCP Data 00112 Mutex mTcpMutex; 00113 CxUtils::TcpListenSocket mListenSocket; 00114 CxUtils::Thread mTcpListenThread; 00115 std::map<Address, JTCP*> mTcpConnections; 00116 std::vector<JTCP*> mUnknownConnections; 00117 // Other information 00118 std::map<Address, IP4Address> mPermanentConnections; 00119 }; 00120 } 00121 00122 #endif 00123 /* End of File */