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