Added launch_application function in BatchRunner 79/210179/2
authorAdrian Wojciechowski <a.wojciecho3@partner.samsung.com>
Tue, 16 Jul 2019 11:07:19 +0000 (13:07 +0200)
committerAdrian Wojciechowski <a.wojciecho3@partner.samsung.com>
Tue, 16 Jul 2019 13:01:03 +0000 (13:01 +0000)
Change-Id: Ia31d4ab7fa169fe87471377468d1f9e2b50de6b2

src/batch/BatchRunner.cpp
src/utils.cpp
src/utils.hpp

index 19a8f825575ef7b033968e0f261b6926914d00f4..2cff47232cc725aa49f6859715f793bf6398d508 100644 (file)
@@ -990,6 +990,15 @@ void BatchExecutor::insertMethods()
                        return std::vector<std::shared_ptr<UIElement>>{};
                }, { { "name" } } };
 
+       variables["launch_application"] = EvaluationValueFunction{ [&](std::string name) -> EvaluationValue {
+                       executeOnMainThread([&]()
+                       {
+                               bool ret = utils::generateLaunchRequest(name);
+                               if (!ret) throw EvaluationFailure{} << "failed to launch application " << name;
+                       });
+                       return EvaluationValue{};
+               }, { { "name" } } };
+
        auto generateTapFunction = [&](size_t tapCount) {
                Optional<EvaluationValue> defValue;
                if (tapCount > 1)
index dad706135d07530bd3890026bc1abe4ca8b3e496..1878f0570828725426b9040d6cc274872d34e506 100644 (file)
@@ -21,6 +21,8 @@
 #include "dbusLocators.hpp"
 #include "batch/Monitor.hpp"
 
+#include <app.h>
+
 #include <efl_util.h>
 #include <bundle_internal.h>
 
@@ -86,6 +88,30 @@ namespace utils
                return dbus.method<void(bool, int, double)>("DispatchRotaryEvent").call(clockwise, multiplicity, delay);
        }
 
+       bool generateLaunchRequest(std::string appId)
+       {
+               app_control_h appControlHandle;
+
+               DEBUG("Launching application %s", appId.c_str());
+
+               auto status = app_control_create(&appControlHandle);
+               RETURN_DEFAULT_IF(status != APP_CONTROL_ERROR_NONE);
+
+               status = app_control_set_operation(appControlHandle, APP_CONTROL_OPERATION_DEFAULT);
+               RETURN_DEFAULT_IF(status != APP_CONTROL_ERROR_NONE);
+
+               status = app_control_set_app_id(appControlHandle, appId.c_str());
+               RETURN_DEFAULT_IF(status != APP_CONTROL_ERROR_NONE);
+
+               status = app_control_send_launch_request(appControlHandle, NULL, NULL);
+               if (status != APP_CONTROL_ERROR_NONE) {
+                       ERROR("launching '%s' failed with error code %d", appId.c_str(), status);
+                       return false;
+               }
+
+               return true;
+       }
+
        std::array<Optional<std::string>, (size_t)Argument::_count> parseArguments(int argc, char **argv)
        {
                auto b = std::unique_ptr<bundle, int(*)(bundle *)>(bundle_import_from_argv(argc, argv), bundle_free);
index 80f6196430e998efcb5893aab3707b56de32c2a8..c1dd160e28f23d8600c089e5fd572122823aad86 100644 (file)
@@ -66,6 +66,7 @@ namespace utils
        DBus::ValueOrError<void> generateDragGesture(int from_x, int from_y, int to_x, int to_y, int steps, double hold_time, int pointers_no = 1);
        DBus::ValueOrError<void> generatePinchGesture(int x, int y, int radius_change, int steps);
        DBus::ValueOrError<void> generateWheelTurn(bool clockwise, int multiplicity, double delay);
+       bool generateLaunchRequest(std::string appId);
 
        /**
         * @brief Enum representing allowed arguments