]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: add more macros for defining functions of getting dbus properties
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 May 2018 01:02:17 +0000 (10:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 May 2018 14:07:02 +0000 (23:07 +0900)
src/shared/bus-util.h

index 74526c5e8b234b312ee2b4565173af014ee2da6f..a3af8d8fbccc117eafd5be8c08d2691720fde388 100644 (file)
@@ -157,34 +157,15 @@ int bus_log_create_error(int r);
         }
 
 #define ident(x) (x)
-#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1)    \
+#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)              \
-        int function(sd_bus *bus,                                       \
-                     const char *path,                                  \
-                     const char *interface,                             \
-                     const char *property,                              \
-                     sd_bus_message *reply,                             \
-                     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));             \
-                                                                        \
-                r = sd_bus_message_append_basic(reply, 's', value);     \
-                if (r < 0)                                              \
-                        return r;                                       \
-                                                                        \
-                return 1;                                               \
-        }
+        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)), \