add find_by_criteria batch function 52/205952/4
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Fri, 10 May 2019 12:59:43 +0000 (14:59 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 16 May 2019 09:31:20 +0000 (11:31 +0200)
Change-Id: I6f4f45244341843882133abade82e8d4edb9d264

src/batch/BatchRunner.cpp
src/batch/BatchRunner.hpp
src/batch/batch_exec.sh

index cc7ef4b178bdcd723a1d4b38d63c22c6ab2e62aa..2c4d7e43afb47b2401f3475378271327b1fbf835 100644 (file)
@@ -197,6 +197,7 @@ BatchExecutor::BatchExecutor(std::ostream &output) : output(output)
 {
        insertRoleConstants();
        insertStateConstants();
+       insertCollectionConstants();
        insertMethods();
        insertWaits();
        insertActivities();
@@ -307,7 +308,7 @@ void BatchExecutor::findByName(const std::vector<AtspiAccessiblePtr> &elems, std
 }
 
 void BatchExecutor::getAllObjects(AtspiAccessiblePtr root, std::function<void(DBus::ValueOrError<std::vector<AtspiAccessiblePtr>>)> callback,
-                                                                 std::vector<int> roles, std::vector<int> states)
+                                                                 const std::vector<int> &roles, int roleMode, const std::vector<int> &states, int stateMode)
 {
        auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
        auto col = atspi->getCollectionInterface(root);
@@ -315,8 +316,11 @@ void BatchExecutor::getAllObjects(AtspiAccessiblePtr root, std::function<void(DB
                callback(DBus::Error{ "root '" + Atspi::getUniqueId(root) + "' doesn't have collection interface" });
        } else {
                auto m = Atspi::Matcher();
-               if (!states.empty()) m.states(states.begin(), states.end(), ATSPI_Collection_MATCH_ALL);
-               if (!roles.empty()) m.roles(roles.begin(), roles.end(), ATSPI_Collection_MATCH_ANY);
+               if (!states.empty() && stateMode < 0) stateMode = ATSPI_Collection_MATCH_ALL;
+               if (stateMode >= 0) m.states(states.begin(), states.end(), static_cast<AtspiCollectionMatchType>(stateMode));
+
+               if (!roles.empty() && roleMode < 0) roleMode = ATSPI_Collection_MATCH_ANY;
+               if (roleMode >= 0) m.roles(roles.begin(), roles.end(), static_cast<AtspiCollectionMatchType>(roleMode));
                atspi->getMatchedElements(col, ATSPI_Collection_SORT_ORDER_CANONICAL, 0,
                                                                  m, false, std::move(callback));
        }
@@ -602,8 +606,8 @@ std::pair<std::string, std::string> BatchExecutor::getApplicationInfo(app_info_h
                return {};
        }
 
-       char *appid = "";
-       char *instanceid = "";
+       char *appid = const_cast<char *>("");
+       char *instanceid = const_cast<char *>("");
 
        int ret = app_info_get_app_id(app_info, &appid);
        if (ret != APP_MANAGER_ERROR_NONE) {
@@ -766,6 +770,14 @@ void BatchExecutor::insertMethods()
                        return {};
                },  { {"text"} } };
 
+       variables["len"] = EvaluationValueFunction{ [&](EvaluationValue e) -> EvaluationValue {
+                       if (e.isString()) return static_cast<int>(e.asString().size());
+                       if (e.isVector()) return static_cast<int>(e.asVector().size());
+                       if (e.isSet()) return static_cast<int>(e.asSet().size());
+                       if (e.isDict()) return static_cast<int>(e.asDict().size());
+                       throw EvaluationFailure{} << "value of type " << e.typeName() << " doesn't have size property";
+               },  { {"value"} } };
+
        variables["get_at_point"] = EvaluationValueFunction{ [&](Point point) -> EvaluationValue {
                        return convertToUIElement(point);
                }, { {"point"} } };
@@ -781,7 +793,41 @@ void BatchExecutor::insertMethods()
                        return {};
                }, {} };
 
-       variables["find_by_name"] = EvaluationValueFunction{ [&](std::string name, std::vector<int> roles, std::vector<int> states) -> EvaluationValue {
+       variables["find_by_criteria"] = EvaluationValueFunction{
+               [&](std::vector<int> roles, int roleMode, std::vector<int> states, int stateMode) -> EvaluationValue {
+                       auto root = getVisibleRoot();
+                       if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
+                       ASSERT(root->getObject());
+                       Monitor<BatchValueOrError<bool>> monitor;
+                       std::vector<EvaluationValue> result;
+
+                       executeOnMainThread([&]()
+                       {
+                               getAllObjects(root->getObject(), wrap(monitor, [ =, result = &result ](DBus::ValueOrError<std::vector<AtspiAccessiblePtr>> elements) {
+                                       auto &e = std::get<0>(elements);
+                                       if (e.empty()) {
+                                               auto h = monitor.lock();
+                                               h->setValue(true);
+                                       } else {
+                                               result->reserve(e.size());
+                                               for (auto &f : e) {
+                                                       makeUIElement(f, wrap(monitor, [ = ](DBus::ValueOrError<std::shared_ptr<UIElement>> elem) {
+                                                               result->push_back(std::move(std::get<0>(elem)));
+                                                               if (result->size() == result->capacity()) {
+                                                                       auto h = monitor.lock();
+                                                                       h->setValue(true);
+                                                               }
+                                                       }));
+                                               }
+                                       }
+                               }), roles, roleMode, states, stateMode);
+                       }, monitor);
+                       return std::move(result);
+               }, { { "roles", EvaluationValueSet() }, { "roleMode", -1 },
+                       { "states", EvaluationValueSet() }, { "stateMode", -1 }
+               } };
+
+       variables["find_by_name"] = EvaluationValueFunction{ [&](std::string name) -> EvaluationValue {
                        auto root = getVisibleRoot();
                        if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
                        ASSERT(root->getObject());
@@ -797,9 +843,9 @@ void BatchExecutor::insertMethods()
                                                        h->setValue(std::move(std::get<0>(uiElems)));
                                                }));
                                        }));
-                               }), std::move(roles), std::move(states));
+                               }));
                        }, monitor);
-               }, { { "name" }, { "roles", EvaluationValueSet() }, { "states", EvaluationValueSet() } } };
+               }, { { "name" } } };
 
        auto generateTapFunction = [&](size_t tapCount) {
                Optional<EvaluationValue> defValue;
@@ -1089,6 +1135,19 @@ void BatchExecutor::insertStateConstants()
        }
 }
 
+void BatchExecutor::insertCollectionConstants()
+{
+       for (auto pair : std::initializer_list<std::pair<std::string, int>> {
+#define Q(a) { #a, a }
+       Q(ATSPI_Collection_MATCH_ALL),
+               Q(ATSPI_Collection_MATCH_ANY),
+               Q(ATSPI_Collection_MATCH_NONE),
+               Q(ATSPI_Collection_MATCH_EMPTY),
+       }) {
+               ASSERT(pair.first.substr(0, 6 + 11) == "ATSPI_Collection_");
+               variables[pair.first.substr(6 + 11)] = pair.second;
+       }
+}
 void BatchExecutor::insertRoleConstants()
 {
        // from at-spi2-core v. 2.16.0
index 2c64a9770d94f9ab86b209d1e8ac78ba2fd2c1a6..9baa7387f1cae6c0a87d3159d3883c524de37202 100644 (file)
@@ -102,6 +102,7 @@ protected:
        void insertActivities();
        void insertStateConstants();
        void insertRoleConstants();
+       void insertCollectionConstants();
 
        void clearApplications();
        void killApplication(const std::pair<std::string, std::string> &appInstance);
@@ -111,7 +112,7 @@ protected:
        void callActivity(const std::string &activityName, const EvaluationValueFunction::Args &args);
        void findByName(const std::vector<AtspiAccessiblePtr> &elems, std::string requestedName, std::function<void(DBus::ValueOrError<std::vector<AtspiAccessiblePtr>>)> callback);
        void getAllObjects(AtspiAccessiblePtr root, std::function<void(DBus::ValueOrError<std::vector<AtspiAccessiblePtr>>)> callback,
-                                          std::vector<int> roles = {}, std::vector<int> states = {});
+                                          const std::vector<int> &roles = {}, int roleMode = -1, const std::vector<int> &states = {}, int stateMode = -1);
        void makeUIElement(AtspiAccessiblePtr src, std::function<void(DBus::ValueOrError<std::shared_ptr<UIElement>>)> callback);
        void makeUIElements(std::vector<AtspiAccessiblePtr> sources,
                                                std::function<void(DBus::ValueOrError<std::vector<std::shared_ptr<UIElement>>>)> callback);
index f0226b2220d517820b9616cf3e1153a51e616044..c1c898eb2b84c50c331db40baf60d14df8874ea5 100755 (executable)
@@ -1,7 +1,8 @@
 #!/bin/bash
 
 
-# This line is added to remove calendar app and suppress its crashes
+# Thsose two lines are added to remove calendar app and suppress its crashes
+mount -o remount,rw /
 mv /usr/apps/org.tizen.calendar/ /usr/apps/org.tizen.calendar2