aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-10-30 14:26:59 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-10-30 14:26:59 +0900
commitac38c0f5d121e9dadb0fe5db25d7aed9fa1b9389 (patch)
treecd389a3f4d30fa7661fb5fae063438291d102e87 /src
parent789ecb879cc529400b290eb9750fd1f9298fc690 (diff)
add source for ces2019
Diffstat (limited to 'src')
-rw-r--r--src/homescreen.cpp174
-rw-r--r--src/hs-client.cpp81
-rw-r--r--src/hs-client.h17
-rw-r--r--src/hs-clientmanager.cpp6
-rw-r--r--src/hs-clientmanager.h6
-rw-r--r--src/hs-helper.cpp9
-rw-r--r--src/hs-helper.h10
7 files changed, 256 insertions, 47 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index fdc9e85..db739ee 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -29,14 +29,18 @@ const char _error[] = "error";
const char _application_name[] = "application_name";
const char _display_message[] = "display_message";
const char _reply_message[] = "reply_message";
+const char _args[] = "args";
+const char _parameter[] = "parameter";
static HS_ClientManager* g_client_manager = HS_ClientManager::instance();
+static std::unordered_map<std::string, HS_Client*> g_client_map;
+
/*
********** Method of HomeScreen Service (API) **********
*/
-static void pingSample(afb_req_t request)
+static void pingSample(struct afb_req request)
{
static int pingcount = 0;
afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d", pingcount);
@@ -56,7 +60,7 @@ static void pingSample(afb_req_t request)
* None
*
*/
-static void tap_shortcut (afb_req_t request)
+static void tap_shortcut (struct afb_req request)
{
HMI_NOTICE("homescreen-service","called.");
@@ -90,6 +94,50 @@ static void tap_shortcut (afb_req_t request)
}
/**
+ * showWindow event
+ *
+ * #### Parameters
+ * - id : app's id
+ * - parameter : parameter from app to new window
+ *
+ * #### Return
+ * None
+ *
+ */
+static void showWindow(struct afb_req 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->showWindow(request, 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__);
+ return;
+ }
+
+ // response to HomeScreen
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [showWindow]");
+}
+
+/**
* HomeScreen OnScreen message
*
* #### Parameters
@@ -100,7 +148,7 @@ static void tap_shortcut (afb_req_t request)
* None
*
*/
-static void on_screen_message (afb_req_t request)
+static void on_screen_message (struct afb_req request)
{
HMI_NOTICE("homescreen-service","called.");
@@ -138,7 +186,7 @@ static void on_screen_message (afb_req_t request)
* None
*
*/
-static void on_screen_reply (afb_req_t request)
+static void on_screen_reply (struct afb_req request)
{
HMI_NOTICE("homescreen-service","called.");
@@ -175,7 +223,7 @@ static void on_screen_reply (afb_req_t request)
* None
*
*/
-static void subscribe(afb_req_t request)
+static void subscribe(struct afb_req request)
{
const char *value = afb_req_value(request, "event");
HMI_NOTICE("homescreen-service","value is %s", value);
@@ -209,7 +257,7 @@ static void subscribe(afb_req_t request)
* None
*
*/
-static void unsubscribe(afb_req_t request)
+static void unsubscribe(struct afb_req request)
{
const char *value = afb_req_value(request, "event");
HMI_NOTICE("homescreen-service","value is %s", value);
@@ -240,17 +288,102 @@ static void unsubscribe(afb_req_t request)
afb_req_success_f(request, res, "homescreen binder unsubscribe event name [%s]", value);
}
+/**
+ * allocateRestriction event
+ *
+ * #### Parameters
+ * - value : the json contents to Restriction App.
+ * {"area":"area id"}
+ *
+ * #### Return
+ * None
+ *
+ */
+static void allocateRestriction(struct afb_req request)
+{
+ HMI_NOTICE("homescreen-service","called.");
+
+ int ret = 0;
+ const char* value = afb_req_value(request, _args);
+ if (value) {
+ HMI_NOTICE("homescreen-service","request args = %s.", value);
+ HS_Client* client = g_client_manager->find(std::string("restriction"));
+ if(client != nullptr) {
+ if(client->allocateRestriction(request, 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__);
+ return;
+ }
+
+ // response to Application
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [allocateRestriction]");
+}
+
+/**
+ * releaseRestriction event
+ *
+ * #### Parameters
+ * - value : the json contents to Restriction App.
+ * {"area":"area id"}
+ *
+ * #### Return
+ * None
+ *
+ */
+static void releaseRestriction(struct afb_req request)
+{
+ HMI_NOTICE("homescreen-service","called.");
+
+ int ret = 0;
+ const char* value = afb_req_value(request, _args);
+ if (value) {
+ HMI_NOTICE("homescreen-service","request args = %s.", value);
+ HS_Client* client = g_client_manager->find(std::string("restriction"));
+ if(client != nullptr) {
+ if(client->releaseRestriction(request, 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__);
+ return;
+ }
+
+ // response to Application
+ struct json_object *res = json_object_new_object();
+ hs_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ _error, ret);
+ afb_req_success(request, res, "afb_event_push event [releaseRestriction]");
+}
+
/*
* array of the verbs exported to afb-daemon
*/
-static const afb_verb_t verbs[]= {
- /* VERB'S NAME FUNCTION TO CALL */
- { .verb="ping", .callback=pingSample },
- { .verb="tap_shortcut", .callback=tap_shortcut },
- { .verb="on_screen_message", .callback=on_screen_message },
- { .verb="on_screen_reply", .callback=on_screen_reply },
- { .verb="subscribe", .callback=subscribe },
- { .verb="unsubscribe", .callback=unsubscribe },
+static const struct afb_verb_v2 verbs[]= {
+ /* VERB'S NAME FUNCTION TO CALL authorisation some info SESSION MANAGEMENT */
+ { .verb = "ping", .callback = pingSample, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE },
+ { .verb = "tap_shortcut", .callback = tap_shortcut, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE },
+ { .verb = "showWindow", .callback = showWindow, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE, },
+ { .verb = "on_screen_message", .callback = on_screen_message, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE },
+ { .verb = "on_screen_reply", .callback = on_screen_reply, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE },
+ { .verb = "subscribe", .callback = subscribe, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE },
+ { .verb = "unsubscribe", .callback = unsubscribe, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE },
+ { .verb = "allocateRestriction", .callback = allocateRestriction, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE, },
+ { .verb = "releaseRestriction", .callback = releaseRestriction, .auth = NULL, .info = NULL, .session = AFB_SESSION_NONE, },
{NULL } /* marker for end of the array */
};
@@ -258,13 +391,13 @@ static const afb_verb_t verbs[]= {
* homescreen binding preinit function
*
* #### Parameters
- * - api : the api serving the request
+ * - null
*
* #### Return
* None
*
*/
-static int preinit(afb_api_t api)
+static int preinit()
{
HMI_NOTICE("homescreen-service","binding preinit (was register)");
return 0;
@@ -274,13 +407,13 @@ static int preinit(afb_api_t api)
* homescreen binding init function
*
* #### Parameters
- * - api : the api serving the request
+ * - null
*
* #### Return
* None
*
*/
-static int init(afb_api_t api)
+static int init()
{
HMI_NOTICE("homescreen-service","binding init");
@@ -293,7 +426,6 @@ static int init(afb_api_t api)
* homescreen binding event function
*
* #### Parameters
- * - api : the api serving the request
* - event : event name
* - object : event json object
*
@@ -301,12 +433,12 @@ static int init(afb_api_t api)
* None
*
*/
-static void onevent(afb_api_t api, const char *event, struct json_object *object)
+static void onevent(const char *event, struct json_object *object)
{
HMI_NOTICE("homescreen-service","on_event %s", event);
}
-const afb_binding_t afbBindingExport = {
+const struct afb_binding_v2 afbBindingV2 = {
.api = "homescreen",
.specification = NULL,
.info = NULL,
diff --git a/src/hs-client.cpp b/src/hs-client.cpp
index 9fc9b61..e7b429b 100644
--- a/src/hs-client.cpp
+++ b/src/hs-client.cpp
@@ -30,10 +30,10 @@ static const char _type[] = "type";
* None
*
*/
-HS_Client::HS_Client(afb_req_t request, std::string id) : my_id(id)
+HS_Client::HS_Client(struct afb_req request, std::string id) : my_id(id)
{
HMI_NOTICE("homescreen-service","called.");
- my_event = afb_api_make_event(request->api, id.c_str());
+ my_event = afb_daemon_make_event(id.c_str());
}
/**
@@ -75,6 +75,29 @@ int HS_Client::tap_shortcut(const char* appname)
}
/**
+ * push showWindow event
+ *
+ * #### Parameters
+ * - appname: app's name.
+ *
+ * #### Return
+ * result
+ *
+ */
+int HS_Client::showWindow(struct afb_req request, const char* appname)
+{
+ if(!checkEvent(__FUNCTION__))
+ return 0;
+
+ HMI_NOTICE("homescreen-service","%s application_name = %s.", __FUNCTION__, 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__);
+ const char *param = afb_req_value(request, _parameter);
+ json_object_object_add(push_obj, _parameter, json_tokener_parse(param));
+ return afb_event_push(my_event, push_obj);
+}
+/**
* push on_screen_message event
*
* #### Parameters
@@ -84,7 +107,7 @@ int HS_Client::tap_shortcut(const char* appname)
* result
*
*/
-int HS_Client::on_screen_message(afb_req_t request, const char* message)
+int HS_Client::on_screen_message(struct afb_req request, const char* message)
{
if(!checkEvent(__FUNCTION__))
return 0;
@@ -106,7 +129,7 @@ int HS_Client::on_screen_message(afb_req_t request, const char* message)
* result
*
*/
-int HS_Client::on_screen_reply(afb_req_t request, const char* message)
+int HS_Client::on_screen_reply(struct afb_req request, const char* message)
{
if(!checkEvent(__FUNCTION__))
return 0;
@@ -128,7 +151,7 @@ int HS_Client::on_screen_reply(afb_req_t request, const char* message)
* result
*
*/
-int HS_Client::subscribe(afb_req_t request, const char* event)
+int HS_Client::subscribe(struct afb_req request, const char* event)
{
int ret = 0;
auto ip = event_list.find(std::string(event));
@@ -149,7 +172,7 @@ int HS_Client::subscribe(afb_req_t request, const char* event)
* result
*
*/
-int HS_Client::unsubscribe(afb_req_t request, const char* event)
+int HS_Client::unsubscribe(struct afb_req request, const char* event)
{
int ret = 0;
event_list.erase(std::string(event));
@@ -160,6 +183,52 @@ int HS_Client::unsubscribe(afb_req_t request, const char* event)
}
/**
+ * allocate restriction
+ *
+ * #### Parameters
+ * - area: display area.
+ *
+ * #### Return
+ * result
+ *
+ */
+int HS_Client::allocateRestriction(struct afb_req request, const char* area)
+{
+ if(!checkEvent(__FUNCTION__))
+ return 0;
+
+ HMI_NOTICE("homescreen-service","%s area=%s.", __FUNCTION__, area);
+ struct json_object* push_obj = json_object_new_object();
+ hs_add_object_to_json_object_str( push_obj, 4, _application_name, "restriction",
+ _type, __FUNCTION__);
+ json_object_object_add(push_obj, _args, json_tokener_parse(area));
+ return afb_event_push(my_event, push_obj);
+}
+
+/**
+ * release restriction
+ *
+ * #### Parameters
+ * - area: display area.
+ *
+ * #### Return
+ * result
+ *
+ */
+int HS_Client::releaseRestriction(struct afb_req request, const char* area)
+{
+ if(!checkEvent(__FUNCTION__))
+ return 0;
+
+ HMI_NOTICE("homescreen-service","%s area=%s.", __FUNCTION__, area);
+ struct json_object* push_obj = json_object_new_object();
+ hs_add_object_to_json_object_str( push_obj, 4, _application_name, "restriction",
+ _type, __FUNCTION__);
+ json_object_object_add(push_obj, _args, json_tokener_parse(area));
+ return afb_event_push(my_event, push_obj);
+}
+
+/**
* check if client subscribe event
*
* #### Parameters
diff --git a/src/hs-client.h b/src/hs-client.h
index 1b2eb8f..bd881e6 100644
--- a/src/hs-client.h
+++ b/src/hs-client.h
@@ -24,24 +24,27 @@
class HS_Client {
public:
- HS_Client(afb_req_t request, const char* id) : HS_Client(request, std::string(id)){}
- HS_Client(afb_req_t request, std::string id);
+ HS_Client(struct afb_req request, const char* id) : HS_Client(request, std::string(id)){}
+ HS_Client(struct afb_req request, std::string id);
HS_Client(HS_Client&) = delete;
HS_Client &operator=(HS_Client&) = delete;
~HS_Client();
int tap_shortcut(const char* appname);
- int on_screen_message (afb_req_t request, const char* message);
- int on_screen_reply (afb_req_t request, const char* message);
- int subscribe(afb_req_t request, const char* event);
- int unsubscribe(afb_req_t request, const char* event);
+ int showWindow(struct afb_req request, const char* appname);
+ int on_screen_message (struct afb_req request, const char* message);
+ int on_screen_reply (struct afb_req request, const char* message);
+ int subscribe(struct afb_req request, const char* event);
+ int unsubscribe(struct afb_req request, const char* event);
+ int allocateRestriction(struct afb_req request, const char* area);
+ int releaseRestriction(struct afb_req request, const char* area);
private:
bool checkEvent(const char* event);
private:
std::string my_id;
- afb_event_t my_event;
+ struct afb_event my_event;
std::unordered_map<std::string, int> event_list;
};
diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp
index a79e9bb..3dea3a6 100644
--- a/src/hs-clientmanager.cpp
+++ b/src/hs-clientmanager.cpp
@@ -104,7 +104,7 @@ HS_Client* HS_ClientManager::find(std::string appid)
* found HS_Client pointer
*
*/
-HS_Client* HS_ClientManager::getClient(afb_req_t req, std::string appid)
+HS_Client* HS_ClientManager::getClient(afb_req req, std::string appid)
{
std::lock_guard<std::mutex> lock(this->mtx);
HS_Client* p = nullptr;
@@ -148,7 +148,7 @@ std::vector<HS_Client*> HS_ClientManager::getAllClient(void)
* HS_ClientCtxt pointer
*
*/
-HS_ClientCtxt* HS_ClientManager::createClientCtxt(afb_req_t req, std::string appid)
+HS_ClientCtxt* HS_ClientManager::createClientCtxt(afb_req req, std::string appid)
{
HS_ClientCtxt *ctxt = (HS_ClientCtxt *)afb_req_context_get(req);
if (!ctxt)
@@ -171,7 +171,7 @@ HS_ClientCtxt* HS_ClientManager::createClientCtxt(afb_req_t req, std::string app
* HS_Client pointer
*
*/
-HS_Client* HS_ClientManager::addClient(afb_req_t req, std::string appid)
+HS_Client* HS_ClientManager::addClient(afb_req req, std::string appid)
{
return (client_list[appid] = new HS_Client(req, appid));
}
diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h
index 99c6c0b..cb49088 100644
--- a/src/hs-clientmanager.h
+++ b/src/hs-clientmanager.h
@@ -47,13 +47,13 @@ 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);
+ HS_Client* getClient(afb_req req, std::string appid);
std::vector<HS_Client*> getAllClient(void);
void removeClientCtxt(void *data);
private:
- HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
- HS_Client* addClient(afb_req_t req, std::string appid);
+ HS_ClientCtxt* createClientCtxt(afb_req req, std::string appid);
+ HS_Client* addClient(afb_req req, std::string appid);
void removeClient(std::string appid);
private:
diff --git a/src/hs-helper.cpp b/src/hs-helper.cpp
index 2d8ab7a..8780cc0 100644
--- a/src/hs-helper.cpp
+++ b/src/hs-helper.cpp
@@ -21,8 +21,11 @@
const char* evlist[] = {
"tap_shortcut",
+ "showWindow",
"on_screen_message",
"on_screen_reply",
+ "allocateRestriction",
+ "releaseRestriction",
"reserved"
};
@@ -38,7 +41,7 @@ const char* evlist[] = {
* error code
*
*/
-REQ_ERROR get_value_uint16(const afb_req_t request, const char *source, uint16_t *out_id)
+REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id)
{
char* endptr;
const char* tmp = afb_req_value (request, source);
@@ -74,7 +77,7 @@ REQ_ERROR get_value_uint16(const afb_req_t request, const char *source, uint16_t
* error code
*
*/
-REQ_ERROR get_value_int16(const afb_req_t request, const char *source, int16_t *out_id)
+REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id)
{
char* endptr;
const char* tmp = afb_req_value (request, source);
@@ -110,7 +113,7 @@ REQ_ERROR get_value_int16(const afb_req_t request, const char *source, int16_t *
* error code
*
*/
-REQ_ERROR get_value_int32(const afb_req_t request, const char *source, int32_t *out_id)
+REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id)
{
char* endptr;
const char* tmp = afb_req_value (request, source);
diff --git a/src/hs-helper.h b/src/hs-helper.h
index 3195daf..b2354e0 100644
--- a/src/hs-helper.h
+++ b/src/hs-helper.h
@@ -16,7 +16,7 @@
#ifndef HOMESCREEN_HELPER_H
#define HOMESCREEN_HELPER_H
-#define AFB_BINDING_VERSION 3
+#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include <json-c/json.h>
@@ -34,10 +34,12 @@ extern const char _error[];
extern const char _application_name[];
extern const char _display_message[];
extern const char _reply_message[];
+extern const char _args[];
+extern const char _parameter[];
-REQ_ERROR get_value_uint16(const afb_req_t request, const char *source, uint16_t *out_id);
-REQ_ERROR get_value_int16(const afb_req_t request, const char *source, int16_t *out_id);
-REQ_ERROR get_value_int32(const afb_req_t request, const char *source, int32_t *out_id);
+REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id);
+REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id);
+REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id);
void hs_add_object_to_json_object(struct json_object* j_obj, int count, ...);
void hs_add_object_to_json_object_str(struct json_object* j_obj, int count, ...);
void hs_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...);