diff --git a/tools/gateway/appl/GateWay.cpp b/tools/gateway/appl/GateWay.cpp index adf5d00..035ee89 100644 --- a/tools/gateway/appl/GateWay.cpp +++ b/tools/gateway/appl/GateWay.cpp @@ -304,3 +304,25 @@ void appl::GateWay::onPropertyChangeServicePort() { void appl::GateWay::onPropertyChangeServiceMax() { } + +// Check if it take a long time without activity to kill itself ... +bool appl::GateWay::checkIsAlive(const echrono::Duration& _timeout) { + // if no roueter, no delay to check + if (*propertyRouterNo == true) { + return true; + } + // If no router ==> dead + if (m_routerClient == nullptr) { + return false; + } + // check only for smallest time-out : 1 second. + if (_timeout > echrono::seconds(1)) { + echrono::Steady now = echrono::Steady::now(); + echrono::Steady lastTransmission = m_routerClient->getLastTransmission(); + if ((now - lastTransmission) >= _timeout) { + APPL_INFO("Detect timeout ... last transmission=" << lastTransmission); + return false; + } + } + return true; +} \ No newline at end of file diff --git a/tools/gateway/appl/GateWay.hpp b/tools/gateway/appl/GateWay.hpp index ba80f9f..07278fe 100644 --- a/tools/gateway/appl/GateWay.hpp +++ b/tools/gateway/appl/GateWay.hpp @@ -54,6 +54,8 @@ namespace appl { uint16_t getId(); bool serviceExist(const std::string& _service); uint16_t serviceClientIdGet(const std::string& _service); + // Check if it take a long time without activity to kill itself ... + bool checkIsAlive(const echrono::Duration& _timeout); }; } diff --git a/tools/gateway/appl/RouterInterface.cpp b/tools/gateway/appl/RouterInterface.cpp index 997b9c2..d26d8bc 100644 --- a/tools/gateway/appl/RouterInterface.cpp +++ b/tools/gateway/appl/RouterInterface.cpp @@ -403,4 +403,20 @@ void appl::RouterInterface::clean() { } ++it; } -} \ No newline at end of file +} + +echrono::Steady appl::RouterInterface::getLastTransmission() { + auto receive = m_interfaceWeb.getLastTimeReceive(); + auto send = m_interfaceWeb.getLastTimeSend(); + if (receive >= send) { + if (receive == 0) { + return echrono::Steady::now(); + } + return receive; + } + if (send == 0) { + return echrono::Steady::now(); + } + return send; +} + diff --git a/tools/gateway/appl/RouterInterface.hpp b/tools/gateway/appl/RouterInterface.hpp index 696fd6d..c170dcb 100644 --- a/tools/gateway/appl/RouterInterface.hpp +++ b/tools/gateway/appl/RouterInterface.hpp @@ -40,6 +40,7 @@ namespace appl { bool isAlive(); void send(const ememory::SharedPtr& _data); void clean(); + echrono::Steady getLastTransmission(); }; } diff --git a/tools/gateway/appl/main-gateway.cpp b/tools/gateway/appl/main-gateway.cpp index 9d75f18..ae74d3d 100644 --- a/tools/gateway/appl/main-gateway.cpp +++ b/tools/gateway/appl/main-gateway.cpp @@ -136,6 +136,7 @@ int main(int _argc, const char *_argv[]) { // The default service port is 1985 m_client.propertyPort.set(1985); #endif + uint32_t routerDisconnectionDelay = 30; for (int32_t iii=0; iii<_argc ; ++iii) { std::string data = _argv[iii]; if (etk::start_with(data, "--user=") == true) { @@ -146,6 +147,8 @@ int main(int _argc, const char *_argv[]) { basicGateway.propertyRouterIp.set(std::string(&data[12])); } else if (etk::start_with(data, "--router-port=") == true) { basicGateway.propertyRouterPort.set(etk::string_to_uint16_t(std::string(&data[14]))); + } else if (etk::start_with(data, "--router-delay=") == true) { + routerDisconnectionDelay = etk::string_to_uint32_t(std::string(&data[15])); } else if (etk::start_with(data, "--service-ip=") == true) { basicGateway.propertyServiceIp.set(std::string(&data[13])); #ifdef GATEWAY_ENABLE_LAUNCHER @@ -174,11 +177,12 @@ int main(int _argc, const char *_argv[]) { APPL_PRINT(" " << _argv[0] << " [options]"); APPL_PRINT(" --user=XXX Name of the user that we are connected."); APPL_PRINT(" --no-router Router connection disable ==> this enable the direct donnection of external client like on the router"); - APPL_PRINT(" --router-ip=XXX Router connection IP (default: 1.7.0.0.1)"); - APPL_PRINT(" --router-port=XXX Router connection PORT (default: 1984)"); - APPL_PRINT(" --service-ip=XXX Service connection IP (default: 1.7.0.0.1)"); - APPL_PRINT(" --service-port=XXX Service connection PORT (default: 1985)"); - APPL_PRINT(" --service-max=XXX Service Maximum IO (default: 15)"); + APPL_PRINT(" --router-ip=XXX Router connection IP (default: " << basicGateway.propertyRouterIp.get() << ")"); + APPL_PRINT(" --router-port=XXX Router connection PORT (default: " << basicGateway.propertyRouterPort.get() << ")"); + APPL_PRINT(" --service-ip=XXX Service connection IP (default: " << basicGateway.propertyServiceIp.get() << ")"); + APPL_PRINT(" --service-port=XXX Service connection PORT (default: " << basicGateway.propertyServicePort.get() << ")"); + APPL_PRINT(" --service-max=XXX Service Maximum IO (default: " << basicGateway.propertyServiceMax.get() << ")"); + APPL_PRINT(" --router-delay=XXX Delay before disconnect from the router (default: " << routerDisconnectionDelay << ")"); #ifdef GATEWAY_ENABLE_LAUNCHER APPL_PRINT(" specific for internal launcher:"); APPL_PRINT(" --base-path=XXX base path to search data (default: 'USERDATA:')"); @@ -193,13 +197,19 @@ int main(int _argc, const char *_argv[]) { basicGateway.start(); #ifdef GATEWAY_ENABLE_LAUNCHER if (services.size() == 0) { + bool routerAlive = true; #endif - while (true) { + while (routerAlive == true) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); basicGateway.cleanIO(); + routerAlive = basicGateway.checkIsAlive(echrono::seconds(routerDisconnectionDelay)); + if (routerAlive == false) { + APPL_WARNING("Router is Dead or Timeout"); + } } #ifdef GATEWAY_ENABLE_LAUNCHER } else { + bool routerAlive = true; std::vector> listElements; for (auto &it: services) { ememory::SharedPtr tmp = ememory::makeShared(it); @@ -215,7 +225,8 @@ int main(int _argc, const char *_argv[]) { it->publish(m_client); } uint32_t iii = 0; - while(m_client.isAlive() == true) { + while ( m_client.isAlive() == true + && routerAlive == true) { m_client.pingIsAlive(); m_client.displayConnectedObject(); m_client.cleanDeadObject(); @@ -223,8 +234,14 @@ int main(int _argc, const char *_argv[]) { it->peridic_call(); } basicGateway.cleanIO(); - std::this_thread::sleep_for(std::chrono::seconds(1)); - APPL_INFO("service in waiting ... " << iii << "/inf"); + routerAlive = basicGateway.checkIsAlive(echrono::seconds(routerDisconnectionDelay)); + if (routerAlive == false) { + APPL_WARNING("Router is Dead or Timeout"); + } else { + elog::flush(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + APPL_INFO("service in waiting ... " << iii << "/inf"); + } iii++; } for (auto &it: listElements) { @@ -241,5 +258,6 @@ int main(int _argc, const char *_argv[]) { APPL_INFO("=================================="); APPL_INFO("== ZEUS gateway stop =="); APPL_INFO("=================================="); + elog::flush(); return 0; } diff --git a/tools/launcher/appl/main-launcher.cpp b/tools/launcher/appl/main-launcher.cpp index 7ef3dc0..ba14682 100644 --- a/tools/launcher/appl/main-launcher.cpp +++ b/tools/launcher/appl/main-launcher.cpp @@ -191,6 +191,7 @@ int main(int _argc, const char *_argv[]) { for (auto &it: listElements) { it->uninit(); } + elog::flush(); return 0; } diff --git a/tools/player-video/appl/Windows.cpp b/tools/player-video/appl/Windows.cpp index 175e7fa..75e62dc 100644 --- a/tools/player-video/appl/Windows.cpp +++ b/tools/player-video/appl/Windows.cpp @@ -55,82 +55,16 @@ appl::Windows::Windows(): void appl::Windows::init() { ewol::widget::Windows::init(); load_db(); - std::string composition = std::string(""); - composition += "\n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += " \n"; - composition += "\n"; - m_composer = ewol::widget::Composer::create(); if (m_composer == nullptr) { APPL_CRITICAL(" An error occured ... in the windows creatrion ..."); return; } - m_composer->loadFromString(composition); + m_composer->loadFromFile("DATA:gui.xml"); setSubWidget(m_composer); m_listViewer = ememory::dynamicPointerCast(m_composer->getSubObjectNamed("ws-name-list-viewer")); + m_listViewer->signalSelect.connect(sharedFromThis(), &appl::Windows::onCallbackSelectMedia); subBind(ewol::widget::Button, "bt-previous", signalPressed, sharedFromThis(), &appl::Windows::onCallbackPrevious); subBind(ewol::widget::Button, "bt-play", signalValue, sharedFromThis(), &appl::Windows::onCallbackPlay); @@ -337,3 +271,19 @@ void appl::Windows::onCallbackSelectSourses() { m_listViewer->searchElements("courses"); } +void appl::Windows::onCallbackSelectMedia(const uint32_t& _value) { + ewol::propertySetOnObjectNamed("view-selection", "select", "ws-name-player"); + ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); + if (tmpDisp != nullptr) { + // stop previous (if needed) + tmpDisp->stop(); + // Set new file: + tmpDisp->setZeusMedia(m_clientProp, _value); + tmpDisp->play(); + echrono::Duration time = tmpDisp->getDuration(); + APPL_DEBUG("duration = " << time << " " << etk::to_string(time.toSeconds())); + propertySetOnWidgetNamed("progress-bar", "value", "0"); + propertySetOnWidgetNamed("progress-bar", "max", etk::to_string(time.toSeconds())); + } +} + diff --git a/tools/player-video/appl/Windows.hpp b/tools/player-video/appl/Windows.hpp index 4494ada..7f3dad6 100644 --- a/tools/player-video/appl/Windows.hpp +++ b/tools/player-video/appl/Windows.hpp @@ -49,6 +49,7 @@ namespace appl { void onCallbackSelectTeather(); void onCallbackSelectOneManShow(); void onCallbackSelectSourses(); + void onCallbackSelectMedia(const uint32_t& _value); }; } diff --git a/tools/player-video/appl/widget/ListViewer.cpp b/tools/player-video/appl/widget/ListViewer.cpp index 2d4aa0b..97be7c6 100644 --- a/tools/player-video/appl/widget/ListViewer.cpp +++ b/tools/player-video/appl/widget/ListViewer.cpp @@ -25,9 +25,12 @@ #include #include -appl::widget::ListViewer::ListViewer() { +appl::widget::ListViewer::ListViewer() : + signalSelect(this, "select", "Select a media to view") { addObjectType("appl::widget::ListViewer"); - + propertyCanFocus.setDirectCheck(true); + // Limit event at 1: + setMouseLimit(1); } void appl::widget::ListViewer::init() { @@ -319,6 +322,8 @@ void appl::ElementDisplayed::generateDisplay(vec2 _startPos, vec2 _size) { m_draw.setColor(m_bgColor); m_draw.rectangleWidth(_size); + m_pos = _startPos; + m_size = _size; // -------------------------------------------- // -- Display text... // -------------------------------------------- @@ -364,3 +369,48 @@ void appl::ElementDisplayed::generateDisplay(vec2 _startPos, vec2 _size) { m_image.print(vec2(_size.y(), _size.y())-vec2(20,20)); } + +bool appl::widget::ListViewer::onEventInput(const ewol::event::Input& _event) { + APPL_VERBOSE("Event on BT : " << _event); + vec2 relativePos = relativePosition(_event.getPos()); + int32_t findId = -1; + for (size_t iii=0; iiim_pos.x() + || relativePos.y() < m_listDisplay[iii]->m_pos.y() + || relativePos.x() > m_listDisplay[iii]->m_pos.x() + m_listDisplay[iii]->m_size.x() + || relativePos.y() > m_listDisplay[iii]->m_pos.y() + m_listDisplay[iii]->m_size.y() ) { + continue; + } + findId = iii; + break; + } + if (findId == -1) { + return false; + } + if (_event.getId() == 1) { + if(_event.getStatus() == gale::key::status::pressSingle) { + APPL_WARNING("Select element : " << findId << " " << m_listDisplay[findId]->m_idCurentElement); + ememory::SharedPtr prop = m_listDisplay[findId]->m_property; + if (prop != nullptr) { + std::string fullTitle; + if (prop->m_serie != "") { + fullTitle += prop->m_serie + "-"; + } + if (prop->m_saison != "") { + fullTitle += "s" + prop->m_saison + "-"; + } + if (prop->m_episode != "") { + fullTitle += "e" + prop->m_episode + "-"; + } + fullTitle += prop->m_title; + APPL_WARNING("info element : " << prop->m_id << " title: " << fullTitle); + signalSelect.emit(prop->m_id); + } + return true; + } + } + return false; +} \ No newline at end of file diff --git a/tools/player-video/appl/widget/ListViewer.hpp b/tools/player-video/appl/widget/ListViewer.hpp index 5aaf948..bd19ce1 100644 --- a/tools/player-video/appl/widget/ListViewer.hpp +++ b/tools/player-video/appl/widget/ListViewer.hpp @@ -42,6 +42,8 @@ namespace appl { ememory::SharedPtr m_property; int32_t m_idCurentElement; etk::Color m_bgColor; + vec2 m_pos; + vec2 m_size; protected: ewol::compositing::Image m_image; ewol::compositing::Text m_text; @@ -63,6 +65,8 @@ namespace appl { class ListViewer : public ewol::widget::WidgetScrolled { protected: ewol::compositing::Text m_text; + public: + esignal::Signal signalSelect; //!< when select a media to view protected: ememory::SharedPtr m_clientProp; //!< Generic entrypoint on the Client @@ -85,6 +89,7 @@ namespace appl { m_clientProp = _prop; } void searchElements(std::string _filter); + bool onEventInput(const ewol::event::Input& _event) override; }; } } diff --git a/tools/player-video/appl/widget/VideoPlayer.hpp b/tools/player-video/appl/widget/VideoPlayer.hpp index 92cab02..a053ea8 100644 --- a/tools/player-video/appl/widget/VideoPlayer.hpp +++ b/tools/player-video/appl/widget/VideoPlayer.hpp @@ -62,6 +62,7 @@ namespace appl { void onRegenerateDisplay() override; public: void setFile(const std::string& _fileName); + void setZeusMedia(ememory::SharedPtr _property, uint32_t _mediaId) { }; protected: bool m_isPalying; public: diff --git a/tools/player-video/data/gui.xml b/tools/player-video/data/gui.xml new file mode 100644 index 0000000..b0f5782 --- /dev/null +++ b/tools/player-video/data/gui.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/router/appl/main-router.cpp b/tools/router/appl/main-router.cpp index 14ca99f..8212a64 100644 --- a/tools/router/appl/main-router.cpp +++ b/tools/router/appl/main-router.cpp @@ -59,5 +59,6 @@ int main(int _argc, const char *_argv[]) { APPL_INFO("=================================="); APPL_INFO("== ZEUS router stop =="); APPL_INFO("=================================="); + elog::flush(); return 0; } diff --git a/zeus/Client.cpp b/zeus/Client.cpp index e960616..a0c468c 100644 --- a/zeus/Client.cpp +++ b/zeus/Client.cpp @@ -324,7 +324,7 @@ bool zeus::Client::isAlive() { } void zeus::Client::pingIsAlive() { - if (std::chrono::steady_clock::now() - m_interfaceWeb->getLastTimeSend() >= std::chrono::seconds(30)) { + if (echrono::Steady::now() - m_interfaceWeb->getLastTimeSend() >= echrono::seconds(30)) { m_interfaceWeb->ping(); } } diff --git a/zeus/WebServer.hpp b/zeus/WebServer.hpp index 1c79988..6a3e436 100644 --- a/zeus/WebServer.hpp +++ b/zeus/WebServer.hpp @@ -254,7 +254,7 @@ namespace zeus { * @param[in] * @return */ - const std::chrono::steady_clock::time_point& getLastTimeReceive() { + const echrono::Steady& getLastTimeReceive() { return m_connection.getLastTimeReceive(); } /** @@ -262,7 +262,7 @@ namespace zeus { * @param[in] * @return */ - const std::chrono::steady_clock::time_point& getLastTimeSend() { + const echrono::Steady& getLastTimeSend() { return m_connection.getLastTimeSend(); } private: