JsonStorageComponentPlugin.cpp
Go to the documentation of this file.
2
4#include <ArmarXCore/interface/components/JsonStorageInterface.h>
5
6namespace 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
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
88namespace 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
std::string makePropertyName(const std::string &name)
std::string getName() const
Retrieve name of object.
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
JsonStorageRetrievedValue JsonStorage_retrieveValue(std::string const &key)
void JsonStorage_storeValue(std::string const &key, nlohmann::json const &value)
void storeValue(std::string const &key, nlohmann::json const &value)
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
JsonStorageRetrievedValue retrieveValue(std::string const &key)