bootstrap: add a infra to handle pre/post moment of execution maion command
authorWonki Kim <wonki_.kim@samsung.com>
Thu, 13 Feb 2020 07:22:19 +0000 (16:22 +0900)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 3 Mar 2020 06:59:56 +0000 (15:59 +0900)
bootstrap handles APIs by using Command pattern.
global pre/post commands are executed just after and before execution of the command.
and it gets necessary to handles pre/post moment for each command.
so this patch introduces a infrastructure to handle it.

Change-Id: I2e62cb7b9018ffb020f72666276be55605a588a0

13 files changed:
bootstrap/server/inc/AurumServiceImpl.h
bootstrap/server/inc/Commands/CloseAppCommand.h
bootstrap/server/inc/Commands/Command.h
bootstrap/server/inc/Commands/GetAttributeCommand.h
bootstrap/server/inc/Commands/LaunchAppCommand.h
bootstrap/server/inc/Commands/PostCommand.h
bootstrap/server/inc/Commands/PreCommand.h
bootstrap/server/src/AurumServiceImpl.cc
bootstrap/server/src/Commands/CloseAppCommand.cc
bootstrap/server/src/Commands/Command.cc
bootstrap/server/src/Commands/LaunchAppCommand.cc
bootstrap/server/src/Commands/PostCommand.cc
bootstrap/server/src/Commands/PreCommand.cc

index 935094b569710d8efbbb4f28ec512c53037e053a..bf6ae4144d5a00602dff1c12805b22aa3c91a575 100644 (file)
@@ -11,7 +11,7 @@ public:
     virtual ~aurumServiceImpl();
 
 protected:
-    ::grpc::Status execute(Command &cmd);
+    ::grpc::Status execute(Command *cmd);
 
 public:
     ::grpc::Status sync(::grpc::ServerContext *  context,
index e4eb3d3c91a22fbc7de2d0a8f96283fb20fb30da..fb00f3996599d279214d0c6a527facbbe0b4b835 100644 (file)
@@ -16,8 +16,8 @@ private:
 public:
     CloseAppCommand(const ::aurum::ReqCloseApp* request,
                     ::aurum::RspCloseApp*       response);
-    ;
     ::grpc::Status execute() override;
+    ::grpc::Status executePost() override;
 };
 
 #endif
\ No newline at end of file
index d443856d3b9e0661d553b370f8bdc934bc872fd6..59bf76ec3af4c734d54d5c66707689302e3169fc 100644 (file)
@@ -12,6 +12,8 @@ class Command {
 public:
     virtual ~Command(){};
     virtual ::grpc::Status execute() = 0;
+    virtual ::grpc::Status executePost();
+    virtual ::grpc::Status executePre();
 };
 
 #endif
\ No newline at end of file
index a69fc46f9d1795310dd479cd8371560bd5c777c2..bea4b92d124449a06b85605ec8650b57d97e0d3a 100644 (file)
@@ -23,13 +23,15 @@ public:
 class AttributeGetter {
 private:
 public:
+    virtual ~AttributeGetter();
     static AttributeGetter *Creator(::aurum::ReqGetAttribute_RequestType type);
-    virtual bool getPerform(UiObject *obj,  ::aurum::RspGetAttribute* mResponse){}
+    virtual bool getPerform(UiObject *obj,  ::aurum::RspGetAttribute* mResponse){return true;}
 };
 
 class VisibleGetter : public AttributeGetter{
 private:
 public:
+    virtual ~VisibleGetter();
     bool getPerform(UiObject *obj, ::aurum::RspGetAttribute* rsp) override;
 };
 
index bf5352f53da62c402445309f86fb776563110bba..2227fed689c4412570f403a477e66c7be5641a85 100644 (file)
@@ -16,8 +16,8 @@ private:
 public:
     LaunchAppCommand(const ::aurum::ReqLaunchApp* request,
                      ::aurum::RspLaunchApp*       response);
-    ;
     ::grpc::Status execute() override;
+    ::grpc::Status executePost() override;
 };
 
 #endif
\ No newline at end of file
index 757b4ba20921c79ac60a2bba79edd450129aa09c..29bd8a217e20cfc0038fd989e36403b66f9be6b0 100644 (file)
@@ -15,6 +15,7 @@ private:
 public:
     PostCommand(Command *cmd);
     ::grpc::Status execute() override;
+    ::grpc::Status executePre() override;
 };
 
 #endif
\ No newline at end of file
index 0005ee2389092e7acf6a9ce2dbeb551be86be118..7d59d2a6e360a5edf6b7d7288ffae2740fb7f811 100644 (file)
@@ -15,6 +15,7 @@ private:
 public:
     PreCommand(Command *cmd);
     ::grpc::Status execute() override;
+    ::grpc::Status executePost() override;
 };
 
 #endif
\ No newline at end of file
index fc15be05d94d5c5a8582233f1752aa3ef54c7180..1b689f1cda7f28fea36dca4802aea84acd61e42e 100644 (file)
@@ -16,11 +16,11 @@ aurumServiceImpl::aurumServiceImpl()
     Accessible::getInstance();
 }
 
-::grpc::Status aurumServiceImpl::execute(Command& cmd)
+::grpc::Status aurumServiceImpl::execute(Command* cmd)
 {
-    PreCommand     proxyPreCmd{&cmd};
-    PostCommand    proxyPostCmd{&proxyPreCmd};
-    ::grpc::Status rst = proxyPostCmd.execute();
+    std::unique_ptr<PreCommand>  proxyPreCmd  = std::make_unique<PreCommand>(cmd);
+    std::unique_ptr<PostCommand> proxyPostCmd = std::make_unique<PostCommand>(proxyPreCmd.get());
+    ::grpc::Status rst = proxyPostCmd->execute();
     return rst;
 }
 
@@ -29,154 +29,154 @@ aurumServiceImpl::~aurumServiceImpl() {}
     ::grpc::ServerContext* context, const ::aurum::ReqEmpty* request,
     ::aurum::RspEmpty* response)
 {
-    SyncCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<SyncCommand> cmd = std::make_unique<SyncCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::aurumServiceImpl::killServer(
     ::grpc::ServerContext* context, const ::aurum::ReqEmpty* request,
     ::aurum::RspEmpty* response)
 {
-    KillServerCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<KillServerCommand> cmd = std::make_unique<KillServerCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::aurumServiceImpl::findElement(
     ::grpc::ServerContext* context, const ::aurum::ReqFindElement* request,
     ::aurum::RspFindElement* response)
 {
-    FindElementCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<FindElementCommand> cmd = std::make_unique<FindElementCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::aurumServiceImpl::click(
     ::grpc::ServerContext* context, const ::aurum::ReqClick* request,
     ::aurum::RspClick* response)
 {
-    ClickCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<ClickCommand> cmd = std::make_unique<ClickCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::getValue(::grpc::ServerContext*      context,
                                           const ::aurum::ReqGetValue* request,
                                           ::aurum::RspGetValue*       response)
 {
-    GetValueCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<GetValueCommand> cmd = std::make_unique<GetValueCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::setValue(::grpc::ServerContext*      context,
                                           const ::aurum::ReqSetValue* request,
                                           ::aurum::RspSetValue*       response)
 {
-    SetValueCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<SetValueCommand> cmd = std::make_unique<SetValueCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::getAttribute(
     ::grpc::ServerContext* context, const ::aurum::ReqGetAttribute* request,
     ::aurum::RspGetAttribute* response)
 {
-    GetAttributeCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<GetAttributeCommand> cmd = std::make_unique<GetAttributeCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::getSize(::grpc::ServerContext*     context,
                                          const ::aurum::ReqGetSize* request,
                                          ::aurum::RspGetSize*       response)
 {
-    GetSizeCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<GetSizeCommand> cmd = std::make_unique<GetSizeCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::clear(::grpc::ServerContext*   context,
                                        const ::aurum::ReqClear* request,
                                        ::aurum::RspClear*       response)
 {
-    ClearCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<ClearCommand> cmd = std::make_unique<ClearCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::installApp(
     ::grpc::ServerContext*                         context,
     ::grpc::ServerReader< ::aurum::ReqInstallApp>* request,
     ::aurum::RspInstallApp*                        response)
 {
-    InstallAppCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<InstallAppCommand> cmd = std::make_unique<InstallAppCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::removeApp(::grpc::ServerContext*       context,
                                            const ::aurum::ReqRemoveApp* request,
                                            ::aurum::RspRemoveApp* response)
 {
-    RemoveAppCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<RemoveAppCommand> cmd = std::make_unique<RemoveAppCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::getAppInfo(
     ::grpc::ServerContext* context, const ::aurum::ReqGetAppInfo* request,
     ::aurum::RspGetAppInfo* response)
 {
-    GetAppInfoCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<GetAppInfoCommand> cmd = std::make_unique<GetAppInfoCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::launchApp(::grpc::ServerContext*       context,
                                            const ::aurum::ReqLaunchApp* request,
                                            ::aurum::RspLaunchApp* response)
 {
-    LaunchAppCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<LaunchAppCommand> cmd = std::make_unique<LaunchAppCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::closeApp(::grpc::ServerContext*      context,
                                           const ::aurum::ReqCloseApp* request,
                                           ::aurum::RspCloseApp*       response)
 {
-    CloseAppCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<CloseAppCommand> cmd = std::make_unique<CloseAppCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::touchDown(::grpc::ServerContext*       context,
                                            const ::aurum::ReqTouchDown* request,
                                            ::aurum::RspTouchDown* response)
 {
-    TouchDownCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<TouchDownCommand> cmd = std::make_unique<TouchDownCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::touchUp(::grpc::ServerContext*     context,
                                          const ::aurum::ReqTouchUp* request,
                                          ::aurum::RspTouchUp*       response)
 {
-    TouchUpCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<TouchUpCommand> cmd = std::make_unique<TouchUpCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::touchMove(::grpc::ServerContext*       context,
                                            const ::aurum::ReqTouchMove* request,
                                            ::aurum::RspTouchMove* response)
 {
-    TouchMoveCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<TouchMoveCommand> cmd = std::make_unique<TouchMoveCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::longClick(::grpc::ServerContext*   context,
                                            const ::aurum::ReqClick* request,
                                            ::aurum::RspClick*       response)
 {
-    LongClickCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<LongClickCommand> cmd = std::make_unique<LongClickCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::flick(::grpc::ServerContext*   context,
                                        const ::aurum::ReqFlick* request,
                                        ::aurum::RspFlick*       response)
 {
-    FlickCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<FlickCommand> cmd = std::make_unique<FlickCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::getDeviceTime(
     ::grpc::ServerContext* context, const ::aurum::ReqGetDeviceTime* request,
     ::aurum::RspGetDeviceTime* response)
 {
-    GetDeviceTimeCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<GetDeviceTimeCommand> cmd = std::make_unique<GetDeviceTimeCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::getLocation(
     ::grpc::ServerContext* context, const ::aurum::ReqGetLocation* request,
     ::aurum::RspGetLocation* response)
 {
-    GetLocationCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<GetLocationCommand> cmd = std::make_unique<GetLocationCommand>(request, response);
+    return execute(cmd.get());
 }
 ::grpc::Status aurumServiceImpl::sendKey(::grpc::ServerContext* context,
                                          const ::aurum::ReqKey* request,
                                          ::aurum::RspKey*       response)
 {
-    SendKeyCommand cmd(request, response);
-    return execute(cmd);
+    std::unique_ptr<SendKeyCommand> cmd = std::make_unique<SendKeyCommand>(request, response);
+    return execute(cmd.get());
 }
index 9cb72df76190c095c1fd36b787ceb50e2b5bec7d..3221d365fb73287e63336d168d091d4e4ac96030 100644 (file)
@@ -1,5 +1,7 @@
 #include "CloseAppCommand.h"
 #include <loguru.hpp>
+#include <chrono>
+#include <thread>
 #ifdef GBSBUILD
 #include <app_manager_extension.h>
 #endif
@@ -33,4 +35,11 @@ CloseAppCommand::CloseAppCommand(const ::aurum::ReqCloseApp* request,
     }
 #endif
     return grpc::Status::OK;
+}
+
+::grpc::Status CloseAppCommand::executePost()
+{
+    LOG_SCOPE_F(INFO, "CloseAppCommand::executePost");
+    std::this_thread::sleep_for(std::chrono::milliseconds{1500});
+    return grpc::Status::OK;
 }
\ No newline at end of file
index 5d4690ed8bb5d9e6cc4848efc48fba42264d1049..71a6eb789d7637c17dedc2b978c883df98325b51 100644 (file)
@@ -1,2 +1,12 @@
 #include "Command.h"
-#include <loguru.hpp>
\ No newline at end of file
+#include <loguru.hpp>
+
+::grpc::Status Command::executePost()
+{
+    return ::grpc::Status::OK;
+}
+
+::grpc::Status Command::executePre()
+{
+    return ::grpc::Status::OK;
+}
index 020044c28bcadc84a2f85a23496e81e08bbc100b..6002a94f55dd7c3755e1d64390a046204957e1e6 100644 (file)
@@ -1,5 +1,8 @@
 #include "LaunchAppCommand.h"
 #include <loguru.hpp>
+#include <chrono>
+#include <thread>
+
 #ifdef GBSBUILD
 #include <app_control.h>
 #endif
@@ -42,4 +45,10 @@ LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp* request,
     }
 #endif
     return grpc::Status::OK;
+}
+::grpc::Status LaunchAppCommand::executePost()
+{
+    LOG_SCOPE_F(INFO, "LaunchAppCommand::executePost");
+    std::this_thread::sleep_for(std::chrono::milliseconds{1500});
+    return grpc::Status::OK;
 }
\ No newline at end of file
index 27ba5ade6469878cd6fc500389101c3187dff5d8..71f4692b9423a9623bbf2ee8e939f22f87d3e05c 100644 (file)
@@ -9,6 +9,12 @@ PostCommand::PostCommand(Command *cmd) : mCommand{cmd} {}
 {
     ::grpc::Status rst = mCommand->execute();
     LOG_SCOPE_F(INFO, "PostCommand --------------- ");
+    mCommand->executePost();
     // do post-command
     return rst;
+}
+
+::grpc::Status PostCommand::executePre()
+{
+    return mCommand->executePre();
 }
\ No newline at end of file
index 647c10bb9875fa898c89400d2f1f311d3c27dff5..a0f13ff65138ffb54b0f6054d5967d3acc227dbf 100644 (file)
@@ -10,9 +10,17 @@ PreCommand::PreCommand(Command *cmd) : mCommand{cmd} {}
     {
         LOG_SCOPE_F(INFO, "PreCommand --------------- ");
         AtspiAccessible *n = atspi_get_desktop(0);
-        free(atspi_accessible_get_name(n, NULL));
-        g_object_unref(n);
+        if (n) {
+            char *name = atspi_accessible_get_name(n, NULL);
+            if(name) free(name);
+            g_object_unref(n);
+        }
     }
-
+    mCommand->executePre();
     return mCommand->execute();
+}
+
+::grpc::Status PreCommand::executePost()
+{
+    return mCommand->executePost();
 }
\ No newline at end of file