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 
28 namespace armarx
29 {
31 
33  {
34  public:
37  {
38  }
39  };
40 
41  std::string
43  {
44  return "JsonStorage";
45  }
46 
47  void
49  {
50  }
51 
52  void
54  {
55  }
56 
57  void
59  {
60  }
61 
62  void
64  {
65  }
66 
69  {
72  }
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
armarx::JsonStorage::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
Definition: JsonStorage.cpp:68
armarx::JsonStorage::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: JsonStorage.cpp:48
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::JsonStorage::mutex
std::mutex mutex
Definition: JsonStorage.h:48
armarx::JsonStorage::storeJsonValue
void storeJsonValue(const JsonStoreValue &value, const Ice::Current &) override
Definition: JsonStorage.cpp:75
armarx::ARMARX_DECOUPLED_REGISTER_COMPONENT
ARMARX_DECOUPLED_REGISTER_COMPONENT(JsonStorage)
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
JsonStorage.h
armarx::JsonStoragePropertyDefinitions
Definition: JsonStorage.cpp:32
armarx::JsonStorage::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: JsonStorage.cpp:42
armarx::JsonStoragePropertyDefinitions::JsonStoragePropertyDefinitions
JsonStoragePropertyDefinitions(std::string prefix)
Definition: JsonStorage.cpp:35
armarx::JsonStorage::retrieveValue
JsonRetrieveValue retrieveValue(const std::string &key, const Ice::Current &) override
Definition: JsonStorage.cpp:92
armarx::JsonStorage::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: JsonStorage.cpp:58
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:79
armarx::JsonStorage::data
std::map< std::string, JsonRetrieveValue > data
Definition: JsonStorage.h:49
Decoupled.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
TimeUtil.h
armarx::JsonStorage::revision
long revision
Definition: JsonStorage.h:50
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::JsonStorage::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: JsonStorage.cpp:63
armarx::JsonStorage::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: JsonStorage.cpp:53
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27