mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralfms.git
synced 2026-01-27 10:23:12 +00:00
Framework update
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
// Arilia Wireless Inc.
|
||||
//
|
||||
|
||||
#ifndef OPENWIFI_MICROSERVICE_H
|
||||
#define OPENWIFI_MICROSERVICE_H
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
@@ -20,6 +19,7 @@
|
||||
#include <regex>
|
||||
#include <random>
|
||||
#include <iomanip>
|
||||
#include <queue>
|
||||
|
||||
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<Types::StringPair> & 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<typename T> 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<Poco::JSON::Array::Ptr>();
|
||||
for (auto const &i : *Object) {
|
||||
for (const auto &i : *Object) {
|
||||
auto InnerObject = i.template extract<Poco::JSON::Array::Ptr>();
|
||||
if(InnerObject->size()==2) {
|
||||
Types::StringPair P{InnerObject->get(0).toString(), InnerObject->get(1).toString()};
|
||||
R.push_back(P);
|
||||
auto S1 = InnerObject->getElement<std::string>(0);
|
||||
auto S2 = InnerObject->getElement<std::string>(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
|
||||
|
||||
@@ -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 <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
|
||||
#include "Poco/StringTokenizer.h"
|
||||
#include "Poco/JSON/Parser.h"
|
||||
#include "Poco/JSON/Stringifier.h"
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
namespace OpenWifi::Types {
|
||||
typedef std::pair<std::string,std::string> StringPair;
|
||||
typedef std::vector<StringPair> StringPairVec;
|
||||
typedef std::vector<StringPair> StringPairVec;
|
||||
typedef std::queue<StringPair> StringPairQueue;
|
||||
typedef std::vector<std::string> StringVec;
|
||||
typedef std::set<std::string> StringSet;
|
||||
typedef std::map<std::string,std::set<std::string>> StringMapStringSet;
|
||||
typedef std::function<void(std::string, std::string)> TopicNotifyFunction;
|
||||
typedef std::list<std::pair<TopicNotifyFunction,int>> TopicNotifyFunctionList;
|
||||
typedef std::map<std::string, TopicNotifyFunctionList> NotifyTable;
|
||||
typedef std::vector<std::string> StringVec;
|
||||
typedef std::set<std::string> StringSet;
|
||||
typedef std::map<std::string,std::set<std::string>> StringMapStringSet;
|
||||
typedef std::function<void(std::string, std::string)> TopicNotifyFunction;
|
||||
typedef std::list<std::pair<TopicNotifyFunction,int>> TopicNotifyFunctionList;
|
||||
typedef std::map<std::string, TopicNotifyFunctionList> NotifyTable;
|
||||
typedef std::map<std::string,uint64_t> CountedMap;
|
||||
typedef std::vector<uint64_t> TagList;
|
||||
typedef std::string UUID_t;
|
||||
typedef std::vector<UUID_t> 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<Poco::JSON::Array::Ptr>();
|
||||
|
||||
for(const auto &i:*O) {
|
||||
auto Inner = i.extract<Poco::JSON::Array::Ptr>();
|
||||
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<Poco::JSON::Array::Ptr>();
|
||||
|
||||
for(auto const &i:*O) {
|
||||
V.push_back(i.toString());
|
||||
}
|
||||
} catch (...) {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // UCENTRALGW_UCENTRALTYPES_H
|
||||
}
|
||||
|
||||
@@ -208,19 +208,19 @@ namespace OpenWifi {
|
||||
auto Status = RSet[5].convert<std::string>();
|
||||
|
||||
// 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();
|
||||
|
||||
Reference in New Issue
Block a user