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