diff --git a/test/client/appl/main-test-client.cpp b/test/client/appl/main-test-client.cpp index 6fc5601..16cf374 100644 --- a/test/client/appl/main-test-client.cpp +++ b/test/client/appl/main-test-client.cpp @@ -381,10 +381,10 @@ int main(int _argc, const char *_argv[]) { APPL_INFO(" ----------------------------------"); APPL_INFO(" -- Get service count"); APPL_INFO(" ----------------------------------"); - zeus::Future retNbService = client1.call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceCount"); + zeus::Future retNbService = client1.getServiceCount(); + zeus::Future> retServiceList = client1.getServiceList(); retNbService.wait(); APPL_INFO("Nb services = " << retNbService.get()); - zeus::Future> retServiceList = client1.call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceList"); retServiceList.wait(); APPL_INFO("List services:"); for (auto &it: retServiceList.get()) { @@ -398,7 +398,9 @@ int main(int _argc, const char *_argv[]) { } */ - if (false) { + if ( client1.waitForService("user") == true + && false) { + APPL_INFO(" ----------------------------------"); APPL_INFO(" -- Get service system-user"); APPL_INFO(" ----------------------------------"); @@ -446,7 +448,8 @@ int main(int _argc, const char *_argv[]) { APPL_INFO(" ----------------------------------"); APPL_INFO(" -- Get service picture"); APPL_INFO(" ----------------------------------"); - if (false) { + if ( client1.waitForService("picture") == true + && false) { zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture"); if (remoteServicePicture.exist() == true) { // Send a full path: @@ -455,7 +458,8 @@ int main(int _argc, const char *_argv[]) { APPL_ERROR("Can not get service Picture ..."); } } - if (false) { + if ( client1.waitForService("picture") == true + && false) { zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture"); if (remoteServicePicture.exist() == true) { zeus::Future> retCall = remoteServicePicture.albumGetList().wait(); @@ -505,7 +509,8 @@ int main(int _argc, const char *_argv[]) { APPL_INFO(" ----------------------------------"); APPL_INFO(" -- Get service video (send DATA) "); APPL_INFO(" ----------------------------------"); - if (true) { + if ( client1.waitForService("video") == true + && true) { zeus::service::ProxyVideo remoteServiceVideo = client1.getService("video"); // remove all media (for test) if (remoteServiceVideo.exist() == true) { diff --git a/tools/gateway/appl/main-gateway.cpp b/tools/gateway/appl/main-gateway.cpp index 523898a..29acfd6 100644 --- a/tools/gateway/appl/main-gateway.cpp +++ b/tools/gateway/appl/main-gateway.cpp @@ -35,20 +35,22 @@ typedef zeus::Object* (*SERVICE_IO_instanciate_t)(uint32_t, ememory::SharedPtr> listAvaillableServices; + if (services.size() != 0) { + // find all services: + etk::FSNode dataPath(etk::FSNodeGetApplicationPath() + "/../share"); + std::vector listSubPath = dataPath.folderGetSub(true, false, ".*"); + APPL_DEBUG(" Base data path: " << dataPath.getName()); + APPL_DEBUG(" SubPath: " << listSubPath); + for (auto &it: listSubPath) { + if (etk::FSNodeExist(it + "/zeus/") == true) { + etk::FSNode dataPath(it + "/zeus/"); + std::vector listServices = dataPath.folderGetSub(false, true, ".*\\.srv"); + for (auto &it2: listServices) { + std::string nameFileSrv = etk::FSNode(it2).getNameFile(); + std::vector spl = etk::split(std::string(nameFileSrv.begin(), nameFileSrv.end()-4), "-service-"); + if (spl.size() != 2) { + APPL_ERROR("reject service, wrong format ... '" << it2 << "' missing XXX-service-SERVICE-NAME.srv"); + continue; + } + APPL_INFO("find service : " << it2); + listAvaillableServices.push_back(std::make_pair(spl[1], std::string(nameFileSrv.begin(), nameFileSrv.end()-4))); + } + } else { + // not check the second path ==> no service availlable + } + } + } + #endif + APPL_INFO("=================================="); APPL_INFO("== ZEUS gateway start =="); APPL_INFO("=================================="); @@ -219,9 +250,28 @@ int main(int _argc, const char *_argv[]) { } else { bool routerAlive = true; std::vector> listElements; - for (auto &it: services) { - ememory::SharedPtr tmp = ememory::makeShared(it); - listElements.push_back(tmp); + if ( services.size() == 1 + && services[0] == "all") { + for (auto &it: listAvaillableServices) { + ememory::SharedPtr tmp = ememory::makeShared(it.first, it.second); + listElements.push_back(tmp); + } + } else { + for (auto &it: services) { + // find the real service name: + bool find = false; + for (auto &it2: listAvaillableServices) { + if (it2.first == it) { + ememory::SharedPtr tmp = ememory::makeShared(it2.first, it2.second); + listElements.push_back(tmp); + find = true; + break; + } + } + if (find == false) { + APPL_ERROR("Can not find the service: " << it); + } + } } for (auto &it: listElements) { it->init(_argc, _argv, basePath); diff --git a/tools/router/appl/Router.cpp b/tools/router/appl/Router.cpp index d4df2f1..e122126 100644 --- a/tools/router/appl/Router.cpp +++ b/tools/router/appl/Router.cpp @@ -239,9 +239,7 @@ ememory::SharedPtr appl::Router::get(const std::string& int ret = execlp( binary.c_str(), binary.c_str(), // must repeate the binary name to have the name as first argument ... userConf.c_str(), - "--srv=user", - "--srv=picture", - "--srv=video", + "--srv=all", delay.c_str(), basePath.c_str(), logFile.c_str(), diff --git a/zeus/Client.cpp b/zeus/Client.cpp index 6f92944..61b2cff 100644 --- a/zeus/Client.cpp +++ b/zeus/Client.cpp @@ -187,6 +187,33 @@ zeus::ObjectRemote zeus::Client::getService(const std::string& _name) { return zeus::ObjectRemote(ret.get()); } + +zeus::Future zeus::Client::getServiceCount() { + return call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceCount"); +} + +zeus::Future> zeus::Client::getServiceList() { + return call(ZEUS_NO_ID_OBJECT, ZEUS_ID_GATEWAY, "getServiceList"); +} + +// TODO : This is an active waiting ==> this is bad ... ==> use future, it will be better +bool zeus::Client::waitForService(const std::string& _serviceName) { + int32_t delayMax = 10; + while (delayMax > 0) { + auto listValues = getServiceList(); + listValues.wait(); + for (auto &it: listValues.get()) { + if (it == _serviceName) { + return true; + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + delayMax--; + } + return false; +} + + void zeus::Client::onPropertyChangeIp() { disconnect(); } diff --git a/zeus/Client.hpp b/zeus/Client.hpp index 20bf0b1..e05576f 100644 --- a/zeus/Client.hpp +++ b/zeus/Client.hpp @@ -156,6 +156,11 @@ namespace zeus { * @brief Display all connected object remote and local ... */ void cleanDeadObject(); + public: + zeus::Future getServiceCount(); + zeus::Future> getServiceList(); + // TODO : This is an active waiting ==> this is bad ... ==> use future, it will be better + bool waitForService(const std::string& _serviceName); }; } diff --git a/zeus/WebServer.cpp b/zeus/WebServer.cpp index 083024f..4d8c331 100644 --- a/zeus/WebServer.cpp +++ b/zeus/WebServer.cpp @@ -276,12 +276,18 @@ int32_t zeus::WebServer::writeBinary(ememory::SharedPtr _obj) { bool zeus::WebServer::onReceiveUri(const std::string& _uri, const std::vector& _protocols) { ZEUS_INFO("Receive Header uri: " << _uri); + bool findProtocol = false; for (auto &it : _protocols) { if (it == "zeus/1.0") { m_connection.setProtocol(it); + findProtocol = true; break; } } + if (findProtocol == false) { + ZEUS_ERROR("Disable connection request URI='" << _uri << "' with wrong protocol:" << _protocols); + return false; + } // TODO : Add better return on specific user ... if (m_observerRequestUri != nullptr) { return m_observerRequestUri(_uri);