Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TCP_HPP
00017 #define TCP_HPP
00018
00019 #include "sick_scan/tcp/BasicDatatypes.hpp"
00020 #include <sys/socket.h>
00021 #include <arpa/inet.h>
00022 #include "sick_scan/tcp/Mutex.hpp"
00023 #include "sick_scan/tcp/SickThread.hpp"
00024 #include <list>
00025
00026
00027
00028
00029
00030 class Tcp
00031 {
00032 public:
00033 Tcp();
00034 ~Tcp();
00035
00036
00037 bool open(std::string ipAddress, UINT16 port, bool enableVerboseDebugOutput = false);
00038 bool open(UINT32 ipAddress, UINT16 port, bool enableVerboseDebugOutput = false);
00039 void close();
00040 bool isOpen();
00041 bool write(UINT8* buffer, UINT32 numberOfBytes);
00042 std::string readString(UINT8 delimiter);
00043
00044
00045 UINT32 getNumReadableBytes();
00046 UINT32 read(UINT8* buffer, UINT32 bufferLen);
00047
00048
00049 typedef void (*ReadFunction)(void* obj, UINT8* inputBuffer, UINT32& numBytes);
00050 void setReadCallbackFunction(ReadFunction readFunction, void* obj);
00051
00052
00053 typedef void (*DisconnectFunction)(void* obj);
00054 void setDisconnectCallbackFunction(DisconnectFunction discFunction, void* obj);
00055
00056
00057 private:
00058 bool m_longStringWarningPrinted;
00059 std::string m_rxString;
00060 bool isClientConnected_unlocked();
00061 std::list<unsigned char> m_rxBuffer;
00062 void stopReadThread();
00063 void startServerThread();
00064 void stopServerThread();
00065
00066 struct sockaddr_in m_serverAddr;
00067 bool m_beVerbose;
00068 Mutex m_socketMutex;
00069 #ifndef _MSC_VER
00070 INT32 m_connectionSocket;
00071 #else
00072 SOCKET m_connectionSocket;
00073
00074 #endif
00075 void readThreadFunction(bool& endThread, UINT16& waitTimeMs);
00076 SickThread<Tcp, &Tcp::readThreadFunction> m_readThread;
00077 INT32 readInputData();
00078
00079 ReadFunction m_readFunction;
00080 void* m_readFunctionObjPtr;
00081 DisconnectFunction m_disconnectFunction;
00082 void* m_disconnectFunctionObjPtr;
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00101
00102
00106
00107
00108
00109
00110
00111
00112 };
00113
00114 #endif // TCP_HPP