--- /dev/null
+#include "UIActivity.hpp"
+#include "ActivityFactory.hpp"
+#include "UniversalSwitchLog.hpp"
+#include "ScreenScannerManager.hpp"
+
+//TODO: ramove after integration with SelectActivity
+class AcceptScanningActivity : public UIActivity, private RegisterActivity<AcceptScanningActivity>
+{
+public:
+ constexpr static const char *activityType = "ACCEPT_SCANNING";
+ AcceptScanningActivity()
+ : UIActivity(activityType)
+ {}
+
+ bool process() override
+ {
+ ScreenScannerManager::instance().acceptAutoscanning();
+ return true;
+ }
+};
auto event = static_cast<Ecore_Event_Key *>(ev);
std::string keyId(event->key);
+ //TODO: static_cast should work fine here however it is causing runtime errors in animation rendering
auto accessoriesSwitchProvider = reinterpret_cast<AccessoriesSwitchProvider *>(data);
auto switchId = SwitchId(keyId, accessoriesSwitchProvider->getId());
auto sw = accessoriesSwitchProvider->findSwitchById(switchId.getGlobalId());
-
if (sw)
accessoriesSwitchProvider->notify(sw);
SET(SRCS
+ main.cpp
AccessoriesSwitchProvider.cpp
QueryBuilder.cpp
Switch.cpp
SwitchProvider.cpp
- universalswitch.cpp
Activity.cpp
CompositeSwitchProvider.cpp
SwitchConfigurationItem.cpp
AutoScanOnActivity.cpp
MenuBuilder.cpp
Atspi.cpp
+ UniversalSwitch.cpp
+ AcceptScanningActivity.cpp
)
ADD_LIBRARY(universal-switch-obj OBJECT ${SRCS})
{
return providers;
}
+
+void CompositeSwitchProvider::attach(std::weak_ptr<Observer<Switch>> observer, std::shared_ptr<Condition<Switch>> cond)
+{
+ auto item = cond->getItem();
+ if (item) {
+ auto providerId = item->getId()->getProviderId();
+ for (auto &provider : providers)
+ if (provider->getId() == providerId) {
+ provider->attach(observer, std::move(cond));
+ return;
+ }
+ } else {
+ for (auto &provider : providers)
+ provider->attach(observer, cond);
+ }
+}
std::shared_ptr<Switch> findSwitchById(const std::string &id) const override;
void add(std::shared_ptr<SwitchProvider> provider);
std::vector<std::shared_ptr<SwitchProvider>> getProviders();
+ void attach(std::weak_ptr<Observer<Switch>> observer, std::shared_ptr<Condition<Switch>> cond) override;
private:
std::vector<std::shared_ptr<SwitchProvider>> providers;
SingletonBase &operator = (SingletonBase &&) = delete;
};
+template <class Implementation>
+class Singleton : protected SingletonBase
+{
+public:
+ static Implementation &instance()
+ {
+ static Implementation implementation;
+ return implementation;
+ }
+};
+
template <class Interface>
class MockableSingleton : protected SingletonBase
{
class Subject
{
public:
- void attach(std::weak_ptr<Observer<T>> observer, std::unique_ptr<Condition<T>> cond)
+ virtual void attach(std::weak_ptr<Observer<T>> observer, std::shared_ptr<Condition<T>> cond)
{
observers.emplace_back(std::move(observer), std::move(cond));
}
}
}
- std::vector<std::pair<std::weak_ptr<Observer<T>>, std::unique_ptr<Condition<T>>>> observers;
+ std::vector<std::pair<std::weak_ptr<Observer<T>>, std::shared_ptr<Condition<T>>>> observers;
};
#endif
void update(const std::shared_ptr<UIElement> &elem) override;
-private:
+protected:
std::shared_ptr<UIElement> uiElement;
};
--- /dev/null
+#include "UniversalSwitch.hpp"
+
+std::shared_ptr<SwitchManager> UniversalSwitch::getSwitchManager() const
+{
+ return switchManager;
+}
+
+std::shared_ptr<CompositeSwitchProvider> UniversalSwitch::getCompositeSwitchProvider() const
+{
+ return compositeSwitchProvider;
+}
+
+void UniversalSwitch::setSwitchManager(const std::shared_ptr<SwitchManager> &sm)
+{
+ switchManager = sm;
+}
+
+void UniversalSwitch::setCompositeSwitchProvider(const std::shared_ptr<CompositeSwitchProvider> &csp)
+{
+ compositeSwitchProvider = csp;
+}
\ No newline at end of file
--- /dev/null
+#ifndef UNIVERSAL_SWITCH_HPP
+#define UNIVERSAL_SWITCH_HPP
+
+#include "Singleton.hpp"
+
+#include "SwitchManager.hpp"
+#include "CompositeSwitchProvider.hpp"
+
+struct UniversalSwitch : public Singleton<UniversalSwitch> {
+public:
+ std::shared_ptr<SwitchManager> getSwitchManager() const;
+ std::shared_ptr<CompositeSwitchProvider> getCompositeSwitchProvider() const;
+
+ void setSwitchManager(const std::shared_ptr<SwitchManager> &sm);
+ void setCompositeSwitchProvider(const std::shared_ptr<CompositeSwitchProvider> &csp);
+
+private:
+ std::shared_ptr<SwitchManager> switchManager;
+ std::shared_ptr<CompositeSwitchProvider> compositeSwitchProvider;
+};
+
+#endif
-#ifndef UNIVERSAL_SWITCH_HPP
-#define UNIVERSAL_SWITCH_HPP
+#ifndef UNIVERSAL_SWITCH_LOG_HPP
+#define UNIVERSAL_SWITCH_LOG_HPP
#include <libintl.h>
#include <dlog.h>
--- /dev/null
+#include "UniversalSwitchLog.hpp"
+#include "Window.hpp"
+#include "ScreenScannerManager.hpp"
+#include "Atspi.hpp"
+
+#include "UniversalSwitch.hpp"
+#include "CompositeSwitchProvider.hpp"
+#include "AccessoriesSwitchProvider.hpp"
+#include "SQLiteConfiguration.hpp"
+#include "SwitchConfigurationItem.hpp"
+#include "ActivityFactory.hpp"
+#include "SwitchManager.hpp"
+
+#include <tizen.h>
+#include <app.h>
+#include <Elementary.h>
+
+static void _setting_time_lang_changed(app_event_info_h event_info, void *data)
+{
+ char *lang = NULL;
+ if (app_event_get_language(event_info, &lang) == APP_ERROR_NONE) {
+ DEBUG("Language is changed : %s", lang);
+ elm_language_set(lang);
+ elm_config_all_flush();
+ free(lang);
+ } else {
+ ERROR("Cannot get language from event_info");
+ }
+}
+
+bool app_create(void *data)
+{
+ DEBUG("App create");
+ ecore_event_init();
+ Atspi::ConnectAtClient();
+
+ auto activityFactory = ActivityFactory::getInstance();
+
+ auto compositeSwitchProvider = std::make_shared<CompositeSwitchProvider>();
+ compositeSwitchProvider->add(std::make_shared<AccessoriesSwitchProvider>());
+ //TODO: add ScreenSwitchProvider when available
+ //TDOO: add CameraSwitchProvider when available
+
+ //TODO: temporarily memory database is used (change to file database)
+ auto configuration = std::make_shared<SQLiteConfiguration>(true);
+
+ {
+ //TODO: remove after integration with settings app
+ std::string switchId = "AccessoriesSwitchProvider_x";
+ auto switch_ = compositeSwitchProvider->findSwitchById(switchId);
+ std::string activityType = "ACCEPT_SCANNING";
+ auto item = std::make_shared<SwitchConfigurationItem>(switch_->getId()->getGlobalId(), activityType);
+ DEBUG("getGlobalId %s", switch_->getId()->getGlobalId().c_str());
+ configuration->add(item);
+ }
+
+ UniversalSwitch::instance().setSwitchManager(SwitchManager::create<SwitchManager>(compositeSwitchProvider, configuration, activityFactory));
+ UniversalSwitch::instance().setCompositeSwitchProvider(compositeSwitchProvider);
+
+ //TODO: move to navigation context changed signal
+ ScreenScannerManager::instance().startAutoscanning();
+
+ return true;
+}
+
+void app_terminate(void *data)
+{
+ DEBUG("app termination procedure");
+ ecore_event_shutdown();
+ Atspi::DisconnectAtClient();
+ ScreenScannerManager::instance().stopAutoscanning();
+
+ return;
+}
+
+int main(int argc, char *argv[])
+{
+ DEBUG("main function called");
+
+ ui_app_lifecycle_callback_s event_callback = {
+ .create = app_create,
+ .terminate = app_terminate,
+ .pause = nullptr,
+ .resume = nullptr,
+ .app_control = nullptr
+ };
+
+ 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);
+}
+++ /dev/null
-#include "UniversalSwitchLog.hpp"
-#include "Window.hpp"
-#include "ScreenScannerManager.hpp"
-#include "Atspi.hpp"
-
-#include <tizen.h>
-#include <app.h>
-#include <Elementary.h>
-
-static void _setting_time_lang_changed(app_event_info_h event_info, void *data)
-{
- char *lang = NULL;
- if (app_event_get_language(event_info, &lang) == APP_ERROR_NONE) {
- DEBUG("Language is changed : %s", lang);
- elm_language_set(lang);
- elm_config_all_flush();
- free(lang);
- } else {
- ERROR("Cannot get language from event_info");
- }
-}
-
-bool app_create(void *data)
-{
- DEBUG("App create");
- Atspi::ConnectAtClient();
-
- return true;
-}
-
-void app_terminate(void *data)
-{
- DEBUG("app termination procedure");
- Atspi::DisconnectAtClient();
-
- return;
-}
-
-void app_control(app_control_h app_control, void *data)
-{
- return;
-}
-
-int main(int argc, char *argv[])
-{
- DEBUG("main function called");
-
- ui_app_lifecycle_callback_s event_callback = {
- .create = app_create,
- .terminate = app_terminate,
- .pause = nullptr,
- .resume = nullptr,
- .app_control = app_control
- };
-
- 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);
-}