[DEV] get the service and call it ...
This commit is contained in:
parent
db1affa89c
commit
619604b6c5
@ -105,15 +105,15 @@ class AttributeDefinition:
|
||||
|
||||
def generate_cpp(self, space, object):
|
||||
out = "";
|
||||
# TODO : Set it in protected
|
||||
out += space[:-1] + "protected:"
|
||||
out += space + convert_type_in_cpp(self.type) + " m_" + self.name + "; //!<" + self.brief + "\n"
|
||||
# TODO: set it in public ...
|
||||
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 + "}\n"
|
||||
out += self.generate_doxy_set(space, object)
|
||||
out += space + "virtual void set" + capital_first(self.name) + "(const " + convert_type_in_cpp(self.type) + "& _value) {\n"
|
||||
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 + "}\n"
|
||||
return out;
|
||||
@ -460,6 +460,7 @@ class ServiceDefinition:
|
||||
|
||||
out += " " + namespace + "register" + self.name[-1] + "(*obj);\n"
|
||||
out += " _iface2->addWebObj(obj);\n"
|
||||
out += " ZEUS_INFO(\"Create object ID : \" << idObj);\n"
|
||||
out += " fullId = (uint32_t(id)<<16)+idObj;\n"
|
||||
out += " }\n"
|
||||
# return Object ID and interface adress
|
||||
@ -527,7 +528,7 @@ class ServiceDefinition:
|
||||
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, _destination, uint32_t(_iface->getAddress())<<16, tmp2); \\\n"
|
||||
out += space + " _iface->answerValue(_transactionId, uint32_t(_iface->getAddress())<<16, _destination, tmp2); \\\n"
|
||||
out += space + " }\n"
|
||||
out += space + "\n"
|
||||
"""
|
||||
|
@ -61,7 +61,6 @@ def configure(target, my_module):
|
||||
'zeus/WebServer.cpp',
|
||||
'zeus/mineType.cpp',
|
||||
'zeus/BaseProxy.cpp',
|
||||
'zeus/ServiceProxy.cpp',
|
||||
'zeus/SystemProxy.cpp',
|
||||
])
|
||||
my_module.add_header_file([
|
||||
@ -92,7 +91,6 @@ def configure(target, my_module):
|
||||
'zeus/WebServer.hpp',
|
||||
'zeus/mineType.hpp',
|
||||
'zeus/BaseProxy.hpp',
|
||||
'zeus/ServiceProxy.hpp',
|
||||
'zeus/SystemProxy.hpp',
|
||||
])
|
||||
if target.config["compilator"] == "clang":
|
||||
|
@ -105,20 +105,13 @@ int main(int _argc, const char *_argv[]) {
|
||||
zeus::Future<std::string> retVersion = remoteServiceUser.sys.getVersion();
|
||||
zeus::Future<std::string> retType = remoteServiceUser.sys.getType();
|
||||
zeus::Future<std::vector<std::string>> retMaintainer = remoteServiceUser.sys.getAuthors();
|
||||
//service DOC
|
||||
zeus::Future<std::vector<std::string>> retExtention = remoteServiceUser.srv.getExtention();
|
||||
retDesc.wait();
|
||||
retVersion.wait();
|
||||
retType.wait();
|
||||
retExtention.wait();
|
||||
retMaintainer.wait();
|
||||
APPL_INFO("Service: system-user");
|
||||
APPL_INFO(" version : " << retVersion.get());
|
||||
APPL_INFO(" type : " << retType.get());
|
||||
APPL_INFO(" Extention : " << retExtention.get().size());
|
||||
for (auto &it : retExtention.get()) {
|
||||
APPL_INFO(" - " << it);
|
||||
}
|
||||
APPL_INFO(" maintainer: " << retMaintainer.get().size());
|
||||
for (auto &it : retMaintainer.get()) {
|
||||
APPL_INFO(" - " << it);
|
||||
|
@ -11,17 +11,18 @@ const zeus::BaseProxy& zeus::BaseProxy::operator= (const zeus::ServiceRemote& _o
|
||||
m_obj = _obj;
|
||||
return *this;
|
||||
}
|
||||
|
||||
zeus::BaseProxy::BaseProxy():
|
||||
sys(m_obj),
|
||||
srv(m_obj) {
|
||||
sys(m_obj) {
|
||||
|
||||
}
|
||||
|
||||
zeus::BaseProxy::BaseProxy(const zeus::ServiceRemote& _obj):
|
||||
m_obj(_obj),
|
||||
sys(m_obj),
|
||||
srv(m_obj) {
|
||||
sys(m_obj) {
|
||||
|
||||
}
|
||||
|
||||
bool zeus::BaseProxy::exist() const {
|
||||
return m_obj.exist();
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <zeus/ServiceProxy.hpp>
|
||||
#include <zeus/SystemProxy.hpp>
|
||||
|
||||
namespace zeus {
|
||||
@ -18,7 +17,6 @@ namespace zeus {
|
||||
zeus::ServiceRemote m_obj; //!< Service instance handle
|
||||
public:
|
||||
zeus::SystemProxy sys;
|
||||
zeus::ServiceProxy srv;
|
||||
public:
|
||||
const BaseProxy& operator= (const zeus::ServiceRemote& _srv);
|
||||
BaseProxy();
|
||||
|
@ -55,6 +55,10 @@ namespace zeus {
|
||||
ZEUS_TYPE_DATA getAnswer() const {
|
||||
return getParameter<ZEUS_TYPE_DATA>(0);
|
||||
}
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
ZEUS_TYPE_DATA getAnswer(const ememory::SharedPtr<zeus::WebServer>& _iface) const {
|
||||
return getParameter<ZEUS_TYPE_DATA>(_iface, 0);
|
||||
}
|
||||
/**
|
||||
* @brief Ann an error on the message answer
|
||||
* @param[in] _value error value (simple string with no space with all capital letter separaete with '_'
|
||||
|
@ -98,11 +98,24 @@ zeus::ParamType zeus::BufferParameter::getParameterType(int32_t _id) const {
|
||||
m_parameter[_id].first = sizeof(uint16_t);
|
||||
return zeus::ParamType("raw", paramTypeRaw);
|
||||
}
|
||||
if (typeId == paramTypeObject) {
|
||||
std::string type = reinterpret_cast<const char*>(&m_parameter[_id].second[2]);
|
||||
m_parameter[_id].first = type.size() + sizeof(uint16_t);
|
||||
// TODO : Check error of \0 ==> limit at 256 char ...
|
||||
return zeus::ParamType(type, paramTypeObject);
|
||||
if ( typeId == paramTypeObject
|
||||
|| typeId == paramTypeService) {
|
||||
const char* tmp = reinterpret_cast<const char*>(&m_parameter[_id].second[2]);
|
||||
bool find = false;
|
||||
for (int32_t iii=0; iii<1024; ++iii) {
|
||||
if (tmp[iii] == 0) {
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find == false) {
|
||||
ZEUS_ERROR("Request object with a name too big ==> error ...");
|
||||
m_parameter[_id].first = 0;
|
||||
return zeus::ParamType("no-name", typeId);
|
||||
}
|
||||
std::string type(tmp);
|
||||
m_parameter[_id].first = type.size() + sizeof(uint16_t) + 1; // add \0
|
||||
return zeus::ParamType(type, typeId);
|
||||
}
|
||||
ZEUS_ERROR("Can not get type of parameter ... ");
|
||||
return createType<void>();
|
||||
|
@ -23,6 +23,13 @@ namespace zeus {
|
||||
*/
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
ZEUS_TYPE_DATA getParameter(int32_t _id) const;
|
||||
/**
|
||||
* @brief Template to get a parameter with a specific type
|
||||
* @param[in] _id Number of the parameter
|
||||
* @return Converted type of the parameter (or empty value)
|
||||
*/
|
||||
template<class ZEUS_TYPE_DATA>
|
||||
ZEUS_TYPE_DATA getParameter(const ememory::SharedPtr<zeus::WebServer>& _iface, int32_t _id) const;
|
||||
/**
|
||||
* @brief Get the type of a parameter.
|
||||
* @param[in] _id Number of the parameter
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <zeus/ParamType.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <zeus/AbstractFunction.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
#include <climits>
|
||||
namespace zeus {
|
||||
template<>
|
||||
@ -1469,5 +1470,36 @@ namespace zeus {
|
||||
ZEUS_ERROR("Can not get type from '" << type << "'");
|
||||
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;
|
||||
zeus::ParamType type = getParameterType(_id);
|
||||
const uint8_t* pointer = getParameterPointer(_id);
|
||||
uint32_t dataSize = getParameterSize(_id);
|
||||
// TODO : Check size ...
|
||||
if (type.getId() == zeus::paramTypeService) {
|
||||
// Get the type string of the parameter:
|
||||
ZEUS_VERBOSE("Get type : " << type.getName());
|
||||
ZEUS_VERBOSE("Get id : " << getSourceId() << "/" << getSourceObjectId());
|
||||
const uint32_t* tmp = reinterpret_cast<const uint32_t*>(pointer);
|
||||
uint32_t serviceAddress = *tmp;
|
||||
ZEUS_VERBOSE("Get id : " << (*tmp>>16) << "/" << (*tmp&0xFFFF));
|
||||
|
||||
// get new local ID:
|
||||
|
||||
if (_iface != nullptr) {
|
||||
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());
|
||||
_iface2->addWebObj(out);
|
||||
} else {
|
||||
ZEUS_ERROR("missing interface to crate object: '" << type << "'");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
ZEUS_ERROR("Can not get type from '" << type << "'");
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,10 +141,27 @@ zeus::ServiceRemote zeus::Client::getService(const std::string& _name) {
|
||||
return zeus::ServiceRemote(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);
|
||||
ret.wait();
|
||||
if (ret.hasError() == true) {
|
||||
ZEUS_WARNING("Can not unlink with the service id: '" << _name << "' ==> link error");
|
||||
return zeus::ServiceRemote();
|
||||
}
|
||||
//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);
|
||||
m_listConnectedService.push_back(tmp);
|
||||
return zeus::ServiceRemote(tmp);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void zeus::Client::onPropertyChangeIp() {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <zeus/debug.hpp>
|
||||
|
||||
#include <zeus/File.hpp>
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
|
||||
namespace zeus {
|
||||
template<>
|
||||
@ -338,4 +339,23 @@ namespace zeus {
|
||||
}
|
||||
}
|
||||
|
||||
// NamespaceSpace for Object and services
|
||||
|
||||
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;
|
||||
if ( m_data == nullptr
|
||||
|| m_data->m_returnData == nullptr) {
|
||||
return out;
|
||||
}
|
||||
if (m_data->m_returnData->getType() != zeus::Buffer::typeMessage::answer) {
|
||||
ZEUS_WARNING("No Return value ...");
|
||||
return out;
|
||||
}
|
||||
out = static_cast<zeus::BufferAnswer*>(m_data->m_returnData.get())->getAnswer<ememory::SharedPtr<zeus::ServiceRemoteBase>>(_iface);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,6 +38,11 @@ namespace zeus {
|
||||
* @return requested value
|
||||
*/
|
||||
ZEUS_RETURN get();
|
||||
/**
|
||||
* @brief Get the value Requested with the type expecially for object and services
|
||||
* @return requested value
|
||||
*/
|
||||
ZEUS_RETURN get(const ememory::SharedPtr<zeus::WebServer>& _iface);
|
||||
};
|
||||
/**
|
||||
* @brief future template to cast type in a void methode (fallback)
|
||||
|
@ -1,16 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <zeus/ServiceProxy.hpp>
|
||||
|
||||
zeus::ServiceProxy::ServiceProxy(zeus::ServiceRemote& _srv):
|
||||
m_srv(_srv) {
|
||||
|
||||
}
|
||||
zeus::Future<std::vector<std::string>> zeus::ServiceProxy::getExtention() {
|
||||
return m_srv.call("srv.getExtention");
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <zeus/ServiceRemote.hpp>
|
||||
|
||||
namespace zeus {
|
||||
class ServiceProxy {
|
||||
protected:
|
||||
zeus::ServiceRemote& m_srv; //!< Service instance handle
|
||||
public:
|
||||
ServiceProxy(zeus::ServiceRemote& _srv);
|
||||
/**
|
||||
* @brief Get the list of extention of this service
|
||||
* @return List of all extention availlable
|
||||
*/
|
||||
virtual zeus::Future<std::vector<std::string>> getExtention();
|
||||
};
|
||||
}
|
@ -9,23 +9,12 @@
|
||||
|
||||
|
||||
|
||||
zeus::ServiceRemoteBase::ServiceRemoteBase(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name, uint16_t _localId, uint16_t _localObjectId):
|
||||
zeus::WebObj(_clientLink, _localId, _localObjectId),
|
||||
m_name(_name),
|
||||
m_serviceId(0),
|
||||
zeus::ServiceRemoteBase::ServiceRemoteBase(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_isLinked(false) {
|
||||
if (m_interfaceWeb == nullptr) {
|
||||
return;
|
||||
}
|
||||
// little hack : Call the service manager with the service ID=0 ...
|
||||
zeus::Future<uint32_t> ret = m_interfaceWeb->call(getFullId(), ZEUS_GATEWAY_ADDRESS, "link", _name);
|
||||
ret.wait();
|
||||
if (ret.hasError() == true) {
|
||||
ZEUS_WARNING("Can not link with the service named: '" << _name << "' ==> link error");
|
||||
return;
|
||||
}
|
||||
m_isLinked = true;
|
||||
m_serviceId = ret.get();
|
||||
}
|
||||
|
||||
zeus::ServiceRemoteBase::~ServiceRemoteBase() {
|
||||
@ -54,7 +43,7 @@ bool zeus::ServiceRemoteBase::exist() const {
|
||||
}
|
||||
|
||||
const std::string& zeus::ServiceRemoteBase::getName() const {
|
||||
return m_name;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
zeus::ServiceRemote::ServiceRemote(ememory::SharedPtr<zeus::ServiceRemoteBase> _interface):
|
||||
|
@ -24,7 +24,7 @@ namespace zeus {
|
||||
class ServiceRemoteBase : public zeus::WebObj {
|
||||
friend class ServiceRemote;
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_type;
|
||||
uint32_t m_serviceId;
|
||||
bool m_isLinked;
|
||||
public:
|
||||
@ -42,7 +42,7 @@ namespace zeus {
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
ServiceRemoteBase(ememory::SharedPtr<zeus::WebServer> _clientLink, const std::string& _name, uint16_t _localId, uint16_t _localObjectId);
|
||||
ServiceRemoteBase(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _localId, uint16_t _localObjectId, uint32_t _address, const std::string& _type);
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
|
@ -34,22 +34,24 @@ zeus::WebServer::WebServer() :
|
||||
m_connection(),
|
||||
m_localAddress(0),
|
||||
m_licalIdObjectIncrement(1),
|
||||
m_interfaceId(0),
|
||||
m_transmissionId(1),
|
||||
m_observerElement(nullptr),
|
||||
m_threadAsync(nullptr) {
|
||||
m_interfaceId = interfaceId++;
|
||||
m_threadAsyncRunning = false;
|
||||
m_transmissionId = 1;
|
||||
}
|
||||
|
||||
zeus::WebServer::WebServer(enet::Tcp _connection, bool _isServer) :
|
||||
m_connection(),
|
||||
m_localAddress(0),
|
||||
m_licalIdObjectIncrement(1),
|
||||
m_interfaceId(0),
|
||||
m_transmissionId(1),
|
||||
m_observerElement(nullptr),
|
||||
m_threadAsync(nullptr) {
|
||||
m_interfaceId = interfaceId++;
|
||||
m_threadAsyncRunning = false;
|
||||
m_transmissionId = 1;
|
||||
setInterface(std::move(_connection), _isServer);
|
||||
}
|
||||
|
||||
@ -217,6 +219,18 @@ void zeus::WebServer::onReceiveData(std::vector<uint8_t>& _frame, bool _isBinary
|
||||
return;
|
||||
}
|
||||
ememory::SharedPtr<zeus::Buffer> dataRaw = zeus::Buffer::create(_frame);
|
||||
if (dataRaw == nullptr) {
|
||||
ZEUS_ERROR("Buffer Allocation ERROR ... ");
|
||||
disconnect(true);
|
||||
return;
|
||||
}
|
||||
if ( m_localAddress != 0
|
||||
&& dataRaw->getSource() == 0
|
||||
&& dataRaw->getDestination() == 0) {
|
||||
ZEUS_ERROR("Protocol ERROR ... " << dataRaw);
|
||||
disconnect(true);
|
||||
return;
|
||||
}
|
||||
dataRaw->setInterfaceId(m_interfaceId);
|
||||
newBuffer(dataRaw);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user