Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021
00022 #include "PeriodicThreadImplQNX.h"
00023
00024 #include <sys/siginfo.h>
00025 #include <sys/neutrino.h>
00026
00027 #include "Logging.h"
00028
00029 namespace icl_core {
00030 namespace thread {
00031
00032 PeriodicThreadImplQNX::PeriodicThreadImplQNX(const icl_core::TimeSpan& period)
00033 : m_period(period),
00034 m_made_periodic(false),
00035 m_chid(-1)
00036 {
00037 m_chid = ChannelCreate(0);
00038 if (m_chid == -1)
00039 {
00040 LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
00041 "Could not create timer channel." << endl);
00042 }
00043 }
00044
00045 PeriodicThreadImplQNX::~PeriodicThreadImplQNX()
00046 {
00047 ChannelDestroy(m_chid);
00048 }
00049
00050 void PeriodicThreadImplQNX::makePeriodic()
00051 {
00052 if (m_chid == -1)
00053 {
00054 LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
00055 "No timer channel available! Cannot make this thread periodic!" << endl);
00056 return;
00057 }
00058
00059 struct sigevent event;
00060 int coid;
00061
00062 coid = ConnectAttach(0, 0, m_chid, 0, 0);
00063 if (coid == -1)
00064 {
00065 LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
00066 "Could not attach to the timer channel! Cannot make this thread periodic!" << endl);
00067 return;
00068 }
00069
00070 SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, ePT_PULSE_TIMER, 0);
00071
00072 int res = timer_create(CLOCK_REALTIME, &event, &m_timerid);
00073 if (res == -1)
00074 {
00075 LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
00076 "Could not create timer! Cannot make this thread periodic!" << endl);
00077 return;
00078 }
00079
00080 m_made_periodic = true;
00081
00082 setPeriod(m_period);
00083 }
00084
00085 bool PeriodicThreadImplQNX::setPeriod(const icl_core::TimeSpan& period)
00086 {
00087 m_period = period;
00088
00089 if (m_made_periodic)
00090 {
00091 struct itimerspec timer;
00092 timer.it_value = m_period.timespec();
00093 timer.it_interval = m_period.timespec();
00094 timer_settime(m_timerid, 0, &timer, NULL);
00095 }
00096
00097 return true;
00098 }
00099
00100 void PeriodicThreadImplQNX::waitPeriod()
00101 {
00102 int rcvid;
00103 struct _pulse msg;
00104
00105
00106 rcvid = MsgReceivePulse(m_chid, &msg, sizeof(msg), NULL);
00107
00108 return;
00109 }
00110
00111 }
00112 }