[DEV] base of machro generation
This commit is contained in:
parent
bca8a8f2bd
commit
a31212ce48
@ -15,13 +15,16 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <etk/stdTools.hpp>
|
#include <etk/stdTools.hpp>
|
||||||
|
#include <zeus/Service.hpp>
|
||||||
|
#include <zeus/zeus.hpp>
|
||||||
|
|
||||||
typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], 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_uninit_t)();
|
||||||
typedef bool (*SERVICE_IO_execute_t)(std::string _ip, uint16_t _port);
|
typedef zeus::Service* (*SERVICE_IO_instanciate_t)();
|
||||||
|
|
||||||
int main(int _argc, const char *_argv[]) {
|
int main(int _argc, const char *_argv[]) {
|
||||||
etk::init(_argc, _argv);
|
etk::init(_argc, _argv);
|
||||||
|
zeus::init(_argc, _argv);
|
||||||
std::string ip;
|
std::string ip;
|
||||||
uint16_t port = 0;
|
uint16_t port = 0;
|
||||||
std::string basePath;
|
std::string basePath;
|
||||||
@ -56,7 +59,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
APPL_PRINT("Use base path: " << basePath);
|
APPL_PRINT("Use base path: " << basePath);
|
||||||
}
|
}
|
||||||
void *handle = nullptr;
|
void *handle = nullptr;
|
||||||
std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + service + ".so";
|
std::string srv = etk::FSNodeGetApplicationPath() + "/../lib/libzeus-service-" + service + "-impl.so";
|
||||||
APPL_PRINT("Try to open service with name: '" << service << "' at position: '" << srv << "'");
|
APPL_PRINT("Try to open service with name: '" << service << "' at position: '" << srv << "'");
|
||||||
handle = dlopen(srv.c_str(), RTLD_LAZY);
|
handle = dlopen(srv.c_str(), RTLD_LAZY);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
@ -66,7 +69,7 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
char *error = nullptr;
|
char *error = nullptr;
|
||||||
SERVICE_IO_init_t SERVICE_IO_init = nullptr;
|
SERVICE_IO_init_t SERVICE_IO_init = nullptr;
|
||||||
SERVICE_IO_uninit_t SERVICE_IO_uninit = nullptr;
|
SERVICE_IO_uninit_t SERVICE_IO_uninit = nullptr;
|
||||||
SERVICE_IO_execute_t SERVICE_IO_execute = nullptr;
|
SERVICE_IO_instanciate_t SERVICE_IO_instanciate = nullptr;
|
||||||
SERVICE_IO_init = (SERVICE_IO_init_t)dlsym(handle, "SERVICE_IO_init");
|
SERVICE_IO_init = (SERVICE_IO_init_t)dlsym(handle, "SERVICE_IO_init");
|
||||||
error = dlerror();
|
error = dlerror();
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
@ -77,21 +80,52 @@ int main(int _argc, const char *_argv[]) {
|
|||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
APPL_WARNING("Can not function SERVICE_IO_uninit :" << error);
|
APPL_WARNING("Can not function SERVICE_IO_uninit :" << error);
|
||||||
}
|
}
|
||||||
SERVICE_IO_execute = (SERVICE_IO_execute_t)dlsym(handle, "SERVICE_IO_execute");
|
SERVICE_IO_instanciate = (SERVICE_IO_instanciate_t)dlsym(handle, "SERVICE_IO_instanciate");
|
||||||
error = dlerror();
|
error = dlerror();
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
APPL_WARNING("Can not function SERVICE_IO_execute:" << error);
|
APPL_WARNING("Can not function SERVICE_IO_instanciate:" << error);
|
||||||
}
|
}
|
||||||
if (SERVICE_IO_init != nullptr) {
|
if (SERVICE_IO_init != nullptr) {
|
||||||
(*SERVICE_IO_init)(_argc, _argv, basePath);
|
(*SERVICE_IO_init)(_argc, _argv, basePath);
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
if (SERVICE_IO_execute == nullptr) {
|
if (SERVICE_IO_instanciate == nullptr) {
|
||||||
// nothing to do ...
|
// nothing to do ...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((*SERVICE_IO_execute)(ip, port) == true) {
|
zeus::Service* tmpSrv = (*SERVICE_IO_instanciate)();
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
APPL_INFO("wait 5 second ...");
|
APPL_INFO("wait 5 second ...");
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
|
@ -28,6 +28,7 @@ def configure(target, my_module):
|
|||||||
my_module.add_path(".")
|
my_module.add_path(".")
|
||||||
my_module.add_depend([
|
my_module.add_depend([
|
||||||
'etk',
|
'etk',
|
||||||
|
'zeus',
|
||||||
'elog'
|
'elog'
|
||||||
])
|
])
|
||||||
my_module.add_src_file([
|
my_module.add_src_file([
|
||||||
|
@ -25,7 +25,7 @@ def configure(target, my_module):
|
|||||||
my_module.add_depend([
|
my_module.add_depend([
|
||||||
'zeus-router',
|
'zeus-router',
|
||||||
'zeus-gateway',
|
'zeus-gateway',
|
||||||
'zeus-service-user',
|
'zeus-service-user-impl',
|
||||||
'zeus-service-picture',
|
'zeus-service-picture',
|
||||||
'zeus-service-video',
|
'zeus-service-video',
|
||||||
'zeus-launcher',
|
'zeus-launcher',
|
||||||
|
@ -312,6 +312,11 @@ ETK_EXPORT_API bool SERVICE_IO_uninit() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ZEUS_SERVICE_PICTURE_DECLARE_DEFAULT(appl::PictureService);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ETK_EXPORT_API 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("===========================================================");
|
||||||
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
||||||
@ -327,8 +332,9 @@ ETK_EXPORT_API bool SERVICE_IO_execute(std::string _ip, uint16_t _port) {
|
|||||||
}
|
}
|
||||||
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
||||||
serviceInterface.setDescription("Picture Private Interface");
|
serviceInterface.setDescription("Picture Private Interface");
|
||||||
serviceInterface.setVersion("0.1.0");
|
serviceInterface.setVersionImplementation("0.1.0");
|
||||||
serviceInterface.setType("PICTURE", 1);
|
serviceInterface.setVersion("1.0");
|
||||||
|
serviceInterface.setType("PICTURE");
|
||||||
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
||||||
|
|
||||||
serviceInterface.advertise("getAlbums", &appl::PictureService::getAlbums);
|
serviceInterface.advertise("getAlbums", &appl::PictureService::getAlbums);
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <etk/stdTools.hpp>
|
#include <etk/stdTools.hpp>
|
||||||
|
|
||||||
|
#include <zeus/service/User.hpp>
|
||||||
|
#include <zeus/service/registerUser.hpp>
|
||||||
|
|
||||||
static std::mutex g_mutex;
|
static std::mutex g_mutex;
|
||||||
static std::string g_basePath;
|
static std::string g_basePath;
|
||||||
@ -21,7 +23,7 @@ static std::string g_baseDBName = std::string(SERVICE_NAME) + "-database.json";
|
|||||||
static ejson::Document g_database;
|
static ejson::Document g_database;
|
||||||
|
|
||||||
namespace appl {
|
namespace appl {
|
||||||
class SystemService {
|
class SystemService : public zeus::service::User {
|
||||||
private:
|
private:
|
||||||
ememory::SharedPtr<zeus::ClientProperty> m_client;
|
ememory::SharedPtr<zeus::ClientProperty> m_client;
|
||||||
public:
|
public:
|
||||||
@ -113,8 +115,6 @@ namespace appl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], 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;
|
g_basePath = _basePath;
|
||||||
std::unique_lock<std::mutex> lock(g_mutex);
|
std::unique_lock<std::mutex> lock(g_mutex);
|
||||||
APPL_WARNING("Load USER: " << g_basePath);
|
APPL_WARNING("Load USER: " << g_basePath);
|
||||||
@ -137,69 +137,11 @@ ETK_EXPORT_API bool SERVICE_IO_uninit() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ETK_EXPORT_API bool SERVICE_IO_execute(std::string _ip, uint16_t _port) {
|
#if 1
|
||||||
APPL_INFO("===========================================================");
|
ZEUS_SERVICE_USER_DECLARE_DEFAULT(appl::SystemService);
|
||||||
APPL_INFO("== ZEUS instanciate service: " << SERVICE_NAME << " [START]");
|
#else
|
||||||
APPL_INFO("===========================================================");
|
ZEUS_SERVICE_USER_DECLARE(appl::SystemService,
|
||||||
zeus::ServiceType<appl::SystemService> serviceInterface([](ememory::SharedPtr<zeus::ClientProperty> _client){
|
[](ememory::SharedPtr<zeus::ClientProperty> _client){
|
||||||
return ememory::makeShared<appl::SystemService>(_client);
|
return ememory::makeShared<appl::SystemService>(_client);
|
||||||
});
|
})
|
||||||
if (_ip != "") {
|
#endif
|
||||||
serviceInterface.propertyIp.set(_ip);
|
|
||||||
}
|
|
||||||
if (_port != 0) {
|
|
||||||
serviceInterface.propertyPort.set(_port);
|
|
||||||
}
|
|
||||||
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
|
||||||
serviceInterface.setDescription("user interface management");
|
|
||||||
serviceInterface.setVersion("0.1.0");
|
|
||||||
serviceInterface.setType("USER", 1);
|
|
||||||
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
|
||||||
zeus::AbstractFunction* func = serviceInterface.advertise("checkTocken", &appl::SystemService::checkTocken);
|
|
||||||
if (func != nullptr) {
|
|
||||||
func->setDescription("Check if a user tocken is correct or not");
|
|
||||||
func->addParam("clientName", "Name of the client");
|
|
||||||
func->addParam("tocken", "String containing the Tocken");
|
|
||||||
}
|
|
||||||
func = serviceInterface.advertise("checkAuth", &appl::SystemService::checkAuth);
|
|
||||||
if (func != nullptr) {
|
|
||||||
func->setDescription("Check the password of the curent user");
|
|
||||||
func->addParam("password", "client/user password");
|
|
||||||
}
|
|
||||||
func = serviceInterface.advertise("getGroups", &appl::SystemService::getGroups);
|
|
||||||
if (func != nullptr) {
|
|
||||||
func->setDescription("Get list of group availlable for a client name");
|
|
||||||
func->addParam("clientName", "Name of the client");
|
|
||||||
}
|
|
||||||
func = serviceInterface.advertise("filterServices", &appl::SystemService::filterServices);
|
|
||||||
if (func != nullptr) {
|
|
||||||
func->setDescription("Filter a list of service with the cuurent profile of the user (restrict area)");
|
|
||||||
func->addParam("clientName", "Name of the client");
|
|
||||||
func->addParam("currentList", "Vector of name of the services");
|
|
||||||
}
|
|
||||||
APPL_INFO("===========================================================");
|
|
||||||
APPL_INFO("== ZEUS service: " << *serviceInterface.propertyNameService << " [service instanciate]");
|
|
||||||
APPL_INFO("===========================================================");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#srv-brief: user interface management
|
#srv-brief: user interface management
|
||||||
#srv-version: 0.1.0
|
#srv-version: 1.0
|
||||||
#srv-type-api:USER/1
|
#srv-type:USER
|
||||||
#srv-author:Heero Yui<yui.heero@gmail.com>
|
#srv-author:Heero Yui<yui.heero@gmail.com>
|
||||||
|
|
||||||
// Idl comment example
|
// Idl comment example
|
47
tools/service-user/lutin_zeus-service-user-impl.py
Normal file
47
tools/service-user/lutin_zeus-service-user-impl.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import lutin.debug as debug
|
||||||
|
import lutin.tools as tools
|
||||||
|
import os
|
||||||
|
import copy
|
||||||
|
|
||||||
|
|
||||||
|
def get_type():
|
||||||
|
return "LIBRARY_DYNAMIC"
|
||||||
|
#return "BINARY"
|
||||||
|
|
||||||
|
def get_sub_type():
|
||||||
|
return "TOOLS"
|
||||||
|
|
||||||
|
def get_desc():
|
||||||
|
return "ZEUS service user"
|
||||||
|
|
||||||
|
def get_licence():
|
||||||
|
return "APACHE-2"
|
||||||
|
|
||||||
|
def get_compagny_type():
|
||||||
|
return "com"
|
||||||
|
|
||||||
|
def get_compagny_name():
|
||||||
|
return "atria-soft"
|
||||||
|
|
||||||
|
def get_maintainer():
|
||||||
|
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
|
||||||
|
|
||||||
|
def configure(target, my_module):
|
||||||
|
my_module.add_path(".")
|
||||||
|
my_module.add_depend([
|
||||||
|
'zeus',
|
||||||
|
'ejson',
|
||||||
|
'zeus-service-user'
|
||||||
|
])
|
||||||
|
my_module.add_src_file([
|
||||||
|
'appl/debug.cpp',
|
||||||
|
'appl/main.cpp'
|
||||||
|
])
|
||||||
|
|
||||||
|
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"user\\\"\"")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
|||||||
import lutin.debug as debug
|
import lutin.debug as debug
|
||||||
import lutin.tools as tools
|
import lutin.tools as tools
|
||||||
import os
|
import os
|
||||||
|
import copy
|
||||||
|
|
||||||
|
|
||||||
def get_type():
|
def get_type():
|
||||||
@ -14,7 +15,7 @@ def get_sub_type():
|
|||||||
def get_desc():
|
def get_desc():
|
||||||
return "ZEUS service user"
|
return "ZEUS service user"
|
||||||
|
|
||||||
def get_licence():
|
def get_license():
|
||||||
return "APACHE-2"
|
return "APACHE-2"
|
||||||
|
|
||||||
def get_compagny_type():
|
def get_compagny_type():
|
||||||
@ -67,6 +68,20 @@ def convert_type_in_cpp(data):
|
|||||||
return elem[1]
|
return elem[1]
|
||||||
debug.error(" can not find type in IDL : '" + data + "'")
|
debug.error(" can not find type in IDL : '" + data + "'")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_start_stop_spacer(data):
|
||||||
|
dataout = copy.deepcopy(data)
|
||||||
|
while len(dataout) >= 1 \
|
||||||
|
and ( dataout[0] == " " \
|
||||||
|
or dataout[0] == "\t"):
|
||||||
|
dataout = dataout[1:]
|
||||||
|
while len(dataout) >= 1 \
|
||||||
|
and ( dataout[-1] == " " \
|
||||||
|
or dataout[-1] == "\t"):
|
||||||
|
dataout = dataout[:-1]
|
||||||
|
return dataout
|
||||||
|
|
||||||
|
|
||||||
class FunctionDefinition:
|
class FunctionDefinition:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = "";
|
self.name = "";
|
||||||
@ -76,11 +91,11 @@ class FunctionDefinition:
|
|||||||
self.parameters = []
|
self.parameters = []
|
||||||
|
|
||||||
def set_function_name(self, name):
|
def set_function_name(self, name):
|
||||||
self.name = name;
|
self.name = remove_start_stop_spacer(name);
|
||||||
|
|
||||||
def set_brief(self, desc):
|
def set_brief(self, desc):
|
||||||
self.name = "";
|
self.name = "";
|
||||||
self.brief = desc;
|
self.brief = remove_start_stop_spacer(desc);
|
||||||
self.return_type = "";
|
self.return_type = "";
|
||||||
self.return_brief = "";
|
self.return_brief = "";
|
||||||
self.parameters = []
|
self.parameters = []
|
||||||
@ -89,44 +104,43 @@ class FunctionDefinition:
|
|||||||
for elem in self.parameters:
|
for elem in self.parameters:
|
||||||
if elem["name"] == "" \
|
if elem["name"] == "" \
|
||||||
and elem["brief"] == "":
|
and elem["brief"] == "":
|
||||||
elem["name"] = name;
|
elem["name"] = remove_start_stop_spacer(name);
|
||||||
elem["brief"] = desc;
|
elem["brief"] = remove_start_stop_spacer(desc);
|
||||||
return;
|
return;
|
||||||
self.parameters.append({
|
self.parameters.append({
|
||||||
"type":"",
|
"type":"",
|
||||||
"name":name,
|
"name":remove_start_stop_spacer(name),
|
||||||
"brief":desc
|
"brief":remove_start_stop_spacer(desc)
|
||||||
})
|
})
|
||||||
|
|
||||||
def set_return_comment(self, desc):
|
def set_return_comment(self, desc):
|
||||||
self.return_brief = desc;
|
self.return_brief = remove_start_stop_spacer(desc);
|
||||||
|
|
||||||
def set_return_type(self, type):
|
def set_return_type(self, type):
|
||||||
self.return_type = type;
|
self.return_type = remove_start_stop_spacer(type);
|
||||||
|
|
||||||
def add_parameter_type(self, type):
|
def add_parameter_type(self, type):
|
||||||
for elem in self.parameters:
|
for elem in self.parameters:
|
||||||
if elem["type"] == "":
|
if elem["type"] == "":
|
||||||
elem["type"] = type;
|
elem["type"] = remove_start_stop_spacer(type);
|
||||||
return;
|
return;
|
||||||
self.parameters.append({
|
self.parameters.append({
|
||||||
"type":type,
|
"type":remove_start_stop_spacer(type),
|
||||||
"name":"",
|
"name":"",
|
||||||
"brief":""
|
"brief":""
|
||||||
})
|
})
|
||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
debug.info(" BRIEF: " + self.brief)
|
debug.info(" BRIEF: " + self.brief)
|
||||||
debug.info(" BRIEF-return: " + self.return_brief)
|
debug.info(" BRIEF-return: " + self.return_brief)
|
||||||
debug.info(" " + self.return_type + " " + self.name + "(")
|
debug.info(" " + self.return_type + " " + self.name + "(")
|
||||||
for elem in self.parameters:
|
for elem in self.parameters:
|
||||||
debug.info(" " + elem["type"] + " " + elem["name"] + ", # " + elem["brief"])
|
debug.info(" " + elem["type"] + " " + elem["name"] + ", # " + elem["brief"])
|
||||||
debug.info(" )")
|
debug.info(" )")
|
||||||
|
|
||||||
def generate_cpp(self, space):
|
def generate_doxy(self, space):
|
||||||
out = "";
|
|
||||||
# generate doxygen comment:
|
# generate doxygen comment:
|
||||||
out += space + "/**\n"
|
out = space + "/**\n"
|
||||||
if self.brief != "":
|
if self.brief != "":
|
||||||
out += space + " * @brief " + self.brief + "\n"
|
out += space + " * @brief " + self.brief + "\n"
|
||||||
for elem in self.parameters:
|
for elem in self.parameters:
|
||||||
@ -142,7 +156,11 @@ class FunctionDefinition:
|
|||||||
if self.return_brief != "":
|
if self.return_brief != "":
|
||||||
out += space + " * @return " + self.return_brief + "\n"
|
out += space + " * @return " + self.return_brief + "\n"
|
||||||
out += space + " */\n"
|
out += space + " */\n"
|
||||||
|
return out
|
||||||
|
|
||||||
|
def generate_cpp(self, space):
|
||||||
|
out = "";
|
||||||
|
out += self.generate_doxy(space)
|
||||||
out += space + "virtual "
|
out += space + "virtual "
|
||||||
out += convert_type_in_cpp(self.return_type) + " " + self.name + "("
|
out += convert_type_in_cpp(self.return_type) + " " + self.name + "("
|
||||||
param_data = ""
|
param_data = ""
|
||||||
@ -154,16 +172,403 @@ class FunctionDefinition:
|
|||||||
out += ") = 0;\n"
|
out += ") = 0;\n"
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
def parse_service_idl(path):
|
def generate_hpp_proxy(self, space):
|
||||||
debug.info("Parsing .zeus.idl [start] " + str(path))
|
out = "";
|
||||||
name_file = os.path.basename(path)
|
out += self.generate_doxy(space)
|
||||||
|
out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + self.name + "("
|
||||||
|
param_data = ""
|
||||||
|
for elem in self.parameters:
|
||||||
|
if len(param_data) != 0:
|
||||||
|
param_data += ", "
|
||||||
|
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _" + elem["name"]
|
||||||
|
out += param_data
|
||||||
|
out += ");\n"
|
||||||
|
return out;
|
||||||
|
def generate_cpp_proxy(self, space, class_name):
|
||||||
|
out = "";
|
||||||
|
out += space + "zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + class_name + "::" + self.name + "("
|
||||||
|
param_data = ""
|
||||||
|
for elem in self.parameters:
|
||||||
|
if len(param_data) != 0:
|
||||||
|
param_data += ", "
|
||||||
|
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _" + elem["name"]
|
||||||
|
out += param_data
|
||||||
|
out += ") {\n"
|
||||||
|
space += " "
|
||||||
|
out += space + 'return m_srv.call("' + self.name + '"'
|
||||||
|
for elem in self.parameters:
|
||||||
|
out += ", "
|
||||||
|
out += "_" + elem["name"]
|
||||||
|
out += ');\n'
|
||||||
|
out += "}\n"
|
||||||
|
space = space[:-1]
|
||||||
|
return out;
|
||||||
|
|
||||||
|
class ServiceDefinition:
|
||||||
|
def __init__(self):
|
||||||
|
self.name = [""];
|
||||||
|
self.brief = "";
|
||||||
|
self.version = "";
|
||||||
|
self.api = "";
|
||||||
|
self.authors = []
|
||||||
|
self.functions = []
|
||||||
|
|
||||||
|
def set_name(self, value):
|
||||||
|
self.name = value
|
||||||
|
# TODO : Check range ...
|
||||||
|
self.name[-1] = self.name[-1].title()
|
||||||
|
|
||||||
|
def set_brief(self, value):
|
||||||
|
self.brief = remove_start_stop_spacer(value)
|
||||||
|
|
||||||
|
def set_version(self, value):
|
||||||
|
self.version = remove_start_stop_spacer(value)
|
||||||
|
|
||||||
|
def set_api(self, value):
|
||||||
|
self.api = remove_start_stop_spacer(value)
|
||||||
|
|
||||||
|
def add_author(self, value):
|
||||||
|
self.authors.append(remove_start_stop_spacer(value))
|
||||||
|
|
||||||
|
def add_function(self, value):
|
||||||
|
self.functions.append(value)
|
||||||
|
|
||||||
|
def display(self):
|
||||||
|
debug.info("Display service definition : ")
|
||||||
|
debug.info(" name: " + str(self.name))
|
||||||
|
debug.info(" brief: '" + str(self.brief) + "'")
|
||||||
|
debug.info(" version: '" + str(self.version) + "'")
|
||||||
|
debug.info(" api: '" + str(self.api) + "'")
|
||||||
|
debug.info(" authors: '" + str(self.authors) + "'")
|
||||||
|
debug.info(" functions: ")
|
||||||
|
for elem in self.functions:
|
||||||
|
elem.display();
|
||||||
|
|
||||||
|
def generate_header(self):
|
||||||
|
filename = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
filename += elem + "/"
|
||||||
|
filename += self.name[-1] + ".hpp";
|
||||||
|
out = ""
|
||||||
|
# TODO: add global header:
|
||||||
|
out += "/** @file\n"
|
||||||
|
out += " * @note Generated file !!! Do not modify !!!\n"
|
||||||
|
out += " * @license APACHE-2\n"
|
||||||
|
out += " * @copyright none\n"
|
||||||
|
out += " */\n"
|
||||||
|
out += "#pragma once\n"
|
||||||
|
out += "\n"
|
||||||
|
out += "#include <etk/types.hpp>\n"
|
||||||
|
out += "#include <string>\n"
|
||||||
|
out += "#include <vector>\n"
|
||||||
|
out += "\n"
|
||||||
|
space = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
out += space + "namespace " + elem + " {\n"
|
||||||
|
space += " "
|
||||||
|
|
||||||
|
out += space + " /**\n"
|
||||||
|
if self.brief != "":
|
||||||
|
out += space + " * @brief " + self.brief + " \n"
|
||||||
|
if self.version != "":
|
||||||
|
out += space + " * version:" + self.version + "\n"
|
||||||
|
if self.api != "":
|
||||||
|
out += space + " * api:" + self.api + "\n"
|
||||||
|
for elem in self.authors:
|
||||||
|
out += space + " * authors:" + elem + "\n"
|
||||||
|
out += space + " */\n"
|
||||||
|
out += space + "class " + self.name[-1] + " {\n"
|
||||||
|
space += " "
|
||||||
|
out += space + "public:\n"
|
||||||
|
space += " "
|
||||||
|
out += space + "/**\n"
|
||||||
|
out += space + " * @brief Generic virtual destructor\n"
|
||||||
|
out += space + " */\n"
|
||||||
|
out += space + "virtual ~" + self.name[-1] + "() = default;\n"
|
||||||
|
|
||||||
|
for elem in self.functions:
|
||||||
|
out += elem.generate_cpp(space)
|
||||||
|
|
||||||
|
space = space[:-2]
|
||||||
|
out += space + "};\n"
|
||||||
|
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
space = space[:-1]
|
||||||
|
out += space + "}\n"
|
||||||
|
return [filename, out]
|
||||||
|
|
||||||
|
def generate_register_header(self):
|
||||||
|
filename = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
filename += elem + "/"
|
||||||
|
filename += "register" + self.name[-1] + ".hpp";
|
||||||
|
|
||||||
|
class_name = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
class_name += "" + elem + "::"
|
||||||
|
class_name += self.name[-1];
|
||||||
|
|
||||||
|
out = ""
|
||||||
|
out += "/** @file\n"
|
||||||
|
out += " * @note Generated file !!! Do not modify !!!\n"
|
||||||
|
out += " * @license APACHE-2\n"
|
||||||
|
out += " * @copyright none\n"
|
||||||
|
out += " */\n"
|
||||||
|
out += "#pragma once\n"
|
||||||
|
out += "\n"
|
||||||
|
out += "#include <etk/types.hpp>\n"
|
||||||
|
out += "#include <zeus/Service.hpp>\n"
|
||||||
|
out += "#include <" + class_name.replace("::","/") + ".hpp>\n"
|
||||||
|
out += "#include <string>\n"
|
||||||
|
out += "#include <vector>\n"
|
||||||
|
out += "\n"
|
||||||
|
space = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
out += space + "namespace " + elem + " {\n"
|
||||||
|
space += " "
|
||||||
|
|
||||||
|
out += space + "void register" + self.name[-1] + "(zeus::ServiceType<" + class_name + ">& _serviceInterface);\n"
|
||||||
|
out += space + "template<class ZEUS_TYPE_SERVICE>\n"
|
||||||
|
out += space + "zeus::Service* create" + self.name[-1] + "(std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(ememory::SharedPtr<ClientProperty>)> _factory) {\n"
|
||||||
|
out += space + " zeus::ServiceType<zeus::service::User>* tmp = nullptr;\n"
|
||||||
|
out += space + " tmp = new zeus::ServiceType<zeus::service::User>(_factory);\n"
|
||||||
|
out += space + " zeus::service::registerUser(*tmp);\n"
|
||||||
|
out += space + " return tmp;\n"
|
||||||
|
out += space + "}\n"
|
||||||
|
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
space = space[:-1]
|
||||||
|
out += space + "}\n"
|
||||||
|
out += space + "\n"
|
||||||
|
|
||||||
|
out += space + "#define ZEUS_SERVICE_USER_DECLARE_DEFAULT(type) \\\n"
|
||||||
|
out += space + " ETK_EXPORT_API zeus::Service* SERVICE_IO_instanciate() { \\\n"
|
||||||
|
out += space + " return zeus::service::create" + self.name[-1] + "<type>([](ememory::SharedPtr<zeus::ClientProperty> _client){ \\\n"
|
||||||
|
out += space + " return ememory::makeShared<type>(_client); \\\n"
|
||||||
|
out += space + " }); \\\n"
|
||||||
|
out += space + " }\n"
|
||||||
|
out += space + "\n"
|
||||||
|
out += space + "#define ZEUS_SERVICE_USER_DECLARE(type, factory) \\\n"
|
||||||
|
out += space + " ETK_EXPORT_API zeus::Service* SERVICE_IO_instanciate() { \\\n"
|
||||||
|
out += space + " return zeus::service::create" + self.name[-1] + "<type>(factory); \\\n"
|
||||||
|
out += space + " }\n"
|
||||||
|
|
||||||
|
return [filename, out]
|
||||||
|
|
||||||
|
def generate_register_code(self):
|
||||||
|
filename = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
filename += elem + "/"
|
||||||
|
filename += "register" + self.name[-1] + ".cpp";
|
||||||
|
|
||||||
|
class_name = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
class_name += "" + elem + "::"
|
||||||
|
class_name += self.name[-1];
|
||||||
|
|
||||||
|
out = ""
|
||||||
|
out += "/** @file\n"
|
||||||
|
out += " * @note Generated file !!! Do not modify !!!\n"
|
||||||
|
out += " * @license APACHE-2\n"
|
||||||
|
out += " * @copyright none\n"
|
||||||
|
out += " */\n"
|
||||||
|
out += "\n"
|
||||||
|
out += "#include <" + filename.replace(".cpp", ".hpp") + ">\n"
|
||||||
|
out += "#include <zeus/debug.hpp>\n"
|
||||||
|
out += "\n"
|
||||||
|
space = ""
|
||||||
|
function_name = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
function_name += "" + elem + "::"
|
||||||
|
function_name += "register" + self.name[-1];
|
||||||
|
|
||||||
|
class_name = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
class_name += "" + elem + "::"
|
||||||
|
class_name += self.name[-1];
|
||||||
|
|
||||||
|
out += space + "void " + function_name + "(zeus::ServiceType<" + class_name + ">& _serviceInterface) {\n"
|
||||||
|
space += " "
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
out += space + 'ZEUS_INFO("===========================================================");\n';
|
||||||
|
out += space + 'ZEUS_INFO("== Instanciate service: ' + self.name[-1] + '");\n';
|
||||||
|
out += space + 'ZEUS_INFO("===========================================================");\n';
|
||||||
|
"""
|
||||||
|
zeus::ServiceType<appl::SystemService> _serviceInterface([](ememory::SharedPtr<zeus::ClientProperty> _client){
|
||||||
|
return ememory::makeShared<appl::SystemService>(_client);
|
||||||
|
});
|
||||||
|
if (_ip != "") {
|
||||||
|
_serviceInterface.propertyIp.set(_ip);
|
||||||
|
}
|
||||||
|
if (_port != 0) {
|
||||||
|
_serviceInterface.propertyPort.set(_port);
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
out += space + '_serviceInterface.propertyNameService.set("' + self.name[-1].lower() + '");\n'
|
||||||
|
if self.brief != "":
|
||||||
|
out += space + '_serviceInterface.setDescription("' + self.brief + '");\n';
|
||||||
|
if self.version != "":
|
||||||
|
out += space + '_serviceInterface.setVersion("' + self.version + '");\n';
|
||||||
|
if self.api != "":
|
||||||
|
out += space + '_serviceInterface.setType("' + self.api + '");\n';
|
||||||
|
for elem in self.authors:
|
||||||
|
out += space + '_serviceInterface.addAuthor("' + elem.split("<")[0] + '", "' + elem.split("<")[1].replace(">","") + '");\n';
|
||||||
|
if len(self.functions) != 0:
|
||||||
|
out += space + "zeus::AbstractFunction* func = nullptr;\n"
|
||||||
|
for elem in self.functions:
|
||||||
|
out += space + 'func = _serviceInterface.advertise("' + elem.name + '", &' + class_name + '::' + elem.name + ');\n'
|
||||||
|
out += space + 'if (func != nullptr) {\n'
|
||||||
|
space += " "
|
||||||
|
if elem.brief != "":
|
||||||
|
out += space + 'func->setDescription("' + elem.name + '");\n'
|
||||||
|
for elem_p in elem.parameters:
|
||||||
|
if elem_p["name"] == "" \
|
||||||
|
and elem_p["brief"] == "":
|
||||||
|
continue
|
||||||
|
out += space + 'func->addParam("'
|
||||||
|
if elem_p["name"] != "":
|
||||||
|
out += elem_p["name"]
|
||||||
|
out += '", "'
|
||||||
|
if elem_p["brief"] != "":
|
||||||
|
out += elem_p["brief"]
|
||||||
|
out += '");\n'
|
||||||
|
if elem.return_brief != "":
|
||||||
|
out += space + 'func->setReturn("' + elem.return_brief + '");\n'
|
||||||
|
space = space[:-1]
|
||||||
|
out += space + '}\n'
|
||||||
|
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"
|
||||||
|
return [filename, out]
|
||||||
|
|
||||||
|
def generate_proxy_header(self):
|
||||||
|
filename = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
filename += elem + "/"
|
||||||
|
filename += "Proxy" + self.name[-1] + ".hpp";
|
||||||
|
out = ""
|
||||||
|
|
||||||
|
out += "/** @file\n"
|
||||||
|
out += " * @note Generated file !!! Do not modify !!!\n"
|
||||||
|
out += " * @license APACHE-2\n"
|
||||||
|
out += " * @copyright none\n"
|
||||||
|
out += " */\n"
|
||||||
|
out += "#pragma once\n"
|
||||||
|
out += "\n"
|
||||||
|
out += "#include <zeus/ServiceRemote.hpp>\n"
|
||||||
|
out += "#include <string>\n"
|
||||||
|
out += "#include <vector>\n"
|
||||||
|
out += "\n"
|
||||||
|
space = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
out += space + "namespace " + elem + " {\n"
|
||||||
|
space += " "
|
||||||
|
|
||||||
|
out += space + " /**\n"
|
||||||
|
if self.brief != "":
|
||||||
|
out += space + " * @brief " + self.brief + " \n"
|
||||||
|
if self.version != "":
|
||||||
|
out += space + " * version:" + self.version + "\n"
|
||||||
|
if self.api != "":
|
||||||
|
out += space + " * api:" + self.api + "\n"
|
||||||
|
for elem in self.authors:
|
||||||
|
out += space + " * authors:" + elem + "\n"
|
||||||
|
out += space + " */\n"
|
||||||
|
#out += space + "class Proxy" + self.name[-1] + " : public " + self.name[-1] + " {\n"
|
||||||
|
out += space + "class Proxy" + self.name[-1] + " {\n"
|
||||||
|
space += " "
|
||||||
|
out += space + "protected:\n"
|
||||||
|
out += space + " zeus::ServiceRemote m_srv; //!< Service instance handle\n"
|
||||||
|
out += space + "public:\n"
|
||||||
|
space += " "
|
||||||
|
"""
|
||||||
|
out += space + "/**\n"
|
||||||
|
out += space + " * @brief Generic virtual destructor\n"
|
||||||
|
out += space + " */\n"
|
||||||
|
out += space + "virtual ~" + self.name[-1] + "() = default;\n"
|
||||||
|
"""
|
||||||
|
for elem in self.functions:
|
||||||
|
out += elem.generate_hpp_proxy(space)
|
||||||
|
|
||||||
|
space = space[:-2]
|
||||||
|
out += space + "};\n"
|
||||||
|
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
space = space[:-1]
|
||||||
|
out += space + "}\n"
|
||||||
|
return [filename, out]
|
||||||
|
|
||||||
|
def generate_proxy_code(self):
|
||||||
|
filename = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
filename += elem + "/"
|
||||||
|
filename += "Proxy" + self.name[-1] + ".cpp";
|
||||||
|
out = ""
|
||||||
|
|
||||||
|
class_name = ""
|
||||||
|
for elem in self.name[:-1]:
|
||||||
|
class_name += "" + elem + "::"
|
||||||
|
class_name += "Proxy" + self.name[-1];
|
||||||
|
|
||||||
|
out += "/** @file\n"
|
||||||
|
out += " * @note Generated file !!! Do not modify !!!\n"
|
||||||
|
out += " * @license APACHE-2\n"
|
||||||
|
out += " * @copyright none\n"
|
||||||
|
out += " */\n"
|
||||||
|
out += "\n"
|
||||||
|
out += "#include <" + filename.replace(".cpp",".hpp") + ">\n"
|
||||||
|
out += "\n"
|
||||||
|
|
||||||
|
for elem in self.functions:
|
||||||
|
out += elem.generate_cpp_proxy("", class_name)
|
||||||
|
return [filename, out]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def tool_generate_idl(target, module, data):
|
||||||
|
debug.debug("Parsing .zeus.idl [start] " + str(data))
|
||||||
|
name_file = os.path.basename(data)
|
||||||
if len(name_file) < 9 \
|
if len(name_file) < 9 \
|
||||||
and name_file[-9:] != ".zeus.idl":
|
and name_file[-9:] != ".zeus.idl":
|
||||||
debug.error("IDL must have an extention ended with '.zeus.idl' and not with '" + name_file[-9:] + "'")
|
debug.error("IDL must have an extention ended with '.zeus.idl' and not with '" + name_file[-9:] + "'")
|
||||||
|
|
||||||
# TODO : Get from filename the namespace and the service name
|
service_def = ServiceDefinition()
|
||||||
service_base = name_file[:-9].split("-")
|
service_def.set_name(name_file[:-9].split("-"))
|
||||||
data = tools.file_read_data(os.path.join(os.path.dirname(__file__), path))
|
data = tools.file_read_data(os.path.join(module.get_origin_path(), data))
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
debug.error("Can not parse zeus.idl ==> no data in the file, or no file.")
|
debug.error("Can not parse zeus.idl ==> no data in the file, or no file.")
|
||||||
return;
|
return;
|
||||||
@ -173,18 +578,17 @@ def parse_service_idl(path):
|
|||||||
id_line = 0
|
id_line = 0
|
||||||
multi_comment = False
|
multi_comment = False
|
||||||
current_def = FunctionDefinition()
|
current_def = FunctionDefinition()
|
||||||
list_all_function = []
|
|
||||||
for line in data.split("\n"):
|
for line in data.split("\n"):
|
||||||
id_line += 1;
|
id_line += 1;
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
# empty line
|
# empty line
|
||||||
debug.info("find line " + str(id_line) + " ==> empty line")
|
debug.extreme_verbose("find line " + str(id_line) + " ==> empty line")
|
||||||
continue
|
continue
|
||||||
if multi_comment == False:
|
if multi_comment == False:
|
||||||
if len(line) >= 2 \
|
if len(line) >= 2 \
|
||||||
and line[:2] == "/*":
|
and line[:2] == "/*":
|
||||||
# Comment multi-line
|
# Comment multi-line
|
||||||
debug.info("find line " + str(id_line) + " ==> comment multi-line [START]")
|
debug.extreme_verbose("find line " + str(id_line) + " ==> comment multi-line [START]")
|
||||||
if len(line) > 2:
|
if len(line) > 2:
|
||||||
debug.error("line " + str(id_line) + " ==> /* must be alone in the line (no text after)")
|
debug.error("line " + str(id_line) + " ==> /* must be alone in the line (no text after)")
|
||||||
multi_comment = True
|
multi_comment = True
|
||||||
@ -196,7 +600,7 @@ def parse_service_idl(path):
|
|||||||
if len(line) >= 2 \
|
if len(line) >= 2 \
|
||||||
and line[:2] == "*/":
|
and line[:2] == "*/":
|
||||||
# Comment multi-line
|
# Comment multi-line
|
||||||
debug.info("find line " + str(id_line) + " ==> comment multi-line [STOP]")
|
debug.extreme_verbose("find line " + str(id_line) + " ==> comment multi-line [STOP]")
|
||||||
multi_comment = False
|
multi_comment = False
|
||||||
if len(line) > 2:
|
if len(line) > 2:
|
||||||
debug.error("line " + str(id_line) + " ==> find '/*' must be alone in the line (no text after)")
|
debug.error("line " + str(id_line) + " ==> find '/*' must be alone in the line (no text after)")
|
||||||
@ -205,12 +609,12 @@ def parse_service_idl(path):
|
|||||||
if len(line) >= 2 \
|
if len(line) >= 2 \
|
||||||
and line[:2] == "//":
|
and line[:2] == "//":
|
||||||
# Comment line
|
# Comment line
|
||||||
debug.info("find line " + str(id_line) + " ==> comment line")
|
debug.extreme_verbose("find line " + str(id_line) + " ==> comment line")
|
||||||
continue
|
continue
|
||||||
if len(line) >= 1 \
|
if len(line) >= 1 \
|
||||||
and line[0] == "#":
|
and line[0] == "#":
|
||||||
# Documentation line
|
# Documentation line
|
||||||
debug.info("find line " + str(id_line) + " ==> documentation line")
|
debug.extreme_verbose("find line " + str(id_line) + " ==> documentation line")
|
||||||
#get keyword:
|
#get keyword:
|
||||||
list_elems = line.split(":")
|
list_elems = line.split(":")
|
||||||
if len(list_elems) < 1:
|
if len(list_elems) < 1:
|
||||||
@ -218,34 +622,34 @@ def parse_service_idl(path):
|
|||||||
doc_keyword = list_elems[0] + ":"
|
doc_keyword = list_elems[0] + ":"
|
||||||
doc_data = line[len(doc_keyword):]
|
doc_data = line[len(doc_keyword):]
|
||||||
if doc_keyword == "#brief:":
|
if doc_keyword == "#brief:":
|
||||||
debug.info(" BRIEF: '" + doc_data + "'")
|
debug.extreme_verbose(" BRIEF: '" + doc_data + "'")
|
||||||
current_def = FunctionDefinition()
|
current_def = FunctionDefinition()
|
||||||
current_def.set_brief(doc_data)
|
current_def.set_brief(doc_data)
|
||||||
elif doc_keyword == "#param:":
|
elif doc_keyword == "#param:":
|
||||||
debug.info(" PARAMETER: '" + doc_data + "'")
|
debug.extreme_verbose(" PARAMETER: '" + doc_data + "'")
|
||||||
# TODO : Do it better ...
|
# TODO : Do it better ...
|
||||||
current_def.add_param_comment(doc_data.split(":")[0], doc_data.split(":")[1])
|
current_def.add_param_comment(doc_data.split(":")[0], doc_data.split(":")[1])
|
||||||
elif doc_keyword == "#return:":
|
elif doc_keyword == "#return:":
|
||||||
debug.info(" RETURN: '" + doc_data + "'")
|
debug.extreme_verbose(" RETURN: '" + doc_data + "'")
|
||||||
current_def.set_return_comment(doc_data)
|
current_def.set_return_comment(doc_data)
|
||||||
elif doc_keyword == "#srv-brief:":
|
elif doc_keyword == "#srv-brief:":
|
||||||
debug.info(" SRV-BRIEF: '" + doc_data + "'")
|
debug.extreme_verbose(" SRV-BRIEF: '" + doc_data + "'")
|
||||||
# TODO: ...
|
service_def.set_brief(doc_data)
|
||||||
elif doc_keyword == "#srv-version:":
|
elif doc_keyword == "#srv-version:":
|
||||||
debug.info(" SRV-VERSION: '" + doc_data + "'")
|
debug.extreme_verbose(" SRV-VERSION: '" + doc_data + "'")
|
||||||
# TODO: ...
|
service_def.set_version(doc_data)
|
||||||
elif doc_keyword == "#srv-type-api:":
|
elif doc_keyword == "#srv-type:":
|
||||||
debug.info(" SRV-TYPE-API: '" + doc_data + "'")
|
debug.extreme_verbose(" SRV-TYPE: '" + doc_data + "'")
|
||||||
# TODO: ...
|
service_def.set_api(doc_data)
|
||||||
elif doc_keyword == "#srv-author:":
|
elif doc_keyword == "#srv-author:":
|
||||||
debug.info(" SRV-AUTHOR: '" + doc_data + "'")
|
debug.extreme_verbose(" SRV-AUTHOR: '" + doc_data + "'")
|
||||||
# TODO: ...
|
service_def.add_author(doc_data)
|
||||||
else:
|
else:
|
||||||
debug.warning("line " + str(id_line) + " ==> Unknow: keyword: '" + doc_keyword + "'")
|
debug.warning("line " + str(id_line) + " ==> Unknow: keyword: '" + doc_keyword + "'")
|
||||||
debug.error(" support only: '#brief:' '#param:' '#return:' '#srv-brief:' '#srv-version:' '#srv-type-api:' '#srv-author:'")
|
debug.error(" support only: '#brief:' '#param:' '#return:' '#srv-brief:' '#srv-version:' '#srv-type:' '#srv-author:'")
|
||||||
continue
|
continue
|
||||||
debug.info("Need to parse the fucntion line:")
|
debug.extreme_verbose("Need to parse the fucntion line:")
|
||||||
debug.info(" '" + line + "'")
|
debug.extreme_verbose(" '" + line + "'")
|
||||||
if True:
|
if True:
|
||||||
if line[-1] != ")":
|
if line[-1] != ")":
|
||||||
debug.error("line " + str(id_line) + " Can not parse function the line dos not ended by a ')'")
|
debug.error("line " + str(id_line) + " Can not parse function the line dos not ended by a ')'")
|
||||||
@ -267,65 +671,72 @@ def parse_service_idl(path):
|
|||||||
for elem in argument_list:
|
for elem in argument_list:
|
||||||
if elem not in get_list_type():
|
if elem not in get_list_type():
|
||||||
debug.error("line " + str(id_line) + " fucntion argument type unknow : '" + elem + "' not in " + str(get_list_type()))
|
debug.error("line " + str(id_line) + " fucntion argument type unknow : '" + elem + "' not in " + str(get_list_type()))
|
||||||
debug.info(" Parse of function done :")
|
debug.extreme_verbose(" Parse of function done :")
|
||||||
debug.info(" return:" + return_value)
|
debug.extreme_verbose(" return:" + return_value)
|
||||||
debug.info(" name:" + function_name)
|
debug.extreme_verbose(" name:" + function_name)
|
||||||
debug.info(" arguments:" + str(argument_list))
|
debug.extreme_verbose(" arguments:" + str(argument_list))
|
||||||
current_def.set_function_name(function_name)
|
current_def.set_function_name(function_name)
|
||||||
current_def.set_return_type(return_value)
|
current_def.set_return_type(return_value)
|
||||||
for elem in argument_list:
|
for elem in argument_list:
|
||||||
current_def.add_parameter_type(elem)
|
current_def.add_parameter_type(elem)
|
||||||
list_all_function.append(current_def)
|
service_def.add_function(current_def)
|
||||||
current_def = FunctionDefinition()
|
current_def = FunctionDefinition()
|
||||||
if multi_comment == True:
|
if multi_comment == True:
|
||||||
debug.error("reach end of file and missing end of multi-line comment */")
|
debug.error("reach end of file and missing end of multi-line comment */")
|
||||||
debug.warning("Parsing Done")
|
debug.verbose("Parsing idl Done (no error ...)")
|
||||||
for elem in list_all_function:
|
|
||||||
elem.display();
|
|
||||||
debug.warning("Display Done")
|
|
||||||
cpp_header = ""
|
|
||||||
# TODO: add global header:
|
|
||||||
cpp_header += "/** @file\n"
|
|
||||||
cpp_header += " * @note Generated file !!! Do not modify !!!\n"
|
|
||||||
cpp_header += " */\n"
|
|
||||||
cpp_header += "#pragma once"
|
|
||||||
cpp_header += "\n"
|
|
||||||
space = ""
|
|
||||||
for elem in service_base[:-1]:
|
|
||||||
cpp_header += space + "namespace " + elem + " {\n"
|
|
||||||
space += " "
|
|
||||||
|
|
||||||
cpp_header += space + "class " + service_base[-1] + " {\n"
|
#service_def.display()
|
||||||
space += " "
|
|
||||||
cpp_header += space + "public:\n"
|
|
||||||
space += " "
|
|
||||||
|
|
||||||
for elem in list_all_function:
|
service_header = service_def.generate_header()
|
||||||
cpp_header += elem.generate_cpp(space)
|
register_header = service_def.generate_register_header()
|
||||||
|
register_code = service_def.generate_register_code()
|
||||||
|
proxy_header = service_def.generate_proxy_header()
|
||||||
|
proxy_code = service_def.generate_proxy_code()
|
||||||
|
|
||||||
space = space[:-2]
|
debug.verbose("----------------- " + service_header[0] + " -----------------")
|
||||||
cpp_header += space + "};\n"
|
debug.verbose("\n" + service_header[1])
|
||||||
|
debug.verbose("----------------- " + register_header[0] + " -----------------")
|
||||||
|
debug.verbose("\n" + register_header[1])
|
||||||
|
debug.verbose("----------------- " + register_code[0] + " -----------------")
|
||||||
|
debug.verbose("\n" + register_code[1])
|
||||||
|
debug.verbose("----------------- " + proxy_header[0] + " -----------------")
|
||||||
|
debug.verbose("\n" + proxy_header[1])
|
||||||
|
debug.verbose("----------------- " + proxy_code[0] + " -----------------")
|
||||||
|
debug.verbose("\n" + proxy_code[1])
|
||||||
|
|
||||||
for elem in service_base[:-1]:
|
tmp_path = os.path.join(target.get_build_path_temporary_generate(module.get_name()), "idl_src")
|
||||||
space = space[:-1]
|
module.add_generated_header_file(service_header[1], service_header[0], install_element=True)
|
||||||
cpp_header += space + "}\n"
|
module.add_generated_header_file(register_header[1], register_header[0], install_element=True)
|
||||||
debug.info(cpp_header)
|
|
||||||
debug.warning("Generate C++ Done")
|
|
||||||
|
|
||||||
debug.error("Parsing .zeus.idl [DONE]")
|
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_header_file(proxy_header[1], proxy_header[0], install_element=True)
|
||||||
|
|
||||||
|
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]")
|
||||||
|
|
||||||
def configure(target, my_module):
|
def configure(target, my_module):
|
||||||
my_module.add_path(".")
|
my_module.add_path(".")
|
||||||
my_module.add_depend([
|
my_module.add_depend([
|
||||||
'zeus',
|
'zeus'
|
||||||
'ejson'
|
|
||||||
])
|
])
|
||||||
|
"""
|
||||||
my_module.add_src_file([
|
my_module.add_src_file([
|
||||||
'appl/debug.cpp',
|
'appl/debug.cpp',
|
||||||
'appl/main.cpp'
|
'appl/main.cpp'
|
||||||
])
|
])
|
||||||
|
"""
|
||||||
|
my_module.add_action(tool_generate_idl, data='appl/zeus-service-user.zeus.idl')
|
||||||
|
|
||||||
parse_service_idl('appl/service-user.zeus.idl')
|
#parse_service_idl(my_module, 'appl/zeus-service-user.zeus.idl')
|
||||||
|
|
||||||
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"" + my_module.get_name()[13:] + "\\\"\"")
|
my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"" + my_module.get_name()[13:] + "\\\"\"")
|
||||||
|
|
||||||
|
@ -326,9 +326,10 @@ ETK_EXPORT_API bool SERVICE_IO_execute(std::string _ip, uint16_t _port) {
|
|||||||
serviceInterface.propertyPort.set(_port);
|
serviceInterface.propertyPort.set(_port);
|
||||||
}
|
}
|
||||||
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
serviceInterface.propertyNameService.set(SERVICE_NAME);
|
||||||
serviceInterface.setDescription("Picture Private Interface");
|
serviceInterface.setDescription("Video Private Interface");
|
||||||
serviceInterface.setVersion("0.1.0");
|
serviceInterface.setVersionImplementation("0.1.0");
|
||||||
serviceInterface.setType("PICTURE", 1);
|
serviceInterface.setVersion("1.0");
|
||||||
|
serviceInterface.setType("VIDEO");
|
||||||
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com");
|
||||||
|
|
||||||
serviceInterface.advertise("getAlbums", &appl::VideoService::getAlbums);
|
serviceInterface.advertise("getAlbums", &appl::VideoService::getAlbums);
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include <zeus/FutureBase.hpp>
|
#include <zeus/FutureBase.hpp>
|
||||||
|
|
||||||
|
// TODO : When do a cast of the type on the future ==> do a wait ...
|
||||||
|
|
||||||
namespace zeus {
|
namespace zeus {
|
||||||
/**
|
/**
|
||||||
* @brief future template to cast type in a specific type
|
* @brief future template to cast type in a specific type
|
||||||
|
@ -69,6 +69,14 @@ std::string zeus::RemoteProcessCall::getVersion() {
|
|||||||
return m_version;
|
return m_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void zeus::RemoteProcessCall::setVersionImplementation(const std::string& _desc) {
|
||||||
|
m_versionImplement = _desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string zeus::RemoteProcessCall::getVersionImplementation() {
|
||||||
|
return m_versionImplement;
|
||||||
|
}
|
||||||
|
|
||||||
void zeus::RemoteProcessCall::addAuthor(const std::string& _name, const std::string& _email) {
|
void zeus::RemoteProcessCall::addAuthor(const std::string& _name, const std::string& _email) {
|
||||||
m_authors.push_back(std::make_pair(_name, _email));
|
m_authors.push_back(std::make_pair(_name, _email));
|
||||||
}
|
}
|
||||||
@ -102,8 +110,8 @@ std::string zeus::RemoteProcessCall::getType() {
|
|||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zeus::RemoteProcessCall::setType(const std::string& _type, uint16_t _version) {
|
void zeus::RemoteProcessCall::setType(const std::string& _type) {
|
||||||
m_type = _type + "/" + etk::to_string(_version);
|
m_type = _type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,19 @@ namespace zeus {
|
|||||||
* @return String containing the version (form: 1.0[.x[.y]][-dev]
|
* @return String containing the version (form: 1.0[.x[.y]][-dev]
|
||||||
*/
|
*/
|
||||||
std::string getVersion();
|
std::string getVersion();
|
||||||
|
protected:
|
||||||
|
std::string m_versionImplement; //!< Version implementation of the service
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Set the Version implementation of the service
|
||||||
|
* @param[in] _vers String containing the version (form: 1.0[.x[.y]][-dev]
|
||||||
|
*/
|
||||||
|
void setVersionImplementation(const std::string& _vers);
|
||||||
|
/**
|
||||||
|
* @brief Get the Version implementation of the service
|
||||||
|
* @return String containing the version (form: 1.0[.x[.y]][-dev]
|
||||||
|
*/
|
||||||
|
std::string getVersionImplementation();
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::pair<std::string,std::string>> m_authors;//! List of autors of the module (name, email)
|
std::vector<std::pair<std::string,std::string>> m_authors;//! List of autors of the module (name, email)
|
||||||
public:
|
public:
|
||||||
@ -81,7 +94,7 @@ namespace zeus {
|
|||||||
* @param[in]
|
* @param[in]
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void setType(const std::string& _type, uint16_t _version);
|
void setType(const std::string& _type);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
Loading…
x
Reference in New Issue
Block a user