CARMA C++
SaxHandler.h
Go to the documentation of this file.
1 
9 #ifndef CARMA_DBMS_SAXHANDLER_H
10 #define CARMA_DBMS_SAXHANDLER_H
11 
12 
13 #include <xercesc/sax/HandlerBase.hpp>
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include "MonitorDescription.h"
18 
19 XERCES_CPP_NAMESPACE_USE
20 
21 namespace carma {
22 namespace dbms {
23 
24 
25 class SaxHandler : public HandlerBase {
26 public:
27  typedef enum {SUBSYSTEM, CONTAINER, POINT, SHORT, LONG, UNITS,
28  DESCRIPTION, INTEGRATE, WARNLO, WARNHI, ERRLO, ERRHI,
29  ENDELEMENT} currentElementType;
30 
31  SaxHandler() {};
32  virtual ~SaxHandler() {};
33 
34  // SAX DocumentHandler methods
35  // - parses data between start and end tags
36  void characters(const XMLCh *const chars, const unsigned int length);
37  // - parses start tag, including attributes
38  void startElement(const XMLCh *const elementName,
39  AttributeList &attributes);
40  // - parses end tag ... use this to avoid parsing whitespace or other data
41  // not contained within an element
42  void endElement(const XMLCh *const elementName);
43 
44  // processing methods
45  // - process container element
46  //void processContainer(AttributeList &attributes);
47  void processContainer(const std::string& containerType,
48  AttributeList &attributes);
54  void processPoint(MonitorPointType type, AttributeList &attributes);
55 
60  void processEnum(const AttributeList& attributes);
61 
62 
63  // SAX ErrorHandler methods
64  void warning(const SAXParseException &ex);
65  void error(const SAXParseException &ex);
66  void fatalError(const SAXParseException &ex);
67 
68  // load monitor point into DB
69  // void loadDescription(MonitorDescription
70 
74  std::string getContainerName();
75 
80  std::vector<std::string> getCombinations(
81  const std::vector<char *>& names,
82  const std::vector<unsigned>& count,
83  const std::string& prepend="")
84  const;
85 
86 
87  inline std::vector<carma::dbms::MonitorDescription>
88  getMonitorDescriptions() const {
89  return monitorDescriptions_;
90  }
91 
92  inline std::string getAggregateSubsystemName() const {
93  return aggregateSubsystemName_;
94  }
95 
96  inline unsigned getAggregateSubsystemCount() const {
97  return aggregateSubsystemCount_;
98  }
99 
100  inline unsigned getAggregateSubsystemMaxSamples() const {
101  return aggregateSubsystemMaxSamples_;
102  }
103 
104  inline unsigned getAggregateSubsystemMaxPoints() const {
105  return aggregateSubsystemMaxPoints_;
106  }
107 
108 private:
109 
110  std::string getLocation(const std::string& cname) const;
111  std::string getDevice(const std::string& cname) const;
112 
113  // monitorDescription class defined in MonitorDescription.h
114  std::map<std::string, MonitorDescription*> monitorPoints_;
115  //currentElementType currentElement_; // - current element being parsed
116  std::vector<std::string> elementStack_;
117  // names of containers being parsed, the first element is the subsystem
118  // name
119  // this contains a list of currently applicable Container[@name]'s and
120  // Container[@count]'s (default @count = 1). Containers include
121  // <Subsystem>,<Container>, and <Device>
122 
123  std::vector<char*> containerNames_;
124  std::vector<unsigned> containerCount_;
125 
126  enum CONTAINER_TYPE {C_SUBSYSTEM, C_CONTAINER, C_DEVICE};
127 
128  std::vector<CONTAINER_TYPE> containerTypes_;
129 
130  std::string currentEnumerator_;
131 
132  std::string location_;
133  typedef struct {
134  std::string name;
135  std::string id;
136  } Device;
137 
138  std::vector<Device> devices_;
139 
140  // container for temporary use
141  std::vector<MonitorDescription> currentMonitorDescriptions_;
142  // all monitor descriptions should end up here
143  std::vector<carma::dbms::MonitorDescription> monitorDescriptions_;
144 
145  // subsystem information (name, count)
146  std::string aggregateSubsystemName_;
147  unsigned aggregateSubsystemCount_;
148  unsigned aggregateSubsystemMaxSamples_;
149  unsigned aggregateSubsystemMaxPoints_;
150  // is the parser currently reading inside a MonitorPoint (or similar)
151  // element?
152  //bool processingPoint_;
153 
154 }; // end class SaxHandler
155 }; // end namespace dbms
156 }; // end namespace carma
157 
158 #endif
MonitorPointType
describes to what class this monitor point belongs