From 791b3d039a33d58e4dbd2dde0d29a5927d41eccd Mon Sep 17 00:00:00 2001
From: Peter Kaiser <peter.kaiser@kit.edu>
Date: Fri, 15 Aug 2014 21:15:09 +0200
Subject: [PATCH] Added DummyUnit and DummyObserver as simple examples for the
 documentation

---
 scenarios/DummyTest/CMakeLists.txt            |  1 +
 scenarios/DummyTest/config/DummyUnitApp.cfg   | 83 +++++++++++++++++++
 .../DummyTest/config/DummyUnitObserver.cfg    | 83 +++++++++++++++++++
 source/RobotAPI/applications/CMakeLists.txt   |  3 +
 .../DummyUnitObserver/CMakeLists.txt          |  8 ++
 .../DummyUnitObserver/DummyUnitObserverApp.h  | 40 +++++++++
 .../applications/DummyUnitObserver/main.cpp   | 33 ++++++++
 source/RobotAPI/interface/CMakeLists.txt      |  1 +
 .../observers/DummyUnitObserverInterface.ice  | 37 +++++++++
 .../interface/units/DummyUnitInterface.ice    |  1 +
 source/RobotAPI/units/CMakeLists.txt          |  2 +
 source/RobotAPI/units/DummyUnit.cpp           | 15 ++++
 source/RobotAPI/units/DummyUnit.h             |  7 +-
 source/RobotAPI/units/DummyUnitObserver.cpp   | 47 +++++++++++
 source/RobotAPI/units/DummyUnitObserver.h     | 61 ++++++++++++++
 15 files changed, 421 insertions(+), 1 deletion(-)
 create mode 100644 scenarios/DummyTest/config/DummyUnitApp.cfg
 create mode 100644 scenarios/DummyTest/config/DummyUnitObserver.cfg
 create mode 100644 source/RobotAPI/applications/DummyUnitObserver/CMakeLists.txt
 create mode 100644 source/RobotAPI/applications/DummyUnitObserver/DummyUnitObserverApp.h
 create mode 100644 source/RobotAPI/applications/DummyUnitObserver/main.cpp
 create mode 100644 source/RobotAPI/interface/observers/DummyUnitObserverInterface.ice
 create mode 100644 source/RobotAPI/units/DummyUnitObserver.cpp
 create mode 100644 source/RobotAPI/units/DummyUnitObserver.h

diff --git a/scenarios/DummyTest/CMakeLists.txt b/scenarios/DummyTest/CMakeLists.txt
index e16143090..4cee04548 100644
--- a/scenarios/DummyTest/CMakeLists.txt
+++ b/scenarios/DummyTest/CMakeLists.txt
@@ -1,5 +1,6 @@
 set(SCENARIO_COMPONENTS
     DummyUnitApp
+    DummyUnitObserver
     )
 
 # optional 3rd parameter: "path/to/global/config.cfg"
diff --git a/scenarios/DummyTest/config/DummyUnitApp.cfg b/scenarios/DummyTest/config/DummyUnitApp.cfg
new file mode 100644
index 000000000..e0b8b5606
--- /dev/null
+++ b/scenarios/DummyTest/config/DummyUnitApp.cfg
@@ -0,0 +1,83 @@
+# ==================================================================
+# ArmarX properties
+# ==================================================================
+
+# ArmarX.DataPath:  Semicolon-separated search list for data files
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.DataPath = ""
+
+
+# ArmarX.Verbosity:  Global logging level for whole application
+#  Attributes:
+#  - Default:            Verbose
+#  - Case sensitivity:   no
+#  - Required:           no
+#  - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning}
+# ArmarX.Verbosity = Verbose
+
+
+# ArmarX.DisableLogging:  Turn logging off in whole application
+#  Attributes:
+#  - Default:            0
+#  - Case sensitivity:   no
+#  - Required:           no
+#  - Possible values: {0, 1, false, no, true, yes}
+# ArmarX.DisableLogging = 0
+
+
+# ArmarX.CachePath:  Path for cache files
+#  Attributes:
+#  - Default:            ${HOME}/.armarx/mongo/.cache
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache
+
+
+# ArmarX.ApplicationName:  Application name
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.ApplicationName = ""
+
+
+# ArmarX.Config:  Comma-separated list of configuration files 
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.Config = ""
+
+
+# ==================================================================
+# ArmarX.DummyUnit properties
+# ==================================================================
+
+# ArmarX.DummyUnit.ReportPeriod:  The unit's reporting period in ms
+#  Attributes:
+#  - Case sensitivity:   no
+#  - Required:           yes
+ArmarX.DummyUnit.ReportPeriod = 1000
+
+
+# ArmarX.DummyUnit.MinimumLoggingLevel:  Local logging level only for this component
+#  Attributes:
+#  - Default:            Undefined
+#  - Case sensitivity:   no
+#  - Required:           no
+#  - Possible values: {Error, Fatal, Info, Undefined, Verbose, Warning}
+# ArmarX.DummyUnit.MinimumLoggingLevel = Undefined
+
+
+# ArmarX.DummyUnit.ObjectName:  Name of IceGrid well-known object
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.DummyUnit.ObjectName = ""
+
+
+
diff --git a/scenarios/DummyTest/config/DummyUnitObserver.cfg b/scenarios/DummyTest/config/DummyUnitObserver.cfg
new file mode 100644
index 000000000..5994f9f5e
--- /dev/null
+++ b/scenarios/DummyTest/config/DummyUnitObserver.cfg
@@ -0,0 +1,83 @@
+# ==================================================================
+# ArmarX properties
+# ==================================================================
+
+# ArmarX.DataPath:  Semicolon-separated search list for data files
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.DataPath = ""
+
+
+# ArmarX.Verbosity:  Global logging level for whole application
+#  Attributes:
+#  - Default:            Verbose
+#  - Case sensitivity:   no
+#  - Required:           no
+#  - Possible values: {Debug, Error, Fatal, Important, Info, Undefined, Verbose, Warning}
+# ArmarX.Verbosity = Verbose
+
+
+# ArmarX.DisableLogging:  Turn logging off in whole application
+#  Attributes:
+#  - Default:            0
+#  - Case sensitivity:   no
+#  - Required:           no
+#  - Possible values: {0, 1, false, no, true, yes}
+# ArmarX.DisableLogging = 0
+
+
+# ArmarX.CachePath:  Path for cache files
+#  Attributes:
+#  - Default:            ${HOME}/.armarx/mongo/.cache
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache
+
+
+# ArmarX.ApplicationName:  Application name
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.ApplicationName = ""
+
+
+# ArmarX.Config:  Comma-separated list of configuration files 
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.Config = ""
+
+
+# ==================================================================
+# ArmarX.DummyUnitObserver properties
+# ==================================================================
+
+# ArmarX.DummyUnitObserver.ReportPeriod:  The unit's reporting period in ms
+#  Attributes:
+#  - Case sensitivity:   no
+#  - Required:           yes
+ArmarX.DummyUnitObserver.ReportPeriod = <set value!>
+
+
+# ArmarX.DummyUnitObserver.MinimumLoggingLevel:  Local logging level only for this component
+#  Attributes:
+#  - Default:            Undefined
+#  - Case sensitivity:   no
+#  - Required:           no
+#  - Possible values: {Error, Fatal, Info, Undefined, Verbose, Warning}
+# ArmarX.DummyUnitObserver.MinimumLoggingLevel = Undefined
+
+
+# ArmarX.DummyUnitObserver.ObjectName:  Name of IceGrid well-known object
+#  Attributes:
+#  - Default:            ""
+#  - Case sensitivity:   no
+#  - Required:           no
+# ArmarX.DummyUnitObserver.ObjectName = ""
+
+
+
diff --git a/source/RobotAPI/applications/CMakeLists.txt b/source/RobotAPI/applications/CMakeLists.txt
index 3018fcc51..9c5c39bca 100644
--- a/source/RobotAPI/applications/CMakeLists.txt
+++ b/source/RobotAPI/applications/CMakeLists.txt
@@ -21,3 +21,6 @@ add_subdirectory(PlatformUnitObserver)
 add_subdirectory(RobotStateComponent)
 add_subdirectory(RobotStateObserver)
 add_subdirectory(HandUnitObserver)
+add_subdirectory(DummyUnit)
+add_subdirectory(DummyUnitObserver)
+
diff --git a/source/RobotAPI/applications/DummyUnitObserver/CMakeLists.txt b/source/RobotAPI/applications/DummyUnitObserver/CMakeLists.txt
new file mode 100644
index 000000000..5ecfd42e2
--- /dev/null
+++ b/source/RobotAPI/applications/DummyUnitObserver/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+armarx_component_set_name(DummyUnitObserver)
+
+set(COMPONENT_LIBS RobotAPIUnits RobotAPICore RobotAPIInterfaces ArmarXInterfaces ArmarXCore ArmarXCoreObservers)
+
+set(SOURCES main.cpp DummyUnitObserverApp.h)
+
+armarx_add_component_executable("${SOURCES}")
diff --git a/source/RobotAPI/applications/DummyUnitObserver/DummyUnitObserverApp.h b/source/RobotAPI/applications/DummyUnitObserver/DummyUnitObserverApp.h
new file mode 100644
index 000000000..27d9c4cd9
--- /dev/null
+++ b/source/RobotAPI/applications/DummyUnitObserver/DummyUnitObserverApp.h
@@ -0,0 +1,40 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::application::DummyUnit
+ * @author     Peter Kaiser (peter dot kaiser at kit dot edu)
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#include <Core/core/application/Application.h>
+#include <RobotAPI/units/DummyUnitObserver.h>
+
+namespace armarx
+{
+    class DummyUnitObserverApp :
+		virtual public armarx::Application
+	{
+        void setup(const ManagedIceObjectRegistryInterfacePtr& registry, Ice::PropertiesPtr properties)
+        {
+            registry->addObject( Component::create<DummyUnitObserver>(properties) );
+        }
+    };
+}
+
+
+
diff --git a/source/RobotAPI/applications/DummyUnitObserver/main.cpp b/source/RobotAPI/applications/DummyUnitObserver/main.cpp
new file mode 100644
index 000000000..f33f71dbf
--- /dev/null
+++ b/source/RobotAPI/applications/DummyUnitObserver/main.cpp
@@ -0,0 +1,33 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::application::DummyUnit
+ * @author     Peter Kaiser (peter dot kaiser at kit dot edu)
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#include "DummyUnitObserverApp.h"
+#include <Core/core/logging/Logging.h>
+
+int main(int argc, char* argv[])
+{
+    armarx::ApplicationPtr app = armarx::Application::createInstance<armarx::DummyUnitObserverApp>();
+    app->setName("DummyUnitObserver");
+
+    return app->main(argc, argv);
+}
diff --git a/source/RobotAPI/interface/CMakeLists.txt b/source/RobotAPI/interface/CMakeLists.txt
index 194b47ee1..1b25210e2 100644
--- a/source/RobotAPI/interface/CMakeLists.txt
+++ b/source/RobotAPI/interface/CMakeLists.txt
@@ -9,6 +9,7 @@ set(SLICE_FILES
 	
 	observers/KinematicUnitObserverInterface.ice
 	observers/PlatformUnitObserverInterface.ice
+    observers/DummyUnitObserverInterface.ice
 
 	robotstate/LinkedPoseBase.ice
 	robotstate/PoseBase.ice
diff --git a/source/RobotAPI/interface/observers/DummyUnitObserverInterface.ice b/source/RobotAPI/interface/observers/DummyUnitObserverInterface.ice
new file mode 100644
index 000000000..8ee86c6ff
--- /dev/null
+++ b/source/RobotAPI/interface/observers/DummyUnitObserverInterface.ice
@@ -0,0 +1,37 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::units
+ * @author     Peter Kaiser (peter dot kaiser at kit dot edu)
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#ifndef _ARMARX_CORE_DUMMY_UNIT_OBSERVER_SLICE_
+#define _ARMARX_CORE_DUMMY_UNIT_OBSERVER_SLICE_
+
+#include <RobotAPI/interface/units/DummyUnitInterface.ice>
+#include <Core/interface/observers/ObserverInterface.ice>
+
+module armarx
+{
+    interface DummyUnitObserverInterface extends ObserverInterface, DummyUnitListener
+    {
+    };
+};
+
+#endif
diff --git a/source/RobotAPI/interface/units/DummyUnitInterface.ice b/source/RobotAPI/interface/units/DummyUnitInterface.ice
index 71b89cae2..8e970cbb9 100644
--- a/source/RobotAPI/interface/units/DummyUnitInterface.ice
+++ b/source/RobotAPI/interface/units/DummyUnitInterface.ice
@@ -26,6 +26,7 @@
 
 #include <RobotAPI/interface/units/UnitInterface.ice>
 #include <Core/interface/observers/VariantBase.ice>
+#include <Core/interface/observers/ObserverInterface.ice>
 
 /*
  * The DummyUnit is a SensorActorUnit that is only implemented for documentation
diff --git a/source/RobotAPI/units/CMakeLists.txt b/source/RobotAPI/units/CMakeLists.txt
index 09c34d7f9..5aaba769d 100644
--- a/source/RobotAPI/units/CMakeLists.txt
+++ b/source/RobotAPI/units/CMakeLists.txt
@@ -48,6 +48,7 @@ set(LIB_HEADERS
     PlatformUnitObserver.h
     SensorActorUnit.h
     DummyUnit.h
+    DummyUnitObserver.h
 )
 
 set(LIB_FILES
@@ -71,6 +72,7 @@ set(LIB_FILES
     PlatformUnitObserver.cpp
     SensorActorUnit.cpp
     DummyUnit.cpp
+    DummyUnitObserver.cpp
 )
 
 armarx_add_library("${LIB_NAME}" "${LIB_VERSION}" "${LIB_SOVERSION}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
diff --git a/source/RobotAPI/units/DummyUnit.cpp b/source/RobotAPI/units/DummyUnit.cpp
index 46e5ee14b..ff8abbfd4 100644
--- a/source/RobotAPI/units/DummyUnit.cpp
+++ b/source/RobotAPI/units/DummyUnit.cpp
@@ -29,12 +29,21 @@ void DummyUnit::onInitComponent()
 {
     period = getProperty<int>("ReportPeriod").getValue();
 
+    periodicValue = VariantPtr(new Variant(10));
+
     offeringTopic("PeriodicDummyValue");
 }
 
 void DummyUnit::onConnectComponent()
 {
     listenerPrx = getTopic<DummyUnitListenerPrx>("PeriodicDummyValue");
+
+    if(periodicTask)
+    {
+        periodicTask->stop();
+    }
+    periodicTask = new PeriodicTask<DummyUnit>(this, &DummyUnit::reportValue, period, false, "DummyValueProducer");
+    periodicTask->start();
 }
 
 void DummyUnit::onExitComponent()
@@ -43,9 +52,15 @@ void DummyUnit::onExitComponent()
 
 void DummyUnit::setPeriodicValue(const VariantBasePtr &value, const Ice::Current &c)
 {
+    periodicValue = VariantPtr::dynamicCast(value);
 }
 
 PropertyDefinitionsPtr DummyUnit::createPropertyDefinitions()
 {
     return PropertyDefinitionsPtr(new DummyUnitPropertyDefinitions(getConfigIdentifier()));
 }
+
+void DummyUnit::reportValue()
+{
+    listenerPrx->reportPeriodicValue(periodicValue);
+}
diff --git a/source/RobotAPI/units/DummyUnit.h b/source/RobotAPI/units/DummyUnit.h
index 687346939..2167a64d9 100644
--- a/source/RobotAPI/units/DummyUnit.h
+++ b/source/RobotAPI/units/DummyUnit.h
@@ -30,6 +30,7 @@
 #include <Core/core/application/properties/Properties.h>
 #include <Core/core/system/ImportExportComponent.h>
 #include <Core/observers/variant/Variant.h>
+#include <Core/core/services/tasks/PeriodicTask.h>
 
 #include <RobotAPI/interface/units/DummyUnitInterface.h>
 
@@ -62,10 +63,14 @@ namespace armarx
         virtual PropertyDefinitionsPtr createPropertyDefinitions();
 
     protected:
+        void reportValue();
+
         DummyUnitListenerPrx listenerPrx;
 
+        PeriodicTask<DummyUnit>::pointer_type periodicTask;
+
         int period;
-        Variant value;
+        VariantPtr periodicValue;
     };
 }
 
diff --git a/source/RobotAPI/units/DummyUnitObserver.cpp b/source/RobotAPI/units/DummyUnitObserver.cpp
new file mode 100644
index 000000000..336703696
--- /dev/null
+++ b/source/RobotAPI/units/DummyUnitObserver.cpp
@@ -0,0 +1,47 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::units
+ * @author     Peter Kaiser (peter dot kaiser at kit dot edu)
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#include "DummyUnitObserver.h"
+
+armarx::DummyUnitObserver::DummyUnitObserver()
+{
+}
+
+void armarx::DummyUnitObserver::onInitObserver()
+{
+    usingTopic("PeriodicDummyValue");
+}
+
+void armarx::DummyUnitObserver::onConnectObserver()
+{
+}
+
+void armarx::DummyUnitObserver::reportPeriodicValue(const armarx::VariantBasePtr &value, const Ice::Current &)
+{
+    ARMARX_INFO << VariantPtr::dynamicCast(value);
+}
+
+armarx::PropertyDefinitionsPtr armarx::DummyUnitObserver::createPropertyDefinitions()
+{
+    return armarx::PropertyDefinitionsPtr(new DummyUnitPropertyDefinitions(getConfigIdentifier()));
+}
diff --git a/source/RobotAPI/units/DummyUnitObserver.h b/source/RobotAPI/units/DummyUnitObserver.h
new file mode 100644
index 000000000..ca0f1f1f0
--- /dev/null
+++ b/source/RobotAPI/units/DummyUnitObserver.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::units
+ * @author     Peter Kaiser (peter dot kaiser at kit dot edu)
+ * @date       2014
+ * @copyright  http://www.gnu.org/licenses/gpl.txt
+ *             GNU General Public License
+ */
+
+#ifndef _ARMARX_ROBOTAPI_DUMMYUNIT_OBSERVER_H
+#define _ARMARX_ROBOTAPI_DUMMYUNIT_OBSERVER_H
+
+#include <RobotAPI/interface/observers/DummyUnitObserverInterface.h>
+#include <Core/observers/Observer.h>
+#include <Core/core/application/properties/Properties.h>
+
+namespace armarx
+{
+    class DummyUnitPropertyDefinitions : public ComponentPropertyDefinitions
+    {
+        public:
+            DummyUnitPropertyDefinitions(std::string prefix) :
+                ComponentPropertyDefinitions(prefix)
+            {
+                // No required properties
+            }
+    };
+
+    class DummyUnitObserver :
+            virtual public Observer,
+            virtual public DummyUnitObserverInterface
+    {
+    public:
+        DummyUnitObserver();
+
+        virtual std::string getDefaultName() const { return "DummyUnitObserver"; }
+        void onInitObserver();
+        void onConnectObserver();
+
+        void reportPeriodicValue(const VariantBasePtr &value, const ::Ice::Current& = ::Ice::Current());
+
+        virtual PropertyDefinitionsPtr createPropertyDefinitions();
+    };
+}
+
+#endif
+
-- 
GitLab