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 
26 
28 
29 
30 namespace armarx
31 {
33 
36  {
37  public:
40  {
41  }
42  };
43 
44 
45  std::string JsonStorage::getDefaultName() const
46  {
47  return "JsonStorage";
48  }
49 
50 
52  {
53 
54  }
55 
56 
58  {
59 
60  }
61 
62 
64  {
65 
66  }
67 
68 
70  {
71 
72  }
73 
75  {
78  }
79 
80  void JsonStorage::storeJsonValue(const JsonStoreValue& value, const Ice::Current&)
81  {
82  long timestampInMicroSeconds = TimeUtil::GetTime().toMicroSeconds();
83 
84  std::lock_guard lock(mutex);
85 
86  revision += 1;
87 
88  JsonRetrieveValue& inserted = data[value.key];
89  inserted.key = value.key;
90  inserted.value = value.value;
91  inserted.provider = value.provider;
92  inserted.revision = revision;
93  inserted.timestampInMicroSeconds = timestampInMicroSeconds;
94  }
95 
96  JsonRetrieveValue JsonStorage::retrieveValue(const std::string& key, const Ice::Current&)
97  {
98  std::lock_guard lock(mutex);
99 
100  auto it = data.find(key);
101  if (it == data.end())
102  {
103  return JsonRetrieveValue();
104  }
105  else
106  {
107  return it->second;
108  }
109  }
110 
111 }
112 
armarx::JsonStorage::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
Definition: JsonStorage.cpp:74
armarx::JsonStorage::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: JsonStorage.cpp:51
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::JsonStorage::mutex
std::mutex mutex
Definition: JsonStorage.h:50
armarx::JsonStorage::storeJsonValue
void storeJsonValue(const JsonStoreValue &value, const Ice::Current &) override
Definition: JsonStorage.cpp:80
armarx::ARMARX_DECOUPLED_REGISTER_COMPONENT
ARMARX_DECOUPLED_REGISTER_COMPONENT(JsonStorage)
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
JsonStorage.h
armarx::JsonStoragePropertyDefinitions
Definition: JsonStorage.cpp:34
armarx::JsonStorage::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: JsonStorage.cpp:45
armarx::JsonStoragePropertyDefinitions::JsonStoragePropertyDefinitions
JsonStoragePropertyDefinitions(std::string prefix)
Definition: JsonStorage.cpp:38
armarx::JsonStorage::retrieveValue
JsonRetrieveValue retrieveValue(const std::string &key, const Ice::Current &) override
Definition: JsonStorage.cpp:96
armarx::JsonStorage::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: JsonStorage.cpp:63
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::JsonStorage::data
std::map< std::string, JsonRetrieveValue > data
Definition: JsonStorage.h:51
Decoupled.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
TimeUtil.h
armarx::JsonStorage::revision
long revision
Definition: JsonStorage.h:52
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::JsonStorage::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: JsonStorage.cpp:69
armarx::JsonStorage::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: JsonStorage.cpp:57
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28