Fixing mutex

This commit is contained in:
stephb9959
2022-03-04 14:13:51 -08:00
parent 0221b79816
commit 72d7f16337
4 changed files with 46 additions and 4 deletions

View File

@@ -245,4 +245,32 @@ namespace OpenWifi::FMSObjects {
}
return false;
}
void DeviceInformation::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "serialNumber",serialNumber);
field_to_json(Obj, "history", history);
field_to_json(Obj, "currentFirmware", currentFirmware);
field_to_json(Obj, "currentFirmwareDate", currentFirmwareDate);
field_to_json(Obj, "latestFirmware", latestFirmware);
field_to_json(Obj, "latestFirmwareDate", latestFirmwareDate);
field_to_json(Obj, "latestFirmwareAvailable",latestFirmwareAvailable);
field_to_json(Obj, "latestFirmwareURI",latestFirmwareURI);
}
bool DeviceInformation::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serialNumber",serialNumber);
field_from_json(Obj, "history", history);
field_from_json(Obj, "currentFirmware", currentFirmware);
field_from_json(Obj, "currentFirmwareDate", currentFirmwareDate);
field_from_json(Obj, "latestFirmware", latestFirmware);
field_from_json(Obj, "latestFirmwareDate", latestFirmwareDate);
field_from_json(Obj, "latestFirmwareAvailable",latestFirmwareAvailable);
field_from_json(Obj, "latestFirmwareURI",latestFirmwareURI);
return true;
} catch(...) {
}
return false;
}
}

View File

@@ -127,6 +127,20 @@ namespace OpenWifi::FMSObjects {
void reset();
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct DeviceInformation {
std::string serialNumber;
RevisionHistoryEntryList history;
std::string currentFirmware;
uint64_t currentFirmwareDate=0;
std::string latestFirmware;
uint64_t latestFirmwareDate=0;
bool latestFirmwareAvailable;
std::string latestFirmwareURI;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
}

View File

@@ -18,7 +18,7 @@ namespace OpenWifi {
}
void SerialNumberCache::AddSerialNumber(const std::string &S, const std::string &DeviceType) {
std::lock_guard G(M_);
std::lock_guard G(Mutex_);
auto Hint = DeviceTypeDictionary_.find(DeviceType);
int Index;
@@ -41,7 +41,7 @@ namespace OpenWifi {
}
void SerialNumberCache::DeleteSerialNumber(const std::string &S) {
std::lock_guard G(M_);
std::lock_guard G(Mutex_);
uint64_t SN = std::stoull(S, nullptr,16);
auto It = std::find_if(SNs_.begin(),SNs_.end(),[SN](const DeviceTypeCacheEntry &E) { return E.SerialNumber == SN; });
@@ -51,7 +51,7 @@ namespace OpenWifi {
}
void SerialNumberCache::FindNumbers(const std::string &S, uint HowMany, std::vector<uint64_t> &A) {
std::lock_guard G(M_);
std::lock_guard G(Mutex_);
if(S.length()==12) {
uint64_t SN = std::stoull(S, nullptr, 16);
@@ -79,6 +79,7 @@ namespace OpenWifi {
}
bool SerialNumberCache::FindDevice(const std::string &SerialNumber, std::string & DeviceType) {
std::lock_guard G(Mutex_);
uint64_t SN = std::stoull(SerialNumber, nullptr, 16);
auto It = std::find_if(SNs_.begin(),SNs_.end(),[SN](const DeviceTypeCacheEntry &E) { return E.SerialNumber == SN; });
if(It != SNs_.end()) {

View File

@@ -40,7 +40,6 @@ namespace OpenWifi {
uint64_t LastUpdate_ = 0 ;
SerialCacheContent SNs_;
std::map<std::string,int> DeviceTypeDictionary_;
std::mutex M_;
SerialNumberCache() noexcept:
SubSystemServer("SerialNumberCache", "SNCACHE-SVR", "serialcache")