[DEV] nearly work, need to update the get and set parameter with the web interface

This commit is contained in:
Edouard DUPIN 2016-12-05 22:17:47 +01:00
parent e49c34b260
commit 615486529d
13 changed files with 277 additions and 62 deletions

View File

@ -45,10 +45,36 @@ def get_list_type():
out.append(elem[0])
return out
def convert_type_in_cpp(data):
def validate_type(data):
if data in get_list_type():
return True
val = data.split(":")
if val[0] == "obj":
return True
return False
def convert_type_in_cpp(data, proxy=False, argument=False):
for elem in list_of_known_type:
if data == elem[0]:
return elem[1]
val = data.split(":")
if val[0] == "obj":
# this is a generated object:
listElem = val[1].split("-")
out = ""
for elem in listElem[:-1]:
out += elem + "::"
if proxy == True:
if argument == False:
out += "Proxy" + listElem[-1]
else:
out = "ememory::SharedPtr<" + out + listElem[-1] + ">"
else:
if argument == True:
out += "Proxy" + listElem[-1]
else:
out = "ememory::SharedPtr<" + out + listElem[-1] + ">"
return out
debug.error(" can not find type in IDL : '" + data + "'")
@ -190,14 +216,14 @@ class FunctionDefinition:
out = "";
out += self.generate_doxy(space)
out += space + "virtual "
out += convert_type_in_cpp(self.return_type) + " " + self.name + "("
out += convert_type_in_cpp(self.return_type, False, False) + " " + self.name + "("
param_data = ""
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
if len(param_data) != 0:
param_data += ", "
param_data += convert_type_in_cpp(elem["type"]) + " _"
param_data += convert_type_in_cpp(elem["type"], False, True) + " _"
if elem["name"] == "":
param_data += "no_name_param_" + str(id_parameter)
else:
@ -209,14 +235,14 @@ class FunctionDefinition:
def generate_hpp_proxy(self, space):
out = "";
out += self.generate_doxy(space)
out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + self.name + "("
out += space + "virtual zeus::Future<" + convert_type_in_cpp(self.return_type, True, False) + "> " + self.name + "("
param_data = ""
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
if len(param_data) != 0:
param_data += ", "
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _"
param_data += "const " + convert_type_in_cpp(elem["type"], True, True) + "& _"
if elem["name"] == "":
param_data += "no_name_param_" + str(id_parameter)
else:
@ -226,14 +252,14 @@ class FunctionDefinition:
return out;
def generate_cpp_proxy(self, space, class_name):
out = "";
out += space + "zeus::Future<" + convert_type_in_cpp(self.return_type) + "> " + class_name + "::" + self.name + "("
out += space + "zeus::Future<" + convert_type_in_cpp(self.return_type, True, False) + "> " + class_name + "::" + self.name + "("
param_data = ""
id_parameter = 0
for elem in self.parameters:
id_parameter += 1
if len(param_data) != 0:
param_data += ", "
param_data += "const " + convert_type_in_cpp(elem["type"]) + "& _"
param_data += "const " + convert_type_in_cpp(elem["type"], True, True) + "& _"
if elem["name"] == "":
param_data += "no_name_param_" + str(id_parameter)
else:
@ -266,6 +292,7 @@ class ServiceDefinition:
self.authors = []
self.attributes = []
self.functions = []
self.imports = []
def set_name(self, value):
self.name = value
@ -292,6 +319,9 @@ class ServiceDefinition:
# TODO : Check if attribute already exist
self.attributes.append(value)
def add_import(self, value):
self.imports.append(value)
def display(self):
debug.info("Display service definition : ")
debug.info(" name: " + str(self.name))
@ -322,11 +352,18 @@ class ServiceDefinition:
out += "#include <zeus/Raw.hpp>\n"
out += "#include <string>\n"
out += "#include <vector>\n"
out += "#include <ememory/memory.hpp>\n"
for elem in self.imports:
out += "#include <" + elem.replace("-","/") + ".hpp>\n"
out += "#include <" + elem.replace("-","/Proxy") + ".hpp>\n"
out += "\n"
space = ""
class_name = ""
for elem in self.name[:-1]:
out += space + "namespace " + elem + " {\n"
space += " "
class_name += elem + "::"
class_name += self.name[-1]
out += space + " /**\n"
if self.brief != "":
@ -345,6 +382,11 @@ class ServiceDefinition:
out += space + "/**\n"
out += space + " * @brief Generic virtual destructor\n"
out += space + " */\n"
out += space + "template<typename ... ZEUS_OBJECT_CREATE>\n"
out += space + "static ememory::SharedPtr<" + class_name + "> create(ZEUS_OBJECT_CREATE ...);\n"
out += space + "/**\n"
out += space + " * @brief Generic virtual destructor\n"
out += space + " */\n"
out += space + "virtual ~" + self.name[-1] + "() = default;\n"
for elem in self.attributes:
@ -366,12 +408,14 @@ class ServiceDefinition:
for elem in self.name[:-1]:
filename += elem + "/"
register_filename = filename + "register" + self.name[-1] + ".hpp";
register_filename_proxy = filename + "Proxy" + self.name[-1] + ".hpp";
filename += self.name[-1] + ".cpp";
out = ""
class_name = ""
for elem in self.name[:-1]:
class_name += "" + elem + "::"
class_name_proxy = class_name + "Proxy" + self.name[-1];
class_name += self.name[-1];
namespace = ""
@ -386,6 +430,7 @@ class ServiceDefinition:
out += "\n"
out += "#include <" + filename.replace(".cpp",".hpp") + ">\n"
out += "#include <" + register_filename + ">\n"
out += "#include <" + register_filename_proxy + ">\n"
out += "#include <etk/types.hpp>\n"
out += "#include <zeus/Buffer.hpp>\n"
out += "#include <zeus/BufferData.hpp>\n"
@ -406,6 +451,12 @@ class ServiceDefinition:
out += " static zeus::ParamType type(\"obj:" + class_name + "\", zeus::paramTypeObject, false, false);\n"
out += " return type;\n"
out += " }\n"
out += " \n"
out += " template<> const zeus::ParamType& createType<" + class_name_proxy + ">() {\n"
out += " static zeus::ParamType type(\"obj:" + class_name + "\", zeus::paramTypeObject, false, false);\n"
out += " return type;\n"
out += " }\n"
out += " \n"
out += " template<>\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"
@ -433,7 +484,13 @@ class ServiceDefinition:
out += " memcpy(&data[currentOffset], &fullId, 4);\n"
out += " m_parameter.push_back(std::make_pair(startOffset,data));\n"
out += " }\n"
out += " \n"
out += " template<>\n"
out += " " + class_name_proxy + " BufferParameter::getParameter<" + class_name_proxy + ">(const ememory::SharedPtr<zeus::WebServer>& _iface, int32_t _id) const {\n"
out += " ememory::SharedPtr<zeus::ObjectRemoteBase> out;\n"
out += " out = zeus::BufferParameter::getParameter<ememory::SharedPtr<zeus::ObjectRemoteBase>>(_iface, _id);\n"
out += " return zeus::ObjectRemote(out);\n"
out += " }\n"
out += "}\n"
return [filename, out]
@ -814,7 +871,11 @@ def tool_generate_idl(target, module, data_option):
continue
debug.extreme_verbose("Need to parse the fucntion/attribute line:")
debug.extreme_verbose(" '" + line + "'")
if line[-1] == ")":
if line[:7] == "import ":
debug.debug("find import : " + line)
# TODO : Add check ...
service_def.add_import(line.split(" ")[1])
elif line[-1] == ")":
# Find a fundtion ==> parse it
#debug.error("line " + str(id_line) + " Can not parse function the line dos not ended by a ')'")
#get first part (befor '('):
@ -834,10 +895,10 @@ def tool_generate_idl(target, module, data_option):
return_value = list_elems[0]
function_name = list_elems[1]
# check types:
if return_value not in get_list_type():
if validate_type(return_value) == False:
debug.error("line " + str(id_line) + " fucntion return type unknow : '" + return_value + "' not in " + str(get_list_type()))
for elem in argument_list:
if elem not in get_list_type():
if validate_type(elem) == False:
debug.error("line " + str(id_line) + " fucntion argument type unknow : '" + elem + "' not in " + str(get_list_type()))
debug.extreme_verbose(" Parse of function done :")
debug.extreme_verbose(" return:" + return_value)
@ -855,7 +916,7 @@ def tool_generate_idl(target, module, data_option):
elem = line.split(" ")
if len(elem) != 2:
debug.error("line " + str(id_line) + " Can not parse attribute must be constituated with the type and the name")
if elem[0] not in get_list_type():
if validate_type(elem[0]) == False:
debug.error("line " + str(id_line) + " Attribute type unknow : '" + elem[0] + "' not in " + str(get_list_type()))
current_attr.set_type(elem[0]);
current_attr.set_name(elem[1]);

View File

@ -43,6 +43,7 @@ def configure(target, my_module):
'zeus/FutureBase.cpp',
'zeus/Future.cpp',
'zeus/Raw.cpp',
'zeus/FileImpl.cpp',
'zeus/Buffer.cpp',
'zeus/BufferParameter.cpp',
'zeus/BufferCall.cpp',
@ -73,6 +74,7 @@ def configure(target, my_module):
'zeus/FutureBase.hpp',
'zeus/Future.hpp',
'zeus/Raw.hpp',
'zeus/FileImpl.hpp',
'zeus/Buffer.hpp',
'zeus/BufferParameter.hpp',
'zeus/BufferCall.hpp',

View File

@ -16,6 +16,8 @@
#include <etk/stdTools.hpp>
#include <zeus/service/ProxyUser.hpp>
#include <zeus/service/ProxyPicture.hpp>
#include <zeus/ProxyFile.hpp>
#include <zeus/ObjectRemote.hpp>
#include <echrono/Steady.hpp>
@ -162,28 +164,32 @@ int main(int _argc, const char *_argv[]) {
zeus::Future<std::vector<std::string>> retListImage = remoteServicePicture.getAlbumListPicture(it2).wait();
for (auto &it3 : retListImage.get()) {
APPL_INFO(" - " << it3);
zeus::Future<zeus::File> retListImage = remoteServicePicture.getAlbumListPicture(it3).wait();
zeus::File tmpFile = retListImage.get();
APPL_INFO(" mine-type: " << tmpFile.getMineType());
APPL_INFO(" size: " << tmpFile.getData().size());
// TODO : This is really bad : Do it better ...
zeus::Future<ememory::SharedPtr<zeus::ObjectRemoteBase>> retListImage = remoteServicePicture.getAlbumListPicture(it3).wait();
zeus::ProxyFile tmpFile = zeus::ObjectRemote(retListImage.get(client1.m_interfaceWeb));
APPL_INFO(" mine-type: " << tmpFile.getMineType().wait().get());
APPL_INFO(" size: " << tmpFile.size().wait().get());
APPL_INFO(" receive in =" << int64_t(retListImage.getTransmitionTime().count()/1000)/1000.0 << " ms");
std::string tmpFileName = std::string("./out/") + it + "_" + it2 + "_" + it3 + "." + zeus::getExtention(tmpFile.getMineType());
std::string tmpFileName = std::string("./out/") + it + "_" + it2 + "_" + it3 + "." + zeus::getExtention(tmpFile.getMineType().wait().get());
APPL_INFO(" store in: " << tmpFileName);
/*
etk::FSNode node(tmpFileName);
node.fileOpenWrite();
node.fileWrite(&tmpFile.getData()[0], 1, tmpFile.getData().size());
node.fileClose();
*/
}
} else {
APPL_INFO(" - " << it2);
}
}
}
#if 0
#if 1
echrono::Steady start = echrono::Steady::now();
//zeus::File tmp("./testzz.png");
zeus::File tmp("./tmpResult.bmp");
int32_t size = tmp.getData().size();
// TODO : Read file size before ..
int32_t size = 1024;
ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./tmpResult.bmp");
zeus::FutureBase retSendImage = remoteServicePicture.addFile(tmp).wait();
echrono::Steady stop = echrono::Steady::now();
APPL_WARNING(" IO*=" << (stop-start));

View File

@ -20,6 +20,8 @@
#include <zeus/service/Picture.hpp>
#include <zeus/service/registerPicture.hpp>
#include <zeus/ProxyClientProperty.hpp>
#include <zeus/File.hpp>
#include <zeus/ProxyFile.hpp>
static std::mutex g_mutex;
static std::string g_basePath;
@ -185,7 +187,7 @@ namespace appl {
APPL_ERROR(" ==> Not find ...");
return nullptr;
}
std::string addFile(ememory::SharedPtr<zeus::File> _dataFile) {
std::string addFile(zeus::ProxyFile _dataFile) {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
uint64_t id = createFileID();
@ -194,6 +196,7 @@ namespace appl {
zeus::Future<zeus::Raw> data(_data);
zeus::Raw ppp = data.get();
APPL_ERROR("Get data In andThen " << ppp.size());
return true;
});
/*
APPL_ERROR(" ==> Receive FILE " << _dataFile.getMineType() << " size=" << _dataFile.getData().size());

View File

@ -3,13 +3,14 @@
#elem-type:PICTURE
#elem-author:Heero Yui<yui.heero@gmail.com
import zeus-File
vector:string getAlbums()
vector:string getSubAlbums(string)
uint32 getAlbumCount(string)
vector:string getAlbumListPicture(string)
//file getAlbumPicture(string)
//string addFile(file)
//obj:zeus-File getAlbumPicture(string)
string addFile(obj:zeus-File)
bool removeFile(string)
/*
// ----------------- Get media with their ID -----------------------

View File

@ -52,6 +52,7 @@ namespace appl {
}
*/
// TODO: check if basished ...
/*
if (m_client.getName().get() != "") {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
@ -74,6 +75,7 @@ namespace appl {
out.push_back(it.toString().get());
}
}
*/
// TODO: Check default visibility ... (if user want to have default visibility at Noone ==> then public must be removed...
if (true) {
out.push_back("public");

View File

@ -163,6 +163,7 @@ namespace appl {
}
return out;
}
/*
// Return a File Data (might be a picture .tiff/.png/.jpg)
zeus::FileServer getAlbumPicture(std::string _pictureName) {
std::unique_lock<std::mutex> lock(g_mutex);
@ -198,6 +199,11 @@ namespace appl {
m_listFile.insert(std::make_pair(id, filename));
return etk::to_string(id);//zeus::FileServer();
}
*/
/*
// Return a global UTC time
zeus::Time getAlbumPictureTime(std::string _pictureName) {

48
zeus/FileImpl.cpp Normal file
View File

@ -0,0 +1,48 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <zeus/FileImpl.hpp>
#include "debug.hpp"
namespace zeus {
template<>
ememory::SharedPtr<zeus::File> File::create<std::string>(std::string _filename) {
return ememory::makeShared<zeus::FileImpl>(_filename);
}
template<>
ememory::SharedPtr<zeus::File> File::create<const char*>(const char* _filename) {
return ememory::makeShared<zeus::FileImpl>(_filename);
}
}
zeus::FileImpl::FileImpl(std::string _filename) :
m_filename(_filename),
m_node(_filename) {
m_node.fileOpenRead();
}
zeus::FileImpl::~FileImpl() {
m_node.fileClose();
}
uint64_t zeus::FileImpl::size() {
return 4092;
}
std::string zeus::FileImpl::name() {
return m_filename;
}
std::string zeus::FileImpl::getMineType() {
return "audio/x-matroska";
}
zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
return zeus::Raw(4092);
}

26
zeus/FileImpl.hpp Normal file
View File

@ -0,0 +1,26 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <zeus/File.hpp>
#include <etk/os/FSNode.hpp>
namespace zeus {
class FileImpl : public zeus::File {
private:
std::string m_filename;
etk::FSNode m_node;
public:
FileImpl(std::string _filename);
~FileImpl();
uint64_t size() override;
std::string name() override;
std::string getMineType() override;
zeus::Raw getPart(uint64_t _start, uint64_t _stop) override;
};
}

View File

@ -43,6 +43,31 @@ namespace zeus {
* @return requested value
*/
ZEUS_RETURN get(const ememory::SharedPtr<zeus::WebServer>& _iface);
const Future<ZEUS_RETURN>& wait() const {
zeus::FutureBase::wait();
return *this;
}
Future<ZEUS_RETURN>& wait() {
zeus::FutureBase::wait();
return *this;
}
const Future<ZEUS_RETURN>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) const {
zeus::FutureBase::waitFor(_delta);
return *this;
}
Future<ZEUS_RETURN>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) {
zeus::FutureBase::waitFor(_delta);
return *this;
}
const Future<ZEUS_RETURN>& waitUntil(std::chrono::steady_clock::time_point _endTime) const {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
Future<ZEUS_RETURN>& waitUntil(std::chrono::steady_clock::time_point _endTime) {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
};
/**
* @brief future template to cast type in a void methode (fallback)
@ -67,5 +92,29 @@ namespace zeus {
m_data = _base.m_data;
return *this;
}
const Future<void>& wait() const {
zeus::FutureBase::wait();
return *this;
}
Future<void>& wait() {
zeus::FutureBase::wait();
return *this;
}
const Future<void>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) const {
zeus::FutureBase::waitFor(_delta);
return *this;
}
Future<void>& waitFor(std::chrono::microseconds _delta = std::chrono::seconds(30)) {
zeus::FutureBase::waitFor(_delta);
return *this;
}
const Future<void>& waitUntil(std::chrono::steady_clock::time_point _endTime) const {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
Future<void>& waitUntil(std::chrono::steady_clock::time_point _endTime) {
zeus::FutureBase::waitUntil(_endTime);
return *this;
}
};
}

View File

@ -32,6 +32,7 @@ static uint32_t interfaceId = 1;
zeus::WebServer::WebServer() :
m_connection(),
m_processingPool(20),
m_localAddress(0),
m_licalIdObjectIncrement(1),
m_interfaceId(0),
@ -40,10 +41,12 @@ zeus::WebServer::WebServer() :
m_threadAsync(nullptr) {
m_interfaceId = interfaceId++;
m_threadAsyncRunning = false;
}
zeus::WebServer::WebServer(enet::Tcp _connection, bool _isServer) :
m_connection(),
m_processingPool(20),
m_localAddress(0),
m_licalIdObjectIncrement(1),
m_interfaceId(0),
@ -71,6 +74,9 @@ void zeus::WebServer::setInterface(enet::Tcp _connection, bool _isServer, const
zeus::WebServer::~WebServer() {
disconnect();
m_processingPool.stop();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // TODO : Remove this ...
m_processingPool.join();
}
void zeus::WebServer::setInterfaceName(const std::string& _name) {
@ -241,27 +247,9 @@ void zeus::WebServer::ping() {
void zeus::WebServer::newBuffer(ememory::SharedPtr<zeus::Buffer> _buffer) {
ZEUS_LOG_INPUT_OUTPUT("Receive :" << _buffer);
// Try to find in the current call that has been done to add data in an answer :
zeus::FutureBase future;
uint64_t tid = _buffer->getTransactionId();
if (tid == 0) {
ZEUS_ERROR("Get a Protocol error ... No ID ...");
/*
if (obj["error"].toString().get() == "PROTOCOL-ERROR") {
ZEUS_ERROR("Get a Protocol error ...");
std::unique_lock<std::mutex> lock(m_mutex);
for (auto &it : m_pendingCall) {
if (it.isValid() == false) {
continue;
}
it.appendData(obj);
}
m_pendingCall.clear();
} else {
ZEUS_ERROR("call with no ID ==> error ...");
}
*/
return;
}
{
std::unique_lock<std::mutex> lock(m_pendingCallMutex);
auto it = m_pendingCall.begin();
@ -278,6 +266,7 @@ void zeus::WebServer::newBuffer(ememory::SharedPtr<zeus::Buffer> _buffer) {
break;
}
}
// Not find a pen,ding call ==> execute it ...
if (future.isValid() == false) {
uint32_t dest = _buffer->getDestination();
for (auto &it : m_listObject) {
@ -285,33 +274,51 @@ void zeus::WebServer::newBuffer(ememory::SharedPtr<zeus::Buffer> _buffer) {
continue;
}
if (it->getFullId() == dest) {
it->receive(_buffer);
// send in an other async to syncronize the
m_processingPool.async(
[=](){
ememory::SharedPtr<zeus::WebObj> tmpObj = it;
tmpObj->receive(_buffer);
},
dest
);
return;
}
}
// not a pending call ==> simple event or call ...
if (m_observerElement != nullptr) {
m_observerElement(_buffer);
m_processingPool.async(
[=](){
// not a pending call ==> simple event or call ...
m_observerElement(_buffer); //!< all input arrive at the same element
},
9);
}
return;
}
bool ret = future.appendData(_buffer);
if (ret == true) {
std::unique_lock<std::mutex> lock(m_pendingCallMutex);
auto it = m_pendingCall.begin();
while (it != m_pendingCall.end()) {
if (it->second.isValid() == false) {
it = m_pendingCall.erase(it);
continue;
}
if (it->second.getTransactionId() != tid) {
++it;
continue;
}
it = m_pendingCall.erase(it);
break;
}
}
m_processingPool.async(
[=](){
zeus::FutureBase fut = future;
// add data ...
bool ret = fut.appendData(_buffer);
if (ret == true) {
std::unique_lock<std::mutex> lock(m_pendingCallMutex);
auto it = m_pendingCall.begin();
while (it != m_pendingCall.end()) {
if (it->second.isValid() == false) {
it = m_pendingCall.erase(it);
continue;
}
if (it->second.getTransactionId() != tid) {
++it;
continue;
}
it = m_pendingCall.erase(it);
break;
}
}
},
tid); // force at the transaction Id to have a correct order in the processing of the data ...
}
void zeus::WebServer::addAsync(zeus::WebServer::ActionAsync _elem) {

View File

@ -12,6 +12,7 @@
#include <zeus/AbstractFunction.hpp>
#include <zeus/FutureBase.hpp>
#include <zeus/WebObj.hpp>
#include <ethread/Pool.hpp>
//#define ZEUS_NO_ID_CLIENT (0xFFFFFFFF)
#define ZEUS_NO_ID_CLIENT (0x00000000)
@ -91,6 +92,7 @@ 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;
ethread::Pool m_processingPool;
uint16_t m_localAddress;
uint16_t m_licalIdObjectIncrement; //!< attribute a unique ID for an object

View File

@ -16,5 +16,7 @@ string name()
string getMineType()
#brief:get a part of the file (size < 64ko)
#param:_start:Start position in the file
#param:_stop:Stop position in the file
#return:Buffer with the data
raw getPart(uint64, uint64)