chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / shared / bus-util.h
index d22b7d8c13bf77eb0101cafd5994a0d5d88cf487..ac1b79c56ea8466c9f8389d1f2aa745892a5cdbd 100644 (file)
@@ -2,8 +2,6 @@
 #pragma once
 
 /***
-  This file is part of systemd.
-
   Copyright 2013 Lennart Poettering
 ***/
 
@@ -37,8 +35,8 @@ struct bus_properties_map {
 };
 
 enum {
-        BUS_MAP_STRDUP          = 1U << 0, /* If set, each "s" message is duplicated. Thus, each pointer needs to be freed. */
-        BUS_MAP_BOOLEAN_AS_BOOL = 1U << 1, /* If set, each "b" message is written to a bool pointer. If not set, "b" is written to a int pointer. */
+        BUS_MAP_STRDUP          = 1 << 0, /* If set, each "s" message is duplicated. Thus, each pointer needs to be freed. */
+        BUS_MAP_BOOLEAN_AS_BOOL = 1 << 1, /* If set, each "b" message is written to a bool pointer. If not set, "b" is written to a int pointer. */
 };
 
 int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
@@ -138,7 +136,7 @@ int bus_log_create_error(int r);
 
 #if 0 /// UNNEEDED by elogind
 #endif // 0
-#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type)              \
+#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val)         \
         int function(sd_bus *bus,                                       \
                      const char *path,                                  \
                      const char *interface,                             \
@@ -147,23 +145,42 @@ int bus_log_create_error(int r);
                      void *userdata,                                    \
                      sd_bus_error *error) {                             \
                                                                         \
-                const char *value;                                      \
-                type *field = userdata;                                 \
-                int r;                                                  \
-                                                                        \
                 assert(bus);                                            \
                 assert(reply);                                          \
-                assert(field);                                          \
                                                                         \
-                value = strempty(name##_to_string(*field));             \
+                return sd_bus_message_append(reply, bus_type, val);     \
+        }
+
+#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \
+        int function(sd_bus *bus,                                       \
+                     const char *path,                                  \
+                     const char *interface,                             \
+                     const char *property,                              \
+                     sd_bus_message *reply,                             \
+                     void *userdata,                                    \
+                     sd_bus_error *error) {                             \
                                                                         \
-                r = sd_bus_message_append_basic(reply, 's', value);     \
-                if (r < 0)                                              \
-                        return r;                                       \
+                data_type *data = userdata;                             \
                                                                         \
-                return 1;                                               \
+                assert(bus);                                            \
+                assert(reply);                                          \
+                assert(data);                                           \
+                                                                        \
+                return sd_bus_message_append(reply, bus_type,           \
+                                             get2(get1(data)));         \
         }
 
+#define ident(x) (x)
+#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \
+        BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident)
+
+#define ref(x) (*(x))
+#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \
+        BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get)
+
+#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type)              \
+        BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string)
+
 #define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
         SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
         SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))
@@ -179,4 +196,11 @@ int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface
 int bus_track_add_name_many(sd_bus_track *t, char **l);
 #endif // 0
 
-int bus_open_system_watch_bind(sd_bus **ret);
+int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *description);
+static inline int bus_open_system_watch_bind(sd_bus **ret) {
+        return bus_open_system_watch_bind_with_description(ret, NULL);
+}
+
+int bus_request_name_async_may_reload_dbus(sd_bus *bus, sd_bus_slot **ret_slot, const char *name, uint64_t flags, void *userdata);
+
+int bus_reply_pair_array(sd_bus_message *m, char **l);