bus-slot.c revision 9cbfc66c621c42aa6e58e9e0da0adfb01efa7537
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen/***
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen This file is part of systemd.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Copyright 2013 Lennart Poettering
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen systemd is free software; you can redistribute it and/or modify it
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen under the terms of the GNU Lesser General Public License as published by
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen (at your option) any later version.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen systemd is distributed in the hope that it will be useful, but
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Lesser General Public License for more details.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen You should have received a copy of the GNU Lesser General Public License
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen***/
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "sd-bus.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "bus-control.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "bus-objects.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "bus-slot.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringsd_bus_slot *bus_slot_allocate(
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering sd_bus *bus,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering bool floating,
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen BusSlotType type,
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen size_t extra,
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen void *userdata) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering sd_bus_slot *slot;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert(bus);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot = malloc0(offsetof(sd_bus_slot, reply_callback) + extra);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (!slot)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->n_ref = 1;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->type = type;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus = bus;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->floating = floating;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->userdata = userdata;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (!floating)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus_ref(bus);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_PREPEND(slots, bus->slots, slot);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ sd_bus_slot* sd_bus_slot_ref(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert(slot->n_ref > 0);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->n_ref++;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenvoid bus_slot_disconnect(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus *bus;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert(slot);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (!slot->bus)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen switch (slot->type) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_REPLY_CALLBACK:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->reply_callback.cookie != 0)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen ordered_hashmap_remove(slot->bus->reply_callbacks, &slot->reply_callback.cookie);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->reply_callback.timeout != 0)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen prioq_remove(slot->bus->reply_callbacks_prioq, &slot->reply_callback, &slot->reply_callback.prioq_idx);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_FILTER_CALLBACK:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus->filter_callbacks_modified = true;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_REMOVE(callbacks, slot->bus->filter_callbacks, &slot->filter_callback);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_MATCH_CALLBACK:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->bus->bus_client)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_remove_match_internal(slot->bus, slot->match_callback.match_string, slot->match_callback.cookie);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus->match_callbacks_modified = true;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_match_remove(&slot->bus->match_callbacks, &slot->match_callback);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen free(slot->match_callback.match_string);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_NODE_CALLBACK:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->node_callback.node) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_REMOVE(callbacks, slot->node_callback.node->callbacks, &slot->node_callback);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus->nodes_modified = true;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_node_gc(slot->bus, slot->node_callback.node);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_NODE_ENUMERATOR:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->node_enumerator.node) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_REMOVE(enumerators, slot->node_enumerator.node->enumerators, &slot->node_enumerator);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus->nodes_modified = true;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_node_gc(slot->bus, slot->node_enumerator.node);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_NODE_OBJECT_MANAGER:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->node_object_manager.node) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_REMOVE(object_managers, slot->node_object_manager.node->object_managers, &slot->node_object_manager);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus->nodes_modified = true;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_node_gc(slot->bus, slot->node_object_manager.node);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case BUS_NODE_VTABLE:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->node_vtable.node && slot->node_vtable.interface && slot->node_vtable.vtable) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen const sd_bus_vtable *v;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen for (v = slot->node_vtable.vtable; v->type != _SD_BUS_VTABLE_END; v++) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen struct vtable_member *x = NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen switch (v->type) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case _SD_BUS_VTABLE_METHOD: {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen struct vtable_member key;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen key.path = slot->node_vtable.node->path;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen key.interface = slot->node_vtable.interface;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen key.member = v->x.method.member;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen x = hashmap_remove(slot->bus->vtable_methods, &key);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case _SD_BUS_VTABLE_PROPERTY:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen case _SD_BUS_VTABLE_WRITABLE_PROPERTY: {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen struct vtable_member key;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen key.path = slot->node_vtable.node->path;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen key.interface = slot->node_vtable.interface;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen key.member = v->x.method.member;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen x = hashmap_remove(slot->bus->vtable_properties, &key);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen free(x);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen free(slot->node_vtable.interface);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->node_vtable.node) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_REMOVE(vtables, slot->node_vtable.node->vtables, &slot->node_vtable);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus->nodes_modified = true;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_node_gc(slot->bus, slot->node_vtable.node);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
2237aa02f3e2739a1ebe9c0bc224b5125f5eb292David Herrmann break;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen default:
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_not_reached("Wut? Unknown slot type?");
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus = slot->bus;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->type = _BUS_SLOT_INVALID;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->bus = NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen LIST_REMOVE(slots, bus->slots, slot);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (!slot->floating)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus_unref(bus);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (!slot)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert(slot->n_ref > 0);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->n_ref > 1) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->n_ref --;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen }
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen bus_slot_disconnect(slot);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen free(slot->description);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen free(slot);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot->bus;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ void *sd_bus_slot_get_userdata(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot->userdata;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ void *sd_bus_slot_set_userdata(sd_bus_slot *slot, void *userdata) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen void *ret;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen ret = slot->userdata;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen slot->userdata = userdata;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return ret;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot->type >= 0, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->bus->current_slot != slot)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot->bus->current_message;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ sd_bus_message_handler_t sd_bus_slot_get_current_handler(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot->type >= 0, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->bus->current_slot != slot)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot->bus->current_handler;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ void* sd_bus_slot_get_current_userdata(sd_bus_slot *slot) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot->type >= 0, NULL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (slot->bus->current_slot != slot)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return NULL;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return slot->bus->current_userdata;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ int sd_bus_slot_set_description(sd_bus_slot *slot, const char *description) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, -EINVAL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return free_and_strdup(&slot->description, description);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen_public_ int sd_bus_slot_get_description(sd_bus_slot *slot, char **description) {
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot, -EINVAL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(description, -EINVAL);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen assert_return(slot->description, -ENXIO);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen *description = slot->description;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return 0;
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen}
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen