X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fhs-clientmanager.h;h=9e58e641ca2d5c7bc84c2ef094f6451ce6d5b48d;hb=405a974acd1c2c19ae6e549e5c88aac2c1cb3ea5;hp=d485ea86d220368d74c69edbe7fa7742cba10c9d;hpb=53ae85dc62875fc92f1d24e25359beda8787826d;p=apps%2Fagl-service-homescreen.git diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h index d485ea8..9e58e64 100644 --- a/src/hs-clientmanager.h +++ b/src/hs-clientmanager.h @@ -21,9 +21,31 @@ #include #include #include +#include +#include #include "hs-helper.h" #include "hs-client.h" + +class listener_interface { +public: + listener_interface(std::string uid, std::set listen_appid = std::set()) : m_uid(uid), m_listen_appid(listen_appid) {} + virtual ~listener_interface() {} + virtual void notify(afb_api_t api, std::string appid = "") = 0; + std::string myUid(void) {return m_uid;} + void addListenAppId(const std::string &appid) {m_listen_appid.insert(appid);} + void removeListenAppId(const std::string &appid) {m_listen_appid.erase(appid);} + bool isListenAppId(const std::string &appid) { + auto it = m_listen_appid.find(appid); + return it != m_listen_appid.end() ? true : false; + } + bool listenAppEmpty(void) {return m_listen_appid.empty();} + void clearListenAppSet(void) {m_listen_appid.clear();} +private: + std::string m_uid; + std::set m_listen_appid; +}; + typedef struct HS_ClientCtxt { std::string id; @@ -46,18 +68,26 @@ public: static HS_ClientManager* instance(void); int init(void); 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 + void setStartupAppidAndArea(const std::pair pair) {startup_appid = pair.first;startup_area = pair.second;} + bool isAppStarted(const std::string &appid); + void addListener(listener_interface* listener); + void removeListener(listener_interface* listener); private: HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid); HS_Client* addClient(afb_req_t req, std::string appid); void removeClient(std::string appid); + void notifyListener(afb_api_t api, const std::string &appid); private: static HS_ClientManager* me; + std::unordered_map listener_list; std::unordered_map client_list; std::unordered_map appid2ctxt; std::mutex mtx; + std::string startup_appid, startup_area; }; #endif // HOMESCREEN_CLIENTMANAGER_H \ No newline at end of file