mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-01 19:28:01 +00:00
Adding proper capabilities/platform cache.
This commit is contained in:
@@ -7,10 +7,11 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "CentralConfig.h"
|
||||||
#include "Poco/JSON/Parser.h"
|
#include "Poco/JSON/Parser.h"
|
||||||
#include "Poco/JSON/Object.h"
|
#include "Poco/JSON/Object.h"
|
||||||
#include "Poco/Data/RecordSet.h"
|
#include "Poco/Data/RecordSet.h"
|
||||||
|
#include "CapabilitiesCache.h"
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -25,23 +26,11 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
uint64_t Now = std::time(nullptr);
|
uint64_t Now = std::time(nullptr);
|
||||||
|
|
||||||
// Find compatible in the capabilities...
|
OpenWifi::Config::Capabilities Caps(Capabilities);
|
||||||
std::string Compatible;
|
|
||||||
|
|
||||||
Poco::JSON::Parser P;
|
Compat = Caps.Compatible();
|
||||||
Poco::JSON::Parser IncomingParser;
|
if(!Caps.Compatible().empty() && !Caps.Platform().empty())
|
||||||
Poco::JSON::Object::Ptr Obj = IncomingParser.parse(Capabilities).extract<Poco::JSON::Object::Ptr>();
|
CapabilitiesCache::instance()->Add(Caps.Compatible(),Caps.Platform());
|
||||||
Poco::DynamicStruct ds = *Obj;
|
|
||||||
|
|
||||||
if(ds.contains("compatible")) {
|
|
||||||
Compat = Compatible = ds["compatible"].toString();
|
|
||||||
} else {
|
|
||||||
// Maybe this is an old firmware
|
|
||||||
auto TmpCompatible = ds["model"]["id"].toString();
|
|
||||||
|
|
||||||
for(const auto &i:TmpCompatible)
|
|
||||||
Compatible += (char) ( i==',' ? '_' : i);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string St{"SELECT SerialNumber FROM Capabilities WHERE SerialNumber=?"};
|
std::string St{"SELECT SerialNumber FROM Capabilities WHERE SerialNumber=?"};
|
||||||
Select << ConvertParams(St),
|
Select << ConvertParams(St),
|
||||||
@@ -49,7 +38,10 @@ namespace OpenWifi {
|
|||||||
Poco::Data::Keywords::use(SerialNumber);
|
Poco::Data::Keywords::use(SerialNumber);
|
||||||
Select.execute();
|
Select.execute();
|
||||||
|
|
||||||
{ std::lock_guard G(Mutex_); CapsCache_[Compatible] = Capabilities; }
|
{
|
||||||
|
std::lock_guard G(Mutex_);
|
||||||
|
CapsCache_[Compat] = Capabilities;
|
||||||
|
}
|
||||||
|
|
||||||
if (SS.empty()) {
|
if (SS.empty()) {
|
||||||
Logger_.information("Adding capabilities for " + SerialNumber);
|
Logger_.information("Adding capabilities for " + SerialNumber);
|
||||||
@@ -78,7 +70,7 @@ namespace OpenWifi {
|
|||||||
Update.execute();
|
Update.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::SetDeviceCompatibility(SerialNumber, Compatible);
|
Storage::SetDeviceCompatibility(SerialNumber, Compat);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (const Poco::Exception &E) {
|
catch (const Poco::Exception &E) {
|
||||||
|
|||||||
Reference in New Issue
Block a user