[maemo-commits] [maemo-commits] r8913 - in projects/haf/trunk/libosso: debian src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Wed Jan 3 09:43:44 EET 2007
- Previous message: [maemo-commits] r8912 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . src
- Next message: [maemo-commits] r8914 - in projects/haf/trunk/osso-af-startup: debian services
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: kihamala Date: 2007-01-03 09:43:42 +0200 (Wed, 03 Jan 2007) New Revision: 8913 Modified: projects/haf/trunk/libosso/debian/changelog projects/haf/trunk/libosso/src/muali.h projects/haf/trunk/libosso/src/osso-hw.c projects/haf/trunk/libosso/src/osso-init.c projects/haf/trunk/libosso/src/osso-internal.h projects/haf/trunk/libosso/src/osso-rpc.c Log: new muali development: muali_reply_error Modified: projects/haf/trunk/libosso/debian/changelog =================================================================== --- projects/haf/trunk/libosso/debian/changelog 2007-01-02 16:08:06 UTC (rev 8912) +++ projects/haf/trunk/libosso/debian/changelog 2007-01-03 07:43:42 UTC (rev 8913) @@ -14,9 +14,9 @@ to use. * Made lot of muali development, design fixes, and tested code. * Implemented muali_reply_string (not sure if *_string functions make - sense...) + sense...) and muali_reply_error. - -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> Fri, 29 Dec 2006 16:35:39 +0200 + -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> Wed, 03 Jan 2007 09:43:15 +0200 libosso (1.20-1) unstable; urgency=low Modified: projects/haf/trunk/libosso/src/muali.h =================================================================== --- projects/haf/trunk/libosso/src/muali.h 2007-01-02 16:08:06 UTC (rev 8912) +++ projects/haf/trunk/libosso/src/muali.h 2007-01-03 07:43:42 UTC (rev 8913) @@ -106,8 +106,8 @@ * for e.g. pre-defined events. */ muali_bus_type bus_type; - /* This can be ID of the reply or a received message. */ - long message_id; + /* This can be an ID string of the reply or a received message. */ + const char *message_id; /* received error message, or NULL */ const char *error; @@ -265,14 +265,14 @@ muali_bus_type bus_type, const char *destination, const char *message_name, - const char *string, - long *message_id); + const char *string); muali_error_t muali_send_varargs(muali_context_t *context, muali_handler_t *reply_handler, const void *user_data, - long *reply_id, - const char *service, + muali_bus_type bus_type, + const char *destination, + const char *message_name, int arg_type, ...); /* blocking */ @@ -287,17 +287,24 @@ const char *service, int arg_type, ...); +/* signals */ +muali_error_t muali_send_signal(muali_context_t *context, + muali_bus_type bus_type, + const char *signal_name, + const char *argument); + +muali_error_t muali_send_signal_full(muali_context_t *context, + muali_bus_type bus_type, + const char *signal_path, + const char *signal_interface, + const char *signal_name, + int arg_type, ...); + + /****************************************/ /* 'advanced' message or signal sending */ /****************************************/ -/* asyncronous */ -muali_error_t muali_send_any(muali_context_t *context, - muali_handler_t *reply_handler, - const void *user_data, - long *reply_id, - const muali_event_info_t *info); - muali_error_t muali_send_any_varargs(muali_context_t *context, muali_handler_t *reply_handler, const void *user_data, @@ -320,19 +327,17 @@ /**********************/ muali_error_t muali_reply_string(muali_context_t *context, - muali_bus_type bus_type, - const char *dest, - long message_id, + const char *message_id, const char *string); muali_error_t muali_reply_varargs(muali_context_t *context, - long message_id, + const char *message_id, int arg_type, ...); muali_error_t muali_reply_error(muali_context_t *context, - long message_id, - const char *name, - const char *message); + const char *message_id, + const char *error_name, + const char *error_message); #ifdef __cplusplus Modified: projects/haf/trunk/libosso/src/osso-hw.c =================================================================== --- projects/haf/trunk/libosso/src/osso-hw.c 2007-01-02 16:08:06 UTC (rev 8912) +++ projects/haf/trunk/libosso/src/osso-hw.c 2007-01-03 07:43:42 UTC (rev 8913) @@ -607,6 +607,7 @@ muali_event_info_t info; DBusMessageIter iter; muali_handler_t *cb; + char id_buf[MAX_MSGID_LEN + 1]; ULOG_DEBUG_F("entered"); assert(osso != NULL && data != NULL); @@ -632,11 +633,23 @@ osso->reply_dummy = reply; } } + if (osso->error_dummy == NULL && + dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_CALL) { + DBusMessage *reply; + reply = dbus_message_new_error(msg, "org.foo.dummy", NULL); + if (reply == NULL) { + ULOG_WARN_F("could not create error_dummy"); + } else { + osso->error_dummy = reply; + } + } if ((dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_CALL && !dbus_message_get_no_reply(msg)) || dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN) { - info.message_id = dbus_message_get_serial(msg); + _muali_make_id(dbus_type, dbus_message_get_sender(msg), + dbus_message_get_serial(msg), id_buf); + info.message_id = id_buf; } if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_ERROR) { Modified: projects/haf/trunk/libosso/src/osso-init.c =================================================================== --- projects/haf/trunk/libosso/src/osso-init.c 2007-01-02 16:08:06 UTC (rev 8912) +++ projects/haf/trunk/libosso/src/osso-init.c 2007-01-03 07:43:42 UTC (rev 8913) @@ -221,6 +221,21 @@ } void __attribute__ ((visibility("hidden"))) +make_default_error_name(const char *service, const char *name, + char *ready_name) +{ + assert(service != NULL); + assert(name != NULL); + assert(ready_name != NULL); + + if (g_strrstr(name, ".") != NULL) { + g_snprintf(ready_name, MAX_ERROR_LEN, "%s", name); + } else { + g_snprintf(ready_name, MAX_ERROR_LEN, "%s.%s", service, name); + } +} + +void __attribute__ ((visibility("hidden"))) make_default_service(const char *application, char *service) { assert(application != NULL); Modified: projects/haf/trunk/libosso/src/osso-internal.h =================================================================== --- projects/haf/trunk/libosso/src/osso-internal.h 2007-01-02 16:08:06 UTC (rev 8912) +++ projects/haf/trunk/libosso/src/osso-internal.h 2007-01-03 07:43:42 UTC (rev 8913) @@ -69,8 +69,10 @@ #define MAX_SVC_LEN 255 #define MAX_OP_LEN 255 #define MAX_MEMBER_LEN 255 +#define MAX_ERROR_LEN 255 #define MAX_HASH_KEY_LEN (MAX_IF_LEN + MAX_SVC_LEN + MAX_OP_LEN) #define MAX_OPM_HASH_KEY_LEN (MAX_OP_LEN + MAX_MEMBER_LEN) +#define MAX_MSGID_LEN (MAX_SVC_LEN + 20 + 20 + 2) #define MAX_APP_NAME_LEN 50 #define MAX_VERSION_LEN 30 @@ -172,7 +174,7 @@ GArray *cp_plugins; int next_handler_id; /* next available handler id, unique in this context */ - const DBusMessage *reply_dummy; + const DBusMessage *reply_dummy, *error_dummy; } _osso_af_context_t, _muali_context_t; typedef struct _muali_context_t { @@ -201,7 +203,7 @@ GArray *cp_plugins; int next_handler_id; /* next available handler id, unique in this context */ - const DBusMessage *reply_dummy; + const DBusMessage *reply_dummy, *error_dummy; } _muali_this_type_is_not_used_t; # ifdef LIBOSSO_DEBUG @@ -256,6 +258,9 @@ void __attribute__ ((visibility("hidden"))) make_default_object_path(const char *application, char *path); +void __attribute__ ((visibility("hidden"))) +make_default_error_name(const char *service, const char *name, + char *ready_name); gboolean __attribute__ ((visibility("hidden"))) _muali_set_handler(_muali_context_t *context, @@ -292,4 +297,11 @@ void _close_all_plugins(osso_context_t *osso); +inline void __attribute__ ((visibility("hidden"))) +_muali_parse_id(const char *id, muali_bus_type *bus, char *sender, + int *serial); + +inline void __attribute__ ((visibility("hidden"))) +_muali_make_id(muali_bus_type bus, const char *sender, int serial, char *id); + #endif /* OSSO_INTERNAL_H_ */ Modified: projects/haf/trunk/libosso/src/osso-rpc.c =================================================================== --- projects/haf/trunk/libosso/src/osso-rpc.c 2007-01-02 16:08:06 UTC (rev 8912) +++ projects/haf/trunk/libosso/src/osso-rpc.c 2007-01-03 07:43:42 UTC (rev 8913) @@ -35,6 +35,7 @@ #include "osso-internal.h" #include <assert.h> +#include <stdlib.h> static void _rpc_handler (osso_context_t * osso, DBusMessage * msg, @@ -1025,7 +1026,45 @@ * muali = maemo user application library ******************************************************/ +inline void __attribute__ ((visibility("hidden"))) +_muali_parse_id(const char *id, muali_bus_type *bus, char *sender, + int *serial) +{ + int i; + char buf[20], *p; + /* get bus type */ + for (i = 0, p = id; *p != ','; ++p, ++i) { + assert(*p != '\0'); + assert(i < 20); + buf[i] = *p; + } + buf[i] = '\0'; + *bus = atoi(buf); + /* get sender */ + ++p; + for (i = 0; *p != ','; ++p, ++i) { + assert(*p != '\0'); + assert(i <= MAX_SVC_LEN); + sender[i] = *p; + } + sender[i] = '\0'; + /* get serial */ + ++p; + for (i = 0; *p != '\0'; ++p, ++i) { + assert(i < 20); + buf[i] = *p; + } + buf[i] = '\0'; + *serial = atoi(buf); +} + +inline void __attribute__ ((visibility("hidden"))) +_muali_make_id(muali_bus_type bus, const char *sender, int serial, char *id) +{ + snprintf(id, MAX_MSGID_LEN, "%d,%s,%d", bus, sender, serial); +} + static void muali_reply_handler(osso_context_t *osso, DBusMessage *msg, _osso_callback_data_t *cb_data, @@ -1035,6 +1074,7 @@ DBusMessageIter iter; muali_handler_t *cb; int msgtype; + char id_buf[MAX_MSGID_LEN + 1]; ULOG_DEBUG_F("entered"); @@ -1053,25 +1093,40 @@ osso->reply_dummy = reply; } } + if (osso->error_dummy == NULL) { + DBusMessage *reply; + reply = dbus_message_new_error(msg, "org.foo.dummy", NULL); + if (reply == NULL) { + ULOG_WARN_F("could not create error_dummy"); + } else { + osso->error_dummy = reply; + } + } memset(&info, 0, sizeof(info)); + msgtype = dbus_message_get_type(msg); info.service = dbus_message_get_sender(msg); info.path = dbus_message_get_path(msg); info.interface = dbus_message_get_interface(msg); - info.name = dbus_message_get_member(msg); + if (msgtype == DBUS_MESSAGE_TYPE_ERROR) { + info.name = dbus_message_get_error_name(msg); + } else { + info.name = dbus_message_get_member(msg); + } info.bus_type = dbus_type; - info.message_id = dbus_message_get_serial(msg); + _muali_make_id(dbus_type, dbus_message_get_sender(msg), + dbus_message_get_serial(msg), id_buf); + info.message_id = id_buf; - msgtype = dbus_message_get_type(msg); info.event_type = muali_convert_msgtype(msgtype); - if (msgtype == DBUS_MESSAGE_TYPE_ERROR) { - info.error = dbus_message_get_error_name(msg); - } - if (dbus_message_iter_init(msg, &iter)) { info.args = _get_muali_args(&iter); + if (info.args != NULL && msgtype == DBUS_MESSAGE_TYPE_ERROR + && info.args[0].type == MUALI_TYPE_STRING) { + info.error = info.args[0].value.s; + } } cb = cb_data->user_cb; @@ -1085,14 +1140,147 @@ } } +#if 0 +muali_error_t muali_send_any(muali_context_t *context, + muali_handler_t *reply_handler, + const void *user_data, + const muali_event_info_t *info) +{ + DBusConnection *conn; + char service[MAX_SVC_LEN + 1], path_buf[MAX_OP_LEN + 1], + if_buf[MAX_IF_LEN + 1], *path, *interface, *destination; + int type; + + if (context == NULL || info == NULL) { + return MUALI_ERROR_INVALID; + } + + type = info->event_type; + if (type != MUALI_EVENT_MESSAGE && type != MUALI_EVENT_SIGNAL) { + ULOG_ERR_F("only MUALI_EVENT_MESSAGE and MUALI_EVENT_SIGNAL" + " event types are currently supported"); + return MUALI_ERROR_INVALID; + } + if (type == MUALI_EVENT_MESSAGE && + (info->service == NULL || info->name == NULL)) { + ULOG_ERR_F("service and name are required for " + "MUALI_EVENT_MESSAGE"); + return MUALI_ERROR_INVALID; + } + if (type == MUALI_EVENT_SIGNAL && + (info->path == NULL || info->interface == NULL + || info->name == NULL)) { + ULOG_ERR_F("service, interface and name are required for " + "MUALI_EVENT_SIGNAL"); + return MUALI_ERROR_INVALID; + } + + if (info->bus_type != MUALI_BUS_SESSION + && info->bus_type != MUALI_BUS_SYSTEM) { + ULOG_ERR_F("bus_type must be either MUALI_BUS_SESSION " + "or MUALI_BUS_SYSTEM"); + return MUALI_ERROR_INVALID; + } + + if (info->bus_type == MUALI_BUS_SESSION) { + conn = context->conn; + } else { + conn = context->sys_conn; + } + + if (!dbus_connection_get_is_connected(conn)) { + ULOG_ERR_F("connection %p is not open", conn); + return MUALI_ERROR_INVALID; + } + + if (reply_handler == NULL && user_data != NULL) { + ULOG_WARN_F("reply_handler == NULL: ignoring user_data " + "argument"); + fprintf(stderr, "Warning: reply_handler is NULL: ignoring" + " user_data argument"); + } + + destination = info->service; + make_default_service(destination, service); + if (info->path == NULL) { + make_default_object_path(destination, path_buf); + path = path_buf; + } else { + path = info->path; + } + if (info->interface == NULL) { + make_default_interface(destination, if_buf); + interface = if_buf; + } else { + interface = info->interface; + } +} +#endif + +muali_error_t muali_send_signal(muali_context_t *context, + muali_bus_type bus_type, + const char *signal_name, + const char *argument) +{ + DBusConnection *conn; + DBusMessage *msg; + dbus_bool_t ret; + + if (context == NULL || signal_name == NULL) { + return MUALI_ERROR_INVALID; + } + if (bus_type != MUALI_BUS_SESSION && bus_type != MUALI_BUS_SYSTEM) { + ULOG_ERR_F("bus_type must be either MUALI_BUS_SESSION " + "or MUALI_BUS_SYSTEM"); + return MUALI_ERROR_INVALID; + } + + if (bus_type == MUALI_BUS_SESSION) { + conn = context->conn; + } else { + conn = context->sys_conn; + } + + if (!dbus_connection_get_is_connected(conn)) { + ULOG_ERR_F("connection %p is not open", conn); + return MUALI_ERROR_INVALID; + } + + msg = dbus_message_new_signal(context->object_path, + context->interface, signal_name); + if (msg == NULL) { + ULOG_ERR_F("dbus_message_new_signal failed"); + return MUALI_ERROR_OOM; + } + + if (argument != NULL) { + ret = dbus_message_append_args(msg, DBUS_TYPE_STRING, + &argument, + DBUS_TYPE_INVALID); + if (!ret) { + ULOG_ERR_F("dbus_message_append_args failed"); + dbus_message_unref(msg); + return MUALI_ERROR; + } + } + + if (!dbus_connection_send(conn, msg, NULL)) { + ULOG_ERR_F("dbus_connection_send failed"); + dbus_message_unref(msg); + return MUALI_ERROR_OOM; + } + dbus_message_unref(msg); + + return MUALI_ERROR_SUCCESS; +} + muali_error_t muali_send_string(muali_context_t *context, muali_handler_t *reply_handler, const void *user_data, muali_bus_type bus_type, const char *destination, const char *message_name, - const char *string_to_send, - long *message_id) + const char *string_to_send) { char service[MAX_SVC_LEN + 1], path[MAX_OP_LEN + 1], interface[MAX_IF_LEN + 1]; @@ -1100,6 +1288,7 @@ DBusMessage *msg; DBusConnection *conn; int msg_serial = 0, handler_id; + dbus_bool_t ret; if (context == NULL) { return MUALI_ERROR_INVALID; @@ -1116,12 +1305,11 @@ return MUALI_ERROR_INVALID; } - if (reply_handler == NULL && (user_data != NULL - || message_id != NULL)) { - ULOG_WARN_F("reply_handler == NULL: ignoring user_data and " - "message_id arguments"); + if (reply_handler == NULL && user_data != NULL) { + ULOG_WARN_F("reply_handler == NULL: ignoring user_data " + "argument"); fprintf(stderr, "Warning: reply_handler is NULL: ignoring" - " user_data and message_id arguments"); + " user_data argument"); } if (bus_type == MUALI_BUS_SESSION) { @@ -1146,8 +1334,16 @@ goto _muali_send_oom; } - dbus_message_append_args(msg, DBUS_TYPE_STRING, &string_to_send, - DBUS_TYPE_INVALID); + if (string_to_send != NULL) { + ret = dbus_message_append_args(msg, DBUS_TYPE_STRING, + &string_to_send, + DBUS_TYPE_INVALID); + if (!ret) { + ULOG_ERR_F("dbus_message_append_args failed"); + dbus_message_unref(msg); + goto _muali_send_oom; + } + } if (reply_handler == NULL) { dbus_message_set_no_reply(msg, TRUE); @@ -1193,13 +1389,6 @@ if (_muali_set_handler((_muali_context_t*)context, muali_reply_handler, cb_data, handler_id, FALSE)) { - - if (message_id != NULL) { - /* the caller can use message_id to track - * the reply */ - *message_id = (long)msg_serial; - } - return MUALI_ERROR_SUCCESS; } else { ULOG_ERR_F("_muali_set_handler failed"); @@ -1212,17 +1401,30 @@ return MUALI_ERROR_OOM; } +muali_error_t muali_send_varargs(muali_context_t *context, + muali_handler_t *reply_handler, + const void *user_data, + muali_bus_type bus_type, + const char *destination, + const char *message_name, + int arg_type, ...) +{ + /* TODO */ + return MUALI_ERROR_OOM; +} + muali_error_t muali_reply_string(muali_context_t *context, - muali_bus_type bus_type, - const char *dest, - long message_id, + const char *message_id, const char *string) { DBusConnection *conn; DBusMessage *reply; dbus_bool_t ret; + char sender[MAX_SVC_LEN + 1]; + int serial; + muali_bus_type bus_type; - if (context == NULL || string == NULL || dest == NULL) { + if (context == NULL || string == NULL || message_id == NULL) { return MUALI_ERROR_INVALID; } if (context->reply_dummy == NULL) { @@ -1231,11 +1433,10 @@ ULOG_ERR_F("reply_dummy has not been created"); return MUALI_ERROR; } - if (bus_type != MUALI_BUS_SYSTEM && bus_type != MUALI_BUS_SESSION) { - ULOG_ERR_F("bus type must be either MUALI_BUS_SYSTEM or" - " MUALI_BUS_SESSION"); - return MUALI_ERROR_INVALID; - } + + _muali_parse_id(message_id, &bus_type, sender, &serial); + assert(bus_type == MUALI_BUS_SYSTEM || bus_type == MUALI_BUS_SESSION); + if (bus_type == MUALI_BUS_SYSTEM) { conn = context->sys_conn; } else { @@ -1246,18 +1447,17 @@ return MUALI_ERROR_INVALID; } - /* make a copy of the reply_dummy */ + /* make a copy of the reply_dummy and modify the copy */ reply = dbus_message_copy(context->reply_dummy); if (reply == NULL) { ULOG_ERR_F("dbus_message_copy failed"); return MUALI_ERROR_OOM; } - if (!dbus_message_set_destination(reply, dest)) { + if (!dbus_message_set_destination(reply, sender)) { ULOG_ERR_F("dbus_message_set_destination failed"); goto unref_and_exit; } - if (!dbus_message_set_reply_serial(reply, - (dbus_uint32_t)message_id)) { + if (!dbus_message_set_reply_serial(reply, serial)) { ULOG_ERR_F("dbus_message_set_reply_serial failed"); goto unref_and_exit; } @@ -1281,3 +1481,80 @@ return MUALI_ERROR_OOM; } +muali_error_t muali_reply_error(muali_context_t *context, + const char *message_id, + const char *name, + const char *message) +{ + DBusConnection *conn; + DBusMessage *reply; + dbus_bool_t ret; + char sender[MAX_SVC_LEN + 1], error_name[MAX_ERROR_LEN + 1]; + int serial; + muali_bus_type bus_type; + + if (context == NULL || name == NULL || message_id == NULL) { + return MUALI_ERROR_INVALID; + } + if (context->error_dummy == NULL) { + /* OOM has happened earlier in the handler, or + * the context is invalid */ + ULOG_ERR_F("error_dummy has not been created"); + return MUALI_ERROR; + } + + _muali_parse_id(message_id, &bus_type, sender, &serial); + assert(bus_type == MUALI_BUS_SYSTEM || bus_type == MUALI_BUS_SESSION); + + if (bus_type == MUALI_BUS_SYSTEM) { + conn = context->sys_conn; + } else { + conn = context->conn; + } + if (!dbus_connection_get_is_connected(conn)) { + ULOG_ERR_F("connection %p is not open", conn); + return MUALI_ERROR_INVALID; + } + + make_default_error_name(context->service, name, error_name); + + /* make a copy of the error_dummy and modify the copy */ + reply = dbus_message_copy(context->error_dummy); + if (reply == NULL) { + ULOG_ERR_F("dbus_message_copy failed"); + return MUALI_ERROR_OOM; + } + if (!dbus_message_set_destination(reply, sender)) { + ULOG_ERR_F("dbus_message_set_destination failed"); + goto unref_and_exit; + } + if (!dbus_message_set_reply_serial(reply, serial)) { + ULOG_ERR_F("dbus_message_set_reply_serial failed"); + goto unref_and_exit; + } + if (!dbus_message_set_error_name(reply, error_name)) { + ULOG_ERR_F("dbus_message_set_error_name failed"); + goto unref_and_exit; + } + + if (message != NULL) { + ret = dbus_message_append_args(reply, DBUS_TYPE_STRING, + &message, + DBUS_TYPE_INVALID); + if (!ret) { + ULOG_ERR_F("dbus_message_append_args failed"); + goto unref_and_exit; + } + } + + if (!dbus_connection_send(conn, reply, NULL)) { + ULOG_ERR_F("dbus_connection_send failed"); + goto unref_and_exit; + } + dbus_message_unref(reply); + return MUALI_ERROR_SUCCESS; + +unref_and_exit: + dbus_message_unref(reply); + return MUALI_ERROR_OOM; +}
- Previous message: [maemo-commits] r8912 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . src
- Next message: [maemo-commits] r8914 - in projects/haf/trunk/osso-af-startup: debian services
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]