chiark / gitweb /
timedatectl: introduce new command line client for timedated
[elogind.git] / src / shared / dbus-common.h
index ca398fc3f5444f41802e8fbb2ce860f37188745f..005a715d0aa6ae4dc59184d9a987c327b901eac4 100644 (file)
@@ -1,7 +1,6 @@
 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
 
-#ifndef foodbuscommonhfoo
-#define foodbuscommonhfoo
+#pragma once
 
 /***
   This file is part of systemd.
@@ -23,6 +22,7 @@
 ***/
 
 #include <dbus/dbus.h>
+#include <inttypes.h>
 
 #ifndef DBUS_ERROR_UNKNOWN_OBJECT
 #define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
@@ -91,6 +91,7 @@ int bus_connect_system_ssh(const char *user, const char *host, DBusConnection **
 int bus_connect_system_polkit(DBusConnection **_bus, DBusError *error);
 
 const char *bus_error_message(const DBusError *error);
+const char *bus_error_message_or_strerror(const DBusError *error, int err);
 
 typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
 typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property, void *data);
@@ -144,6 +145,9 @@ int bus_property_append_long(DBusMessageIter *i, const char *property, void *dat
 #define bus_property_append_unsigned bus_property_append_uint32
 #define bus_property_append_usec bus_property_append_uint64
 
+int bus_property_set_uint64(DBusMessageIter *i, const char *property, void *data);
+#define bus_property_set_usec bus_property_set_uint64
+
 #define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type)             \
         int function(DBusMessageIter *i, const char *property, void *data) { \
                 const char *value;                                      \
@@ -152,7 +156,7 @@ int bus_property_append_long(DBusMessageIter *i, const char *property, void *dat
                 assert(i);                                              \
                 assert(property);                                       \
                                                                         \
-                value = name##_to_string(*field);                       \
+                value = strempty(name##_to_string(*field));             \
                                                                         \
                 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
                         return -ENOMEM;                                 \
@@ -163,15 +167,18 @@ int bus_property_append_long(DBusMessageIter *i, const char *property, void *dat
 #define DEFINE_BUS_PROPERTY_SET_ENUM(function,name,type)                \
         int function(DBusMessageIter *i, const char *property, void *data) { \
                 const char *value;                                      \
-                type *field = data;                                     \
+                type f, *field = data;                                  \
                                                                         \
                 assert(i);                                              \
                 assert(property);                                       \
                                                                         \
                 dbus_message_iter_get_basic(i, &value);                 \
                                                                         \
-                *field = name##_from_string(value);                     \
+                f = name##_from_string(value);                          \
+                if (f < 0)                                              \
+                        return f;                                       \
                                                                         \
+                *field = f;                                             \
                 return 0;                                               \
         }
 
@@ -196,4 +203,20 @@ void bus_async_unregister_and_exit(DBusConnection *bus, const char *name);
 
 DBusHandlerResult bus_exit_idle_filter(DBusConnection *bus, DBusMessage *m, void *userdata);
 
-#endif
+pid_t bus_get_unix_process_id(DBusConnection *connection, const char *name, DBusError *error);
+
+bool bus_error_is_no_service(const DBusError *error);
+int bus_method_call_with_reply(DBusConnection *bus,
+                               const char *destination,
+                               const char *path,
+                               const char *interface,
+                               const char *method,
+                               DBusMessage **return_reply,
+                               DBusError *return_error,
+                               int first_arg_type, ...);
+
+const char *bus_message_get_sender_with_fallback(DBusMessage *m);
+
+void bus_message_unrefp(DBusMessage **reply);
+
+#define _cleanup_dbus_message_unref_ __attribute__((cleanup(bus_message_unrefp)))