ArmarXTimeserver.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::application::ArmarXTimeserver
19 * @author Clemens Wallrath ( uagzs at student dot kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl.txt
22 * GNU General Public License
23 */
24
25#include "ArmarXTimeserver.h"
26
27namespace armarx
28{
29 void
31 {
32 offeringTopic(TIME_TOPIC_NAME);
33 clock = TimeKeeper();
34 stepTimeMS = getProperty<int>("TimeStepMS").getValue();
35 }
36
37 void
39 {
40 clock.start();
42
44 {
45 broadcastTimeTask->stop();
46 }
47
49 this, &ArmarXTimeserver::broadcastTime, 1, false, "SpammingTimeServer::Broadcast");
50 broadcastTimeTask->start();
51 }
52
53 void
57
58 void
62
63 Ice::Long
64 ArmarXTimeserver::getTime(const ::Ice::Current&)
65 {
66 return static_cast<Ice::Long>(clock.getTime().toMilliSeconds());
67 }
68
69 void
74
75 void
76 ArmarXTimeserver::stop(const ::Ice::Current&)
77 {
78 ARMARX_DEBUG << "TimeServer clock has stopped";
79 clock.stop();
80 }
81
82 void
83 ArmarXTimeserver::start(const ::Ice::Current&)
84 {
85 ARMARX_DEBUG << "TimeServer clock started";
86 clock.start();
87 }
88
89 void
90 ArmarXTimeserver::step(const ::Ice::Current&)
91 {
92 clock.step(IceUtil::Time::milliSeconds(stepTimeMS));
93 }
94
95 void
96 ArmarXTimeserver::setSpeed(Ice::Float newSpeed, const ::Ice::Current&)
97 {
98 ARMARX_DEBUG << "Setting TimeServer clock speed to " << newSpeed;
99 clock.setSpeed(newSpeed);
100 }
101
102 Ice::Float
103 ArmarXTimeserver::getSpeed(const Ice::Current&)
104 {
105 return clock.getSpeed();
106 }
107
108 Ice::Int
109 ArmarXTimeserver::getStepTimeMS(const ::Ice::Current&)
110 {
111 return stepTimeMS;
112 }
113
118
121 {
123 getConfigDomain() + "." +
124 "ArmarXTimeserver")); // not using defaultName since it has to be GLOBAL_TIMESERVER_NAME (="MasterTimeServer") for all timeservers
125 }
126} // namespace armarx
void setSpeed(Ice::Float newSpeed, const ::Ice::Current &=Ice::emptyCurrent) override
void broadcastTime()
periodically writes the current time to the "Time" topic
Ice::Int getStepTimeMS(const ::Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
void start(const ::Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
PeriodicTask< ArmarXTimeserver >::pointer_type broadcastTimeTask
broadcastTimeTask calls broadcastTime() periodically
int stepTimeMS
time the clock advances dirung one call of step() in milliseconds
void onConnectComponent() override
Ice::Float getSpeed(const ::Ice::Current &=Ice::emptyCurrent) override
TimeServerListenerPrx timeTopicPrx
a handle for the topic "Time"
void stop(const ::Ice::Current &=Ice::emptyCurrent) override
Ice::Long getTime(const ::Ice::Current &=Ice::emptyCurrent) override
getTime returns the current (simulator) time as milliseconds (as in IceUtil::Time::toMilliSeconds)
void step(const ::Ice::Current &=Ice::emptyCurrent) override
step() advances the time by the value of ArmarX.ArmarXTimeserver.StepTimeMS (in milliseconds) the def...
std::string getConfigDomain()
Retrieve config domain for this component as set in constructor.
Definition Component.cpp:76
Property< PropertyType > getProperty(const std::string &name)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
The TimeKeeper class tracks the passing of time and allows to stop it, restart it,...
Definition TimeKeeper.h:42
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.