Apply shutdown condition to service
authorSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 9 Jan 2020 09:32:20 +0000 (18:32 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Tue, 14 Jan 2020 01:57:30 +0000 (10:57 +0900)
If timeout is occured and there are no activated admins,
shutdown the service

Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/vist/rmi/gateway.cpp
src/vist/rmi/gateway.hpp
src/vist/service/vistd.cpp

index 1a2c2e6..801f6a5 100644 (file)
@@ -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<ondemand::Server>(path, dispatcher);
@@ -62,9 +62,9 @@ public:
 #endif
        }
 
-       inline void start()
+       inline void start(int timeout, std::function<bool()> 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<Impl>(*this,
 
 Gateway::~Gateway() = default;
 
-void Gateway::start()
+void Gateway::start(int timeout, std::function<bool()> stopper)
 {
-       this->pImpl->start();
+       this->pImpl->start(timeout, stopper);
 }
 
 void Gateway::stop(void)
index 48fc45e..bef6b19 100644 (file)
@@ -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 <vist/klass/functor.hpp>
 #include <vist/macro.hpp>
 
+#include <functional>
 #include <memory>
 #include <string>
 
@@ -38,7 +39,7 @@ public:
        Gateway(Gateway&&) = default;
        Gateway& operator=(Gateway&&) = default;
 
-       void start();
+       void start(int timeout = -1, std::function<bool()> stopper = nullptr);
        void stop();
 
        template<typename O, typename F>
index 45b680b..d32a7bf 100644 (file)
@@ -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.";
 }