summaryrefslogtreecommitdiffstats
path: root/libmapper
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2017-05-11 09:16:02 -0500
committerAdriana Kobylak <anoo@us.ibm.com>2017-05-11 09:16:02 -0500
commit2a8bfc96a93e54bcbc0f6c6114f0a9504297c53d (patch)
treef29adfec753707e48dab8f24b9b9c2dd5c420b26 /libmapper
parent6a8688f4f46df8c0c98f7571a072241eac4290af (diff)
downloadphosphor-objmgr-2a8bfc96a93e54bcbc0f6c6114f0a9504297c53d.tar.gz
phosphor-objmgr-2a8bfc96a93e54bcbc0f6c6114f0a9504297c53d.zip
Create libmapper subtree function and call it in event loop
Call a new mapper subtree interface in an event loop. Create an enum to specify the mapper action, in this case wait for an interface to be removed. This allows to later add other operations like wait for an interface to be added since the logic would be different. Change-Id: I8330852d47185c3c4e40e994c6e4719054a9fc06 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Diffstat (limited to 'libmapper')
-rw-r--r--libmapper/app.c43
-rw-r--r--libmapper/mapper.c18
-rw-r--r--libmapper/mapper.h8
3 files changed, 69 insertions, 0 deletions
diff --git a/libmapper/app.c b/libmapper/app.c
index 501a191..3bdd0c6 100644
--- a/libmapper/app.c
+++ b/libmapper/app.c
@@ -140,10 +140,14 @@ finish:
static int subtree_main(int argc, char *argv[])
{
int r = 0;
+ int op = 0;
static const char* token = ":";
char* tmp = NULL;
char* namespace = NULL;
char* interface = NULL;
+ sd_bus *conn = NULL;
+ sd_event *loop = NULL;
+ mapper_async_subtree *subtree = NULL;
if (argc != 3) {
fprintf(stderr, "Usage: %s subtree-remove "
@@ -151,6 +155,8 @@ static int subtree_main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ op = MAPPER_OP_REMOVE;
+
namespace = strtok_r(argv[2], token, &tmp);
interface = strtok_r(NULL, token, &tmp);
if ((namespace == NULL) || (interface == NULL)) {
@@ -158,6 +164,43 @@ static int subtree_main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ r = sd_bus_default_system(&conn);
+ if(r < 0) {
+ fprintf(stderr, "Error connecting to system bus: %s\n",
+ strerror(-r));
+ goto finish;
+ }
+
+ r = sd_event_default(&loop);
+ if (r < 0) {
+ fprintf(stderr, "Error obtaining event loop: %s\n",
+ strerror(-r));
+ goto finish;
+ }
+
+ r = sd_bus_attach_event(conn, loop, SD_EVENT_PRIORITY_NORMAL);
+ if (r < 0) {
+ fprintf(stderr, "Failed to attach system bus to event loop: %s\n",
+ strerror(-r));
+ goto finish;
+ }
+
+ r = mapper_subtree_async(conn, loop, namespace, interface, quit, loop,
+ &subtree, op);
+ if(r < 0) {
+ fprintf(stderr, "Error configuring subtree list: %s\n",
+ strerror(-r));
+ goto finish;
+ }
+
+ r = sd_event_loop(loop);
+ if(r < 0) {
+ fprintf(stderr, "Error starting event loop: %s\n",
+ strerror(-r));
+ goto finish;
+ }
+
+finish:
exit(r < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
diff --git a/libmapper/mapper.c b/libmapper/mapper.c
index 962b4e0..194041e 100644
--- a/libmapper/mapper.c
+++ b/libmapper/mapper.c
@@ -61,6 +61,10 @@ struct async_wait_callback_data
int retry;
};
+struct mapper_async_subtree
+{
+};
+
static int async_wait_match_introspection_complete(sd_bus_message *, void *,
sd_bus_error *);
static int async_wait_check_done(mapper_async_wait *);
@@ -374,6 +378,20 @@ free_wait:
return r;
}
+int mapper_subtree_async(sd_bus *conn,
+ sd_event *loop,
+ char *namespace,
+ char *interface,
+ void (*callback)(int, void *),
+ void *userdata,
+ mapper_async_subtree **t,
+ int op)
+{
+ int r = 0;
+
+ return r;
+}
+
int mapper_get_object(sd_bus *conn, const char *obj, sd_bus_message **reply)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
diff --git a/libmapper/mapper.h b/libmapper/mapper.h
index 7459e15..8fa5db6 100644
--- a/libmapper/mapper.h
+++ b/libmapper/mapper.h
@@ -4,11 +4,19 @@
#ifdef __cplusplus
extern "C" {
#endif
+typedef enum mapper_operation
+{
+ MAPPER_OP_REMOVE = 1
+} mapper_operation;
typedef struct mapper_async_wait mapper_async_wait;
+typedef struct mapper_async_subtree mapper_async_subtree;
void mapper_wait_async_free(mapper_async_wait *);
+void mapper_subtree_async_free(mapper_async_subtree *);
int mapper_wait_async(sd_bus *, sd_event *, char *[],
void (*)(int, void *), void *, mapper_async_wait **);
+int mapper_subtree_async(sd_bus *, sd_event *, char *, char *,
+ void (*)(int, void *), void *, mapper_async_subtree **, int);
int mapper_get_service(sd_bus *conn, const char *obj, char **service);
int mapper_get_object(sd_bus *conn, const char *obj, sd_bus_message **reply);
#ifdef __cplusplus
OpenPOWER on IntegriCloud