28
28
#include < lib/support/Base64.h>
29
29
#include < lib/support/CHIPMem.h>
30
30
#include < lib/support/CodeUtils.h>
31
+ #include < platform/KeyValueStoreManager.h>
31
32
32
33
#include " ../clusters/JsonParser.h"
33
34
@@ -41,6 +42,35 @@ constexpr const char * kJsonCommandKey = "command";
41
42
constexpr const char * kJsonCommandSpecifierKey = " command_specifier" ;
42
43
constexpr const char * kJsonArgumentsKey = " arguments" ;
43
44
45
+ template <typename T>
46
+ struct HasInitWithString
47
+ {
48
+ template <typename U>
49
+ static constexpr auto check (U *) -> typename std::is_same<decltype(std::declval<U>().Init(" " )), CHIP_ERROR>::type;
50
+
51
+ template <typename >
52
+ static constexpr std::false_type check (...);
53
+
54
+ typedef decltype (check<std::remove_reference_t <T>>(nullptr )) type;
55
+
56
+ public:
57
+ static constexpr bool value = type::value;
58
+ };
59
+
60
+ // Template so we can do conditional enabling
61
+ template <typename T, std::enable_if_t <HasInitWithString<T>::value, int > = 0 >
62
+ static void UseStorageDirectory (T & storageManagerImpl, const char * storageDirectory)
63
+ {
64
+ #if !CHIP_DISABLE_PLATFORM_KVS
65
+ std::string platformKVS = std::string (storageDirectory) + " /chip_tool_kvs" ;
66
+ storageManagerImpl.Init (platformKVS.c_str ());
67
+ #endif // !CHIP_DISABLE_PLATFORM_KVS
68
+ }
69
+
70
+ template <typename T, std::enable_if_t <!HasInitWithString<T>::value, int > = 0 >
71
+ static void UseStorageDirectory (T & storageManagerImpl, const char * storageDirectory)
72
+ {}
73
+
44
74
bool GetArgumentsFromJson (Command * command, Json::Value & value, bool optional, std::vector<std::string> & outArgs)
45
75
{
46
76
auto memberNames = value.getMemberNames ();
@@ -290,6 +320,8 @@ CHIP_ERROR Commands::RunCommand(int argc, char ** argv, bool interactive,
290
320
}
291
321
292
322
chip::Logging::SetLogFilter (mStorage .GetLoggingLevel ());
323
+
324
+ UseStorageDirectory (chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl (), mStorage .GetDirectory ());
293
325
#endif // CONFIG_USE_LOCAL_STORAGE
294
326
295
327
return command->Run ();
0 commit comments