Adds support to parse arguments from command line in main function.
Argument passing will be used in test instrumentation.
Change-Id: I109442f16270879fb84313df08742d9a6002c54b
#include "Window.hpp"
#include "dbusLocators.hpp"
#include "utils.hpp"
+#include "DBus.hpp"
#include <device/display.h>
-void UniversalSwitch::initialize()
+void UniversalSwitch::initialize(const std::array<Optional<std::string>, (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>();
compositeSwitchProvider->add(std::make_shared<ScreenSwitchProvider>());
compositeSwitchProvider->add(std::make_shared<AccessoriesSwitchProvider>());
});
}
-void UniversalSwitch::switchToActiveMode()
-{
- DEBUG("Universal-switch active mode");
-
- atspi = std::make_shared<Atspi>();
- navigationInterface = createNavigationImpl();
-
- auto activityFactory = ActivityFactory::getInstance();
- switchManager = SwitchManager::create<SwitchManager>(compositeSwitchProvider, configuration, activityFactory);
-
- textToSpeech = std::make_shared<TextToSpeech>();
- soundFeedback = std::make_shared<SoundFeedback>();
-
- screenScannerManager = std::make_shared<ScreenScannerManager>();
- 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<Atspi>();
+ navigationInterface = createNavigationImpl();
+ switchManager = SwitchManager::create<SwitchManager>(compositeSwitchProvider, configuration, ActivityFactory::getInstance());
+ textToSpeech = std::make_shared<TextToSpeech>();
+ soundFeedback = std::make_shared<SoundFeedback>();
+ screenScannerManager = std::make_shared<ScreenScannerManager>();
+ 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<Atspi>();
+ navigationInterface = createNavigationImpl();
+ break;
}
- navigationInterface.reset();
- atspi.reset();
}
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)
{
device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, displayStateChangedCallback);
callbackHandle.reset();
- switchToPasiveMode();
+ changeMode(Mode::passive);
switchManager.reset();
compositeSwitchProvider.reset();
configuration.reset();
#include "Singleton.hpp"
#include "VConf.hpp"
+#include "Optional.hpp"
+#include "utils.hpp"
#include <device/callback.h>
std::shared_ptr<ScrollActivitiesData> getScrollActivitiesData() const;
void setScrollActivitiesData(std::shared_ptr<ScrollActivitiesData>);
- std::string getTestFilePath() const;
- void setTestFilePath(const std::string &path);
- void setTestOutputPath(const std::string &path);
-
- void initialize();
+ void initialize(const std::array<Optional<std::string>, (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<SwitchManager> &sm);
void setCompositeSwitchProvider(const std::shared_ptr<CompositeSwitchProvider> &csp);
VConfInterface::CallbackHandle callbackHandle;
bool isScanningOn = false;
bool isDisplayOn = false;
- std::string testFilePath, testOutputPath;
+ std::string batchFilePath;
+ std::string batchOutputPath;
};
#endif
#include "UniversalSwitch.hpp"
#include "UniversalSwitchLog.hpp"
#include "Window.hpp"
+#include "utils.hpp"
#include <app.h>
#include <Elementary.h>
}
}
-bool app_create(void *data)
+struct InitData {
+ char **argv;
+ int argc;
+};
+
+bool app_create(void *data_)
{
+ auto data = static_cast<InitData *>(data_);
+ auto arguments = utils::parseArguments(data->argc, data->argv);
+
DEBUG("App create");
ecore_event_init();
- Singleton<UniversalSwitch>::instance().initialize();
+ Singleton<UniversalSwitch>::instance().initialize(arguments);
return true;
}
DEBUG("app termination procedure");
Singleton<UniversalSwitch>::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");
.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);
}
#include "DoneCallback.hpp"
#include <efl_util.h>
+#include <bundle_internal.h>
#include <memory>
+#include <vector>
namespace utils
{
return ecore::TimerRepetitionPolicy::cancel;
}
+
+ 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);
+ std::array<Optional<std::string>, (size_t)Argument::_count> result;
+
+ for (auto key : std::vector<std::pair<std::string, Argument>> {
+ { "TESTS_PATH", Argument::SourcePath },
+ { "TESTS_OUTPUT", Argument::OutputPath },
+ }) {
+ auto val = bundle_get_val(b.get(), key.first.c_str());
+
+ if (val)
+ result[static_cast<size_t>(key.second)] = val;
+ }
+ return result;
+ }
}
#define UTILS_HPP
#include "ecore.hpp"
+#include "Optional.hpp"
#include <string>
+#include <array>
class DoneCallback;
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<Optional<std::string>, (size_t)Argument::_count> parseArguments(int argc, char **argv);
}
#endif