[DEV] continue integration of user frendly use of API and multiple service start in launcher

This commit is contained in:
Edouard DUPIN 2016-11-25 22:02:05 +01:00
parent 5e1300867d
commit 1d0f1265eb
19 changed files with 545 additions and 194 deletions

View File

@ -30,6 +30,11 @@ list_of_known_type = [
["vector:uint64", "std::vector<uint64_t>"],
["vector:float32", "std::vector<float>"],
["vector:float64", "std::vector<double>"],
["duration", "echrono::Duration"],
["time", "echrono::Time"],
["file", "zeus::File"],
["stream", "zeus::Stream"],
["json", "ejson::Object"],
]
@ -141,10 +146,16 @@ class FunctionDefinition:
out += space + "virtual "
out += convert_type_in_cpp(self.return_type) + " " + self.name + "("
param_data = ""
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
if len(param_data) != 0:
param_data += ", "
param_data += convert_type_in_cpp(elem["type"]) + " _" + elem["name"]
param_data += convert_type_in_cpp(elem["type"]) + " _"
if elem["name"] == "":
param_data += "no_name_param_" + str(id_parameter)
else:
param_data += elem["name"]
out += param_data
out += ") = 0;\n"
return out;
@ -154,10 +165,16 @@ class FunctionDefinition:
out += self.generate_doxy(space)
out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + self.name + "("
param_data = ""
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
if len(param_data) != 0:
param_data += ", "
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _" + elem["name"]
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _"
if elem["name"] == "":
param_data += "no_name_param_" + str(id_parameter)
else:
param_data += elem["name"]
out += param_data
out += ");\n"
return out;
@ -165,17 +182,29 @@ class FunctionDefinition:
out = "";
out += space + "zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + class_name + "::" + self.name + "("
param_data = ""
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
if len(param_data) != 0:
param_data += ", "
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _" + elem["name"]
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _"
if elem["name"] == "":
param_data += "no_name_param_" + str(id_parameter)
else:
param_data += elem["name"]
out += param_data
out += ") {\n"
space += " "
out += space + 'return m_srv.call("' + self.name + '"'
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
out += ", "
out += "_" + elem["name"]
out += "_"
if elem["name"] == "":
out += "no_name_param_" + str(id_parameter)
else:
out += elem["name"]
out += ');\n'
out += "}\n"
space = space[:-1]
@ -314,7 +343,7 @@ class ServiceDefinition:
out += space + "void register" + self.name[-1] + "(zeus::ServiceType<" + class_name + ">& _serviceInterface);\n"
out += space + "\n"
out += space + "template<class " + MACRO_BASE_NAME + "TYPE>\n"
out += space + "zeus::Service* create" + self.name[-1] + "(std::function<ememory::SharedPtr<" + MACRO_BASE_NAME + "TYPE>(ememory::SharedPtr<ClientProperty>)> _factory) {\n"
out += space + "zeus::Service* create" + self.name[-1] + "(std::function<ememory::SharedPtr<" + MACRO_BASE_NAME + "TYPE>(ememory::SharedPtr<ClientProperty>, const std::string& _userName)> _factory) {\n"
out += space + " zeus::ServiceType<" + class_name + ">* tmp = nullptr;\n"
out += space + " tmp = new zeus::ServiceType<" + class_name + ">(_factory);\n"
out += space + " zeus::service::register" + self.name[-1] + "(*tmp);\n"
@ -328,8 +357,8 @@ class ServiceDefinition:
out += space + "#define " + MACRO_BASE_NAME + "DECLARE_DEFAULT(type) \\\n"
out += space + " ETK_EXPORT_API zeus::Service* SERVICE_IO_instanciate() { \\\n"
out += space + " return " + namespace + "create" + self.name[-1] + "<type>([](ememory::SharedPtr<zeus::ClientProperty> _client){ \\\n"
out += space + " return ememory::makeShared<type>(_client); \\\n"
out += space + " return " + namespace + "create" + self.name[-1] + "<type>([](ememory::SharedPtr<zeus::ClientProperty> _client, const std::string& _userName){ \\\n"
out += space + " return ememory::makeShared<type>(_client, _userName); \\\n"
out += space + " }); \\\n"
out += space + " }\n"
out += space + "\n"
@ -427,34 +456,6 @@ class ServiceDefinition:
out += space + 'ZEUS_INFO("===========================================================");\n';
out += space + 'ZEUS_INFO("== Instanciate service: ' + self.name[-1] + ' [DONE]");\n';
out += space + 'ZEUS_INFO("===========================================================");\n';
"""
if (_serviceInterface.connect() == false) {
return false;
}
if (_serviceInterface.GateWayAlive() == false) {
APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << *_serviceInterface.propertyNameService << " [STOP] Can not connect to the GateWay");
APPL_INFO("===========================================================");
return false;
}
int32_t iii=0;
while (_serviceInterface.GateWayAlive() == true) {
std::this_thread::sleep_for(std::chrono::seconds(10));
_serviceInterface.pingIsAlive();
APPL_INFO("service in waiting ... " << iii << "/inf");
iii++;
}
APPL_INFO("Disconnect service ...");
_serviceInterface.disconnect();
APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << *_serviceInterface.propertyNameService << " [STOP] GateWay Stop");
APPL_INFO("===========================================================");
return true;
"""
out += "}\n"
out += "\n"
@ -499,6 +500,11 @@ class ServiceDefinition:
out += space + "protected:\n"
out += space + " zeus::ServiceRemote m_srv; //!< Service instance handle\n"
out += space + "public:\n"
out += space + " const Proxy" + self.name[-1] + "& operator= (const zeus::ServiceRemote& _srv) {\n"
out += space + " m_srv = _srv;\n"
out += space + " return *this;\n"
out += space + " }\n"
out += space + "public:\n"
space += " "
"""
out += space + "/**\n"
@ -696,21 +702,11 @@ def tool_generate_idl(target, module, data_path):
tmp_path = os.path.join(target.get_build_path_temporary_generate(module.get_name()), "idl_src")
module.add_generated_header_file(service_header[1], service_header[0], install_element=True)
module.add_generated_header_file(register_header[1], register_header[0], install_element=True)
path_file = os.path.join(tmp_path, register_code[0])
tools.file_write_data(path_file, register_code[1], only_if_new=True)
module.add_src_file(path_file)
module.add_generated_src_file(register_code[1], register_code[0])
module.add_generated_header_file(proxy_header[1], proxy_header[0], install_element=True)
module.add_generated_src_file(proxy_code[1], proxy_code[0])
path_file = os.path.join(tmp_path, proxy_code[0])
tools.file_write_data(path_file, proxy_code[1], only_if_new=True)
module.add_src_file(path_file)
debug.info("build in : " + tmp_path);
debug.warning("Parsing .zeus.idl [DONE]")
debug.debug("Parsing .zeus.idl [DONE]")
def parse_service_idl(module, idl_path):

View File

@ -29,7 +29,9 @@ def configure(target, my_module):
'etk',
'enet',
'ememory',
'eproperty'])
'eproperty',
'echrono'
])
my_module.add_src_file([
'zeus/debug.cpp'
])

View File

@ -14,6 +14,9 @@
#include <etk/stdTools.hpp>
#include <zeus/service/ProxyUser.hpp>
#include <echrono/Steady.hpp>
int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
@ -86,12 +89,59 @@ int main(int _argc, const char *_argv[]) {
}
*/
if (false) {
if (true) {
APPL_INFO(" ----------------------------------");
APPL_INFO(" -- Get service system-user");
APPL_INFO(" ----------------------------------");
zeus::ServiceRemote remoteServiceUser = client1.getService("system-user");
#if 1
zeus::service::ProxyUser remoteServiceUser;
remoteServiceUser = client1.getService("user");
if (remoteServiceUser.exist() == true) {
zeus::Future<std::vector<std::string>> retCall = remoteServiceUser.getGroups("clientTest1#atria-soft.com");
retCall.wait();
APPL_INFO("system-user.getGroups() = " << retCall.get());
zeus::Future<std::string> retDesc = remoteServiceUser.sys.getDescription();
zeus::Future<std::string> retVersion = remoteServiceUser.sys.getVersion();
zeus::Future<std::string> retType = remoteServiceUser.sys.getType();
zeus::Future<std::vector<std::string>> retExtention = remoteServiceUser.srv.getExtention();
zeus::Future<std::vector<std::string>> retMaintainer = remoteServiceUser.sys.getAuthors();
retDesc.wait();
retVersion.wait();
retType.wait();
retExtention.wait();
retMaintainer.wait();
APPL_INFO("Service: system-user");
APPL_INFO(" version : " << retVersion.get());
APPL_INFO(" type : " << retType.get());
APPL_INFO(" Extention : " << retExtention.get().size());
for (auto &it : retExtention.get()) {
APPL_INFO(" - " << it);
}
APPL_INFO(" maintainer: " << retMaintainer.get().size());
for (auto &it : retMaintainer.get()) {
APPL_INFO(" - " << it);
}
APPL_INFO(" description:");
APPL_INFO(" " << retDesc.get());
APPL_INFO(" Function List:");
zeus::Future<std::vector<std::string>> retFuctions = remoteServiceUser.sys.getFunctions().wait();
for (auto it : retFuctions.get()) {
echrono::Steady start = echrono::Steady::now();
zeus::Future<std::string> retFunctionPrototype = remoteServiceUser.sys.getFunctionPrototype(it);
zeus::Future<std::string> retFunctionHelp = remoteServiceUser.sys.getFunctionDescription(it);
retFunctionPrototype.wait();
retFunctionHelp.wait();
echrono::Steady stop = echrono::Steady::now();
APPL_INFO(" - " << retFunctionPrototype.get());
APPL_INFO(" " << retFunctionHelp.get());
APPL_INFO(" IO1=" << int64_t(retFunctionPrototype.getTransmitionTime().count()/1000)/1000.0 << " ms");
APPL_INFO(" IO2=" << int64_t(retFunctionHelp.getTransmitionTime().count()/1000)/1000.0 << " ms");
APPL_INFO(" IO*=" << (stop-start));
}
}
#else
zeus::ServiceRemote remoteServiceUser = client1.getService("user");
if (remoteServiceUser.exist() == true) {
zeus::Future<std::vector<std::string>> retCall = remoteServiceUser.call("getGroups", "clientTest1#atria-soft.com");
retCall.wait();
@ -135,11 +185,12 @@ int main(int _argc, const char *_argv[]) {
APPL_INFO(" IO*=" << int64_t((stop-start).count()/1000)/1000.0 << " ms");
}
}
#endif
}
APPL_INFO(" ----------------------------------");
APPL_INFO(" -- Get service picture");
APPL_INFO(" ----------------------------------");
if (true) {
if (false) {
zeus::ServiceRemote remoteServicePicture = client1.getService("picture");
if (remoteServicePicture.exist() == true) {
zeus::Future<std::vector<std::string>> retCall = remoteServicePicture.call("getAlbums").wait();

View File

@ -26,7 +26,10 @@ def get_maintainer():
def configure(target, my_module):
my_module.add_path(".")
my_module.add_depend(['zeus'])
my_module.add_depend([
'zeus',
'zeus-service-user'
])
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp'

View File

@ -15,9 +15,10 @@
static const std::string protocolError = "PROTOCOL-ERROR";
appl::userSpecificInterface::userSpecificInterface() {
appl::userSpecificInterface::userSpecificInterface(const std::string& _userName) {
m_uid = 0;
m_localIdUser = 0;
m_userConnectionName = _userName;
m_state = appl::clientState::unconnect;
APPL_INFO("----------------");
APPL_INFO("-- NEW Client --");
@ -44,7 +45,7 @@ bool appl::userSpecificInterface::start(uint32_t _transactionId, appl::GateWay*
m_state = appl::clientState::connect;
//m_interfaceRouterClient->setInterfaceName("cli-" + etk::to_string(m_uid));
APPL_WARNING("[" << m_uid << "] New client");
APPL_WARNING("[" << m_uid << "] New client : " << m_clientName);
m_userService = m_gatewayInterface->get("user");
if (m_userService == nullptr) {
@ -121,6 +122,13 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
}
case appl::clientState::connect:
{
uint32_t serviceId = callObj->getServiceId();
if (serviceId != 0) {
APPL_ERROR("Call at a service at this state is not allowed serviceID=" << serviceId);
answerProtocolError(transactionId, "MISSING IDENTIFICATION STEP");
return;
}
m_clientServices.clear();
m_clientgroups.clear();
m_clientName.clear();
@ -174,7 +182,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
// --------------------------------
// -- Get groups:
// --------------------------------
zeus::Future<std::vector<std::string>> futGroup = m_userService->m_interfaceClient.callClient(m_localIdUser, "getGroups", m_clientName);
zeus::Future<std::vector<std::string>> futGroup = m_userService->m_interfaceClient.callClient(m_localIdUser, "clientGroupsGet", m_clientName);
futGroup.wait(); // TODO: Set timeout ...
if (futGroup.hasError() == true) {
APPL_ERROR("Get error from the service ...");
@ -187,7 +195,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
// -- Get services:
// --------------------------------
std::vector<std::string> currentServices = m_gatewayInterface->getAllServiceName();
zeus::Future<std::vector<std::string>> futServices = m_userService->m_interfaceClient.callClient(m_localIdUser, "filterServices", m_clientName, currentServices);
zeus::Future<std::vector<std::string>> futServices = m_userService->m_interfaceClient.callClient(m_localIdUser, "filterClientServices", m_clientName, currentServices);
futServices.wait(); // TODO: Set timeout ...
if (futServices.hasError() == true) {
APPL_ERROR("Get error from the service ...");
@ -209,6 +217,7 @@ void appl::userSpecificInterface::onClientData(ememory::SharedPtr<zeus::Buffer>
case appl::clientState::clientIdentify:
{
uint32_t serviceId = callObj->getServiceId();
if (serviceId == 0) {
// This is 2 default service for the cient interface that manage the authorisation of view:
if (callFunction == "getServiceCount") {
@ -334,7 +343,7 @@ appl::RouterInterface::RouterInterface(const std::string& _ip, uint16_t _port, c
return;
}
m_interfaceRouterClient.setInterface(std::move(connection), false, _userName);
//m_userConnectionName = _userName;
m_userConnectionName = _userName;
m_state = appl::clientState::connect;
m_interfaceRouterClient.connect(this, &appl::RouterInterface::onClientData);
m_interfaceRouterClient.connect(true);
@ -388,7 +397,7 @@ void appl::RouterInterface::onClientData(ememory::SharedPtr<zeus::Buffer> _value
}
}
if (localId == -1) {
m_listUser.push_back(userSpecificInterface());
m_listUser.push_back(userSpecificInterface(m_userConnectionName));
localId = m_listUser.size()-1;
bool ret = m_listUser[localId].start(_value->getTransactionId(), m_gatewayInterface, &m_interfaceRouterClient, clientId);
if (ret == false) {

View File

@ -30,7 +30,7 @@ namespace appl {
std::string m_clientName;
std::vector<std::string> m_clientgroups;
std::vector<std::string> m_clientServices;
userSpecificInterface();
userSpecificInterface(const std::string& _userName);
~userSpecificInterface();
bool start(uint32_t _transactionId, appl::GateWay* _gatewayInterface, zeus::WebServer* _interfaceGateWayClient, uint64_t _id);
void onClientData(ememory::SharedPtr<zeus::Buffer> _value);
@ -48,6 +48,7 @@ namespace appl {
private:
appl::GateWay* m_gatewayInterface;
zeus::WebServer m_interfaceRouterClient;
std::string m_userConnectionName;
public:
RouterInterface(const std::string& _ip, uint16_t _port, const std::string& _userName, appl::GateWay* _gatewayInterface);
virtual ~RouterInterface();

View File

@ -52,7 +52,6 @@ appl::ServiceInterface::ServiceInterface(enet::Tcp _connection, appl::GateWay* _
}
appl::ServiceInterface::~ServiceInterface() {
APPL_INFO("--------------------");
APPL_INFO("-- DELETE Service --");
APPL_INFO("--------------------");
@ -104,25 +103,15 @@ void appl::ServiceInterface::onServiceData(ememory::SharedPtr<zeus::Buffer> _val
*/
return;
}
/*
DEPRECATED:
if (_value->getType() == zeus::Buffer::typeMessage::call) {
ememory::SharedPtr<zeus::BufferCall> callObj = ememory::staticPointerCast<zeus::BufferCall>(_value);
std::string callFunction = callObj->getCall();
if (callFunction == "connect-service") {
if (m_name != "") {
APPL_WARNING("Service interface ==> try change the service name after init: '" << callObj->getParameter<std::string>(0));
m_interfaceClient.answerValue(transactionId, false);
return;
}
m_name = callObj->getParameter<std::string>(0);
m_interfaceClient.setInterfaceName("srv-" + m_name);
m_interfaceClient.answerValue(transactionId, true);
if (callFunction == "getUserName") {
m_interfaceClient.answerValue(transactionId, *m_gatewayInterface->propertyUserName);
return;
}
answerProtocolError(transactionId, "unknow function");
}
*/
if (_value->getClientId() == 0) {
APPL_ERROR("Service interface ==> wrong service answer ==> missing 'client-id'");
return;

View File

@ -22,13 +22,131 @@ typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], std::string _b
typedef bool (*SERVICE_IO_uninit_t)();
typedef zeus::Service* (*SERVICE_IO_instanciate_t)();
class PlugginAccess {
private:
std::string m_name;
void* m_handle;
SERVICE_IO_init_t m_SERVICE_IO_init;
SERVICE_IO_uninit_t m_SERVICE_IO_uninit;
SERVICE_IO_instanciate_t m_SERVICE_IO_instanciate;
zeus::Service* m_srv;
public:
PlugginAccess(const std::string& _name) :
m_name(_name),
m_handle(nullptr),
m_SERVICE_IO_init(nullptr),
m_SERVICE_IO_uninit(nullptr),
m_SERVICE_IO_instanciate(nullptr),
m_srv(nullptr){
std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + m_name + "-impl.so";
APPL_PRINT("Try to open service with name: '" << m_name << "' at position: '" << srv << "'");
m_handle = dlopen(srv.c_str(), RTLD_LAZY);
if (!m_handle) {
APPL_ERROR("Can not load Lbrary:" << dlerror());
return;
}
char *error = nullptr;
m_SERVICE_IO_init = (SERVICE_IO_init_t)dlsym(m_handle, "SERVICE_IO_init");
error = dlerror();
if (error != nullptr) {
m_SERVICE_IO_init = nullptr;
APPL_WARNING("Can not function SERVICE_IO_init :" << error);
}
m_SERVICE_IO_uninit = (SERVICE_IO_uninit_t)dlsym(m_handle, "SERVICE_IO_uninit");
error = dlerror();
if (error != nullptr) {
m_SERVICE_IO_uninit = nullptr;
APPL_WARNING("Can not function SERVICE_IO_uninit :" << error);
}
m_SERVICE_IO_instanciate = (SERVICE_IO_instanciate_t)dlsym(m_handle, "SERVICE_IO_instanciate");
error = dlerror();
if (error != nullptr) {
m_SERVICE_IO_instanciate = nullptr;
APPL_WARNING("Can not function SERVICE_IO_instanciate:" << error);
}
}
~PlugginAccess() {
if (m_srv != nullptr) {
delete m_srv;
m_srv = nullptr;
}
}
bool init(int _argc, const char *_argv[], std::string _basePath) {
if (m_SERVICE_IO_init == nullptr) {
return false;
}
if (_basePath.size() == 0) {
_basePath = "USERDATA:" + m_name + "/";
APPL_PRINT("Use base path: " << _basePath);
}
return (*m_SERVICE_IO_init)(_argc, _argv, _basePath);
}
bool uninit() {
if (m_SERVICE_IO_uninit == nullptr) {
return false;
}
return (*m_SERVICE_IO_uninit)();
}
bool instanciate() {
if (m_SERVICE_IO_instanciate == nullptr) {
return false;
}
m_srv = (*m_SERVICE_IO_instanciate)();
return m_srv != nullptr;
}
bool connect(std::string _ip, uint16_t _port) {
if (m_srv == nullptr) {
return false;
}
if (_ip != "") {
m_srv->propertyIp.set(_ip);
}
if (_port != 0) {
m_srv->propertyPort.set(_port);
}
if (m_srv->connect() == false) {
return false;
}
if (m_srv->GateWayAlive() == false) {
APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << *m_srv->propertyNameService << " [STOP] Can not connect to the GateWay");
APPL_INFO("===========================================================");
//delete m_srv;
//m_srv = nullptr;
return false;
}
return true;
}
bool ping() {
if (m_srv == nullptr) {
return false;
}
if (m_srv->GateWayAlive() == true) {
m_srv->pingIsAlive();
}
return m_srv->GateWayAlive();
}
bool disconnect() {
if (m_srv == nullptr) {
return false;
}
m_srv->disconnect();
APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << *m_srv->propertyNameService << " [STOP] GateWay Stop");
APPL_INFO("===========================================================");
return true;
}
};
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;
std::string service;
std::vector<std::string> services;
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
if (etk::start_with(data, "--ip=") == true) {
@ -38,11 +156,7 @@ 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) {
if (service != "") {
APPL_ERROR("Drop sercice : '" << data << "' ==> support run only one service");
return -1;
}
service = std::string(&data[6]);
services.push_back(std::string(&data[6]));
} else if ( data == "-h"
|| data == "--help") {
APPL_PRINT(etk::getApplicationName() << " - help : ");
@ -50,89 +164,47 @@ int main(int _argc, const char *_argv[]) {
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)");
APPL_PRINT(" --srv=XXX service path");
APPL_PRINT(" --srv=XXX service path (N)");
return -1;
}
}
if (basePath.size() == 0) {
basePath = "USERDATA:" + service + "/";
APPL_PRINT("Use base path: " << basePath);
std::vector<ememory::SharedPtr<PlugginAccess>> listElements;
for (auto &it: services) {
ememory::SharedPtr<PlugginAccess> tmp = ememory::makeShared<PlugginAccess>(it);
listElements.push_back(tmp);
}
void *handle = nullptr;
std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + service + "-impl.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;
for (auto &it: listElements) {
it->init(_argc, _argv, basePath);
}
char *error = nullptr;
SERVICE_IO_init_t SERVICE_IO_init = nullptr;
SERVICE_IO_uninit_t SERVICE_IO_uninit = nullptr;
SERVICE_IO_instanciate_t SERVICE_IO_instanciate = 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);
for (auto &it: listElements) {
it->instanciate();
}
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);
for (auto &it: listElements) {
it->connect(ip, port);
}
SERVICE_IO_instanciate = (SERVICE_IO_instanciate_t)dlsym(handle, "SERVICE_IO_instanciate");
error = dlerror();
if (error != nullptr) {
APPL_WARNING("Can not function SERVICE_IO_instanciate:" << error);
}
if (SERVICE_IO_init != nullptr) {
(*SERVICE_IO_init)(_argc, _argv, basePath);
}
while (true) {
if (SERVICE_IO_instanciate == nullptr) {
// nothing to do ...
break;
}
zeus::Service* tmpSrv = (*SERVICE_IO_instanciate)();
if (tmpSrv != nullptr) {
if (ip != "") {
tmpSrv->propertyIp.set(ip);
}
if (port != 0) {
tmpSrv->propertyPort.set(port);
}
if (tmpSrv->connect() == false) {
return false;
}
if (tmpSrv->GateWayAlive() == false) {
APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << *tmpSrv->propertyNameService << " [STOP] Can not connect to the GateWay");
APPL_INFO("===========================================================");
delete tmpSrv;
} else {
int32_t iii=0;
while (tmpSrv->GateWayAlive() == true) {
std::this_thread::sleep_for(std::chrono::seconds(10));
tmpSrv->pingIsAlive();
APPL_INFO("service in waiting ... " << iii << "/inf");
iii++;
}
APPL_INFO("Disconnect service ...");
tmpSrv->disconnect();
APPL_INFO("===========================================================");
APPL_INFO("== ZEUS service: " << *tmpSrv->propertyNameService << " [STOP] GateWay Stop");
APPL_INFO("===========================================================");
delete tmpSrv;
break;
uint32_t iii = 0;
bool oneAlive = true;
while (oneAlive == true) {
oneAlive = false;
for (auto &it: listElements) {
if (it->ping() == true) {
oneAlive = true;
}
}
APPL_INFO("wait 5 second ...");
std::this_thread::sleep_for(std::chrono::seconds(5));
if (oneAlive == true) {
std::this_thread::sleep_for(std::chrono::seconds(10));
APPL_INFO("service in waiting ... " << iii << "/inf");
iii++;
}
}
APPL_INFO("Stop service ==> flush internal datas ...");
if (SERVICE_IO_uninit != nullptr) {
(*SERVICE_IO_uninit)();
for (auto &it: listElements) {
it->disconnect();
}
APPL_INFO("Stop service*** ==> flush internal datas ...");
for (auto &it: listElements) {
it->uninit();
}
return 0;
}

View File

@ -36,9 +36,11 @@ namespace appl {
class PictureService : public zeus::service::Picture {
private:
ememory::SharedPtr<zeus::ClientProperty> m_client;
std::string m_userName;
public:
PictureService(ememory::SharedPtr<zeus::ClientProperty> _client) :
m_client(_client) {
PictureService(ememory::SharedPtr<zeus::ClientProperty> _client, const std::string& _userName) :
m_client(_client),
m_userName(_userName) {
APPL_WARNING("New PictureService ... for user: ");
}
~PictureService() {

View File

@ -8,14 +8,143 @@ vector:string getAlbums()
vector:string getSubAlbums(string)
uint32 getAlbumCount(string)
vector:string getAlbumListPicture(string)
//zeus::FileServer getAlbumPicture(string)
//string addFile(zeus::File)
//file getAlbumPicture(string)
//string addFile(file)
bool removeFile(string)
/*
string createAlbum(string)
bool removeAlbum(string)
bool setAlbumDescription(string, string)
string getAlbumDescription(string)
bool addInAlbum(string, string)
bool removeFromAlbum(string, string)
*/
// ----------------- Get media with their ID -----------------------
#brief:Get the number of media availlable (a media is a picture or a video)
#return: Number of media
uint32 mediaIdCount()
#brief:Get list of name of the media in a specific range (<1024)
#param:start:First Id of the media stream requested (range [0..+inf[)
#param:stop:Last Id of the media stream requested (excluded) (range [0..+inf[)
#return:List of the media names
vector:string mediaIdGetName(uint32,uint32)
// ----------------- Get media with their ID in a range of time -----------------------
#brief:Get the number of media availlable in a range of time
#param:timeStart:First time that the element is requested
#param:timeStop:Last time the count is requested
#return: Number of media in this range of time
uint32 mediaTimeCount(time, time)
#brief:Get list of name of the media in a specific range (<1024)
#param:timeStart:First time that the element is requested
#param:timeStop:Last time the count is requested
#param:start:First Id of the media stream requested (range [0..+inf[)
#param:stop:Last Id of the media stream requested (excluded) (range [0..+inf[)
#return:List of the media names
vector:string mediaTimeGetName(time, time, uint32,uint32)
// ----------------- media Access -----------------------
#brief:Get a media
#param:mediaName:Name of the media
#return:A file reference on the media (transmission is async)
file mediaGet(string)
#brief:Get a media in STREAM mode (usefull for video)
#param:mediaName:Name of the media
#return:A stream reference on the media (transmission is async)
stream mediaStream(string)
#brief:Add a new media in the service
#param:data:A file reference on the media (transmission is async)
#return:Full name of the media (created by the engine ==> not prefictible)
string mediaAdd(file)
#brief:Remove a media in the service (no trash)
#param:mediaName:Name of the media
void mediaRemove(string)
// ----------------- meta-data Access -----------------------
#brief:Get all meta-data of a media
#param:mediaName:Name of the media
#return:a json description of the metadata
json mediaMetadataGet(string)
#brief:Get all meta-data keys of a media
#param:mediaName:Name of the media
#return:List of all availlable keys
vector:string mediaMetadataGetKeys(string)
#brief:Get a meta-data value of a key
#param:mediaName:Name of the media
#param:key:Key of the meta-data
#return:data in the key
string mediaMetadataGetKey(string, string)
#brief:Set a meta-data value of a key
#param:name:Name of the media
#param:key:Key of the meta-data
#param:value:data in the key
void mediaMetadataSetKey(string, string, string)
#brief:Get all meta-data of a media
#param:name:Name of the media
#param:description: a json description of the metadata
void mediaMetadataGet(string, json)
// ----------------- Album Access -----------------------
#brief: Create an album
#param:albumName:Name of the Album
#return:Id of the album
uint32 albumCreate(string)
#brief: Remove an album
#param:albumId:Id of the Album
void albumRemove(uint32)
#brief:Get list of Id of all albums
#return:List of all Id of the albums
vector:uint32 albumGetList()
#brief:Get the name of the album
#param:albumId:Id of the Album
#return:Name of the Album
string albumNameGet(uint32)
#brief:Set the name of the album
#param:albumId:Id of the Album
#param:albumName:Name of the Album
void albumNameSet(uint32, string)
#brief:Get the description of the album
#param:albumId:Id of the Album
#return:Description of the Album
string albumDescriptionGet(uint32)
#brief:Set the description of the album
#param:albumId:Id of the Album
#param:desc:Description of the Album
void albumDescriptionSet(uint32, string)
#brief:Add a media in an album
#param:albumId:Id of the Album
#param:mediaName:Name of the media to add
void albumMediaAdd(uint32, string)
#brief:Remove a media in an album
#param:albumId:Id of the Album
#param:mediaName:Name of the media to remove
void albumMediaRemove(uint32, string)
#brief:Get number of media in an album
#param:albumId:Id of the Album
#return:Number of medias
uint32 albumMediaCount(uint32)
#brief:Get list of name of the media in a specific range (<1024)
#param:albumId:Id of the Album
#param:start:First Id of the media stream requested (range [0..+inf[)
#param:stop:Last Id of the media stream requested (excluded) (range [0..+inf[)
#return:List of the media names
vector:string albumMediaGetName(uint32, uint32,uint32)
#brief:Set the parrent album at a specific album
#param:albumId:Id of the Album
#param:albumParentId:Id of the parent Album
void albumParentSet(uint32, uint32)
#brief:Remove the parrent album at a specific album
#param:albumId:Id of the Album
void albumParentRemove(uint32)
#brief:Get the parrent album at a specific album
#param:albumId:Id of the Album
uint32 albumParentGet(uint32)
// ----------------- Album Right Access -----------------------
// ----------------- Media Right Access -----------------------
*/

View File

@ -26,16 +26,18 @@ namespace appl {
class SystemService : public zeus::service::User {
private:
ememory::SharedPtr<zeus::ClientProperty> m_client;
std::string m_userName;
public:
SystemService(ememory::SharedPtr<zeus::ClientProperty> _client) :
m_client(_client) {
SystemService(ememory::SharedPtr<zeus::ClientProperty> _client, const std::string& _userName) :
m_client(_client),
m_userName(_userName) {
APPL_WARNING("New SystemService ... for user: ");
}
~SystemService() {
APPL_WARNING("Delete service-user interface.");
}
public:
std::vector<std::string> getGroups(std::string _clientName) {
std::vector<std::string> clientGroupsGet(std::string _clientName) {
std::vector<std::string> out;
if (m_client == nullptr) {
return out;
@ -71,13 +73,16 @@ namespace appl {
}
bool checkTocken(std::string _clientName, std::string _tocken) {
std::unique_lock<std::mutex> lock(g_mutex);
APPL_INFO("Check TOCKEN for : '" << _clientName << "' tocken='" << _clientName << "'");
ejson::Object clients = g_database["client"].toObject();
if (clients.exist() == false) {
APPL_INFO(" ==> return false");
// Section never created
return false;
}
ejson::Object client = clients[_clientName].toObject();
if (clients.exist() == false) {
APPL_INFO(" ==> return false");
// No specificity for this client (in case it have no special right)
return false;
}
@ -85,12 +90,15 @@ namespace appl {
// TODO: Do it better ...
std::string registerTocken = client["tocken"].toString().get();
if (registerTocken == _tocken) {
APPL_INFO(" ==> return true");
return true;
}
APPL_INFO(" ==> return false");
return false;
}
bool checkAuth(std::string _password) {
std::unique_lock<std::mutex> lock(g_mutex);
APPL_INFO("Check AUTH for : '" << _password << "'");
std::string pass = g_database["password"].toString().get();
if (pass == "") {
// pb password
@ -101,10 +109,12 @@ namespace appl {
}
return false;
}
std::vector<std::string> filterServices(std::string _clientName, std::vector<std::string> _currentList) {
std::vector<std::string> filterClientServices(std::string _clientName, std::vector<std::string> _currentList) {
std::unique_lock<std::mutex> lock(g_mutex);
APPL_INFO("Filter services : '" << _clientName << "' " << _currentList);
// When connected to our session ==> we have no control access ...
if (_clientName == g_basePath) {
if (_clientName == m_userName) {
APPL_INFO(" return all");
return _currentList;
}
std::vector<std::string> out;

View File

@ -3,17 +3,7 @@
#srv-type:USER
#srv-author:Heero Yui<yui.heero@gmail.com>
// Idl comment example
/*
Multiple line comment example
And an other line
*/
#brief:Get list of group availlable for a client name
#param:clientName:Name of the client
vector:string getGroups(string)
// ----------------- Check authorisations -----------------------
#brief:Check if a user tocken is correct or not
#param:clientName:Name of the client
#param:tocken:String containing the Tocken
@ -25,7 +15,84 @@ bool checkTocken(string, string)
#return: true if the pasword is validated or false if it is wrong
bool checkAuth(string)
#brief:Filter a list of service with the cuurent profile of the user (restrict area)
// ----------------- Check GROUP right restriction for a client -----------------------
#brief:Get list of group availlable for a client name
#param:clientName:Name of the client
vector:string clientGroupsGet(string)
/*
#brief:Add a group for a client
#param:clientName:Name of the client
#param:groupName:Name of the group to add
void clientGroupsAdd(string, string)
#brief:Remove a group for a client
#param:clientName:Name of the client
#param:groupName:Name of the group to remove
void clientGroupsRemove(string, string)
*/
// ----------------- Check SERVICE right restriction for a client -----------------------
#brief:Filter a list of service with for a the user (restrict area)
#param:clientName:Name of the client
#param:currentList:Vector of name of the services
vector:string filterServices(string, vector:string)
vector:string filterClientServices(string, vector:string)
/*
#brief:Add a Service acces for a client
#param:clientName:Name of the client
#param:serviceName:Name of the Service access to add
void clientServiceAccessAdd(string, string)
#brief:Remove a group for a client
#param:clientName:Name of the client
#param:serviceName:Name of the Service access to add
void clientServiceAccessRemove(string, string)
*/
// ----------------- Add / remove Client access request -----------------------
/*
#brief:Request access form a client (the answer is asynchronous ... when user athorize it)
#param:clientName:Name of the client
#param:message:Message from the client to convince the user to athorise him to access
void clientRequestAccess(string, string)
#brief:Get the Number of client requesting an access of this user
#return: The count of pending request
uint32 getClientRequestAccessCount()
#brief:Get a pending request
#param:id:Id of the pending request
#return: a pair of value: name,message
// TODO: support real pair of value ...
vector:string getClientRequestAccessList(uint32)
#brief:Accept or refuse the access on a specific client (with message)
#param:answer:true The access is athorized, false otherwise
#param:clientName:Name of the client
#param:message:Answer message of the request
string getClientRequestAccessAnswer(bool, string, string)
#brief:Remove the access request on a specific client
#param:clientName:Name of the client
string getClientRequestAccessRemove(string)
*/
// ----------------- Remove Client access -----------------------
/*
#brief:Get the list of all client reference for this user
#return:All the client connected
string clientGetList()
#brief:Remove all Access of a specific client
#param:clientName:Name of the client
void clientRemove(string)
#brief:Suspend all Access of a specific client
#param:clientName:Name of the client
#param:while:The duration while the client has been suspended, if 0 this is infinite
void clientSuspend(string, duration)
#brief:Get the last connection of a user
#param:clientName:Name of the client
#return:The last connection time
time clientLastConnection(string, duration)
*/

View File

@ -36,9 +36,11 @@ namespace appl {
class VideoService : public zeus::service::Video {
private:
ememory::SharedPtr<zeus::ClientProperty> m_client;
std::string m_userName;
public:
VideoService(ememory::SharedPtr<zeus::ClientProperty> _client) :
m_client(_client) {
VideoService(ememory::SharedPtr<zeus::ClientProperty> _client, const std::string& _userName) :
m_client(_client),
m_userName(_userName) {
APPL_WARNING("New VideoService ... for user: ");
}
~VideoService() {

View File

@ -98,6 +98,7 @@ void zeus::Buffer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {
void zeus::Buffer::clear() {
m_header.transactionID = 1;
m_header.clientID = 0;
m_header.serviceID = 0;
m_header.flags = ZEUS_BUFFER_FLAG_FINISH;
}
@ -115,6 +116,7 @@ void zeus::Buffer::generateDisplay(std::ostream& _os) const {
_os << " if=" << etk::to_string(getInterfaceId());
_os << " tr-id=" << etk::to_string(getTransactionId());
_os << " cId=" << etk::to_string(getClientId());
_os << " sId=" << etk::to_string(getServiceId());
if (getPartFinish() == true) {
_os << " finish";
}
@ -164,6 +166,14 @@ void zeus::Buffer::setClientId(uint32_t _value) {
m_header.clientID = _value;
}
uint32_t zeus::Buffer::getServiceId() const {
return m_header.serviceID;
}
void zeus::Buffer::setServiceId(uint32_t _value) {
m_header.serviceID = _value;
}
bool zeus::Buffer::getPartFinish() const {
return (m_header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0;
}
@ -205,6 +215,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
}
value->setTransactionId(header.transactionID);
value->setClientId(header.clientID);
value->setServiceId(header.serviceID);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin));
@ -218,6 +229,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
}
value->setTransactionId(header.transactionID);
value->setClientId(header.clientID);
value->setServiceId(header.serviceID);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin));
@ -231,6 +243,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
}
value->setTransactionId(header.transactionID);
value->setClientId(header.clientID);
value->setServiceId(header.serviceID);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin));
@ -244,6 +257,7 @@ ememory::SharedPtr<zeus::Buffer> zeus::Buffer::create(const std::vector<uint8_t>
}
value->setTransactionId(header.transactionID);
value->setClientId(header.clientID);
value->setServiceId(header.serviceID);
value->setPartFinish((header.flags & ZEUS_BUFFER_FLAG_FINISH) != 0);
value->composeWith(&_buffer[sizeof(headerBin)],
_buffer.size() - sizeof(headerBin));

View File

@ -33,7 +33,8 @@ namespace zeus {
struct headerBin {
//uint16_t versionProtocol; // protocol Version (might be 1)
uint32_t transactionID;
uint32_t clientID; // same as sevice ID
uint32_t clientID; // Client Routing ID
uint32_t serviceID; // service routing ID
uint8_t flags; // List of flags & type message:
// - 0-2: Type of the message
// - 3-5: Reserved
@ -191,7 +192,7 @@ namespace zeus {
* @brief Get the Client identifier of the packet
* @return Value of the Client identifier
*/
uint32_t getClientId() const;// this is the same as serviceId
uint32_t getClientId() const;
/**
* @brief Set the Client identifier of the packet
* @param[in] _value New value of the Client identifier
@ -201,16 +202,12 @@ namespace zeus {
* @brief Get the Service identifier of the packet (same as client)
* @return Value of the Service identifier
*/
uint32_t getServiceId() const {
return getClientId();
}
uint32_t getServiceId() const;
/**
* @brief Set the Service identifier of the packet (same as client)
* @param[in] _value New value of the Service identifier
*/
void setServiceId(uint32_t _value) {
setClientId(_value);
}
void setServiceId(uint32_t _value);
/**
* @brief Check if it is the last packet of the buffer
* @return If "true" The Buffer wait no more datas

View File

@ -101,6 +101,12 @@ bool zeus::Service::connect(uint32_t _numberRetry){
ZEUS_ERROR("Can not connect service ...");
return false;
}
zeus::Future<std::string> ret = m_interfaceClient->call("getUserName");
ret.wait();
m_nameUser = ret.get();
ZEUS_ERROR("Connect with name user: '" << m_nameUser << "'");
ZEUS_DEBUG("connect [STOP]");
return true;
}

View File

@ -112,6 +112,7 @@ namespace zeus {
uint32_t m_id;
std::vector<std::string> m_newData;
std::vector<zeus::FutureBase> m_callMultiData;
std::string m_nameUser;
public:
/**
* @brief
@ -245,9 +246,9 @@ namespace zeus {
template<class ZEUS_TYPE_SERVICE>
class ServiceType : public zeus::Service {
private:
std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(ememory::SharedPtr<ClientProperty>)> m_factory;
std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(ememory::SharedPtr<ClientProperty>, const std::string&)> m_factory;
public:
ServiceType(std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(ememory::SharedPtr<ClientProperty>)> _factory) {
ServiceType(std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(ememory::SharedPtr<ClientProperty>, const std::string&)> _factory) {
m_factory = _factory;
}
private:
@ -312,7 +313,7 @@ namespace zeus {
ememory::SharedPtr<ClientProperty> tmpProperty = ememory::makeShared<ClientProperty>(_clientName, _groups);
ememory::SharedPtr<ZEUS_TYPE_SERVICE> tmpSrv;
if (m_factory != nullptr) {
tmpSrv = m_factory(tmpProperty);
tmpSrv = m_factory(tmpProperty, m_nameUser);
} else {
ZEUS_ERROR("Create service with no factory");
}