From 7cef0f6b08ce265d93ed8211dc558b22c29c651f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 23 Nov 2016 21:38:34 +0100 Subject: [PATCH] [DEV] luncher work well bun run only one service (Missing set of the user data in a specific path) --- tools/launcher/appl/main.cpp | 89 +++++++++++-------- tools/service-picture/appl/main.cpp | 55 +----------- .../lutin_zeus-service-picture.py | 3 +- tools/service-user/appl/main.cpp | 57 ++---------- tools/service-user/lutin_zeus-service-user.py | 2 +- tools/service-video/appl/main.cpp | 55 +----------- .../service-video/lutin_zeus-service-video.py | 3 +- 7 files changed, 66 insertions(+), 198 deletions(-) diff --git a/tools/launcher/appl/main.cpp b/tools/launcher/appl/main.cpp index 6f72a05..3d49331 100644 --- a/tools/launcher/appl/main.cpp +++ b/tools/launcher/appl/main.cpp @@ -13,20 +13,19 @@ #include #include #include - +#include #include -typedef bool (*SERVICE_IO_init_t)(std::string _basePath); +typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], std::string _basePath); typedef bool (*SERVICE_IO_uninit_t)(); typedef bool (*SERVICE_IO_execute_t)(std::string _ip, uint16_t _port); int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); - // TODO : permit module to init libraries ... zeus::init(_argc, _argv); std::string ip; uint16_t port = 0; std::string basePath; - std::vector services; + std::string service; for (int32_t iii=0; iii<_argc ; ++iii) { std::string data = _argv[iii]; if (etk::start_with(data, "--ip=") == true) { @@ -36,7 +35,11 @@ int main(int _argc, const char *_argv[]) { } else if (etk::start_with(data, "--base-path=") == true) { basePath = std::string(&data[12]); } else if (etk::start_with(data, "--srv=") == true) { - services.push_back(std::string(&data[6])); + if (service != "") { + APPL_ERROR("Drop sercice : '" << data << "' ==> support run only one service"); + return -1; + } + service = std::string(&data[6]); } else if ( data == "-h" || data == "--help") { APPL_PRINT(etk::getApplicationName() << " - help : "); @@ -49,44 +52,52 @@ int main(int _argc, const char *_argv[]) { } } if (basePath.size() == 0) { - basePath = "USERDATA:"; + basePath = "USERDATA:" + service + "/"; APPL_PRINT("Use base path: " << basePath); } - for (auto &it : services) { - void *handle; - handle = dlopen(it.c_str(), RTLD_LAZY); - if (!handle) { - APPL_ERROR("Can not load Lbrary:" << dlerror()); - return -1; + void *handle = nullptr; + std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + service + ".so"; + APPL_PRINT("Try to open service with name: '" << service << "' at position: '" << srv << "'"); + handle = dlopen(srv.c_str(), RTLD_LAZY); + if (!handle) { + APPL_ERROR("Can not load Lbrary:" << dlerror()); + return -1; + } + char *error = nullptr; + SERVICE_IO_init_t SERVICE_IO_init = nullptr; + SERVICE_IO_uninit_t SERVICE_IO_uninit = nullptr; + SERVICE_IO_execute_t SERVICE_IO_execute = nullptr; + SERVICE_IO_init = (SERVICE_IO_init_t)dlsym(handle, "SERVICE_IO_init"); + error = dlerror(); + if (error != nullptr) { + APPL_WARNING("Can not function SERVICE_IO_init :" << error); + } + SERVICE_IO_uninit = (SERVICE_IO_uninit_t)dlsym(handle, "SERVICE_IO_uninit"); + error = dlerror(); + if (error != nullptr) { + APPL_WARNING("Can not function SERVICE_IO_uninit :" << error); + } + SERVICE_IO_execute = (SERVICE_IO_execute_t)dlsym(handle, "SERVICE_IO_execute"); + error = dlerror(); + if (error != nullptr) { + APPL_WARNING("Can not function SERVICE_IO_execute:" << error); + } + if (SERVICE_IO_init != nullptr) { + (*SERVICE_IO_init)(_argc, _argv, basePath); + } + while (true) { + if (SERVICE_IO_execute == nullptr) { + // nothing to do ... + break; } - char *error = nullptr; - SERVICE_IO_init_t SERVICE_IO_init; - SERVICE_IO_uninit_t SERVICE_IO_uninit; - SERVICE_IO_execute_t SERVICE_IO_execute; - SERVICE_IO_init = (SERVICE_IO_init_t)dlsym(handle, "SERVICE_IO_init"); - error = dlerror(); - if (error != nullptr) { - APPL_ERROR("Can not function SERVICE_IO_init :" << error); - return -1; + if ((*SERVICE_IO_execute)(ip, port) == true) { + break; } - SERVICE_IO_uninit = (SERVICE_IO_uninit_t)dlsym(handle, "SERVICE_IO_uninit"); - error = dlerror(); - if (error != nullptr) { - APPL_ERROR("Can not function SERVICE_IO_uninit :" << error); - return -1; - } - SERVICE_IO_execute = (SERVICE_IO_execute_t)dlsym(handle, "SERVICE_IO_execute"); - error = dlerror(); - if (error != nullptr) { - APPL_ERROR("Can not function SERVICE_IO_execute:" << error); - return -1; - } - (*SERVICE_IO_init)(basePath); - // TODO: Remove the While true, ==> sevice must be spown by a user call, if a service die, the wall system will die ... - while (true) { - (*SERVICE_IO_execute)(ip, port); - } - APPL_INFO("Stop service ==> flush internal datas ..."); + APPL_INFO("wait 5 second ..."); + std::this_thread::sleep_for(std::chrono::seconds(5)); + } + APPL_INFO("Stop service ==> flush internal datas ..."); + if (SERVICE_IO_uninit != nullptr) { (*SERVICE_IO_uninit)(); } return 0; diff --git a/tools/service-picture/appl/main.cpp b/tools/service-picture/appl/main.cpp index 7eb8a0d..97a4e78 100644 --- a/tools/service-picture/appl/main.cpp +++ b/tools/service-picture/appl/main.cpp @@ -253,7 +253,7 @@ namespace appl { }; } -bool SERVICE_IO_init(std::string _basePath) { +ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string _basePath) { g_basePath = _basePath; std::unique_lock lock(g_mutex); APPL_WARNING("Load USER: " << g_basePath); @@ -300,7 +300,7 @@ bool SERVICE_IO_init(std::string _basePath) { return true; } -bool SERVICE_IO_uninit() { +ETK_EXPORT_API bool SERVICE_IO_uninit() { std::unique_lock lock(g_mutex); APPL_DEBUG("Store User Info:"); bool ret = g_database.storeSafe(g_basePath + g_baseDBName); @@ -312,7 +312,7 @@ bool SERVICE_IO_uninit() { return true; } -bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { +ETK_EXPORT_API bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("==========================================================="); APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]"); APPL_INFO("==========================================================="); @@ -346,16 +346,12 @@ bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]"); APPL_INFO("==========================================================="); if (serviceInterface.connect() == false) { - APPL_INFO("wait 5 second ..."); - std::this_thread::sleep_for(std::chrono::seconds(5)); return false; } if (serviceInterface.GateWayAlive() == false) { APPL_INFO("==========================================================="); APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] Can not connect to the GateWay"); APPL_INFO("==========================================================="); - APPL_INFO("wait 5 second ..."); - std::this_thread::sleep_for(std::chrono::seconds(5)); return false; } int32_t iii=0; @@ -375,48 +371,3 @@ bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("==========================================================="); return true; } - -#ifndef APPL_BUILD_SHARED_LIBRARY - -int main(int _argc, const char *_argv[]) { - etk::init(_argc, _argv); - zeus::init(_argc, _argv); - std::string ip; - uint16_t port = 0; - std::string basePath; - for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; - if (etk::start_with(data, "--ip=") == true) { - ip = std::string(&data[5]); - } else if (etk::start_with(data, "--port=") == true) { - port = etk::string_to_uint16_t(std::string(&data[7])); - } else if (etk::start_with(data, "--base-path=") == true) { - basePath = std::string(&data[12]); - } else if ( data == "-h" - || data == "--help") { - APPL_PRINT(etk::getApplicationName() << " - help : "); - APPL_PRINT(" " << _argv[0] << " [options]"); - APPL_PRINT(" --base-path=XXX base path to search data (default: 'USERDATA:')"); - APPL_PRINT(" --ip=XXX Server connection IP (default: 1.7.0.0.1)"); - APPL_PRINT(" --port=XXX Server connection PORT (default: 1983)"); - return -1; - } - } - if (basePath.size() == 0) { - basePath = "USERDATA:"; - APPL_PRINT("Use base path: " << basePath); - } - SERVICE_IO_init(basePath); - // TODO: Remove the While true, ==> sevice must be spown by a user call, if a service die, the wall system will die ... - while (true) { - SERVICE_IO_execute(ip, port); - } - APPL_INFO("Stop service ==> flush internal datas ..."); - SERVICE_IO_uninit(); - APPL_INFO("==========================================================="); - APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [END-APPLICATION]"); - APPL_INFO("==========================================================="); - return 0; -} - -#endif diff --git a/tools/service-picture/lutin_zeus-service-picture.py b/tools/service-picture/lutin_zeus-service-picture.py index b9956e7..7930d8d 100644 --- a/tools/service-picture/lutin_zeus-service-picture.py +++ b/tools/service-picture/lutin_zeus-service-picture.py @@ -4,7 +4,8 @@ import lutin.tools as tools def get_type(): - return "BINARY" + return "LIBRARY_DYNAMIC" + #return "BINARY" def get_sub_type(): return "TOOLS" diff --git a/tools/service-user/appl/main.cpp b/tools/service-user/appl/main.cpp index 9cc6595..2d3f04c 100644 --- a/tools/service-user/appl/main.cpp +++ b/tools/service-user/appl/main.cpp @@ -112,7 +112,9 @@ namespace appl { }; } -bool SERVICE_IO_init(std::string _basePath) { +ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string _basePath) { + // Already init : etk::init(_argc, _argv); + zeus::init(_argc, _argv); g_basePath = _basePath; std::unique_lock lock(g_mutex); APPL_WARNING("Load USER: " << g_basePath); @@ -123,7 +125,7 @@ bool SERVICE_IO_init(std::string _basePath) { return true; } -bool SERVICE_IO_uninit() { +ETK_EXPORT_API bool SERVICE_IO_uninit() { std::unique_lock lock(g_mutex); APPL_DEBUG("Store User Info:"); bool ret = g_database.storeSafe(g_basePath + g_baseDBName); @@ -135,7 +137,7 @@ bool SERVICE_IO_uninit() { return true; } -bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { +ETK_EXPORT_API bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("==========================================================="); APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]"); APPL_INFO("==========================================================="); @@ -179,16 +181,12 @@ bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]"); APPL_INFO("==========================================================="); if (serviceInterface.connect() == false) { - APPL_INFO("wait 5 second ..."); - std::this_thread::sleep_for(std::chrono::seconds(5)); return false; } if (serviceInterface.GateWayAlive() == false) { APPL_INFO("==========================================================="); APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] Can not connect to the GateWay"); APPL_INFO("==========================================================="); - APPL_INFO("wait 5 second ..."); - std::this_thread::sleep_for(std::chrono::seconds(5)); return false; } int32_t iii=0; @@ -205,48 +203,3 @@ bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("==========================================================="); return true; } - -#ifndef APPL_BUILD_SHARED_LIBRARY - -int main(int _argc, const char *_argv[]) { - etk::init(_argc, _argv); - zeus::init(_argc, _argv); - std::string ip; - uint16_t port = 0; - std::string basePath; - for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; - if (etk::start_with(data, "--ip=") == true) { - ip = std::string(&data[5]); - } else if (etk::start_with(data, "--port=") == true) { - port = etk::string_to_uint16_t(std::string(&data[7])); - } else if (etk::start_with(data, "--base-path=") == true) { - basePath = std::string(&data[12]); - } else if ( data == "-h" - || data == "--help") { - APPL_PRINT(etk::getApplicationName() << " - help : "); - APPL_PRINT(" " << _argv[0] << " [options]"); - APPL_PRINT(" --base-path=XXX base path to search data (default: 'USERDATA:')"); - APPL_PRINT(" --ip=XXX Server connection IP (default: 1.7.0.0.1)"); - APPL_PRINT(" --port=XXX Server connection PORT (default: 1983)"); - return -1; - } - } - if (basePath.size() == 0) { - basePath = "USERDATA:"; - APPL_PRINT("Use base path: " << basePath); - } - SERVICE_IO_init(basePath); - // TODO: Remove the While true, ==> sevice must be spown by a user call, if a service die, the wall system will die ... - while (true) { - SERVICE_IO_execute(ip, port); - } - APPL_INFO("Stop service ==> flush internal datas ..."); - SERVICE_IO_uninit(); - APPL_INFO("==========================================================="); - APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [END-APPLICATION]"); - APPL_INFO("==========================================================="); - return 0; -} - -#endif diff --git a/tools/service-user/lutin_zeus-service-user.py b/tools/service-user/lutin_zeus-service-user.py index ddde477..3507204 100644 --- a/tools/service-user/lutin_zeus-service-user.py +++ b/tools/service-user/lutin_zeus-service-user.py @@ -11,7 +11,7 @@ def get_sub_type(): return "TOOLS" def get_desc(): - return "ZEUS test service" + return "ZEUS service user" def get_licence(): return "APACHE-2" diff --git a/tools/service-video/appl/main.cpp b/tools/service-video/appl/main.cpp index b56b150..37766ea 100644 --- a/tools/service-video/appl/main.cpp +++ b/tools/service-video/appl/main.cpp @@ -253,7 +253,7 @@ namespace appl { }; } -bool SERVICE_IO_init(std::string _basePath) { +ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string _basePath) { g_basePath = _basePath; std::unique_lock lock(g_mutex); APPL_WARNING("Load USER: " << g_basePath); @@ -300,7 +300,7 @@ bool SERVICE_IO_init(std::string _basePath) { return true; } -bool SERVICE_IO_uninit() { +ETK_EXPORT_API bool SERVICE_IO_uninit() { std::unique_lock lock(g_mutex); APPL_DEBUG("Store User Info:"); bool ret = g_database.storeSafe(g_basePath + g_baseDBName); @@ -312,7 +312,7 @@ bool SERVICE_IO_uninit() { return true; } -bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { +ETK_EXPORT_API bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("==========================================================="); APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]"); APPL_INFO("==========================================================="); @@ -346,16 +346,12 @@ bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]"); APPL_INFO("==========================================================="); if (serviceInterface.connect() == false) { - APPL_INFO("wait 5 second ..."); - std::this_thread::sleep_for(std::chrono::seconds(5)); return false; } if (serviceInterface.GateWayAlive() == false) { APPL_INFO("==========================================================="); APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [STOP] Can not connect to the GateWay"); APPL_INFO("==========================================================="); - APPL_INFO("wait 5 second ..."); - std::this_thread::sleep_for(std::chrono::seconds(5)); return false; } int32_t iii=0; @@ -375,48 +371,3 @@ bool SERVICE_IO_execute(std::string _ip, uint16_t _port) { APPL_INFO("==========================================================="); return true; } - -#ifndef APPL_BUILD_SHARED_LIBRARY - -int main(int _argc, const char *_argv[]) { - etk::init(_argc, _argv); - zeus::init(_argc, _argv); - std::string ip; - uint16_t port = 0; - std::string basePath; - for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; - if (etk::start_with(data, "--ip=") == true) { - ip = std::string(&data[5]); - } else if (etk::start_with(data, "--port=") == true) { - port = etk::string_to_uint16_t(std::string(&data[7])); - } else if (etk::start_with(data, "--base-path=") == true) { - basePath = std::string(&data[12]); - } else if ( data == "-h" - || data == "--help") { - APPL_PRINT(etk::getApplicationName() << " - help : "); - APPL_PRINT(" " << _argv[0] << " [options]"); - APPL_PRINT(" --base-path=XXX base path to search data (default: 'USERDATA:')"); - APPL_PRINT(" --ip=XXX Server connection IP (default: 1.7.0.0.1)"); - APPL_PRINT(" --port=XXX Server connection PORT (default: 1983)"); - return -1; - } - } - if (basePath.size() == 0) { - basePath = "USERDATA:"; - APPL_PRINT("Use base path: " << basePath); - } - SERVICE_IO_init(basePath); - // TODO: Remove the While true, ==> sevice must be spown by a user call, if a service die, the wall system will die ... - while (true) { - SERVICE_IO_execute(ip, port); - } - APPL_INFO("Stop service ==> flush internal datas ..."); - SERVICE_IO_uninit(); - APPL_INFO("==========================================================="); - APPL_INFO("== ZEUS service: " << SERVICE_NAME << " [END-APPLICATION]"); - APPL_INFO("==========================================================="); - return 0; -} - -#endif diff --git a/tools/service-video/lutin_zeus-service-video.py b/tools/service-video/lutin_zeus-service-video.py index fab82e1..433705e 100644 --- a/tools/service-video/lutin_zeus-service-video.py +++ b/tools/service-video/lutin_zeus-service-video.py @@ -4,7 +4,8 @@ import lutin.tools as tools def get_type(): - return "BINARY" + return "LIBRARY_DYNAMIC" + #return "BINARY" def get_sub_type(): return "TOOLS"