CARMA C++
RtdServerTask.h
Go to the documentation of this file.
1 // $Id: RtdServerTask.h,v 1.2 2013/11/19 22:55:28 eml Exp $
2 
3 #ifndef SZA_UTIL_RTDSERVERTASK_H
4 #define SZA_UTIL_RTDSERVERTASK_H
5 
15 #include "carma/szautil/BitMask.h"
18 #include "carma/szautil/ServerTask.h"
19 
20 #define REG_DATA_FN(fn) void (fn)(unsigned nByte, unsigned nEl, unsigned char* src, unsigned char* dest)
21 
22 namespace sza {
23  namespace util {
24 
25  class NetMonitorFrame;
26 
27  //------------------------------------------------------------
28  // A message class for use with this task
29  //------------------------------------------------------------
30 
31  class RtdServerMsg : public GenericTaskMsg {
32  public:
33 
34  enum MsgType {
35  ADD_REG = 0x1,
36  REM_REG = 0x2,
37  };
38 
39  union {
40  unsigned regId_;
41  } body;
42 
43  // A type for this message
44 
45  MsgType type;
46  };
47 
48  class RtdServerTask : public sza::util::ServerTask<RtdServerMsg> {
49  public:
50 
51  //------------------------------------------------------------
52  // A class for maintaining per-register info
53  //------------------------------------------------------------
54 
55  class MonitoredReg {
56  public:
57 
58  MonitoredReg(RegMapBlock* block, unsigned char* srcPtr, BitMask* validityBitMask);
59 
60  // Information describing this register
61 
62  RegMapBlock* block_;
63  unsigned nEl_;
64  unsigned nByte_;
65 
66  // A pointer to the start of the data for this register in the
67  // data frame
68 
69  unsigned char* srcPtr_;
70  BitMask* validityBitMask_;
71 
72  // A function for processing the data for this register
73 
74  REG_DATA_FN(*convFn_);
75 
76  // Method to pack data for this register
77 
78  unsigned pack(unsigned char* destPtr);
79 
80  // Possible options for this conversion function
81 
82  static REG_DATA_FN(convertNone);
83  static REG_DATA_FN(convertHtons);
84  static REG_DATA_FN(convertHtonl);
85  static REG_DATA_FN(convertDouble);
86  static REG_DATA_FN(convertPairedFourByteType);
87  };
88 
89  //------------------------------------------------------------
90  // A class for maintaining per-client data
91  //------------------------------------------------------------
92 
93  class ClientData :
94  public ServerTask<RtdServerMsg>::ServerData
95  {
96  public:
97 
98  ClientData() {};
99  virtual ~ClientData();
100 
101  RtdClientData clientData_;
102 
103  void processMessage(RtdServerTask* server,
104  ServerConnection* client,
105  std::map<unsigned, RegMapBlock*>& regMap,
106  std::map<unsigned, unsigned char*>& srcPtrMap);
107 
108  void resize();
109 
110  void pack();
111 
112  std::map<unsigned, MonitoredReg*> monitoredRegsMap_;
113  std::list<MonitoredReg*> monitoredRegsList_;
114  };
115 
116  //------------------------------------------------------------
117  // Now method of the RtdServerTask class itself
118  //------------------------------------------------------------
119 
123  RtdServerTask(bool spawnThread, unsigned port, NetMonitorFrame* nmf);
124  RtdServerTask(bool spawnThread, unsigned port, NetMonitorFrame* nmf, int fdRead);
125 
129  virtual ~RtdServerTask();
130 
131  void run();
132 
133  private:
134 
135  std::map<unsigned, RegMapBlock*> registerBlockMap_;
136  std::map<unsigned, unsigned char*> srcPtrMap_;
137 
138  unsigned char* vRegPtr_;
139  RegMapBlock* vRegBlk_;
140  BitMask validityBitMask_;
141 
142  NetMonitorFrame* nmf_;
143  int fdRead_;
144  RtdClientData clientData_;
145  bool haveRegMap_;
146 
147  void constructMapOfRegisters();
148 
149  void checkForServerData();
150  void processClientData(ServerConnection* client);
151 
152  void sendRegisterMap(ServerConnection* client);
153  void sendRegisterMap();
154 
155  void sendAddRegAck(ServerConnection* client);
156  void sendRemRegAck(ServerConnection* client);
157 
158  void sendDataRegisters();
159  void sendDataRegisters(ServerConnection* client);
160 
161  // Inherited interface from Server
162 
163  void readClientData(ServerConnection* client);
164  void acceptClientAction(ServerConnection* conn);
165 
166  }; // End class RtdServerTask
167 
168  } // End namespace util
169 } // End namespace sza
170 
171 
172 
173 #endif // End #ifndef SZA_UTIL_RTDSERVERTASK_H
Tagged: Tue Mar 6 16:39:02 PST 2012.
Tagged: Thu Mar 7 15:26:50 PST 2013.
Tagged: Fri Nov 14 12:39:34 UTC 2003.