[DEV] luncher work well bun run only one service (Missing set of the user data in a specific path)

This commit is contained in:
Edouard DUPIN 2016-11-23 21:38:34 +01:00
parent 9b7cff391d
commit 7cef0f6b08
7 changed files with 66 additions and 198 deletions

View File

@ -13,20 +13,19 @@
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <thread>
#include <etk/stdTools.hpp>
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<std::string> 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;

View File

@ -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<std::mutex> 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<std::mutex> 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

View File

@ -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"

View File

@ -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<std::mutex> 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<std::mutex> 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

View File

@ -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"

View File

@ -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<std::mutex> 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<std::mutex> 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

View File

@ -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"