CARMA C++
TransactionManager.h
Go to the documentation of this file.
1 #ifndef SZA_ARRAY_TRANSACTION_H
2 #define SZA_ARRAY_TRANSACTION_H
3 
11 #include <string>
12 #include <list>
13 
14 #include "carma/szaarrayutils/input.h"
15 
16 namespace sza {
17  namespace array {
18 
23  public:
24 
25  static const unsigned DEV_NAME_MAX = 100;
26  static const unsigned SERIAL_NAME_MAX = 20;
27  static const unsigned LOCATION_NAME_MAX = 100;
28  static const unsigned WHO_NAME_MAX = 20;
29  static const unsigned PREFIX_LEN = 5;
30 
35 
39  virtual ~TransactionManager();
40 
44  void readCatalog(std::string dir, std::string file);
45 
49  void printDevices();
50 
54  void printLocations();
55 
59  void printSerialNumbers();
60 
64  void printAll();
65 
66  //------------------------------------------------------------
67  // A location specifier
68  //------------------------------------------------------------
69 
70  struct Location {
71  std::string name_;
72 
73  Location(std::string name) : name_(name) {};
74  };
75 
80  class Location_eq : public std::unary_function<Location, bool> {
81  std::string name_;
82  public:
83  explicit Location_eq(std::string name) : name_(name) {}
84  bool operator() (const Location& location) const {
85  return location.name_ == name_;
86  }
87  };
88 
89  //------------------------------------------------------------
90  // A serial number specifier
91  //------------------------------------------------------------
92 
93  struct SerialNumber {
94  std::string name_;
95 
96  SerialNumber(std::string name) : name_(name) {};
97  };
98 
103  class SerialNumber_eq : public std::unary_function<SerialNumber, bool> {
104  std::string name_;
105  public:
106  explicit SerialNumber_eq(std::string name) : name_(name) {}
107  bool operator() (const SerialNumber& sn) const {
108  return sn.name_ == name_;
109  }
110  };
111 
112  //------------------------------------------------------------
113  // A device specifier
114  //------------------------------------------------------------
115 
116  struct Device {
117  std::string name_;
118 
119  // A list of pointers to valid serial numbers for this device
120 
121  std::list<SerialNumber*> serialNumbers_;
122 
123  // A list of pointers to valid locations for this device
124 
125  std::list<Location*> locations_;
126 
127  Device(std::string name) : name_(name) {};
128  void addLocation(Location* location);
129  void addSerialNumber(SerialNumber* serialNumber);
130  void printLocations();
131  void printSerialNumbers();
132  Location* findLocation(std::string name);
133  SerialNumber* findSerialNumber(std::string name);
134  bool isValidLocation(std::string name);
135  bool isValidSerialNumber(std::string name);
136  };
137 
142  class Device_eq : public std::unary_function<Device, bool> {
143  std::string name_;
144  public:
145  explicit Device_eq(std::string name) : name_(name) {}
146  bool operator() (const Device& device) const {
147  return device.name_ == name_;
148  }
149  };
150 
154  void clearCatalog();
155 
156  private:
157 
158  // The known list of devices
159 
160  std::list<Device> devices_;
161  std::list<Location> locations_;
162  std::list<SerialNumber> serialNumbers_;
163 
164  // Read a location specifier from an input stream
165 
166  void readLocation(Device* device, InputStream* stream);
167 
168  // Read a serialNumber specifier from an input stream
169 
170  void readSerialNumber(Device* device, InputStream* stream);
171 
172  // Read a device specifier from an input stream
173 
174  Device* readDevice(InputStream* stream);
175 
176  public:
177 
178  // Find a device by name
179 
180  Device* findDevice(std::string name);
181 
182  // Return true if this is a valid device
183 
184  bool isValidDevice(std::string name);
185 
186  // Return true if this is a valid serial number/device pair
187 
188  bool isValidSerialNumber(std::string device, std::string serial);
189 
190  // Return true if this is a valid location/device pair
191 
192  bool isValidLocation(std::string device, std::string location);
193 
194  private:
195 
196  // Find a device by name
197 
198  Location* findLocation(std::string name);
199 
200  // Find a serial number by name
201 
202  SerialNumber* findSerialNumber(std::string name);
203 
204  public:
205 
206  /*
207  * Return non-zero if a character isn't a separator character.
208  */
209  static int notSeparatorChar(int c);
210 
211  // Add a device by name
212 
213  Device* addDevice(std::string name);
214 
215  // Add a device by name
216 
217  Location* addLocation(std::string name);
218 
219  // Add a serial number by name
220 
221  SerialNumber* addSerialNumber(std::string name);
222 
223  }; // End class TransactionManager
224 
225  } // End namespace array
226 } // End namespace sza
227 
228 
229 
230 #endif // End #ifndef SZA_ARRAY_TRANSACTION_H
virtual ~TransactionManager()
Destructor.
void printSerialNumbers()
Print known serialNumbers.
A predicate for testing if a Device matches a requested device.
void printDevices()
Print known devices.
A class for managing transactions.
void printLocations()
Print known locations.
A predicate for testing if a Location matches a requested location.
void clearCatalog()
Clear the catalog.
A predicate for testing if a SerialNumber matches a requested sn.
void readCatalog(std::string dir, std::string file)
Read a transaction catalog.
void printAll()
Print the tree of device-&gt;location/serialNumbers.