PeriodicThreadImplQNX.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 #include "PeriodicThreadImplQNX.h"
23 
24 #include <sys/siginfo.h>
25 #include <sys/neutrino.h>
26 
27 #include "Logging.h"
28 
29 namespace icl_core {
30 namespace thread {
31 
33  : m_period(period),
34  m_made_periodic(false),
35  m_chid(-1)
36 {
37  m_chid = ChannelCreate(0);
38  if (m_chid == -1)
39  {
41  "Could not create timer channel." << endl);
42  }
43 }
44 
46 {
47  ChannelDestroy(m_chid);
48 }
49 
51 {
52  if (m_chid == -1)
53  {
55  "No timer channel available! Cannot make this thread periodic!" << endl);
56  return;
57  }
58 
59  struct sigevent event;
60  int coid;
61 
62  coid = ConnectAttach(0, 0, m_chid, 0, 0);
63  if (coid == -1)
64  {
66  "Could not attach to the timer channel! Cannot make this thread periodic!" << endl);
67  return;
68  }
69 
70  SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, ePT_PULSE_TIMER, 0);
71 
72  int res = timer_create(CLOCK_REALTIME, &event, &m_timerid);
73  if (res == -1)
74  {
76  "Could not create timer! Cannot make this thread periodic!" << endl);
77  return;
78  }
79 
80  m_made_periodic = true;
81 
83 }
84 
86 {
87  m_period = period;
88 
89  if (m_made_periodic)
90  {
91  struct itimerspec timer;
92  timer.it_value = m_period.timespec();
93  timer.it_interval = m_period.timespec();
94  timer_settime(m_timerid, 0, &timer, NULL);
95  }
96 
97  return true;
98 }
99 
101 {
102  int rcvid;
103  struct _pulse msg;
104 
105  // TODO: Catch missed periods!
106  rcvid = MsgReceivePulse(m_chid, &msg, sizeof(msg), NULL);
107 
108  return;
109 }
110 
111 }
112 }
PeriodicThreadImplQNX(const icl_core::TimeSpan &period)
Contains icl_core::thread::PeriodicThreadImplQNX.
Contains logging definitions for the icl_core_thread library.
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
struct timespec timespec() const
Definition: TimeBase.cpp:113
Repesents absolute times.
Definition: TimeSpan.h:46
virtual bool setPeriod(const icl_core::TimeSpan &period)
virtual icl_core::TimeSpan period() const
#define LOGGING_ERROR_C(streamname, classname, arg)


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58