[DEV] add factory and tools in IDL and store list of file in the picture engine
This commit is contained in:
parent
559752a3b9
commit
26843381d7
@ -212,11 +212,17 @@ class FunctionDefinition:
|
||||
out += space + " */\n"
|
||||
return out
|
||||
|
||||
def generate_cpp(self, space):
|
||||
def generate_cpp(self, space, class_name="", virtual=True):
|
||||
out = "";
|
||||
out += self.generate_doxy(space)
|
||||
out += space + "virtual "
|
||||
out += convert_type_in_cpp(self.return_type, False, False) + " " + self.name + "("
|
||||
out += space
|
||||
if self.return_type != "":
|
||||
if virtual == True:
|
||||
out += "virtual "
|
||||
out += convert_type_in_cpp(self.return_type, False, False) + " "
|
||||
else:
|
||||
out += "static ememory::SharedPtr<" + class_name + "> "
|
||||
out += self.name + "("
|
||||
param_data = ""
|
||||
id_parameter = 0
|
||||
for elem in self.parameters:
|
||||
@ -229,7 +235,11 @@ class FunctionDefinition:
|
||||
else:
|
||||
param_data += elem["name"]
|
||||
out += param_data
|
||||
out += ") = 0;\n"
|
||||
out += ")"
|
||||
if self.return_type != "" \
|
||||
and virtual == True:
|
||||
out += " = 0"
|
||||
out += ";\n"
|
||||
return out;
|
||||
|
||||
def generate_hpp_proxy(self, space):
|
||||
@ -292,6 +302,8 @@ class ServiceDefinition:
|
||||
self.authors = []
|
||||
self.attributes = []
|
||||
self.functions = []
|
||||
self.factories = []
|
||||
self.tools = []
|
||||
self.imports = []
|
||||
|
||||
def set_name(self, value):
|
||||
@ -311,6 +323,14 @@ class ServiceDefinition:
|
||||
def add_author(self, value):
|
||||
self.authors.append(remove_start_stop_spacer(value).replace("\"", "\\\""))
|
||||
|
||||
def add_factory(self, value):
|
||||
# TODO : Check if function already exist
|
||||
self.factories.append(value)
|
||||
|
||||
def add_tool(self, value):
|
||||
# TODO : Check if function already exist
|
||||
self.tools.append(value)
|
||||
|
||||
def add_function(self, value):
|
||||
# TODO : Check if function already exist
|
||||
self.functions.append(value)
|
||||
@ -365,6 +385,7 @@ class ServiceDefinition:
|
||||
class_name += elem + "::"
|
||||
class_name += self.name[-1]
|
||||
|
||||
out += space + "class Proxy" + self.name[-1] + ";\n"
|
||||
out += space + " /**\n"
|
||||
if self.brief != "":
|
||||
out += space + " * @brief " + self.brief + " \n"
|
||||
@ -379,11 +400,16 @@ class ServiceDefinition:
|
||||
space += " "
|
||||
out += space + "public:\n"
|
||||
space += " "
|
||||
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"
|
||||
if len(self.factories) == 0:
|
||||
out += space + "/**\n"
|
||||
out += space + " * @brief generic factory, pay attention when set arguments...\n"
|
||||
out += space + " */\n"
|
||||
out += space + "template<typename ... ZEUS_OBJECT_CREATE>\n"
|
||||
out += space + "static ememory::SharedPtr<" + class_name + "> create(ZEUS_OBJECT_CREATE ...);\n"
|
||||
else:
|
||||
for elem in self.factories:
|
||||
out += elem.generate_cpp(space, class_name)
|
||||
|
||||
out += space + "/**\n"
|
||||
out += space + " * @brief Generic virtual destructor\n"
|
||||
out += space + " */\n"
|
||||
@ -397,6 +423,9 @@ class ServiceDefinition:
|
||||
|
||||
space = space[:-2]
|
||||
out += space + "};\n"
|
||||
# now we simply add tools provided:
|
||||
for elem in self.tools:
|
||||
out += elem.generate_cpp(space, virtual=False)
|
||||
|
||||
for elem in self.name[:-1]:
|
||||
space = space[:-1]
|
||||
@ -880,7 +909,7 @@ def tool_generate_idl(target, module, data_option):
|
||||
# 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 '('):
|
||||
list_elems = line.split("(")
|
||||
list_elems = line.replace("[tool-remote] ", "[tool-remote]").split("(")
|
||||
if len(list_elems) <= 1:
|
||||
debug.error("line " + str(id_line) + " function parsing error missing the '(' element")
|
||||
fist_part = list_elems[0].replace(" ", " ").replace(" ", " ").replace(" ", " ")
|
||||
@ -896,20 +925,39 @@ def tool_generate_idl(target, module, data_option):
|
||||
return_value = list_elems[0]
|
||||
function_name = list_elems[1]
|
||||
# check types:
|
||||
if validate_type(return_value) == False:
|
||||
debug.extreme_verbose(" Parse of function done :")
|
||||
current_def.set_function_name(function_name)
|
||||
type_function = "normal"
|
||||
if return_value[:13] == "[tool-remote]":
|
||||
type_function = "tool"
|
||||
current_def.set_return_type(return_value[13:])
|
||||
debug.extreme_verbose(" return:" + return_value[13:])
|
||||
if validate_type(return_value[13:]) == False:
|
||||
debug.error("line " + str(id_line) + " fucntion return type unknow : '" + return_value + "' not in " + str(get_list_type()))
|
||||
elif return_value == "[factory]":
|
||||
type_function = "factory"
|
||||
if function_name != "create":
|
||||
debug.error("line " + str(id_line) + " factory function name must be 'create' not '" + function_name + "'")
|
||||
debug.extreme_verbose(" return: --- ")
|
||||
elif validate_type(return_value) == False:
|
||||
debug.error("line " + str(id_line) + " fucntion return type unknow : '" + return_value + "' not in " + str(get_list_type()))
|
||||
else:
|
||||
current_def.set_return_type(return_value)
|
||||
debug.extreme_verbose(" return:" + return_value)
|
||||
|
||||
for elem in argument_list:
|
||||
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)
|
||||
debug.extreme_verbose(" name:" + function_name)
|
||||
debug.extreme_verbose(" arguments:" + str(argument_list))
|
||||
current_def.set_function_name(function_name)
|
||||
current_def.set_return_type(return_value)
|
||||
for elem in argument_list:
|
||||
current_def.add_parameter_type(elem)
|
||||
service_def.add_function(current_def)
|
||||
if type_function == "normal":
|
||||
service_def.add_function(current_def)
|
||||
elif type_function == "factory":
|
||||
service_def.add_factory(current_def)
|
||||
else:
|
||||
service_def.add_tool(current_def)
|
||||
else:
|
||||
# if must be a simple element separate with a space
|
||||
if len(line.split("(")) != 1:
|
||||
|
@ -145,7 +145,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
if (true) {
|
||||
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
|
||||
if (remoteServicePicture.exist() == true) {
|
||||
#if 0
|
||||
#if 1
|
||||
zeus::Future<std::vector<std::string>> retCall = remoteServicePicture.getAlbums().wait();
|
||||
APPL_INFO(" album list: ");
|
||||
for (auto &it : retCall.get()) {
|
||||
@ -171,7 +171,7 @@ int main(int _argc, const char *_argv[]) {
|
||||
zeus::Future<ememory::SharedPtr<zeus::ObjectRemoteBase>> retListImage = remoteServicePicture.getAlbumListPicture(it3).wait();
|
||||
zeus::ProxyFile tmpFile = zeus::ObjectRemote(retListImage.get());
|
||||
APPL_INFO(" mine-type: " << tmpFile.getMineType().wait().get());
|
||||
APPL_INFO(" size: " << tmpFile.size().wait().get());
|
||||
APPL_INFO(" size: " << tmpFile.getSize().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().wait().get());
|
||||
APPL_INFO(" store in: " << tmpFileName);
|
||||
@ -190,7 +190,9 @@ int main(int _argc, const char *_argv[]) {
|
||||
#endif
|
||||
#if 1
|
||||
echrono::Steady start = echrono::Steady::now();
|
||||
ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./tmpResult.bmp");
|
||||
//ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./tmpResult.bmp");
|
||||
ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./testImage.png");
|
||||
//ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./test_log.txt");
|
||||
int32_t size = tmp->getSize();
|
||||
auto retSendImage = remoteServicePicture.addFile(tmp).wait();
|
||||
echrono::Steady stop = echrono::Steady::now();
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
typedef bool (*SERVICE_IO_init_t)(int _argc, const char *_argv[], std::string _basePath);
|
||||
typedef bool (*SERVICE_IO_uninit_t)();
|
||||
typedef void (*SERVICE_IO_peridic_call_t)();
|
||||
typedef zeus::Object* (*SERVICE_IO_instanciate_t)(uint32_t, ememory::SharedPtr<zeus::WebServer>&, uint32_t);
|
||||
|
||||
class PlugginAccess {
|
||||
@ -29,6 +30,7 @@ class PlugginAccess {
|
||||
void* m_handle;
|
||||
SERVICE_IO_init_t m_SERVICE_IO_init;
|
||||
SERVICE_IO_uninit_t m_SERVICE_IO_uninit;
|
||||
SERVICE_IO_peridic_call_t m_SERVICE_IO_peridic_call;
|
||||
SERVICE_IO_instanciate_t m_SERVICE_IO_instanciate;
|
||||
zeus::Client m_client;
|
||||
public:
|
||||
@ -58,6 +60,12 @@ class PlugginAccess {
|
||||
m_SERVICE_IO_uninit = nullptr;
|
||||
APPL_WARNING("Can not function SERVICE_IO_uninit :" << error);
|
||||
}
|
||||
m_SERVICE_IO_peridic_call = (SERVICE_IO_peridic_call_t)dlsym(m_handle, "SERVICE_IO_peridic_call");
|
||||
error = dlerror();
|
||||
if (error != nullptr) {
|
||||
m_SERVICE_IO_uninit = nullptr;
|
||||
APPL_WARNING("Can not function SERVICE_IO_uninit :" << error);
|
||||
}
|
||||
m_SERVICE_IO_instanciate = (SERVICE_IO_instanciate_t)dlsym(m_handle, "SERVICE_IO_instanciate");
|
||||
error = dlerror();
|
||||
if (error != nullptr) {
|
||||
@ -98,6 +106,12 @@ class PlugginAccess {
|
||||
}
|
||||
return (*m_SERVICE_IO_uninit)();
|
||||
}
|
||||
void peridic_call() {
|
||||
if (m_SERVICE_IO_peridic_call == nullptr) {
|
||||
return;
|
||||
}
|
||||
(*m_SERVICE_IO_peridic_call)();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -157,6 +171,9 @@ int main(int _argc, const char *_argv[]) {
|
||||
m_client.pingIsAlive();
|
||||
m_client.displayConnectedObject();
|
||||
m_client.cleanDeadObject();
|
||||
for (auto &it: listElements) {
|
||||
it->peridic_call();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
APPL_INFO("service in waiting ... " << iii << "/inf");
|
||||
iii++;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <zeus/File.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
#include <zeus/zeus.hpp>
|
||||
#include <echrono/Time.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <ejson/ejson.hpp>
|
||||
@ -16,7 +17,6 @@
|
||||
#include <sstream>
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <algue/sha512.hpp>
|
||||
|
||||
#include <zeus/service/Picture.hpp>
|
||||
#include <zeus/service/registerPicture.hpp>
|
||||
@ -28,8 +28,17 @@ static std::mutex g_mutex;
|
||||
static std::string g_basePath;
|
||||
static std::string g_baseDBName = std::string(SERVICE_NAME) + "-database.json";
|
||||
static ejson::Document g_database;
|
||||
static std::map<uint64_t,std::string> m_listFile;
|
||||
class FileProperty {
|
||||
public:
|
||||
std::string m_fileName; // Sha 512
|
||||
std::string m_name;
|
||||
std::string m_mineType;
|
||||
echrono::Time m_creationData;
|
||||
};
|
||||
|
||||
static std::vector<FileProperty> m_listFile;
|
||||
static uint64_t m_lastMaxId = 0;
|
||||
static bool g_needToStore = false;
|
||||
|
||||
static uint64_t createFileID() {
|
||||
m_lastMaxId++;
|
||||
@ -51,10 +60,10 @@ namespace appl {
|
||||
}
|
||||
*/
|
||||
PictureService(uint16_t _clientId) {
|
||||
APPL_WARNING("New PictureService ... for user: " << _clientId);
|
||||
APPL_VERBOSE("New PictureService ... for user: " << _clientId);
|
||||
}
|
||||
~PictureService() {
|
||||
APPL_WARNING("delete PictureService ...");
|
||||
APPL_VERBOSE("delete PictureService ...");
|
||||
}
|
||||
public:
|
||||
std::vector<std::string> getAlbums() {
|
||||
@ -168,78 +177,82 @@ namespace appl {
|
||||
return out;
|
||||
}
|
||||
// Return a File Data (might be a picture .tiff/.png/.jpg)
|
||||
ememory::SharedPtr<zeus::File> getAlbumPicture(std::string _pictureName) {
|
||||
ememory::SharedPtr<zeus::File> getAlbumPicture(std::string _mediaName) {
|
||||
std::unique_lock<std::mutex> lock(g_mutex);
|
||||
// TODO : Check right ...
|
||||
uint64_t id = etk::string_to_uint64_t(_pictureName);
|
||||
APPL_WARNING("try to get file : " << _pictureName << " with id=" << id);
|
||||
//Check if the file exist:
|
||||
bool find = false;
|
||||
FileProperty property;
|
||||
for (auto &it : m_listFile) {
|
||||
if (it.m_fileName == _mediaName) {
|
||||
find = true;
|
||||
property = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find == false) {
|
||||
throw std::invalid_argument("Wrong file name ...");
|
||||
}
|
||||
return zeus::File::create(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType), "", property.m_mineType);
|
||||
|
||||
|
||||
|
||||
|
||||
//uint64_t id = etk::string_to_uint64_t(_pictureName);
|
||||
//APPL_WARNING("try to get file : " << _pictureName << " with id=" << id);
|
||||
{
|
||||
/*
|
||||
auto it = m_listFile.find(id);
|
||||
if (it != m_listFile.end()) {
|
||||
return zeus::File::create(g_basePath + it->second);
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
for (auto &it : m_listFile) {
|
||||
APPL_WARNING("compare: " << it.first << " with " << id << " " << it.second);
|
||||
if (it.first == id) {
|
||||
return zeus::File::create(g_basePath + it.second);
|
||||
}
|
||||
}
|
||||
*/
|
||||
APPL_ERROR(" ==> Not find ...");
|
||||
return nullptr;
|
||||
}
|
||||
std::string addFile(zeus::ProxyFile _dataFile) {
|
||||
std::unique_lock<std::mutex> lock(g_mutex);
|
||||
APPL_ERROR("Call add file ... ");
|
||||
// TODO : Check right ...
|
||||
uint64_t id = createFileID();
|
||||
APPL_ERROR("New ID : " << id);
|
||||
|
||||
auto futType = _dataFile.getMineType();
|
||||
auto futName = _dataFile.getName();
|
||||
auto futSize = _dataFile.getSize();
|
||||
std::string tmpFileName = g_basePath + "tmpImport_" + etk::to_string(id);
|
||||
std::string sha512String = zeus::storeInFile(_dataFile, tmpFileName);
|
||||
futType.wait();
|
||||
APPL_ERROR("mine-type : " << futType.get());
|
||||
futName.wait();
|
||||
APPL_ERROR("name : " << futName.get());
|
||||
futSize.wait();
|
||||
APPL_ERROR("size : " << futSize.get());
|
||||
int64_t retSize = futSize.get();
|
||||
int64_t offset = 0;
|
||||
algue::Sha512 shaCtx;
|
||||
etk::FSNode nodeFile(g_basePath + "tmpImport_" + etk::to_string(id));
|
||||
nodeFile.fileOpenWrite();
|
||||
while (retSize > 0) {
|
||||
int32_t nbElement = 1*1024*1024;
|
||||
if (retSize<nbElement) {
|
||||
nbElement = retSize;
|
||||
// TODO : Get internal data of the file and remove all the meta-data ==> proper files ...
|
||||
for (auto &it : m_listFile) {
|
||||
if (it.m_fileName == sha512String) {
|
||||
APPL_INFO("File already registered at " << it.m_creationData);
|
||||
// TODO : Check if data is identical ...
|
||||
// remove temporary file
|
||||
etk::FSNodeRemove(tmpFileName);
|
||||
return sha512String;
|
||||
}
|
||||
auto futData = _dataFile.getPart(offset, offset + nbElement);
|
||||
futData.wait();
|
||||
if (futData.hasError() == true) {
|
||||
throw std::runtime_error("ErrorWhen loading data");
|
||||
}
|
||||
zeus::Raw buffer = futData.get();
|
||||
APPL_ERROR(" get size ... : " << buffer.size() << " " << nbElement);
|
||||
shaCtx.update(buffer.data(), buffer.size());
|
||||
nodeFile.fileWrite(buffer.data(), 1, buffer.size());
|
||||
offset += nbElement;
|
||||
retSize -= nbElement;
|
||||
}
|
||||
std::string sha256String = algue::stringConvert(shaCtx.finalize());
|
||||
APPL_ERROR(" filename : " << sha256String);
|
||||
return sha256String;
|
||||
|
||||
/*
|
||||
APPL_ERROR(" ==> Receive FILE " << _dataFile.getMineType() << " size=" << _dataFile.getData().size());
|
||||
std::stringstream val;
|
||||
val << std::hex << std::setw(16) << std::setfill('0') << id;
|
||||
std::string filename = val.str();
|
||||
filename += ".";
|
||||
filename += zeus::getExtention(_dataFile.getMineType());
|
||||
_dataFile.storeIn(g_basePath + filename);
|
||||
m_listFile.insert(std::make_pair(id, filename));
|
||||
*/
|
||||
return etk::to_string(id);
|
||||
// move the file at the good position:
|
||||
APPL_ERROR("move temporay file in : " << g_basePath << sha512String);
|
||||
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
|
||||
FileProperty property;
|
||||
property.m_fileName = sha512String;
|
||||
property.m_name = futName.get();
|
||||
property.m_mineType = futType.get();
|
||||
property.m_creationData = echrono::Time::now();
|
||||
APPL_ERROR("Current Time : " << echrono::Time::now());
|
||||
m_listFile.push_back(property);
|
||||
g_needToStore = true;
|
||||
APPL_ERROR(" filename : " << sha512String);
|
||||
return sha512String;
|
||||
}
|
||||
/*
|
||||
// Return a global UTC time
|
||||
@ -304,14 +317,58 @@ namespace appl {
|
||||
};
|
||||
}
|
||||
|
||||
static void store_db() {
|
||||
APPL_ERROR("Store database [START]");
|
||||
ejson::Document database;
|
||||
ejson::Array listFilesArray;
|
||||
database.add("list-files", listFilesArray);
|
||||
for (auto &it : m_listFile) {
|
||||
ejson::Object fileElement;
|
||||
fileElement.add("file-name", ejson::String(it.m_fileName));
|
||||
fileElement.add("name", ejson::String(it.m_name));
|
||||
fileElement.add("mine-type", ejson::String(it.m_mineType));
|
||||
fileElement.add("add-date", ejson::Number(it.m_creationData.count()));
|
||||
listFilesArray.add(fileElement);
|
||||
}
|
||||
bool retGenerate = database.storeSafe(g_basePath + g_baseDBName);
|
||||
APPL_ERROR("Store database [STOP] : " << (g_basePath + g_baseDBName) << " ret = " << retGenerate);
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
static void load_db() {
|
||||
ejson::Document database;
|
||||
bool ret = database.load(g_basePath + g_baseDBName);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> LOAD error");
|
||||
}
|
||||
ejson::Array listFilesArray = database["list-files"].toArray();
|
||||
for (const auto itArray: listFilesArray) {
|
||||
ejson::Object fileElement = itArray.toObject();
|
||||
FileProperty property;
|
||||
|
||||
property.m_fileName = fileElement["file-name"].toString().get();
|
||||
property.m_name = fileElement["name"].toString().get();
|
||||
property.m_mineType = fileElement["mine-type"].toString().get();
|
||||
property.m_creationData = echrono::Time(fileElement["add-date"].toNumber().getU64()*1000);
|
||||
|
||||
if (property.m_fileName == "") {
|
||||
APPL_ERROR("Can not access on the file : ... No name ");
|
||||
} else {
|
||||
m_listFile.push_back(property);
|
||||
}
|
||||
}
|
||||
g_needToStore = false;
|
||||
}
|
||||
|
||||
ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string _basePath) {
|
||||
g_basePath = _basePath;
|
||||
std::unique_lock<std::mutex> lock(g_mutex);
|
||||
APPL_WARNING("Load USER: " << g_basePath);
|
||||
bool ret = g_database.load(g_basePath + g_baseDBName);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> LOAD error");
|
||||
}
|
||||
load_db();
|
||||
|
||||
/*
|
||||
|
||||
|
||||
// Load all files (image and video ...)
|
||||
etk::FSNode node(g_basePath);
|
||||
std::vector<etk::FSNode*> tmpList = node.folderGetSubList(false, false, true, false);
|
||||
@ -339,7 +396,7 @@ ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string
|
||||
if (id <= 1024) {
|
||||
APPL_WARNING(" ==> REJECTED file " << it->getNameFile() << " with ID = " << id);
|
||||
} else {
|
||||
m_listFile.insert(std::make_pair(id, it->getNameFile()));
|
||||
//m_listFile.insert(std::make_pair(id, it->getNameFile()));
|
||||
m_lastMaxId = std::max(m_lastMaxId,id);
|
||||
APPL_WARNING(" ==> load file " << it->getNameFile() << " with ID = " << id);
|
||||
}
|
||||
@ -347,22 +404,30 @@ ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string
|
||||
APPL_WARNING(" ==> REJECT file " << it->getNameFile());
|
||||
}
|
||||
}
|
||||
*/
|
||||
APPL_WARNING("new USER: [STOP]");
|
||||
return true;
|
||||
}
|
||||
|
||||
ETK_EXPORT_API bool SERVICE_IO_uninit() {
|
||||
std::unique_lock<std::mutex> lock(g_mutex);
|
||||
APPL_DEBUG("Store User Info:");
|
||||
bool ret = g_database.storeSafe(g_basePath + g_baseDBName);
|
||||
if (ret == false) {
|
||||
APPL_WARNING(" ==> Store error");
|
||||
return false;
|
||||
}
|
||||
store_db();
|
||||
APPL_WARNING("delete USER [STOP]");
|
||||
return true;
|
||||
}
|
||||
|
||||
ETK_EXPORT_API void SERVICE_IO_peridic_call() {
|
||||
if (g_needToStore == false) {
|
||||
return;
|
||||
}
|
||||
// try lock mutex:
|
||||
if (g_mutex.try_lock() == false) {
|
||||
return;
|
||||
}
|
||||
store_db();
|
||||
g_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
ZEUS_SERVICE_PICTURE_DECLARE(appl::PictureService);
|
||||
|
||||
|
@ -20,14 +20,13 @@ zeus::Raw::Raw(uint32_t _size) :
|
||||
m_dataExternal(nullptr),
|
||||
m_dataInternal() {
|
||||
m_dataInternal.resize(_size);
|
||||
ZEUS_ERROR("Create BUFFER 1 : " << m_size);
|
||||
}
|
||||
|
||||
zeus::Raw::Raw(uint32_t _size, const uint8_t* _data) :
|
||||
m_size(_size),
|
||||
m_dataExternal(_data),
|
||||
m_dataInternal() {
|
||||
ZEUS_ERROR("Create BUFFER 2 : " << m_size);
|
||||
|
||||
}
|
||||
|
||||
zeus::Raw::~Raw() {
|
||||
|
@ -35,9 +35,9 @@ void zeus::WebObj::receive(ememory::SharedPtr<zeus::Message> _value) {
|
||||
}
|
||||
|
||||
void zeus::WebObj::display() {
|
||||
ZEUS_INFO(" - [" << m_id << "/" << m_objectId << "]");
|
||||
ZEUS_DEBUG(" - [" << m_id << "/" << m_objectId << "]");
|
||||
for (auto &it : m_listRemoteConnected) {
|
||||
ZEUS_INFO(" * [" << (it>>16) << "/" << (it&0xFFFF) << "]");
|
||||
ZEUS_DEBUG(" * [" << (it>>16) << "/" << (it&0xFFFF) << "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,8 +235,8 @@ class SendAsyncBinary {
|
||||
}
|
||||
};
|
||||
|
||||
#define ZEUS_LOG_INPUT_OUTPUT ZEUS_WARNING
|
||||
//#define ZEUS_LOG_INPUT_OUTPUT ZEUS_VERBOSE
|
||||
//#define ZEUS_LOG_INPUT_OUTPUT ZEUS_WARNING
|
||||
#define ZEUS_LOG_INPUT_OUTPUT ZEUS_VERBOSE
|
||||
|
||||
|
||||
int32_t zeus::WebServer::writeBinary(ememory::SharedPtr<zeus::Message> _obj) {
|
||||
@ -427,7 +427,7 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
|
||||
m_processingPool.async(
|
||||
[=](){
|
||||
zeus::FutureBase fut = future;
|
||||
ZEUS_INFO("PROCESS FUTURE : " << _buffer);
|
||||
ZEUS_LOG_INPUT_OUTPUT("PROCESS FUTURE : " << _buffer);
|
||||
// add data ...
|
||||
bool ret = fut.setMessage(_buffer);
|
||||
if (ret == true) {
|
||||
@ -456,7 +456,7 @@ void zeus::WebServer::listObjects() {
|
||||
&& m_listRemoteObject.size() == 0) {
|
||||
return;
|
||||
}
|
||||
ZEUS_INFO("[" << m_interfaceId << "] Interface WebServer:");
|
||||
ZEUS_DEBUG("[" << m_interfaceId << "] Interface WebServer:");
|
||||
for (auto &it : m_listObject) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
|
@ -1443,14 +1443,7 @@ namespace zeus {
|
||||
uint32_t dataSize = getParameterSize(_id);
|
||||
// TODO : Check size ...
|
||||
if (createType<zeus::Raw>() == type) {
|
||||
// get size if the file in int32_t
|
||||
#if 0
|
||||
uint32_t size = 0;
|
||||
memcpy(&size, pointer, sizeof(uint32_t));
|
||||
#else
|
||||
uint32_t size = dataSize;
|
||||
#endif
|
||||
return zeus::Raw(size, &pointer[sizeof(uint32_t)]);
|
||||
return zeus::Raw(dataSize, pointer);
|
||||
}
|
||||
ZEUS_ERROR("Can not get type from '" << type << "'");
|
||||
return zeus::Raw();
|
||||
|
@ -120,6 +120,35 @@ static std::vector<std::pair<std::string, std::string>> mineList = {
|
||||
{ "rgb", "image/x-raw/r8g8b8"},
|
||||
{ "rgba", "image/x-raw/r8g8b8a8"},
|
||||
|
||||
{ "js", "application/javascript"},
|
||||
{ "raw", "application/octet-stream"},
|
||||
{ "ogg", "application/ogg"},
|
||||
{ "pdf", "application/pdf"},
|
||||
{ "xhtml", "application/xhtml+xml"},
|
||||
{ "flw", "application/x-shockwave-flash"},
|
||||
{ "json", "application/json"},
|
||||
{ "xml", "application/xml"},
|
||||
{ "zip", "application/zip"},
|
||||
{ "gz", "application/gzip"},
|
||||
{ "rar", "application/rar"},
|
||||
|
||||
{ "css", "text/css"},
|
||||
{ "csv", "text/csv"},
|
||||
{ "html", "text/html"},
|
||||
{ "js", "text/javascript"}, // DEPRECATED application/javascript.
|
||||
{ "txt", "text/plain"},
|
||||
{ "xml", "text/xml"},
|
||||
{ "json", "text/json"},
|
||||
{ "yml", "text/yml"},
|
||||
|
||||
{ "c", "code/c"},
|
||||
{ "h", "header/c"},
|
||||
{ "cpp", "code/c++"},
|
||||
{ "hpp", "header/c++"},
|
||||
{ "c#", "code/c#"},
|
||||
{ "py", "code/python"},
|
||||
{ "java", "code/java"},
|
||||
{ "js", "code/javascript"},
|
||||
};
|
||||
|
||||
std::string zeus::getMineType(const std::string& _extention) {
|
||||
|
@ -5,29 +5,37 @@
|
||||
*/
|
||||
|
||||
#include <zeus/zeus-File.impl.hpp>
|
||||
#include <zeus/ProxyFile.hpp>
|
||||
#include <zeus/mineType.hpp>
|
||||
#include <algue/sha512.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);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal);
|
||||
}
|
||||
|
||||
zeus::FileImpl::FileImpl(std::string _filename) :
|
||||
m_filename(_filename),
|
||||
m_node(_filename) {
|
||||
ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) {
|
||||
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _fileNameShow, _mineType);
|
||||
}
|
||||
|
||||
zeus::FileImpl::FileImpl(std::string _fileNameReal) :
|
||||
m_filename(_fileNameReal),
|
||||
m_node(_fileNameReal) {
|
||||
m_size = m_node.fileSize();
|
||||
m_node.fileOpenRead();
|
||||
std::string extention = std::string(_filename.begin()+_filename.size() -3, _filename.end());
|
||||
std::string extention = std::string(_fileNameReal.begin()+_fileNameReal.size() -3, _fileNameReal.end());
|
||||
m_mineType = zeus::getMineType(extention);
|
||||
}
|
||||
|
||||
zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) :
|
||||
m_filename(_fileNameShow),
|
||||
m_node(_fileNameReal),
|
||||
m_mineType(_mineType) {
|
||||
m_size = m_node.fileSize();
|
||||
m_node.fileOpenRead();
|
||||
}
|
||||
|
||||
zeus::FileImpl::~FileImpl() {
|
||||
m_node.fileClose();
|
||||
}
|
||||
@ -61,5 +69,36 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
|
||||
return std::move(tmp);
|
||||
}
|
||||
|
||||
std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename) {
|
||||
auto futSize = _file.getSize();
|
||||
futSize.wait();
|
||||
int64_t retSize = futSize.get();
|
||||
int64_t offset = 0;
|
||||
|
||||
algue::Sha512 shaCtx;
|
||||
etk::FSNode nodeFile(_filename);
|
||||
nodeFile.fileOpenWrite();
|
||||
while (retSize > 0) {
|
||||
// get by batch of 1 MB
|
||||
int32_t nbElement = 1*1024*1024;
|
||||
if (retSize<nbElement) {
|
||||
nbElement = retSize;
|
||||
}
|
||||
auto futData = _file.getPart(offset, offset + nbElement);
|
||||
futData.wait();
|
||||
if (futData.hasError() == true) {
|
||||
throw std::runtime_error("Error when loading data");
|
||||
}
|
||||
zeus::Raw buffer = futData.get();
|
||||
shaCtx.update(buffer.data(), buffer.size());
|
||||
nodeFile.fileWrite(buffer.data(), 1, buffer.size());
|
||||
offset += nbElement;
|
||||
retSize -= nbElement;
|
||||
}
|
||||
nodeFile.fileClose();
|
||||
// get the final sha512 of the file:
|
||||
std::string sha512String = algue::stringConvert(shaCtx.finalize());
|
||||
return sha512String;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,7 +16,8 @@ namespace zeus {
|
||||
size_t m_size;
|
||||
std::string m_mineType;
|
||||
public:
|
||||
FileImpl(std::string _filename);
|
||||
FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType);
|
||||
FileImpl(std::string _fileNameReal);
|
||||
~FileImpl();
|
||||
uint64_t getSize() override;
|
||||
std::string getName() override;
|
||||
|
@ -3,29 +3,48 @@
|
||||
#elem-type:FILE
|
||||
#elem-author:Heero Yui<yui.heero@gmail.com>
|
||||
|
||||
#param:_fileName: Name of the local file to instanciate
|
||||
//factory obj:zeus-File
|
||||
// --------------------------
|
||||
// -- Factory --
|
||||
// --------------------------
|
||||
|
||||
#brief:Get size of the file
|
||||
#return:current size of the file
|
||||
#brief:Factory to create a local object.
|
||||
#param:fileName:Name of the local file to instanciate.
|
||||
[factory] create(string)
|
||||
#brief:Factory to create a local object.
|
||||
#param:fileNameReal:Name of the local file to instanciate.
|
||||
#param:fileNameShow:Name of the file like the remote user will se it.
|
||||
#param:mineType:Mine-type of the file.
|
||||
[factory] create(string, string, string)
|
||||
|
||||
// --------------------------
|
||||
// -- Members --
|
||||
// --------------------------
|
||||
|
||||
#brief:Get size of the file.
|
||||
#return:current size of the file.
|
||||
uint64 getSize()
|
||||
|
||||
#brief:Get the name of the file
|
||||
#return:Full name of the file (sha512)
|
||||
#brief:Get the name of the file.
|
||||
#return:Full name of the file (sha512).
|
||||
string getName()
|
||||
|
||||
#brief:Get the file "mine-type"
|
||||
#return:string of the mine-type
|
||||
#brief:Get the file "mine-type".
|
||||
#return:string of the mine-type.
|
||||
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
|
||||
#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)
|
||||
|
||||
// --------------------------
|
||||
// -- Tools --
|
||||
// --------------------------
|
||||
|
||||
#brief:Store all the data in a specific file.
|
||||
#param:file:Handle on the file.
|
||||
#param:filename:Local filename.
|
||||
#return:the sha512 of the file (calculated with the input stream.
|
||||
[tool-remote] string storeInFile(obj:zeus-File, string)
|
||||
|
||||
#brief:Store all the data in a specific file
|
||||
#param:_file: Handle on the file
|
||||
#param:_filename:Local filename
|
||||
//tool void storeInTemporaryFile(obj:zeus-File, string)
|
||||
|
Loading…
Reference in New Issue
Block a user