openETCS
case study for the European Train Control System developed for the authors dissertation
DriverMachineInterfaceMOC.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2012
3  Johannes Feuser <feuser@uni-bremen.de>
4  This file is part of the openETCS library.
5 
6  The openETCS library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  any later version.
10 
11  The openETCS library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with the openETCS library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*!
21  * \author Johannes Feuser <feuser@uni-bremen.de>
22  * \brief driver machine classes for observer usage
23  */
24 
25 #ifndef __OETCS_DF_DRIVERMACHINEINTERFACEMOC_H__
26 #define __OETCS_DF_DRIVERMACHINEINTERFACEMOC_H__
27 
28 
29 
30 #include <QtGui>
31 #include <iostream>
32 #include "oETCS/DF/PS/SIM/DMIAdaptor.h"
33 
34 #include <QWidget>
35 #include <vector>
36 #include <QString>
37 #include <QStringList>
38 #include <QGridLayout>
39 #include <QLabel>
40 #include <QPushButton>
41 #include <QMutex>
42 #include "EVCStateMachine.h"
43 #include "FunctionBlocks.h"
44 
45 
46 
47 
48 namespace oETCS { namespace DF { class CEVCStateMachine; } }
49 namespace oETCS { namespace DF { struct CDMISubject; } }
50 
51 
52 namespace oETCS {
53 
54 namespace DF {
55 
56 
57 /*!
58  * \brief Driver Machine Interface Qt4 class
59  *
60  * Observer implementation as Qt4 QWidget.
61  */
63 {
64  Q_OBJECT
65  public:
66  /*!
67  * \brief general constructor
68  *
69  * Attaches the concrete Qt4 observer to a EVC state machine object.
70  *
71  * \param[in] pStateMachine pointer to the related state machine
72  * \param[in] pWidgetParent optional pointer to the parent QWidget object
73  * \param[in] bSimAdaptor optional flag to actiavate instance as D-Bus adaptor for simulation
74  */
75  explicit CDMIQWidget(oETCS::DF::CEVCStateMachine * const pStateMachine, QWidget * pWidgetParent = 0, const bool & bSimAdaptor = false) throw();
76 
77 
78 
79  /*!
80  * \brief destructor
81  */
82  virtual ~CDMIQWidget() throw();
83 
84 
85 
86  /*!
87  * \brief updates the observer representation
88  */
89  virtual void Update() throw();
90 
91 
92 
93  /*!
94  * \brief notifies an observer about it was detached by the EVC state machine
95  *
96  * In the implementation for the Qt observer this cause a closing of the QWidget.
97  */
98  virtual void Detached() throw();
99 
100 
101 
102  /*!
103  * \brief checks, if an element is part of an vector
104  *
105  * \param[in] Element element to be searched in container
106  * \param[in] Container container to be searched in
107  *
108  * \return true, if element is found
109  */
110  template< class ELEMENT_T, class CONTAINER_T = ::std::vector< ELEMENT_T > >
111  static inline bool IsPartOf(const ELEMENT_T& Element, const CONTAINER_T& Container) throw();
112 
113 
114 
115 
116  Q_SIGNALS:
117  /*!
118  * \brief signal emited, if a Update() message from the EVC state machine was received
119  */
120  void Updated();
121 
122 
123 
124  /*!
125  * \brief signal for sending an error
126  *
127  * This signal should be emitted in the case that an error in the HW ocurres.
128  *
129  * \param[in] ErrorMessage textual description of the error
130  */
131  void Error(const ::QString& ErrorMessage);
132 
133 
134 
135 
136  public Q_SLOTS:
137  /*!
138  * \brief slot for notification about entered data
139  */
140  void DataEntered() throw();
141 
142 
143 
144  /*!
145  * \brief slot after a Update() message from the EVC State Machine
146  *
147  * \remark connected with the Updated() signal due to multi threading
148  */
149  virtual void UpdateSlot() throw();
150 
151 
152 
153  /*!
154  * \brief gets all active inputs
155  *
156  * \return list of active/enabled inputs
157  */
158  QStringList GetInputs();
159 
160 
161 
162  /*!
163  * \brief gets all available ouputs
164  *
165  * \return list of all all outputs
166  */
167  ::QStringList GetOutputs();
168 
169 
170 
171  /*!
172  * \brief gets a value of a certain output
173  *
174  * \param[in] OutputName name of the output field
175  *
176  * \return output value
177  */
178  QString GetOutputValue(const QString & OutputName);
179 
180 
181 
182  /*!
183  * \brief gets the flag for the existence of any input field
184  *
185  * \return true, if any input field exists
186  */
187  bool HasInput();
188 
189 
190 
191  /*!
192  * \brief sets a value of an boolean input field
193  *
194  * \param[in] InputName name of the input field
195  * \param[in] bValue new value
196  */
197  void SetBooleanValue(const QString & InputName, bool bValue);
198 
199 
200 
201  /*!
202  * \brief sets a value of an double input field
203  *
204  * \param[in] InputName name of the input field
205  * \param[in] dValue new value
206  */
207  void SetDoubleValue(const QString & InputName, double dValue);
208 
209 
210 
211  /*!
212  * \brief sets a value of an integer input field
213  *
214  * \param[in] InputName name of the input field
215  * \param[in] iValue new value
216  */
217  void SetIntegerValue(const QString & InputName, int iValue);
218 
219 
220 
221  /*!
222  * \brief sets a value of an string input field
223  *
224  * \param[in] InputName name of the input field
225  * \param[in] Value new value
226  */
227  void SetStringValue(const QString & InputName, const QString & Value);
228 
229 
230 
231 
232  private:
233  /*!
234  * \brief pointer to the DMI adaptor object (used for simulation only)
235  */
236  ::ADMI* m_pAdaptor;
237 
238 
239 
240  /*!
241  * \brief layout object of the Dialog
242  */
243  ::QGridLayout m_Layout;
244 
245 
246 
247  /*!
248  * \brief vector with pointers to labels used for inputs and outputs in grid layout
249  */
250  ::std::vector< ::QLabel* > m_Labels;
251 
252 
253 
254  /*!
255  * \brief vector with pointers to all input widgets
256  */
257  ::std::vector< ::QWidget* > m_InputWidgets;
258 
259 
260 
261  /*!
262  * \brief vector with pointers to all output widgets
263  */
264  ::std::vector< ::QWidget* > m_OutputWidgets;
265 
266 
267 
268  /*!
269  * \brief poniter to the last subject used in Update().
270  */
272 
273 
274 
275  /*!
276  * \brief vector of pointer to all push buttons to submit entered data by the driver
277  */
278  ::std::vector< ::QPushButton* > m_InputButtons;
279 
280 
281 
282  /*!
283  * \brief mutable exclusion for setting DMI values while subject changes
284  */
285  ::QMutex m_Mutex;
286 
287 
288 
289 
290 }; // class CDMIQWidget : public ::QWidget, public oETCS::DF::CDMIObserver
291 
292 template< class ELEMENT_T, class CONTAINER_T >
293 bool CDMIQWidget::IsPartOf(const ELEMENT_T& Element, const CONTAINER_T& Container) throw()
294 {
295  // Bouml preserved body begin 000CF302
296  bool bFound(false);
297  decltype (Container.begin()) x;
298 
299 
300  // check, if container is empty
301  if (Container.empty())
302  {
303  // empty container means all values allowed
304  bFound = true;
305 
306  } // if (Container.empty())
307  else
308  {
309  // process all container elements
310  for (x = Container.begin(); x != Container.end() && not bFound; x++)
311  {
312  // check, if current element is searched one
313  bFound = (*x == Element);
314 
315  } // for (x = Container.begin(); x != Container.end() && not bFound; x++)
316 
317  } // else
318 
319  // return found flag
320  return (bFound);
321  // Bouml preserved body end 000CF302
322 
323 } // bool CDMIQWidget::IsPartOf() throw()
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 } // namespace oETCS::DF
334 
335 } // namespace oETCS
336 
337 #endif // __ OETCS_DF_DRIVERMACHINEINTERFACEMOC_H__

Copyright (C) 2010-2012 Johannes Feuser (feuser@uni-bremen.de)
The openETCS library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
The openETCS library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the openETCS library. If not, see "http://www.gnu.org/licenses/.