Esempio n. 1
0
int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
{
	/*
	 * Generate the path to the node and try to open it.
	 */
	char path[orb_maxpath];
	int inst = instance;
	int ret = uORB::Utils::node_mkpath(path, meta, &inst);

	if (ret != OK) {
		errno = -ret;
		return PX4_ERROR;
	}

#if defined(__PX4_NUTTX)
	struct stat buffer;
	ret = stat(path, &buffer);
#else
	ret = px4_access(path, F_OK);

#ifdef ORB_COMMUNICATOR

	if (ret == -1 && meta != nullptr && !_remote_topics.empty()) {
		ret = (_remote_topics.find(meta->o_name) != _remote_topics.end()) ? OK : PX4_ERROR;
	}

#endif /* ORB_COMMUNICATOR */

#endif

	if (ret == 0) {
		// we know the topic exists, but it's not necessarily advertised/published yet (for example
		// if there is only a subscriber)
		// The open() will not lead to memory allocations.
		int fd = px4_open(path, 0);

		if (fd >= 0) {
			unsigned long is_published;

			if (px4_ioctl(fd, ORBIOCISPUBLISHED, (unsigned long)&is_published) == 0) {
				if (!is_published) {
					ret = PX4_ERROR;
				}
			}

			px4_close(fd);
		}
	}

	return ret;
}
Esempio n. 2
0
int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
{
  /*
   * Generate the path to the node and try to open it.
   */
  char path[orb_maxpath];
  int inst = instance;
  int ret = uORB::Utils::node_mkpath(path, PUBSUB, meta, &inst);

  if (ret != OK) {
    errno = -ret;
    return ERROR;
  }

  return px4_access(path, F_OK);
}