ofs | hex dump | ascii |
---|
0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 04 38 00 00 05 d0 08 02 00 00 00 3f 12 69 | .PNG........IHDR...8.........?.i |
0020 | 83 00 00 00 06 74 52 4e 53 00 00 00 00 00 00 6e a6 07 91 00 00 ff ff 49 44 41 54 78 da ec bd 89 | .....tRNS......n.......IDATx.... |
0040 | b6 2c 3b 6f 1e 06 ee f7 90 7e e9 d7 db 45 71 1c 2d 3b 83 23 5b f1 a4 d8 8e a7 38 2b 93 33 3f 68 | .,;o.....~...Eq.-;.#[.....8+.3?h |
0060 | 4e 33 67 77 15 49 cc 24 ab 58 dd ac dd ac b5 ee 3d bd ab 48 90 00 27 7c 00 48 86 3f f9 f7 ff 2f | N3gw.I.$.X......=..H..'|.H.?.../ |
0080 | 98 4f 84 51 4f 6c 23 d5 58 60 1b b5 d0 48 ae b1 6e 8f c6 ba 8d 2b b1 ad fe a1 ab 95 5a 1b 62 64 | .O.QOl#.X`...H..n....+......Z.bd |
00a0 | 0d fb 92 b7 16 dd 9b be b1 fd 7a 68 76 d5 f4 d1 c7 57 e8 93 c3 05 0d d1 2e 87 3d 71 8f 84 0f cd | ..........zhv....W........=q.... |
00c0 | 2d 7d 5d bd bb fe dd d4 2f 66 b7 4f a4 9d 1d 26 3d 9d dd f2 20 27 07 d9 3f 56 d6 b1 c2 ba 7a ef | -}]...../f.O...&=....'..?V....z. |
00e0 | 8d f8 3a b1 88 1f ca 7a b0 1f 1e e4 2e 3f 87 9a ef 04 9b a8 e4 73 f9 4f 30 7e 50 d4 43 38 1f a2 | ..:....z.....?.......s.O0~P.C8.. |
0100 | 1b f6 2d 19 32 fb 98 4a 9c 27 d1 bd 30 5d c7 ce 18 99 fc 26 33 50 f9 77 5a d9 2e 85 66 0a 02 a8 | ..-.2..J.'..0].....&3P.wZ...f... |
0120 | 8c ab 1f bc 01 9f cc 0b 4e da 0b 6d 20 77 95 c6 76 05 3e b9 44 27 be 00 9c 34 92 ed 95 7c cf 32 | ........N..m.w..v.>.D'...4...|.2 |
0140 | d6 bf f0 bc bd 21 7a 57 9a eb f1 c9 55 40 b7 bf fe d7 83 13 78 11 3e 59 e0 e4 5e 7c 9d 54 9d 8f | .....!zW....U@......x.>Y..^|.T.. |
0160 | 64 7a 07 3e 39 a9 e6 9e 29 f9 23 c1 c9 e9 dc 89 c8 19 54 39 0b 38 81 1f 88 4f e2 50 62 d5 56 6e | dz.>9...).#.......T9.8...O.Pb.Vn |
0180 | 45 29 bf 2b 94 81 ca 72 9e a4 67 56 70 02 37 72 9e 5c a1 13 77 a4 5f ce 93 ce b4 dd 0d f1 51 ce | E).+...r..gVp.7r.\..w._.......Q. |
01a0 | 93 6b bc 55 3c d7 72 9e bc 2a d7 c2 27 83 b2 2e e7 c9 cb b8 3e 87 4f 6e 0e 4e 60 22 7c f2 53 c1 | .k.U<.r..*..'.......>.On.N`"|.S. |
01c0 | c9 18 aa 1d ad dc 80 52 50 55 7e 03 95 ff 67 04 b7 43 ad d1 77 8f ec 6a 2d f4 02 70 d2 ce ef b8 | .......RPU~...g..C..w..j-..p.... |
01e0 | 1a 76 27 7f bb f3 e4 0a 70 02 97 3a 4f 66 68 88 9b 3b 4f 66 f0 56 f1 5c cb 79 f2 aa 5c 0b 9c 8c | .v'.....p..:Ofh..;Of.V.\.y..\... |
0200 | cb bd 9c 27 af e1 fa f6 91 5d f0 43 9c 27 13 81 93 61 74 74 22 47 68 1f 69 62 a3 98 87 59 83 73 | ...'.....].C.'...att"Gh.ib...Y.s |
0220 | 40 65 5a e7 c9 bc e0 a4 95 dc 47 3b 4f de 18 d9 d5 c9 fd 0f 8f ec 82 f9 9c 27 f3 44 76 1d 64 77 | @eZ.......G;O............'.Dv.dw |
0240 | 42 e7 c9 02 27 f7 e2 6b 81 93 ab d8 44 85 2f e7 c9 61 22 cb 79 32 9a 9d 97 c8 a4 73 a9 3c dc ca | B...'..k....D./..a".y2.....s.<.. |
0260 | 4a 31 e1 51 d9 14 d3 0f 54 a6 05 27 ed 75 fb 19 db e2 1b 4b 5f db e2 87 73 3f 4f 64 57 7b f2 b5 | J1.Q....T..'.u.....K_...s?OdW{.. |
0280 | 2d 7e 14 0b 3f 04 9c 1c e5 e4 06 7a fc c2 27 63 b2 ae c8 ae 97 31 7e 7b e7 c9 02 27 c3 d9 19 b6 | -~..?......z..'c.....1~{...'.... |
02a0 | 9d bd 89 4e 5b 84 cd b9 56 a6 95 09 68 b8 55 4b 6f 06 2a 6b 5b fc 81 42 97 f3 64 58 e2 b5 2d be | ...N[...V...h.UKo.*k[..B..dX..-. |
02c0 | 3f ed 47 45 76 75 a7 9f 0b 9c c0 72 9e 9c c9 b5 c0 c9 b8 dc 9f e5 3c 79 1f 38 81 0f 77 9e 4c 03 | ?.GEvu.....r..........<y.8..w.L. |
02e0 | 4e e0 07 e2 93 3e 22 95 32 07 e0 93 9d 50 d0 86 5b 0b c7 2e 50 f9 10 e7 c9 02 27 e7 d3 2e e7 c9 | N....>".2....P..[...P.....'..... |
0300 | f3 79 bf f3 e4 ee 91 5d bd 2c bc 5d e0 4a ae e5 3c 79 55 ae 85 4f 06 65 5d ce 93 97 71 fd d1 e0 | .y.....].,.].J..<yU..O.e]...q... |
0320 | 04 26 c2 27 1f 0e 4e 2a 85 0f 03 27 df cf 13 9f 9c da 15 a3 01 95 81 0a df b4 e0 a4 b1 fe ad 85 | .&.'..N*...'.................... |
0340 | be 2f b2 6b 68 0d bb 93 bf dd 79 b2 b6 c5 77 c9 61 4f 7c 73 e7 c9 0c de 2a 9e 6b 39 4f 5e 95 6b | ./.kh.....y...w.aO|s....*.k9O^.k |
0360 | 81 93 71 b9 97 f3 e4 35 5c df 3e b2 0b 7e 88/*
* Copyright (c) 2018 TOYOTA MOTOR CORPORATION
* Copyright (C) 2020 Konsulko Group
*
* 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 <cstring>
#include <algorithm>
#include "hs-clientmanager.h"
static const char _homescreen[] = "homescreen";
HS_ClientManager* HS_ClientManager::me = nullptr;
static void cbRemoveClientCtxt(void *data)
{
HS_ClientManager::instance()->removeClientCtxt(data);
}
/**
* HS_ClientManager construction function
*
* #### Parameters
* - Nothing
*
* #### Return
* None
*
*/
HS_ClientManager::HS_ClientManager()
{
}
/**
* get instance
*
* #### Parameters
* - Nothing
*
* #### Return
* HS_ClientManager instance pointer
*
*/
HS_ClientManager* HS_ClientManager::instance(void)
{
if(me == nullptr)
me = new HS_ClientManager();
return me;
}
/**
* HS_ClientManager init function
*
* #### Parameters
* - Nothing
*
* #### Return
* init result
*
*/
int HS_ClientManager::init(void)
{
return 0;
}
/**
* create client's afb_req_context
*
* #### Parameters
* - appid: app's id
*
* #### Return
* HS_ClientCtxt pointer
*
*/
HS_ClientCtxt* HS_ClientManager::createClientCtxt(afb_req_t req, std::string appid)
{
HS_ClientCtxt *ctxt = (HS_ClientCtxt *)afb_req_context_get(req);
if (!ctxt)
{
AFB_INFO( "create new session for %s", appid.c_str());
ctxt = new HS_ClientCtxt(appid);
afb_req_session_set_LOA(req, 1);
afb_req_context_set(req, ctxt, cbRemoveClientCtxt);
}
appid2ctxt[appid] = ctxt;
return ctxt;
}
/**
* add Client
*
* #### Parameters
* - ctxt: app's id
*
* #### Return
* HS_Client pointer
*
*/
HS_Client* HS_ClientManager::addClient(afb_req_t req, std::string appid)
{
return (client_list[appid] = new HS_Client(req, appid));
}
/**
* remove Client
*
* #### Parameters
* - appid: app's id
*
* #### Return
* None
*
*/
void HS_ClientManager::removeClient(std::string appid)
{
delete client_list[appid];
client_list.erase(appid);
}
/**
* remove Client from list
*
* #### Parameters
* - data: HS_ClientCtxt pointer
*
* #### Return
* None
*
*/
void HS_ClientManager::removeClientCtxt(void *data)
{
HS_ClientCtxt *ctxt = (HS_ClientCtxt *)data;
if(ctxt == nullptr)
{
AFB_WARNING( "data is nullptr");
return;
}
AFB_INFO( "remove app %s", ctxt->id.c_str());
std::lock_guard<std::mutex> lock(this->mtx);
removeClient(ctxt->id);
delete appid2ctxt[ctxt->id];
appid2ctxt.erase(ctxt->id);
}
/**
* 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()) {
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;
}
|