X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fhs-clientmanager.cpp;h=8735c2ea935a0afe24325828303f4480193216fc;hb=211769e800f3a57de55b3774de82af55d2a0160a;hp=7d658e430922e447cbe09686065ccce3c35ec629;hpb=25299ef60fa4df5f590ff364cff004e90376a4bf;p=apps%2Fagl-service-homescreen.git diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp index 7d658e4..8735c2e 100644 --- a/src/hs-clientmanager.cpp +++ b/src/hs-clientmanager.cpp @@ -189,9 +189,45 @@ int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const c } else { HMI_NOTICE("homescreen-service","not exist session"); - ret = AFB_EVENT_BAD_REQUEST; + ret = AFB_REQ_NOT_STARTED_APPLICATION; } } } return ret; +} + +/** + * push event + * + * #### Parameters + * - event : the event want to push + * - param : the parameter contents of event + * - appid : the destination application's id + * + * #### Return + * 0 : success + * others : fail + * + */ +int HS_ClientManager::pushEvent(const char *event, struct json_object *param, std::string appid) +{ + if(event == nullptr) { + HMI_ERROR("homescreen-service","event name is null."); + return -1; + } + + std::lock_guard lock(this->mtx); + if(appid.empty()) { // broadcast event to clients who subscribed this event + for(auto m : client_list) { + m.second->pushEvent(event, param); + } + } + else { // push event to specific client + auto ip = client_list.find(appid); + if(ip != client_list.end()) { + ip->second->pushEvent(event, param); + } + } + + return 0; } \ No newline at end of file