- HMI_NOTICE("homescreen-service","Please input display_message");
- ret = AFB_EVENT_BAD_REQUEST;
- }
- return ret;
-}
-
-/**
- * on_screen_reply
- *
- * #### Parameters
- * - request: the request to bindings
- *
- * #### Return
- * result
- *
- */
-int HS_ClientManager::on_screen_reply(afb_req_t request)
-{
- int ret = 0;
- const char* value = afb_req_value(request, _reply_message);
- if (value) {
- HMI_NOTICE("homescreen-service","request params = %s.", value);
- std::lock_guard<std::mutex> lock(this->mtx);
- for(auto m : client_list) {
- m.second->on_screen_reply(request, value);
- }
- }
- else {
- HMI_NOTICE("homescreen-service","Please input reply_message");
- ret = AFB_EVENT_BAD_REQUEST;
- }
- return ret;
-}
-
-/**
- * subscribe
- *
- * #### Parameters
- * - request: the request to bindings
- *
- * #### Return
- * result
- *
- */
-int HS_ClientManager::subscribe(afb_req_t request)
-{
- int ret = 0;
- const char *value = afb_req_value(request, "event");
- HMI_NOTICE("homescreen-service","value is %s", value);
- if(value) {
- std::string appid(afb_req_get_application_id(request));
- std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
- std::lock_guard<std::mutex> lock(this->mtx);
-
- HS_Client* client = nullptr;
- auto ip = client_list.find(appid);
- if(ip != client_list.end()) {
- client = client_list[appid];
+ std::string id(appid);
+ auto ip = client_list.find(id);
+ if(ip != client_list.end()) {
+ // for showWindow verb we need to verify if the app is (still)
+ // running, and return the appropriate value to attempt to start it
+ // again. This 'problem' is avoided if the application itself
+ // subscribes and with that process, to install a callback that
+ // automatically removes the application from client_list.
+ // That is exactly how "subscribe" verb is handled below.
+ if (strcasecmp(verb, "showWindow") == 0) {
+ ret = is_application_running(id, client_list);
+ if (ret == AFB_REQ_NOT_STARTED_APPLICATION) {
+ AFB_INFO("%s is not running. Will attempt to start it", appid);
+ return ret;
+ }
+ }
+ AFB_INFO("%s found to be running. Forwarding request to the client", appid);
+ ret = ip->second->handleRequest(request, verb);