test-bus-introspect.c revision 29ddb38fea134c6132e4f2dd608e9da3871eaebe
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
220a21d38f675eb835f5758e3d23e896573aa5eaLennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering/***
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering This file is part of systemd.
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering Copyright 2013 Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering systemd is free software; you can redistribute it and/or modify it
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering under the terms of the GNU Lesser General Public License as published by
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering (at your option) any later version.
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering systemd is distributed in the hope that it will be useful, but
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering Lesser General Public License for more details.
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering You should have received a copy of the GNU Lesser General Public License
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering***/
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering#include "util.h"
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering#include "log.h"
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering#include "bus-introspect.h"
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poetteringstatic int prop_get(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering return -EINVAL;
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering}
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poetteringstatic int prop_set(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata) {
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering return -EINVAL;
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering}
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poetteringstatic const sd_bus_vtable vtable[] = {
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering SD_BUS_VTABLE_START(0),
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering SD_BUS_METHOD("Hello", "ssas", "a(uu)", 0, NULL),
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering SD_BUS_METHOD("DeprecatedHello", "", "", SD_BUS_VTABLE_DEPRECATED, NULL),
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering SD_BUS_METHOD("DeprecatedHelloNoReply", "", "", SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_METHOD_NO_REPLY, NULL),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_SIGNAL("Wowza", "sss", 0),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_SIGNAL("DeprecatedWowza", "ut", SD_BUS_VTABLE_DEPRECATED),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_WRITABLE_PROPERTY("AProperty", "s", prop_get, prop_set, 0, 0),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_PROPERTY("AReadOnlyDeprecatedProperty", "(ut)", prop_get, 0, SD_BUS_VTABLE_DEPRECATED),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_PROPERTY("ChangingProperty", "t", prop_get, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_PROPERTY("Invalidating", "t", prop_get, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE|SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY),
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering SD_BUS_VTABLE_END
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering};
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poetteringint main(int argc, char *argv[]) {
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering struct introspect intro;
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering log_set_max_level(LOG_DEBUG);
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering assert_se(introspect_begin(&intro) >= 0);
597c52cfedb5edd13ee1635fa6be72fc80e587c3Lennart Poettering
075d4ecb4026c5bc55e73bd2d44e3fc4d679adc7Lennart Poettering assert_se(introspect_write_interface(&intro, "org.foo", vtable) >= 0);
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering fflush(intro.f);
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering fputs(intro.introspection, stdout);
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering introspect_free(&intro);
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering return 0;
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering}
b6a867398de9f75fb623a84db7c6181d26b0a8d5Lennart Poettering