diff --git a/build b/build index 19c7bdb..8e2afd3 100644 --- a/build +++ b/build @@ -1 +1 @@ -16 \ No newline at end of file +17 \ No newline at end of file diff --git a/src/framework/EventBusManager.cpp b/src/framework/EventBusManager.cpp index ef182bf..28d8037 100644 --- a/src/framework/EventBusManager.cpp +++ b/src/framework/EventBusManager.cpp @@ -14,18 +14,18 @@ namespace OpenWifi { void EventBusManager::run() { Running_ = true; Utils::SetThreadName("fmwk:EventMgr"); - auto Msg = MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN); + auto Msg = std::make_shared(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN)); KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, false); while (Running_) { Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer()); if (!Running_) break; - Msg = MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE); + Msg = std::make_shared(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE)); KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, false); } - Msg = MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE); + Msg = std::make_shared(MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_LEAVE)); KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg, false); }; diff --git a/src/framework/KafkaManager.cpp b/src/framework/KafkaManager.cpp index af37a8d..b8193b8 100644 --- a/src/framework/KafkaManager.cpp +++ b/src/framework/KafkaManager.cpp @@ -180,7 +180,7 @@ namespace OpenWifi { Consumer.async_commit(Msg); continue; } - KafkaManager()->Dispatch(Msg.get_topic(), Msg.get_key(), Msg.get_payload()); + KafkaManager()->Dispatch(Msg.get_topic().c_str(), Msg.get_key(), std::make_shared(Msg.get_payload())); if (!AutoCommit) Consumer.async_commit(Msg); } @@ -212,8 +212,8 @@ namespace OpenWifi { } } - void KafkaProducer::Produce(const std::string &Topic, const std::string &Key, - const std::string &Payload) { + void KafkaProducer::Produce(const char *Topic, const std::string &Key, + const std::shared_ptr Payload) { std::lock_guard G(Mutex_); Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload)); } @@ -275,8 +275,8 @@ namespace OpenWifi { } } - void KafkaDispatcher::Dispatch(const std::string &Topic, const std::string &Key, - const std::string &Payload) { + void KafkaDispatcher::Dispatch(const char *Topic, const std::string &Key, + const std::shared_ptr Payload) { std::lock_guard G(Mutex_); auto It = Notifiers_.find(Topic); if (It != Notifiers_.end()) { @@ -332,20 +332,21 @@ namespace OpenWifi { } } - void KafkaManager::PostMessage(const std::string &topic, const std::string &key, - const std::string &PayLoad, bool WrapMessage) { + void KafkaManager::PostMessage(const char *topic, const std::string &key, + const std::shared_ptr PayLoad, bool WrapMessage) { if (KafkaEnabled_) { ProducerThr_.Produce(topic, key, WrapMessage ? WrapSystemId(PayLoad) : PayLoad); } } - void KafkaManager::Dispatch(const std::string &Topic, const std::string &Key, - const std::string &Payload) { + void KafkaManager::Dispatch(const char *Topic, const std::string &Key, + const std::shared_ptr Payload) { Dispatcher_.Dispatch(Topic, Key, Payload); } - [[nodiscard]] std::string KafkaManager::WrapSystemId(const std::string &PayLoad) { - return SystemInfoWrapper_ + PayLoad + "}"; + [[nodiscard]] const std::shared_ptr KafkaManager::WrapSystemId(const std::shared_ptr PayLoad) { + *PayLoad = SystemInfoWrapper_ + *PayLoad + "}"; + return PayLoad; } uint64_t KafkaManager::RegisterTopicWatcher(const std::string &Topic, diff --git a/src/framework/KafkaManager.h b/src/framework/KafkaManager.h index b9630df..b78c072 100644 --- a/src/framework/KafkaManager.h +++ b/src/framework/KafkaManager.h @@ -18,17 +18,17 @@ namespace OpenWifi { class KafkaMessage : public Poco::Notification { public: - KafkaMessage(const std::string &Topic, const std::string &Key, const std::string &Payload) - : Topic_(Topic), Key_(Key), Payload_(Payload) {} + KafkaMessage(const char * Topic, const std::string &Key, const std::shared_ptr Payload) + : Topic_(Topic), Key_(Key), Payload_(std::move(Payload)) {} - inline const std::string &Topic() { return Topic_; } + inline const char * Topic() { return Topic_; } inline const std::string &Key() { return Key_; } - inline const std::string &Payload() { return Payload_; } + inline const std::string &Payload() { return *Payload_; } private: - std::string Topic_; + const char *Topic_; std::string Key_; - std::string Payload_; + std::shared_ptr Payload_; }; class KafkaProducer : public Poco::Runnable { @@ -36,7 +36,7 @@ namespace OpenWifi { void run() override; void Start(); void Stop(); - void Produce(const std::string &Topic, const std::string &Key, const std::string &Payload); + void Produce(const char *Topic, const std::string &Key, const std::shared_ptr Payload); private: std::recursive_mutex Mutex_; @@ -63,7 +63,7 @@ namespace OpenWifi { void Stop(); auto RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); void UnregisterTopicWatcher(const std::string &Topic, int Id); - void Dispatch(const std::string &Topic, const std::string &Key, const std::string &Payload); + void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr Payload); void run() override; void Topics(std::vector &T); @@ -91,10 +91,10 @@ namespace OpenWifi { int Start() override; void Stop() override; - void PostMessage(const std::string &topic, const std::string &key, - const std::string &PayLoad, bool WrapMessage = true); - void Dispatch(const std::string &Topic, const std::string &Key, const std::string &Payload); - [[nodiscard]] std::string WrapSystemId(const std::string &PayLoad); + void PostMessage(const char *topic, const std::string &key, + const std::shared_ptr PayLoad, bool WrapMessage = true); + void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr Payload); + [[nodiscard]] const std::shared_ptr WrapSystemId(const std::shared_ptr PayLoad); [[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; } uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F); void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id); diff --git a/src/framework/KafkaTopics.h b/src/framework/KafkaTopics.h index 4c93b59..e5f9cea 100644 --- a/src/framework/KafkaTopics.h +++ b/src/framework/KafkaTopics.h @@ -10,32 +10,32 @@ #include namespace OpenWifi::KafkaTopics { - static const std::string HEALTHCHECK{"healthcheck"}; - static const std::string STATE{"state"}; - static const std::string CONNECTION{"connection"}; - static const std::string WIFISCAN{"wifiscan"}; - static const std::string ALERTS{"alerts"}; - static const std::string COMMAND{"command"}; - static const std::string SERVICE_EVENTS{"service_events"}; - static const std::string DEVICE_EVENT_QUEUE{"device_event_queue"}; - static const std::string DEVICE_TELEMETRY{"device_telemetry"}; - static const std::string PROVISIONING_CHANGE{"provisioning_change"}; + inline const char * HEALTHCHECK = "healthcheck"; + inline const char * STATE = "state"; + inline const char * CONNECTION = "connection"; + inline const char * WIFISCAN = "wifiscan"; + inline const char * ALERTS = "alerts"; + inline const char * COMMAND = "command"; + inline const char * SERVICE_EVENTS = "service_events"; + inline const char * DEVICE_EVENT_QUEUE = "device_event_queue"; + inline const char * DEVICE_TELEMETRY = "device_telemetry"; + inline const char * PROVISIONING_CHANGE = "provisioning_change"; namespace ServiceEvents { - static const std::string EVENT_JOIN{"join"}; - static const std::string EVENT_LEAVE{"leave"}; - static const std::string EVENT_KEEP_ALIVE{"keep-alive"}; - static const std::string EVENT_REMOVE_TOKEN{"remove-token"}; + inline const char * EVENT_JOIN = "join"; + inline const char * EVENT_LEAVE = "leave"; + inline const char * EVENT_KEEP_ALIVE = "keep-alive"; + inline const char * EVENT_REMOVE_TOKEN = "remove-token"; namespace Fields { - static const std::string EVENT{"event"}; - static const std::string ID{"id"}; - static const std::string TYPE{"type"}; - static const std::string PUBLIC{"publicEndPoint"}; - static const std::string PRIVATE{"privateEndPoint"}; - static const std::string KEY{"key"}; - static const std::string VRSN{"version"}; - static const std::string TOKEN{"token"}; + inline const char * EVENT = "event"; + inline const char * ID = "id"; + inline const char * TYPE = "type"; + inline const char * PUBLIC = "publicEndPoint"; + inline const char * PRIVATE = "privateEndPoint"; + inline const char * KEY = "key"; + inline const char * VRSN = "version"; + inline const char * TOKEN = "token"; } // namespace Fields } // namespace ServiceEvents } // namespace OpenWifi::KafkaTopics diff --git a/src/framework/MicroServiceFuncs.cpp b/src/framework/MicroServiceFuncs.cpp index 22eccbd..367d464 100644 --- a/src/framework/MicroServiceFuncs.cpp +++ b/src/framework/MicroServiceFuncs.cpp @@ -47,11 +47,11 @@ namespace OpenWifi { void MicroServiceReload(const std::string &Type) { MicroService::instance().Reload(Type); } - const Types::StringVec MicroServiceGetLogLevelNames() { + Types::StringVec MicroServiceGetLogLevelNames() { return MicroService::instance().GetLogLevelNames(); } - const Types::StringVec MicroServiceGetSubSystems() { + Types::StringVec MicroServiceGetSubSystems() { return MicroService::instance().GetSubSystems(); } @@ -79,7 +79,7 @@ namespace OpenWifi { std::string MicroServiceGetUIURI() { return MicroService::instance().GetUIURI(); } - const SubSystemVec MicroServiceGetFullSubSystems() { + SubSystemVec MicroServiceGetFullSubSystems() { return MicroService::instance().GetFullSubSystems(); } @@ -87,7 +87,7 @@ namespace OpenWifi { std::uint64_t MicroServiceDaemonBusTimer() { return MicroService::instance().DaemonBusTimer(); } - std::string MicroServiceMakeSystemEventMessage(const std::string &Type) { + std::string MicroServiceMakeSystemEventMessage(const char *Type) { return MicroService::instance().MakeSystemEventMessage(Type); } diff --git a/src/framework/MicroServiceFuncs.h b/src/framework/MicroServiceFuncs.h index ec06c7a..b266156 100644 --- a/src/framework/MicroServiceFuncs.h +++ b/src/framework/MicroServiceFuncs.h @@ -31,8 +31,8 @@ namespace OpenWifi { void MicroServiceLoadConfigurationFile(); void MicroServiceReload(); void MicroServiceReload(const std::string &Type); - const Types::StringVec MicroServiceGetLogLevelNames(); - const Types::StringVec MicroServiceGetSubSystems(); + Types::StringVec MicroServiceGetLogLevelNames(); + Types::StringVec MicroServiceGetSubSystems(); Types::StringPairVec MicroServiceGetLogLevels(); bool MicroServiceSetSubsystemLogLevel(const std::string &SubSystem, const std::string &Level); void MicroServiceGetExtraConfiguration(Poco::JSON::Object &Answer); @@ -40,10 +40,10 @@ namespace OpenWifi { std::uint64_t MicroServiceUptimeTotalSeconds(); std::uint64_t MicroServiceStartTimeEpochTime(); std::string MicroServiceGetUIURI(); - const SubSystemVec MicroServiceGetFullSubSystems(); + SubSystemVec MicroServiceGetFullSubSystems(); std::string MicroServiceCreateUUID(); std::uint64_t MicroServiceDaemonBusTimer(); - std::string MicroServiceMakeSystemEventMessage(const std::string &Type); + std::string MicroServiceMakeSystemEventMessage(const char *Type); Poco::ThreadPool &MicroServiceTimerPool(); std::string MicroServiceConfigPath(const std::string &Key, const std::string &DefaultValue); std::string MicroServiceWWWAssetsDir(); diff --git a/src/framework/ow_constants.h b/src/framework/ow_constants.h index 863bc8c..2b01edd 100644 --- a/src/framework/ow_constants.h +++ b/src/framework/ow_constants.h @@ -566,6 +566,7 @@ namespace OpenWifi::uCentralProtocol { static const char *HEALTHCHECK = "healthcheck"; static const char *LOG = "log"; static const char *CRASHLOG = "crashlog"; + static const char *REBOOTLOG = "rebootLog"; static const char *PING = "ping"; static const char *CFGPENDING = "cfgpending"; static const char *RECOVERY = "recovery"; @@ -624,6 +625,8 @@ namespace OpenWifi::uCentralProtocol { static const char *DEVICEUPDATE = "deviceupdate"; static const char *FWSIGNATURE = "FWsignature"; static const char *SIGNATURE = "signature"; + static const char *INFO = "info"; + static const char *DATE = "date"; static const char *SERIALNUMBER = "serialNumber"; static const char *COMPATIBLE = "compatible"; @@ -654,6 +657,7 @@ namespace OpenWifi::uCentralProtocol::Events { static const char *HEALTHCHECK = "healthcheck"; static const char *LOG = "log"; static const char *CRASHLOG = "crashlog"; + static const char *REBOOTLOG = "rebootLog"; static const char *PING = "ping"; static const char *CFGPENDING = "cfgpending"; static const char *RECOVERY = "recovery"; @@ -677,7 +681,8 @@ namespace OpenWifi::uCentralProtocol::Events { ET_VENUEBROADCAST, ET_EVENT, ET_WIFISCAN, - ET_ALARM + ET_ALARM, + ET_REBOOTLOG }; inline EVENT_MSG EventFromString(const std::string &Method) { @@ -708,8 +713,10 @@ namespace OpenWifi::uCentralProtocol::Events { else if (strcmp(WIFISCAN, Method.c_str()) == 0) return ET_WIFISCAN; else if (strcmp(ALARM, Method.c_str()) == 0) - return ET_WIFISCAN; - return ET_ALARM; + return ET_ALARM; + else if (strcmp(REBOOTLOG, Method.c_str()) == 0) + return ET_REBOOTLOG; + return ET_UNKNOWN; }; } // namespace OpenWifi::uCentralProtocol::Events diff --git a/src/framework/utils.h b/src/framework/utils.h index 698912f..f1cdef3 100644 --- a/src/framework/utils.h +++ b/src/framework/utils.h @@ -146,4 +146,38 @@ namespace OpenWifi::Utils { bool ExtractBase64CompressedData(const std::string &CompressedData, std::string &UnCompressedData, uint64_t compress_sz); + + inline bool match(const char* first, const char* second) + { + // If we reach at the end of both strings, we are done + if (*first == '\0' && *second == '\0') + return true; + + // Make sure to eliminate consecutive '*' + if (*first == '*') { + while (*(first + 1) == '*') + first++; + } + + // Make sure that the characters after '*' are present + // in second string. This function assumes that the + // first string will not contain two consecutive '*' + if (*first == '*' && *(first + 1) != '\0' + && *second == '\0') + return false; + + // If the first string contains '?', or current + // characters of both strings match + if (*first == '?' || *first == *second) + return match(first + 1, second + 1); + + // If there is *, then there are two possibilities + // a) We consider current character of second string + // b) We ignore current character of second string. + if (*first == '*') + return match(first + 1, second) + || match(first, second + 1); + return false; + } + } // namespace OpenWifi::Utils