aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/homescreen.cpp77
-rw-r--r--src/hs-client.cpp25
-rw-r--r--src/hs-client.h1
-rw-r--r--src/hs-clientmanager.cpp37
-rw-r--r--src/hs-clientmanager.h1
-rw-r--r--src/hs-periphery.cpp165
-rw-r--r--src/hs-periphery.h70
-rw-r--r--src/hs-proxy.cpp104
-rw-r--r--src/hs-proxy.h55
10 files changed, 525 insertions, 14 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3687345..c6dc972 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,7 +26,9 @@ set(binding_hs_sources
homescreen.cpp
hs-helper.cpp
hs-clientmanager.cpp
- hs-client.cpp)
+ hs-client.cpp
+ hs-proxy.cpp
+ hs-periphery.cpp)
link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
include_directories(${PROJECT_SOURCE_DIR}/include)
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index fce25ee..0f6a10d 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -22,6 +22,7 @@
#include "hs-helper.h"
#include "hmi-debug.h"
#include "hs-clientmanager.h"
+#include "hs-periphery.h"
const char _error[] = "error";
@@ -29,7 +30,44 @@ const char _application_id[] = "application_id";
const char _display_message[] = "display_message";
const char _reply_message[] = "reply_message";
-static HS_ClientManager* g_client_manager = HS_ClientManager::instance();
+struct hs_instance {
+ HS_ClientManager *client_manager; // the connection session manager
+ HS_PeripheryManager *periphery_manager; // the periphery application manager
+
+ hs_instance() : client_manager(HS_ClientManager::instance()), periphery_manager(HS_PeripheryManager::instance()) {}
+ int init(afb_api_t api);
+};
+
+/**
+ * init function
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ *
+ * #### Return
+ * 0 : init success
+ * 1 : init fail
+ *
+ */
+int hs_instance::init(afb_api_t api)
+{
+ if(client_manager == nullptr) {
+ HMI_ERROR("homescreen-service","FATAL ERROR: client_manager is nullptr.");
+ return -1;
+ }
+ client_manager->init();
+
+ if(periphery_manager == nullptr) {
+ HMI_ERROR("homescreen-service","FATAL ERROR: periphery_manager is nullptr.");
+ return -1;
+ }
+ periphery_manager->init(api);
+
+ return 0;
+}
+
+static struct hs_instance *g_hs_instance;
+// static HS_ClientManager* g_client_manager = HS_ClientManager::instance();
/*
********** Method of HomeScreen Service (API) **********
@@ -58,7 +96,7 @@ static void pingSample(afb_req_t request)
static void tap_shortcut (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->tap_shortcut(request);
+ int ret = g_hs_instance->client_manager->tap_shortcut(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -86,7 +124,7 @@ static void on_screen_message (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->on_screen_message(request);
+ int ret = g_hs_instance->client_manager->on_screen_message(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -114,7 +152,7 @@ static void on_screen_reply (afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->on_screen_reply(request);
+ int ret = g_hs_instance->client_manager->on_screen_reply(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -141,7 +179,7 @@ static void subscribe(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->subscribe(request);
+ int ret = g_hs_instance->client_manager->subscribe(request);
if(ret) {
afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
return;
@@ -168,7 +206,7 @@ static void unsubscribe(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->unsubscribe(request);
+ int ret = g_hs_instance->client_manager->unsubscribe(request);
if(ret) {
afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
return;
@@ -195,7 +233,7 @@ static void showWindow(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->showWindow(request);
+ int ret = g_hs_instance->client_manager->showWindow(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -222,7 +260,7 @@ static void hideWindow(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->hideWindow(request);
+ int ret = g_hs_instance->client_manager->hideWindow(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -249,7 +287,7 @@ static void replyShowWindow(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->replyShowWindow(request);
+ int ret = g_hs_instance->client_manager->replyShowWindow(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -278,7 +316,7 @@ static void showNotification(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->showNotification(request);
+ int ret = g_hs_instance->client_manager->showNotification(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -307,7 +345,7 @@ static void showInformation(afb_req_t request)
{
HMI_NOTICE("homescreen-service","called.");
- int ret = g_client_manager->showInformation(request);
+ int ret = g_hs_instance->client_manager->showInformation(request);
if (ret != 0) {
afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
return;
@@ -369,9 +407,21 @@ static int init(afb_api_t api)
{
HMI_NOTICE("homescreen-service","binding init");
- g_client_manager->init();
+ // g_client_manager->init();
+ if(g_hs_instance != nullptr) {
+ HMI_WARNING("homescreen-service", "g_hs_instance isn't null.");
+ delete g_hs_instance->client_manager;
+ delete g_hs_instance->periphery_manager;
+ delete g_hs_instance;
+ g_hs_instance = nullptr;
+ }
+ g_hs_instance = new hs_instance();
+ if(g_hs_instance == nullptr) {
+ HMI_ERROR("homescreen-service", "Fatal Error: new g_hs_instance failed.");
+ return -1;
+ }
- return 0;
+ return g_hs_instance->init(api);
}
/**
@@ -389,6 +439,7 @@ static int init(afb_api_t api)
static void onevent(afb_api_t api, const char *event, struct json_object *object)
{
HMI_NOTICE("homescreen-service","on_event %s", event);
+ g_hs_instance->periphery_manager->onEvent(api, event, object);
}
const afb_binding_t afbBindingExport = {
diff --git a/src/hs-client.cpp b/src/hs-client.cpp
index e97f844..41be426 100644
--- a/src/hs-client.cpp
+++ b/src/hs-client.cpp
@@ -388,3 +388,28 @@ int HS_Client::showInformation(afb_req_t request)
return ret;
}
+
+/**
+ * push event
+ *
+ * #### Parameters
+ * - event : the event want to push
+ * - param : the parameter contents of event
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_Client::pushEvent(const char *event, struct json_object *param)
+{
+ if(!checkEvent(event))
+ return 0;
+
+ struct json_object* push_obj = json_object_new_object();
+ hs_add_object_to_json_object_str( push_obj, 4, _application_id, my_id.c_str(), _type, event);
+ if(param != nullptr)
+ json_object_object_add(push_obj, _parameter, param);
+ afb_event_push(my_event, push_obj);
+ return 0;
+} \ No newline at end of file
diff --git a/src/hs-client.h b/src/hs-client.h
index b06a717..32756b2 100644
--- a/src/hs-client.h
+++ b/src/hs-client.h
@@ -40,6 +40,7 @@ public:
int unsubscribe(afb_req_t request, const char* event);
int showNotification(afb_req_t request);
int showInformation(afb_req_t request);
+ int pushEvent(const char *event, struct json_object *param);
private:
bool checkEvent(const char* event);
diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp
index 1355c99..9fe8b96 100644
--- a/src/hs-clientmanager.cpp
+++ b/src/hs-clientmanager.cpp
@@ -463,3 +463,40 @@ int HS_ClientManager::showInformation(afb_req_t request)
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;
+ }
+
+ if(appid.empty()) { // broadcast event to clients who subscribed this event
+ std::lock_guard<std::mutex> lock(this->mtx);
+ for(auto m : client_list) {
+ m.second->pushEvent(event, param);
+ }
+ }
+ else { // push event to specific client
+ std::lock_guard<std::mutex> lock(this->mtx);
+ auto ip = client_list.find(appid);
+ if(ip != client_list.end()) {
+ ip->second->pushEvent(event, param);
+ }
+ }
+
+ return 0;
+}
diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h
index 64ca03c..a568298 100644
--- a/src/hs-clientmanager.h
+++ b/src/hs-clientmanager.h
@@ -57,6 +57,7 @@ public:
int unsubscribe(afb_req_t request);
int showNotification(afb_req_t request);
int showInformation(afb_req_t request);
+ int pushEvent(const char *event, struct json_object *param, std::string appid = "");
private:
HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
diff --git a/src/hs-periphery.cpp b/src/hs-periphery.cpp
new file mode 100644
index 0000000..a629ead
--- /dev/null
+++ b/src/hs-periphery.cpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hs-periphery.h"
+#include "hs-proxy.h"
+#include "hmi-debug.h"
+#include "hs-clientmanager.h"
+
+static const char _restriction_on[] = "RestrictionOn";
+static const char _restriction_off[] = "RestrictionOff";
+
+/* -------------------------------------HS_PeripheryManager------------------------------------------ */
+
+HS_PeripheryManager* HS_PeripheryManager::me = nullptr;
+
+/**
+ * HS_PeripheryManager init function
+ *
+ * #### Parameters
+ * - Nothing
+ *
+ * #### Return
+ * init result
+ *
+ */
+int HS_PeripheryManager::init(afb_api_t api)
+{
+ return m_restriction.init(api);
+}
+
+/**
+ * get instance
+ *
+ * #### Parameters
+ * - Nothing
+ *
+ * #### Return
+ * HS_PeripheryManager instance pointer
+ *
+ */
+HS_PeripheryManager* HS_PeripheryManager::instance(void)
+{
+ if(me == nullptr)
+ me = new HS_PeripheryManager();
+ return me;
+}
+
+/**
+ * event function
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - event : event name
+ * - object : event json object
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_PeripheryManager::onEvent(afb_api_t api, const char *event, struct json_object *object)
+{
+ m_restriction.onEvent(api, event, object);
+}
+
+/* -------------------------------------HS_Restriction------------------------------------------ */
+
+/**
+ * HS_Restriction init function
+ *
+ * #### Parameters
+ * - Nothing
+ *
+ * #### Return
+ * init result
+ *
+ */
+int HS_Restriction::init(afb_api_t api)
+{
+ HS_WmProxy wm_proxy;
+ // TBD
+ wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated);
+ return 0;
+}
+
+/**
+ * event function
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - event : event name
+ * - object : event json object
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_Restriction::onEvent(afb_api_t api, const char *event, struct json_object *object)
+{
+ if(!isConcernedEvent(event))
+ return;
+
+ std::string ev = event;
+ std::size_t pos = ev.find("/");
+ if(pos != std::string::npos) {
+ ev = ev.substr(pos + 1);
+ }
+ else {
+ HMI_ERROR("homescreen-service","received event is error.");
+ return;
+ }
+
+ if(ev == _restriction_on) {
+ restrictionOn(api, object);
+ }
+ else if(ev == _restriction_off) {
+ restrictionOff(api, object);
+ }
+ else {
+ }
+}
+
+/**
+ * restriction on function
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - object : event json object
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_Restriction::restrictionOn(afb_api_t api, struct json_object *object)
+{
+
+}
+
+/**
+ * restriction off function
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - object : event json object
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_Restriction::restrictionOff(afb_api_t api, struct json_object *object)
+{
+
+} \ No newline at end of file
diff --git a/src/hs-periphery.h b/src/hs-periphery.h
new file mode 100644
index 0000000..f551db3
--- /dev/null
+++ b/src/hs-periphery.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef HOMESCREEN_PERIPHERY_H
+#define HOMESCREEN_PERIPHERY_H
+
+#include <unordered_set>
+#include "hs-helper.h"
+
+class HS_Restriction {
+public:
+ HS_Restriction() = default;
+ ~HS_Restriction() = default;
+
+ int init(afb_api_t api);
+ void onEvent(afb_api_t api, const char *event, struct json_object *object);
+
+private:
+ const std::unordered_set<const char*> concerned_event_list {
+ "windowmanager/RestrictionOn",
+ "windowmanager/RestrictionOff"
+ };
+ inline bool isConcernedEvent(const char* event) const {
+ return (concerned_event_list.find(event) != concerned_event_list.end()) ? true : false;
+ }
+
+ void restrictionOn(afb_api_t api, struct json_object *object);
+ void restrictionOff(afb_api_t api, struct json_object *object);
+
+ std::string m_appid = "restriction";
+};
+
+class HS_PeripheryManager {
+public:
+ HS_PeripheryManager() = default;
+ ~HS_PeripheryManager() = default;
+
+ int init(afb_api_t api);
+ static HS_PeripheryManager* instance(void);
+ void onEvent(afb_api_t api, const char *event, struct json_object *object);
+
+ inline bool isPeripheryApp(const char* name) const {
+ return (periphery_app_list.find(name) != periphery_app_list.end()) ? true : false;
+ }
+
+private:
+ const std::unordered_set<const char*> periphery_app_list {
+ "launcher",
+ "homescreen",
+ "onscreenapp",
+ "restriction"
+ };
+
+ static HS_PeripheryManager* me;
+ HS_Restriction m_restriction;
+};
+
+#endif // HOMESCREEN_PERIPHERY_H \ No newline at end of file
diff --git a/src/hs-proxy.cpp b/src/hs-proxy.cpp
new file mode 100644
index 0000000..6ac4439
--- /dev/null
+++ b/src/hs-proxy.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hs-proxy.h"
+#include "hmi-debug.h"
+
+static const char _windowmanager[] = "windowmanager";
+static const char _event[] = "event";
+
+
+/**
+ * the callback function
+ *
+ * #### Parameters
+ * - closure : the user defined closure pointer 'closure'
+ * - object : a JSON object returned (can be NULL)
+ * - error : a string not NULL in case of error but NULL on success
+ * - info : a string handling some info (can be NULL)
+ * - api : the api
+ *
+ * #### Return
+ * None
+ *
+ */
+static void api_callback(void *closure, struct json_object *object, const char *error, const char *info, afb_api_t api)
+{
+ HMI_NOTICE("homescreen-service","asynchronous call, error=%s, info=%s, object=%s.", error, info, json_object_get_string(object));
+ callback_func* f = (callback_func*)closure;
+ if(f != nullptr)
+ (*f)(api, object);
+}
+
+/**
+ * call api asynchronous
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - service : the api name of service
+ * - verb : the verb of service
+ * - args : parameter
+ *
+ * #### Return
+ * None
+ *
+ */
+static void api_call(afb_api_t api, const char *service, const char *verb, struct json_object *args, callback_func *f = nullptr)
+{
+ HMI_NOTICE("homescreen-service","service=%s verb=%s, args=%s.", service, verb, json_object_get_string(args));
+ afb_api_call(api, service, verb, args, api_callback, (void*)f);
+}
+
+/**
+ * call api synchronous
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - service : the api name of service
+ * - verb : the verb of afm-main
+ * - args : parameter
+ * - object : return the details of application
+ *
+ * #### Return
+ * 0 : success
+ * 1 : fail
+ *
+ */
+static int api_call_sync(afb_api_t api, const char *service, const char *verb, struct json_object *args, struct json_object **object)
+{
+ char *error = nullptr, *info = nullptr;
+ int ret = afb_api_call_sync(api, service, verb, args, object, &error, &info);
+ HMI_NOTICE("homescreen-service","synchronous call, error=%s, info=%s.", error, info);
+ return ret;
+}
+
+/**
+ * subscribe windowmanager event
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - event : windowmanager event
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_WmProxy::subscribe(afb_api_t api, EventType event)
+{
+ struct json_object* push_obj = json_object_new_object();
+ json_object_object_add(push_obj, _event, json_object_new_int(event));
+ api_call(api, _windowmanager, "wm_subscribe", push_obj);
+}
diff --git a/src/hs-proxy.h b/src/hs-proxy.h
new file mode 100644
index 0000000..eae80fc
--- /dev/null
+++ b/src/hs-proxy.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HOMESCREEN_PROXY_H
+#define HOMESCREEN_PROXY_H
+
+#include <functional>
+#include "hs-helper.h"
+
+
+using callback_func = std::function<void(afb_api_t, json_object*)>;
+
+class HS_WmProxy {
+public:
+ HS_WmProxy() = default;
+ ~HS_WmProxy() = default;
+
+ enum EventType
+ {
+ Event_Val_Min = 0,
+
+ Event_Active = Event_Val_Min,
+ Event_Inactive,
+
+ Event_Visible,
+ Event_Invisible,
+
+ Event_SyncDraw,
+ Event_FlushDraw,
+
+ Event_ScreenUpdated,
+
+ Event_Error,
+
+ Event_Val_Max = Event_Error,
+ };
+
+ // asynchronous call, reply in callback function
+ void subscribe(afb_api_t api, EventType event);
+};
+
+#endif // HOMESCREEN_PROXY_H \ No newline at end of file