You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/07/24 09:00:32 UTC

[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1230: system/uorb: support uorb, include uorb wraper, unit test, uorb_listener, topic definition

xiaoxiang781216 commented on code in PR #1230:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1230#discussion_r928222373


##########
system/uorb/uORB/uORB.c:
##########
@@ -90,18 +89,16 @@ static int orb_open(FAR const struct orb_metadata *meta, bool advertiser,
           return ret;
         }
 
-      first_open = true;
-    }
-
-  fd = open(path, O_CLOEXEC | (advertiser ? O_WRONLY : O_RDONLY));
-  if (fd < 0)
-    {
-      return fd;
-    }
+      fd = open(path, flags);
+      if (fd < 0)
+        {
+          return fd;
+        }
 
-  if (first_open)
-    {
-      ioctl(fd, SNIOC_SET_USERPRIV, (unsigned long)(uintptr_t)meta);
+      if (ret != -EEXIST)

Review Comment:
   use errno instead



##########
system/uorb/uORB/uORB.c:
##########
@@ -0,0 +1,314 @@
+/****************************************************************************
+ * apps/system/uorb/uORB/uORB.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <poll.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include <uORB/uORB.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: orb_open
+ *
+ * Description:
+ *   Open device node as advertiser / subscriber, regist node and save meta
+ *   in driver for first user, set buffer number for advertisers.
+ *
+ * Input Parameters:
+ *   meta         The uORB metadata (usually from the ORB_ID() macro)
+ *   advertiser   Whether advertiser or subscriber.
+ *   instance     Instance number to open.
+ *   queue_size   Maximum number of buffered elements.
+ *
+ * Returned Value:
+ *   fd on success, otherwise returns negative value and set errno.
+ ****************************************************************************/
+
+static int orb_open(FAR const struct orb_metadata *meta, bool advertiser,
+                    int instance, unsigned int queue_size)
+{
+  char path[PATH_MAX];
+  bool first_open = false;
+  int fd;
+  int ret;
+
+  snprintf(path, PATH_MAX, ORB_SENSOR_PATH"%s%d", meta->o_name, instance);
+
+  /* Check existance before open */
+
+  ret = access(path, F_OK);
+  if (ret < 0)
+    {
+      struct sensor_reginfo_s reginfo;
+
+      reginfo.path    = path;
+      reginfo.esize   = meta->o_size;
+      reginfo.nbuffer = queue_size;
+
+      fd = open(ORB_USENSOR_PATH, O_WRONLY);
+      if (fd < 0)
+        {
+          return fd;
+        }
+
+      /* Register new device node */
+
+      ret = ioctl(fd, SNIOC_REGISTER, (unsigned long)(uintptr_t)&reginfo);
+      close(fd);
+      if (ret < 0 && ret != -EEXIST)

Review Comment:
   check errno instead



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org