[DEV) write code to return object and service in generique mode is done, runtime bug ...

This commit is contained in:
Edouard DUPIN 2016-12-02 00:20:26 +01:00
parent aabcf5b9ce
commit db1affa89c
24 changed files with 191 additions and 103 deletions

View File

@ -390,6 +390,7 @@ class ServiceDefinition:
filename = ""
for elem in self.name[:-1]:
filename += elem + "/"
register_filename = filename + "register" + self.name[-1] + ".hpp";
filename += self.name[-1] + ".cpp";
out = ""
@ -409,6 +410,7 @@ class ServiceDefinition:
out += " */\n"
out += "\n"
out += "#include <" + filename.replace(".cpp",".hpp") + ">\n"
out += "#include <" + register_filename + ">\n"
out += "#include <etk/types.hpp>\n"
out += "#include <zeus/Buffer.hpp>\n"
out += "#include <zeus/BufferData.hpp>\n"
@ -418,37 +420,47 @@ class ServiceDefinition:
out += "#include <zeus/AbstractFunction.hpp>\n"
out += "#include <climits>\n"
out += "#include <etk/os/FSNode.hpp>\n"
out += "#include <zeus/mineType.hpp>\n"
out += "#include <zeus/BufferParameter.hpp>\n"
out += "#include <zeus/WebServer.hpp>\n"
out += "#include <zeus/Object.hpp>\n"
out += "\n"
# now gebnerate the get and set parameter object ...
out += "namespace zeus {\n"
"""
out += " template<> const zeus::ParamType& createType<" + class_name + ">() {\n"
out += " static zeus::ParamType type(\"obj:" + class_name + "\", zeus::paramTypeObject, false, false);\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 += " return type;\n"
out += " }\n"
"""
out += " template<>\n"
out += " void BufferParameter::addParameter<" + class_name + ">(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const ememory::SharedPtr<" + class_name + ">& _value) {\n"
out += " void BufferParameter::addParameter<ememory::SharedPtr<" + class_name + ">>(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _paramId, const ememory::SharedPtr<" + class_name + ">& _value) {\n"
out += " std::vector<uint8_t> data;\n"
"""
out += " addType(data, createType<" + class_name + ">());\n"
"""
out += " addTypeObject(data, \"" + class_name + "\");\n"
if object == True:
out += " addTypeObject(data, \"" + class_name + "\");\n"
else:
out += " addTypeService(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"
out += " uint32_t fullId = 0;\n"
# convert the object in a real System Object ....
out += " if (_iface != nullptr) {\n"
out += " uint16_t id = _iface->getAdress();\n"
out += " uint16_t idObj = _iface->getNewObjectId();\n"
out += " ememory::SharedPtr<zeus::ObjectType<" + class_name + ">> obj(_iface, idObj, _value);\n"
out += " " + namespace + "register" + self.name[-1] + "(_value);\n"
out += " _iface->addObject(obj)\n"
out += " fullId = (uint32_t(id)<<16)+idObj\n"
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 += " " + namespace + "register" + self.name[-1] + "(*obj);\n"
out += " _iface2->addWebObj(obj);\n"
out += " fullId = (uint32_t(id)<<16)+idObj;\n"
out += " }\n"
# return Object ID and interface adress
out += " memcpy(&data[currentOffset], &fullId, 4);\n"
@ -505,26 +517,17 @@ class ServiceDefinition:
else:
out += space + "void register" + self.name[-1] + "(zeus::ServiceType<" + class_name + ">& _interface);\n"
out += space + "\n"
if object == False:
out += space + "template<class " + MACRO_BASE_NAME + "TYPE>\n"
out += space + "zeus::Object* create" + self.name[-1] + "(zeus::Client* _client, uint16_t _objectId, uint16_t _clientId, zeus::ServiceType<" + class_name + ">::factory _factory) {\n"
out += space + " zeus::ServiceType<" + class_name + ">* tmp = nullptr;\n"
out += space + " tmp = new zeus::ServiceType<" + class_name + ">(_client, _objectId, _clientId, _factory);\n"
out += space + " zeus::service::register" + self.name[-1] + "(*tmp);\n"
out += space + " return tmp;\n"
out += space + "}\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 zeus::Object* SERVICE_IO_instanciate(zeus::Client* _client, uint16_t _objectId, uint16_t _clientId) { \\\n"
out += space + " return " + namespace + "create" + self.name[-1] + "<type>(_client, _objectId, _clientId, \\\n"
out += space + " [](uint16_t _clientId){ \\\n"
out += space + " return ememory::makeShared<type>(_clientId); \\\n"
out += space + " }); \\\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, _destination, uint32_t(_iface->getAddress())<<16, tmp2); \\\n"
out += space + " }\n"
out += space + "\n"
"""

View File

@ -186,7 +186,7 @@ int main(int _argc, const char *_argv[]) {
}
}
}
#if 1
#if 0
echrono::Steady start = echrono::Steady::now();
//zeus::File tmp("./testzz.png");
zeus::File tmp("./tmpResult.bmp");

View File

@ -21,7 +21,7 @@
typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], std::string _basePath);
typedef bool (*SERVICE_IO_uninit_t)();
typedef zeus::Object* (*SERVICE_IO_instanciate_t)(zeus::Client* _realClient, uint16_t _serviceId, uint16_t _clientId);
typedef zeus::Object* (*SERVICE_IO_instanciate_t)(uint32_t, ememory::SharedPtr<zeus::WebServer>&, uint32_t);
class PlugginAccess {
private:
@ -83,9 +83,8 @@ class PlugginAccess {
if (m_SERVICE_IO_instanciate == nullptr) {
return false;
}
_client.serviceAdd(m_name, [=](zeus::Client* _realClient, uint16_t _serviceId, uint16_t _clientId) {
ememory::SharedPtr<zeus::Object> out((*m_SERVICE_IO_instanciate)(_realClient, _serviceId, _clientId));
return out;
_client.serviceAdd(m_name, [=](uint32_t _transactionId, ememory::SharedPtr<zeus::WebServer>& _iface, uint32_t _destination) {
(*m_SERVICE_IO_instanciate)(_transactionId, _iface, _destination);
});
return true;
}

View File

@ -19,6 +19,7 @@
#include <zeus/service/Picture.hpp>
#include <zeus/service/registerPicture.hpp>
#include <zeus/ProxyClientProperty.hpp>
static std::mutex g_mutex;
static std::string g_basePath;
@ -36,7 +37,7 @@ namespace appl {
class PictureService : public zeus::service::Picture {
private:
//ememory::SharedPtr<zeus::ClientProperty>& m_client;
ememory::SharedPtr<zeus::ClientProperty> m_client;
zeus::ProxyClientProperty m_client;
std::string m_userName;
public:
/*

View File

@ -9,7 +9,7 @@ vector:string getSubAlbums(string)
uint32 getAlbumCount(string)
vector:string getAlbumListPicture(string)
//file getAlbumPicture(string)
string addFile(file)
//string addFile(file)
bool removeFile(string)
/*
// ----------------- Get media with their ID -----------------------

View File

@ -30,7 +30,8 @@ def configure(target, my_module):
my_module.add_depend([
'zeus',
'ejson',
'zeus-service-picture'
'zeus-service-picture',
'zeus-service-user'
])
my_module.add_src_file([
'appl/debug.cpp',

View File

@ -0,0 +1,16 @@
#elem-brief: File Object interface
#elem-version: 1.0
#elem-type:FILE
#elem-author:Heero Yui<yui.heero@gmail.com>
#brief:Get size of the file
#return:current size of the file
uint64 size()
#brief:Get the file "mine-type"
#return:string of the mine-type
string getMineType()
#brief:get a part of the file (size < 25Mo)
#return:Buffer with the data
buffer getPart(uint64, uint64)

View File

@ -16,6 +16,7 @@
#include <zeus/service/User.hpp>
#include <zeus/service/registerUser.hpp>
#include <zeus/ProxyClientProperty.hpp>
static std::mutex g_mutex;
static std::string g_basePath;
@ -25,7 +26,7 @@ static ejson::Document g_database;
namespace appl {
class SystemService : public zeus::service::User {
private:
ememory::SharedPtr<zeus::ClientProperty> m_client;
zeus::ProxyClientProperty m_client;
std::string m_userName;
public:
/*
@ -45,11 +46,13 @@ namespace appl {
std::vector<std::string> clientGroupsGet(std::string _clientName) {
APPL_WARNING("call clientGroupsGet : " << _clientName);
std::vector<std::string> out;
/*
if (m_client == nullptr) {
return out;
}
*/
// TODO: check if basished ...
if (m_client->getName() != "") {
if (m_client.getName().get() != "") {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
ejson::Object clients = g_database["client"].toObject();
@ -57,7 +60,7 @@ namespace appl {
// Section never created
return out;
}
ejson::Object client = clients[m_client->getName()].toObject();
ejson::Object client = clients[m_client.getName().get()].toObject();
if (clients.exist() == false) {
// No specificity for this client (in case it have no special right)
return out;

View File

@ -0,0 +1,12 @@
#elem-brief: client property struture
#elem-version: 1.0
#elem-author:Heero Yui<yui.heero@gmail.com>
#brief:Name of the client
string name
#brief:List of group of the Client
vector:string groups
#brief:List of the authorised functions
vector:string listAthorizedFunction

View File

@ -19,6 +19,7 @@
#include <zeus/service/Video.hpp>
#include <zeus/service/registerVideo.hpp>
#include <zeus/ProxyClientProperty.hpp>
static std::mutex g_mutex;
static std::string g_basePath;
@ -35,7 +36,7 @@ static uint64_t createFileID() {
namespace appl {
class VideoService : public zeus::service::Video {
private:
ememory::SharedPtr<zeus::ClientProperty> m_client;
zeus::ProxyClientProperty m_client;
std::string m_userName;
public:
/*

View File

@ -30,7 +30,8 @@ def configure(target, my_module):
my_module.add_depend([
'zeus',
'ejson',
'zeus-service-video'
'zeus-service-video',
'zeus-service-user'
])
my_module.add_src_file([
'appl/debug.cpp',

View File

@ -305,6 +305,12 @@ namespace zeus {
* @param[in] _type string of the type to add
*/
void addTypeObject(std::vector<uint8_t>& _data, const std::string _type);
/**
* @brief Add a parameter object type in the buffer
* @param[in] _data Buffer to add type
* @param[in] _type string of the type to add
*/
void addTypeService(std::vector<uint8_t>& _data, const std::string _type);
/**
* @brief Add a parameter RAW type in the buffer
* @param[in] _data Buffer to add type

View File

@ -30,6 +30,15 @@ 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));

View File

@ -19,9 +19,7 @@ void zeus::Client::answerProtocolError(uint32_t _transactionId, const std::strin
zeus::Client::Client() :
propertyIp(this, "ip", "127.0.0.1", "Ip to connect server", &zeus::Client::onPropertyChangeIp),
propertyPort(this, "port", 1983, "Port to connect server", &zeus::Client::onPropertyChangePort),
m_localAddress(0),
m_licalIdObjectIncrement(1) {
propertyPort(this, "port", 1983, "Port to connect server", &zeus::Client::onPropertyChangePort) {
}
@ -56,9 +54,9 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
return;
}
// Check if we are the destinated Of this message
if (_value->getDestinationId() != m_localAddress) {
ZEUS_ERROR("Protocol error ==> Wrong ID of the interface " << _value->getDestinationId() << " != " << m_localAddress);
answerProtocolError(transactionId, "wrong adress: request " + etk::to_string(m_localAddress) + " have " + etk::to_string(m_localAddress));
if (_value->getDestinationId() != m_interfaceWeb->getAddress()) {
ZEUS_ERROR("Protocol error ==> Wrong ID of the interface " << _value->getDestinationId() << " != " << m_interfaceWeb->getAddress());
answerProtocolError(transactionId, "wrong adress: request " + etk::to_string(_value->getDestinationId()) + " have " + etk::to_string(m_interfaceWeb->getAddress()));
return;
}
if (_value->getDestinationObjectId() == ZEUS_ID_GATEWAY_OBJECT) {
@ -76,18 +74,22 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
for (auto &it : m_listServicesAvaillable) {
if (it.first == serviceName) {
ZEUS_INFO("find service : " << it.first);
// TODO: ...
// Create new service object
it.second(transactionId, m_interfaceWeb, _value->getSource());
// TODO : Do it better ...
/*
// Check if it is not already connected to this service, if it is true ==> reject IT
// Create new service object
ememory::SharedPtr<zeus::Object> newService = it.second(this, m_licalIdObjectIncrement, _value->getSourceId());
uint16_t tmpId = m_interfaceWeb->getNewObjectId();
ememory::SharedPtr<zeus::Object> newService = it.second(this, tmpId, _value->getSourceId());
// TODO : Do it better ...
m_listProvicedService.push_back(newService);
//m_listProvicedService.push_back(newService);
// Return the Value of the object service .... this is really bad, Maybe add a message type for this...
m_interfaceWeb->answerValue(transactionId, _value->getDestination(), _value->getSource(), (uint32_t(m_localAddress)<<16)+m_licalIdObjectIncrement );
m_licalIdObjectIncrement++;
m_interfaceWeb->answerValue(transactionId, _value->getDestination(), _value->getSource(), (uint32_t(m_interfaceWeb->getAddress())<<16)+tmpId);
*/
return;
}
}
@ -99,21 +101,12 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Buffer> _value) {
}
// find the object to communicate the adress to send value ...
uint16_t objId = _value->getDestinationObjectId();
for (auto &it : m_listProvicedService) {
if (it == nullptr) {
continue;
}
if (it->getObjectId() == objId) {
it->receive(_value);
return;
}
}
ZEUS_ERROR("Get Data On the Communication interface that is not understand ... : " << _value);
}
bool zeus::Client::serviceAdd(const std::string& _serviceName, factoryService _factory) {
// Check if we can provide new service:
zeus::Future<bool> futValidate = m_interfaceWeb->call(uint32_t(m_localAddress)<<16, ZEUS_GATEWAY_ADDRESS, "serviceAdd", _serviceName);
zeus::Future<bool> futValidate = m_interfaceWeb->call(uint32_t(m_interfaceWeb->getAddress())<<16, ZEUS_GATEWAY_ADDRESS, "serviceAdd", _serviceName);
futValidate.wait(); // TODO: Set timeout ...
if (futValidate.hasError() == true) {
ZEUS_ERROR("Can not provide a new sevice ... '" << futValidate.getErrorType() << "' help:" << futValidate.getErrorHelp());
@ -125,7 +118,7 @@ bool zeus::Client::serviceAdd(const std::string& _serviceName, factoryService _f
bool zeus::Client::serviceRemove(const std::string& _serviceName) {
// Check if we can provide new service:
zeus::Future<bool> futValidate = m_interfaceWeb->call(uint32_t(m_localAddress)<<16, ZEUS_GATEWAY_ADDRESS, "serviceRemove", _serviceName);
zeus::Future<bool> futValidate = m_interfaceWeb->call(uint32_t(m_interfaceWeb->getAddress())<<16, ZEUS_GATEWAY_ADDRESS, "serviceRemove", _serviceName);
futValidate.wait(); // TODO: Set timeout ...
if (futValidate.hasError() == true) {
ZEUS_ERROR("Can not provide a new sevice ... '" << futValidate.getErrorType() << "' help:" << futValidate.getErrorHelp());
@ -148,7 +141,8 @@ zeus::ServiceRemote zeus::Client::getService(const std::string& _name) {
return zeus::ServiceRemote(val);
}
}
ememory::SharedPtr<zeus::ServiceRemoteBase> tmp = ememory::makeShared<zeus::ServiceRemoteBase>(m_interfaceWeb, _name, m_localAddress, m_licalIdObjectIncrement++);
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);
}
@ -181,7 +175,7 @@ bool zeus::Client::connectTo(const std::string& _address) {
disconnect();
return false;
}
m_localAddress = retIdentify.get();
m_interfaceWeb->setAddress(retIdentify.get());
/*
ZEUS_WARNING("Now, we get information relative with our name and adress" << _address);

View File

@ -15,6 +15,7 @@
#include <zeus/Object.hpp>
namespace zeus {
class Object;
/**
* @brief Client interface to acces on the remote service and gateway
*/
@ -24,13 +25,11 @@ namespace zeus {
eproperty::Value<std::string> propertyIp; //!< Ip of WebSocket TCP connection
eproperty::Value<uint16_t> propertyPort; //!< Port of the WebSocket connection
public:
uint16_t m_localAddress;
uint16_t m_licalIdObjectIncrement; //!< attribute a unique ID for an object
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::SharedPtr<zeus::Object>> m_listProvicedService; //!< Connect only one time on each service, not needed more.
//std::vector<ememory::SharedPtr<zeus::Object>> m_listLocalObject;
public:
void answerProtocolError(uint32_t _transactionId, const std::string& _errorHelp);
ememory::SharedPtr<zeus::WebServer> getWebInterface() {
@ -89,7 +88,7 @@ namespace zeus {
* @return Pointer on an interface of remote service
*/
zeus::ServiceRemote getService(const std::string& _serviceName);
using factoryService = std::function<ememory::SharedPtr<zeus::Object>(zeus::Client*, uint16_t, uint16_t)>; // pointer on this, object ID, client creator ID
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
/**
@ -123,11 +122,11 @@ namespace zeus {
ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
return zeus::FutureBase(0, ret);
}
uint32_t source = (uint32_t(m_localAddress) << 16) + _srcObjectId;
uint32_t source = (uint32_t(m_interfaceWeb->getAddress()) << 16) + _srcObjectId;
return m_interfaceWeb->call(source, _destination, _functionName, _args...);
}
uint16_t getlocalAddress() {
return m_localAddress;
return m_interfaceWeb->getAddress();
}
private:
/**

View File

@ -12,22 +12,22 @@
zeus::Object::Object(zeus::Client* _client, uint16_t _objectId) :
/*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->getAdress(), _objectId),
m_clientId(_iface->getAdress()),
zeus::RemoteProcessCall(_iface, _iface->getAddress(), _objectId),
m_clientId(_iface->getAddress()),
m_objectId(_objectId) {
}

View File

@ -12,6 +12,7 @@
#include <zeus/debug.hpp>
#include <zeus/RemoteProcessCall.hpp>
#include <zeus/Future.hpp>
#include <zeus/Client.hpp>
/**
* @brief Main zeus library namespace
@ -37,7 +38,7 @@ namespace zeus {
* @param[in]
* @return
*/
Object(zeus::Client* _client, uint16_t _objectId);
//Object(zeus::Client* _client, uint16_t _objectId);
Object(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _objectId);
/**
* @brief
@ -46,11 +47,6 @@ namespace zeus {
*/
virtual ~Object();
public:
/**
* @brief
* @param[in]
* @return
*/
void receive(ememory::SharedPtr<zeus::Buffer> _value);
private:
/**
@ -107,11 +103,11 @@ namespace zeus {
/*
ObjectType(zeus::Client* _client, uint16_t _objectId, uint16_t _clientId) :
Object(_client, _objectId) {
m_interface = ememory::makeShared<ZEUS_TYPE_OBJECT>(_clientId);
m_interface = ememory::makeShared<ZEUS_TYPE_OBJECT>(/ *_clientId* /);
}
*/
ObjectType(zeus::Client* _client, uint16_t _objectId, const ememory::SharedPtr<ZEUS_TYPE_OBJECT>& _element) :
Object(_client, _objectId),
ObjectType(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t _objectId, const ememory::SharedPtr<ZEUS_TYPE_OBJECT>& _element) :
Object(_iface, _objectId),
m_interface(_element) {
// nothing else to do ...
}
@ -181,19 +177,19 @@ namespace zeus {
switch (it2->getType()) {
case zeus::AbstractFunction::type::object: {
ZEUS_TYPE_OBJECT* elem = m_interface.get();
it2->execute(m_interfaceClient, _obj, (void*)elem);
it2->execute(m_interfaceWeb, _obj, (void*)elem);
return;
}
case zeus::AbstractFunction::type::local: {
it2->execute(m_interfaceClient, _obj, (void*)((RemoteProcessCall*)this));
it2->execute(m_interfaceWeb, _obj, (void*)((RemoteProcessCall*)this));
return;
}
case zeus::AbstractFunction::type::service: {
it2->execute(m_interfaceClient, _obj, (void*)this);
it2->execute(m_interfaceWeb, _obj, (void*)this);
return;
}
case zeus::AbstractFunction::type::global: {
it2->execute(m_interfaceClient, _obj, nullptr);
it2->execute(m_interfaceWeb, _obj, nullptr);
return;
}
case zeus::AbstractFunction::type::unknow:
@ -201,7 +197,7 @@ namespace zeus {
break;
}
}
m_interfaceClient->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "FUNCTION-UNKNOW", "not find function name: '" + _call + "'");
m_interfaceWeb->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "FUNCTION-UNKNOW", "not find function name: '" + _call + "'");
return;
}
};

View File

@ -132,5 +132,6 @@ 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::paramTypeRaw = 0xFFFE;
const uint16_t zeus::paramTypeService = 0xFFFE;
const uint16_t zeus::paramTypeRaw = 0xFFFD;

View File

@ -89,6 +89,7 @@ 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

View File

@ -100,15 +100,21 @@ namespace zeus {
template<class ZEUS_TYPE_SERVICE>
class ServiceType : public zeus::Object {
public:
using factory = std::function<ememory::SharedPtr<ZEUS_TYPE_SERVICE>(uint16_t)>;
//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(zeus::Client* _client, uint16_t _objectId, uint16_t _clientId, factory _factory) :
Object(_client, _objectId) {
/*
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) :
@ -253,7 +259,7 @@ namespace zeus {
/*
auto it = m_interface.find(_obj->getSourceId());
if (it == m_interface.end()) {
m_interfaceClient->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "CLIENT-UNKNOW", "");
m_interfaceWeb->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "CLIENT-UNKNOW", "");
return;
}
*/
@ -267,19 +273,19 @@ namespace zeus {
switch (it2->getType()) {
case zeus::AbstractFunction::type::object: {
ZEUS_TYPE_SERVICE* elem = m_interface.get();
it2->execute(m_interfaceClient, _obj, (void*)elem);
it2->execute(m_interfaceWeb, _obj, (void*)elem);
return;
}
case zeus::AbstractFunction::type::local: {
it2->execute(m_interfaceClient, _obj, (void*)((RemoteProcessCall*)this));
it2->execute(m_interfaceWeb, _obj, (void*)((RemoteProcessCall*)this));
return;
}
case zeus::AbstractFunction::type::service: {
it2->execute(m_interfaceClient, _obj, (void*)this);
it2->execute(m_interfaceWeb, _obj, (void*)this);
return;
}
case zeus::AbstractFunction::type::global: {
it2->execute(m_interfaceClient, _obj, nullptr);
it2->execute(m_interfaceWeb, _obj, nullptr);
return;
}
case zeus::AbstractFunction::type::unknow:
@ -287,7 +293,7 @@ namespace zeus {
break;
}
}
m_interfaceClient->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "FUNCTION-UNKNOW", "");
m_interfaceWeb->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "FUNCTION-UNKNOW", "");
return;
}
};

View File

@ -14,7 +14,7 @@
#include <zeus/WebObj.hpp>
namespace zeus {
class Client;
//class Client;
class ServiceRemote;
/**
* @brief

View File

@ -26,6 +26,9 @@ namespace zeus {
uint32_t getFullId() {
return (uint32_t(m_id) << 16 ) + m_objectId;
}
virtual void receive(ememory::SharedPtr<zeus::Buffer> _value) {
ZEUS_ERROR("Receive a message ==> not implemented magaging ..." << _value);
}
};
}

View File

@ -32,6 +32,8 @@ static uint32_t interfaceId = 1;
zeus::WebServer::WebServer() :
m_connection(),
m_localAddress(0),
m_licalIdObjectIncrement(1),
m_observerElement(nullptr),
m_threadAsync(nullptr) {
m_interfaceId = interfaceId++;
@ -41,6 +43,8 @@ zeus::WebServer::WebServer() :
zeus::WebServer::WebServer(enet::Tcp _connection, bool _isServer) :
m_connection(),
m_localAddress(0),
m_licalIdObjectIncrement(1),
m_observerElement(nullptr),
m_threadAsync(nullptr) {
m_interfaceId = interfaceId++;
@ -71,6 +75,10 @@ void zeus::WebServer::setInterfaceName(const std::string& _name) {
//ethread::setName(*m_thread, "Tcp-" + _name);
}
void zeus::WebServer::addWebObj(ememory::SharedPtr<zeus::WebObj> _obj) {
m_listObject.push_back(_obj);
}
bool zeus::WebServer::isActive() const {
return m_connection.isAlive();
@ -257,6 +265,16 @@ void zeus::WebServer::newBuffer(ememory::SharedPtr<zeus::Buffer> _buffer) {
}
}
if (future.isValid() == false) {
uint32_t dest = _buffer->getDestination();
for (auto &it : m_listObject) {
if (it == nullptr) {
continue;
}
if (it->getFullId() == dest) {
it->receive(_buffer);
return;
}
}
// not a pending call ==> simple event or call ...
if (m_observerElement != nullptr) {
m_observerElement(_buffer);

View File

@ -91,6 +91,24 @@ namespace zeus {
std::vector<ememory::SharedPtr<zeus::WebObj>> m_actifObject; //!< List of all active object created and that remove is in progress ...
private:
enet::WebSocket m_connection;
uint16_t m_localAddress;
uint16_t m_licalIdObjectIncrement; //!< attribute a unique ID for an object
public:
uint16_t getAddress() const {
return m_localAddress;
}
void setAddress(uint16_t _address) {
m_localAddress = _address;
}
uint16_t getNewObjectId() {
return m_licalIdObjectIncrement++;
}
private:
std::vector<ememory::SharedPtr<zeus::WebObj>> m_listObject;
public:
void addWebObj(ememory::SharedPtr<zeus::WebObj> _obj);
private:
uint32_t m_interfaceId;
uint16_t m_transmissionId;
uint16_t getId() {