Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-7831
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Oct 4, 2023
1 parent 65e5669 commit 3469b20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
26 changes: 6 additions & 20 deletions src/DeviceTypeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,9 @@ namespace OpenWifi {
std::lock_guard G(Mutex_);

Initialized_ = true;
std::string DeviceTypes;
if (AppServiceRegistry().Get("deviceTypes", DeviceTypes)) {
Poco::JSON::Parser P;
try {
auto O = P.parse(DeviceTypes).extract<Poco::JSON::Array::Ptr>();
for (const auto &i : *O) {
DeviceTypes_.insert(i.toString());
}
} catch (...) {
}
}
std::vector<std::string> DeviceTypes;
AppServiceRegistry().Get("deviceTypes", DeviceTypes);
std::for_each(DeviceTypes.begin(),DeviceTypes.end(),[&](const std::string &s){ DeviceTypes_.insert(s);});
}

inline bool UpdateDeviceTypes() {
Expand Down Expand Up @@ -107,15 +99,9 @@ namespace OpenWifi {

inline void SaveCache() {
std::lock_guard G(Mutex_);

Poco::JSON::Array Arr;
for (auto const &i : DeviceTypes_)
Arr.add(i);

std::stringstream OS;
Arr.stringify(OS);

AppServiceRegistry().Set("deviceTypes", OS.str());
std::vector<std::string> DeviceTypes;
std::for_each(DeviceTypes_.begin(),DeviceTypes_.end(),[&](const std::string &s){DeviceTypes.emplace_back(s);});
AppServiceRegistry().Set("deviceTypes", DeviceTypes);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/framework/AppServiceRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace OpenWifi {
}

bool Get(const char *key, std::vector<std::string> &Value) {
if(Registry_->has(key) && Registry_->isArray(key)) {
if(Registry_->has(key) && !Registry_->isNull(key) && Registry_->isArray(key)) {
auto Arr = Registry_->get(key);
for(const auto &v:Arr) {
Value.emplace_back(v);
Expand Down

0 comments on commit 3469b20

Please sign in to comment.