#include "hs-clientmanager.h"
#include "hmi-debug.h"
+static const char _homescreen[] = "homescreen";
+
HS_ClientManager* HS_ClientManager::me = nullptr;
static void cbRemoveClientCtxt(void *data)
int HS_ClientManager::tap_shortcut(afb_req_t request)
{
int ret = 0;
- const char* value = afb_req_value(request, _application_name);
+ const char* value = afb_req_value(request, _application_id);
if (value) {
HMI_NOTICE("homescreen-service","request params = %s.", value);
- // first step get appid from appname, next step change appname to appid
- std::string appid(value);
- std::transform(appid.begin(), appid.end(), appid.begin(), ::tolower);
std::lock_guard<std::mutex> lock(this->mtx);
- auto ip = client_list.find(appid);
+ auto ip = client_list.find(std::string(value));
if(ip != client_list.end()) {
ip->second->tap_shortcut(value);
}
}
else {
- HMI_NOTICE("homescreen-service","Please input application_name");
+ HMI_NOTICE("homescreen-service","Please input application_id");
ret = AFB_EVENT_BAD_REQUEST;
}
return ret;
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);
+ std::string appid =std::move(get_application_id(request));
+ if(appid.empty()) {
+ HMI_NOTICE("homescreen-service","can't get application identifier");
+ return AFB_REQ_GETAPPLICATIONID_ERROR;
+ }
+ std::lock_guard<std::mutex> lock(this->mtx);
HS_Client* client = nullptr;
auto ip = client_list.find(appid);
if(ip != client_list.end()) {
HMI_NOTICE("homescreen-service","value is %s", value);
int ret = 0;
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);
+ std::string appid = std::move(get_application_id(request));
+ if(appid.empty()) {
+ HMI_NOTICE("homescreen-service","can't get application identifier");
+ return AFB_REQ_GETAPPLICATIONID_ERROR;
+ }
+ std::lock_guard<std::mutex> lock(this->mtx);
auto ip = client_list.find(appid);
if(ip != client_list.end()
&& ip->second->unsubscribe(request, value) != 0) {
}
return ret;
}
+
+/**
+ * showWindow event
+ *
+ * #### Parameters
+ * - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::showWindow(afb_req_t request)
+{
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ HMI_NOTICE("homescreen-service","request params = %s.", value);
+ std::lock_guard<std::mutex> lock(this->mtx);
+ auto ip = client_list.find(std::string(value));
+ if(ip != client_list.end()) {
+ ret = ip->second->showWindow(request, value);
+ }
+ }
+ else {
+ HMI_NOTICE("homescreen-service","Please input application_id");
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
+ return ret;
+}
+
+/**
+ * hideWindow event
+ *
+ * #### Parameters
+ * - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::hideWindow(afb_req_t request)
+{
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ HMI_NOTICE("homescreen-service","request params = %s.", value);
+ std::lock_guard<std::mutex> lock(this->mtx);
+ auto ip = client_list.find(std::string(value));
+ if(ip != client_list.end()) {
+ ret = ip->second->hideWindow(request);
+ }
+ }
+ else {
+ HMI_NOTICE("homescreen-service","Please input application_id");
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
+ return ret;
+}
+
+/**
+ * replyShowWindow event
+ *
+ * #### Parameters
+ * - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::replyShowWindow(afb_req_t request)
+{
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_id);
+ if (value) {
+ HMI_NOTICE("homescreen-service","request params = %s.", value);
+ std::lock_guard<std::mutex> lock(this->mtx);
+ auto ip = client_list.find(std::string(value));
+ if(ip != client_list.end()) {
+ ret = ip->second->replyShowWindow(request, value);
+ }
+ }
+ else {
+ HMI_NOTICE("homescreen-service","Please input application_id");
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
+ return ret;
+}
+
+/**
+ * showNotification event
+ *
+ * #### Parameters
+ * - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::showNotification(afb_req_t request)
+{
+ int ret = 0;
+ std::lock_guard<std::mutex> lock(this->mtx);
+ auto ip = client_list.find(_homescreen);
+ if(ip != client_list.end()) {
+ ret = ip->second->showNotification(request);
+ }
+ else {
+ HMI_NOTICE("homescreen-service","not exist sessiion with homescreen");
+ ret = AFB_REQ_SHOWNOTIFICATION_ERROR;
+ }
+
+ return ret;
+}
+
+/**
+ * showInformation event
+ *
+ * #### Parameters
+ * - request : the request
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::showInformation(afb_req_t request)
+{
+ int ret = 0;
+ std::lock_guard<std::mutex> lock(this->mtx);
+ auto ip = client_list.find(_homescreen);
+ if(ip != client_list.end()) {
+ ret = ip->second->showInformation(request);
+ }
+ else {
+ HMI_NOTICE("homescreen-service","not exist sessiion with homescreen");
+ ret = AFB_REQ_SHOWINFORMATION_ERROR;
+ }
+
+ return ret;
+}