Fix: only one subscription could be made 42/22142/3
authorRomain Forlot <romain.forlot@iot.bzh>
Mon, 12 Aug 2019 15:58:50 +0000 (17:58 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Tue, 13 Aug 2019 12:15:21 +0000 (12:15 +0000)
Only one subscription could be made and then only one subscriber
could receive associated events. As the relationship between events
and subscriber is not 1-1 but 1-N, so this was the mistake. Now 1 event
is created for N subscriber where before there was 1 event for 1
subscriber and subsequent subscribers could not receive same events
than the ones already subscribed.

Bug-AGL: SPEC-2726

Change-Id: I4e4a80ac9f9b6b4c6b006108ee55f355a7c1e377
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
low-can-binding/binding/low-can-cb.cpp
low-can-binding/binding/low-can-subscription.cpp

index 5fdd961..2b63084 100644 (file)
@@ -151,8 +151,7 @@ static int subscribe_unsubscribe_signal(afb_req_t request,
                }
 
                // Event doesn't exist , so let's create it
-               if (! subscription_exists &&
-                   (ret = can_subscription->subscribe(request)) < 0)
+               if ((ret = can_subscription->subscribe(request)) < 0)
                        return ret;
 
                if(! subscription_exists)
index bb48888..736e034 100644 (file)
@@ -95,8 +95,13 @@ int low_can_subscription_t::set_event()
  */
 int low_can_subscription_t::subscribe(afb_req_t request)
 {
-       if(set_event() < 0)
-               return -1;
+       if(! afb_event_is_valid(event_))
+       {
+               if(set_event() < 0)
+               {
+                       return -1;
+               }
+       }
        return afb_req_subscribe(request, event_);
 }