diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-10-11 20:32:16 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-10-11 20:32:16 +0200 |
commit | 77a874a3fb6f65d2308c20827f005c43bb075752 (patch) | |
tree | 077579630bf03b004f2ff998d13f9eab458737aa /src | |
parent | 992c052c34d180dd9fe6bd4f89fff3a481a729dc (diff) |
bus: don't rely on gccisms/c11 in public header files.
One day sd-bus.h should become a public header file. We generally try to
be conservative in language features we use in public headers (much
unlike in private code), hence don't make use of anonymous unions in
structs for the vtable definitions.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-introspect.c | 14 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-objects.c | 75 | ||||
-rw-r--r-- | src/systemd/sd-bus-vtable.h | 36 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 5 |
4 files changed, 65 insertions, 65 deletions
diff --git a/src/libsystemd-bus/bus-introspect.c b/src/libsystemd-bus/bus-introspect.c index 8dc9a2de15..c04d9b51f7 100644 --- a/src/libsystemd-bus/bus-introspect.c +++ b/src/libsystemd-bus/bus-introspect.c @@ -128,9 +128,9 @@ int introspect_write_interface(struct introspect *i, const char *interface, cons break; case _SD_BUS_VTABLE_METHOD: - fprintf(i->f, " <method name=\"%s\">\n", v->method.member); - introspect_write_arguments(i, v->method.signature, "in"); - introspect_write_arguments(i, v->method.result, "out"); + fprintf(i->f, " <method name=\"%s\">\n", v->x.method.member); + introspect_write_arguments(i, v->x.method.signature, "in"); + introspect_write_arguments(i, v->x.method.result, "out"); introspect_write_flags(i, v->type, v->flags); fputs(" </method>\n", i->f); break; @@ -138,16 +138,16 @@ int introspect_write_interface(struct introspect *i, const char *interface, cons case _SD_BUS_VTABLE_PROPERTY: case _SD_BUS_VTABLE_WRITABLE_PROPERTY: fprintf(i->f, " <property name=\"%s\" type=\"%s\" access=\"%s\">\n", - v->property.member, - v->property.signature, + v->x.property.member, + v->x.property.signature, v->type == _SD_BUS_VTABLE_WRITABLE_PROPERTY ? "readwrite" : "read"); introspect_write_flags(i, v->type, v->flags); fputs(" </property>\n", i->f); break; case _SD_BUS_VTABLE_SIGNAL: - fprintf(i->f, " <signal name=\"%s\">\n", v->signal.member); - introspect_write_arguments(i, v->signal.signature, NULL); + fprintf(i->f, " <signal name=\"%s\">\n", v->x.signal.member); + introspect_write_arguments(i, v->x.signal.signature, NULL); introspect_write_flags(i, v->type, v->flags); fputs(" </signal>\n", i->f); break; diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c index da49d75031..8d953762be 100644 --- a/src/libsystemd-bus/bus-objects.c +++ b/src/libsystemd-bus/bus-objects.c @@ -57,7 +57,7 @@ static int node_vtable_get_userdata( static void *vtable_property_convert_userdata(const sd_bus_vtable *p, void *u) { assert(p); - return (uint8_t*) u + p->property.offset; + return (uint8_t*) u + p->x.property.offset; } static int vtable_property_get_userdata( @@ -242,19 +242,19 @@ static int method_callbacks_run( if (r < 0) return r; - if (!streq(strempty(c->vtable->method.signature), signature)) { + if (!streq(strempty(c->vtable->x.method.signature), signature)) { r = sd_bus_reply_method_errorf(bus, m, "org.freedesktop.DBus.Error.InvalidArgs", "Invalid arguments '%s' to call %s:%s, expecting '%s'.", - signature, c->interface, c->member, strempty(c->vtable->method.signature)); + signature, c->interface, c->member, strempty(c->vtable->x.method.signature)); if (r < 0) return r; return 1; } - if (c->vtable->method.handler) - return c->vtable->method.handler(bus, m, u); + if (c->vtable->x.method.handler) + return c->vtable->x.method.handler(bus, m, u); /* If the method callback is NULL, make this a successful NOP */ r = sd_bus_reply_method_return(bus, m, NULL); @@ -280,14 +280,15 @@ static int invoke_property_get( assert(bus); assert(v); - if (v->property.get) - return v->property.get(bus, path, interface, property, m, error, userdata); + if (v->x.property.get) + return v->x.property.get(bus, path, interface, property, m, error, userdata); /* Automatic handling if no callback is defined. */ - assert(bus_type_is_basic(v->property.signature[0])); + assert(signature_is_single(v->x.property.signature, false)); + assert(bus_type_is_basic(v->x.property.signature[0])); - switch (v->property.signature[0]) { + switch (v->x.property.signature[0]) { case SD_BUS_TYPE_STRING: case SD_BUS_TYPE_OBJECT_PATH: @@ -300,7 +301,7 @@ static int invoke_property_get( break; } - r = sd_bus_message_append_basic(m, v->property.signature[0], p); + r = sd_bus_message_append_basic(m, v->x.property.signature[0], p); if (r < 0) return r; @@ -322,15 +323,15 @@ static int invoke_property_set( assert(bus); assert(v); - if (v->property.set) - return v->property.set(bus, path, interface, property, value, error, userdata); + if (v->x.property.set) + return v->x.property.set(bus, path, interface, property, value, error, userdata); /* Automatic handling if no callback is defined. */ - assert(signature_is_single(v->property.signature, false)); - assert(bus_type_is_basic(v->property.signature[0])); + assert(signature_is_single(v->x.property.signature, false)); + assert(bus_type_is_basic(v->x.property.signature[0])); - switch (v->property.signature[0]) { + switch (v->x.property.signature[0]) { case SD_BUS_TYPE_STRING: case SD_BUS_TYPE_OBJECT_PATH: @@ -338,7 +339,7 @@ static int invoke_property_set( const char *p; char *n; - r = sd_bus_message_read_basic(value, v->property.signature[0], &p); + r = sd_bus_message_read_basic(value, v->x.property.signature[0], &p); if (r < 0) return r; @@ -353,7 +354,7 @@ static int invoke_property_set( } default: - r = sd_bus_message_read_basic(value, v->property.signature[0], userdata); + r = sd_bus_message_read_basic(value, v->x.property.signature[0], userdata); if (r < 0) return r; @@ -396,7 +397,7 @@ static int property_get_set_callbacks_run( c->last_iteration = bus->iteration_counter; if (is_get) { - r = sd_bus_message_open_container(reply, 'v', c->vtable->property.signature); + r = sd_bus_message_open_container(reply, 'v', c->vtable->x.property.signature); if (r < 0) return r; @@ -420,7 +421,7 @@ static int property_get_set_callbacks_run( if (c->vtable->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY) sd_bus_error_setf(&error, "org.freedesktop.DBus.Error.PropertyReadOnly", "Property '%s' is not writable.", c->member); else { - r = sd_bus_message_enter_container(m, 'v', c->vtable->property.signature); + r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature); if (r < 0) return r; @@ -476,11 +477,11 @@ static int vtable_append_all_properties( if (r < 0) return r; - r = sd_bus_message_open_container(reply, 'v', v->property.signature); + r = sd_bus_message_open_container(reply, 'v', v->x.property.signature); if (r < 0) return r; - r = invoke_property_get(bus, v, path, c->interface, v->property.member, reply, error, vtable_property_convert_userdata(v, userdata)); + r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, error, vtable_property_convert_userdata(v, userdata)); if (r < 0) return r; @@ -1321,7 +1322,7 @@ static void free_node_vtable(sd_bus *bus, struct node_vtable *w) { key.path = w->node->path; key.interface = w->interface; - key.member = v->method.member; + key.member = v->x.method.member; x = hashmap_remove(bus->vtable_methods, &key); break; @@ -1333,7 +1334,7 @@ static void free_node_vtable(sd_bus *bus, struct node_vtable *w) { key.path = w->node->path; key.interface = w->interface; - key.member = v->property.member; + key.member = v->x.property.member; x = hashmap_remove(bus->vtable_properties, &key); break; }} @@ -1390,7 +1391,7 @@ static int add_object_vtable_internal( return -EINVAL; if (!interface_name_is_valid(interface)) return -EINVAL; - if (!vtable || vtable[0].type != _SD_BUS_VTABLE_START || vtable[0].start.element_size != sizeof(struct sd_bus_vtable)) + if (!vtable || vtable[0].type != _SD_BUS_VTABLE_START || vtable[0].x.start.element_size != sizeof(struct sd_bus_vtable)) return -EINVAL; if (bus_pid_changed(bus)) return -ECHILD; @@ -1444,10 +1445,10 @@ static int add_object_vtable_internal( case _SD_BUS_VTABLE_METHOD: { struct vtable_member *m; - if (!member_name_is_valid(v->method.member) || - !signature_is_valid(strempty(v->method.signature), false) || - !signature_is_valid(strempty(v->method.result), false) || - !(v->method.handler || (isempty(v->method.signature) && isempty(v->method.result))) || + if (!member_name_is_valid(v->x.method.member) || + !signature_is_valid(strempty(v->x.method.signature), false) || + !signature_is_valid(strempty(v->x.method.result), false) || + !(v->x.method.handler || (isempty(v->x.method.signature) && isempty(v->x.method.result))) || v->flags & (SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE|SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY)) { r = -EINVAL; goto fail; @@ -1462,7 +1463,7 @@ static int add_object_vtable_internal( m->parent = c; m->path = n->path; m->interface = c->interface; - m->member = v->method.member; + m->member = v->x.method.member; m->vtable = v; r = hashmap_put(bus->vtable_methods, m, m); @@ -1476,7 +1477,7 @@ static int add_object_vtable_internal( case _SD_BUS_VTABLE_WRITABLE_PROPERTY: - if (!(v->property.set || bus_type_is_basic(v->property.signature[0]))) { + if (!(v->x.property.set || bus_type_is_basic(v->x.property.signature[0]))) { r = -EINVAL; goto fail; } @@ -1486,9 +1487,9 @@ static int add_object_vtable_internal( case _SD_BUS_VTABLE_PROPERTY: { struct vtable_member *m; - if (!member_name_is_valid(v->property.member) || - !signature_is_single(v->property.signature, false) || - !(v->property.get || bus_type_is_basic(v->property.signature[0])) || + if (!member_name_is_valid(v->x.property.member) || + !signature_is_single(v->x.property.signature, false) || + !(v->x.property.get || bus_type_is_basic(v->x.property.signature[0])) || v->flags & SD_BUS_VTABLE_METHOD_NO_REPLY || (v->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY && !(v->flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE))) { r = -EINVAL; @@ -1505,7 +1506,7 @@ static int add_object_vtable_internal( m->parent = c; m->path = n->path; m->interface = c->interface; - m->member = v->property.member; + m->member = v->x.property.member; m->vtable = v; r = hashmap_put(bus->vtable_properties, m, m); @@ -1519,8 +1520,8 @@ static int add_object_vtable_internal( case _SD_BUS_VTABLE_SIGNAL: - if (!member_name_is_valid(v->signal.member) || - !signature_is_single(strempty(v->signal.signature), false)) { + if (!member_name_is_valid(v->x.signal.member) || + !signature_is_single(strempty(v->x.signal.signature), false)) { r = -EINVAL; goto fail; } @@ -1776,7 +1777,7 @@ static int emit_properties_changed_on_interface( if (r < 0) return r; - r = sd_bus_message_open_container(m, 'v', v->vtable->property.signature); + r = sd_bus_message_open_container(m, 'v', v->vtable->x.property.signature); if (r < 0) return r; diff --git a/src/systemd/sd-bus-vtable.h b/src/systemd/sd-bus-vtable.h index 5203bf1a9b..82e50d24c8 100644 --- a/src/systemd/sd-bus-vtable.h +++ b/src/systemd/sd-bus-vtable.h @@ -70,53 +70,53 @@ struct sd_bus_vtable { sd_bus_property_set_t set; size_t offset; } property; - }; + } x; }; #define SD_BUS_VTABLE_START(_flags) \ { \ .type = _SD_BUS_VTABLE_START, \ .flags = _flags, \ - .start.element_size = sizeof(sd_bus_vtable), \ + .x.start.element_size = sizeof(sd_bus_vtable), \ } #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags) \ { \ .type = _SD_BUS_VTABLE_METHOD, \ .flags = _flags, \ - .method.member = _member, \ - .method.signature = _signature, \ - .method.result = _result, \ - .method.handler = _handler, \ + .x.method.member = _member, \ + .x.method.signature = _signature, \ + .x.method.result = _result, \ + .x.method.handler = _handler, \ } #define SD_BUS_SIGNAL(_member, _signature, _flags) \ { \ .type = _SD_BUS_VTABLE_SIGNAL, \ .flags = _flags, \ - .signal.member = _member, \ - .signal.signature = _signature, \ + .x.signal.member = _member, \ + .x.signal.signature = _signature, \ } -#define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \ +#define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \ { \ .type = _SD_BUS_VTABLE_PROPERTY, \ .flags = _flags, \ - .property.member = _member, \ - .property.signature = _signature, \ - .property.get = _get, \ - .property.offset = _offset, \ + .x.property.member = _member, \ + .x.property.signature = _signature, \ + .x.property.get = _get, \ + .x.property.offset = _offset, \ } #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \ { \ .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \ .flags = _flags, \ - .property.member = _member, \ - .property.signature = _signature, \ - .property.get = _get, \ - .property.set = _set, \ - .property.offset = _offset, \ + .x.property.member = _member, \ + .x.property.signature = _signature, \ + .x.property.get = _get, \ + .x.property.set = _set, \ + .x.property.offset = _offset, \ } #define SD_BUS_VTABLE_END \ diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index 2c12cf0f7d..bbeec1302a 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -147,6 +147,7 @@ int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type); int sd_bus_message_get_serial(sd_bus_message *m, uint64_t *serial); int sd_bus_message_get_reply_serial(sd_bus_message *m, uint64_t *serial); int sd_bus_message_get_no_reply(sd_bus_message *m); +int sd_bus_message_get_signature(sd_bus_message *m, int complete, const char **signature); const char *sd_bus_message_get_path(sd_bus_message *m); const char *sd_bus_message_get_interface(sd_bus_message *m); @@ -201,8 +202,6 @@ int sd_bus_message_exit_container(sd_bus_message *m); int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char **contents); int sd_bus_message_rewind(sd_bus_message *m, int complete); -int sd_bus_message_get_signature(sd_bus_message *m, int complete, const char **signature); - /* Convenience calls */ int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...); @@ -235,8 +234,8 @@ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machi /* Error structures */ -#define SD_BUS_ERROR_NULL ((sd_bus_error) {NULL, NULL, 0}) #define SD_BUS_ERROR_MAKE(name, message) ((sd_bus_error) {(name), (message), 0}) +#define SD_BUS_ERROR_NULL SD_BUS_ERROR_MAKE(NULL, NULL) void sd_bus_error_free(sd_bus_error *e); int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...) _sd_printf_attr_(3, 0); |