2929#include " framework/WebSocketLogger.h"
3030#include " framework/utils.h"
3131
32- namespace OpenWifi {
32+ #ifdef USE_MEDUSA_CLIENT
33+ #include < medusa/MedusaClient.h>
34+ #endif
3335
34- void MicroService::Exit ( int Reason) { std::exit (Reason); }
36+ namespace OpenWifi {
3537
36- static std::string MakeServiceListString (const Types::MicroServiceMetaMap &Services) {
38+ static std::string MakeServiceListString (const Types::MicroServiceMetaMap &Services) {
3739 std::string SvcList;
3840 for (const auto &Svc : Services) {
3941 if (SvcList.empty ())
@@ -204,25 +206,29 @@ namespace OpenWifi {
204206 Res.push_back (ServiceRec);
205207 }
206208 return Res;
209+
207210 }
208211
209212 void MicroService::LoadConfigurationFile () {
210- std::string Location = Poco::Environment::get (DAEMON_CONFIG_ENV_VAR , " ." );
211- ConfigFileName_ =
212- ConfigFileName_.empty () ? Location + " /" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
213- Poco::Path ConfigFile (ConfigFileName_);
214-
215- if (!ConfigFile.isFile ()) {
216- std::cerr << DAEMON_APP_NAME << " : Configuration " << ConfigFile.toString ()
217- << " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR +
218- " env variable the path of the " + DAEMON_PROPERTIES_FILENAME +
219- " file."
220- << std::endl;
221- std::exit (Poco::Util::Application::EXIT_CONFIG );
222- }
223-
224- // loadConfiguration(ConfigFile.toString());
225- PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration (ConfigFile.toString ());
213+ if (ConfigContent_.empty ()) {
214+ std::string Location = Poco::Environment::get (DAEMON_CONFIG_ENV_VAR , " ." );
215+ ConfigFileName_ =
216+ ConfigFileName_.empty () ? Location + " /" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
217+ Poco::Path ConfigFile (ConfigFileName_);
218+
219+ if (!ConfigFile.isFile ()) {
220+ std::cerr << DAEMON_APP_NAME << " : Configuration " << ConfigFile.toString ()
221+ << " does not seem to exist. Please set " + DAEMON_CONFIG_ENV_VAR +
222+ " env variable the path of the " + DAEMON_PROPERTIES_FILENAME +
223+ " file."
224+ << std::endl;
225+ std::exit (Poco::Util::Application::EXIT_CONFIG );
226+ }
227+ PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration (ConfigFile.toString ());
228+ } else {
229+ std::istringstream is (ConfigContent_);
230+ PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration (is);
231+ }
226232 configPtr ()->addWriteable (PropConfigurationFile_, PRIO_DEFAULT );
227233 }
228234
@@ -425,49 +431,59 @@ namespace OpenWifi {
425431
426432 void DaemonPostInitialization (Poco::Util::Application &self);
427433
428- void MicroService::initialize (Poco::Util::Application &self) {
429- // add the default services
430- LoadConfigurationFile ();
431- InitializeLoggingSystem ();
432-
433- SubSystems_.push_back (KafkaManager ());
434- SubSystems_.push_back (ALBHealthCheckServer ());
435- SubSystems_.push_back (RESTAPI_ExtServer ());
436- SubSystems_.push_back (RESTAPI_IntServer ());
434+ void MicroService::StartEverything (Poco::Util::Application &self) {
435+ LoadConfigurationFile ();
436+ InitializeLoggingSystem ();
437+
438+ static bool InitializedBaseService=false ;
439+ if (!InitializedBaseService) {
440+ InitializedBaseService = true ;
441+ SubSystems_.push_back (KafkaManager ());
442+ SubSystems_.push_back (ALBHealthCheckServer ());
443+ SubSystems_.push_back (RESTAPI_ExtServer ());
444+ SubSystems_.push_back (RESTAPI_IntServer ());
437445#ifndef TIP_SECURITY_SERVICE
438- SubSystems_.push_back (AuthClient ());
446+ SubSystems_.push_back (AuthClient ());
439447#endif
440- Poco::Net::initializeSSL ();
441- Poco::Net::HTTPStreamFactory::registerFactory ();
442- Poco::Net::HTTPSStreamFactory::registerFactory ();
443- Poco::Net::FTPStreamFactory::registerFactory ();
444- Poco::Net::FTPSStreamFactory::registerFactory ();
445-
446- Poco::File DataDir (ConfigPath (" openwifi.system.data" ));
447- DataDir_ = DataDir.path ();
448- if (!DataDir.exists ()) {
449- try {
450- DataDir.createDirectory ();
451- } catch (const Poco::Exception &E) {
452- Logger_.log (E);
453- }
454- }
455- WWWAssetsDir_ = ConfigPath (" openwifi.restapi.wwwassets" , " " );
456- if (WWWAssetsDir_.empty ())
457- WWWAssetsDir_ = DataDir_;
458448
459- LoadMyConfig ();
449+ Poco::Net::initializeSSL ();
450+ Poco::Net::HTTPStreamFactory::registerFactory ();
451+ Poco::Net::HTTPSStreamFactory::registerFactory ();
452+ Poco::Net::FTPStreamFactory::registerFactory ();
453+ Poco::Net::FTPSStreamFactory::registerFactory ();
454+ }
460455
461- AllowExternalMicroServices_ = ConfigGetBool (" allowexternalmicroservices" , true );
456+ Poco::File DataDir (ConfigPath (" openwifi.system.data" ));
457+ DataDir_ = DataDir.path ();
458+ if (!DataDir.exists ()) {
459+ try {
460+ DataDir.createDirectory ();
461+ } catch (const Poco::Exception &E) {
462+ Logger_.log (E);
463+ }
464+ }
465+ WWWAssetsDir_ = ConfigPath (" openwifi.restapi.wwwassets" , " " );
466+ if (WWWAssetsDir_.empty ())
467+ WWWAssetsDir_ = DataDir_;
462468
463- InitializeSubSystemServers ();
464- ServerApplication::initialize (self);
465- DaemonPostInitialization (self);
469+ LoadMyConfig ();
466470
467- Types::TopicNotifyFunction F = [this ](const std::string &Key, const std::string &Payload) {
468- this ->BusMessageReceived (Key, Payload);
469- };
470- KafkaManager ()->RegisterTopicWatcher (KafkaTopics::SERVICE_EVENTS , F);
471+ AllowExternalMicroServices_ = ConfigGetBool (" allowexternalmicroservices" , true );
472+
473+ InitializeSubSystemServers ();
474+ ServerApplication::initialize (self);
475+ DaemonPostInitialization (self);
476+
477+ Types::TopicNotifyFunction F = [this ](const std::string &Key, const std::string &Payload) {
478+ this ->BusMessageReceived (Key, Payload);
479+ };
480+ KafkaManager ()->RegisterTopicWatcher (KafkaTopics::SERVICE_EVENTS , F);
481+ }
482+
483+ void MicroService::initialize ([[maybe_unused]] Poco::Util::Application &self) {
484+ #ifndef USE_MEDUSA_CLIENT
485+ StartEverything (self);
486+ #endif
471487 }
472488
473489 void MicroService::uninitialize () {
@@ -753,6 +769,8 @@ namespace OpenWifi {
753769 MicroServiceErrorHandler ErrorHandler (*this );
754770 Poco::ErrorHandler::set (&ErrorHandler);
755771
772+ Args_ = args;
773+
756774 if (!HelpRequested_) {
757775 SavePID ();
758776
@@ -768,11 +786,18 @@ namespace OpenWifi {
768786 poco_information (logger, " Starting as a daemon." );
769787 }
770788
789+ #ifdef USE_MEDUSA_CLIENT
790+ MedusaClient::instance ()->SetSubSystems (SubSystems_);
791+ MedusaClient::instance ()->Start ();
792+ waitForTerminationRequest ();
793+ MedusaClient::instance ()->Stop ();
794+ #else
771795 poco_information (logger, fmt::format (" System ID set to {}" , ID_ ));
772796 StartSubSystemServers ();
773797 waitForTerminationRequest ();
774798 StopSubSystemServers ();
775799 logger.notice (fmt::format (" Stopped {}..." , DAEMON_APP_NAME ));
800+ #endif
776801 }
777802
778803 return Application::EXIT_OK ;
0 commit comments