#define HOMESCREEN_CLIENTMANAGER_H
#include <string>
-#include <vector>
#include <mutex>
#include <memory>
#include <unordered_map>
+#include <list>
+#include <set>
#include "hs-helper.h"
#include "hs-client.h"
+
+class listener_interface {
+public:
+ listener_interface(std::string uid, std::set<std::string> listen_appid = std::set<std::string>()) : 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<std::string> m_listen_appid;
+};
+
typedef struct HS_ClientCtxt
{
std::string id;
static HS_ClientManager* instance(void);
int init(void);
- HS_Client* find(std::string appid);
- HS_Client* getClient(afb_req req, std::string appid);
- std::vector<HS_Client*> getAllClient(void);
- void removeClientCtxt(void *data);
+ 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<std::string, std::string> 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 req, std::string appid);
- HS_Client* addClient(afb_req req, std::string appid);
+ 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<std::string, listener_interface*> listener_list;
std::unordered_map<std::string, HS_Client*> client_list;
std::unordered_map<std::string, HS_ClientCtxt*> appid2ctxt;
std::mutex mtx;
+ std::string startup_appid, startup_area;
};
#endif // HOMESCREEN_CLIENTMANAGER_H
\ No newline at end of file