[openrtm-commit:00665] r2310 - in trunk/OpenRTM-aist/src/lib/coil: common posix/coil win32/coil
openrtm @ openrtm.org
openrtm @ openrtm.org
2012年 2月 7日 (火) 11:09:56 JST
Author: n-ando
Date: 2012-02-07 11:09:55 +0900 (Tue, 07 Feb 2012)
New Revision: 2310
Added:
trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp
trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h
Modified:
trunk/OpenRTM-aist/src/lib/coil/common/Makefile.am
trunk/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am
trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am
Log:
[incompat,impl/header,func] ClockManager class has been introduced. refs #2355
Added: trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp (rev 0)
+++ trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.cpp 2012-02-07 02:09:55 UTC (rev 2310)
@@ -0,0 +1,114 @@
+// -*- C++ -*-
+/*!
+ * @file ClockManager.cpp
+ * @brief Global clock management class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2012
+ * Noriaki Ando
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#include <coil/Time.h>
+#include <math.h>
+#include <coil/ClockManager.h>
+
+namespace coil
+{
+ //============================================================
+ // System Clock
+ //============================================================
+ SystemClock::~SystemClock()
+ {
+ }
+ coil::TimeValue SystemClock::gettime() const
+ {
+ return coil::gettimeofday();
+ }
+ bool SystemClock::settime(coil::TimeValue clocktime)
+ {
+ timeval tv;
+ tv.tv_sec = clocktime.sec();
+ tv.tv_usec = clocktime.usec();
+ if (coil::settimeofday(&tv, 0) == 0)
+ {
+ return true;
+ }
+ return false;
+ }
+ //
+ //============================================================
+
+ //============================================================
+ // Logical Time Clock
+ //============================================================
+ LogicalClock::LogicalClock()
+ : m_currentTime(0.0)
+ {
+ }
+
+ LogicalClock::~LogicalClock()
+ {
+ }
+
+ coil::TimeValue LogicalClock::gettime() const
+ {
+ return m_currentTime;
+ }
+
+ bool LogicalClock::settime(coil::TimeValue clocktime)
+ {
+ m_currentTime = clocktime;
+ return true;
+ }
+ //
+ //============================================================
+
+ //============================================================
+ // Adjusted Clock
+ //============================================================
+ AdjustedClock::AdjustedClock()
+ : m_offset(0.0)
+ {
+ }
+
+ AdjustedClock::~AdjustedClock()
+ {
+ }
+
+ coil::TimeValue AdjustedClock::gettime() const
+ {
+ return coil::gettimeofday() - m_offset;
+ }
+
+ bool AdjustedClock::settime(coil::TimeValue clocktime)
+ {
+ m_offset = coil::gettimeofday() - clocktime;
+ return true;
+ }
+
+ IClock& ClockManager::getClock(std::string clocktype)
+ {
+ if (clocktype == "logical")
+ {
+ return m_logicalClock;
+ }
+ else if (clocktype == "adjusted")
+ {
+ return m_adjustedClock;
+ }
+ else if (clocktype == "system")
+ {
+ return m_systemClock;
+ }
+ return m_systemClock;
+ }
+
+}; // namespace coil
Added: trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h (rev 0)
+++ trunk/OpenRTM-aist/src/lib/coil/common/ClockManager.h 2012-02-07 02:09:55 UTC (rev 2310)
@@ -0,0 +1,180 @@
+// -*- C++ -*-
+/*!
+ * @file ClockManager.h
+ * @brief Global clock management class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2012
+ * Noriaki Ando
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef COIL_CLOCKMANAGER_H
+#define COIL_CLOCKMANAGER_H
+
+#include <string>
+#include <coil/Singleton.h>
+#include <coil/TimeValue.h>
+
+namespace coil
+{
+ /*!
+ * @if jp
+ * @class ÝèEæ¾IuWFNgÌC^[tF[X
+ *
+ * ±ÌNXÍ ClockManager ÉæÁÄdzêéNbNIuWFNgÌ
+ * ½ßÌC^[tF[XÅ éBClockManager Í¡ÌNbNIuWF
+ * NgðǵAKvɶÄKØÈNbNIuWFNgð IClock C
+ * ^[tF[XðàÂIuWFNgƵÄÔ·BNbNIuWFNgÍP
+ * ÉVXeðÔ·àÌâAÆ©Ì_ðÂNbNIuWFN
+ * gªl¦çêéB
+ *
+ * @else
+ * @brief An interface to set and get time
+ *
+ * This class is a interface for clock objects managed by
+ * ClockManager. ClockManager manages one or more clocks, and it
+ * returns appropriate clock objects according to demands. The clock
+ * object might be clock which just returns system time, or a clock
+ * which returns individual logical time.
+ *
+ * @endif
+ */
+ class IClock
+ {
+ public:
+ virtual ~IClock() {}
+ /*!
+ * @if jp
+ * @brief ðæ¾·é
+ * @return »ÝÌ
+ * @else
+ * @brief Getting time
+ * @return Current time
+ * @endif
+ */
+ virtual coil::TimeValue gettime() const = 0;
+ /*!
+ * @if jp
+ * @brief ðÝè·é
+ * @param clocktime »ÝÌ
+ * @else
+ * @brief Setting time
+ * @param clocktime Current time
+ * @endif
+ */
+ virtual bool settime(coil::TimeValue clocktime) = 0;
+ };
+
+ /*!
+ * @if jp
+ * @class VXeðµ¤NbNIuWFNg
+ *
+ * ±ÌNXÍVXeNbNðÝèܽÍæ¾·éNXÅ éB
+ *
+ * @else
+ * @brief clock object to handle system clock
+ *
+ * This class sets and gets system clock.
+ *
+ * @endif
+ */
+ class SystemClock
+ : public IClock
+ {
+ public:
+ virtual ~SystemClock();
+ virtual coil::TimeValue gettime() const;
+ virtual bool settime(coil::TimeValue clocktime);
+ };
+
+ /*!
+ * @if jp
+ * @class _Ôðµ¤NbNIuWFNg
+ *
+ * ±ÌNXÍ_ÔðÝèܽÍæ¾·éNXÅ éB
+ * PÉ settime() ÉæÁÄÝè³ê½ð gettime() ÉæÁÄæ¾·é·B
+ *
+ * @else
+ * @brief Clock object to handle logical clock
+ *
+ * This class sets and gets system clock.
+ * It just sets time by settime() and gets time by gettime().
+ *
+ * @endif
+ */
+ class LogicalClock
+ : public IClock
+ {
+ coil::TimeValue m_currentTime;
+ public:
+ LogicalClock();
+ virtual ~LogicalClock();
+ virtual coil::TimeValue gettime() const;
+ virtual bool settime(coil::TimeValue clocktime);
+ };
+
+ /*!
+ * @if jp
+ * @class ²®ÏÝðµ¤NbNIuWFNg
+ *
+ * settime() ÄÑoµÉ»ÝÆÌ·ðItZbgƵÄÛµA
+ * gettime() ÉæÁÄItZbg²®ÏÝÌðÔ·B
+ *
+ * @else
+ * @brief Clock object to handle adjusted clock
+ *
+ * This class stores a offset time with current system clock when
+ * settime(), and gettime() returns adjusted clock by the offset.
+ *
+ * @endif
+ */
+ class AdjustedClock
+ : public IClock
+ {
+ coil::TimeValue m_offset;
+ public:
+ AdjustedClock();
+ virtual ~AdjustedClock();
+ virtual coil::TimeValue gettime() const;
+ virtual bool settime(coil::TimeValue clocktime);
+ };
+
+ /*!
+ * @if jp
+ * @class O[oÈNbNÇNXB
+ *
+ * ±ÌNXÍO[oÉNbNIuWFNgðñ·éVOg
+ * NXÅ éBgetClocK(NbN¼) Éæè IClock ^ÌNbNIu
+ * WFNgðÔ·BpÂ\ÈNbNÍ "system", "logical" ¨æÑ
+ * "adjusted" ÌRíÞÅ éB
+ *
+ * @else
+ * @brief A global clock management class
+ *
+ * This class is a singleton class that provides clock objects
+ * globally. It provides a IClock object by getClock(<clock
+ * type>). As clock types, "system", "logical" and "adjusted" are
+ * available.
+ *
+ * @endif
+ */
+ class ClockManager
+ : public coil::Singleton<ClockManager>
+ {
+ public:
+ IClock& getClock(std::string clocktype);
+ private:
+ SystemClock m_systemClock;
+ LogicalClock m_logicalClock;
+ AdjustedClock m_adjustedClock;
+ };
+}; // namespace coil
+#endif // COIL_CLOCKMANAGER_H
Modified: trunk/OpenRTM-aist/src/lib/coil/common/Makefile.am
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/common/Makefile.am 2012-02-06 07:04:23 UTC (rev 2309)
+++ trunk/OpenRTM-aist/src/lib/coil/common/Makefile.am 2012-02-07 02:09:55 UTC (rev 2310)
@@ -5,17 +5,18 @@
## $Id$
##---------------------------------------------------------------------------
-COIL_COMMON_SRC = \
+COIL_COMMON_SRC = \
Allocator.cpp \
PeriodicTask.cpp\
Properties.cpp \
TimeValue.cpp \
TimeMeasure.cpp \
Timer.cpp \
- crc.cpp \
+ ClockManager.h \
+ crc.cpp \
stringutil.cpp
-COIL_COMMON_H = \
+COIL_COMMON_H = \
Allocator.h \
Async.h \
Listener.h \
@@ -28,6 +29,7 @@
PeriodicTask.h \
Properties.h \
Timer.h \
+ ClockManager.h \
Logger.h \
Singleton.h \
crc.h \
Modified: trunk/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am 2012-02-06 07:04:23 UTC (rev 2309)
+++ trunk/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am 2012-02-07 02:09:55 UTC (rev 2310)
@@ -35,6 +35,7 @@
TimeMeasure.cpp \
TimeValue.cpp \
Timer.cpp \
+ ClockManager.cpp \
crc.cpp \
stringutil.cpp
@@ -54,6 +55,7 @@
TimeMeasure.h \
TimeValue.h \
Timer.h \
+ ClockManager.h \
crc.h \
stringutil.h
Modified: trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am 2012-02-06 07:04:23 UTC (rev 2309)
+++ trunk/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am 2012-02-07 02:09:55 UTC (rev 2310)
@@ -33,6 +33,7 @@
TimeMeasure.cpp \
TimeValue.cpp \
Timer.cpp \
+ ClockManager.cpp \
crc.cpp \
stringutil.cpp
@@ -52,6 +53,7 @@
TimeMeasure.h \
TimeValue.h \
Timer.h \
+ ClockManager.h \
crc.h \
stringutil.h
openrtm-commit メーリングリストの案内