From 85be785bce866037591f9042e2bb0145d9fa28bb Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Fri, 4 Feb 2022 09:58:31 -0800 Subject: [PATCH] Framework update. --- build | 2 +- src/RESTObjects/RESTAPI_GWobjects.cpp | 1 - src/RESTObjects/RESTAPI_GWobjects.h | 1 - src/framework/MicroService.h | 41 ++++++++++++++------------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/build b/build index 56a6051..d8263ee 100644 --- a/build +++ b/build @@ -1 +1 @@ -1 \ No newline at end of file +2 \ No newline at end of file diff --git a/src/RESTObjects/RESTAPI_GWobjects.cpp b/src/RESTObjects/RESTAPI_GWobjects.cpp index be66a0a..2f7c58a 100644 --- a/src/RESTObjects/RESTAPI_GWobjects.cpp +++ b/src/RESTObjects/RESTAPI_GWobjects.cpp @@ -181,7 +181,6 @@ namespace OpenWifi::GWObjects { } void ConnectionState::to_json(Poco::JSON::Object &Obj) const { - field_to_json(Obj,"serialNumber", SerialNumber); field_to_json(Obj,"ipAddress", Address); field_to_json(Obj,"txBytes", TX); field_to_json(Obj,"rxBytes", RX); diff --git a/src/RESTObjects/RESTAPI_GWobjects.h b/src/RESTObjects/RESTAPI_GWobjects.h index dfc0ca2..6ec2b4f 100644 --- a/src/RESTObjects/RESTAPI_GWobjects.h +++ b/src/RESTObjects/RESTAPI_GWobjects.h @@ -22,7 +22,6 @@ namespace OpenWifi::GWObjects { struct ConnectionState { uint64_t MessageCount = 0 ; - std::string SerialNumber; std::string Address; uint64_t UUID = 0 ; uint64_t PendingUUID = 0 ; diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 51c3655..4e90044 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -830,20 +830,7 @@ namespace OpenWifi::Utils { } [[nodiscard]] inline uint64_t SerialNumberToInt(const std::string & S) { - uint64_t R=0; - - for(const auto &i:S) - if(i>='0' && i<='9') { - R <<= 4; - R += (i-'0'); - } else if(i>='a' && i<='f') { - R <<= 4; - R += (i-'a') + 10 ; - } else if(i>='A' && i<='F') { - R <<= 4; - R += (i-'A') + 10 ; - } - return R; + return std::stoull(S,nullptr,16); } [[nodiscard]] inline std::string IntToSerialNumber(uint64_t S) { @@ -1099,8 +1086,8 @@ namespace OpenWifi { template class FIFO { public: - explicit FIFO(uint32_t Size) : Size_(Size) { - Buffer_->reserve(Size_); + explicit FIFO(uint32_t Size) { + Buffer_->reserve(Size); } mutable Poco::BasicEvent Writable_; @@ -1114,9 +1101,10 @@ namespace OpenWifi { } t = (*Buffer_)[Read_++]; - if (Read_ == Size_) { + if (Read_ == Buffer_->capacity()) { Read_ = 0; } + Used_--; } bool flag = true; Writable_.notify(this, flag); @@ -1126,21 +1114,36 @@ namespace OpenWifi { inline bool Write(const T &t) { { std::lock_guard M(Mutex_); + + if(isFull()) { + Buffer_->reserve( Buffer_->size()+100 ); + } + (*Buffer_)[Write_++] = t; - if (Write_ == Size_) { + if (Write_ == Buffer_->capacity()) { Write_ = 0; } + Used_++; + MaxEverUsed_ = std::max(Used_,MaxEverUsed_); } bool flag = true; Readable_.notify(this, flag); return false; } + inline bool isFull() { + std::lock_guard M(Mutex_); + return Used_==Buffer_->capacity(); + } + + inline auto MaxEverUser() const { return MaxEverUsed_; } + private: std::mutex Mutex_; - uint32_t Size_; uint32_t Read_=0; uint32_t Write_=0; + uint32_t Used_=0; + uint32_t MaxEverUsed_=0; std::unique_ptr> Buffer_=std::make_unique>(); };