dbus-common.h revision 23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye This file is part of systemd.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye Copyright 2010 Lennart Poettering
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye systemd is free software; you can redistribute it and/or modify it
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye under the terms of the GNU Lesser General Public License as published by
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye the Free Software Foundation; either version 2.1 of the License, or
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye (at your option) any later version.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye systemd is distributed in the hope that it will be useful, but
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye WITHOUT ANY WARRANTY; without even the implied warranty of
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye Lesser General Public License for more details.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye You should have received a copy of the GNU Lesser General Public License
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye along with systemd; If not, see <http://www.gnu.org/licenses/>.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <method name=\"Get\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </method>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <method name=\"GetAll\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </method>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <method name=\"Set\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </method>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <signal name=\"PropertiesChanged\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg type=\"s\" name=\"interface\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </signal>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </interface>\n"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <method name=\"Introspect\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </method>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </interface>\n"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <method name=\"Ping\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <method name=\"GetMachineId\">\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye " </method>\n" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye "</interface>\n"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye "org.freedesktop.DBus.Properties\0" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye "org.freedesktop.DBus.Introspectable\0" \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye "org.freedesktop.DBus.Peer\0"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbyeint bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
26eda24db2dc16f2cc45055efb39762fafd606deKnut Anders Hatlenint bus_connect_system_ssh(const char *user, const char *host, DBusConnection **_bus, DBusError *error);
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlenint bus_connect_system_polkit(DBusConnection **_bus, DBusError *error);
c7eb123c8b2081a261deff3c401fbf92ddba1b58Jorgen Austvikconst char *bus_error_message(const DBusError *error);
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvikconst char *bus_error_message_or_strerror(const DBusError *error, int err);
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Koscotypedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Koscotypedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property, void *data);
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Koscotypedef struct BusProperty {
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco const char *property; /* name of the property */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco BusPropertyCallback append; /* Function that is called to serialize this property */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco const uint16_t offset; /* Offset from BusBoundProperties::base address to the property data.
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco * uint16_t is sufficient, because we have no structs too big.
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco * -Werror=overflow will catch it if this does not hold. */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco bool indirect; /* data is indirect, ie. not base+offset, but *(base+offset) */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco BusPropertySetCallback set; /* Optional: Function that is called to set this property */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco const char *interface; /* interface of the properties */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco const BusProperty *properties; /* array of properties, ended by a NULL-filled element */
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco const void *const base; /* base pointer to which the offset must be added to reach data */
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvikdbus_bool_t bus_maybe_send_reply (DBusConnection *c,
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen AustvikDBusHandlerResult bus_default_message_handler(
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvikint bus_property_append_string(DBusMessageIter *i, const char *property, void *data);
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvikint bus_property_append_strv(DBusMessageIter *i, const char *property, void *data);
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Koscoint bus_property_append_bool(DBusMessageIter *i, const char *property, void *data);
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvikint bus_property_append_tristate_false(DBusMessageIter *i, const char *property, void *data);
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvikint bus_property_append_int32(DBusMessageIter *i, const char *property, void *data);
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvikint bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data);
1ed6b730409d4740e941142599767d5eac7e7d92Lubos Koscoint bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data);
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvikint bus_property_append_size(DBusMessageIter *i, const char *property, void *data);
1ed6b730409d4740e941142599767d5eac7e7d92Lubos Koscoint bus_property_append_ul(DBusMessageIter *i, const char *property, void *data);
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvikint bus_property_append_long(DBusMessageIter *i, const char *property, void *data);
1ed6b730409d4740e941142599767d5eac7e7d92Lubos Kosco#define bus_property_append_int bus_property_append_int32
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_append_pid bus_property_append_uint32
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_append_uid bus_property_append_uint32
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_append_gid bus_property_append_uint32
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_append_mode bus_property_append_uint32
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_append_unsigned bus_property_append_uint32
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_append_usec bus_property_append_uint64
3ef4850ec38b34ea6eda02c22a70ac98500584c1Trond Norbyeint bus_property_set_uint64(DBusMessageIter *i, const char *property, void *data);
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define bus_property_set_usec bus_property_set_uint64
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye int function(DBusMessageIter *i, const char *property, void *data) { \
225d5411e0f1f0e690e3553aad7a97c648d566a1HemangLavana const char *value; \
75640e2b0da81c240758d747e76d30acd1ed194dKnut Anders Hatlen value = strempty(name##_to_string(*field)); \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye#define DEFINE_BUS_PROPERTY_SET_ENUM(function,name,type) \
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbye int function(DBusMessageIter *i, const char *property, void *data) { \
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbye const char *value; \
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbye if (f < 0) \
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond NorbyeDBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond NorbyeDBusMessage* bus_properties_changed_one_new(const char *path, const char *interface, const char *property);
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbyeuint32_t bus_flags_to_events(DBusWatch *bus_watch);
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbyeint bus_parse_strv_iter(DBusMessageIter *iter, char ***_l);
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbyeint bus_append_strv_iter(DBusMessageIter *iter, char **l);
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvikint bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next);
64b763950bf11e9357facbd2b5666631a895c085Trond Norbyeint generic_print_property(const char *name, DBusMessageIter *iter, bool all);
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlenvoid bus_async_unregister_and_exit(DBusConnection *bus, const char *name);
64b763950bf11e9357facbd2b5666631a895c085Trond NorbyeDBusHandlerResult bus_exit_idle_filter(DBusConnection *bus, DBusMessage *m, void *userdata);
9cf297d9a579835e9336d587eaee187ca0954767Knut Anders Hatlenpid_t bus_get_unix_process_id(DBusConnection *connection, const char *name, DBusError *error);
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlenbool bus_error_is_no_service(const DBusError *error);
9cf297d9a579835e9336d587eaee187ca0954767Knut Anders Hatlenint bus_method_call_with_reply(DBusConnection *bus,
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlenconst char *bus_message_get_sender_with_fallback(DBusMessage *m);
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlenvoid bus_message_unrefp(DBusMessage **reply);
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen#define _cleanup_dbus_message_unref_ __attribute__((cleanup(bus_message_unrefp)))