UniversalSwitchPageModel::UniversalSwitchPageModel()
{
- interactionServiceStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, false, [this](auto state) {
- this->interactionServiceState_ = state;
- });
-
- interactionServiceState_.attach([](auto val) {
- Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, val);
- });
-
- configurationServiceStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE, false, [this](auto state) {
- this->configurationServiceState_ = state;
- });
-
- configurationServiceState_.attach([this](auto val) {
- Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE, val);
- if (!val)
- this->dbusConfigurationServiceState_ = false;
- });
-
connectionPtr_ = DBus::getDBusConnectionByType(DBus::ConnectionType::SESSION);
- ownerNameCallbackHandle_ = DBus::registerNameOwnerChangedCallback(connectionPtr_, BUS, [this](std::string oldID, std::string newID) {
- dbusConfigurationServiceState_ = true;
- });
+ sentinel_ = Singleton<UniversalSwitchSentinelService>::instance().getSentinel();
}
bool UniversalSwitchPageModel::atLeastOneSwitchConfigured()
#include "DBus.hpp"
#include "ObservableProperty.hpp"
+#include "UniversalSwitchSentinel.hpp"
#include "VConf.hpp"
class UniversalSwitchPageModel
{
public:
UniversalSwitchPageModel();
- ObservableProperty<bool> interactionServiceState_;
- ObservableProperty<bool> configurationServiceState_;
- ObservableProperty<bool> dbusConfigurationServiceState_;
bool atLeastOneSwitchConfigured();
+ UniversalSwitchSentinel sentinel_;
private:
- VConfInterface::CallbackHandle interactionServiceStateHandle_;
- VConfInterface::CallbackHandle configurationServiceStateHandle_;
- DBus::OwnerNameCallbackHandle ownerNameCallbackHandle_;
DBus::DBusWrapper::ConnectionPtr connectionPtr_;
};
dBusClient_.addSignal<void()>(std::string{"switchesConfigurationChanged"}, [this]() {
this->getConfiguredSwitchesCount();
});
+ sentinel_ = Singleton<UniversalSwitchSentinelService>::instance().getSentinel();
getConfiguredSwitchesCount();
}
#include "DBus.hpp"
#include "Geometry.hpp"
#include "ObservableProperty.hpp"
+#include "UniversalSwitchSentinel.hpp"
#include "UniversalSwitchTypes.hpp"
#include "VConf.hpp"
UniversalSwitchSettingsPageModel();
ObservableProperty<int> configuredSwitchesCount_;
-
ObservableProperty<bool> autoTapKeyboardState_;
+ UniversalSwitchSentinel sentinel_;
private:
template <typename T>
groups_.emplace_back("");
auto &items = groups_.back().items_;
items.push_back(std::make_unique<ListItem>(
- model_.interactionServiceState_.value() ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF",
+ model_.sentinel_->interactionServiceState_.value() ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF",
std::string{},
[this](auto item) {
if (!item->widgetState_.value())
- model_.interactionServiceState_ = false;
+ model_.sentinel_->setInteractionServiceState(false);
else if (model_.atLeastOneSwitchConfigured())
- model_.interactionServiceState_ = true;
+ model_.sentinel_->setInteractionServiceState(true);
else {
item->widgetState_ = false;
DEBUG("No switch configured");
ListItem::WidgetType::toggle,
std::function<void(ListItem * item)>{},
std::function<void(ListItem * item)>{},
- model_.interactionServiceState_.value()));
- items.back()->enabled_ = model_.dbusConfigurationServiceState_.value();
+ model_.sentinel_->interactionServiceState_.value()));
+ items.back()->enabled_ = model_.sentinel_->configurationServiceState_.value();
items.push_back(std::make_unique<ListItem>(
std::string{},
addAction(std::make_unique<Action>("titleRightAction", "IDS_ACCS_SETTINGS_CAPS", [this](auto action) {
Singleton<AppContext>::instance().push(std::make_unique<UniversalSwitchSettingsPagePresenter>());
},
- model_.dbusConfigurationServiceState_.value()));
+ model_.sentinel_->configurationServiceState_.value()));
- model_.dbusConfigurationServiceState_.attach([this, &items](auto value) {
+ model_.sentinel_->configurationServiceState_.attach([this, &items](auto value) {
+ ERROR("value: %d", value);
this->getAction("titleRightAction")->enabled_ = value;
items.front()->enabled_ = value;
});
- model_.configurationServiceState_ = true;
+ model_.sentinel_->setConfigurationServiceState(true);
- model_.interactionServiceState_.attach([this, &items](auto value) {
+ model_.sentinel_->interactionServiceState_.attach([this, &items](auto value) {
items.front()->title_ = value ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF";
items.front()->widgetState_ = value;
});
}
-
-UniversalSwitchPagePresenter::~UniversalSwitchPagePresenter()
-{
- model_.configurationServiceState_ = false;
-}
\ No newline at end of file
{
public:
UniversalSwitchPagePresenter();
- ~UniversalSwitchPagePresenter();
private:
UniversalSwitchPageModel model_;
--- /dev/null
+#include "UniversalSwitchSentinel.hpp"
+
+#include "UniversalSwitchConstants.hpp"
+
+UniversalSwitchState::UniversalSwitchState()
+{
+ interactionServiceStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, false, [this](auto state) {
+ this->vconfInteractionState_ = state;
+ this->syncInteractionServiceState();
+ });
+
+ configurationServiceStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE, false, [this](auto state) {
+ this->vconfConfigurationState_ = state;
+ this->syncConfigurationServiceState();
+ });
+
+ connectionPtr_ = DBus::getDBusConnectionByType(DBus::ConnectionType::SESSION);
+ ownerNameCallbackHandle_ = DBus::registerNameOwnerChangedCallback(connectionPtr_, BUS, [this](std::string oldID, std::string newID) {
+ dbusConfigurationServiceState_ = true;
+ syncInteractionServiceState();
+ syncConfigurationServiceState();
+ });
+}
+
+UniversalSwitchState::~UniversalSwitchState()
+{
+ Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE, false);
+}
+
+void UniversalSwitchState::syncInteractionServiceState()
+{
+ auto v = vconfInteractionState_ && dbusConfigurationServiceState_;
+ if (this->interactionServiceState_.value_ != v) {
+ this->interactionServiceState_.value_ = v;
+ this->interactionServiceState_.notify(v);
+ }
+}
+
+void UniversalSwitchState::syncConfigurationServiceState()
+{
+ auto v = vconfConfigurationState_ && dbusConfigurationServiceState_;
+ if (this->configurationServiceState_.value_ != v) {
+ this->configurationServiceState_.value_ = v;
+ this->configurationServiceState_.notify(v);
+ }
+}
+
+void UniversalSwitchState::setInteractionServiceState(bool state)
+{
+ Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, state);
+}
+
+void UniversalSwitchState::setConfigurationServiceState(bool state)
+{
+ Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE, state);
+}
+
+UniversalSwitchSentinel UniversalSwitchSentinelService::getSentinel()
+{
+ if (auto s = sentinel_.lock()) {
+ return s;
+ } else {
+ auto x = std::make_shared<UniversalSwitchState>();
+ sentinel_ = x;
+ return x;
+ }
+}
\ No newline at end of file
--- /dev/null
+#ifndef UNIVERSAL_SWITCH_SENTINEL_HPP
+#define UNIVERSAL_SWITCH_SENTINEL_HPP
+
+#include "DBus.hpp"
+#include "ObservableProperty.hpp"
+#include "VConf.hpp"
+
+#include <memory>
+
+class UniversalSwitchState
+{
+ public:
+ class ReadOnlyProperty : public Observable<bool>
+ {
+ friend class UniversalSwitchState;
+
+ public:
+ ReadOnlyProperty() = default;
+ ReadOnlyProperty(bool val)
+ : value_(val)
+ {}
+
+ bool value() const
+ {
+ return value_;
+ }
+
+ private:
+ bool value_ = false;
+ };
+
+ UniversalSwitchState();
+ ~UniversalSwitchState();
+ ReadOnlyProperty interactionServiceState_;
+ ReadOnlyProperty configurationServiceState_;
+
+ void setInteractionServiceState(bool state);
+ void setConfigurationServiceState(bool state);
+
+ private:
+ void syncInteractionServiceState();
+ void syncConfigurationServiceState();
+
+ VConfInterface::CallbackHandle interactionServiceStateHandle_;
+ VConfInterface::CallbackHandle configurationServiceStateHandle_;
+ DBus::OwnerNameCallbackHandle ownerNameCallbackHandle_;
+ DBus::DBusWrapper::ConnectionPtr connectionPtr_;
+ bool dbusConfigurationServiceState_ = false;
+ bool vconfConfigurationState_ = false;
+ bool vconfInteractionState_ = false;
+};
+
+using UniversalSwitchSentinel = std::shared_ptr<UniversalSwitchState>;
+
+class UniversalSwitchSentinelService
+{
+ public:
+ UniversalSwitchSentinel getSentinel();
+
+ private:
+ std::weak_ptr<UniversalSwitchState> sentinel_;
+};
+
+#endif
\ No newline at end of file