diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c54695..db74ab2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -project(owfms VERSION 2.4.0) +project(owfms VERSION 2.5.0) set(CMAKE_CXX_STANDARD 17) diff --git a/build b/build index cabf43b..56a6051 100644 --- a/build +++ b/build @@ -1 +1 @@ -24 \ No newline at end of file +1 \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index 53e780a..9526e4a 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -562,7 +562,7 @@ namespace OpenWifi::ProvObjects { } I.notes = N; I.modified = I.created = Now; - I.id = MicroService::instance().CreateUUID(); + I.id = MicroService::CreateUUID(); return true; } diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 935b57c..3b5ca09 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -6,8 +6,7 @@ // Arilia Wireless Inc. // -#ifndef OPENWIFI_MICROSERVICE_H -#define OPENWIFI_MICROSERVICE_H +#pragma once #include #include @@ -20,6 +19,7 @@ #include #include #include +#include using namespace std::chrono_literals; @@ -58,10 +58,12 @@ using namespace std::chrono_literals; #include "Poco/Net/HTTPSClientSession.h" #include "Poco/Net/NetworkInterface.h" #include "Poco/ExpireLRUCache.h" +#include "Poco/JSON/Object.h" +#include "Poco/JSON/Parser.h" +#include "Poco/StringTokenizer.h" #include "cppkafka/cppkafka.h" -#include "framework/OpenWifiTypes.h" #include "framework/KafkaTopics.h" #include "framework/RESTAPI_protocol.h" #include "framework/RESTAPI_errors.h" @@ -168,12 +170,13 @@ namespace OpenWifi::RESTAPI_utils { Obj.set(Field,S); } - inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const std::vector & S) { + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) { Poco::JSON::Array Array; for(const auto &i:S) { Poco::JSON::Object O; O.set("tag",i.first); O.set("value", i.second); + Array.add(O); } Obj.set(Field,Array); } @@ -211,7 +214,6 @@ namespace OpenWifi::RESTAPI_utils { Obj.set(Field,A); } - template void field_to_json(Poco::JSON::Object &Obj, const char *Field, const T &V, @@ -241,6 +243,7 @@ namespace OpenWifi::RESTAPI_utils { V = (Obj->get(Field).toString() == "true"); } + inline void field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, Types::StringPairVec &Vec) { if(Obj->isArray(Field)) { auto O = Obj->getArray(Field); @@ -450,11 +453,12 @@ namespace OpenWifi::RESTAPI_utils { try { Poco::JSON::Parser P; auto Object = P.parse(S).template extract(); - for (auto const &i : *Object) { + for (const auto &i : *Object) { auto InnerObject = i.template extract(); if(InnerObject->size()==2) { - Types::StringPair P{InnerObject->get(0).toString(), InnerObject->get(1).toString()}; - R.push_back(P); + auto S1 = InnerObject->getElement(0); + auto S2 = InnerObject->getElement(1); + R.push_back(std::make_pair(S1,S2)); } } } catch (...) { @@ -3897,5 +3901,3 @@ namespace OpenWifi::CIDR { return std::all_of(cbegin(Ranges), cend(Ranges), ValidateRange); } } - -#endif // UCENTRALGW_MICROSERVICE_H diff --git a/src/framework/OpenWifiTypes.h b/src/framework/OpenWifiTypes.h index 8952de6..c5b3804 100644 --- a/src/framework/OpenWifiTypes.h +++ b/src/framework/OpenWifiTypes.h @@ -1,103 +1,40 @@ // -// License type: BSD 3-Clause License -// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE -// -// Created by Stephane Bourque on 2021-03-04. -// Arilia Wireless Inc. +// Created by stephane bourque on 2021-11-16. // -#ifndef UCENTRALGW_UCENTRALTYPES_H -#define UCENTRALGW_UCENTRALTYPES_H +#pragma once -#include -#include #include -#include -#include #include +#include +#include +#include #include - -#include "Poco/StringTokenizer.h" -#include "Poco/JSON/Parser.h" -#include "Poco/JSON/Stringifier.h" +#include +#include namespace OpenWifi::Types { typedef std::pair StringPair; - typedef std::vector StringPairVec; + typedef std::vector StringPairVec; typedef std::queue StringPairQueue; - typedef std::vector StringVec; - typedef std::set StringSet; - typedef std::map> StringMapStringSet; - typedef std::function TopicNotifyFunction; - typedef std::list> TopicNotifyFunctionList; - typedef std::map NotifyTable; + typedef std::vector StringVec; + typedef std::set StringSet; + typedef std::map> StringMapStringSet; + typedef std::function TopicNotifyFunction; + typedef std::list> TopicNotifyFunctionList; + typedef std::map NotifyTable; typedef std::map CountedMap; typedef std::vector TagList; typedef std::string UUID_t; typedef std::vector UUIDvec_t; +} - inline void UpdateCountedMap(CountedMap &M, const std::string &S, uint64_t Increment=1) { +namespace OpenWifi { + inline void UpdateCountedMap(OpenWifi::Types::CountedMap &M, const std::string &S, uint64_t Increment=1) { auto it = M.find(S); if(it==M.end()) M[S] = Increment; else it->second += Increment; } - - inline std::string to_string( const StringVec &V) { - Poco::JSON::Array O; - for(const auto &i:V) { - O.add(i); - } - std::stringstream SS; - Poco::JSON::Stringifier::stringify(O,SS); - return SS.str(); - } - - inline std::string to_string( const StringPairVec &V) { - Poco::JSON::Array O; - for(const auto &i:V) { - Poco::JSON::Array OO; - OO.add(i.first); - OO.add(i.second); - O.add(OO); - } - - std::stringstream SS; - Poco::JSON::Stringifier::stringify(O,SS); - return SS.str(); - } - - inline void from_string(const std::string &S, StringPairVec &V) { - try { - Poco::JSON::Parser P; - auto O = P.parse(S).extract(); - - for(const auto &i:*O) { - auto Inner = i.extract(); - for(const auto &j:*Inner) { - auto S1 = i[0].toString(); - auto S2 = i[1].toString(); - V.push_back(std::make_pair(S1,S2)); - } - } - } catch (...) { - - } - } - - inline void from_string(const std::string &S, StringVec &V) { - try { - Poco::JSON::Parser P; - auto O = P.parse(S).extract(); - - for(auto const &i:*O) { - V.push_back(i.toString()); - } - } catch (...) { - - } - } -}; - -#endif // UCENTRALGW_UCENTRALTYPES_H +} diff --git a/src/storage/storage_deviceInfo.cpp b/src/storage/storage_deviceInfo.cpp index b196b56..6a13a65 100644 --- a/src/storage/storage_deviceInfo.cpp +++ b/src/storage/storage_deviceInfo.cpp @@ -208,19 +208,19 @@ namespace OpenWifi { auto Status = RSet[5].convert(); // find the real revision for this device... - Types::UpdateCountedMap(Report.DeviceTypes_, DeviceType); - Types::UpdateCountedMap(Report.Revisions_, Revision); - Types::UpdateCountedMap(Report.Status_, Status); - Types::UpdateCountedMap(Report.EndPoints_, EndPoint); - Types::UpdateCountedMap(Report.OUI_, SerialNumber.substr(0, 6)); + UpdateCountedMap(Report.DeviceTypes_, DeviceType); + UpdateCountedMap(Report.Revisions_, Revision); + UpdateCountedMap(Report.Status_, Status); + UpdateCountedMap(Report.EndPoints_, EndPoint); + UpdateCountedMap(Report.OUI_, SerialNumber.substr(0, 6)); FMSObjects::FirmwareAgeDetails Age; if (ComputeFirmwareAge(DeviceType, Revision, Age)) { if (Age.latest) { - Types::UpdateCountedMap(Report.UsingLatest_, Revision); + UpdateCountedMap(Report.UsingLatest_, Revision); } else if (Age.age == 0) { - Types::UpdateCountedMap(Report.UnknownFirmwares_, Revision); + UpdateCountedMap(Report.UnknownFirmwares_, Revision); } else { - Types::UpdateCountedMap(Report.totalSecondsOld_,"total_seconds", Age.age); + UpdateCountedMap(Report.totalSecondsOld_,"total_seconds", Age.age); } } More = RSet.moveNext();