]> err.no Git - systemd/commitdiff
dbus: add generic DEFINE_BUS_PROPERTY_SET_ENUM() macro for enum properties
authorMichael Olbrich <m.olbrich@pengutronix.de>
Fri, 6 Apr 2012 19:38:01 +0000 (21:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Apr 2012 20:41:20 +0000 (22:41 +0200)
The defined function can be used as BusPropertySetCallback.

src/dbus-common.h

index 1dc0f591d09cda9fb2f4d2f81acc9e89cf739f7a..892d1297feb9b66bdf209725bd1a4f799fa7234e 100644 (file)
@@ -160,6 +160,21 @@ int bus_property_append_long(DBusMessageIter *i, const char *property, void *dat
                 return 0;                                               \
         }
 
+#define DEFINE_BUS_PROPERTY_SET_ENUM(function,name,type)                \
+        int function(DBusMessageIter *i, const char *property, void *data) { \
+                const char *value;                                      \
+                type *field = data;                                     \
+                                                                        \
+                assert(i);                                              \
+                assert(property);                                       \
+                                                                        \
+                dbus_message_iter_get_basic(i, &value);                 \
+                                                                        \
+                *field = name##_from_string(value);                     \
+                                                                        \
+                return 0;                                               \
+        }
+
 const char *bus_errno_to_dbus(int error);
 
 DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);