CARMA C++
RtdServer.h
Go to the documentation of this file.
1 // $Id: RtdServer.h,v 1.1 2013/07/10 15:37:57 eml Exp $
2 
3 #ifndef SZA_UTIL_RTDSERVER_H
4 #define SZA_UTIL_RTDSERVER_H
5 
16 #include "carma/szautil/Server.h"
17 
18 #define REG_DATA_FN(fn) void (fn)(unsigned nByte, unsigned nEl, unsigned char* src, unsigned char* dest)
19 
20 namespace sza {
21  namespace util {
22 
23  class NetMonitorFrame;
24 
25  class RtdServer : public sza::util::Server {
26  public:
27 
28  //------------------------------------------------------------
29  // A class for maintaining per-register info
30  //------------------------------------------------------------
31 
32  class MonitoredReg {
33  public:
34 
35  MonitoredReg(RegMapBlock* block, unsigned char* srcPtr);
36 
37  // Information describing this register
38 
39  RegMapBlock* block_;
40  unsigned nEl_;
41  unsigned nByte_;
42 
43  // A pointer to the start of the data for this register in the
44  // data frame
45 
46  unsigned char* srcPtr_;
47 
48  // A function for processing the data for this register
49 
50  REG_DATA_FN(*convFn_);
51 
52  // Method to pack data for this register
53 
54  unsigned pack(unsigned char* destPtr);
55 
56  // Possible options for this conversion function
57 
58  static REG_DATA_FN(convertNone);
59  static REG_DATA_FN(convertHtons);
60  static REG_DATA_FN(convertHtonl);
61  };
62 
63  //------------------------------------------------------------
64  // A class for maintaining per-client data
65  //------------------------------------------------------------
66 
67  class ClientData :
68  public Server::ServerData
69  {
70  public:
71 
72  ClientData() {};
73  virtual ~ClientData();
74 
75  RtdClientData clientData_;
76 
77  void processMessage(RtdServer* server,
78  ServerConnection* client,
79  std::map<unsigned, RegMapBlock*>& regMap,
80  std::map<unsigned, unsigned char*>& srcPtrMap);
81 
82  void resize();
83 
84  void pack();
85 
86  std::map<unsigned, MonitoredReg*> monitoredRegs_;
87  };
88 
89  //------------------------------------------------------------
90  // Now method of the RtdServer class itself
91  //------------------------------------------------------------
92 
96  RtdServer(bool spawnThread, unsigned port, NetMonitorFrame* nmf);
97  RtdServer(bool spawnThread, unsigned port, NetMonitorFrame* nmf, int fdRead);
98 
102  virtual ~RtdServer();
103 
104  private:
105 
106  std::map<unsigned, RegMapBlock*> registerBlockMap_;
107  std::map<unsigned, unsigned char*> srcPtrMap_;
108 
109  NetMonitorFrame* nmf_;
110  int fdRead_;
111  RtdClientData clientData_;
112  bool haveRegMap_;
113 
114  void constructMapOfRegisters();
115 
116  void checkForServerData();
117  void processClientData(ServerConnection* client);
118 
119  void sendRegisterMap(ServerConnection* client);
120  void sendRegisterMap();
121 
122  void sendAddRegAck(ServerConnection* client);
123  void sendRemRegAck(ServerConnection* client);
124 
125  void sendDataRegisters();
126  void sendDataRegisters(ServerConnection* client);
127 
128  // Inherited interface from Server
129 
130  void run();
131  void readClientData(ServerConnection* client);
132  void acceptClientAction(ServerConnection* conn);
133 
134  }; // End class RtdServer
135 
136  } // End namespace util
137 } // End namespace sza
138 
139 
140 
141 #endif // End #ifndef SZA_UTIL_RTDSERVER_H
Tagged: Thu Mar 7 15:26:50 PST 2013.