[DEV] update to the new property methodologie
This commit is contained in:
parent
619604b6c5
commit
697b2a743d
@ -87,56 +87,28 @@ class AttributeDefinition:
|
||||
debug.info(" BRIEF: " + self.brief)
|
||||
debug.info(" " + self.type + " " + self.name + ";")
|
||||
|
||||
def generate_doxy_get(self, space, object):
|
||||
out = ""
|
||||
out += space + "/**\n"
|
||||
out += space + " * @brief Get parameter " + self.brief + "\n"
|
||||
out += space + " * @return Requested parameter\n"
|
||||
out += space + " */\n"
|
||||
return out
|
||||
|
||||
def generate_doxy_set(self, space, object):
|
||||
out = ""
|
||||
out += space + "/**\n"
|
||||
out += space + " * @brief Set parameter " + self.brief + "\n"
|
||||
out += space + " * @param[in] _value New parameter value\n"
|
||||
out += space + " */\n"
|
||||
return out
|
||||
|
||||
def generate_cpp(self, space, object):
|
||||
def generate_cpp(self, space):
|
||||
out = "";
|
||||
out += space[:-1] + "protected:"
|
||||
out += space + convert_type_in_cpp(self.type) + " m_" + self.name + "; //!<" + self.brief + "\n"
|
||||
out += space[:-1] + "public:"
|
||||
out += self.generate_doxy_get(space, object)
|
||||
out += space + "virtual " + convert_type_in_cpp(self.type) + " get" + capital_first(self.name) + "() {\n"
|
||||
out += space + " return m_" + self.name + ";\n"
|
||||
out += space + "eproperty::Value<" + convert_type_in_cpp(self.type) + "> " + self.name + "; //!<" + self.brief + "\n"
|
||||
out += space + "//! Internal interface to call property\n"
|
||||
out += space + "virtual " + convert_type_in_cpp(self.type) + " _internalWrapperProperty_get" + capital_first(self.name) + "() {\n"
|
||||
out += space + " return " + self.name + ".get();\n"
|
||||
out += space + "}\n"
|
||||
out += self.generate_doxy_set(space, object)
|
||||
out += space + "virtual void set" + capital_first(self.name) + "(" + convert_type_in_cpp(self.type) + " _value) {\n"
|
||||
out += space + " m_" + self.name + " = _value;\n"
|
||||
out += space + "//! Internal interface to call property\n"
|
||||
out += space + "virtual void _internalWrapperProperty_set" + capital_first(self.name) + "(" + convert_type_in_cpp(self.type) + " _value) {\n"
|
||||
out += space + " " + self.name + ".set(_value);\n"
|
||||
out += space + "}\n"
|
||||
return out;
|
||||
|
||||
def generate_hpp_proxy(self, space, object):
|
||||
def generate_hpp_proxy(self, space):
|
||||
out = "";
|
||||
out += self.generate_doxy_get(space, object)
|
||||
out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.type) + "> get" + capital_first(self.name) + "();\n"
|
||||
out += self.generate_doxy_set(space, object)
|
||||
out += space + "virtual zeus::Future<void> set" + capital_first(self.name) + "(const " + convert_type_in_cpp(self.type) + "& _value);\n"
|
||||
out += space + "zeus::RemoteProperty<" + convert_type_in_cpp(self.type) + "> " + self.name + "; //!<" + self.brief + "\n"
|
||||
return out;
|
||||
|
||||
def generate_cpp_proxy(self, space, class_name, object):
|
||||
def generate_cpp_proxy(self, space, class_name):
|
||||
out = "";
|
||||
out += space + "zeus::Future<" + convert_type_in_cpp(self.type) + "> " + class_name + "::get" + capital_first(self.name) + "() {\n"
|
||||
out += space + ' return m_obj.call("' + self.name + '.get");\n'
|
||||
out += space + "}\n"
|
||||
out += space + "zeus::Future<void> " + class_name + "::set" + capital_first(self.name) + "(const " + convert_type_in_cpp(self.type) + "& _value) {\n"
|
||||
out += space + ' return m_obj.call("' + self.name + '.set", _value);\n'
|
||||
out += space + "}\n"
|
||||
return out;
|
||||
|
||||
|
||||
class FunctionDefinition:
|
||||
def __init__(self):
|
||||
self.name = "";
|
||||
@ -193,7 +165,7 @@ class FunctionDefinition:
|
||||
debug.info(" " + elem["type"] + " " + elem["name"] + ", # " + elem["brief"])
|
||||
debug.info(" )")
|
||||
|
||||
def generate_doxy(self, space, object):
|
||||
def generate_doxy(self, space):
|
||||
# generate doxygen comment:
|
||||
out = space + "/**\n"
|
||||
if self.brief != "":
|
||||
@ -213,9 +185,9 @@ class FunctionDefinition:
|
||||
out += space + " */\n"
|
||||
return out
|
||||
|
||||
def generate_cpp(self, space, object):
|
||||
def generate_cpp(self, space):
|
||||
out = "";
|
||||
out += self.generate_doxy(space, object)
|
||||
out += self.generate_doxy(space)
|
||||
out += space + "virtual "
|
||||
out += convert_type_in_cpp(self.return_type) + " " + self.name + "("
|
||||
param_data = ""
|
||||
@ -233,9 +205,9 @@ class FunctionDefinition:
|
||||
out += ") = 0;\n"
|
||||
return out;
|
||||
|
||||
def generate_hpp_proxy(self, space, object):
|
||||
def generate_hpp_proxy(self, space):
|
||||
out = "";
|
||||
out += self.generate_doxy(space, object)
|
||||
out += self.generate_doxy(space)
|
||||
out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + self.name + "("
|
||||
param_data = ""
|
||||
id_parameter = 0
|
||||
@ -251,7 +223,7 @@ class FunctionDefinition:
|
||||
out += param_data
|
||||
out += ");\n"
|
||||
return out;
|
||||
def generate_cpp_proxy(self, space, class_name, object):
|
||||
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 = ""
|
||||
@ -330,7 +302,7 @@ class ServiceDefinition:
|
||||
for elem in self.functions:
|
||||
elem.display();
|
||||
|
||||
def generate_header(self, object):
|
||||
def generate_header(self):
|
||||
filename = ""
|
||||
for elem in self.name[:-1]:
|
||||
filename += elem + "/"
|
||||
@ -345,6 +317,7 @@ class ServiceDefinition:
|
||||
out += "#pragma once\n"
|
||||
out += "\n"
|
||||
out += "#include <etk/types.hpp>\n"
|
||||
out += "#include <eproperty/Value.hpp>\n"
|
||||
out += "#include <string>\n"
|
||||
out += "#include <vector>\n"
|
||||
out += "\n"
|
||||
@ -373,10 +346,10 @@ class ServiceDefinition:
|
||||
out += space + "virtual ~" + self.name[-1] + "() = default;\n"
|
||||
|
||||
for elem in self.attributes:
|
||||
out += elem.generate_cpp(space, object)
|
||||
out += elem.generate_cpp(space)
|
||||
|
||||
for elem in self.functions:
|
||||
out += elem.generate_cpp(space, object)
|
||||
out += elem.generate_cpp(space)
|
||||
|
||||
space = space[:-2]
|
||||
out += space + "};\n"
|
||||
@ -386,7 +359,7 @@ class ServiceDefinition:
|
||||
out += space + "}\n"
|
||||
return [filename, out]
|
||||
|
||||
def generate_source(self, object):
|
||||
def generate_source(self):
|
||||
filename = ""
|
||||
for elem in self.name[:-1]:
|
||||
filename += elem + "/"
|
||||
@ -428,10 +401,7 @@ class ServiceDefinition:
|
||||
# now gebnerate the get and set parameter object ...
|
||||
out += "namespace zeus {\n"
|
||||
out += " template<> const zeus::ParamType& createType<ememory::SharedPtr<" + class_name + ">>() {\n"
|
||||
if object == True:
|
||||
out += " static zeus::ParamType type(\"obj:" + class_name + "\", zeus::paramTypeObject, false, false);\n"
|
||||
else:
|
||||
out += " static zeus::ParamType type(\"srv:" + class_name + "\", zeus::paramTypeService, false, false);\n"
|
||||
out += " static zeus::ParamType type(\"obj:" + class_name + "\", zeus::paramTypeObject, false, false);\n"
|
||||
out += " return type;\n"
|
||||
out += " }\n"
|
||||
out += " template<>\n"
|
||||
@ -440,10 +410,7 @@ class ServiceDefinition:
|
||||
"""
|
||||
out += " addType(data, createType<" + class_name + ">());\n"
|
||||
"""
|
||||
if object == True:
|
||||
out += " addTypeObject(data, \"" + class_name + "\");\n"
|
||||
else:
|
||||
out += " addTypeService(data, \"" + class_name + "\");\n"
|
||||
out += " addTypeObject(data, \"" + class_name + "\");\n"
|
||||
out += " int32_t currentOffset = data.size();\n"
|
||||
out += " int32_t startOffset = data.size();\n"
|
||||
out += " data.resize(data.size()+4);\n"
|
||||
@ -453,10 +420,7 @@ class ServiceDefinition:
|
||||
out += " ememory::SharedPtr<zeus::WebServer> _iface2 = _iface;\n"
|
||||
out += " uint16_t id = _iface2->getAddress();\n"
|
||||
out += " uint16_t idObj = _iface2->getNewObjectId();\n"
|
||||
if object == True:
|
||||
out += " ememory::SharedPtr<zeus::ObjectType<" + class_name + ">> obj = ememory::makeShared<zeus::ObjectType<" + class_name + ">>(_iface, idObj, _value);\n"
|
||||
else:
|
||||
out += " ememory::SharedPtr<zeus::ServiceType<" + class_name + ">> obj = ememory::makeShared<zeus::ServiceType<" + class_name + ">>(_iface, idObj, _value);\n"
|
||||
out += " ememory::SharedPtr<zeus::ObjectType<" + class_name + ">> obj = ememory::makeShared<zeus::ObjectType<" + class_name + ">>(_iface, idObj, _value);\n"
|
||||
|
||||
out += " " + namespace + "register" + self.name[-1] + "(*obj);\n"
|
||||
out += " _iface2->addWebObj(obj);\n"
|
||||
@ -472,7 +436,7 @@ class ServiceDefinition:
|
||||
|
||||
return [filename, out]
|
||||
|
||||
def generate_register_header(self, object):
|
||||
def generate_register_header(self):
|
||||
filename = ""
|
||||
for elem in self.name[:-1]:
|
||||
filename += elem + "/"
|
||||
@ -492,10 +456,7 @@ class ServiceDefinition:
|
||||
out += "#pragma once\n"
|
||||
out += "\n"
|
||||
out += "#include <etk/types.hpp>\n"
|
||||
if object == True:
|
||||
out += "#include <zeus/Object.hpp>\n"
|
||||
else:
|
||||
out += "#include <zeus/Service.hpp>\n"
|
||||
out += "#include <zeus/Object.hpp>\n"
|
||||
out += "#include <zeus/Client.hpp>\n"
|
||||
out += "#include <" + class_name.replace("::","/") + ".hpp>\n"
|
||||
out += "#include <string>\n"
|
||||
@ -513,35 +474,25 @@ class ServiceDefinition:
|
||||
MACRO_BASE_NAME += elem.upper() + "_"
|
||||
|
||||
out += space + "\n"
|
||||
if object == True:
|
||||
out += space + "void register" + self.name[-1] + "(zeus::ObjectType<" + class_name + ">& _interface);\n"
|
||||
else:
|
||||
out += space + "void register" + self.name[-1] + "(zeus::ServiceType<" + class_name + ">& _interface);\n"
|
||||
out += space + "void register" + self.name[-1] + "(zeus::ObjectType<" + class_name + ">& _interface);\n"
|
||||
out += space + "\n"
|
||||
for elem in self.name[:-1]:
|
||||
space = space[:-1]
|
||||
out += space + "}\n"
|
||||
out += space + "\n"
|
||||
if object == False:
|
||||
out += space + "#define " + MACRO_BASE_NAME + "DECLARE(type) \\\n"
|
||||
out += space + " ETK_EXPORT_API void SERVICE_IO_instanciate(uint32_t _transactionId, ememory::SharedPtr<zeus::WebServer>& _iface, uint32_t _destination) { \\\n"
|
||||
out += space + " ememory::SharedPtr<type> tmp; \\\n"
|
||||
out += space + " tmp = ememory::makeShared<type>(_destination>>16); \\\n"
|
||||
out += space + " ememory::SharedPtr<" + class_name + "> tmp2 = tmp; \\\n"
|
||||
out += space + " _iface->answerValue(_transactionId, uint32_t(_iface->getAddress())<<16, _destination, tmp2); \\\n"
|
||||
out += space + " }\n"
|
||||
out += space + "\n"
|
||||
"""
|
||||
out += space + "#define " + MACRO_BASE_NAME + "DECLARE_FACTORY(type, factory) \\\n"
|
||||
out += space + " ETK_EXPORT_API zeus::Service* SERVICE_IO_instanciate() { \\\n"
|
||||
out += space + " return " + namespace + "create" + self.name[-1] + "<type>(factory); \\\n"
|
||||
out += space + " }\n"
|
||||
"""
|
||||
out += space + "#define " + MACRO_BASE_NAME + "DECLARE(type) \\\n"
|
||||
out += space + " ETK_EXPORT_API void SERVICE_IO_instanciate(uint32_t _transactionId, ememory::SharedPtr<zeus::WebServer>& _iface, uint32_t _destination) { \\\n"
|
||||
out += space + " ememory::SharedPtr<type> tmp; \\\n"
|
||||
out += space + " tmp = ememory::makeShared<type>(_destination>>16); \\\n"
|
||||
out += space + " ememory::SharedPtr<" + class_name + "> tmp2 = tmp; \\\n"
|
||||
out += space + " _iface->answerValue(_transactionId, uint32_t(_iface->getAddress())<<16, _destination, tmp2); \\\n"
|
||||
out += space + " }\n"
|
||||
out += space + "\n"
|
||||
|
||||
|
||||
return [filename, out]
|
||||
|
||||
def generate_register_code(self, object):
|
||||
def generate_register_code(self):
|
||||
filename = ""
|
||||
for elem in self.name[:-1]:
|
||||
filename += elem + "/"
|
||||
@ -572,10 +523,7 @@ class ServiceDefinition:
|
||||
for elem in self.name[:-1]:
|
||||
class_name += "" + elem + "::"
|
||||
class_name += self.name[-1];
|
||||
if object == True:
|
||||
out += space + "void " + function_name + "(zeus::ObjectType<" + class_name + ">& _interface) {\n"
|
||||
else:
|
||||
out += space + "void " + function_name + "(zeus::ServiceType<" + class_name + ">& _interface) {\n"
|
||||
out += space + "void " + function_name + "(zeus::ObjectType<" + class_name + ">& _interface) {\n"
|
||||
|
||||
space += " "
|
||||
|
||||
@ -595,12 +543,12 @@ class ServiceDefinition:
|
||||
or len(self.attributes) != 0:
|
||||
out += space + "zeus::AbstractFunction* func = nullptr;\n"
|
||||
for elem in self.attributes:
|
||||
out += space + 'func = _interface.advertise("' + elem.name + '.set", &' + class_name + '::set' + capital_first(elem.name) + ');\n'
|
||||
out += space + 'func = _interface.advertise("' + elem.name + '.set", &' + class_name + '::_internalWrapperProperty_set' + capital_first(elem.name) + ');\n'
|
||||
out += space + 'if (func != nullptr) {\n'
|
||||
if elem.brief != "":
|
||||
out += space + ' func->setDescription("Set parameter ' + elem.brief + '");\n'
|
||||
out += space + '}\n'
|
||||
out += space + 'func = _interface.advertise("' + elem.name + '.get", &' + class_name + '::get' + capital_first(elem.name) + ');\n'
|
||||
out += space + 'func = _interface.advertise("' + elem.name + '.get", &' + class_name + '::_internalWrapperProperty_get' + capital_first(elem.name) + ');\n'
|
||||
out += space + 'if (func != nullptr) {\n'
|
||||
if elem.brief != "":
|
||||
out += space + ' func->setDescription("Get parameter ' + elem.brief + '");\n'
|
||||
@ -634,7 +582,7 @@ class ServiceDefinition:
|
||||
out += "\n"
|
||||
return [filename, out]
|
||||
|
||||
def generate_proxy_header(self, object):
|
||||
def generate_proxy_header(self):
|
||||
filename = ""
|
||||
for elem in self.name[:-1]:
|
||||
filename += elem + "/"
|
||||
@ -648,8 +596,9 @@ class ServiceDefinition:
|
||||
out += " */\n"
|
||||
out += "#pragma once\n"
|
||||
out += "\n"
|
||||
out += "#include <zeus/ServiceRemote.hpp>\n"
|
||||
out += "#include <zeus/ObjectRemote.hpp>\n"
|
||||
out += "#include <zeus/BaseProxy.hpp>\n"
|
||||
out += "#include <zeus/RemoteProperty.hpp>\n"
|
||||
out += "#include <string>\n"
|
||||
out += "#include <vector>\n"
|
||||
out += "\n"
|
||||
@ -672,14 +621,29 @@ class ServiceDefinition:
|
||||
out += space + "class Proxy" + self.name[-1] + " :public zeus::BaseProxy {\n"
|
||||
space += " "
|
||||
out += space + "public:\n"
|
||||
out += space + " const Proxy" + self.name[-1] + "& operator= (const zeus::ServiceRemote& _srv) {\n"
|
||||
out += space + " const Proxy" + self.name[-1] + "& operator= (const zeus::ObjectRemote& _srv) {\n"
|
||||
out += space + " m_obj = _srv;\n"
|
||||
out += space + " return *this;\n"
|
||||
out += space + " }\n"
|
||||
out += space + " ~Proxy" + self.name[-1] + "() = default;\n"
|
||||
out += space + " Proxy" + self.name[-1] + "() = default;\n"
|
||||
out += space + " Proxy" + self.name[-1] + "(const zeus::ServiceRemote& _srv) :\n"
|
||||
out += space + " zeus::BaseProxy(_srv) {\n"
|
||||
out += space + " Proxy" + self.name[-1] + "()"
|
||||
if len(self.attributes) != 0:
|
||||
out += ": \n"
|
||||
first = True
|
||||
for elem in self.attributes:
|
||||
if first == False:
|
||||
out += ",\n"
|
||||
out += space + " " + elem.name + "(m_obj, \"" + elem.name + "\")"
|
||||
first = False
|
||||
out += " {}\n"
|
||||
|
||||
out += space + " Proxy" + self.name[-1] + "(const zeus::ObjectRemote& _srv) :\n"
|
||||
out += space + " zeus::BaseProxy(_srv)"
|
||||
for elem in self.attributes:
|
||||
out += ",\n"
|
||||
out += space + " " + elem.name + "(m_obj, \"" + elem.name + "\")"
|
||||
first = False
|
||||
out += " {\n"
|
||||
out += space + " \n"
|
||||
out += space + " }\n"
|
||||
"""
|
||||
@ -696,9 +660,9 @@ class ServiceDefinition:
|
||||
out += space + "virtual ~" + self.name[-1] + "() = default;\n"
|
||||
"""
|
||||
for elem in self.attributes:
|
||||
out += elem.generate_hpp_proxy(space, object)
|
||||
out += elem.generate_hpp_proxy(space)
|
||||
for elem in self.functions:
|
||||
out += elem.generate_hpp_proxy(space, object)
|
||||
out += elem.generate_hpp_proxy(space)
|
||||
|
||||
space = space[:-2]
|
||||
out += space + "};\n"
|
||||
@ -708,7 +672,7 @@ class ServiceDefinition:
|
||||
out += space + "}\n"
|
||||
return [filename, out]
|
||||
|
||||
def generate_proxy_code(self, object):
|
||||
def generate_proxy_code(self):
|
||||
filename = ""
|
||||
for elem in self.name[:-1]:
|
||||
filename += elem + "/"
|
||||
@ -733,10 +697,10 @@ class ServiceDefinition:
|
||||
out += "\n"
|
||||
|
||||
for elem in self.attributes:
|
||||
out += elem.generate_cpp_proxy("", proxy_class_name, object)
|
||||
out += elem.generate_cpp_proxy("", proxy_class_name)
|
||||
|
||||
for elem in self.functions:
|
||||
out += elem.generate_cpp_proxy("", proxy_class_name, object)
|
||||
out += elem.generate_cpp_proxy("", proxy_class_name)
|
||||
|
||||
return [filename, out]
|
||||
|
||||
@ -903,12 +867,12 @@ def tool_generate_idl(target, module, data_option):
|
||||
|
||||
#service_def.display()
|
||||
|
||||
service_header = service_def.generate_header(data_option["type"] == "object")
|
||||
service_source = service_def.generate_source(data_option["type"] == "object")
|
||||
register_header = service_def.generate_register_header(data_option["type"] == "object")
|
||||
register_code = service_def.generate_register_code(data_option["type"] == "object")
|
||||
proxy_header = service_def.generate_proxy_header(data_option["type"] == "object")
|
||||
proxy_code = service_def.generate_proxy_code(data_option["type"] == "object")
|
||||
service_header = service_def.generate_header()
|
||||
service_source = service_def.generate_source()
|
||||
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()
|
||||
|
||||
debug.verbose("----------------- " + service_header[0] + " -----------------")
|
||||
debug.verbose("\n" + service_header[1])
|
||||
@ -933,10 +897,6 @@ def tool_generate_idl(target, module, data_option):
|
||||
|
||||
debug.debug("Parsing .zeus.idl [DONE]")
|
||||
|
||||
|
||||
def parse_service_idl(module, idl_path):
|
||||
module.add_action(tool_generate_idl, data={"path":idl_path, "type":"service"})
|
||||
|
||||
def parse_object_idl(module, idl_path):
|
||||
module.add_action(tool_generate_idl, data={"path":idl_path, "type":"object"})
|
||||
|
||||
|
@ -55,13 +55,13 @@ def configure(target, my_module):
|
||||
'zeus/ParamType.cpp',
|
||||
'zeus/Client.cpp',
|
||||
'zeus/Object.cpp',
|
||||
'zeus/ObjectRemote.cpp',
|
||||
'zeus/RemoteProcessCall.cpp',
|
||||
'zeus/Service.cpp',
|
||||
'zeus/ServiceRemote.cpp',
|
||||
'zeus/WebServer.cpp',
|
||||
'zeus/mineType.cpp',
|
||||
'zeus/BaseProxy.cpp',
|
||||
'zeus/SystemProxy.cpp',
|
||||
'zeus/RemoteProperty.cpp',
|
||||
])
|
||||
my_module.add_header_file([
|
||||
'zeus/zeus.hpp',
|
||||
@ -84,13 +84,13 @@ def configure(target, my_module):
|
||||
'zeus/debug.hpp',
|
||||
'zeus/Client.hpp',
|
||||
'zeus/Object.hpp',
|
||||
'zeus/ObjectRemote.hpp',
|
||||
'zeus/RemoteProcessCall.hpp',
|
||||
'zeus/Service.hpp',
|
||||
'zeus/ServiceRemote.hpp',
|
||||
'zeus/WebObj.hpp',
|
||||
'zeus/WebServer.hpp',
|
||||
'zeus/mineType.hpp',
|
||||
'zeus/BaseProxy.hpp',
|
||||
'zeus/RemoteProperty.hpp',
|
||||
'zeus/SystemProxy.hpp',
|
||||
])
|
||||
if target.config["compilator"] == "clang":
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
#include <zeus/Client.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <dlfcn.h>
|
||||
#include <thread>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <zeus/Service.hpp>
|
||||
#include <zeus/Object.hpp>
|
||||
#include <zeus/Client.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
#include <zeus/Service.hpp>
|
||||
#include <zeus/Object.hpp>
|
||||
#include <zeus/File.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
|
@ -31,7 +31,7 @@ def configure(target, my_module):
|
||||
'zeus'
|
||||
])
|
||||
zeus_macro = macro.load_macro('zeus')
|
||||
zeus_macro.parse_service_idl(my_module, 'appl/zeus-service-picture.srv.zeus.idl')
|
||||
zeus_macro.parse_object_idl(my_module, 'appl/zeus-service-picture.srv.zeus.idl')
|
||||
#module_zeus = target.get_module('zeus')
|
||||
#module_zeus.parse_service_idl(my_module, 'appl/zeus-service-picture.zeus.idl')
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
#include <zeus/Service.hpp>
|
||||
#include <zeus/Object.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
|
||||
|
@ -33,7 +33,7 @@ def configure(target, my_module):
|
||||
])
|
||||
|
||||
zeus_macro = macro.load_macro('zeus')
|
||||
zeus_macro.parse_service_idl(my_module, 'appl/zeus-service-user.srv.zeus.idl')
|
||||
zeus_macro.parse_object_idl(my_module, 'appl/zeus-service-user.srv.zeus.idl')
|
||||
# use object for a first step ...
|
||||
zeus_macro.parse_object_idl(my_module, 'appl/zeus-clientProperty.obj.zeus.idl')
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
#include <zeus/Service.hpp>
|
||||
#include <zeus/Object.hpp>
|
||||
#include <zeus/File.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
|
@ -32,7 +32,7 @@ def configure(target, my_module):
|
||||
])
|
||||
|
||||
zeus_macro = macro.load_macro('zeus')
|
||||
zeus_macro.parse_service_idl(my_module, 'appl/zeus-service-video.srv.zeus.idl')
|
||||
zeus_macro.parse_object_idl(my_module, 'appl/zeus-service-video.srv.zeus.idl')
|
||||
#module_zeus = target.get_module('zeus')
|
||||
#module_zeus.parse_service_idl(my_module, 'appl/zeus-service-video.zeus.idl')
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <zeus/BaseProxy.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
|
||||
const zeus::BaseProxy& zeus::BaseProxy::operator= (const zeus::ServiceRemote& _obj) {
|
||||
const zeus::BaseProxy& zeus::BaseProxy::operator= (const zeus::ObjectRemote& _obj) {
|
||||
m_obj = _obj;
|
||||
return *this;
|
||||
}
|
||||
@ -17,7 +17,7 @@ zeus::BaseProxy::BaseProxy():
|
||||
|
||||
}
|
||||
|
||||
zeus::BaseProxy::BaseProxy(const zeus::ServiceRemote& _obj):
|
||||
zeus::BaseProxy::BaseProxy(const zeus::ObjectRemote& _obj):
|
||||
m_obj(_obj),
|
||||
sys(m_obj) {
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
#include <zeus/SystemProxy.hpp>
|
||||
|
||||
namespace zeus {
|
||||
@ -14,14 +14,14 @@ namespace zeus {
|
||||
*/
|
||||
class BaseProxy {
|
||||
protected:
|
||||
zeus::ServiceRemote m_obj; //!< Service instance handle
|
||||
zeus::ObjectRemote m_obj; //!< Service instance handle
|
||||
public:
|
||||
zeus::SystemProxy sys;
|
||||
public:
|
||||
const BaseProxy& operator= (const zeus::ServiceRemote& _srv);
|
||||
const BaseProxy& operator= (const zeus::ObjectRemote& _srv);
|
||||
BaseProxy();
|
||||
virtual ~BaseProxy() = default;
|
||||
BaseProxy(const zeus::ServiceRemote& _srv);
|
||||
BaseProxy(const zeus::ObjectRemote& _srv);
|
||||
bool exist() const;
|
||||
};
|
||||
}
|
||||
|
@ -98,8 +98,7 @@ zeus::ParamType zeus::BufferParameter::getParameterType(int32_t _id) const {
|
||||
m_parameter[_id].first = sizeof(uint16_t);
|
||||
return zeus::ParamType("raw", paramTypeRaw);
|
||||
}
|
||||
if ( typeId == paramTypeObject
|
||||
|| typeId == paramTypeService) {
|
||||
if (typeId == paramTypeObject) {
|
||||
const char* tmp = reinterpret_cast<const char*>(&m_parameter[_id].second[2]);
|
||||
bool find = false;
|
||||
for (int32_t iii=0; iii<1024; ++iii) {
|
||||
|
@ -30,15 +30,6 @@ void zeus::addTypeObject(std::vector<uint8_t>& _data, const std::string _type) {
|
||||
_data.push_back(0);
|
||||
}
|
||||
|
||||
void zeus::addTypeService(std::vector<uint8_t>& _data, const std::string _type) {
|
||||
_data.push_back(uint8_t(zeus::paramTypeService>>8));
|
||||
_data.push_back(uint8_t(zeus::paramTypeService));
|
||||
for (auto &it : _type) {
|
||||
_data.push_back(uint8_t(it));
|
||||
}
|
||||
_data.push_back(0);
|
||||
}
|
||||
|
||||
void zeus::addTypeRaw(std::vector<uint8_t>& _data) {
|
||||
_data.push_back(uint8_t(zeus::paramTypeRaw>>8));
|
||||
_data.push_back(uint8_t(zeus::paramTypeRaw));
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <zeus/ParamType.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <zeus/AbstractFunction.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
#include <climits>
|
||||
namespace zeus {
|
||||
template<>
|
||||
@ -1471,13 +1471,13 @@ namespace zeus {
|
||||
return out;
|
||||
}
|
||||
template<>
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> BufferParameter::getParameter<ememory::SharedPtr<zeus::ServiceRemoteBase>>(const ememory::SharedPtr<zeus::WebServer>& _iface, int32_t _id) const {
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> out;
|
||||
ememory::SharedPtr<zeus::ObjectRemoteBase> BufferParameter::getParameter<ememory::SharedPtr<zeus::ObjectRemoteBase>>(const ememory::SharedPtr<zeus::WebServer>& _iface, int32_t _id) const {
|
||||
ememory::SharedPtr<zeus::ObjectRemoteBase> out;
|
||||
zeus::ParamType type = getParameterType(_id);
|
||||
const uint8_t* pointer = getParameterPointer(_id);
|
||||
uint32_t dataSize = getParameterSize(_id);
|
||||
// TODO : Check size ...
|
||||
if (type.getId() == zeus::paramTypeService) {
|
||||
if (type.getId() == zeus::paramTypeObject) {
|
||||
// Get the type string of the parameter:
|
||||
ZEUS_VERBOSE("Get type : " << type.getName());
|
||||
ZEUS_VERBOSE("Get id : " << getSourceId() << "/" << getSourceObjectId());
|
||||
@ -1491,7 +1491,7 @@ namespace zeus {
|
||||
ememory::SharedPtr<zeus::WebServer> _iface2 = _iface;
|
||||
uint16_t id = _iface2->getAddress();
|
||||
uint16_t idObj = _iface2->getNewObjectId();
|
||||
out = ememory::makeShared<zeus::ServiceRemoteBase>(_iface, id, idObj, serviceAddress, type.getName());
|
||||
out = ememory::makeShared<zeus::ObjectRemoteBase>(_iface, id, idObj, serviceAddress, type.getName());
|
||||
_iface2->addWebObj(out);
|
||||
} else {
|
||||
ZEUS_ERROR("missing interface to crate object: '" << type << "'");
|
||||
|
@ -128,40 +128,27 @@ bool zeus::Client::serviceRemove(const std::string& _serviceName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
zeus::ServiceRemote zeus::Client::getService(const std::string& _name) {
|
||||
zeus::ObjectRemote zeus::Client::getService(const std::string& _name) {
|
||||
ZEUS_TODO("Lock here");
|
||||
auto it = m_listConnectedService.begin();
|
||||
while (it != m_listConnectedService.end()) {
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> val = it->lock();
|
||||
ememory::SharedPtr<zeus::ObjectRemoteBase> val = it->lock();
|
||||
if (val == nullptr) {
|
||||
it = m_listConnectedService.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (val->getName() == _name) {
|
||||
return zeus::ServiceRemote(val);
|
||||
return zeus::ObjectRemote(val);
|
||||
}
|
||||
}
|
||||
// little hack : Call the service manager with the service ID=0 ...
|
||||
zeus::Future<ememory::SharedPtr<zeus::ServiceRemoteBase>> ret = m_interfaceWeb->call(uint32_t(m_interfaceWeb->getAddress())<<16, ZEUS_GATEWAY_ADDRESS, "link", _name);
|
||||
zeus::Future<ememory::SharedPtr<zeus::ObjectRemoteBase>> ret = m_interfaceWeb->call(uint32_t(m_interfaceWeb->getAddress())<<16, ZEUS_GATEWAY_ADDRESS, "link", _name);
|
||||
ret.wait();
|
||||
if (ret.hasError() == true) {
|
||||
ZEUS_WARNING("Can not unlink with the service id: '" << _name << "' ==> link error");
|
||||
return zeus::ServiceRemote();
|
||||
return zeus::ObjectRemote();
|
||||
}
|
||||
//m_listConnectedService.push_back(tmp);
|
||||
//return zeus::ServiceRemote(tmp);
|
||||
return zeus::ServiceRemote(ret.get(m_interfaceWeb));
|
||||
/*
|
||||
if (ret.get() == true) {
|
||||
m_isLinked = false;
|
||||
} else {
|
||||
ZEUS_ERROR("Can not unlink with this service ....");
|
||||
m_serviceId = tmpLocalService;
|
||||
}
|
||||
uint16_t tmpId = m_interfaceWeb->getNewObjectId();
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> tmp = ememory::makeShared<zeus::ServiceRemoteBase>(m_interfaceWeb, _name, m_interfaceWeb->getAddress(), tmpId);
|
||||
*/
|
||||
|
||||
return zeus::ObjectRemote(ret.get(m_interfaceWeb));
|
||||
}
|
||||
|
||||
void zeus::Client::onPropertyChangeIp() {
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <chrono>
|
||||
|
||||
#include <zeus/Future.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
#include <zeus/Object.hpp>
|
||||
|
||||
namespace zeus {
|
||||
@ -20,16 +20,14 @@ namespace zeus {
|
||||
* @brief Client interface to acces on the remote service and gateway
|
||||
*/
|
||||
class Client : public eproperty::Interface {
|
||||
friend class ServiceRemote;
|
||||
friend class ObjectRemote;
|
||||
public:
|
||||
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
|
||||
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
|
||||
public:
|
||||
std::string m_clientName; //!< Local client name to generate the local serrvice name if needed (if direct connection ==> no name)
|
||||
ememory::SharedPtr<zeus::WebServer> m_interfaceWeb; //!< Interface on the Websocket interface
|
||||
std::vector<ememory::WeakPtr<zeus::ServiceRemoteBase>> m_listConnectedService; //!< Connect only one time on each service, not needed more.
|
||||
//std::vector<ememory::SharedPtr<zeus::Object>> m_listProvicedService; //!< Connect only one time on each service, not needed more.
|
||||
//std::vector<ememory::SharedPtr<zeus::Object>> m_listLocalObject;
|
||||
std::vector<ememory::WeakPtr<zeus::ObjectRemoteBase>> m_listConnectedService; //!< Connect only one time on each service, not needed more.
|
||||
public:
|
||||
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
|
||||
ememory::SharedPtr<zeus::WebServer> getWebInterface() {
|
||||
@ -87,7 +85,7 @@ namespace zeus {
|
||||
* @param[in] _serviceName Name of the service
|
||||
* @return Pointer on an interface of remote service
|
||||
*/
|
||||
zeus::ServiceRemote getService(const std::string& _serviceName);
|
||||
zeus::ObjectRemote getService(const std::string& _serviceName);
|
||||
using factoryService = std::function<void(uint32_t, ememory::SharedPtr<zeus::WebServer>& _iface, uint32_t _destination)>; // call this function anser to the callter the requested Object
|
||||
|
||||
std::map<std::string,factoryService> m_listServicesAvaillable; //!< list of all factory availlable
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <zeus/debug.hpp>
|
||||
|
||||
#include <zeus/File.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
|
||||
namespace zeus {
|
||||
template<>
|
||||
@ -343,8 +343,8 @@ namespace zeus {
|
||||
|
||||
namespace zeus {
|
||||
template<>
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> zeus::Future<ememory::SharedPtr<zeus::ServiceRemoteBase>>::get(const ememory::SharedPtr<zeus::WebServer>& _iface) {
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> out;
|
||||
ememory::SharedPtr<zeus::ObjectRemoteBase> zeus::Future<ememory::SharedPtr<zeus::ObjectRemoteBase>>::get(const ememory::SharedPtr<zeus::WebServer>& _iface) {
|
||||
ememory::SharedPtr<zeus::ObjectRemoteBase> out;
|
||||
if ( m_data == nullptr
|
||||
|| m_data->m_returnData == nullptr) {
|
||||
return out;
|
||||
@ -353,7 +353,7 @@ namespace zeus {
|
||||
ZEUS_WARNING("No Return value ...");
|
||||
return out;
|
||||
}
|
||||
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<ememory::SharedPtr<zeus::ServiceRemoteBase>>(_iface);
|
||||
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<ememory::SharedPtr<zeus::ObjectRemoteBase>>(_iface);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
@ -12,23 +12,8 @@
|
||||
|
||||
|
||||
|
||||
/*zeus::Object::Object(zeus::Client* _client, uint16_t _objectId) :
|
||||
zeus::RemoteProcessCall(_client->getWebInterface(), _client->m_localAddress, _objectId),
|
||||
m_clientId(_client->m_localAddress),
|
||||
m_objectId(_objectId) {
|
||||
/ *
|
||||
zeus::AbstractFunction* func = advertise("getExtention", &zeus::Object::getExtention);
|
||||
if (func != nullptr) {
|
||||
func->setDescription("Get List of availlable extention of this Object");
|
||||
func->setReturn("A list of extention register in the Object");
|
||||
}
|
||||
* /
|
||||
}
|
||||
*/
|
||||
zeus::Object::Object(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _objectId) :
|
||||
zeus::RemoteProcessCall(_iface, _iface->getAddress(), _objectId),
|
||||
m_clientId(_iface->getAddress()),
|
||||
m_objectId(_objectId) {
|
||||
zeus::RemoteProcessCall(_iface, _iface->getAddress(), _objectId) {
|
||||
|
||||
}
|
||||
|
||||
@ -76,47 +61,27 @@ void zeus::Object::receive(ememory::SharedPtr<zeus::Buffer> _value) {
|
||||
}
|
||||
|
||||
void zeus::Object::callBinary(ememory::SharedPtr<zeus::Buffer> _obj) {
|
||||
ZEUS_INFO("plop 1 ...");
|
||||
if (_obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("plop 2 ...");
|
||||
if (_obj->getType() == zeus::Buffer::typeMessage::event) {
|
||||
ZEUS_ERROR("Unknow event: '...'");
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("plop 3 ...");
|
||||
if (_obj->getType() == zeus::Buffer::typeMessage::answer) {
|
||||
ZEUS_ERROR("Local Answer: '...'");
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("plop 4 ...");
|
||||
if (_obj->getType() == zeus::Buffer::typeMessage::call) {
|
||||
ZEUS_INFO("plop 5 ... ");
|
||||
ememory::SharedPtr<zeus::BufferCall> callObj = ememory::staticPointerCast<zeus::BufferCall>(_obj);
|
||||
uint32_t source = callObj->getSource();
|
||||
uint32_t sourceId = callObj->getSourceId();
|
||||
std::string callFunction = callObj->getCall();
|
||||
ZEUS_INFO("plop - ... " << callFunction);
|
||||
/*
|
||||
if (callFunction[0] == '_') {
|
||||
if (callFunction == "_new") {
|
||||
std::string userName = callObj->getParameter<std::string>(0);
|
||||
std::string clientName = callObj->getParameter<std::string>(1);
|
||||
std::vector<std::string> clientGroup = callObj->getParameter<std::vector<std::string>>(2);
|
||||
clientConnect(sourceId, userName, clientName, clientGroup);
|
||||
} else if (callFunction == "_delete") {
|
||||
clientDisconnect(sourceId);
|
||||
}
|
||||
m_interfaceWeb->answerValue(callObj->getTransactionId(), uint32_t(m_id)<<16, source, true);
|
||||
return;
|
||||
} else */if (isFunctionAuthorized(sourceId, callFunction) == true) {
|
||||
ZEUS_INFO("plop 6 ...");
|
||||
if (isFunctionAuthorized(sourceId, callFunction) == true) {
|
||||
callBinary2(callFunction, callObj);
|
||||
return;
|
||||
} else {
|
||||
ZEUS_INFO("plop 7 ...");
|
||||
m_interfaceWeb->answerError(callObj->getTransactionId(), (uint32_t(m_clientId)<<16) + m_objectId, source, "NOT-AUTHORIZED-FUNCTION", "");
|
||||
m_interfaceWeb->answerError(callObj->getTransactionId(), getFullId(), source, "NOT-AUTHORIZED-FUNCTION", "");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,6 @@ namespace zeus {
|
||||
protected:
|
||||
std::mutex m_mutex;
|
||||
protected:
|
||||
uint16_t m_clientId; // TODO : Remove it
|
||||
uint16_t m_objectId; // TODO : Remove it
|
||||
std::vector<zeus::FutureBase> m_callMultiData;
|
||||
public:
|
||||
uint16_t getObjectId() { return m_objectId; }
|
||||
@ -38,7 +36,6 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
//Object(zeus::Client* _client, uint16_t _objectId);
|
||||
Object(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _objectId);
|
||||
/**
|
||||
* @brief
|
||||
|
@ -4,60 +4,60 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
#include <zeus/Client.hpp>
|
||||
|
||||
|
||||
|
||||
zeus::ServiceRemoteBase::ServiceRemoteBase(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _localId, uint16_t _localObjectId, uint32_t _address, const std::string& _type):
|
||||
zeus::ObjectRemoteBase::ObjectRemoteBase(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _localId, uint16_t _localObjectId, uint32_t _address, const std::string& _type):
|
||||
zeus::WebObj(_iface, _localId, _localObjectId),
|
||||
m_type(_type),
|
||||
m_serviceId(_address),
|
||||
m_remoteAddress(_address),
|
||||
m_isLinked(false) {
|
||||
m_isLinked = true;
|
||||
}
|
||||
|
||||
zeus::ServiceRemoteBase::~ServiceRemoteBase() {
|
||||
zeus::ObjectRemoteBase::~ObjectRemoteBase() {
|
||||
if (m_isLinked == true) {
|
||||
uint32_t tmpLocalService = m_serviceId;
|
||||
uint32_t tmpLocalService = m_remoteAddress;
|
||||
// little hack : Call the service manager with the service ID=0 ...
|
||||
m_serviceId = 0;
|
||||
zeus::Future<bool> ret = m_interfaceWeb->call(getFullId(), m_serviceId, "unlink", tmpLocalService);
|
||||
m_remoteAddress = 0;
|
||||
zeus::Future<bool> ret = m_interfaceWeb->call(getFullId(), m_remoteAddress, "unlink", tmpLocalService);
|
||||
ret.wait();
|
||||
if (ret.hasError() == true) {
|
||||
ZEUS_WARNING("Can not unlink with the service id: '" << tmpLocalService << "' ==> link error");
|
||||
m_serviceId = tmpLocalService;
|
||||
m_remoteAddress = tmpLocalService;
|
||||
return;
|
||||
}
|
||||
if (ret.get() == true) {
|
||||
m_isLinked = false;
|
||||
} else {
|
||||
ZEUS_ERROR("Can not unlink with this service ....");
|
||||
m_serviceId = tmpLocalService;
|
||||
m_remoteAddress = tmpLocalService;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool zeus::ServiceRemoteBase::exist() const {
|
||||
bool zeus::ObjectRemoteBase::exist() const {
|
||||
return m_isLinked;
|
||||
}
|
||||
|
||||
const std::string& zeus::ServiceRemoteBase::getName() const {
|
||||
const std::string& zeus::ObjectRemoteBase::getName() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::ServiceRemoteBase> _interface):
|
||||
zeus::ObjectRemote::ObjectRemote(ememory::SharedPtr<zeus::ObjectRemoteBase> _interface):
|
||||
m_interface(_interface) {
|
||||
if (m_interface == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
zeus::ServiceRemote::~ServiceRemote() {
|
||||
zeus::ObjectRemote::~ObjectRemote() {
|
||||
|
||||
}
|
||||
|
||||
bool zeus::ServiceRemote::exist() const {
|
||||
bool zeus::ObjectRemote::exist() const {
|
||||
if (m_interface == nullptr) {
|
||||
return false;
|
||||
}
|
@ -8,24 +8,24 @@
|
||||
#include <zeus/WebServer.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
#include <zeus/AbstractFunction.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
#include <zeus/Future.hpp>
|
||||
#include <zeus/WebServer.hpp>
|
||||
#include <zeus/WebObj.hpp>
|
||||
|
||||
namespace zeus {
|
||||
//class Client;
|
||||
class ServiceRemote;
|
||||
class ObjectRemote;
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ServiceRemoteBase : public zeus::WebObj {
|
||||
friend class ServiceRemote;
|
||||
class ObjectRemoteBase : public zeus::WebObj {
|
||||
friend class ObjectRemote;
|
||||
private:
|
||||
std::string m_type;
|
||||
uint32_t m_serviceId;
|
||||
uint32_t m_remoteAddress;
|
||||
bool m_isLinked;
|
||||
public:
|
||||
/**
|
||||
@ -33,7 +33,7 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemoteBase():
|
||||
ObjectRemoteBase():
|
||||
zeus::WebObj(nullptr, 0, 0) {
|
||||
|
||||
}
|
||||
@ -42,13 +42,13 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemoteBase(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _localId, uint16_t _localObjectId, uint32_t _address, const std::string& _type);
|
||||
ObjectRemoteBase(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _localId, uint16_t _localObjectId, uint32_t _address, const std::string& _type);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
~ServiceRemoteBase();
|
||||
~ObjectRemoteBase();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -67,22 +67,22 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ServiceRemote {
|
||||
class ObjectRemote {
|
||||
private:
|
||||
ememory::SharedPtr<zeus::ServiceRemoteBase> m_interface;
|
||||
ememory::SharedPtr<zeus::ObjectRemoteBase> m_interface;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemote(ememory::SharedPtr<zeus::ServiceRemoteBase> _interface = nullptr);
|
||||
ObjectRemote(ememory::SharedPtr<zeus::ObjectRemoteBase> _interface = nullptr);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
~ServiceRemote();
|
||||
~ObjectRemote();
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
@ -106,7 +106,7 @@ namespace zeus {
|
||||
return zeus::FutureBase(0, ret);
|
||||
}
|
||||
return m_interface->m_interfaceWeb->call(m_interface->getFullId(),
|
||||
m_interface->m_serviceId,
|
||||
m_interface->m_remoteAddress,
|
||||
_functionName,
|
||||
_args...);
|
||||
}
|
@ -132,6 +132,5 @@ generate_basic_type(zeus::File, "file", 0x000E, false, false);
|
||||
generate_basic_type(zeus::FileServer, "file", 0x000E, false, false);
|
||||
|
||||
const uint16_t zeus::paramTypeObject = 0xFFFF;
|
||||
const uint16_t zeus::paramTypeService = 0xFFFE;
|
||||
const uint16_t zeus::paramTypeRaw = 0xFFFD;
|
||||
const uint16_t zeus::paramTypeRaw = 0xFFFE;
|
||||
|
||||
|
@ -89,7 +89,6 @@ namespace zeus {
|
||||
bool isVector() const;
|
||||
};
|
||||
extern const uint16_t paramTypeObject; //!< van not automatic create a type with the string named object
|
||||
extern const uint16_t paramTypeService; //!< van not automatic create a type with the string named object
|
||||
extern const uint16_t paramTypeRaw; //!< Raw type (special case of data)
|
||||
/**
|
||||
* @brief Create human readable stream to debug
|
||||
|
0
zeus/RemoteProperty.cpp
Normal file
0
zeus/RemoteProperty.cpp
Normal file
48
zeus/RemoteProperty.hpp
Normal file
48
zeus/RemoteProperty.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/WebServer.hpp>
|
||||
#include <zeus/AbstractFunctionTypeDirect.hpp>
|
||||
#include <zeus/AbstractFunctionTypeClass.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
#include <zeus/WebObj.hpp>
|
||||
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief Remote inteface of a property:
|
||||
*/
|
||||
template<typename ZEUS_TYPE_PROPERTY>
|
||||
class RemoteProperty {
|
||||
private:
|
||||
zeus::ObjectRemote& m_remoteObject;
|
||||
std::string m_name;
|
||||
public:
|
||||
/**
|
||||
* @brief generic constructor
|
||||
*/
|
||||
RemoteProperty(zeus::ObjectRemote& _remoteObject, const std::string& _name) :
|
||||
m_remoteObject(_remoteObject),
|
||||
m_name(_name) {
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Get the property value
|
||||
* @return the requested value
|
||||
*/
|
||||
zeus::Future<ZEUS_TYPE_PROPERTY> get() {
|
||||
return m_remoteObject.call(m_name + ".get");
|
||||
}
|
||||
/**
|
||||
* @brief Set the property value
|
||||
* @param[in] _value The new value to set
|
||||
*/
|
||||
zeus::Future<void> set(const ZEUS_TYPE_PROPERTY& _value) {
|
||||
return m_remoteObject.call(m_name + ".set", _value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/Service.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <enet/TcpClient.hpp>
|
||||
#include <zeus/Client.hpp>
|
||||
|
||||
|
||||
|
302
zeus/Service.hpp
302
zeus/Service.hpp
@ -1,302 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/WebServer.hpp>
|
||||
#include <eproperty/Value.hpp>
|
||||
#include <zeus/AbstractFunctionTypeDirect.hpp>
|
||||
#include <zeus/AbstractFunctionTypeClass.hpp>
|
||||
#include <zeus/debug.hpp>
|
||||
#include <zeus/RemoteProcessCall.hpp>
|
||||
#include <zeus/Future.hpp>
|
||||
#include <zeus/Object.hpp>
|
||||
|
||||
/**
|
||||
* @brief Main zeus library namespace
|
||||
*/
|
||||
namespace zeus {
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
class ClientPropertyddd {
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ClientPropertyddd(const std::string& _clientName="", const std::vector<std::string>& _groups = std::vector<std::string>()) :
|
||||
m_name(_clientName),
|
||||
m_groups(_groups) {
|
||||
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setName(const std::string& _name) {
|
||||
m_name = _name;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::string& getName() {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> m_groups;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void setGroups(std::vector<std::string> _groups) {
|
||||
m_groups = _groups;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
const std::vector<std::string>& getGroups() {
|
||||
return m_groups;
|
||||
}
|
||||
private:
|
||||
std::vector<std::string> m_listAthorizedFunction;
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void addAuthorized(const std::string& _funcName) {
|
||||
m_listAthorizedFunction.push_back(_funcName);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isFunctionAuthorized(const std::string& _funcName) {
|
||||
ZEUS_ERROR("plop: " << _funcName << " " << m_listAthorizedFunction);
|
||||
return std::find(m_listAthorizedFunction.begin(), m_listAthorizedFunction.end(), _funcName) != m_listAthorizedFunction.end();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace zeus {
|
||||
template<class ZEUS_TYPE_SERVICE>
|
||||
class ServiceType : public zeus::Object {
|
||||
public:
|
||||
//using factory = std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(uint16_t)>;
|
||||
private:
|
||||
// no need of shared_ptr or unique_ptr (if service die all is lost and is client die, the gateway notify us...)
|
||||
ememory::SharedPtr<ClientPropertyddd> m_property;
|
||||
ememory::SharedPtr<ZEUS_TYPE_SERVICE> m_interface;
|
||||
public:
|
||||
/*
|
||||
ServiceType(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _objectId, uint16_t _clientId, factory _factory) :
|
||||
Object(_iface, _objectId) {
|
||||
m_interface = _factory(_clientId);
|
||||
}*/
|
||||
ServiceType(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _objectId, const ememory::SharedPtr<ZEUS_TYPE_SERVICE>& _element) :
|
||||
Object(_iface, _objectId),
|
||||
m_interface(_element) {
|
||||
// nothing else to do ...
|
||||
}
|
||||
/*
|
||||
ServiceType(zeus::Client* _client, uint16_t _objectId, ememory::makeShared<ZEUS_TYPE_SERVICE> _instance) :
|
||||
Object(_client, _objectId),
|
||||
m_interface(_instance) {
|
||||
|
||||
}*/
|
||||
public:
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
template<class ZEUS_RETURN_VALUE,
|
||||
class ZEUS_CLASS_TYPE,
|
||||
class... ZEUS_FUNC_ARGS_TYPE>
|
||||
zeus::AbstractFunction* advertise(const std::string& _name,
|
||||
ZEUS_RETURN_VALUE (ZEUS_CLASS_TYPE::*_func)(ZEUS_FUNC_ARGS_TYPE... _args)) {
|
||||
if (etk::start_with(_name, "srv.") == true) {
|
||||
ZEUS_ERROR("Advertise function start with 'srv.' is not permited ==> only allow for internal service: '" << _name << "'");
|
||||
return nullptr;
|
||||
}
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->getName() == _name) {
|
||||
ZEUS_ERROR("Advertise function already bind .. ==> can not be done...: '" << _name << "'");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
zeus::AbstractFunction* tmp = createAbstractFunctionClass(_name, _func);
|
||||
if (tmp == nullptr) {
|
||||
ZEUS_ERROR("can not create abstract function ... '" << _name << "'");
|
||||
return nullptr;
|
||||
}
|
||||
tmp->setType(zeus::AbstractFunction::type::object);
|
||||
ZEUS_INFO("Add function '" << _name << "' in object mode");
|
||||
m_listFunction.push_back(tmp);
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
bool isFunctionAuthorized(uint64_t _clientId, const std::string& _funcName) {
|
||||
/*
|
||||
auto it = m_interface.find(_clientId);
|
||||
if (it == m_interface.end()) {
|
||||
ZEUS_ERROR("CLIENT does not exist ... " << _clientId << " " << _funcName);
|
||||
return false;
|
||||
}
|
||||
return it->second.first->isFunctionAuthorized(_funcName);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
void clientConnect(uint16_t _sourceId, const std::string& _userName, const std::string& _clientName, const std::vector<std::string>& _groups) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ZEUS_DEBUG("connect: " << _sourceId << " to '" << _userName << "'");
|
||||
ZEUS_DEBUG(" client name='" << _clientName << "'");
|
||||
ZEUS_DEBUG(" groups=" << etk::to_string(_groups));
|
||||
ememory::SharedPtr<ClientPropertyddd> tmpProperty = ememory::makeShared<ClientPropertyddd>(_clientName, _groups);
|
||||
ememory::SharedPtr<ZEUS_TYPE_SERVICE> tmpSrv;
|
||||
if (m_factory != nullptr) {
|
||||
tmpSrv = m_factory(tmpProperty, m_nameUser);
|
||||
} else {
|
||||
ZEUS_ERROR("Create service with no factory");
|
||||
}
|
||||
m_interface.insert(std::make_pair(_sourceId, std::make_pair(tmpProperty, tmpSrv)));
|
||||
// enable list of function availlable:
|
||||
for (auto &it : m_listFunction) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
tmpProperty->addAuthorized(it->getName());
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
void clientDisconnect(uint16_t _sourceId) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ZEUS_DEBUG("disconnect: " << _sourceId);
|
||||
auto it = m_interface.find(_sourceId);
|
||||
if (it == m_interface.end()) {
|
||||
ZEUS_WARNING("disconnect ==> Not find Client ID " << _sourceId);
|
||||
// noting to do ==> user never conected.
|
||||
return;
|
||||
}
|
||||
m_interface.erase(it);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
void clientSetName(uint16_t _sourceId, const std::string& _clientName) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
auto it = m_interface.find(_sourceId);
|
||||
if (it == m_interface.end()) {
|
||||
ZEUS_ERROR("Change the client property but client was not created ...");
|
||||
return;
|
||||
}
|
||||
it->second.first->setName(_clientName);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
void clientSetGroup(uint16_t _sourceId, const std::vector<std::string>& _clientGroups) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
auto it = m_interface.find(_sourceId);
|
||||
if (it == m_interface.end()) {
|
||||
ZEUS_ERROR("Change the client property but client was not created ...");
|
||||
return;
|
||||
}
|
||||
it->second.first->setGroups(_clientGroups);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
void callBinary2(const std::string& _call, ememory::SharedPtr<zeus::BufferCall> _obj) {
|
||||
/*
|
||||
auto it = m_interface.find(_obj->getSourceId());
|
||||
if (it == m_interface.end()) {
|
||||
m_interfaceWeb->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "CLIENT-UNKNOW", "");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
for (auto &it2 : m_listFunction) {
|
||||
if (it2 == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it2->getName() != _call) {
|
||||
continue;
|
||||
}
|
||||
switch (it2->getType()) {
|
||||
case zeus::AbstractFunction::type::object: {
|
||||
ZEUS_TYPE_SERVICE* elem = m_interface.get();
|
||||
it2->execute(m_interfaceWeb, _obj, (void*)elem);
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::local: {
|
||||
it2->execute(m_interfaceWeb, _obj, (void*)((RemoteProcessCall*)this));
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::service: {
|
||||
it2->execute(m_interfaceWeb, _obj, (void*)this);
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::global: {
|
||||
it2->execute(m_interfaceWeb, _obj, nullptr);
|
||||
return;
|
||||
}
|
||||
case zeus::AbstractFunction::type::unknow:
|
||||
ZEUS_ERROR("Can not call unknow type ...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_interfaceWeb->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "FUNCTION-UNKNOW", "");
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <zeus/SystemProxy.hpp>
|
||||
|
||||
zeus::SystemProxy::SystemProxy(zeus::ServiceRemote& _srv):
|
||||
zeus::SystemProxy::SystemProxy(zeus::ObjectRemote& _srv):
|
||||
m_srv(_srv) {
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,14 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ObjectRemote.hpp>
|
||||
|
||||
namespace zeus {
|
||||
class SystemProxy {
|
||||
protected:
|
||||
zeus::ServiceRemote& m_srv; //!< Service instance handle
|
||||
zeus::ObjectRemote& m_srv; //!< Service instance handle
|
||||
public:
|
||||
SystemProxy(zeus::ServiceRemote& _srv);
|
||||
SystemProxy(zeus::ObjectRemote& _srv);
|
||||
zeus::Future<std::string> getDescription();
|
||||
zeus::Future<std::string> getVersion();
|
||||
zeus::Future<std::string> getType();
|
||||
|
Loading…
x
Reference in New Issue
Block a user