return nullptr;
}
-void AccessoriesSwitchProvider::processKeyDownEvent(const std::string &keyId)
+Eina_Bool AccessoriesSwitchProvider::processKeyDownEvent(const std::string &keyId)
{
if (currentKeyId == keyId)
- return;
+ return ECORE_CALLBACK_DONE;
- currentKeyId = keyId;
- auto switchId = SwitchId(currentKeyId, getId());
+ DEBUG("key pressed: %s", keyId.c_str());
+
+ auto switchId = SwitchId(keyId, getId());
auto sw = findSwitchById(switchId.getGlobalId());
+ if (!sw) {
+ auto id = SwitchId(prevKeyId, getId());
+ interactionManager.stopInteraction(findSwitchById(id.getGlobalId()));
+ return ECORE_CALLBACK_PASS_ON;
+ }
+
+ currentKeyId = keyId;
+ prevKeyId = keyId;
+
interactionManager.startInteraction([ = ]() {
this->notify(sw);
}, sw);
+
+ return ECORE_CALLBACK_DONE;
}
-void AccessoriesSwitchProvider::processKeyUpEvent(const std::string &keyId)
+Eina_Bool AccessoriesSwitchProvider::processKeyUpEvent(const std::string &keyId)
{
- if (currentKeyId == keyId) {
- auto switchId = SwitchId(currentKeyId, getId());
- interactionManager.stopInteraction(findSwitchById(switchId.getGlobalId()));
- currentKeyId.clear();
- }
+ if (keys.find(keyId) == keys.end())
+ return ECORE_CALLBACK_PASS_ON;
+
+ if (currentKeyId != keyId)
+ return ECORE_CALLBACK_DONE;
+
+ DEBUG("key released: %s", keyId.c_str());
+
+ auto switchId = SwitchId(currentKeyId, getId());
+ auto sw = findSwitchById(switchId.getGlobalId());
+ currentKeyId.clear();
+ if (!sw)
+ return ECORE_CALLBACK_DONE;
+
+ interactionManager.stopInteraction(sw);
+
+ return ECORE_CALLBACK_DONE;
}
Eina_Bool AccessoriesSwitchProvider::keyDownCb(void *data, int type, void *ev)
std::string keyId(event->key);
auto asp = static_cast<AccessoriesSwitchProvider *>(data);
- asp->processKeyDownEvent(keyId);
- return ECORE_CALLBACK_DONE;
+ return asp->processKeyDownEvent(keyId);
}
Eina_Bool AccessoriesSwitchProvider::keyUpCb(void *data, int type, void *ev)
std::string keyId(event->key);
auto asp = static_cast<AccessoriesSwitchProvider *>(data);
- asp->processKeyUpEvent(keyId);
- return ECORE_CALLBACK_DONE;
+ return asp->processKeyUpEvent(keyId);
}
#include <Elementary.h>
#include <Ecore.h>
-#include <vector>
+#include <set>
#include <string>
#include <memory>
std::shared_ptr<Switch> findSwitchById(const std::string &switchId) const override;
private:
- void processKeyDownEvent(const std::string &keyId);
- void processKeyUpEvent(const std::string &keyId);
+ Eina_Bool processKeyDownEvent(const std::string &keyId);
+ Eina_Bool processKeyUpEvent(const std::string &keyId);
static Eina_Bool keyDownCb(void *data, int type, void *ev);
static Eina_Bool keyUpCb(void *data, int type, void *ev);
- const std::vector<std::string> keys;
+ const std::set<std::string> keys;
SwitchCollection switches;
Ecore_Event_Handler *keyDownHandler;
Ecore_Event_Handler *keyUpHandler;
std::string currentKeyId;
+ std::string prevKeyId;
};
#endif
#include "QueryBuilder.hpp"
+enum SwitchConfigurationItemFields {
+ SWITCH_ID,
+ USER_NAME,
+ ACTIVITY_TYPE,
+ Count
+};
+
SQLiteConfiguration::SQLiteConfiguration(bool createInMemory)
: password("UniversalSwitchPassword"), dbName(createInMemory ? ":memory:" : "UniversalSwitch.db"), tableName("`UNIVERSAL_SWITCH`"),
switchIdCol("`SWITCH_ID`"), userNameCol("`USER_NAME`"),
auto query = QueryBuilder().select({"*"}).from(tableName).where(switchIdCol, "=", switchId).build();
INFO("query: %s", query.c_str());
- auto item = std::make_shared<SwitchConfigurationItem>();
+ std::shared_ptr<SwitchConfigurationItem> item;
- if (!executeQuery(query, [ = ](int argc, char **argv, char **azColName) {
- item->construct(argc, argv, azColName);
+ if (!executeQuery(query, [&item](int argc, char **argv, char **azColName) {
+ item = constructItem(argc, argv, azColName);
}))
return nullptr;
auto collection = std::vector<std::shared_ptr<SwitchConfigurationItem>>();
- if (!executeQuery(query, [&](int argc, char **argv, char **azColName) {
- auto item = std::make_shared<SwitchConfigurationItem>();
- item->construct(argc, argv, azColName);
- collection.emplace_back(item);
+ if (!executeQuery(query, [&collection](int argc, char **argv, char **azColName) {
+ collection.emplace_back(constructItem(argc, argv, azColName));
}))
return {};
executeQuery(query);
}
+std::shared_ptr<SwitchConfigurationItem> SQLiteConfiguration::constructItem(int argc, char **argv, char **azColName)
+{
+ ASSERT(argc == SwitchConfigurationItemFields::Count, "Fields number does not match the one in SwitchConfigurationItem");
+
+ auto item = std::make_shared<SwitchConfigurationItem>();
+
+ item->setSwitchId(argv[SwitchConfigurationItemFields::SWITCH_ID]);
+ item->setUserName(argv[SwitchConfigurationItemFields::USER_NAME]);
+ item->setActivityType(argv[SwitchConfigurationItemFields::ACTIVITY_TYPE]);
+
+ INFO("switchId: %s, userName: %s, activityType: %s", item->getSwitchId().c_str(), item->getUserName().c_str(), item->getActivityType().c_str());
+
+ return item;
+}
+
void SQLiteConfiguration::clearTable()
{
auto query = "DELETE FROM " + tableName ;
bool executeQuery(const std::string &query, const execCallback_t &cb) const;
bool executeQuery(const std::string &query) const;
void createTable();
+ static std::shared_ptr<SwitchConfigurationItem> constructItem(int argc, char **argv, char **azColName);
static void update_callback(void *data, int operation, char const *database, char const *table, sqlite_int64 rowid);
protected:
void notify(std::shared_ptr<T> item)
{
+ ASSERT(item, "Notification of NULL item requested");
for (auto &it : observers) {
auto observer = it.first.lock();
if (observer && it.second->matching(item.get()))
#include <dlog.h>
-SwitchConfigurationItem::SwitchConfigurationItem(ChangeType type)
- : changeType(type)
-{}
-
SwitchConfigurationItem::SwitchConfigurationItem(const std::string &switchId, const std::string &activityType)
: switchId(switchId), activityType(activityType)
{}
-SwitchConfigurationItem::SwitchConfigurationItem(const std::string &switchId, const std::string &activityType, ChangeType type)
- : switchId(switchId), activityType(activityType), changeType(type)
-{}
-
bool SwitchConfigurationItem::operator==(const SwitchConfigurationItem &item) const
{
return switchId == item.getSwitchId() && activityType == item.getActivityType() && changeType == item.getChangeType();
{
changeType = type;
}
-
-void SwitchConfigurationItem::construct(int argc, char **argv, char **azColName)
-{
- INFO("Function invokation");
-
- if (argc != static_cast<int>(SwitchConfigurationItemFields::Count)) {
- ERROR("Fields number does not match the one in SwitchConfigurationItem");
- return;
- }
-
- setSwitchId(argv[static_cast<int>(SwitchConfigurationItemFields::SWITCH_ID)]);
- setUserName(argv[static_cast<int>(SwitchConfigurationItemFields::USER_NAME)]);
- setActivityType(argv[static_cast<int>(SwitchConfigurationItemFields::ACTIVITY_TYPE)]);
-
- INFO("switchId: %s, userName: %s, activityType: %s", switchId.c_str(), userName.c_str(), activityType.c_str());
-}
NONE
};
-enum class SwitchConfigurationItemFields {
- SWITCH_ID,
- USER_NAME,
- ACTIVITY_TYPE,
- Count
-};
-
class SwitchConfigurationItem
{
public:
SwitchConfigurationItem() = default;
- SwitchConfigurationItem(ChangeType type);
SwitchConfigurationItem(const std::string &switchId, const std::string &activityType);
- SwitchConfigurationItem(const std::string &switchId, const std::string &activityType, ChangeType type);
bool operator==(const SwitchConfigurationItem &item) const;
ChangeType getChangeType() const;
void setChangeType(ChangeType type);
- void construct(int argc, char **argv, char **azColName);
-
private:
std::string switchId;
std::string userName;
deleteAndClearTimer(minimalSwitchInteractionTimer);
deleteAndClearTimer(notificationRepetitionIntervalTimer);
- notifyMethod = method;
- currentSwitch = sw;
- if (!currentSwitch) {
+ if (!sw) {
ERROR("Switch has not been created by provider");
return;
}
+ currentSwitch = sw;
+ notifyMethod = method;
+
DEBUG("switch: %s", sw->getId()->getGlobalId().c_str());
minimalSwitchInteractionTimer = ecore_timer_add(minimalSwitchInteractionTime, minimalSwitchInteractionTimeCb, this);
}
void SwitchInteractionManager::stopInteraction(const std::shared_ptr<Switch> &sw)
{
- if (currentSwitch->getId()->getGlobalId() != sw->getId()->getGlobalId())
+ bool isActiveInteraction = minimalSwitchInteractionTimer || notificationRepetitionIntervalTimer;
+ if (!isActiveInteraction)
return;
- bool isActiveInteraction = minimalSwitchInteractionTimer || notificationRepetitionIntervalTimer;
+ if (!currentSwitch || !sw || currentSwitch->getId()->getGlobalId() != sw->getId()->getGlobalId())
+ return;
deleteAndClearTimer(minimalSwitchInteractionTimer);
deleteAndClearTimer(notificationRepetitionIntervalTimer);
- if (isActiveInteraction && !switchInteractionIntervalTimer) {
+ if (!switchInteractionIntervalTimer) {
DEBUG("interval timer set");
switchInteractionIntervalTimer = ecore_timer_add(switchInteractionInterval, switchInteractionIntervalCb, this);
}
}
SwitchInteractionManager::SwitchInteractionManager()
+ : minimalSwitchInteractionTime(0.0), switchInteractionInterval(0.0), notificationRepetitionInterval(0.0),
+ minimalSwitchInteractionTimer(nullptr), switchInteractionIntervalTimer(nullptr), notificationRepetitionIntervalTimer(nullptr)
{
minimalSwitchInteractionTimeHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "TAP_DURATION_VALUE", 1.0, [this](int x) {
minimalSwitchInteractionTime = x;
Eina_Bool SwitchInteractionManager::minimalSwitchInteractionTimeCb(void *data)
{
- DEBUG("invoked");
-
auto im = static_cast<SwitchInteractionManager *>(data);
-
- im->minimalSwitchInteractionTimer = nullptr;
- im->notifyMethod();
-
- if (im->notificationRepetitionInterval != 0.0)
- im->notificationRepetitionIntervalTimer = ecore_timer_add(im->notificationRepetitionInterval, notificationRepetitionIntervalCb, im);
- else
- ecore_timer_add(im->switchInteractionInterval, switchInteractionIntervalCb, im);
+ im->afterMinimalInteractionTime();
return ECORE_CALLBACK_CANCEL;
}
Eina_Bool SwitchInteractionManager::switchInteractionIntervalCb(void *data)
{
- DEBUG("invoked");
auto im = static_cast<SwitchInteractionManager *>(data);
- im->switchInteractionIntervalTimer = nullptr;
+ im->afterInteractionInterval();
return ECORE_CALLBACK_CANCEL;
}
Eina_Bool SwitchInteractionManager::notificationRepetitionIntervalCb(void *data)
{
- DEBUG("invoked");
auto im = static_cast<SwitchInteractionManager *>(data);
- im->notifyMethod();
+ im->afterRepetitionInterval();
return ECORE_CALLBACK_RENEW;
}
+
+void SwitchInteractionManager::afterMinimalInteractionTime()
+{
+ DEBUG("invoked: %s", currentSwitch->getId()->getGlobalId().c_str());
+
+ minimalSwitchInteractionTimer = nullptr;
+ notifyMethod();
+
+ if (notificationRepetitionInterval != 0.0)
+ notificationRepetitionIntervalTimer = ecore_timer_add(notificationRepetitionInterval, notificationRepetitionIntervalCb, this);
+ else
+ ecore_timer_add(switchInteractionInterval, switchInteractionIntervalCb, this);
+}
+
+void SwitchInteractionManager::afterInteractionInterval()
+{
+ DEBUG("invoked");
+ switchInteractionIntervalTimer = nullptr;
+}
+
+void SwitchInteractionManager::afterRepetitionInterval()
+{
+ DEBUG("invoked: %s", currentSwitch->getId()->getGlobalId().c_str());
+ notifyMethod();
+}
static Eina_Bool switchInteractionIntervalCb(void *data);
static Eina_Bool notificationRepetitionIntervalCb(void *data);
+ void afterMinimalInteractionTime();
+ void afterInteractionInterval();
+ void afterRepetitionInterval();
+
std::shared_ptr<Switch> currentSwitch;
double minimalSwitchInteractionTime;
double switchInteractionInterval;