bus-slot.c revision cf0fbc49e67b55f8d346fc94de28c90113505297
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering/***
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering This file is part of systemd.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering Copyright 2013 Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering (at your option) any later version.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering systemd is distributed in the hope that it will be useful, but
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering Lesser General Public License for more details.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering***/
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering#include "sd-bus.h"
4871690d9e32608bbd9b18505b5326c2079c9690Allin Cottrell
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering#include "alloc-util.h"
c79e98eadd3056a36a662699fa650db5b1bca0c3Lennart Poettering#include "bus-control.h"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering#include "bus-objects.h"
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering#include "bus-slot.h"
1dfa7e79a60de680086b1d93fcc3629b463f58bdLennart Poettering#include "string-util.h"
d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmeksd_bus_slot *bus_slot_allocate(
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering sd_bus *bus,
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bool floating,
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering BusSlotType type,
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering size_t extra,
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen void *userdata) {
a09abc4ae0bdc0200324eaa0416f23ff2170ec4eLennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering sd_bus_slot *slot;
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert(bus);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot = malloc0(offsetof(sd_bus_slot, reply_callback) + extra);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (!slot)
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return NULL;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->n_ref = 1;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->type = type;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus = bus;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->floating = floating;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->userdata = userdata;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (!floating)
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering sd_bus_ref(bus);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LIST_PREPEND(slots, bus->slots, slot);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek return slot;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ sd_bus_slot* sd_bus_slot_ref(sd_bus_slot *slot) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert(slot->n_ref > 0);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->n_ref++;
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek return slot;
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek}
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poetteringvoid bus_slot_disconnect(sd_bus_slot *slot) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering sd_bus *bus;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert(slot);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering if (!slot->bus)
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek return;
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek switch (slot->type) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case BUS_REPLY_CALLBACK:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering if (slot->reply_callback.cookie != 0)
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering ordered_hashmap_remove(slot->bus->reply_callbacks, &slot->reply_callback.cookie);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->reply_callback.timeout != 0)
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering prioq_remove(slot->bus->reply_callbacks_prioq, &slot->reply_callback, &slot->reply_callback.prioq_idx);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case BUS_FILTER_CALLBACK:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus->filter_callbacks_modified = true;
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek LIST_REMOVE(callbacks, slot->bus->filter_callbacks, &slot->filter_callback);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case BUS_MATCH_CALLBACK:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->match_added)
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus_remove_match_internal(slot->bus, slot->match_callback.match_string, slot->match_callback.cookie);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus->match_callbacks_modified = true;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus_match_remove(&slot->bus->match_callbacks, &slot->match_callback);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering free(slot->match_callback.match_string);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case BUS_NODE_CALLBACK:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->node_callback.node) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LIST_REMOVE(callbacks, slot->node_callback.node->callbacks, &slot->node_callback);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus->nodes_modified = true;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek bus_node_gc(slot->bus, slot->node_callback.node);
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek }
8c0b803b97bb0ee6603d9be85fb6b69cd6081eafLennart Poettering
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek break;
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek case BUS_NODE_ENUMERATOR:
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->node_enumerator.node) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LIST_REMOVE(enumerators, slot->node_enumerator.node->enumerators, &slot->node_enumerator);
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek slot->bus->nodes_modified = true;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus_node_gc(slot->bus, slot->node_enumerator.node);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case BUS_NODE_OBJECT_MANAGER:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->node_object_manager.node) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LIST_REMOVE(object_managers, slot->node_object_manager.node->object_managers, &slot->node_object_manager);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus->nodes_modified = true;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus_node_gc(slot->bus, slot->node_object_manager.node);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
12a717f8347f3daf0ae46a2b71c7d011d9c12feaZbigniew Jędrzejewski-Szmek
92ee6447b1deef7c79962a8121fdf8e58acb3a83Zbigniew Jędrzejewski-Szmek case BUS_NODE_VTABLE:
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek if (slot->node_vtable.node && slot->node_vtable.interface && slot->node_vtable.vtable) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering const sd_bus_vtable *v;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering for (v = slot->node_vtable.vtable; v->type != _SD_BUS_VTABLE_END; v++) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering struct vtable_member *x = NULL;
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering switch (v->type) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case _SD_BUS_VTABLE_METHOD: {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering struct vtable_member key;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering key.path = slot->node_vtable.node->path;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering key.interface = slot->node_vtable.interface;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering key.member = v->x.method.member;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering x = hashmap_remove(slot->bus->vtable_methods, &key);
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek break;
a174f94d529c7ae9be589867308b669ec9b4dcc0Lennart Poettering }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case _SD_BUS_VTABLE_PROPERTY:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering case _SD_BUS_VTABLE_WRITABLE_PROPERTY: {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering struct vtable_member key;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden key.path = slot->node_vtable.node->path;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering key.interface = slot->node_vtable.interface;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering key.member = v->x.method.member;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden x = hashmap_remove(slot->bus->vtable_properties, &key);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering }}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering free(x);
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering free(slot->node_vtable.interface);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->node_vtable.node) {
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden LIST_REMOVE(vtables, slot->node_vtable.node->vtables, &slot->node_vtable);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus->nodes_modified = true;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus_node_gc(slot->bus, slot->node_vtable.node);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering break;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
1f6b411372076426c0faf0bb350437fb4d82931fLennart Poettering default:
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_not_reached("Wut? Unknown slot type?");
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus = slot->bus;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->type = _BUS_SLOT_INVALID;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->bus = NULL;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering LIST_REMOVE(slots, bus->slots, slot);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
1f6b411372076426c0faf0bb350437fb4d82931fLennart Poettering if (!slot->floating)
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek sd_bus_unref(bus);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek}
2a0e0692565f0435657c93498e09cbb2d3517152Shawn Landden
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek_public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek if (!slot)
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek return NULL;
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek assert(slot->n_ref > 0);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->n_ref > 1) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->n_ref --;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return NULL;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering }
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering bus_slot_disconnect(slot);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering free(slot->description);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering free(slot);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return NULL;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return slot->bus;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ void *sd_bus_slot_get_userdata(sd_bus_slot *slot) {
505b6a61c22d5565e9308045c7b9bf79f7d0517eLennart Poettering assert_return(slot, NULL);
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek
505b6a61c22d5565e9308045c7b9bf79f7d0517eLennart Poettering return slot->userdata;
505b6a61c22d5565e9308045c7b9bf79f7d0517eLennart Poettering}
505b6a61c22d5565e9308045c7b9bf79f7d0517eLennart Poettering
505b6a61c22d5565e9308045c7b9bf79f7d0517eLennart Poettering_public_ void *sd_bus_slot_set_userdata(sd_bus_slot *slot, void *userdata) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering void *ret;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering ret = slot->userdata;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering slot->userdata = userdata;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return ret;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot->type >= 0, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->bus->current_slot != slot)
d18d46ecea80a7f07415edb9264af6a254fd70bbZbigniew Jędrzejewski-Szmek return NULL;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return slot->bus->current_message;
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek}
a174f94d529c7ae9be589867308b669ec9b4dcc0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ sd_bus_message_handler_t sd_bus_slot_get_current_handler(sd_bus_slot *slot) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot->type >= 0, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering if (slot->bus->current_slot != slot)
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return NULL;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return slot->bus->current_handler;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ void* sd_bus_slot_get_current_userdata(sd_bus_slot *slot) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, NULL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot->type >= 0, NULL);
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek if (slot->bus->current_slot != slot)
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek return NULL;
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek return slot->bus->current_userdata;
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek}
874bc134ac6504c45e94174e37af13ff21a6bfe2Zbigniew Jędrzejewski-Szmek
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ int sd_bus_slot_set_description(sd_bus_slot *slot, const char *description) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, -EINVAL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering return free_and_strdup(&slot->description, description);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering_public_ int sd_bus_slot_get_description(sd_bus_slot *slot, const char **description) {
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot, -EINVAL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(description, -EINVAL);
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering assert_return(slot->description, -ENXIO);
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen *description = slot->description;
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen return 0;
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering}
0153028ae379eb7c9a463c548ef73ea392c6cdb0Lennart Poettering