merge improvement
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Mon, 14 Jan 2019 05:50:55 +0000 (13:50 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Mon, 14 Jan 2019 05:50:55 +0000 (13:50 +0800)
Change-Id: I555f0e48ff96564695af60e8d2dbbc1379a8bc95

1  2 
src/homescreen.cpp
src/hs-client.cpp
src/hs-client.h
src/hs-clientmanager.cpp
src/hs-clientmanager.h
src/hs-periphery.cpp
src/hs-periphery.h

@@@ -96,17 -58,25 +96,25 @@@ static void pingSample(afb_req_t reques
  static void tap_shortcut (afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     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;
+     int ret = 0;
+     const char* value = afb_req_value(request, _application_id);
+     if (value) {
+         HMI_NOTICE("homescreen-service","request appid = %s.", value);
 -        ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
++        ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, value);
+     }
+     else {
+         ret = AFB_EVENT_BAD_REQUEST;
      }
  
-     // 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 [tap_shortcut]");
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [tap_shortcut]");
+     }
  }
  
  /**
  static void on_screen_message (afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     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;
 -    int ret = g_client_manager->handleRequest(request, __FUNCTION__);
++    int ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__);
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [on_screen_message]");
      }
-   // 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 [on_screen_message]");
  }
  
  /**
  static void on_screen_reply (afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     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;
 -    int ret = g_client_manager->handleRequest(request, __FUNCTION__);
++    int ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__);
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [on_screen_reply]");
      }
-   // 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 [on_screen_reply]");
  }
  
  /**
  static void subscribe(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
 -        ret = g_client_manager->handleRequest(request, __FUNCTION__, req_appid.c_str());
+     int ret = 0;
+     std::string req_appid = std::move(get_application_id(request));
+     if(!req_appid.empty()) {
++        ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, req_appid.c_str());
+     }
+     else {
+         ret = AFB_EVENT_BAD_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;
+         afb_req_fail_f(request, "afb_req_subscribe failed", "called %s.", __FUNCTION__);
+     }
+     else {
+         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.");
      }
-     /*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.");
  }
  
  /**
  static void unsubscribe(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
 -        ret = g_client_manager->handleRequest(request, __FUNCTION__, req_appid.c_str());
+     int ret = 0;
+     std::string req_appid = std::move(get_application_id(request));
+     if(!req_appid.empty()) {
++        ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, req_appid.c_str());
+     }
+     else {
+         ret = AFB_EVENT_BAD_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;
+         afb_req_fail_f(request, "afb_req_unsubscribe failed", "called %s.", __FUNCTION__);
+     }
+     else {
+         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 success.");
      }
-     /*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 success.");
  }
  
  /**
  static void showWindow(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     int ret = g_hs_instance->client_manager->showWindow(request);
-     if (ret != 0) {
-       afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
-       return;
+     int ret = 0;
+     const char* value = afb_req_value(request, _application_id);
+     if (value) {
 -        ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
++        ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, value);
+     }
+     else {
+         ret = AFB_EVENT_BAD_REQUEST;
      }
  
-     // 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]");
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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]");
+     }
  }
  
  /**
  static void hideWindow(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     int ret = g_hs_instance->client_manager->hideWindow(request);
-     if (ret != 0) {
-       afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
-       return;
+     int ret = 0;
+     const char* value = afb_req_value(request, _application_id);
+     if (value) {
 -        ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
++        ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, value);
+     }
+     else {
+         ret = AFB_EVENT_BAD_REQUEST;
      }
  
-     // 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 [hideWindow]");
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [hideWindow]");
+     }
  }
  
  /**
  static void replyShowWindow(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     int ret = g_hs_instance->client_manager->replyShowWindow(request);
-     if (ret != 0) {
-       afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
-       return;
+     int ret = 0;
+     const char* value = afb_req_value(request, _application_id);
+     if (value) {
 -        ret = g_client_manager->handleRequest(request, __FUNCTION__, value);
++        ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, value);
+     }
+     else {
+         ret = AFB_EVENT_BAD_REQUEST;
      }
  
-     // 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 [replyShowWindow]");
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [replyShowWindow]");
+     }
  }
  
  /**
  static void showNotification(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     int ret = g_hs_instance->client_manager->showNotification(request);
-     if (ret != 0) {
-       afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
-       return;
 -    int ret = g_client_manager->handleRequest(request, __FUNCTION__, "homescreen");
++    int ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, "homescreen");
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [showNotification]");
      }
-     // 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 [showNotification]");
  }
  
  /**
  static void showInformation(afb_req_t request)
  {
      HMI_NOTICE("homescreen-service","called.");
-     int ret = g_hs_instance->client_manager->showInformation(request);
-     if (ret != 0) {
-       afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
-       return;
 -    int ret = g_client_manager->handleRequest(request,  __FUNCTION__, "homescreen");
++    int ret = g_hs_instance->client_manager->handleRequest(request,  __FUNCTION__, "homescreen");
+     if (ret) {
+         afb_req_fail_f(request, "failed", "called %s, Unknown parameter", __FUNCTION__);
+     }
+     else {
+         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 [showInformation]");
      }
-     // 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 [showInformation]");
  }
  
  /*
@@@ -389,27 -390,69 +390,93 @@@ int HS_Client::showInformation(afb_req_
      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;
++}
+ /**
+  * check if client subscribe event
+  *
+  * #### Parameters
+  *  - event: homescreen event, tap_shortcut etc.
+  *
+  * #### Return
+  * true: found
+  * false: not found
+  *
+  */
+ bool HS_Client::checkEvent(const char* event)
+ {
+     auto ip = event_list.find(std::string(event));
+     if(ip == event_list.end())
+         return false;
+     else
+         return true;
+ }
+ /**
+  * check if event is supporting
+  *
+  * #### Parameters
+  *  - event: homescreen event, tap_shortcut etc.
+  *
+  * #### Return
+  * true: support
+  * false: not fosupportund
+  *
+  */
+ bool HS_Client::isSupportEvent(const char* event)
+ {
+     auto ip = func_list.find(std::string(event));
+     if(ip == func_list.end())
+         return false;
+     else
+         return true;
+ }
+ /**
+  * handle homescreen event
+  *
+  * #### Parameters
+  *  - request : the request
+  *  - verb: request verb name
+  *
+  * #### Return
+  * 0: success
+  * others: fail
+  *
+  */
+ int HS_Client::handleRequest(afb_req_t request, const char *verb)
+ {
+     HMI_NOTICE("homescreen-service","called.");
+     if((strcasecmp(verb, "subscribe") && strcasecmp(verb, "unsubscribe")) && !checkEvent(verb))
+         return 0;
+     int ret = AFB_EVENT_BAD_REQUEST;
+     auto ip = func_list.find(std::string(verb));
+     if(ip != func_list.end()) {
+         HMI_NOTICE("homescreen-service","[%s]verb found", verb);
+         ret = (this->*(ip->second))(request);
+     }
+     return ret;
  }
diff --cc src/hs-client.h
@@@ -30,20 -31,35 +31,36 @@@ public
      HS_Client &operator=(HS_Client&) = delete;
      ~HS_Client();
  
-     int tap_shortcut(const char* appid);
-     int showWindow(afb_req_t request, const char* appid);
+     int handleRequest(afb_req_t request, const char *verb);
++    int pushEvent(const char *event, struct json_object *param);
+ private:
+     int tap_shortcut(afb_req_t request);
+     int on_screen_message (afb_req_t request);
+     int on_screen_reply (afb_req_t request);
+     int showWindow(afb_req_t request);
      int hideWindow(afb_req_t request);
-     int replyShowWindow(afb_req_t request, const char* appid);
-     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 replyShowWindow(afb_req_t request);
+     int subscribe(afb_req_t request);
+     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);
  
- private:
+     typedef int (HS_Client::*func_handler)(afb_req_t);
+     const std::unordered_map<std::string, func_handler> func_list {
+         {"tap_shortcut",        &HS_Client::tap_shortcut},
+         {"showWindow",          &HS_Client::showWindow},
+         {"hideWindow",          &HS_Client::hideWindow},
+         {"replyShowWindow",     &HS_Client::replyShowWindow},
+         {"on_screen_message",   &HS_Client::on_screen_message},
+         {"on_screen_reply",     &HS_Client::on_screen_reply},
+         {"subscribe",           &HS_Client::subscribe},
+         {"unsubscribe",         &HS_Client::unsubscribe},
+         {"showNotification",    &HS_Client::showNotification},
+         {"showInformation",     &HS_Client::showInformation}
+     };
      bool checkEvent(const char* event);
+     bool isSupportEvent(const char* event);
  
  private:
      std::string my_id;
@@@ -344,159 -177,21 +177,58 @@@ int HS_ClientManager::handleRequest(afb
          }
      }
      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));
+         auto ip = client_list.find(std::string(appid));
          if(ip != client_list.end()) {
-             ret = ip->second->hideWindow(request);
+             ret = ip->second->handleRequest(request, verb);
          }
-     }
-     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 {
+             if(!strcasecmp(verb, "subscribe")) {
+                 appid2ctxt[appid] = createClientCtxt(request, appid);
+                 HS_Client* client = addClient(request, appid);
+                 ret = client->handleRequest(request, "subscribe");
+             }
+             else {
+                 HMI_NOTICE("homescreen-service","not exist session");
+                 ret = AFB_EVENT_BAD_REQUEST;
+             }
          }
      }
-     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;
- }
 +}
 +
 +/**
 + * 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;
+ }
@@@ -45,19 -45,8 +45,9 @@@ public
  
      static HS_ClientManager* instance(void);
      int init(void);
-     void removeClientCtxt(void *data);
-     int tap_shortcut(afb_req_t request);
-     int showWindow(afb_req_t request);
-     int hideWindow(afb_req_t request);
-     int replyShowWindow(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);
-     int showNotification(afb_req_t request);
-     int showInformation(afb_req_t request);
+     int handleRequest(afb_req_t request, const char *verb, const char *appid = nullptr);
 +    int pushEvent(const char *event, struct json_object *param, std::string appid = "");
+     void removeClientCtxt(void *data);  // don't use, internal only
  
  private:
      HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
index a629ead,0000000..06e95ea
mode 100644,000000..100644
--- /dev/null
@@@ -1,165 -1,0 +1,174 @@@
-     return m_restriction.init(api);
 +/*
 + * 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)
 +{
-     m_restriction.onEvent(api, event, object);
++    HS_Restriction* restriction = new HS_Restriction();
++    int ret = restriction->init(api);
++    if(ret) {
++        HMI_ERROR("homescreen-service","restriction init failed.");
++    }
++    else {
++        periphery_list[std::string("restriction")] = restriction;
++    }
++    return ret;
 +}
 +
 +/**
 + * 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)
 +{
++    for(auto m : periphery_list)
++        m.second->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)
 +{
 +
 +}
index f551db3,0000000..d2da39e
mode 100644,000000..100644
--- /dev/null
@@@ -1,70 -1,0 +1,78 @@@
- class HS_Restriction {
 +/*
 + * 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 <unordered_map>
 +#include "hs-helper.h"
 +
-     HS_Restriction m_restriction;
++class HS_Periphery {
++public:
++    virtual int init(afb_api_t api) = 0;
++    virtual void onEvent(afb_api_t api, const char *event, struct json_object *object) = 0;
++};
++
++class HS_Restriction : public HS_Periphery {
 +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;
++    std::unordered_map<std::string, HS_Periphery*> periphery_list;
++    // HS_Restriction m_restriction;
 +};
 +
 +#endif // HOMESCREEN_PERIPHERY_H