[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Žæ“¾ƒIƒuƒWƒFƒNƒg‚̃Cƒ“ƒ^[ƒtƒF[ƒX
+   *
+   * ‚±‚̃Nƒ‰ƒX‚Í ClockManager ‚É‚æ‚Á‚ÄŠÇ—‚³‚ê‚éƒNƒƒbƒNƒIƒuƒWƒFƒNƒg‚Ì
+   * ‚½‚߂̃Cƒ“ƒ^[ƒtƒF[ƒX‚Å‚ ‚éBClockManager ‚Í•¡”‚̃NƒƒbƒNƒIƒuƒWƒF
+   * ƒNƒg‚ðŠÇ—‚µA•K—v‚ɉž‚¶‚Ä“KØ‚ȃNƒƒbƒNƒIƒuƒWƒFƒNƒg‚ð IClock ƒCƒ“
+   * ƒ^[ƒtƒF[ƒX‚ð‚à‚ƒIƒuƒWƒFƒNƒg‚Æ‚µ‚Ä•Ô‚·BƒNƒƒbƒNƒIƒuƒWƒFƒNƒg‚Í’P
+   * ‚ɃVƒXƒeƒ€Žž‚ð•Ô‚·‚à‚Ì‚âA“ÆŽ©‚̘_—Žž‚ðŽ‚ÂƒNƒƒbƒNƒIƒuƒWƒFƒN
+   * ƒ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 ƒVƒXƒeƒ€Žž‚ðˆµ‚¤ƒNƒƒbƒNƒIƒuƒWƒFƒNƒg
+   *
+   * ‚±‚̃Nƒ‰ƒX‚̓VƒXƒeƒ€ƒNƒƒbƒN‚ðÝ’è‚Ü‚½‚͎擾‚·‚éƒNƒ‰ƒX‚Å‚ ‚é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 ˜_—ŽžŠÔ‚ðˆµ‚¤ƒNƒƒbƒNƒIƒuƒWƒFƒNƒg
+   *
+   * ‚±‚̃Nƒ‰ƒX‚͘_—ŽžŠÔ‚ðÝ’è‚Ü‚½‚͎擾‚·‚éƒNƒ‰ƒX‚Å‚ ‚é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 ’²®Ï‚ÝŽž‚ðˆµ‚¤ƒNƒƒbƒNƒIƒuƒWƒFƒNƒg
+   *
+   * settime() ŒÄ‚яo‚µŽž‚ÉŒ»ÝŽž‚Ƃ̍·‚ðƒIƒtƒZƒbƒg‚Æ‚µ‚Ä•ÛŽ‚µA
+   * gettime() ‚É‚æ‚Á‚ăIƒtƒZƒbƒg’²®Ï‚Ý‚ÌŽž‚ð•Ô‚·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ƒ‹‚ȃNƒƒbƒNŠÇ—ƒNƒ‰ƒXB
+   *
+   * ‚±‚̃Nƒ‰ƒX‚̓Oƒ[ƒoƒ‹‚ɃNƒƒbƒNƒIƒuƒWƒFƒNƒg‚ð’ñ‹Ÿ‚·‚éƒVƒ“ƒOƒ‹ƒgƒ“
+   * ƒNƒ‰ƒX‚Å‚ ‚éBgetClocK(ƒNƒƒbƒN–¼) ‚É‚æ‚è IClock Œ^‚̃NƒƒbƒNƒIƒu
+   * ƒWƒFƒNƒg‚ð•Ô‚·B—˜—p‰Â”\‚ȃNƒƒbƒN‚Í "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 メーリングリストの案内