diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-11-13 09:08:08 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-11-13 09:08:08 +0000 |
commit | 944e55c90bca95c2fae33f6bd379ea944078ed9c (patch) | |
tree | 237e92297935ffeea3fdffd814fd899efe27650d /navit/binding | |
parent | ea48014bb9c88c83b0e5a15f645078bfc046d162 (diff) | |
download | navit-944e55c90bca95c2fae33f6bd379ea944078ed9c.tar.gz |
Fix:binding_dbus:Cleanup
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2753 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/binding')
-rw-r--r-- | navit/binding/dbus/binding_dbus.c | 427 |
1 files changed, 214 insertions, 213 deletions
diff --git a/navit/binding/dbus/binding_dbus.c b/navit/binding/dbus/binding_dbus.c index e63ca47ee..a9cd4fff1 100644 --- a/navit/binding/dbus/binding_dbus.c +++ b/navit/binding/dbus/binding_dbus.c @@ -261,59 +261,6 @@ dbus_error_invalid_object_path_parameter(DBusConnection *connection, DBusMessage return dbus_error(connection, message, DBUS_ERROR_BAD_ADDRESS, "object path parameter invalid"); } -static DBusHandlerResult -request_config_get_attr(DBusConnection *connection, DBusMessage *message) -{ - DBusMessage *reply; - DBusMessageIter iter; - struct attr attr; - enum attr_type attr_type; - struct attr_iter *attr_iter; - - dbus_message_iter_init(message, &iter); - attr_type=attr_type_get_from_message(&iter); - attr_iter=object_get_from_message_arg(&iter, "config_attr_iter"); - if (attr_type == attr_none) - return dbus_error_invalid_attr_type(connection, message); - if (config_get_attr(config, attr_type, &attr, attr_iter)) { - reply = dbus_message_new_method_return(message); - encode_attr(reply, &attr); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - return empty_reply(connection, message); -} - -static DBusHandlerResult -request_config_attr_iter(DBusConnection *connection, DBusMessage *message) -{ - DBusMessage *reply; - struct attr_iter *attr_iter=config_attr_iter_new(); - char *opath=object_new("config_attr_iter",attr_iter); - reply = dbus_message_new_method_return(message); - dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult -request_config_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) -{ - struct attr_iter *attr_iter; - DBusMessageIter iter; - - dbus_message_iter_init(message, &iter); - attr_iter=object_get_from_message_arg(&iter, "config_attr_iter"); - if (! attr_iter) - return dbus_error_invalid_object_path_parameter(connection, message); - config_attr_iter_destroy(attr_iter); - - return empty_reply(connection, message); -} - /** * Extracts a struct pcoord from a DBus message * @@ -452,10 +399,175 @@ destroy_attr(struct attr *attr) } } +static char * +get_iter_name(char *type) +{ + return g_strdup_printf("%s_attr_iter",type); +} + +static DBusHandlerResult +request_attr_iter(DBusConnection *connection, DBusMessage *message, char *type, struct attr_iter *(*func)(void)) +{ + DBusMessage *reply; + char *iter_name; + char *opath; + struct attr_iter *attr_iter; + + attr_iter=(*func)(); + iter_name=get_iter_name(type); + opath=object_new(iter_name,attr_iter); + g_free(iter_name); + reply = dbus_message_new_method_return(message); + dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); + + return DBUS_HANDLER_RESULT_HANDLED; +} + +static DBusHandlerResult +request_attr_iter_destroy(DBusConnection *connection, DBusMessage *message, char *type, void (*func)(struct attr_iter *)) +{ + struct attr_iter *attr_iter; + DBusMessageIter iter; + char *iter_name; + + dbus_message_iter_init(message, &iter); + iter_name=get_iter_name(type); + attr_iter=object_get_from_message_arg(&iter, iter_name); + g_free(iter_name); + if (! attr_iter) + return dbus_error_invalid_object_path_parameter(connection, message); + func(attr_iter); + + return empty_reply(connection, message); +} + + +static DBusHandlerResult +request_get_attr(DBusConnection *connection, DBusMessage *message, char *type, int (*func)(void *data, enum attr_type type, struct attr *attr, struct attr_iter *iter)) +{ + DBusMessage *reply; + DBusMessageIter iter; + struct attr attr; + enum attr_type attr_type; + struct attr_iter *attr_iter; + void *data; + char *iter_name; + + data = object_get_from_message(message, type); + if (! data) + return dbus_error_invalid_object_path(connection, message); + + dbus_message_iter_init(message, &iter); + attr_type=attr_type_get_from_message(&iter); + if (attr_type == attr_none) + return dbus_error_invalid_attr_type(connection, message); + iter_name=get_iter_name(type); + attr_iter=object_get_from_message_arg(&iter, iter_name); + g_free(iter_name); + if (func(data, attr_type, &attr, attr_iter)) { + reply = dbus_message_new_method_return(message); + encode_attr(reply, &attr); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + return empty_reply(connection, message); + +} + + +/* config */ +static DBusHandlerResult +request_config_get_attr(DBusConnection *connection, DBusMessage *message) +{ + DBusMessage *reply; + DBusMessageIter iter; + struct attr attr; + enum attr_type attr_type; + struct attr_iter *attr_iter; + + dbus_message_iter_init(message, &iter); + attr_type=attr_type_get_from_message(&iter); + attr_iter=object_get_from_message_arg(&iter, "config_attr_iter"); + if (attr_type == attr_none) + return dbus_error_invalid_attr_type(connection, message); + if (config_get_attr(config, attr_type, &attr, attr_iter)) { + reply = dbus_message_new_method_return(message); + encode_attr(reply, &attr); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + return empty_reply(connection, message); +} + +static DBusHandlerResult +request_config_attr_iter(DBusConnection *connection, DBusMessage *message) +{ + DBusMessage *reply; + struct attr_iter *attr_iter=config_attr_iter_new(); + char *opath=object_new("config_attr_iter",attr_iter); + reply = dbus_message_new_method_return(message); + dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); + + return DBUS_HANDLER_RESULT_HANDLED; +} + +static DBusHandlerResult +request_config_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) +{ + struct attr_iter *attr_iter; + DBusMessageIter iter; + + dbus_message_iter_init(message, &iter); + attr_iter=object_get_from_message_arg(&iter, "config_attr_iter"); + if (! attr_iter) + return dbus_error_invalid_object_path_parameter(connection, message); + config_attr_iter_destroy(attr_iter); + + return empty_reply(connection, message); +} /* graphics */ static DBusHandlerResult +request_graphics_get_data(DBusConnection *connection, DBusMessage *message) +{ + struct graphics *graphics; + char *data; + struct graphics_data_image *image; + DBusMessage *reply; + + graphics = object_get_from_message(message, "graphics"); + if (! graphics) + return dbus_error_invalid_object_path(connection, message); + + if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID)) + return dbus_error_invalid_parameter(connection, message); + image=graphics_get_data(graphics, data); + if (image) { + DBusMessageIter iter1,iter2; + reply = dbus_message_new_method_return(message); +#if 0 + dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID); +#endif + dbus_message_iter_init_append(reply, &iter1); + dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "y", &iter2); + if (image->data && image->size) + dbus_message_iter_append_fixed_array(&iter2, DBUS_TYPE_BYTE, &image->data, image->size); + dbus_message_iter_close_container(&iter1, &iter2); + dbus_connection_send (connection, reply, NULL); + dbus_message_unref (reply); + return DBUS_HANDLER_RESULT_HANDLED; + } + return empty_reply(connection, message); +} + +static DBusHandlerResult request_graphics_set_attr(DBusConnection *connection, DBusMessage *message) { struct graphics *graphics; @@ -474,6 +586,53 @@ request_graphics_set_attr(DBusConnection *connection, DBusMessage *message) return dbus_error_invalid_parameter(connection, message); } +/* map */ + +static DBusHandlerResult +request_map_set_attr(DBusConnection *connection, DBusMessage *message) +{ + struct map *map; + struct attr attr; + int ret; + + map = object_get_from_message(message, "map"); + if (! map) + return dbus_error_invalid_object_path(connection, message); + if (decode_attr(message, &attr)) { + ret=map_set_attr(map, &attr); + destroy_attr(&attr); + if (ret) + return empty_reply(connection, message); + } + return dbus_error_invalid_parameter(connection, message); +} + +static DBusHandlerResult +request_map_get_attr(DBusConnection *connection, DBusMessage *message) +{ + return request_get_attr(connection, message, "map", (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr); +} + +/* mapset */ + +static DBusHandlerResult +request_mapset_attr_iter(DBusConnection *connection, DBusMessage *message) +{ + return request_attr_iter(connection, message, "mapset", (struct attr_iter * (*)(void))mapset_attr_iter_new); +} + +static DBusHandlerResult +request_mapset_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) +{ + return request_attr_iter_destroy(connection, message, "mapset", (void (*)(struct attr_iter *))mapset_attr_iter_destroy); +} + +static DBusHandlerResult +request_mapset_get_attr(DBusConnection *connection, DBusMessage *message) +{ + return request_get_attr(connection, message, "mapset", (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))mapset_get_attr); +} + /* navit */ static DBusHandlerResult @@ -854,130 +1013,6 @@ request_navit_evaluate(DBusConnection *connection, DBusMessage *message) } -static char * -get_iter_name(char *type) -{ - return g_strdup_printf("%s_attr_iter",type); -} - -static DBusHandlerResult -request_attr_iter(DBusConnection *connection, DBusMessage *message, char *type, struct attr_iter *(*func)(void)) -{ - DBusMessage *reply; - char *iter_name; - char *opath; - struct attr_iter *attr_iter; - - attr_iter=(*func)(); - iter_name=get_iter_name(type); - opath=object_new(iter_name,attr_iter); - g_free(iter_name); - reply = dbus_message_new_method_return(message); - dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult -request_attr_iter_destroy(DBusConnection *connection, DBusMessage *message, char *type, void (*func)(struct attr_iter *)) -{ - struct attr_iter *attr_iter; - DBusMessageIter iter; - char *iter_name; - - dbus_message_iter_init(message, &iter); - iter_name=get_iter_name(type); - attr_iter=object_get_from_message_arg(&iter, iter_name); - g_free(iter_name); - if (! attr_iter) - return dbus_error_invalid_object_path_parameter(connection, message); - func(attr_iter); - - return empty_reply(connection, message); -} - - -static DBusHandlerResult -request_get_attr(DBusConnection *connection, DBusMessage *message, char *type, int (*func)(void *data, enum attr_type type, struct attr *attr, struct attr_iter *iter)) -{ - DBusMessage *reply; - DBusMessageIter iter; - struct attr attr; - enum attr_type attr_type; - struct attr_iter *attr_iter; - void *data; - char *iter_name; - - data = object_get_from_message(message, type); - if (! data) - return dbus_error_invalid_object_path(connection, message); - - dbus_message_iter_init(message, &iter); - attr_type=attr_type_get_from_message(&iter); - if (attr_type == attr_none) - return dbus_error_invalid_attr_type(connection, message); - iter_name=get_iter_name(type); - attr_iter=object_get_from_message_arg(&iter, iter_name); - g_free(iter_name); - if (func(data, attr_type, &attr, attr_iter)) { - reply = dbus_message_new_method_return(message); - encode_attr(reply, &attr); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - return empty_reply(connection, message); - -} - -/* map */ - -static DBusHandlerResult -request_map_set_attr(DBusConnection *connection, DBusMessage *message) -{ - struct map *map; - struct attr attr; - int ret; - - map = object_get_from_message(message, "map"); - if (! map) - return dbus_error_invalid_object_path(connection, message); - if (decode_attr(message, &attr)) { - ret=map_set_attr(map, &attr); - destroy_attr(&attr); - if (ret) - return empty_reply(connection, message); - } - return dbus_error_invalid_parameter(connection, message); -} - -static DBusHandlerResult -request_map_get_attr(DBusConnection *connection, DBusMessage *message) -{ - return request_get_attr(connection, message, "map", (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))map_get_attr); -} - -/* mapset */ - -static DBusHandlerResult -request_mapset_attr_iter(DBusConnection *connection, DBusMessage *message) -{ - return request_attr_iter(connection, message, "mapset", (struct attr_iter * (*)(void))mapset_attr_iter_new); -} - -static DBusHandlerResult -request_mapset_attr_iter_destroy(DBusConnection *connection, DBusMessage *message) -{ - return request_attr_iter_destroy(connection, message, "mapset", (void (*)(struct attr_iter *))mapset_attr_iter_destroy); -} - -static DBusHandlerResult -request_mapset_get_attr(DBusConnection *connection, DBusMessage *message) -{ - return request_get_attr(connection, message, "mapset", (int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))mapset_get_attr); -} /* vehicle */ @@ -1000,40 +1035,6 @@ request_vehicle_set_attr(DBusConnection *connection, DBusMessage *message) return dbus_error_invalid_parameter(connection, message); } -/* graphics */ - -static DBusHandlerResult -request_graphics_get_data(DBusConnection *connection, DBusMessage *message) -{ - struct graphics *graphics; - char *data; - struct graphics_data_image *image; - DBusMessage *reply; - - graphics = object_get_from_message(message, "graphics"); - if (! graphics) - return dbus_error_invalid_object_path(connection, message); - - if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID)) - return dbus_error_invalid_parameter(connection, message); - image=graphics_get_data(graphics, data); - if (image) { - DBusMessageIter iter1,iter2; - reply = dbus_message_new_method_return(message); -#if 0 - dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID); -#endif - dbus_message_iter_init_append(reply, &iter1); - dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "y", &iter2); - if (image->data && image->size) - dbus_message_iter_append_fixed_array(&iter2, DBUS_TYPE_BYTE, &image->data, image->size); - dbus_message_iter_close_container(&iter1, &iter2); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - return DBUS_HANDLER_RESULT_HANDLED; - } - return empty_reply(connection, message); -} struct dbus_method { char *path; @@ -1082,7 +1083,7 @@ struct dbus_method { }; static char * -introspect_path(char *object) +introspect_path(const char *object) { char *ret; int i; @@ -1112,7 +1113,7 @@ introspect_path(char *object) } static char * -generate_navitintrospectxml(char *object) +generate_navitintrospectxml(const char *object) { int i,methods_size,n=0; char *navitintrospectxml; |