From: Lukasz Wlazly Date: Tue, 19 Dec 2017 12:34:52 +0000 (+0100) Subject: Parsing arguments in main function X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7965cad5d7648fcd8f6e531ffbb64a2f5c2f776b;p=platform%2Fcore%2Faccessibility%2Funiversal-switch.git Parsing arguments in main function Adds support to parse arguments from command line in main function. Argument passing will be used in test instrumentation. Change-Id: I109442f16270879fb84313df08742d9a6002c54b --- diff --git a/src/UniversalSwitch.cpp b/src/UniversalSwitch.cpp index 8040b97..2bf85fa 100644 --- a/src/UniversalSwitch.cpp +++ b/src/UniversalSwitch.cpp @@ -33,14 +33,23 @@ #include "Window.hpp" #include "dbusLocators.hpp" #include "utils.hpp" +#include "DBus.hpp" #include -void UniversalSwitch::initialize() +void UniversalSwitch::initialize(const std::array, (size_t)utils::Argument::_count> &arguments) { setDBusInterface(DBusInterface::create()); resetA11yDbusProperties(); + if (arguments[(size_t)utils::Argument::SourcePath]) { + batchFilePath = *arguments[(size_t)utils::Argument::SourcePath]; + batchOutputPath = *arguments[(size_t)utils::Argument::OutputPath]; + + changeMode(Mode::testExecution); + return; + } + auto compositeSwitchProvider = std::make_shared(); compositeSwitchProvider->add(std::make_shared()); compositeSwitchProvider->add(std::make_shared()); @@ -65,35 +74,40 @@ void UniversalSwitch::initialize() }); } -void UniversalSwitch::switchToActiveMode() -{ - DEBUG("Universal-switch active mode"); - - atspi = std::make_shared(); - navigationInterface = createNavigationImpl(); - - auto activityFactory = ActivityFactory::getInstance(); - switchManager = SwitchManager::create(compositeSwitchProvider, configuration, activityFactory); - - textToSpeech = std::make_shared(); - soundFeedback = std::make_shared(); - - screenScannerManager = std::make_shared(); - screenScannerManager->startAutoscanning(); -} - -void UniversalSwitch::switchToPasiveMode() -{ - DEBUG("Universal-switch passive mode"); - screenScannerManager.reset(); - soundFeedback.reset(); - textToSpeech.reset(); - if (switchManager) { - switchManager->terminate(); - switchManager.reset(); +void UniversalSwitch::changeMode(Mode mode) +{ + switch (mode) { + case Mode::active: + DEBUG("Universal-switch active mode"); + + atspi = std::make_shared(); + navigationInterface = createNavigationImpl(); + switchManager = SwitchManager::create(compositeSwitchProvider, configuration, ActivityFactory::getInstance()); + textToSpeech = std::make_shared(); + soundFeedback = std::make_shared(); + screenScannerManager = std::make_shared(); + screenScannerManager->startAutoscanning(); + break; + + case Mode::passive: + DEBUG("Universal-switch passive mode"); + screenScannerManager.reset(); + if (switchManager) { + switchManager->terminate(); + switchManager.reset(); + } + soundFeedback.reset(); + textToSpeech.reset(); + navigationInterface.reset(); + atspi.reset(); + break; + + case Mode::testExecution: + DEBUG("Universal-switch test mode"); + atspi = std::make_shared(); + navigationInterface = createNavigationImpl(); + break; } - navigationInterface.reset(); - atspi.reset(); } void UniversalSwitch::resetA11yDbusProperties() @@ -108,9 +122,9 @@ void UniversalSwitch::resetA11yDbusProperties() void UniversalSwitch::updateMode() { if (isScanningOn && isDisplayOn) - switchToActiveMode(); + changeMode(Mode::active); else - switchToPasiveMode(); + changeMode(Mode::passive); } void UniversalSwitch::displayStateChangedCallback(device_callback_e type, void *value, void *user_data) @@ -211,7 +225,7 @@ void UniversalSwitch::terminate() { device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, displayStateChangedCallback); callbackHandle.reset(); - switchToPasiveMode(); + changeMode(Mode::passive); switchManager.reset(); compositeSwitchProvider.reset(); configuration.reset(); diff --git a/src/UniversalSwitch.hpp b/src/UniversalSwitch.hpp index 6b44a50..c55394a 100644 --- a/src/UniversalSwitch.hpp +++ b/src/UniversalSwitch.hpp @@ -19,6 +19,8 @@ #include "Singleton.hpp" #include "VConf.hpp" +#include "Optional.hpp" +#include "utils.hpp" #include @@ -54,16 +56,16 @@ public: std::shared_ptr getScrollActivitiesData() const; void setScrollActivitiesData(std::shared_ptr); - std::string getTestFilePath() const; - void setTestFilePath(const std::string &path); - void setTestOutputPath(const std::string &path); - - void initialize(); + void initialize(const std::array, (size_t)utils::Argument::_count> &arguments); void terminate(); - private: - void switchToActiveMode(); - void switchToPasiveMode(); + enum class Mode { + passive, + active, + testExecution + }; + + void changeMode(Mode mode); void updateMode(); void setSwitchManager(const std::shared_ptr &sm); void setCompositeSwitchProvider(const std::shared_ptr &csp); @@ -87,7 +89,8 @@ private: VConfInterface::CallbackHandle callbackHandle; bool isScanningOn = false; bool isDisplayOn = false; - std::string testFilePath, testOutputPath; + std::string batchFilePath; + std::string batchOutputPath; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 50aecf2..dd9f747 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ #include "UniversalSwitch.hpp" #include "UniversalSwitchLog.hpp" #include "Window.hpp" +#include "utils.hpp" #include #include @@ -44,11 +45,19 @@ static void _setting_time_lang_changed(app_event_info_h event_info, void *data) } } -bool app_create(void *data) +struct InitData { + char **argv; + int argc; +}; + +bool app_create(void *data_) { + auto data = static_cast(data_); + auto arguments = utils::parseArguments(data->argc, data->argv); + DEBUG("App create"); ecore_event_init(); - Singleton::instance().initialize(); + Singleton::instance().initialize(arguments); return true; } @@ -57,9 +66,14 @@ void app_terminate(void *data) DEBUG("app termination procedure"); Singleton::instance().terminate(); ecore_event_shutdown(); - return; } + +/* + * To run Universal-Switch in test mode it should be run this way: + * app_launcher -s org.tizen.universal-switch TESTS_PATH [PATH] + */ + int main(int argc, char *argv[]) { DEBUG("main function called"); @@ -71,9 +85,12 @@ int main(int argc, char *argv[]) .resume = nullptr, .app_control = nullptr }; + InitData data { + argv, argc + }; app_event_handler_h handler; ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, _setting_time_lang_changed, nullptr); - return ui_app_main(argc, argv, &event_callback, nullptr); + return ui_app_main(argc, argv, &event_callback, &data); } diff --git a/src/utils.cpp b/src/utils.cpp index 7a63608..dd4b9cf 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -20,8 +20,10 @@ #include "DoneCallback.hpp" #include +#include #include +#include namespace utils { @@ -118,4 +120,21 @@ namespace utils return ecore::TimerRepetitionPolicy::cancel; } + + std::array, (size_t)Argument::_count> parseArguments(int argc, char **argv) + { + auto b = std::unique_ptr(bundle_import_from_argv(argc, argv), bundle_free); + std::array, (size_t)Argument::_count> result; + + for (auto key : std::vector> { + { "TESTS_PATH", Argument::SourcePath }, + { "TESTS_OUTPUT", Argument::OutputPath }, + }) { + auto val = bundle_get_val(b.get(), key.first.c_str()); + + if (val) + result[static_cast(key.second)] = val; + } + return result; + } } diff --git a/src/utils.hpp b/src/utils.hpp index 2b5f268..ed6586f 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -18,8 +18,10 @@ #define UTILS_HPP #include "ecore.hpp" +#include "Optional.hpp" #include +#include class DoneCallback; @@ -86,6 +88,23 @@ namespace utils static constexpr double LONG_DELAY = 1.0; static constexpr double NO_DELAY = 0.0; }; + + /** + * @brief Enum representing allowed arguments + * + * Every enum's value is an index into array of values returned by parseArguments function + */ + enum class Argument { + SourcePath = 0, OutputPath, _count + }; + + /** + * @brief Parses command line into arguments + * + * Returns array of allowed arguments indexed by Argument enumeration. + * Empty Optional object means given argument werent passed. + */ + std::array, (size_t)Argument::_count> parseArguments(int argc, char **argv); } #endif