aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-01-16 10:29:02 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-01-16 10:29:02 +0800
commit676baef9a7b9ad2868b8e10a7f4d10e54f4b36f1 (patch)
tree52fbdb9660c54d16a603bb3d4079f73ff59cf8d6
parentd6140dad95f7884f8a7a666a125c1b24065d2c60 (diff)
Change-Id: I03dd59e12f50d4092ef9f9cb3995c8927c16650d
-rw-r--r--src/hs-periphery.cpp28
-rw-r--r--src/hs-periphery.h32
2 files changed, 17 insertions, 43 deletions
diff --git a/src/hs-periphery.cpp b/src/hs-periphery.cpp
index 06e95ea..783b01a 100644
--- a/src/hs-periphery.cpp
+++ b/src/hs-periphery.cpp
@@ -19,8 +19,6 @@
#include "hmi-debug.h"
#include "hs-clientmanager.h"
-static const char _restriction_on[] = "RestrictionOn";
-static const char _restriction_off[] = "RestrictionOff";
/* -------------------------------------HS_PeripheryManager------------------------------------------ */
@@ -44,7 +42,7 @@ int HS_PeripheryManager::init(afb_api_t api)
HMI_ERROR("homescreen-service","restriction init failed.");
}
else {
- periphery_list[std::string("restriction")] = restriction;
+ periphery_list[restriction->getAppid()] = restriction;
}
return ret;
}
@@ -118,26 +116,10 @@ int HS_Restriction::init(afb_api_t api)
*/
void HS_Restriction::onEvent(afb_api_t api, const char *event, struct json_object *object)
{
- if(!isConcernedEvent(event))
- return;
-
- std::string ev = event;
- std::size_t pos = ev.find("/");
- if(pos != std::string::npos) {
- ev = ev.substr(pos + 1);
- }
- else {
- HMI_ERROR("homescreen-service","received event is error.");
- return;
- }
-
- if(ev == _restriction_on) {
- restrictionOn(api, object);
- }
- else if(ev == _restriction_off) {
- restrictionOff(api, object);
- }
- else {
+ auto ip = concerned_event_list.find(std::string(event));
+ if(ip != concerned_event_list.end()) {
+ HMI_NOTICE("homescreen-service","[%s] event received.", event);
+ (this->*(ip->second))(api, object);
}
}
diff --git a/src/hs-periphery.h b/src/hs-periphery.h
index d2da39e..3ed98eb 100644
--- a/src/hs-periphery.h
+++ b/src/hs-periphery.h
@@ -20,33 +20,33 @@
#include <unordered_map>
#include "hs-helper.h"
-class HS_Periphery {
-public:
+struct HS_Periphery {
virtual int init(afb_api_t api) = 0;
virtual void onEvent(afb_api_t api, const char *event, struct json_object *object) = 0;
+ std::string getAppid() {return my_appid;}
+
+ std::string my_appid;
};
class HS_Restriction : public HS_Periphery {
public:
- HS_Restriction() = default;
+ HS_Restriction() {my_appid = "restriction";}
~HS_Restriction() = default;
+ HS_Restriction(HS_Restriction const &) = delete;
+ HS_Restriction &operator=(HS_Restriction const &) = delete;
int init(afb_api_t api);
void onEvent(afb_api_t api, const char *event, struct json_object *object);
private:
- const std::unordered_set<const char*> concerned_event_list {
- "windowmanager/RestrictionOn",
- "windowmanager/RestrictionOff"
+ typedef void (HS_Restriction::*func_handler)(afb_api_t, struct json_object*);
+ const std::unordered_map<std::string, func_handler> concerned_event_list {
+ {"windowmanager/RestrictionOn", &HS_Restriction::restrictionOn},
+ {"windowmanager/RestrictionOff", &HS_Restriction::restrictionOff}
};
- inline bool isConcernedEvent(const char* event) const {
- return (concerned_event_list.find(event) != concerned_event_list.end()) ? true : false;
- }
void restrictionOn(afb_api_t api, struct json_object *object);
void restrictionOff(afb_api_t api, struct json_object *object);
-
- std::string m_appid = "restriction";
};
class HS_PeripheryManager {
@@ -59,20 +59,12 @@ public:
void onEvent(afb_api_t api, const char *event, struct json_object *object);
inline bool isPeripheryApp(const char* name) const {
- return (periphery_app_list.find(name) != periphery_app_list.end()) ? true : false;
+ return (periphery_list.find(name) != periphery_list.end()) ? true : false;
}
private:
- const std::unordered_set<const char*> periphery_app_list {
- "launcher",
- "homescreen",
- "onscreenapp",
- "restriction"
- };
-
static HS_PeripheryManager* me;
std::unordered_map<std::string, HS_Periphery*> periphery_list;
- // HS_Restriction m_restriction;
};
#endif // HOMESCREEN_PERIPHERY_H \ No newline at end of file