Improvement:a client instance only call afb_req_subscribe once 35/18135/3
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 21 Nov 2018 08:02:53 +0000 (16:02 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Fri, 23 Nov 2018 02:10:34 +0000 (10:10 +0800)
when call subscribe every time, hs_client instance will call afb_req_subscribe once,
this is needless, every hs_client always only has one event, so only need to call afb_req_subscribe once.

Change-Id: I91417b749201fc378287e03f08dfd4dfd5df9dc7
Signed-off-by: wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
src/hs-client.cpp
src/hs-client.h

index 26e43bb..536ff6e 100644 (file)
@@ -142,7 +142,12 @@ int HS_Client::subscribe(afb_req_t request, const char* event)
     auto ip = event_list.find(std::string(event));
     if(ip == event_list.end()) {
         event_list[std::string(event)] = 0;
+    }
+    if(!subscription) {
         ret = afb_req_subscribe(request, my_event);
+        if(ret == 0) {
+            subscription = true;
+        }
     }
     return ret;
 }
index 16fa39c..b06a717 100644 (file)
@@ -47,6 +47,7 @@ private:
 private:
     std::string my_id;
     afb_event_t my_event;
+    bool subscription = false;
     std::unordered_map<std::string, int> event_list;
 
 };