You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2022/07/23 19:58:19 UTC

[incubator-nuttx-apps] 16/20: app/system/uorb: fix listener run_once not work.

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 874ed7654d1590024c1730b2b672c6769041415f
Author: jihandong <ji...@xiaomi.com>
AuthorDate: Wed Jun 8 19:50:14 2022 +0800

    app/system/uorb: fix listener run_once not work.
    
    And remove dead code.
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 system/uorb/listener.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/system/uorb/listener.c b/system/uorb/listener.c
index eb115967d..284ecfa7f 100644
--- a/system/uorb/listener.c
+++ b/system/uorb/listener.c
@@ -173,6 +173,8 @@ static int listener_add_object(FAR struct list_node *objlist,
                                FAR struct orb_object *object)
 {
   FAR struct listen_object_s *tmp;
+  struct orb_state state;
+  int ret;
 
   tmp = malloc(sizeof(struct listen_object_s));
   if (tmp == NULL)
@@ -180,9 +182,17 @@ static int listener_add_object(FAR struct list_node *objlist,
       return -ENOMEM;
     }
 
+  ret = listener_get_state(object, &state);
+  if (ret < 0)
+    {
+      free(tmp);
+      return ret;
+    }
+
   tmp->object.meta     = object->meta;
   tmp->object.instance = object->instance;
-  tmp->timestamp       = 0;
+  tmp->timestamp       = orb_absolute_time();
+  tmp->generation      = state.generation;
   list_add_tail(objlist, &tmp->node);
   return 0;
 }
@@ -236,13 +246,6 @@ static int listener_update(FAR struct list_node *objlist,
           return ret;
         }
 
-      if (old->timestamp == 0)
-        {
-          old->timestamp  = orb_absolute_time();
-          old->generation = state.generation;
-          return 0;
-        }
-
       delta_time       = now_time - old->timestamp;
       delta_generation = state.generation - old->generation;
       if (delta_generation && delta_time)