diff --git a/CMakeLists.txt b/CMakeLists.txt index b2dde6f..a6397bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ include_directories(/usr/local/include /usr/local/opt/openssl/include src inclu add_executable( ucentralfms build + src/Dashboard.cpp src/Dashboard.h src/Daemon.cpp src/Daemon.h src/StorageService.cpp src/StorageService.h src/storage_tables.cpp src/storage_sqlite.cpp diff --git a/build b/build index ac4213d..2e66562 100644 --- a/build +++ b/build @@ -1 +1 @@ -43 \ No newline at end of file +49 \ No newline at end of file diff --git a/src/Daemon.h b/src/Daemon.h index bdc9ae8..feb5795 100644 --- a/src/Daemon.h +++ b/src/Daemon.h @@ -17,6 +17,7 @@ #include "MicroService.h" #include "uCentralTypes.h" +#include "RESTAPI_FMSObjects.h" namespace uCentral { @@ -38,8 +39,11 @@ namespace uCentral { void initialize(Poco::Util::Application &self); static Daemon *instance(); + inline FMSObjects::DeviceReport & GetDashboard() { return DB_; } + private: static Daemon *instance_; + FMSObjects::DeviceReport DB_; }; inline Daemon * Daemon() { return Daemon::instance(); } diff --git a/src/RESTAPI_FMSObjects.cpp b/src/RESTAPI_FMSObjects.cpp index 55b6e0d..cc3cddf 100644 --- a/src/RESTAPI_FMSObjects.cpp +++ b/src/RESTAPI_FMSObjects.cpp @@ -220,6 +220,16 @@ namespace uCentral::FMSObjects { field_to_json(Obj, "unknownFirmwares", UnknownFirmwares_); } + void DeviceReport::reset() { + OUI_.clear(); + Revisions_.clear(); + DeviceTypes_.clear(); + Status_.clear(); + EndPoints_.clear(); + UsingLatest_.clear(); + UnknownFirmwares_.clear(); + } + bool DeviceReport::from_json(const Poco::JSON::Object::Ptr &Obj) { try { diff --git a/src/RESTAPI_FMSObjects.h b/src/RESTAPI_FMSObjects.h index 9f987fb..956ae23 100644 --- a/src/RESTAPI_FMSObjects.h +++ b/src/RESTAPI_FMSObjects.h @@ -120,8 +120,9 @@ namespace uCentral::FMSObjects { Types::CountedMap EndPoints_; Types::CountedMap UsingLatest_; Types::CountedMap UnknownFirmwares_; - void to_json(Poco::JSON::Object &Obj) const; + void reset(); + bool from_json(const Poco::JSON::Object::Ptr &Obj); }; } diff --git a/src/RESTAPI_deviceReportHandler.cpp b/src/RESTAPI_deviceReportHandler.cpp index c7cc0f0..bb67764 100644 --- a/src/RESTAPI_deviceReportHandler.cpp +++ b/src/RESTAPI_deviceReportHandler.cpp @@ -6,6 +6,7 @@ #include "StorageService.h" #include "RESTAPI_FMSObjects.h" #include "Poco/JSON/Object.h" +#include "Daemon.h" namespace uCentral { void RESTAPI_deviceReportHandler::handleRequest(Poco::Net::HTTPServerRequest &Request, @@ -23,16 +24,10 @@ namespace uCentral { void RESTAPI_deviceReportHandler::DoGet(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) { try { - FMSObjects::DeviceReport R; - - if(Storage()->GenerateDeviceReport(R)) { - Poco::JSON::Object O; - R.to_json(O); - ReturnObject(Request, O, Response); - return; - } else { - NotFound(Request, Response); - } + Storage()->GenerateDeviceReport(Daemon()->GetDashboard()); + Poco::JSON::Object O; + Daemon()->GetDashboard().to_json(O); + ReturnObject(Request, O, Response); return; } catch ( const Poco::Exception &E) { Logger_.log(E);