00001
00002
00008
00009 #include "Logging.h"
00010 #include "PeriodicThread.h"
00011 #include "PeriodicThreadImpl.h"
00012
00013 #if defined _SYSTEM_QNX_
00014 # include "PeriodicThreadImplQNX.h"
00015 #elif defined _SYSTEM_POSIX_
00016 # if defined _SYSTEM_LXRT_
00017 # include "PeriodicThreadImplLxrt.h"
00018 # endif
00019 # if defined _SYSTEM_LINUX_
00020 # include <linux/version.h>
00021 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
00022 # include "PeriodicThreadImplTimerfd.h"
00023 # endif
00024 # endif
00025 # include "PeriodicThreadImplEmulate.h"
00026 #elif defined _SYSTEM_WIN32_
00027 # include "PeriodicThreadImplEmulate.h"
00028 #else
00029 # error "No implementation specified for System dependent components"
00030 #endif
00031
00032 using icl_core::logging::endl;
00033
00034 namespace icl_core {
00035 namespace thread {
00036
00037 PeriodicThread::PeriodicThread(const icl_core::String& description,
00038 const icl_core::TimeSpan& period,
00039 ThreadPriority priority)
00040 : Thread(description, priority)
00041 {
00042 #if defined (_SYSTEM_QNX_)
00043 LOGGING_DEBUG_CO(Thread, PeriodicThread, threadInfo(),
00044 "Creating QNX periodic thread implementation." << endl);
00045 m_impl = new PeriodicThreadImplQNX(period);
00046
00047 #elif defined (_SYSTEM_POSIX_)
00048 # if defined (_SYSTEM_LXRT_)
00049
00050
00051
00052
00053
00054
00055 if (icl_core::os::isLxrtAvailable())
00056 {
00057 LOGGING_DEBUG_CO(IclCoreThread, PeriodicThread, threadInfo(),
00058 "Creating LXRT periodic thread implementation." << endl);
00059 m_impl = new PeriodicThreadImplLxrt(period);
00060 }
00061 else
00062 {
00063 # endif
00064 # if defined (_SYSTEM_LINUX_)
00065 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
00066
00067 LOGGING_DEBUG_CO(IclCoreThread, PeriodicThread, threadInfo(),
00068 "Creating timerfd periodic thread implementation." << endl);
00069 m_impl = new PeriodicThreadImplTimerfd(period);
00070 # else
00071
00072 LOGGING_DEBUG_CO(IclCoreThread, PeriodicThread, threadInfo(),
00073 "Creating emulate periodic thread implementation." << endl);
00074 m_impl = new PeriodicThreadImplEmulate(period);
00075 # endif
00076 # else
00077
00078 LOGGING_DEBUG_CO(IclCoreThread, PeriodicThread, threadInfo(),
00079 "Creating emulate periodic thread implementation." << endl);
00080 m_impl = new PeriodicThreadImplEmulate(period);
00081 # endif
00082 # if defined(_SYSTEM_LXRT_)
00083 }
00084 # endif
00085
00086 #elif defined (_SYSTEM_WIN32_)
00087 LOGGING_DEBUG_CO(IclCoreThread, PeriodicThread, threadInfo(),
00088 "Creating emulate periodic thread implementation." << endl);
00089 m_impl = new PeriodicThreadImplEmulate(period);
00090 #endif
00091 }
00092
00093 PeriodicThread::~PeriodicThread()
00094 {
00095 delete m_impl; m_impl = NULL;
00096 }
00097
00098 icl_core::TimeSpan PeriodicThread::period() const
00099 {
00100 return m_impl->period();
00101 }
00102
00103 bool PeriodicThread::setPeriod(const icl_core::TimeSpan& period)
00104 {
00105 return m_impl->setPeriod(period);
00106 }
00107
00109 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00110
00114 icl_core::TimeSpan PeriodicThread::Period() const
00115 {
00116 return period();
00117 }
00118
00122 bool PeriodicThread::SetPeriod(const icl_core::TimeSpan& period)
00123 {
00124 return setPeriod(period);
00125 }
00126
00127 #endif
00128
00129
00130 void PeriodicThread::waitPeriod()
00131 {
00132 LOGGING_TRACE_CO(IclCoreThread, PeriodicThread, threadInfo(), "Begin." << endl);
00133
00134
00135 if (isHardRealtime() && !executesHardRealtime())
00136 {
00137 if (setHardRealtime(true))
00138 {
00139 LOGGING_INFO_CO(IclCoreThread, PeriodicThread, threadInfo(),
00140 "Resetted to hard realtime mode." << endl);
00141 }
00142 else
00143 {
00144 LOGGING_ERROR_CO(IclCoreThread, PeriodicThread, threadInfo(),
00145 "Resetting to hard realtime mode failed!" << endl);
00146 }
00147 }
00148 else if (!isHardRealtime() && executesHardRealtime())
00149 {
00150 if (setHardRealtime(false))
00151 {
00152 LOGGING_INFO_CO(IclCoreThread, PeriodicThread, threadInfo(),
00153 "Resetted to soft realtime mode." << endl);
00154 }
00155 else
00156 {
00157 LOGGING_ERROR_CO(IclCoreThread, PeriodicThread, threadInfo(),
00158 "Resetting to soft realtime mode failed!" << endl);
00159 }
00160 }
00161
00162
00163 m_impl->waitPeriod();
00164
00165 LOGGING_TRACE_CO(IclCoreThread, PeriodicThread, threadInfo(), "Done." << endl);
00166 }
00167
00168 void PeriodicThread::makePeriodic()
00169 {
00170 LOGGING_TRACE_CO(IclCoreThread, PeriodicThread, threadInfo(), "Begin." << endl);
00171
00172 m_impl->makePeriodic();
00173
00174 LOGGING_TRACE_CO(IclCoreThread, PeriodicThread, threadInfo(), "Done." << endl);
00175 }
00176
00178 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00179
00183 void PeriodicThread::WaitPeriod()
00184 {
00185 waitPeriod();
00186 }
00187
00188 #endif
00189
00190
00191 }
00192 }