JsonStorage.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXCore::ArmarXObjects::JsonStorage
17 * @author Fabian Paus ( fabian dot paus at kit dot edu )
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "JsonStorage.h"
24
27
28namespace armarx
29{
31
40
41 std::string
43 {
44 return "JsonStorage";
45 }
46
47 void
51
52 void
56
57 void
61
62 void
66
73
74 void
75 JsonStorage::storeJsonValue(const JsonStoreValue& value, const Ice::Current&)
76 {
77 long timestampInMicroSeconds = TimeUtil::GetTime().toMicroSeconds();
78
79 std::lock_guard lock(mutex);
80
81 revision += 1;
82
83 JsonRetrieveValue& inserted = data[value.key];
84 inserted.key = value.key;
85 inserted.value = value.value;
86 inserted.provider = value.provider;
87 inserted.revision = revision;
88 inserted.timestampInMicroSeconds = timestampInMicroSeconds;
89 }
90
91 JsonRetrieveValue
92 JsonStorage::retrieveValue(const std::string& key, const Ice::Current&)
93 {
94 std::lock_guard lock(mutex);
95
96 auto it = data.find(key);
97 if (it == data.end())
98 {
99 return JsonRetrieveValue();
100 }
101 else
102 {
103 return it->second;
104 }
105 }
106
107} // namespace armarx
#define ARMARX_DECOUPLED_REGISTER_COMPONENT(ComponentT)
Definition Decoupled.h:34
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
JsonStoragePropertyDefinitions(std::string prefix)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
Pure virtual hook for the subclass.
void storeJsonValue(const JsonStoreValue &value, const Ice::Current &) override
JsonRetrieveValue retrieveValue(const std::string &key, const Ice::Current &) override
std::map< std::string, JsonRetrieveValue > data
Definition JsonStorage.h:49
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Retrieve default name of component.