openETCS
case study for the European Train Control System developed for the authors dissertation
PlatformSpecificClientsMOC.cpp
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 classes (for HW devices) for accessing HW elements through D-Bus interfaces needing the meta object compiler (moc)
23  */
24 
26 #include "Language.h"
27 #include <QByteArray>
28 #include <QString>
29 #include "EVCStateMachine.h"
30 
31 
32 
33 
34 namespace oETCS {
35 
36 namespace DF {
37 
38 
39 CBaliseDeviceIn::CBaliseDeviceIn(const ::std::vector< oETCS::DF::CTelegram * >& Telegrams, const bool& bUsePS) throw()
40 :m_bUsePlatformSpecific(bUsePS),
41  m_ErrorStack(0),
42  m_BitArrays(0),
43  m_Telegrams(Telegrams),
44  m_pProxy(0)
45 {
46  // Bouml preserved body begin 00068982
47  bool bConnected(true);
48 
49 
50 
51  // check, if platform specific implementation should be used
52  if (m_bUsePlatformSpecific)
53  {
54  try
55  {
56  // create new interface proxy
57  m_pProxy = new ::oETCS::DF::IBaliseDeviceIn(::oETCS::DF::IBaliseDeviceIn::staticInterfaceName(), "/oETCS/BaliseDeviceIn", QDBusConnection::sessionBus());
58 
59  // check, if proxy could be connected
60  if (not m_pProxy->isValid())
61  {
62  // print error from dbus to stderr
63  ::std::cerr << "::oETCS::DF::CBaliseDeviceIn had a problem with D-Bus connection: " << m_pProxy->lastError().message().toStdString() << ::std::endl;
64 
65  // delete proxy
66  delete m_pProxy;
67 
68  // reset proxy pointer
69  m_pProxy = nullptr;
70 
71  } // if (not m_pProxy->isValid())
72  else
73  {
74  // connect signals with local slots
75  bConnected &= QObject::connect(m_pProxy, SIGNAL(NewTelegram(const QByteArray &, int)), this, SLOT(NewTelegramReceived(const QByteArray &, int)));
76  bConnected &= QObject::connect(m_pProxy, SIGNAL(Error(const QString &)), this, SLOT(Error(const QString&)));
77 
78  // check, if all signals and slots were connected successfully
79  if (! bConnected)
80  {
81  // print error to stderr
82  ::std::cerr << "::oETCS::DF::CBaliseDeviceIn could not connect all signal and slots" << ::std::endl;
83 
84  } // if (! bConnected)
85 
86  } // else
87 
88  } // try
89  catch (const ::std::bad_alloc& Exception)
90  {
91  // no error handling possible in constructor
92 
93  } // catch (const ::std::bad_alloc& Exception)
94 
95  } // if (m_bUsePlatformSpecific)
96  // Bouml preserved body end 00068982
97 
98 } // CBaliseDeviceIn::CBaliseDeviceIn() throw()
99 
100 
101 
102 
104 {
105  // Bouml preserved body begin 00068A02
106  // check, if platform specific implementation was used
107  if (m_bUsePlatformSpecific && m_pProxy != 0)
108  {
109  // delete proxy
110  delete m_pProxy;
111 
112  } // if (m_bUsePlatformSpecific && m_pProxy != 0)
113  // Bouml preserved body end 00068A02
114 
115 } // CBaliseDeviceIn::~CBaliseDeviceIn() throw()
116 
117 
118 
119 
120 ::std::vector< unsigned char > CBaliseDeviceIn::HasNewTelegram() throw(::oETCS::DF::Error::CException)
121 {
122  // Bouml preserved body begin 000D0C82
123  decltype (m_BitArrays.begin()) ba;
124  decltype (m_Telegrams.begin()) t;
125  ::std::vector< bool > BitVector;
126  ::std::string ErrorMessage;
127  bool bNewTelegram(false);
128  unsigned int iSize(0);
129  unsigned int x(0);
130  ::std::vector< unsigned char > UsedIDs(0);
131 
132 
133 
134  // lock mutex
135  m_Mutex.lock();
136 
137  // process all stored bit arrays and remove all processed ones
138  for (ba = m_BitArrays.begin(); ba != m_BitArrays.end() && not bNewTelegram; ba = m_BitArrays.erase(ba))
139  {
140  // get size from current bit arrays
141  iSize = (*ba).size();
142 
143  // resize target bit vector
144  BitVector.resize(iSize);
145 
146  // copy current bit array to bit vector (bit-wise)
147  for (x = 0; x < iSize; x++)
148  {
149  // copy current bit
150  BitVector[x] = (*ba)[x];
151 
152  } // for (x = 0; x < iSize; x++)
153 
154 
155  // try to stream current bit vector to all connected telegram
156  for (t = m_Telegrams.begin(); t != m_Telegrams.end(); t++)
157  {
158  #ifdef __OETCS_DF_LANGUAGE_DEBUG_OUTPUT__
159  // DEBUG
160  ::std::cout << "CBaliseDeviceIn::HasNewTelegram() bits in balise reader: ";
161  for (decltype (BitVector.begin()) lb = BitVector.begin(); lb != BitVector.end(); lb++)
162  {
163  ::std::cout << *lb << "," << ::std::flush;
164 
165  } // for (decltype (BitVector.begin()) lb = BitVector.begin(); lb != BitVector.end(); lb++)
166  ::std::cout << ::std::endl;
167  ::std::cout << "# bits: "<< BitVector.size() << ::std::endl;
168  #endif // __OETCS_DF_LANGUAGE_DEBUG_OUTPUT__
169 
170 
171  try
172  {
173  // try to stream to current telegram
174  UsedIDs = *(*t) << BitVector;
175 
176  // telegram was accepted, set flag
177  bNewTelegram = true;
178 
179  } // try
180  catch (::oETCS::DF::Error::CInput& Exception)
181  {
182  // just ignore exception here (are not an error, only telegram does not fit)
183 
184  } // catch (::oETCS::DF::Error::CInput& Exception)
185 
186  } // for (t = m_Telegrams.begin(); t != m_Telegrams.end(); t++)
187 
188  } // for (ba = m_BitArrays.begin(); ba != m_BitArrays.end() && not bNewTelegram; ba++)
189 
190  // unlock mutex
191  m_Mutex.unlock();
192 
193  // return list of IDs
194  return (UsedIDs);
195  // Bouml preserved body end 000D0C82
196 
197 } // unsigned char CBaliseDeviceIn::HasNewTelegram() throw(::oETCS::DF::Error::CException)
198 
199 
200 
201 
202 void CBaliseDeviceIn::Clear() throw()
203 {
204  // Bouml preserved body begin 000FE302
205  // lock mutex
206  m_Mutex.lock();
207 
208  // clear bit arrays
209  m_BitArrays.clear();
210 
211  // unlock mutex
212  m_Mutex.unlock();
213  // Bouml preserved body end 000FE302
214 
215 } // void CBaliseDeviceIn::Clear() throw()
216 
217 
218 
219 
220 void CBaliseDeviceIn::NewTelegramReceived(const QByteArray & Bytes, int iBits)
221 {
222  // Bouml preserved body begin 000ABA02
223  ::QBitArray Bits;
224  int by(0);
225  int bi(0);
226  const int BYTES_TO_COPY(iBits / 8 + (iBits % 8 == 0 ? 0 : 1));
227 
228 
229 
230  // check, if number of bits is not bigger than possibly stored in bytes
231  if (BYTES_TO_COPY <= Bytes.size())
232  {
233  // rezize bits array
234  Bits.resize(iBits);
235 
236  // copy telegram byte-wise
237  for (by = 0; by < BYTES_TO_COPY; by++)
238  {
239  // copy current byte bit-wise
240  for (bi = 0; bi < 8 && bi + by * 8 < iBits; bi++)
241  {
242  // copy current bit
243  Bits[bi + by * 8] = (Bytes[by] & (1 << bi)) == 0 ? false : true;
244 
245  } // for (bi = 0; bi < 8 && bi + by * 8 < iBits; bi++
246 
247  } // for (by = 0; by < BYTES_TO_COPY; by++)
248 
249  // lock mutex
250  m_Mutex.lock();
251 
252  // store new telegram
253  m_BitArrays.push_back(Bits);
254 
255  // unlock mutex
256  m_Mutex.unlock();
257 
258  } // if (BYTES_TO_COPY <= Bytes.size())
259  // Bouml preserved body end 000ABA02
260 
261 } // void CBaliseDeviceIn::NewTelegramReceived()
262 
263 
264 
265 
266 void CBaliseDeviceIn::Error(const ::QString& ErrorMessage)
267 {
268  // Bouml preserved body begin 000D6682
269 
270  // lock mutex
271  m_Mutex.lock();
272 
273  // store error message on stack
274  m_ErrorStack.push_back(ErrorMessage.toStdString());
275 
276  // unlock mutex
277  m_Mutex.unlock();
278  // Bouml preserved body end 000D6682
279 
280 } // void CBaliseDeviceIn::Error()
281 
282 
283 
284 
285 CBaliseDeviceOut::CBaliseDeviceOut(const ::std::vector< oETCS::DF::CTelegram * >& Telegrams, const bool& bUsePS) throw()
286 :m_bUsePlatformSpecific(bUsePS),
287  m_ErrorStack(0),
288  m_Telegrams(Telegrams),
289  m_pProxy(0)
290 {
291  // Bouml preserved body begin 0006A502
292  // check, if platform specific implementation should be used
293  if (m_bUsePlatformSpecific)
294  {
295  try
296  {
297  // create new interface proxy
298  m_pProxy = new ::oETCS::DF::IBaliseDeviceOut(::oETCS::DF::IBaliseDeviceOut::staticInterfaceName(), "/oETCS/BaliseDeviceOut", QDBusConnection::sessionBus());
299 
300  // check, if proxy could be connected
301  if (not m_pProxy->isValid())
302  {
303  // print error from dbus to stderr
304  ::std::cerr << "::oETCS::DF::CBaliseDeviceOut had a problem with D-Bus connection: " << m_pProxy->lastError().message().toStdString() << ::std::endl;
305 
306  // delete proxy
307  delete m_pProxy;
308 
309  // reset proxy pointer
310  m_pProxy = 0;
311 
312  } // if (not m_pProxy->isValid())
313  else
314  {
315  // connect signals with local slots
316  QObject::connect(m_pProxy, SIGNAL(Error(const QString &)), this, SLOT(Error(const QString&)));
317 
318  // set timeout for all calls on interface
319  //m_pProxy->setTimeout(10);
320 
321  } // else
322 
323  } // try
324  catch (const ::std::bad_alloc& Exception)
325  {
326  // no error handling possible in constructor
327 
328  } // catch (const ::std::bad_alloc& Exception)
329 
330  } // if (m_bUsePlatformSpecific)
331  // Bouml preserved body end 0006A502
332 
333 } // CBaliseDeviceOut::CBaliseDeviceOut() throw()
334 
335 
336 
337 
339 {
340  // Bouml preserved body begin 0006A582
341  // check, if platform specific implementation was used
342  if (m_bUsePlatformSpecific && m_pProxy != 0)
343  {
344  // delete proxy
345  delete m_pProxy;
346 
347  } // if (m_bUsePlatformSpecific && m_pProxy != 0)
348  // Bouml preserved body end 0006A582
349 
350 } // CBaliseDeviceOut::~CBaliseDeviceOut() throw()
351 
352 
353 
354 
355 void CBaliseDeviceOut::SendTelegram() throw(::oETCS::DF::Error::CException)
356 {
357  // Bouml preserved body begin 000ABA82
358  decltype (m_Telegrams.begin()) t;
359  QBitArray BitArray;
360  QDBusPendingReply<> AsyncReply;
361  ::std::vector< bool > BitVector;
362  ::std::string ErrorMessage;
363  unsigned int iSize(0);
364  unsigned int x(0);
365 
366 
367 
368 
369  // any platform independent implementation can be added below here
370  // ...
371 
372 
373 
374  // check, if platform specific implementations should be used
376  {
377  // lock mutex
378  m_Mutex.lock();
379 
380  // check, if error stack is non-empty
381  if (not m_ErrorStack.empty())
382  {
383  // get error first error message on stack
384  ErrorMessage = m_ErrorStack[0];
385 
386  // remove this message from stack
387  m_ErrorStack.erase(m_ErrorStack.begin());
388 
389  // throw exception
390  throw (::oETCS::DF::Error::CInternal(::std::string("error in PS implementation: ") + ErrorMessage));
391 
392  } // if (not m_ErrorStack.empty())
393 
394  // unlock mutex
395  m_Mutex.unlock();
396 
397  // check, if proxy was created and still is valid
398  if (m_pProxy != 0 && m_pProxy->isValid())
399  {
400  // throw exception
401  throw (::oETCS::DF::Error::CInternal("no proxy available"));
402 
403  } // if (m_pProxy != 0 && m_pProxy->isValid())
404 
405  // process all connected telegrams
406  for (t = m_Telegrams.begin(); t != m_Telegrams.end(); t++)
407  {
408  // get bit vector from current telegram
409  (**t) >> BitVector;
410 
411  // get size of bit vector
412  iSize = BitVector.size();
413 
414  // resize bit array
415  BitArray.resize(iSize);
416 
417  // copy bit vector in array (bit-wise)
418  for (x = 0; x < iSize; x++)
419  {
420  // copy current bit
421  BitArray[x] = BitVector[x];
422 
423  } // for (x = 0; x < iSize; x++)
424 
425  // send bit array via proxy
426  AsyncReply = m_pProxy->SendTelegram(BitArray);
427 
428  // wait for asynchronous call to be finished
429  AsyncReply.waitForFinished();
430 
431  // check, if replay was valid
432  if (not AsyncReply.isValid())
433  {
434  // throw exception
435  throw (::oETCS::DF::Error::CInternal("error while calling remote method SendTelegram() -> " + AsyncReply.error().message().toStdString()));
436 
437  } // if (not AsyncReply.isValid())
438 
439  } // for (t = m_Telegrams.begin(); t != m_Telegrams.end(); t++)
440 
441  } // if (m_bUsePlatformSpecific)
442  // Bouml preserved body end 000ABA82
443 
444 } // void CBaliseDeviceOut::SendTelegram() throw(::oETCS::DF::Error::CException)
445 
446 
447 
448 
449 void CBaliseDeviceOut::Error(const ::QString& ErrorMessage)
450 {
451  // Bouml preserved body begin 000D6702
452 
453  // lock mutex
454  m_Mutex.lock();
455 
456  // store error message on stack
457  m_ErrorStack.push_back(ErrorMessage.toStdString());
458 
459  // unlock mutex
460  m_Mutex.unlock();
461  // Bouml preserved body end 000D6702
462 
463 } // void CBaliseDeviceOut::Error()
464 
465 
466 
467 
468 CEmergencyBrake::CEmergencyBrake(oETCS::DF::CEVCStateMachine * pStateMachine, const bool& bUsePS) throw()
469 :CFunctionBlock(pStateMachine),
470  m_bActivation(false),
471  m_bUsePlatformSpecific(bUsePS),
472  m_ErrorStack(0),
473  m_pProxy(0)
474 {
475  // Bouml preserved body begin 0004E802
476  // check, if platform specific implementation should be used
477  if (m_bUsePlatformSpecific)
478  {
479  try
480  {
481  // create new interface proxy
482  m_pProxy = new ::oETCS::DF::IEmergencyBrake(::oETCS::DF::IEmergencyBrake::staticInterfaceName(), "/oETCS/EmergencyBrake", QDBusConnection::sessionBus());
483 
484  // check, if proxy could be connected
485  if (not m_pProxy->isValid())
486  {
487  // print error from dbus to stderr
488  ::std::cerr << "::oETCS::DF::CEmergencyBrake had a problem with D-Bus connection: " << m_pProxy->lastError().message().toStdString() << ::std::endl;
489 
490  // delete proxy
491  delete m_pProxy;
492 
493  // reset proxy pointer
494  m_pProxy = 0;
495 
496  } // if (not m_pProxy->isValid())
497  else
498  {
499  // connect signals with local slots
500  QObject::connect(m_pProxy, SIGNAL(Error(const QString&)), this, SLOT(Error(const QString&)));
501 
502  // set timeout for all calls on interface
503  //m_pProxy->setTimeout(10);
504 
505  } // else
506 
507  } // try
508  catch (const ::std::bad_alloc& Exception)
509  {
510  // no error handling possible in constructor
511 
512  } // catch (const ::std::bad_alloc& Exception)
513 
514  } // if (m_bUsePlatformSpecific)
515  // Bouml preserved body end 0004E802
516 
517 } // CEmergencyBrake::CEmergencyBrake() throw()
518 
519 
520 
521 
523 {
524  // Bouml preserved body begin 0004E882
525  // check, if platform specific implementation was used
526  if (m_bUsePlatformSpecific && m_pProxy != 0)
527  {
528  // delete proxy
529  delete m_pProxy;
530 
531  } // if (m_bUsePlatformSpecific && m_pProxy != 0)
532  // Bouml preserved body end 0004E882
533 
534 } // CEmergencyBrake::~CEmergencyBrake() throw()
535 
536 
537 
538 
539 void CEmergencyBrake::Calculate() throw(::oETCS::DF::Error::CException)
540 {
541  // Bouml preserved body begin 0004E782
542  QDBusPendingReply<> AsyncReply;
543  ::std::string ErrorMessage;
544 
545 
546 
547  // any platform independent implementation can be added below here
548  // ...
549 
550 
551  // check, if platform specific implementations should be used
553  {
554  // lock mutex
555  m_Mutex.lock();
556 
557  // check, if error stack is non-empty
558  if (not m_ErrorStack.empty())
559  {
560  // get error first error message on stack
561  ErrorMessage = m_ErrorStack[0];
562 
563  // remove this message from stack
564  m_ErrorStack.erase(m_ErrorStack.begin());
565 
566  // throw exception
567  throw (::oETCS::DF::Error::CInternal(::std::string("error in PS implementation: ") + ErrorMessage));
568 
569  } // if (not m_ErrorStack.empty())
570 
571  // unlock mutex
572  m_Mutex.unlock();
573 
574  // check, if proxy was created and still is valid
575  if (m_pProxy == nullptr || not m_pProxy->isValid())
576  {
577  // throw exception
578  throw (::oETCS::DF::Error::CInternal("no proxy available"));
579 
580  } // if (m_pProxy == nullptr || not m_pProxy->isValid())
581 
582  // set brake intensity via proxy
583  AsyncReply = m_pProxy->SetActivation(m_bActivation());
584 
585  // wait for asynchronous call to be finished
586  AsyncReply.waitForFinished();
587 
588  // check, if replay was valid
589  if (not AsyncReply.isValid())
590  {
591  // throw exception
592  throw (::oETCS::DF::Error::CInternal("error while calling remote method SetActivation() -> " + AsyncReply.error().message().toStdString()));
593 
594  } // if (not AsyncReply.isValid())
595 
596  } // if (m_bUsePlatformSpecific)
597  // Bouml preserved body end 0004E782
598 
599 } // void CEmergencyBrake::Calculate() throw(::oETCS::DF::Error::CException)
600 
601 
602 
603 
604 void CEmergencyBrake::Error(const ::QString& ErrorMessage)
605 {
606  // Bouml preserved body begin 000D6782
607 
608  // lock mutex
609  m_Mutex.lock();
610 
611  // store error message on stack
612  m_ErrorStack.push_back(ErrorMessage.toStdString());
613 
614  // unlock mutex
615  m_Mutex.unlock();
616  // Bouml preserved body end 000D6782
617 
618 } // void CEmergencyBrake::Error()
619 
620 
621 
622 
623 COdometer::COdometer(oETCS::DF::CEVCStateMachine * const pStateMachine, const bool& bUsePS) throw()
624 :CFunctionBlock(pStateMachine),
625  m_AbsolutePosition(0),
626  m_Velocity(0),
627  m_bUsePlatformSpecific(bUsePS),
628  m_ErrorStack(0),
629  m_pProxy(0)
630 {
631  // Bouml preserved body begin 0004E582
632  // check, if platform specific implementation should be used
633  if (m_bUsePlatformSpecific)
634  {
635  try
636  {
637  // create new interface proxy
638  m_pProxy = new ::oETCS::DF::IOdometer(::oETCS::DF::IOdometer::staticInterfaceName(), "/oETCS/Odometer", QDBusConnection::sessionBus());
639 
640  // check, if proxy could be connected
641  if (not m_pProxy->isValid())
642  {
643  // print error from dbus to stderr
644  ::std::cerr << "::oETCS::DF::COdometer had a problem with D-Bus connection: " << m_pProxy->lastError().message().toStdString() << ::std::endl;
645 
646  // delete proxy
647  delete m_pProxy;
648 
649  // reset proxy pointer
650  m_pProxy = 0;
651 
652  } // if (not m_pProxy->isValid())
653  else
654  {
655  // connect signals with local slots
656  QObject::connect(m_pProxy, SIGNAL(Error(const QString&)), this, SLOT(Error(const QString&)));
657 
658  // set timeout for all calls on interface
659  //m_pProxy->setTimeout(10);
660 
661  } // else
662 
663  } // try
664  catch (const ::std::bad_alloc& Exception)
665  {
666  // no error handling possible in constructor
667 
668  } // catch (const ::std::bad_alloc& Exception)
669 
670  } // if (m_bUsePlatformSpecific)
671  // Bouml preserved body end 0004E582
672 
673 } // COdometer::COdometer() throw()
674 
675 
676 
677 
679 {
680  // Bouml preserved body begin 0004E602
681  // check, if platform specific implementation was used
682  if (m_bUsePlatformSpecific && m_pProxy != 0)
683  {
684  // delete proxy
685  delete m_pProxy;
686 
687  } // if (m_bUsePlatformSpecific && m_pProxy != 0)
688  // Bouml preserved body end 0004E602
689 
690 } // COdometer::~COdometer() throw()
691 
692 
693 
694 
695 void COdometer::Calculate() throw(::oETCS::DF::Error::CException)
696 {
697  // Bouml preserved body begin 0004E502
698  double dVelocity(0.0);
699  double dAbsolutePosition(0.0);
700  QDBusPendingReply<double> AsyncReply;
701  ::std::string ErrorMessage;
702  decltype (m_Velocity.begin()) v;
703  decltype (m_AbsolutePosition.begin()) p;
704 
705 
706 
707  // any platform independent implementation can be added below here
708  // ...
709 
710 
711  // check, if platform specific implementations should be used
713  {
714  // lock mutex
715  m_Mutex.lock();
716 
717  // check, if error stack is non-empty
718  if (not m_ErrorStack.empty())
719  {
720  // get error first error message on stack
721  ErrorMessage = m_ErrorStack[0];
722 
723  // remove this message from stack
724  m_ErrorStack.erase(m_ErrorStack.begin());
725 
726  // throw exception
727  throw (::oETCS::DF::Error::CInternal(::std::string("error in PS implementation: ") + ErrorMessage));
728 
729  } // if (not m_ErrorStack.empty())
730 
731  // unlock mutex
732  m_Mutex.unlock();
733 
734  // check, if proxy was created and still is valid
735  if (m_pProxy == nullptr || not m_pProxy->isValid())
736  {
737  // throw exception
738  throw (::oETCS::DF::Error::CInternal("no proxy available"));
739 
740  } // if (m_pProxy == nullptr || not m_pProxy->isValid())
741 
742  // get velocity via proxy
743  AsyncReply = m_pProxy->GetVelocity();
744 
745  // wait for asynchronous call to be finished
746  AsyncReply.waitForFinished();
747 
748  // check, if replay was valid
749  if (not AsyncReply.isValid())
750  {
751  // throw exception
752  throw (::oETCS::DF::Error::CInternal("error while calling remote method GetVelocity() -> " + AsyncReply.error().message().toStdString()));
753 
754  } // if (not AsyncReply.isValid())
755 
756  // get velocity from reply
757  dVelocity = AsyncReply.value();
758 
759 
760  // get position via proxy
761  AsyncReply = m_pProxy->GetAbsolutePosition();
762 
763  // wait for asynchronous call to be finished
764  AsyncReply.waitForFinished();
765 
766  // check, if replay was valid
767  if (not AsyncReply.isValid())
768  {
769  // throw exception
770  throw (::oETCS::DF::Error::CInternal("error while calling remote method GetAbsolutePosition()"));
771 
772  } // if (not AsyncReply.isValid())
773 
774  // get position from reply
775  dAbsolutePosition = AsyncReply.value();
776 
777 
778  // copy velocity to all outputs
779  for (v = m_Velocity.begin(); v != m_Velocity.end(); v++)
780  {
781  // copy value to current output
782  **v = dVelocity;
783 
784  } // for (v = m_Velocity.begin(); v != m_Velocity.end(); v++)
785 
786  // copy position to all outputs
787  for (p = m_AbsolutePosition.begin(); p != m_AbsolutePosition.end(); p++)
788  {
789  // copy value to current output
790  **p = dAbsolutePosition;
791 
792  } // for (p = m_AbsolutePosition.begin(); p != m_AbsolutePosition.end(); p++)
793 
794  } // if (m_bUsePlatformSpecific)
795  // Bouml preserved body end 0004E502
796 
797 } // void COdometer::Calculate() throw(::oETCS::DF::Error::CException)
798 
799 
800 
801 
802 void COdometer::Error(const ::QString& ErrorMessage)
803 {
804  // Bouml preserved body begin 000D6882
805 
806  // lock mutex
807  m_Mutex.lock();
808 
809  // store error message on stack
810  m_ErrorStack.push_back(ErrorMessage.toStdString());
811 
812  // unlock mutex
813  m_Mutex.unlock();
814  // Bouml preserved body end 000D6882
815 
816 } // void COdometer::Error()
817 
818 
819 
820 
821 CServiceBrake::CServiceBrake(oETCS::DF::CEVCStateMachine * const pStateMachine, const bool& bUsePS) throw()
822 :CFunctionBlock(pStateMachine),
823  m_dBrakeIntensity(0.0),
824  m_bUsePlatformSpecific(bUsePS),
825  m_ErrorStack(0),
826  m_pProxy(0)
827 {
828  // Bouml preserved body begin 0004EA02
829  // check, if platform specific implementation should be used
830  if (m_bUsePlatformSpecific)
831  {
832  try
833  {
834  // create new interface proxy
835  m_pProxy = new ::oETCS::DF::IServiceBrake(::oETCS::DF::IServiceBrake::staticInterfaceName(), "/oETCS/ServiceBrake", QDBusConnection::sessionBus());
836 
837  // check, if proxy could be connected
838  if (not m_pProxy->isValid())
839  {
840  // print error from dbus to stderr
841  ::std::cerr << "::oETCS::DF::CServiceBrake had a problem with D-Bus connection: " << m_pProxy->lastError().message().toStdString() << ::std::endl;
842 
843  // delete proxy
844  delete m_pProxy;
845 
846  // reset proxy pointer
847  m_pProxy = 0;
848 
849  } // if (not m_pProxy->isValid())
850  else
851  {
852  // connect signals with local slots
853  QObject::connect(m_pProxy, SIGNAL(Error(const QString&)), this, SLOT(Error(const QString&)));
854 
855 
856  // set timeout for all calls on interface
857  //m_pProxy->setTimeout(10);
858 
859  } // else
860 
861  } // try
862  catch (const ::std::bad_alloc& Exception)
863  {
864  // no error handling possible in constructor
865 
866  } // catch (const ::std::bad_alloc& Exception)
867 
868  } // if (m_bUsePlatformSpecific)
869  // Bouml preserved body end 0004EA02
870 
871 } // CServiceBrake::CServiceBrake() throw()
872 
873 
874 
875 
877 {
878  // Bouml preserved body begin 0004EA82
879  // check, if platform specific implementation was used
880  if (m_bUsePlatformSpecific && m_pProxy != 0)
881  {
882  // delete proxy
883  delete m_pProxy;
884 
885  } // if (m_bUsePlatformSpecific && m_pProxy != 0)
886  // Bouml preserved body end 0004EA82
887 
888 } // CServiceBrake::~CServiceBrake() throw()
889 
890 
891 
892 
893 void CServiceBrake::Calculate() throw(::oETCS::DF::Error::CException)
894 {
895  // Bouml preserved body begin 0004E982
896  QDBusPendingReply<> AsyncReply;
897  ::std::string ErrorMessage;
898 
899 
900 
901  // any platform independent implementation can be added below here
902  // ...
903 
904 
905  // check, if platform specific implementations should be used
907  {
908  // lock mutex
909  m_Mutex.lock();
910 
911  // check, if error stack is non-empty
912  if (not m_ErrorStack.empty())
913  {
914  // get error first error message on stack
915  ErrorMessage = m_ErrorStack[0];
916 
917  // remove this message from stack
918  m_ErrorStack.erase(m_ErrorStack.begin());
919 
920  // throw exception
921  throw (::oETCS::DF::Error::CInternal(::std::string("error in PS implementation: ") + ErrorMessage));
922 
923  } // if (not m_ErrorStack.empty())
924 
925  // unlock mutex
926  m_Mutex.unlock();
927 
928  // check, if proxy was created and still is valid
929  if (m_pProxy == nullptr || not m_pProxy->isValid())
930  {
931  // throw exception
932  throw (::oETCS::DF::Error::CInternal("no proxy available"));
933 
934  } // if (m_pProxy == nullptr || not m_pProxy->isValid())
935 
936  // set brake intensity via proxy
937  AsyncReply = m_pProxy->SetIntensity(m_dBrakeIntensity());
938 
939  // wait for asynchronous call to be finished
940  AsyncReply.waitForFinished();
941 
942  // check, if replay was valid
943  if (not AsyncReply.isValid())
944  {
945  // throw exception
946  throw (::oETCS::DF::Error::CInternal("error while calling remote method SetIntensity() -> " + AsyncReply.error().message().toStdString()));
947 
948  } // if (not AsyncReply.isValid())
949 
950  } // if (m_bUsePlatformSpecific)
951  // Bouml preserved body end 0004E982
952 
953 } // void CServiceBrake::Calculate() throw(::oETCS::DF::Error::CException)
954 
955 
956 
957 
958 void CServiceBrake::Error(const ::QString& ErrorMessage)
959 {
960  // Bouml preserved body begin 000D6802
961 
962  // lock mutex
963  m_Mutex.lock();
964 
965  // store error message on stack
966  m_ErrorStack.push_back(ErrorMessage.toStdString());
967 
968  // unlock mutex
969  m_Mutex.unlock();
970  // Bouml preserved body end 000D6802
971 
972 } // void CServiceBrake::Error()
973 
974 
975 
976 
977 
978 
979 } // namespace oETCS::DF
980 
981 } // namespace oETCS

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/.