From c52afc79802cecd91f7ed72e68a0b471c1fdfb1b Mon Sep 17 00:00:00 2001 From: Sangwan Kwon Date: Thu, 9 Jan 2020 18:32:20 +0900 Subject: [PATCH] Apply shutdown condition to service If timeout is occured and there are no activated admins, shutdown the service Signed-off-by: Sangwan Kwon --- src/vist/rmi/gateway.cpp | 12 ++++++------ src/vist/rmi/gateway.hpp | 5 +++-- src/vist/service/vistd.cpp | 7 ++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/vist/rmi/gateway.cpp b/src/vist/rmi/gateway.cpp index 1a2c2e6..801f6a5 100644 --- a/src/vist/rmi/gateway.cpp +++ b/src/vist/rmi/gateway.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public: reply.enclose(result); return reply; - }; + }; #ifdef TIZEN this->server = std::make_unique(path, dispatcher); @@ -62,9 +62,9 @@ public: #endif } - inline void start() + inline void start(int timeout, std::function stopper) { - this->server->run(); + this->server->run(timeout, stopper); } inline void stop() @@ -82,9 +82,9 @@ Gateway::Gateway(const std::string& path) : pImpl(std::make_unique(*this, Gateway::~Gateway() = default; -void Gateway::start() +void Gateway::start(int timeout, std::function stopper) { - this->pImpl->start(); + this->pImpl->start(timeout, stopper); } void Gateway::stop(void) diff --git a/src/vist/rmi/gateway.hpp b/src/vist/rmi/gateway.hpp index 48fc45e..bef6b19 100644 --- a/src/vist/rmi/gateway.hpp +++ b/src/vist/rmi/gateway.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -38,7 +39,7 @@ public: Gateway(Gateway&&) = default; Gateway& operator=(Gateway&&) = default; - void start(); + void start(int timeout = -1, std::function stopper = nullptr); void stop(); template diff --git a/src/vist/service/vistd.cpp b/src/vist/service/vistd.cpp index 45b680b..d32a7bf 100644 --- a/src/vist/service/vistd.cpp +++ b/src/vist/service/vistd.cpp @@ -39,12 +39,13 @@ void Vistd::start() { INFO(VIST) << "Vistd daemon starts."; - policy::PolicyManager::Instance(); - rmi::Gateway gateway(SOCK_ADDR); EXPOSE(gateway, *this, &Vistd::query); - gateway.start(); + auto& pm = policy::PolicyManager::Instance(); + + /// Shutdown service if timeout is occured without activated admin + gateway.start(3000, [&pm]() -> bool { return !pm.isActivated(); }); INFO(VIST) << "Vistd daemon stopped."; } -- 2.34.1