aboutsummaryrefslogtreecommitdiffstats
path: root/src/hs-clientmanager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hs-clientmanager.h')
-rw-r--r--src/hs-clientmanager.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h
index 366f256..c8bc48e 100644
--- a/src/hs-clientmanager.h
+++ b/src/hs-clientmanager.h
@@ -21,9 +21,32 @@
#include <mutex>
#include <memory>
#include <unordered_map>
+#include <list>
+#include <set>
#include "hs-helper.h"
#include "hs-client.h"
+extern const std::string _listen_all;
+
+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;}
+ std::set<std::string> listenAppSet(void) {return m_listen_appid;}
+ void addListenAppId(std::string appid) {m_listen_appid.insert(appid);}
+ bool isListenAppId(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;
@@ -49,15 +72,20 @@ public:
int pushEvent(const char *event, struct json_object *param, std::string appid = "");
void removeClientCtxt(void *data); // don't use, internal only
void setStartupAppid(const std::string &appid) {startup_appid = appid;}
+ 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 checkRegisterApp(afb_api_t api, const std::string &appid);
+ bool checkRegisterApp(afb_api_t api, const std::string &appid);
+ void notifyListener(afb_api_t api, const std::string &appid);
private:
static HS_ClientManager* me;
+ std::unordered_map<std::string, std::list<listener_interface*>> listener_list;
std::unordered_map<std::string, HS_Client*> client_list;
std::unordered_map<std::string, HS_ClientCtxt*> appid2ctxt;
std::mutex mtx;