From 4801cb8306b1154563b3b963fb162d4750545134 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 4 Jun 2017 14:15:48 +0200 Subject: [PATCH] [DEV] better integration of test base and actions/signals --- lutinMacro_zeus.py | 1 + test/client/appl/main-test-client.cpp | 447 +----------------- test/client/lutin_zeus-test-client.py | 4 +- test/service1/appl/debug.cpp | 2 +- test/service1/appl/debug.hpp | 3 +- test/service1/appl/main-test-service.cpp | 118 ----- test/service1/appl/main-test-service1.cpp | 121 +++++ .../appl/zeus-test-service1.srv.zeus.idl | 20 + test/service1/lutin_zeus-test-package.py | 36 ++ .../service1/lutin_zeus-test-service1-impl.py | 43 ++ test/service1/lutin_zeus-test-service1.py | 18 +- tools/gateway/appl/GateWay.cpp | 2 +- tools/gateway/appl/IOInterface.cpp | 16 +- tools/player-video/appl/MediaDecoder.cpp | 11 +- tools/player-video/appl/widget/ListViewer.cpp | 18 +- tools/router/appl/GateWayInterface.cpp | 2 +- zeus/Future.hpp | 18 +- 17 files changed, 273 insertions(+), 607 deletions(-) delete mode 100644 test/service1/appl/main-test-service.cpp create mode 100644 test/service1/appl/main-test-service1.cpp create mode 100644 test/service1/appl/zeus-test-service1.srv.zeus.idl create mode 100644 test/service1/lutin_zeus-test-package.py create mode 100644 test/service1/lutin_zeus-test-service1-impl.py diff --git a/lutinMacro_zeus.py b/lutinMacro_zeus.py index bd86d76..d8e3b3f 100644 --- a/lutinMacro_zeus.py +++ b/lutinMacro_zeus.py @@ -259,6 +259,7 @@ class FunctionDefinition: out += elem["name"] + " " if elem["brief"] != "": out += elem["brief"] + " " + out += "\n" if self.is_action == True: out += space + " * @note: This is an action ==> it can notify of the progression of the call\n" if self.return_brief != "": diff --git a/test/client/appl/main-test-client.cpp b/test/client/appl/main-test-client.cpp index 16cf374..5dbde4a 100644 --- a/test/client/appl/main-test-client.cpp +++ b/test/client/appl/main-test-client.cpp @@ -15,303 +15,12 @@ #include -#include -#include -#include +#include #include #include #include #include -void installPath(zeus::service::ProxyPicture& _srv, std::string _path, uint32_t _albumID) { - etk::FSNode node(_path); - APPL_INFO("Parse : '" << _path << "'"); - std::vector listSubPath = node.folderGetSub(true, false, "*"); - for (auto &itPath : listSubPath) { - APPL_INFO("Create Album : '" << itPath << "'"); - std::string albumName = etk::split(itPath, '/').back(); - uint32_t albumId = _srv.albumCreate(albumName).wait().get(); - _srv.albumDescriptionSet(albumId, itPath).wait(); - if (_albumID != 0) { - _srv.albumParentSet(albumId, _albumID).wait(); - } - installPath(_srv, itPath, albumId); - } - - std::vector listSubFile = node.folderGetSub(false, true, "*"); - for (auto &itFile : listSubFile) { - APPL_INFO("Add media : '" << itFile << "' in " << _albumID); - std::string extention = etk::tolower(std::string(itFile.begin()+itFile.size() -3, itFile.end())); - if ( extention == "jpg" - || extention == "png" - || extention == "gif" - || extention == "bmp" - || extention == "avi" - || extention == "ogg" - || extention == "mp3" - || extention == "mkv" - || extention == "mka" - || extention == "tga" - || extention == "mp2" - || extention == "mov") { - uint32_t mediaId = _srv.mediaAdd(zeus::File::create(itFile)).wait().get(); - if (mediaId == 0) { - APPL_ERROR("Get media ID = 0 With no error"); - } - if (_albumID != 0) { - APPL_INFO("Add media '" << mediaId << "'in ALbum: " << _albumID); - _srv.albumMediaAdd(_albumID, mediaId).wait(); - } - } else { - APPL_ERROR("Sot send file : " << itFile << " Not manage extention..."); - } - } -} - -static std::string extractAndRemove(const std::string& _inputValue, const char _startMark, const char _stopMark, std::vector& _values) { - _values.clear(); - std::string out; - bool inside=false; - std::string insideData; - for (auto &it : _inputValue) { - if ( inside == false - && it == _startMark) { - inside = true; - } else if ( inside == true - && it == _stopMark) { - inside = false; - _values.push_back(insideData); - insideData.clear(); - } else if (inside == true) { - insideData += it; - } else { - out += it; - } - } - return out; -} - - -void installVideoPath(zeus::service::ProxyVideo& _srv, std::string _path, std::map _basicKey = std::map()) { - etk::FSNode node(_path); - APPL_INFO("Parse : '" << _path << "'"); - std::vector listSubPath = node.folderGetSub(true, false, "*"); - for (auto &itPath : listSubPath) { - std::map basicKeyTmp = _basicKey; - APPL_INFO("Add Sub path: '" << itPath << "'"); - std::string lastPathName = etk::split(itPath, '/').back(); - if (basicKeyTmp.size() == 0) { - APPL_INFO("find '" << lastPathName << "' " << basicKeyTmp.size()); - if (lastPathName == "films") { - basicKeyTmp.insert(std::pair("type", "film")); - basicKeyTmp.insert(std::pair("production-methode", "picture")); - } else if (lastPathName == "films-annimation") { - basicKeyTmp.insert(std::pair("type", "film")); - basicKeyTmp.insert(std::pair("production-methode", "draw")); - } else if (lastPathName == "tv-show") { - basicKeyTmp.insert(std::pair("type", "tv-show")); - basicKeyTmp.insert(std::pair("production-methode", "picture")); - } else if (lastPathName == "anim") { - basicKeyTmp.insert(std::pair("type", "tv-show")); - basicKeyTmp.insert(std::pair("production-methode", "draw")); - } else if (lastPathName == "courses") { // short films - basicKeyTmp.insert(std::pair("type", "courses")); - basicKeyTmp.insert(std::pair("production-methode", "picture")); // TODO : Check "draw" - } else if (lastPathName == "theater") { - basicKeyTmp.insert(std::pair("type", "theater")); - basicKeyTmp.insert(std::pair("production-methode", "picture")); - } else if (lastPathName == "one-man-show") { - basicKeyTmp.insert(std::pair("type", "one-man show")); - basicKeyTmp.insert(std::pair("production-methode", "picture")); - } - } else { - APPL_INFO("find '" << lastPathName << "' " << basicKeyTmp.size()); - if (lastPathName == "saison_01") { - basicKeyTmp.insert(std::pair("saison", "1")); - } else if (lastPathName == "saison_02") { - basicKeyTmp.insert(std::pair("saison", "2")); - } else if (lastPathName == "saison_03") { - basicKeyTmp.insert(std::pair("saison", "3")); - } else if (lastPathName == "saison_04") { - basicKeyTmp.insert(std::pair("saison", "4")); - } else if (lastPathName == "saison_05") { - basicKeyTmp.insert(std::pair("saison", "5")); - } else if (lastPathName == "saison_06") { - basicKeyTmp.insert(std::pair("saison", "6")); - } else if (lastPathName == "saison_07") { - basicKeyTmp.insert(std::pair("saison", "7")); - } else if (lastPathName == "saison_08") { - basicKeyTmp.insert(std::pair("saison", "8")); - } else if (lastPathName == "saison_09") { - basicKeyTmp.insert(std::pair("saison", "9")); - } else if (lastPathName == "saison_10") { - basicKeyTmp.insert(std::pair("saison", "10")); - } else if (lastPathName == "saison_11") { - basicKeyTmp.insert(std::pair("saison", "11")); - } else if (lastPathName == "saison_12") { - basicKeyTmp.insert(std::pair("saison", "12")); - } else if (lastPathName == "saison_13") { - basicKeyTmp.insert(std::pair("saison", "13")); - } else if (lastPathName == "saison_14") { - basicKeyTmp.insert(std::pair("saison", "14")); - } else if (lastPathName == "saison_15") { - basicKeyTmp.insert(std::pair("saison", "15")); - } else if (lastPathName == "saison_16") { - basicKeyTmp.insert(std::pair("saison", "16")); - } else if (lastPathName == "saison_17") { - basicKeyTmp.insert(std::pair("saison", "17")); - } else if (lastPathName == "saison_18") { - basicKeyTmp.insert(std::pair("saison", "18")); - } else if (lastPathName == "saison_19") { - basicKeyTmp.insert(std::pair("saison", "19")); - } else if (lastPathName == "saison_20") { - basicKeyTmp.insert(std::pair("saison", "20")); - } else { - basicKeyTmp.insert(std::pair("series-name", lastPathName)); - } - } - installVideoPath(_srv, itPath, basicKeyTmp); - } - // Add files : - std::vector listSubFile = node.folderGetSub(false, true, "*"); - for (auto &itFile : listSubFile) { - std::map basicKeyTmp = _basicKey; - APPL_INFO("Add media : '" << itFile << "'"); - std::string extention = etk::tolower(std::string(itFile.begin()+itFile.size() -3, itFile.end())); - if ( extention == "avi" - || extention == "mkv" - || extention == "mov" - || extention == "mp4") { - - uint32_t mediaId = _srv.mediaAdd(zeus::File::create(itFile)).waitFor(echrono::seconds(20000)).get(); - if (mediaId == 0) { - APPL_ERROR("Get media ID = 0 With no error"); - continue; - } - - // Parse file name: - std::string fileName = etk::split(itFile, '/').back(); - APPL_INFO("Find fileName : '" << fileName << "'"); - // Remove Date (XXXX) - std::vector dates; - fileName = extractAndRemove(fileName, '(', ')', dates); - if (dates.size() > 1) { - APPL_INFO(" '" << fileName << "'"); - APPL_ERROR("Parse Date error : () : " << dates); - } else if (dates.size() == 1) { - APPL_INFO(" '" << fileName << "'"); - basicKeyTmp.insert(std::pair("date", dates[0])); - } - // Remove the actors [XXX YYY][EEE TTT]... - std::vector acthors; - fileName = extractAndRemove(fileName, '[', ']', acthors); - if (acthors.size() > 0) { - APPL_INFO(" '" << fileName << "'"); - std::string actorList; - for (auto &itActor : acthors) { - if (actorList != "") { - actorList += ";"; - } - actorList += itActor; - } - basicKeyTmp.insert(std::pair("acthors", actorList)); - } - - // remove extention - fileName = std::string(fileName.begin(), fileName.begin() + fileName.size() - 4); - - std::vector listElementBase = etk::split(fileName, '-'); - - std::vector listElement; - std::string tmpStartString; - for (size_t iii=0; iii("title", etk::to_string(listElement[0]))); - } else { - /* - for (auto &itt : listElement) { - APPL_INFO(" " << itt); - } - */ - if ( listElement.size() > 3 - && listElement[1][0] == 's' - && listElement[2][0] == 'e') { - // internal formalisme ... - int32_t saison = -1; - int32_t episode = -1; - std::string seriesName = listElement[0]; - - basicKeyTmp.insert(std::pair("series-name", etk::to_string(seriesName))); - basicKeyTmp.insert(std::pair("title", etk::to_string(listElement[3]))); - if (std::string(&listElement[1][1]) == "XX") { - // saison unknow ... ==> nothing to do ... - } else { - saison = etk::string_to_int32_t(&listElement[1][1]); - } - if (std::string(&listElement[2][1]) == "XX") { - // episode unknow ... ==> nothing to do ... - } else { - episode = etk::string_to_int32_t(&listElement[2][1]); - - basicKeyTmp.insert(std::pair("episode", etk::to_string(episode))); - } - APPL_INFO("Find a internal mode series: :"); - APPL_INFO(" origin : '" << fileName << "'"); - std::string saisonPrint = "XX"; - std::string episodePrint = "XX"; - if (saison < 0) { - // nothing to do - } else if(saison < 10) { - saisonPrint = "0" + etk::to_string(saison); - basicKeyTmp.insert(std::pair("saison", etk::to_string(saison))); - } else { - saisonPrint = etk::to_string(saison); - basicKeyTmp.insert(std::pair("saison", etk::to_string(saison))); - } - if (episode < 0) { - // nothing to do - } else if(episode < 10) { - episodePrint = "0" + etk::to_string(episode); - basicKeyTmp.insert(std::pair("episode", etk::to_string(episode))); - } else { - episodePrint = etk::to_string(episode); - basicKeyTmp.insert(std::pair("episode", etk::to_string(episode))); - } - APPL_INFO(" recontituated: '" << seriesName << "-s" << saisonPrint << "-e" << episodePrint << "-" << listElement[3] << "'"); - } - } - - // send all meta data: - zeus::FutureGroup group; - for (auto &itKey : basicKeyTmp) { - group.add(_srv.mediaMetadataSetKey(mediaId, itKey.first, itKey.second)); - } - group.wait(); - - } else { - APPL_ERROR("Sot send file : " << itFile << " Not manage extention..."); - } - } -} int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); elog::init(_argc, _argv); @@ -329,7 +38,7 @@ int main(int _argc, const char *_argv[]) { } else if (etk::start_with(data, "--from=") == true) { fromUser = &data[7]; } else if (etk::start_with(data, "--to=") == true) { - toUser = &data[7]; + toUser = &data[5]; } else if (etk::start_with(data, "--pass=") == true) { pass = &data[7]; } else if (etk::start_with(data, "--tocken=") == true) { @@ -390,154 +99,12 @@ int main(int _argc, const char *_argv[]) { for (auto &it: retServiceList.get()) { APPL_INFO(" - " << it); } - /* - zeus::ServiceRemote localService = client1.getService("serviceTest1"); - if (localService.exist() == true) { - double retCall = localService.call_d("mul", 13.1, 2.0); - APPL_INFO("serviceTest1.mul = " << retCall); + zeus::test::ProxyService1 srv = client1.getService("service1"); + if (srv.exist() == true) { + auto retCall = srv.getU32(11); + retCall.wait(); + APPL_INFO("value = " << retCall.get()); } - */ - - if ( client1.waitForService("user") == true - && false) { - - APPL_INFO(" ----------------------------------"); - APPL_INFO(" -- Get service system-user"); - APPL_INFO(" ----------------------------------"); - zeus::service::ProxyUser remoteServiceUser; - remoteServiceUser = client1.getService("user"); - if (remoteServiceUser.exist() == true) { - zeus::Future> retCall = remoteServiceUser.clientGroupsGet("clientTest1#atria-soft.com"); - retCall.wait(); - APPL_INFO("system-user.getGroups() = " << retCall.get()); - // system DOC - zeus::Future retDesc = remoteServiceUser.sys.getDescription(); - zeus::Future retVersion = remoteServiceUser.sys.getVersion(); - zeus::Future retType = remoteServiceUser.sys.getType(); - zeus::Future> retMaintainer = remoteServiceUser.sys.getAuthors(); - retDesc.wait(); - retVersion.wait(); - retType.wait(); - retMaintainer.wait(); - APPL_INFO("Service: system-user"); - APPL_INFO(" version : " << retVersion.get()); - APPL_INFO(" type : " << retType.get()); - APPL_INFO(" maintainer: " << retMaintainer.get().size()); - for (auto &it : retMaintainer.get()) { - APPL_INFO(" - " << it); - } - APPL_INFO(" description:"); - APPL_INFO(" " << retDesc.get()); - APPL_INFO(" Function List:"); - zeus::Future> retFuctions = remoteServiceUser.sys.getFunctions().wait(); - for (auto it : retFuctions.get()) { - echrono::Steady start = echrono::Steady::now(); - zeus::Future retFunctionPrototype = remoteServiceUser.sys.getFunctionPrototype(it); - zeus::Future retFunctionHelp = remoteServiceUser.sys.getFunctionDescription(it); - retFunctionPrototype.wait(); - retFunctionHelp.wait(); - echrono::Steady stop = echrono::Steady::now(); - APPL_INFO(" - " << retFunctionPrototype.get()); - APPL_INFO(" " << retFunctionHelp.get()); - APPL_INFO(" IO1=" << int64_t(retFunctionPrototype.getTransmitionTime().count()/1000)/1000.0 << " ms"); - APPL_INFO(" IO2=" << int64_t(retFunctionHelp.getTransmitionTime().count()/1000)/1000.0 << " ms"); - APPL_INFO(" IO*=" << (stop-start)); - } - } - } - APPL_INFO(" ----------------------------------"); - APPL_INFO(" -- Get service picture"); - APPL_INFO(" ----------------------------------"); - if ( client1.waitForService("picture") == true - && false) { - zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture"); - if (remoteServicePicture.exist() == true) { - // Send a full path: - installPath(remoteServicePicture, "testPhoto", 0); - } else { - APPL_ERROR("Can not get service Picture ..."); - } - } - if ( client1.waitForService("picture") == true - && false) { - zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture"); - if (remoteServicePicture.exist() == true) { - zeus::Future> retCall = remoteServicePicture.albumGetList().wait(); - if (retCall.hasError() == true) { - APPL_INFO(" Get an error when getting list of albums ..."); - } else { - APPL_INFO(" album list: "); - for (auto &it : retCall.get()) { - std::string name = remoteServicePicture.albumNameGet(it).wait().get(); - std::string desc = remoteServicePicture.albumDescriptionGet(it).wait().get(); - uint32_t retCount = remoteServicePicture.albumMediaCount(it).wait().get(); - uint32_t parentId = remoteServicePicture.albumParentGet(it).wait().get(); - - if (retCount != 0) { - APPL_INFO(" - [" << it << "] '" << name << "' DESC=" << desc); - if (parentId != 0) { - APPL_INFO(" PARENT : " << parentId); - } - APPL_INFO(" " << retCount << " Medias"); - std::vector retListImage = remoteServicePicture.albumMediaIdGet(it, 0, retCount).wait().get(); - for (auto &it3 : retListImage) { - APPL_INFO(" - " << it3); - } - } else { - APPL_INFO(" - " << it); - } - } - } - #if 1 - echrono::Steady start = echrono::Steady::now(); - //ememory::SharedPtr tmp = zeus::File::create("./tmpResult.bmp"); - ememory::SharedPtr tmp = zeus::File::create("./testImage.png"); - //ememory::SharedPtr tmp = zeus::File::create("./test_log.txt"); - int32_t size = tmp->getSize(); - auto retSendImage = remoteServicePicture.mediaAdd(tmp).wait(); - if (retSendImage.hasError() == true) { - APPL_ERROR(" get an error while sending the File : '" << retSendImage.getErrorType() << "' help=" << retSendImage.getErrorHelp() ); - } else { - echrono::Steady stop = echrono::Steady::now(); - APPL_WARNING(" IO*=" << (stop-start) << " " << retSendImage.get()); - double megaParSec = double(size)/(double((stop-start).count())/1000000000.0); - APPL_WARNING(" speed=" << int64_t(megaParSec/1024.0)/1024.0 << " Mo/s"); - } - #endif - } - } - APPL_INFO(" ----------------------------------"); - APPL_INFO(" -- Get service video (send DATA) "); - APPL_INFO(" ----------------------------------"); - if ( client1.waitForService("video") == true - && true) { - zeus::service::ProxyVideo remoteServiceVideo = client1.getService("video"); - // remove all media (for test) - if (remoteServiceVideo.exist() == true) { - uint32_t count = remoteServiceVideo.mediaIdCount().wait().get(); - std::vector list = remoteServiceVideo.mediaIdGet(0,count).wait().get(); - zeus::FutureGroup groupWait; - for (auto& it : list) { - APPL_INFO("remove ELEMENT : " << it); - groupWait.add(remoteServiceVideo.mediaRemove(it)); - } - groupWait.waitFor(echrono::seconds(2000)); - } - - // Update path: - if (remoteServiceVideo.exist() == true) { - // Send a full path: - installVideoPath(remoteServiceVideo, "testVideo"); - } else { - APPL_ERROR("Can not get service Picture ..."); - } - // List all data: - if (remoteServiceVideo.exist() == true) { - - - } - } - int32_t iii=0; while (iii < 3) { diff --git a/test/client/lutin_zeus-test-client.py b/test/client/lutin_zeus-test-client.py index 705b975..fce70b4 100644 --- a/test/client/lutin_zeus-test-client.py +++ b/test/client/lutin_zeus-test-client.py @@ -28,9 +28,7 @@ def configure(target, my_module): my_module.add_path(".") my_module.add_depend([ 'zeus', - 'zeus-service-user', - 'zeus-service-picture', - 'zeus-service-video' + 'zeus-test-service1', ]) my_module.add_src_file([ 'appl/debug.cpp', diff --git a/test/service1/appl/debug.cpp b/test/service1/appl/debug.cpp index e4b8f85..d0a0efb 100644 --- a/test/service1/appl/debug.cpp +++ b/test/service1/appl/debug.cpp @@ -7,6 +7,6 @@ #include int32_t appl::getLogId() { - static int32_t g_val = elog::registerInstance("zeus-test-service1"); + static int32_t g_val = elog::registerInstance("test-service1"); return g_val; } diff --git a/test/service1/appl/debug.hpp b/test/service1/appl/debug.hpp index 70b9c0b..e3932ae 100644 --- a/test/service1/appl/debug.hpp +++ b/test/service1/appl/debug.hpp @@ -17,13 +17,12 @@ namespace appl { #define APPL_CRITICAL(data) APPL_BASE(1, data) #define APPL_ERROR(data) APPL_BASE(2, data) #define APPL_WARNING(data) APPL_BASE(3, data) +#define APPL_INFO(data) APPL_BASE(4, data) #ifdef DEBUG - #define APPL_INFO(data) APPL_BASE(4, data) #define APPL_DEBUG(data) APPL_BASE(5, data) #define APPL_VERBOSE(data) APPL_BASE(6, data) #define APPL_TODO(data) APPL_BASE(4, "TODO : " << data) #else - #define APPL_INFO(data) do { } while(false) #define APPL_DEBUG(data) do { } while(false) #define APPL_VERBOSE(data) do { } while(false) #define APPL_TODO(data) do { } while(false) diff --git a/test/service1/appl/main-test-service.cpp b/test/service1/appl/main-test-service.cpp deleted file mode 100644 index acfaff1..0000000 --- a/test/service1/appl/main-test-service.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2014, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include -#include -#include -#include - - -#include -namespace appl { - class User { - public: - User() { - APPL_WARNING("new USER"); - } - ~User() { - APPL_WARNING("delete USER"); - } - - }; - - class UserManager { - private: - std::map> m_listLoaded; - public: - UserManager() { - - } - ememory::SharedPtr getUser(const std::string& _userName) { - // TODO : Lock ... - auto it = m_listLoaded.find(_userName); - if (it != m_listLoaded.end()) { - // User already loaded: - return it->second; - } - // load New User: - ememory::SharedPtr tmp(new appl::User); - m_listLoaded.insert(std::make_pair(_userName, tmp)); - return tmp; - } - }; - class Calculator { - public: - Calculator() { - APPL_WARNING("New Calculator ..."); - } - ~Calculator() { - APPL_WARNING("delete Calculator ..."); - } - private: - ememory::SharedPtr m_user; - private: - ememory::SharedPtr m_client; - public: - double mul(double _val1, double _val2) { - return _val1*_val2; - } - public: - Calculator(ememory::SharedPtr _user, ememory::SharedPtr _client) : - m_user(_user), - m_client(_client) { - //advertise("mul", &appl::Service1::mul, "simple multiplication to test double IO"); - } - }; -} - - -int main(int _argc, const char *_argv[]) { - etk::init(_argc, _argv); - zeus::init(_argc, _argv); - ememory::SharedPtr userMng = ememory::makeShared(); - zeus::ServiceType serviceInterface(userMng); - serviceInterface.setDescription("Calculator interface"); - serviceInterface.setVersion("0.1.1"); - serviceInterface.addAuthor("Heero Yui", "yui.heero@gmail.com"); - zeus::AbstractFunction* func = serviceInterface.advertise("mul", &appl::Calculator::mul); - if (func != nullptr) { - func->setDescription("simple multiplication to test double IO"); - func->addParam("val1", "First Parameter To multiply"); - func->addParam("val2", "Second Parameter To multiply"); - } - for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; - if (etk::start_with(data, "--ip=") == true) { - serviceInterface.propertyIp.set(std::string(&data[5])); - } else if (etk::start_with(data, "--port=") == true) { - serviceInterface.propertyPort.set(etk::string_to_uint16_t(std::string(&data[7]))); - } else if ( data == "-h" - || data == "--help") { - APPL_PRINT(etk::getApplicationName() << " - help : "); - APPL_PRINT(" " << _argv[0] << " [options]"); - APPL_PRINT(" --ip=XXX Server connection IP (default: 1.7.0.0.1)"); - APPL_PRINT(" --port=XXX Server connection PORT (default: 1983)"); - return -1; - } - } - APPL_INFO("=================================="); - APPL_INFO("== ZEUS test service1 start =="); - APPL_INFO("=================================="); - serviceInterface.propertyNameService.set("serviceTest1"); - serviceInterface.connect(); - int32_t iii=0; - while (true) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - serviceInterface.pingIsAlive(); - APPL_INFO("service in waiting ... " << iii << "/inf"); - iii++; - } - serviceInterface.disconnect(); - APPL_INFO("=================================="); - APPL_INFO("== ZEUS test service1 stop =="); - APPL_INFO("=================================="); - return 0; -} diff --git a/test/service1/appl/main-test-service1.cpp b/test/service1/appl/main-test-service1.cpp new file mode 100644 index 0000000..66aecc0 --- /dev/null +++ b/test/service1/appl/main-test-service1.cpp @@ -0,0 +1,121 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2014, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +static std::mutex g_mutex; +static std::string g_basePath; +static std::string g_baseDBName = std::string(SERVICE_NAME) + "-database.json"; + +static std::vector> m_listFile; + +static uint64_t m_lastMaxId = 0; +static bool g_needToStore = false; + +static uint64_t createUniqueID() { + m_lastMaxId++; + return m_lastMaxId; +} +namespace appl { + class TestService1 : public zeus::test::Service1 { + private: + std::string m_userName; + public: + TestService1(uint16_t _clientId) { + APPL_VERBOSE("New TestService1 ... for user: " << _clientId); + } + ~TestService1() { + APPL_VERBOSE("delete TestService1 ..."); + } + public: + uint32_t getU32(uint32_t _value) override { + return _value*2; + } + + std::vector getVU32(std::vector _value) override { + for (auto &it: _value) { + it *= 2; + } + return _value; + } + + std::string getString(std::string _value) override { + return "get:'" + _value + "'"; + } + void getVoid() override { + // nothing to do ...; + } + }; +} + +static void store_db() { + APPL_INFO("Store database [START]"); + ejson::Document database; + ejson::Array listFilesArray; + database.add("baseValue", ejson::String("plop")); + bool retGenerate = database.storeSafe(g_basePath + g_baseDBName); + APPL_INFO("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"); + } + g_needToStore = false; +} + +ETK_EXPORT_API bool SERVICE_IO_init(int _argc, const char *_argv[], std::string _basePath) { + g_basePath = _basePath; + std::unique_lock lock(g_mutex); + APPL_INFO("Load USER: " << g_basePath); + load_db(); + APPL_INFO("new USER: [STOP]"); + return true; +} + +ETK_EXPORT_API bool SERVICE_IO_uninit() { + std::unique_lock lock(g_mutex); + store_db(); + APPL_INFO("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_TEST_SERVICE1_DECLARE(appl::TestService1); + diff --git a/test/service1/appl/zeus-test-service1.srv.zeus.idl b/test/service1/appl/zeus-test-service1.srv.zeus.idl new file mode 100644 index 0000000..d933fb0 --- /dev/null +++ b/test/service1/appl/zeus-test-service1.srv.zeus.idl @@ -0,0 +1,20 @@ +#elem-brief: picture interface management +#elem-version: 1.0 +#elem-type:PICTURE +#elem-author:Heero Yui"] + +def configure(target, my_module): + my_module.add_depend([ + 'zeus-router', + 'zeus-gateway', + 'zeus-test-service1-impl', + 'zeus-service-user-impl', + 'zeus-launcher', + 'zeus-test-client', + ]) + return True + + + diff --git a/test/service1/lutin_zeus-test-service1-impl.py b/test/service1/lutin_zeus-test-service1-impl.py new file mode 100644 index 0000000..2504021 --- /dev/null +++ b/test/service1/lutin_zeus-test-service1-impl.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +import lutin.debug as debug +import lutin.tools as tools + + +def get_type(): + return "LIBRARY_DYNAMIC" + #return "BINARY" + +def get_sub_type(): + return "TOOLS" + +def get_desc(): + return "ZEUS test service1" + +def get_licence(): + return "MPL-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atria-soft" + +def get_maintainer(): + return ["Mr DUPIN Edouard "] + +def configure(target, my_module): + my_module.add_path(".") + my_module.add_depend([ + 'zeus', + 'ejson', + 'zeus-test-service1' + ]) + my_module.add_src_file([ + 'appl/debug.cpp', + 'appl/main-test-service1.cpp' + ]) + my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"test-service1\\\"\"") + return True + + + diff --git a/test/service1/lutin_zeus-test-service1.py b/test/service1/lutin_zeus-test-service1.py index 521cc5f..5d97c79 100644 --- a/test/service1/lutin_zeus-test-service1.py +++ b/test/service1/lutin_zeus-test-service1.py @@ -1,16 +1,18 @@ #!/usr/bin/python import lutin.debug as debug import lutin.tools as tools +import lutin.macro as macro def get_type(): - return "BINARY" + return "LIBRARY" + #return "BINARY" def get_sub_type(): return "TOOLS" def get_desc(): - return "ZEUS test service" + return "ZEUS test service1" def get_licence(): return "MPL-2" @@ -25,12 +27,14 @@ def get_maintainer(): return ["Mr DUPIN Edouard "] def configure(target, my_module): - my_module.add_path(".") - my_module.add_depend(['zeus']) - my_module.add_src_file([ - 'appl/debug.cpp', - 'appl/main-test-service.cpp' + my_module.add_depend([ + 'zeus' ]) + + zeus_macro = macro.load_macro('zeus') + zeus_macro.parse_object_idl(my_module, 'appl/zeus-test-service1.srv.zeus.idl') + + my_module.add_flag('c++', "-DSERVICE_NAME=\"\\\"test-service1\\\"\"") return True diff --git a/tools/gateway/appl/GateWay.cpp b/tools/gateway/appl/GateWay.cpp index 908d349..6b509ed 100644 --- a/tools/gateway/appl/GateWay.cpp +++ b/tools/gateway/appl/GateWay.cpp @@ -261,7 +261,7 @@ void appl::GateWay::cleanIO() { // send the message the interface has been removed zeus::WebServer* iface = it->getInterface(); uint16_t id = it->getId(); - iface->event(ZEUS_ID_GATEWAY, uint32_t(id)<<16, "removeInterface", tmpIDToRemove); + iface->call(ZEUS_ID_GATEWAY, uint32_t(id)<<16, "removeInterface", tmpIDToRemove); APPL_WARNING("Send it to :" << id << " " << tmpIDToRemove); } } diff --git a/tools/gateway/appl/IOInterface.cpp b/tools/gateway/appl/IOInterface.cpp index 3d29497..63a5129 100644 --- a/tools/gateway/appl/IOInterface.cpp +++ b/tools/gateway/appl/IOInterface.cpp @@ -69,18 +69,6 @@ void appl::IOInterface::receive(ememory::SharedPtr _value) { // Check if we are the destinated Of this message if ( _value->getDestinationId() == ZEUS_ID_GATEWAY && _value->getDestinationObjectId() == ZEUS_ID_GATEWAY_OBJECT) { - if (_value->getType() == zeus::message::type::event) { - ememory::SharedPtr eventObj = ememory::staticPointerCast(_value); - std::string event = eventObj->getCall(); - if (event == "removeRouterClient") { - // TODO : Broadcast that an IO is remoed ... - m_state = appl::clientState::unconnect; - } else { - APPL_ERROR("Protocol error ==>missing 'call'"); - answerProtocolError(transactionId, "missing parameter: 'event' ... "); - } - return; - } if (_value->getType() != zeus::message::type::call) { APPL_ERROR("Protocol error ==>missing 'call'"); answerProtocolError(transactionId, "missing parameter: 'call' / wrong type 'call'"); @@ -88,6 +76,10 @@ void appl::IOInterface::receive(ememory::SharedPtr _value) { } ememory::SharedPtr callObj = ememory::staticPointerCast(_value); std::string callFunction = callObj->getCall(); + if (callFunction == "removeRouterClient") { + // TODO : Broadcast that an IO is remoed ... + m_state = appl::clientState::unconnect; + } switch (m_state) { case appl::clientState::disconnect: case appl::clientState::unconnect: diff --git a/tools/player-video/appl/MediaDecoder.cpp b/tools/player-video/appl/MediaDecoder.cpp index b49dfc5..9a8c559 100644 --- a/tools/player-video/appl/MediaDecoder.cpp +++ b/tools/player-video/appl/MediaDecoder.cpp @@ -397,11 +397,10 @@ void appl::MediaDecoder::init(ememory::SharedPtr _property, uint m_remote->m_fileHandle = _proxy; APPL_WARNING("We have handle"); m_remote->m_fileHandle.getSize().andThen( - [=](const uint64_t& _value) mutable { + [=](uint64_t _value) { APPL_WARNING("Receive FileSize to index property"); - uint64_t sizeOfBuffer = _value; - APPL_WARNING("pppllloooppp " << sizeOfBuffer); - m_remote->m_buffer.resize(sizeOfBuffer, 0); + APPL_WARNING("pppllloooppp " << _value); + m_remote->m_buffer.resize(_value, 0); APPL_WARNING("pppllloooppp"); m_remote->checkIfWeNeedMoreDataFromNetwork(); APPL_WARNING("pppppplllllloooooopppppp"); @@ -638,7 +637,7 @@ void appl::StreamBuffering::checkIfWeNeedMoreDataFromNetwork() { APPL_DEBUG("Request DATA : " << m_bufferReadPosition << " size=" << sizeRequest); auto futData = m_fileHandle.getPart(m_bufferReadPosition, m_bufferReadPosition+sizeRequest); auto localShared = ememory::dynamicPointerCast(sharedFromThis()); - futData.andThen([=](const zeus::Raw& _value) mutable { + futData.andThen([=](zeus::Raw _value) mutable { return localShared->addDataCallback(_value, m_bufferReadPosition); }); m_callInProgress = true; @@ -660,7 +659,7 @@ void appl::StreamBuffering::checkIfWeNeedMoreDataFromNetwork() { APPL_DEBUG("Request DATA : " << m_bufferReadPosition << " size=" << sizeRequest); auto futData = m_fileHandle.getPart(m_bufferReadPosition, m_bufferReadPosition + sizeRequest); auto localShared = ememory::dynamicPointerCast(sharedFromThis()); - futData.andThen([=](const zeus::Raw& _value) mutable { + futData.andThen([=](zeus::Raw _value) mutable { return localShared->addDataCallback(_value, m_bufferReadPosition); }); m_callInProgress = true; diff --git a/tools/player-video/appl/widget/ListViewer.cpp b/tools/player-video/appl/widget/ListViewer.cpp index 6ffe6e9..270c0ce 100644 --- a/tools/player-video/appl/widget/ListViewer.cpp +++ b/tools/player-video/appl/widget/ListViewer.cpp @@ -89,7 +89,7 @@ void appl::ElementProperty::loadData() { m_widget->markToRedraw(); return true; }); - futMedia.andThen([=](const zeus::ProxyMedia& _media) mutable { + futMedia.andThen([=](zeus::ProxyMedia _media) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get media: " << tmpProperty->m_id); if (_media.exist() == false) { APPL_ERROR("get media error"); @@ -113,7 +113,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get title: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -140,7 +140,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_ERROR(" [" << tmpProperty->m_id << "] get serie: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -167,7 +167,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get saison: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -194,7 +194,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get episode: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -221,7 +221,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get description: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -248,7 +248,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get production-methode: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -275,7 +275,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get type: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); @@ -302,7 +302,7 @@ void appl::ElementProperty::loadData() { } return true; }) - .andThen([=](const std::string& _value) mutable { + .andThen([=](std::string _value) mutable { APPL_INFO(" [" << tmpProperty->m_id << "] get mine-type: " << _value); { std::unique_lock lock(tmpProperty->m_mutex); diff --git a/tools/router/appl/GateWayInterface.cpp b/tools/router/appl/GateWayInterface.cpp index 078dd1c..80ae9a6 100644 --- a/tools/router/appl/GateWayInterface.cpp +++ b/tools/router/appl/GateWayInterface.cpp @@ -95,7 +95,7 @@ void appl::GateWayInterface::rmClient(ememory::SharedPtr ++it; } } - m_interfaceClient.event(uint32_t(id)<<16, ZEUS_ID_GATEWAY, "removeRouterClient", id); + m_interfaceClient.call(uint32_t(id)<<16, ZEUS_ID_GATEWAY, "removeRouterClient", id); } void appl::GateWayInterface::onServiceData(ememory::SharedPtr _value) { diff --git a/zeus/Future.hpp b/zeus/Future.hpp index 49c711b..56af523 100644 --- a/zeus/Future.hpp +++ b/zeus/Future.hpp @@ -79,13 +79,8 @@ namespace zeus { * @brief Attach callback on a specific return action (SUCESS) * @param[in] _callback Handle on the function to call in case of sucess on the call */ - Future& andThen(ObserverFut _callback) { - zeus::FutureBase::andThen( - [=](zeus::FutureBase _fut) { - return _callback(zeus::Future(_fut)); - }); - return *this; - } + /* + note : this is anbigous ??? Future& andThen(std::function _callback) { zeus::FutureBase::andThen( [=](zeus::FutureBase _fut) { @@ -94,6 +89,7 @@ namespace zeus { }); return *this; } + */ Future& andThen(std::function _callback) { zeus::FutureBase::andThen( [=](zeus::FutureBase _fut) { @@ -101,6 +97,14 @@ namespace zeus { }); return *this; } + /* + Future& andThen(ObserverFut _callback) { + zeus::FutureBase::andThen( + [=](zeus::FutureBase _fut) { + return _callback(zeus::Future(_fut)); + }); + return *this; + }*/ /** * @brief Attach callback on a specific return action (ERROR) * @param[in] _callback Handle on the function to call in case of error on the call