diff options
author | Adriana Kobylak <anoo@us.ibm.com> | 2017-05-04 15:45:19 -0500 |
---|---|---|
committer | Adriana Kobylak <anoo@us.ibm.com> | 2017-05-15 12:23:08 -0500 |
commit | 78edbb6fed9c546d2fb6b085b3af9cd6fa1562f6 (patch) | |
tree | 39a0168326064c802798a27c5a92b7856fd41f92 | |
parent | 2a8bfc96a93e54bcbc0f6c6114f0a9504297c53d (diff) | |
download | phosphor-objmgr-78edbb6fed9c546d2fb6b085b3af9cd6fa1562f6.tar.gz phosphor-objmgr-78edbb6fed9c546d2fb6b085b3af9cd6fa1562f6.zip |
libmapper: Add match for removed interfaces
Add a match to look for removed interfaces.
Change-Id: If5bd68254b88c664c33f443ea593974b87996b42
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
-rw-r--r-- | libmapper/mapper.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libmapper/mapper.c b/libmapper/mapper.c index 194041e..56fa5b8 100644 --- a/libmapper/mapper.c +++ b/libmapper/mapper.c @@ -35,6 +35,11 @@ static const char *async_wait_interfaces_added_match = "interface='org.freedesktop.DBus.ObjectManager'," "member='InterfacesAdded'"; +static const char *interfaces_removed_match = + "type='signal'," + "interface='org.freedesktop.DBus.ObjectManager'," + "member='InterfacesRemoved'"; + static const int mapper_busy_retries = 5; static const uint64_t mapper_busy_delay_interval_usec = 1000000; @@ -63,6 +68,14 @@ struct async_wait_callback_data struct mapper_async_subtree { + char *namespace; + char *interface; + void (*callback)(int, void *); + void *userdata; + sd_event *loop; + sd_bus *conn; + sd_bus_slot *slot; + int op; }; static int async_wait_match_introspection_complete(sd_bus_message *, void *, @@ -73,6 +86,9 @@ static int async_wait_get_objects(mapper_async_wait *); static int async_wait_getobject_callback(sd_bus_message *, void *, sd_bus_error *); +static int async_subtree_match_callback(sd_bus_message *, void *, + sd_bus_error *); + static int sarraylen(char *array[]) { int count = 0; @@ -378,6 +394,13 @@ free_wait: return r; } +static int async_subtree_match_callback(sd_bus_message *m, + void *t, + sd_bus_error *e) +{ + return 0; +} + int mapper_subtree_async(sd_bus *conn, sd_event *loop, char *namespace, @@ -388,6 +411,47 @@ int mapper_subtree_async(sd_bus *conn, int op) { int r = 0; + mapper_async_subtree *subtree = NULL; + + subtree = malloc(sizeof(*subtree)); + if(!subtree) + return -ENOMEM; + + memset(subtree, 0, sizeof(*subtree)); + subtree->conn = conn; + subtree->loop = loop; + subtree->namespace = namespace; + subtree->interface = interface; + subtree->callback = callback; + subtree->userdata = userdata; + subtree->op = op; + + if (subtree->op == MAPPER_OP_REMOVE) { + r = sd_bus_add_match( + conn, + &subtree->slot, + interfaces_removed_match, + async_subtree_match_callback, + subtree); + if(r < 0) { + fprintf(stderr, "Error adding match rule: %s\n", + strerror(-r)); + goto unref_slot; + } + } else { + /* Operation not supported */ + r = -EINVAL; + goto free_subtree; + } + + *t = subtree; + + return 0; + +unref_slot: + sd_bus_slot_unref(subtree->slot); +free_subtree: + free(subtree); return r; } |