diff --git a/tools/player-video/appl/widget/ListViewer.hpp b/tools/player-video/appl/widget/ListViewer.hpp index f4a052e..5aaf948 100644 --- a/tools/player-video/appl/widget/ListViewer.hpp +++ b/tools/player-video/appl/widget/ListViewer.hpp @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include #include diff --git a/tools/router/appl/GateWayInterface.cpp b/tools/router/appl/GateWayInterface.cpp index 5e3a609..2276078 100644 --- a/tools/router/appl/GateWayInterface.cpp +++ b/tools/router/appl/GateWayInterface.cpp @@ -51,8 +51,8 @@ bool appl::GateWayInterface::requestURI(const std::string& _uri) { } // TODO : Remove subParameters xxx?YYY // check if the USER is already connected: - ememory::SharedPtr tmp = m_routerInterface->get(tmpURI); - if (tmp != nullptr) { + bool tmp = m_routerInterface->userIsConnected(tmpURI); + if (tmp == true) { ZEUS_ERROR("User is already connected ==> this is a big error ..."); return false; } diff --git a/tools/router/appl/Router.cpp b/tools/router/appl/Router.cpp index 07cd867..dd9db37 100644 --- a/tools/router/appl/Router.cpp +++ b/tools/router/appl/Router.cpp @@ -8,6 +8,57 @@ #include #include +static std::string g_pathDBName = "USERDATA:router-database.json"; + +class UserAvaillable { + public: + std::string m_name; + std::string m_basePath; + bool m_accessMediaCenter; +}; +std::vector g_listUserAvaillable; +bool g_needToStore = false; + +static void store_db() { + if (g_needToStore == false) { + return; + } + APPL_ERROR("Store database [START]"); + ejson::Document database; + ejson::Array listUserArray; + database.add("users", listUserArray); + for (auto &it : g_listUserAvaillable) { + ejson::Object propObject; + listUserArray.add(propObject); + propObject.add("name", ejson::String(it.m_name)); + propObject.add("path", ejson::String(it.m_basePath)); + propObject.add("access-media-center", ejson::Boolean(it.m_accessMediaCenter)); + } + bool retGenerate = database.storeSafe(g_pathDBName); + APPL_ERROR("Store database [STOP] : " << g_pathDBName << " ret = " << retGenerate); + g_needToStore = false; +} + +static void load_db() { + ejson::Document database; + bool ret = database.load(g_pathDBName); + if (ret == false) { + APPL_WARNING(" ==> LOAD error"); + } + g_listUserAvaillable.clear(); + ejson::Array listUserArray = database["users"].toArray(); + for (const auto itArray: listUserArray) { + ejson::Object userElement = itArray.toObject(); + UserAvaillable userProperty; + userProperty.m_name = userElement["name"].toString().get(); + userProperty.m_basePath = userElement["path"].toString().get(); + userProperty.m_accessMediaCenter = userElement["access-media-center"].toBoolean().get(); + APPL_INFO("find USER: '" << userProperty.m_name << "'"); + g_listUserAvaillable.push_back(userProperty); + } + g_needToStore = false; +} + namespace appl { class TcpServerInput { @@ -89,6 +140,7 @@ appl::Router::Router() : propertyGateWayMax(this, "gw-max", 8000, "Maximum of Gateway at the same time", &appl::Router::onPropertyChangeGateWayMax) { m_interfaceClientServer = ememory::makeShared(this, false); m_interfaceGateWayServer = ememory::makeShared(this, true); + load_db(); } appl::Router::~Router() { @@ -105,6 +157,22 @@ void appl::Router::stop() { } +bool appl::Router::userIsConnected(const std::string& _userName) { + for (auto &it : m_GateWayList) { + if (it == nullptr) { + continue; + } + if (it->getName() != _userName) { + continue; + } + return true; + } + return false; +} + +#include +#include + ememory::SharedPtr appl::Router::get(const std::string& _userName) { // TODO : Start USer only when needed, not get it all time started... for (auto &it : m_GateWayList) { @@ -116,6 +184,25 @@ ememory::SharedPtr appl::Router::get(const std::string& } return it; } + // we not find the user ==> check if it is availlable ... + for (auto &it : g_listUserAvaillable) { + if (it.m_name == _userName) { + // start interface: + std::string cmd = "~/dev/perso/out/Linux_x86_64/debug/staging/clang/zeus-package-base/zeus-package-base.app/bin/zeus-gateway"; + cmd += " --user=" + it.m_name + " "; + cmd += " --srv=user"; + cmd += " --srv=picture"; + cmd += " --srv=video"; + cmd += " --base-path=" + it.m_basePath; + cmd += " --elog-file=\"/tmp/zeus.gateway." + it.m_name + ".log\""; + cmd += "&"; + APPL_ERROR("Start " << cmd); + system(cmd.c_str()); + std::this_thread::sleep_for(std::chrono::milliseconds(600)); + APPL_ERROR("Is connected ..."); + break; + } + } return nullptr; } @@ -136,7 +223,7 @@ std::vector appl::Router::getAllUserName() { void appl::Router::cleanIO() { - + store_db(); auto it = m_GateWayList.begin(); while (it != m_GateWayList.end()) { if (*it != nullptr) { diff --git a/tools/router/appl/Router.hpp b/tools/router/appl/Router.hpp index 7b1a338..a94f70c 100644 --- a/tools/router/appl/Router.hpp +++ b/tools/router/appl/Router.hpp @@ -34,6 +34,7 @@ namespace appl { void stop(); // Get a specific user gateway: ememory::SharedPtr get(const std::string& _userName); + bool userIsConnected(const std::string& _userName); std::vector getAllUserName(); void newClientGateWay(enet::Tcp _connection);