+
+/**
+ * handle homescreen request
+ *
+ * #### Parameters
+ * - request : the request
+ * - verb : the verb name
+ * - appid : to which application
+ *
+ * #### Return
+ * 0 : success
+ * others : fail
+ *
+ */
+int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const char *appid)
+{
+ AFB_INFO("verb=[%s],appid=[%s].", verb, appid);
+ int ret = 0;
+ std::lock_guard<std::mutex> lock(this->mtx);
+ if(appid == nullptr) {
+ for(auto m : client_list) {
+ m.second->handleRequest(request, verb);
+ }
+ }
+ else {
+ std::string id(appid);
+ auto ip = client_list.find(id);
+ if(ip != client_list.end()) {
+ // FIXME: do another verification here in case the application died
+ ret = ip->second->handleRequest(request, verb);
+ }
+ else {
+ if(!strcasecmp(verb, "subscribe")) {
+ createClientCtxt(request, id);
+ HS_Client* client = addClient(request, id);
+ ret = client->handleRequest(request, "subscribe");
+ }
+ else {
+ AFB_NOTICE("not exist session");
+ ret = AFB_REQ_NOT_STARTED_APPLICATION;
+ }
+ }
+ }
+ 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) {
+ AFB_WARNING("event name is null.");
+ return -1;
+ }
+
+ std::lock_guard<std::mutex> lock(this->mtx);
+ if(appid.empty()) { // broadcast event to clients who subscribed this event
+ for(auto m : client_list) {
+ m.second->pushEvent(event, param);
+ }
+ }
+ else { // push event to specific client
+ auto ip = client_list.find(appid);
+ if(ip != client_list.end()) {
+ ip->second->pushEvent(event, param);
+ }
+ }
+
+ return 0;
+}