JsonStorageComponentPlugin.cpp
Go to the documentation of this file.
2 
4 
5 #include <ArmarXCore/interface/components/JsonStorageInterface.h>
6 
7 
8 namespace armarx::plugins
9 {
11  {
12  std::string propertyName;
13  JsonStorageInterfacePrx proxy;
14 
15  std::string componentName;
16  };
17 
18  static const char* const JsonStorage_PropertyName = "JsonStorageName";
19 
21  {
22 
23  }
24 
26  {
27  if (!impl)
28  {
29  impl.reset(new Impl);
30  impl->propertyName = makePropertyName(JsonStorage_PropertyName);
31  impl->componentName = parent<Component>().getName();
32  }
33 
34  if (!impl->proxy)
35  {
36  parent<Component>().usingProxyFromProperty(impl->propertyName);
37  }
38  }
39 
41  {
42  parent<Component>().getProxyFromProperty(impl->proxy, impl->propertyName);
43  }
44 
46  {
47  if (!properties->hasDefinition(makePropertyName(JsonStorage_PropertyName)))
48  {
49  properties->defineOptionalProperty<std::string>(
50  makePropertyName(JsonStorage_PropertyName),
51  "JsonStorage",
52  "Name of the JSON storage (duh)");
53  }
54  }
55 
56  void JsonStorageComponentPlugin::storeValue(const std::string& key, const nlohmann::json& value)
57  {
58  JsonStoreValue insert;
59  insert.key = key;
60  insert.value = value.dump();
61  insert.provider = impl->componentName;
62  impl->proxy->storeJsonValue(insert);
63  }
64 
66  {
67  JsonRetrieveValue iceResult = impl->proxy->retrieveValue(key);
68 
70  result.valid = !iceResult.key.empty();
71  if (result.valid)
72  {
73  result.key = iceResult.key;
74  result.value = nlohmann::json::parse(iceResult.value);
75  result.provider = iceResult.provider;
76  result.revision = iceResult.revision;
77  result.storeTimestamp = IceUtil::Time::microSeconds(iceResult.timestampInMicroSeconds);
78  }
79 
80  return result;
81  }
82 
83 
84 }
85 
86 namespace armarx
87 {
88  void JsonStorageComponentPluginUser::JsonStorage_storeValue(const std::string& key, const nlohmann::json& value)
89  {
90  plugin->storeValue(key, value);
91  }
92 
94  {
95  return plugin->retrieveValue(key);
96  }
97 }
armarx::JsonStorageComponentPluginUser::plugin
JsonStorageComponentPlugin * plugin
Definition: JsonStorageComponentPlugin.h:89
armarx::JsonStorageComponentPluginUser::JsonStorage_storeValue
void JsonStorage_storeValue(std::string const &key, nlohmann::json const &value)
Definition: JsonStorageComponentPlugin.cpp:88
armarx::plugins::JsonStorageComponentPlugin::Impl::propertyName
std::string propertyName
Definition: JsonStorageComponentPlugin.cpp:12
armarx::JsonStorageRetrievedValue::provider
std::string provider
Definition: JsonStorageComponentPlugin.h:38
armarx::plugins::JsonStorageComponentPlugin::Impl
Definition: JsonStorageComponentPlugin.cpp:10
armarx::plugins::JsonStorageComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: JsonStorageComponentPlugin.cpp:45
armarx::plugins::JsonStorageComponentPlugin::impl
std::unique_ptr< Impl > impl
Definition: JsonStorageComponentPlugin.h:69
armarx::plugins::JsonStorageComponentPlugin::retrieveValue
JsonStorageRetrievedValue retrieveValue(std::string const &key)
Definition: JsonStorageComponentPlugin.cpp:65
armarx::plugins::JsonStorageComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: JsonStorageComponentPlugin.cpp:40
armarx::plugins::JsonStorageComponentPlugin::storeValue
void storeValue(std::string const &key, nlohmann::json const &value)
Definition: JsonStorageComponentPlugin.cpp:56
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::JsonStorageRetrievedValue::revision
long revision
Definition: JsonStorageComponentPlugin.h:39
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::plugins::JsonStorageComponentPlugin::Impl::componentName
std::string componentName
Definition: JsonStorageComponentPlugin.cpp:15
armarx::armem::server::ltm::util::mongodb::detail::insert
bool insert(mongocxx::collection &coll, const nlohmann::json &value)
Definition: mongodb.cpp:43
armarx::plugins::JsonStorageComponentPlugin::Impl::proxy
JsonStorageInterfacePrx proxy
Definition: JsonStorageComponentPlugin.cpp:13
Component.h
armarx::JsonStorageRetrievedValue::value
nlohmann::json value
Definition: JsonStorageComponentPlugin.h:37
armarx::plugins::JsonStorageComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: JsonStorageComponentPlugin.cpp:25
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::plugins::JsonStorageComponentPlugin::~JsonStorageComponentPlugin
~JsonStorageComponentPlugin()
Definition: JsonStorageComponentPlugin.cpp:20
armarx::ManagedIceObjectPlugin::makePropertyName
std::string makePropertyName(const std::string &name)
Definition: ManagedIceObjectPlugin.cpp:53
armarx::JsonStorageComponentPluginUser::JsonStorage_retrieveValue
JsonStorageRetrievedValue JsonStorage_retrieveValue(std::string const &key)
Definition: JsonStorageComponentPlugin.cpp:93
armarx::JsonStorageRetrievedValue::key
std::string key
Definition: JsonStorageComponentPlugin.h:36
armarx::JsonStorageRetrievedValue
Definition: JsonStorageComponentPlugin.h:34
armarx::JsonStorageRetrievedValue::valid
bool valid
Definition: JsonStorageComponentPlugin.h:41
JsonStorageComponentPlugin.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::JsonStorageRetrievedValue::storeTimestamp
IceUtil::Time storeTimestamp
Definition: JsonStorageComponentPlugin.h:40