CARMA C++
SzaRtdUtils.h
Go to the documentation of this file.
1 // $Id: SzaRtdUtils.h,v 1.8 2013/11/19 03:41:14 iws Exp $
2 
3 #ifndef CARMA_UI_RTD_SZARTDUTILS_H
4 #define CARMA_UI_RTD_SZARTDUTILS_H
5 
15 #include "carma/ui/rtd/common/MonitorDisplay.h"
18 #include <boost/shared_ptr.hpp>
19 #include <iostream>
20 
21 #define SZA_COL_ADD_FN(fn) std::vector<MonitorCellPtr> (fn)(carma::monitor::MonitorContainer* container, unsigned colWidth)
22 #define SZA_ROW_ADD_FN(fn) std::vector<MonitorCellPtr> (fn)(carma::monitor::MonitorContainer* container, unsigned colWidth)
23 #define SZA_LABEL_FN(fn) std::vector<std::string> (fn)()
24 #define SZA_CONTAINER_FN(fn) carma::monitor::MonitorContainer* (fn)(carma::monitor::SzaSubsystem& subsystem)
25 
26 #define GENERIC_COLUMN_FN(fn) std::vector<SzaRtdUtils::RtdColumn*> (fn)(MonitorDisplay& display)
27 #define GENERIC_ROW_FN(fn) std::vector<SzaRtdUtils::RtdRow*> (fn)(MonitorDisplay& display)
28 
29 #define CAN_RECEIVED_MP(container) \
30  SzaRtdUtils::cell_ = MonitorCellMapped::makeCell(colWidth, container->received(), "OFFLINE");\
31  SzaRtdUtils::colorMap_.clear();\
32  SzaRtdUtils::colorMap_["OFFLINE"] = RED_CELL_COLOR;\
33  SzaRtdUtils::cell_->setColorMap(SzaRtdUtils::colorMap_);\
34  SzaRtdUtils::cell_->setDefaultLabel("ONLINE");\
35  SzaRtdUtils::cell_->setDefaultColor(GREEN_CELL_COLOR);\
36  col.push_back(SzaRtdUtils::cell_);
37 
38 #define BINARY_MAPPED_MP(mp, state1Label, state2Label, state1Color, state2Color) \
39  SzaRtdUtils::cell_ = MonitorCellMapped::makeCell(colWidth, mp, state1Label, state2Label);\
40  SzaRtdUtils::colorMap_.clear();\
41  SzaRtdUtils::colorMap_[state1Label] = state1Color;\
42  SzaRtdUtils::colorMap_[state2Label] = state2Color;\
43  SzaRtdUtils::cell_->setColorMap(SzaRtdUtils::colorMap_);\
44  col.push_back(SzaRtdUtils::cell_);
45 
46 #define BOOLEAN_MAPPED_MP(mp, state1Label, state2Label, state1Color, state2Color) \
47  {\
48  std::map<std::string, std::string> labelMap; \
49  labelMap["false"] = state1Label;\
50  labelMap["true"] = state2Label;\
51  SzaRtdUtils::cell_ = MonitorCellMapped::makeCell(colWidth, mp, labelMap);\
52  SzaRtdUtils::colorMap_.clear();\
53  SzaRtdUtils::colorMap_[state1Label] = state1Color;\
54  SzaRtdUtils::colorMap_[state2Label] = state2Color;\
55  SzaRtdUtils::cell_->setColorMap(SzaRtdUtils::colorMap_);\
56  col.push_back(SzaRtdUtils::cell_);\
57  }
58 
59 #define BINARY_BIT_MAPPED_MP(mp, bit, state1Label, state2Label, state1Color, state2Color) \
60  SzaRtdUtils::cell_ = MonitorCellMapped::makeCell(colWidth, mp, bit, state1Label, state2Label); \
61  SzaRtdUtils::colorMap_.clear();\
62  SzaRtdUtils::colorMap_[state1Label] = state1Color;\
63  SzaRtdUtils::colorMap_[state2Label] = state2Color;\
64  SzaRtdUtils::cell_->setColorMap(SzaRtdUtils::colorMap_);\
65  col.push_back(SzaRtdUtils::cell_);
66 
67 namespace carma {
68  namespace ui {
69  namespace rtd {
70 
71  class MonitorCellMapped;
72  typedef boost::shared_ptr<MonitorCellMapped> MonitorCellMappedPtr;
73 
74  class SzaRtdUtils {
75  public:
76 
77  struct RtdColumn {
78 
79  RtdColumn(std::string name, carma::monitor::MonitorContainer& container) {
80  name_ = name;
81  container_ = &container;
82  }
83 
84  std::string name_;
86  };
87 
88  struct RtdRow {
89 
90  RtdRow(std::string name, carma::monitor::MonitorContainer& container) {
91  name_ = name;
92  container_ = &container;
93  }
94 
95  std::string name_;
97  };
98 
102  SzaRtdUtils();
103 
107  virtual ~SzaRtdUtils();
108 
109  // Generic function to add a column to a table
110 
111  static void addColumn(carma::monitor::SzaSubsystem& subsystem, RtTablePtr table,
112  SZA_CONTAINER_FN(*conFn), SZA_COL_ADD_FN(*fn), unsigned colWidth);
113 
114  static void addColumn(carma::monitor::MonitorContainer* container, RtTablePtr table,
115  SZA_COL_ADD_FN(*fn), unsigned colWidth);
116 
117  // Generic function to add a table to a folder
118 
119  static void addTable(MonitorDisplay& display, RtFolderPtr folder, std::string tableName,
120  SZA_CONTAINER_FN(*conFn), SZA_COL_ADD_FN(*fn), SZA_LABEL_FN(*labFn), unsigned colWidth);
121 
122  static void addTable(MonitorDisplay& display, RtFolderPtr folder, std::string tableName,
123  GENERIC_COLUMN_FN(*columnFn), SZA_COL_ADD_FN(*columnAddFn), SZA_LABEL_FN(*rowLabelFn), unsigned colWidth);
124 
125  static void addTable(MonitorDisplay& display, RtFolderPtr folder, std::string tableName,
126  GENERIC_ROW_FN(*rowFn), SZA_ROW_ADD_FN(*rowAddFn), SZA_LABEL_FN(*colLabelFn),
127  std::vector<unsigned>& colWidths);
128 
129  static void addTable(MonitorDisplay& display, RtFolderPtr folder, std::string tableName,
130  GENERIC_ROW_FN(*rowFn), SZA_ROW_ADD_FN(*rowAddFn), SZA_LABEL_FN(*colLabelFn),
131  unsigned colWidth);
132 
133  // Generic function to add a folder to an RTD page
134 
135  static void addFolder(MonitorDisplay& display, std::string folderName,
136  SZA_CONTAINER_FN(*conFn), SZA_COL_ADD_FN(*colFn), SZA_LABEL_FN(*labFn), unsigned colWidth);
137 
138  static void addFolder(MonitorDisplay& display, std::string folderName,
139  GENERIC_COLUMN_FN(*columnFn), SZA_COL_ADD_FN(*columnAddFn), SZA_LABEL_FN(*rowLabelFn), unsigned colWidth);
140 
141  static void addFolder(MonitorDisplay& display, std::string folderName,
142  GENERIC_ROW_FN(*rowFn), SZA_ROW_ADD_FN(*rowAddFn), SZA_LABEL_FN(*columnLabelFn),
143  std::vector<unsigned>& colWidths);
144 
145  static void addFolder(MonitorDisplay& display, std::string folderName,
146  GENERIC_ROW_FN(*rowFn), SZA_ROW_ADD_FN(*rowAddFn), SZA_LABEL_FN(*columnLabelFn),
147  unsigned colWidth);
148 
149  // A wrapper around addFolder to add the XAC folder that's
150  // common to every CAN module
151 
152  static void addXacFolder(MonitorDisplay& display, std::string moduleName,
153  SZA_CONTAINER_FN(*conFn));
154 
155  static void addCanModule(MonitorDisplay& display, std::string moduleName,
156  SZA_CONTAINER_FN(*conFn), SZA_COL_ADD_FN(*colFn), SZA_LABEL_FN(*labFn), unsigned colWidth);
157 
158  static SZA_LABEL_FN(getBiasLabels);
159  static SZA_COL_ADD_FN(getBiasColumn);
160  static SZA_CONTAINER_FN(getBiasContainer);
161 
162  static SZA_COL_ADD_FN(getIntmodColumn);
163  static SZA_LABEL_FN(getIntmodLabels);
164  static SZA_CONTAINER_FN(getIntmodContainer);
165 
166  static SZA_LABEL_FN(getVaractorLabels);
167  static SZA_COL_ADD_FN(getVaractorColumn);
168  static SZA_CONTAINER_FN(getVaractorContainer);
169 
170  static SZA_LABEL_FN(getYigLabels);
171  static SZA_COL_ADD_FN(getYigColumn);
172  static SZA_CONTAINER_FN(getYigContainer);
173 
174  static MonitorCellMappedPtr cell_;
175  static std::map<std::string, CellColor> colorMap_;
176 
177  private:
178 
179  static const unsigned nSza_;
180  static const unsigned szaOffsetInCarma_;
181 
182  static SZA_LABEL_FN(getXacLabels);
183  static SZA_COL_ADD_FN(getXacColumn);
184 
185  }; // End class SzaRtdUtils
186 
187  } // End namespace rtd
188  } // End namespace ui
189 } // End namespace carma
190 
191 
192 
193 #endif // End #ifndef CARMA_UI_RTD_SZARTDUTILS_H
The monitor system base class.
Cell that takes a MonitorPoint and displays its current value.
A generic monitor system container base class.