chiark / gitweb /
update TODO
[elogind.git] / src / libsystemd / sd-bus / bus-slot.c
index 8e38992ec4abc512e6c0a57bd4dc9591dbcf23ab..8060e9882cccd9429945eb1f62ce606abe7d2cb6 100644 (file)
@@ -67,16 +67,15 @@ void bus_slot_disconnect(sd_bus_slot *slot) {
 
         assert(slot);
 
-        switch (slot->type) {
-
-        case _BUS_SLOT_DISCONNECTED:
-                /* Already disconnected... */
+        if (!slot->bus)
                 return;
 
+        switch (slot->type) {
+
         case BUS_REPLY_CALLBACK:
 
                 if (slot->reply_callback.cookie != 0)
-                        hashmap_remove(slot->bus->reply_callbacks, &slot->reply_callback.cookie);
+                        ordered_hashmap_remove(slot->bus->reply_callbacks, &slot->reply_callback.cookie);
 
                 if (slot->reply_callback.timeout != 0)
                         prioq_remove(slot->bus->reply_callbacks_prioq, &slot->reply_callback, &slot->reply_callback.prioq_idx);
@@ -181,10 +180,14 @@ void bus_slot_disconnect(sd_bus_slot *slot) {
                 }
 
                 break;
+
+        default:
+                assert_not_reached("Wut? Unknown slot type?");
         }
+
         bus = slot->bus;
 
-        slot->type = _BUS_SLOT_DISCONNECTED;
+        slot->type = _BUS_SLOT_INVALID;
         slot->bus = NULL;
         LIST_REMOVE(slots, bus->slots, slot);
 
@@ -205,6 +208,7 @@ _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
         }
 
         bus_slot_disconnect(slot);
+        free(slot->description);
         free(slot);
 
         return NULL;
@@ -235,10 +239,45 @@ _public_ void *sd_bus_slot_set_userdata(sd_bus_slot *slot, void *userdata) {
 
 _public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) {
         assert_return(slot, NULL);
-        assert_return(slot->type != _BUS_SLOT_DISCONNECTED, NULL);
+        assert_return(slot->type >= 0, NULL);
 
         if (slot->bus->current_slot != slot)
                 return NULL;
 
         return slot->bus->current_message;
 }
+
+_public_ sd_bus_message_handler_t sd_bus_slot_get_current_handler(sd_bus_slot *slot) {
+        assert_return(slot, NULL);
+        assert_return(slot->type >= 0, NULL);
+
+        if (slot->bus->current_slot != slot)
+                return NULL;
+
+        return slot->bus->current_handler;
+}
+
+_public_ void* sd_bus_slot_get_current_userdata(sd_bus_slot *slot) {
+        assert_return(slot, NULL);
+        assert_return(slot->type >= 0, NULL);
+
+        if (slot->bus->current_slot != slot)
+                return NULL;
+
+        return slot->bus->current_userdata;
+}
+
+_public_ int sd_bus_slot_set_description(sd_bus_slot *slot, const char *description) {
+        assert_return(slot, -EINVAL);
+
+        return free_and_strdup(&slot->description, description);
+}
+
+_public_ int sd_bus_slot_get_description(sd_bus_slot *slot, char **description) {
+        assert_return(slot, -EINVAL);
+        assert_return(description, -EINVAL);
+        assert_return(slot->description, -ENXIO);
+
+        *description = slot->description;
+        return 0;
+}