uORB: Add API to check if a topic exists yet

This commit is contained in:
Lorenz Meier
2015-04-25 01:32:34 +02:00
parent f7f949f455
commit 28dfb8983a
2 changed files with 29 additions and 0 deletions
+20
View File
@@ -41,6 +41,7 @@
#include <drivers/device/device.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
@@ -1196,6 +1197,25 @@ node_open(Flavor f, const struct orb_metadata *meta, const void *data, bool adve
} // namespace
int
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 = node_mkpath(path, PUBSUB, meta, &inst);
if (ret != OK) {
errno = -ret;
return ERROR;
}
struct stat buffer;
return stat(path, &buffer);
}
orb_advert_t
orb_advertise(const struct orb_metadata *meta, const void *data)
{