From bfdec3097416fc650ca06c6d563feea68462de35 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Tue, 10 Jan 2023 21:51:42 -0800 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-12068 Signed-off-by: stephb9959 --- build | 2 +- src/framework/UI_WebSocketClientServer.cpp | 2 +- src/framework/UI_WebSocketClientServer.h | 2 +- src/framework/orm.h | 26 ++++++++++++++++++++++ src/framework/utils.h | 18 +++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/build b/build index d8263ee..e440e5c 100644 --- a/build +++ b/build @@ -1 +1 @@ -2 \ No newline at end of file +3 \ No newline at end of file diff --git a/src/framework/UI_WebSocketClientServer.cpp b/src/framework/UI_WebSocketClientServer.cpp index 912687a..ee4a53d 100644 --- a/src/framework/UI_WebSocketClientServer.cpp +++ b/src/framework/UI_WebSocketClientServer.cpp @@ -271,7 +271,7 @@ namespace OpenWifi { std::string Answer; bool CloseConnection=false; if (Processor_ != nullptr) { - Processor_->Processor(Obj, Answer, CloseConnection); + Processor_->Processor(Obj, Answer, CloseConnection,Client->second->UserInfo_.userinfo); } if (!Answer.empty()) Client->second->WS_->sendFrame(Answer.c_str(), (int)Answer.size()); diff --git a/src/framework/UI_WebSocketClientServer.h b/src/framework/UI_WebSocketClientServer.h index 858e516..e008faf 100644 --- a/src/framework/UI_WebSocketClientServer.h +++ b/src/framework/UI_WebSocketClientServer.h @@ -21,7 +21,7 @@ namespace OpenWifi { class UI_WebSocketClientProcessor { public: - virtual void Processor(const Poco::JSON::Object::Ptr &O, std::string &Answer, bool &Done ) = 0; + virtual void Processor(const Poco::JSON::Object::Ptr &O, std::string &Answer, bool &Done , const SecurityObjects::UserInfo & UserInfo) = 0; private: }; diff --git a/src/framework/orm.h b/src/framework/orm.h index 4fc8a15..6b7604f 100644 --- a/src/framework/orm.h +++ b/src/framework/orm.h @@ -483,6 +483,32 @@ namespace ORM { return false; } + template bool GetRecordExt(RecordType & T , Args... args) { + try { + Poco::Data::Session Session = Pool_.get(); + Poco::Data::Statement Select(Session); + RecordTuple RT; + + auto WhereClause = WHERE_AND(args...); + + std::string St = "select " + SelectFields_ + " from " + TableName_ + WhereClause + " limit 1"; + + Select << ConvertParams(St) , + Poco::Data::Keywords::into(RT); + Select.execute(); + + if(Select.execute()==1) { + Convert(RT,T); + if(Cache_) + Cache_->UpdateCache(T); + return true; + } + } catch (const Poco::Exception &E) { + Logger_.log(E); + } + return false; + } + typedef std::vector StringVec; template < typename T, diff --git a/src/framework/utils.h b/src/framework/utils.h index a313f18..b587837 100644 --- a/src/framework/utils.h +++ b/src/framework/utils.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "Poco/Thread.h" #include "Poco/StringTokenizer.h" @@ -128,6 +129,23 @@ namespace OpenWifi::Utils { << std::hex << i; return stream.str(); } + + inline bool SpinLock_Read(std::shared_mutex &M, volatile bool &Flag, uint64_t wait_ms=100) { + while(!M.try_lock_shared() && Flag) { + Poco::Thread::yield(); + Poco::Thread::trySleep((long)wait_ms); + } + return Flag; + } + + inline bool SpinLock_Write(std::shared_mutex &M, volatile bool &Flag, uint64_t wait_ms=100) { + while(!M.try_lock() && Flag) { + Poco::Thread::yield(); + Poco::Thread::trySleep(wait_ms); + } + return Flag; + } + bool ExtractBase64CompressedData(const std::string &CompressedData, std::string &UnCompressedData, uint64_t compress_sz ); }