Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:39

0001 /*
0002   Author: Adam Hunt
0003   email:  ahunt@princeton.edu
0004   Date:   2007-08-24
0005 */
0006 
0007 /* 
0008    Error Codes
0009        0: unknown failure
0010        1: success
0011      101: invalid port
0012         iana.org registers ports from 0 - 1023
0013      201: invalid mode
0014         Acceptable modes are 0:  tcp data,  1: constant fake data, 2: random fake data
0015      301: socket() failed
0016      302: connect() failed
0017      401: Disconnect() called without being connected
0018      501: Failed to Receive Data from server
0019      601; close() failed
0020 
0021 TODO: This should be changed to errno.
0022 
0023 */
0024 
0025 #ifndef HLXTCP_H
0026 #define HLXTCP_H
0027 
0028 #include <string>
0029 #include <netinet/in.h>  // struct sockaddr_in
0030 
0031 namespace HCAL_HLX {
0032 
0033   struct LUMI_SECTION;
0034 
0035   class TCPReceiver {
0036   public:
0037     TCPReceiver();
0038     TCPReceiver(unsigned short int, std::string, unsigned char);
0039     ~TCPReceiver();
0040     int Connect();
0041     int SetPort(unsigned short int);
0042     int SetMode(unsigned char);
0043     void SetIP(std::string IP);
0044     int ReceiveLumiSection(HCAL_HLX::LUMI_SECTION& localSection);
0045     int Disconnect();
0046     bool IsConnected();
0047     bool VerifyFakeData(HCAL_HLX::LUMI_SECTION& localSection);
0048 
0049     void GenerateFakeData(HCAL_HLX::LUMI_SECTION& localSection);
0050     void GenerateRandomData(HCAL_HLX::LUMI_SECTION& localSection);
0051 
0052   private:
0053     unsigned char acquireMode;
0054     bool Connected;
0055 
0056     unsigned short servPort;
0057     std::string servIP;
0058     int tcpSocket;
0059     struct sockaddr_in servAddr;
0060   };
0061 }  // namespace HCAL_HLX
0062 
0063 #endif