aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/homescreen.cpp111
-rw-r--r--src/hs-client.cpp9
-rw-r--r--src/hs-clientmanager.cpp233
-rw-r--r--src/hs-clientmanager.h10
-rw-r--r--src/hs-helper.h3
5 files changed, 206 insertions, 160 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index fdc9e85..b518139 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -23,7 +23,6 @@
#include "hmi-debug.h"
#include "hs-clientmanager.h"
-#define EVENT_SUBSCRIBE_ERROR_CODE 100
const char _error[] = "error";
const char _application_name[] = "application_name";
@@ -59,30 +58,13 @@ static void pingSample(afb_req_t request)
static void tap_shortcut (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
-
- int ret = 0;
- const char* value = afb_req_value(request, _application_name);
- 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);
- HS_Client* client = g_client_manager->find(appid);
- if(client != nullptr) {
- if(client->tap_shortcut(value) != 0) {
- afb_req_fail_f(request, "afb_event_push failed", "called %s.", __FUNCTION__);
- return;
- }
- }
- else {
- // app is not started, do nothing
- }
- } else {
- afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
+ int ret = g_client_manager->tap_shortcut(request);
+ if (ret != 0) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
}
- // response to HomeScreen
+ // response to HomeScreen
struct json_object *res = json_object_new_object();
hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
_error, ret);
@@ -104,19 +86,9 @@ static void on_screen_message (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = 0;
- const char* value = afb_req_value(request, _display_message);
- if (value) {
-
- HMI_NOTICE("homescreen-service","request params = %s.", value);
- for(auto m : g_client_manager->getAllClient()) {
- if(m->on_screen_message(request, value) != 0) {
- afb_req_fail_f(request, "afb_event_push failed", "called %s.", __FUNCTION__);
- return;
- }
- }
- } else {
- afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
+ int ret = g_client_manager->on_screen_message(request);
+ if (ret != 0) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
}
@@ -142,19 +114,9 @@ static void on_screen_reply (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = 0;
- const char* value = afb_req_value(request, _reply_message);
- if (value) {
-
- HMI_NOTICE("homescreen-service","request params = %s.", value);
- for(auto m : g_client_manager->getAllClient()) {
- if(m->on_screen_reply(request, value) != 0) {
- afb_req_fail_f(request, "afb_event_push failed", "called %s.", __FUNCTION__);
- return;
- }
- }
- } else {
- afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
+ int ret = g_client_manager->on_screen_reply(request);
+ if (ret != 0) {
+ afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
}
@@ -177,26 +139,19 @@ static void on_screen_reply (afb_req_t request)
*/
static void subscribe(afb_req_t request)
{
- const char *value = afb_req_value(request, "event");
- 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);
- if(g_client_manager->getClient(request, appid)->subscribe(request, value) != 0) {
- afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
- return;
- }
- }
- else {
- HMI_NOTICE("homescreen-service","Please input event name");
- ret = EVENT_SUBSCRIBE_ERROR_CODE;
+ HMI_NOTICE("homescreen-service","called.");
+
+ int ret = g_client_manager->subscribe(request);
+ if(ret) {
+ afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
+ return;
}
+
/*create response json object*/
struct json_object *res = json_object_new_object();
hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
_error, ret);
- afb_req_success_f(request, res, "homescreen binder subscribe event name [%s]", value);
+ afb_req_success_f(request, res, "homescreen binder subscribe.");
}
/**
@@ -211,33 +166,19 @@ static void subscribe(afb_req_t request)
*/
static void unsubscribe(afb_req_t request)
{
- const char *value = afb_req_value(request, "event");
- 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);
- HS_Client* client = g_client_manager->find(appid);
- if(client != nullptr) {
- if(client->unsubscribe(request, value) != 0) {
- afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
- return;
- }
- }
- else {
- HMI_NOTICE("homescreen-service","not find app's client, unsubscribe failed");
- ret = EVENT_SUBSCRIBE_ERROR_CODE;
- }
- }
- else{
- HMI_NOTICE("homescreen-service","Please input event name");
- ret = EVENT_SUBSCRIBE_ERROR_CODE;
+ HMI_NOTICE("homescreen-service","called.");
+
+ int ret = g_client_manager->unsubscribe(request);
+ if(ret) {
+ afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
+ return;
}
+
/*create response json object*/
struct json_object *res = json_object_new_object();
hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
_error, ret);
- afb_req_success_f(request, res, "homescreen binder unsubscribe event name [%s]", value);
+ afb_req_success_f(request, res, "homescreen binder unsubscribe success.");
}
/*
diff --git a/src/hs-client.cpp b/src/hs-client.cpp
index 9fc9b61..c683c66 100644
--- a/src/hs-client.cpp
+++ b/src/hs-client.cpp
@@ -71,7 +71,8 @@ int HS_Client::tap_shortcut(const char* appname)
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 4, _application_name, appname,
_type, __FUNCTION__);
- return afb_event_push(my_event, push_obj);
+ afb_event_push(my_event, push_obj);
+ return 0;
}
/**
@@ -93,7 +94,8 @@ int HS_Client::on_screen_message(afb_req_t request, const char* message)
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 4, _display_message, message,
_type, __FUNCTION__);
- return afb_event_push(my_event, push_obj);
+ afb_event_push(my_event, push_obj);
+ return 0;
}
/**
@@ -115,7 +117,8 @@ int HS_Client::on_screen_reply(afb_req_t request, const char* message)
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 4, _reply_message, message,
_type, __FUNCTION__);
- return afb_event_push(my_event, push_obj);
+ afb_event_push(my_event, push_obj);
+ return 0;
}
/**
diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp
index a79e9bb..aae8c42 100644
--- a/src/hs-clientmanager.cpp
+++ b/src/hs-clientmanager.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#include <algorithm>
#include "hs-clientmanager.h"
#include "hmi-debug.h"
@@ -69,73 +69,6 @@ HS_ClientManager* HS_ClientManager::instance(void)
int HS_ClientManager::init(void)
{
HMI_NOTICE("homescreen-service","called.");
- // TODO : connect to windowmanger
- // get applist from appfw
-}
-
-/**
- * find HS_Client in client_list
- *
- * #### Parameters
- * - appid: app's id
- *
- * #### Return
- * found HS_Client pointer
- *
- */
-HS_Client* HS_ClientManager::find(std::string appid)
-{
- std::lock_guard<std::mutex> lock(this->mtx);
- HS_Client* p = nullptr;
- auto ip = client_list.find(appid);
- if(ip != client_list.end()) {
- p = client_list[appid];
- }
- return p;
-}
-
-/**
- * get HS_Client
- *
- * #### Parameters
- * - appid: app's id
- *
- * #### Return
- * found HS_Client pointer
- *
- */
-HS_Client* HS_ClientManager::getClient(afb_req_t req, std::string appid)
-{
- std::lock_guard<std::mutex> lock(this->mtx);
- HS_Client* p = nullptr;
- auto ip = client_list.find(appid);
- if(ip != client_list.end()) {
- p = client_list[appid];
- }
- else {
- appid2ctxt[appid] = createClientCtxt(req, appid);
- p = addClient(req, appid);
- }
- return p;
-}
-
-/**
- * get HS_Client pointers set
- *
- * #### Parameters
- * - Nothing
- *
- * #### Return
- * HS_Client pointers set
- *
- */
-std::vector<HS_Client*> HS_ClientManager::getAllClient(void)
-{
- std::lock_guard<std::mutex> lock(this->mtx);
- std::vector<HS_Client*> v;
- for(auto a : client_list)
- v.push_back(a.second);
- return v;
}
/**
@@ -217,3 +150,167 @@ void HS_ClientManager::removeClientCtxt(void *data)
delete appid2ctxt[ctxt->id];
appid2ctxt.erase(ctxt->id);
}
+
+/**
+ * tap_shortcut
+ *
+ * #### Parameters
+ * - request: the request to bindings
+ *
+ * #### Return
+ * result
+ *
+ */
+int HS_ClientManager::tap_shortcut(afb_req_t request)
+{
+ int ret = 0;
+ const char* value = afb_req_value(request, _application_name);
+ 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);
+ if(ip != client_list.end()) {
+ ip->second->tap_shortcut(value);
+ }
+ }
+ else {
+ HMI_NOTICE("homescreen-service","Please input application_name");
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
+ return ret;
+}
+
+/**
+ * on_screen_message
+ *
+ * #### Parameters
+ * - request: the request to bindings
+ *
+ * #### Return
+ * result
+ *
+ */
+int HS_ClientManager::on_screen_message(afb_req_t request)
+{
+ int ret = 0;
+ const char* value = afb_req_value(request, _display_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_message(request, value);
+ }
+ }
+ else {
+ 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];
+ }
+ else {
+ appid2ctxt[appid] = createClientCtxt(request, appid);
+ client = addClient(request, appid);
+ }
+
+ if(client->subscribe(request, value) != 0) {
+ HMI_NOTICE("homescreen-service","subscribe failed");
+ ret = AFB_REQ_SUBSCRIBE_ERROR;
+ }
+ }
+ else {
+ HMI_NOTICE("homescreen-service","Please input event name");
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
+ return ret;
+}
+
+/**
+ * unsubscribe
+ *
+ * #### Parameters
+ * - request: the request to bindings
+ *
+ * #### Return
+ * result
+ *
+ */
+int HS_ClientManager::unsubscribe(afb_req_t request)
+{
+ const char *value = afb_req_value(request, "event");
+ 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);
+
+ auto ip = client_list.find(appid);
+ if(ip != client_list.end()
+ && ip->second->unsubscribe(request, value) != 0) {
+ HMI_NOTICE("homescreen-service","unsubscribe failed");
+ ret = AFB_REQ_UNSUBSCRIBE_ERROR;
+ }
+ }
+ else {
+ HMI_NOTICE("homescreen-service","Please input event name");
+ ret = AFB_EVENT_BAD_REQUEST;
+ }
+ return ret;
+}
diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h
index 99c6c0b..5258090 100644
--- a/src/hs-clientmanager.h
+++ b/src/hs-clientmanager.h
@@ -18,7 +18,6 @@
#define HOMESCREEN_CLIENTMANAGER_H
#include <string>
-#include <vector>
#include <mutex>
#include <memory>
#include <unordered_map>
@@ -46,11 +45,14 @@ public:
static HS_ClientManager* instance(void);
int init(void);
- HS_Client* find(std::string appid);
- HS_Client* getClient(afb_req_t req, std::string appid);
- std::vector<HS_Client*> getAllClient(void);
void removeClientCtxt(void *data);
+ int tap_shortcut(afb_req_t request);
+ int on_screen_message(afb_req_t request);
+ int on_screen_reply(afb_req_t request);
+ int subscribe(afb_req_t request);
+ int unsubscribe(afb_req_t request);
+
private:
HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
HS_Client* addClient(afb_req_t req, std::string appid);
diff --git a/src/hs-helper.h b/src/hs-helper.h
index 3195daf..a2fc0a9 100644
--- a/src/hs-helper.h
+++ b/src/hs-helper.h
@@ -20,6 +20,9 @@
#include <afb/afb-binding.h>
#include <json-c/json.h>
+#define AFB_EVENT_BAD_REQUEST 100
+#define AFB_REQ_SUBSCRIBE_ERROR 101
+#define AFB_REQ_UNSUBSCRIBE_ERROR 102
typedef enum REQ_ERROR
{