aboutsummaryrefslogtreecommitdiffstats
path: root/src/hs-clientmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hs-clientmanager.cpp')
-rw-r--r--src/hs-clientmanager.cpp89
1 files changed, 13 insertions, 76 deletions
diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp
index d84d07b..913e9b6 100644
--- a/src/hs-clientmanager.cpp
+++ b/src/hs-clientmanager.cpp
@@ -20,7 +20,8 @@
#include "hs-apprecover.h"
static const char _homescreen[] = "homescreen";
-const std::string _listen_all("all");
+static const char _area[] = "area";
+static const char _parameter[] = "parameter";
HS_ClientManager* HS_ClientManager::me = nullptr;
@@ -74,8 +75,6 @@ HS_ClientManager* HS_ClientManager::instance(void)
int HS_ClientManager::init(void)
{
listener_list.clear();
- std::list<listener_interface*> interface_list;
- listener_list[_listen_all] = std::move(interface_list);
}
/**
@@ -245,37 +244,6 @@ int HS_ClientManager::pushEvent(const char *event, struct json_object *param, st
}
/**
- * check register application
- *
- * #### Parameters
- * - api : the api
- * - appid : register application's id
- *
- * #### Return
- * true : checked
- * false : not checked
- *
- */
-bool HS_ClientManager::checkRegisterApp(afb_api_t api, const std::string &appid)
-{
- bool ret = true;
- auto &ip = listener_list[_listen_all];
- if(!ip.empty()) {
- for(auto &it : ip) {
- it->notify(api, appid);
- }
- }
- else if(startup_appid == appid) {
- startup_appid.clear();
- pushEvent("showWindow", nullptr, appid);
- }
- else {
- ret = false;
- }
- return ret;
-}
-
-/**
* check whether application was started
*
* #### Parameters
@@ -304,17 +272,7 @@ bool HS_ClientManager::isAppStarted(const std::string &appid)
*/
void HS_ClientManager::addListener(listener_interface* listener)
{
- for (auto &it : listener->listenAppSet()) {
- auto ip = listener_list.find(it);
- if(ip != listener_list.end()) {
- ip->second.push_back(listener);
- }
- else {
- std::list<listener_interface*> lst;
- lst.push_back(listener);
- listener_list[it] = std::move(lst);
- }
- }
+ listener_list[listener->myUid()] = listener;
}
/**
@@ -329,21 +287,7 @@ void HS_ClientManager::addListener(listener_interface* listener)
*/
void HS_ClientManager::removeListener(listener_interface* listener)
{
- for (auto &iter : listener->listenAppSet()) {
- auto it = listener_list.find(iter);
- if(it != listener_list.end()) {
- auto ip = it->second.begin();
- for(; ip != it->second.end(); ++ip) {
- if(listener->myUid() == (*ip)->myUid()) {
- break;
- }
- }
- it->second.erase(ip);
- if(it->second.empty()) {
- listener_list.erase(it->first);
- }
- }
- }
+ listener_list.erase(listener->myUid());
}
/**
@@ -359,25 +303,18 @@ void HS_ClientManager::removeListener(listener_interface* listener)
*/
void HS_ClientManager::notifyListener(afb_api_t api, const std::string &appid)
{
- if (checkRegisterApp(api, appid)) {
- return;
- }
-
AFB_INFO("listen %s, notified", appid.c_str());
- std::list<listener_interface*> interface_list;
- auto ip = listener_list.find(appid);
- if(ip != listener_list.end()) {
- if(!ip->second.empty()) {
- interface_list = ip->second;
- }
- else {
- AFB_WARNING("listener is null.");
- return;
+ for(auto &it : listener_list) {
+ if(it.second->isListenAppId(appid)) {
+ it.second->notify(api, appid);
}
}
- for(auto &it : interface_list) {
- it->notify(api, appid);
+ if(startup_appid == appid) {
+ struct json_object* json_param = json_object_new_object();
+ json_object_object_add(json_param, _area, json_object_new_string(startup_area.c_str()));
+ startup_area.clear();
+ startup_appid.clear();
+ pushEvent("showWindow", json_param, appid);
}
-
} \ No newline at end of file