00001 /* 00002 Author: Adam Hunt 00003 email: ahunt@princeton.edu 00004 Date: 2007-08-24 00005 */ 00006 00007 00008 /* 00009 Error Codes 00010 0: unknown failure 00011 1: success 00012 101: invalid port 00013 iana.org registers ports from 0 - 1023 00014 201: invalid mode 00015 Acceptable modes are 0: tcp data, 1: constant fake data, 2: random fake data 00016 301: socket() failed 00017 302: connect() failed 00018 401: Disconnect() called without being connected 00019 501: Failed to Receive Data from server 00020 601; close() failed 00021 00022 TODO: This should be changed to errno. 00023 00024 */ 00025 00026 #ifndef HLXTCP_H 00027 #define HLXTCP_H 00028 00029 #include <string> 00030 #include <netinet/in.h> // struct sockaddr_in 00031 00032 namespace HCAL_HLX{ 00033 00034 struct LUMI_SECTION; 00035 00036 class TCPReceiver{ 00037 00038 public: 00039 TCPReceiver(); 00040 TCPReceiver(unsigned short int, std::string, unsigned char); 00041 ~TCPReceiver(); 00042 int Connect(); 00043 int SetPort(unsigned short int); 00044 int SetMode(unsigned char); 00045 void SetIP(std::string IP); 00046 int ReceiveLumiSection(HCAL_HLX::LUMI_SECTION & localSection); 00047 int Disconnect(); 00048 bool IsConnected(); 00049 bool VerifyFakeData(HCAL_HLX::LUMI_SECTION & localSection); 00050 00051 void GenerateFakeData(HCAL_HLX::LUMI_SECTION & localSection); 00052 void GenerateRandomData(HCAL_HLX::LUMI_SECTION & localSection); 00053 00054 private: 00055 unsigned char acquireMode; 00056 bool Connected; 00057 00058 unsigned short servPort; 00059 std::string servIP; 00060 int tcpSocket; 00061 struct sockaddr_in servAddr; 00062 }; 00063 } 00064 00065 #endif