From f28d880d2f69e252e8355b06517bc3062dd2e34a Mon Sep 17 00:00:00 2001 From: yy9875-kim Date: Tue, 21 Aug 2012 17:50:44 +0900 Subject: update latest code of media-server --- lib/include/.media-util-register.h.swp | Bin 12288 -> 0 bytes lib/include/media-util-err.h | 5 +++- lib/include/media-util-internal.h | 7 +++++ lib/include/media-util-noti.h | 39 ++++++++++++++++++++++++ lib/media-util-noti.c | 53 +++++++++++++++++++++++++++++++++ lib/media-util-register.c | 2 +- 6 files changed, 104 insertions(+), 2 deletions(-) delete mode 100644 lib/include/.media-util-register.h.swp (limited to 'lib') diff --git a/lib/include/.media-util-register.h.swp b/lib/include/.media-util-register.h.swp deleted file mode 100644 index c6c9aaf..0000000 Binary files a/lib/include/.media-util-register.h.swp and /dev/null differ diff --git a/lib/include/media-util-err.h b/lib/include/media-util-err.h index f658582..241742f 100755 --- a/lib/include/media-util-err.h +++ b/lib/include/media-util-err.h @@ -34,7 +34,7 @@ #define MS_ERROR(X) (X & MS_ERROR_MASKL16) #define MS_MEDIA_ERR_NONE 0 -#define MS_MEDIA_ERR_OCCURRED (MS_MEDIA_ERR_NONE - MS_ERROR(0x01)) +#define MS_MEDIA_ERR_OCCURRED (MS_MEDIA_ERR_NONE - MS_ERROR(0x01)) #define MS_MEDIA_ERR_INVALID_PARAMETER (MS_MEDIA_ERR_NONE - MS_ERROR(0x01)) /**< invalid parameter(s) */ #define MS_MEDIA_ERR_INVALID_PATH (MS_MEDIA_ERR_NONE - MS_ERROR(0x02)) /**< Invalid file path */ @@ -48,6 +48,9 @@ #define MS_MEDIA_ERR_INSERT_FAIL (MS_MEDIA_ERR_NONE - MS_ERROR(0x09))/**< DB insert fail */ #define MS_MEDIA_ERR_DRM_INSERT_FAIL (MS_MEDIA_ERR_NONE - MS_ERROR(0x0a))/**< DRM file insert fail */ +#define MS_MEDIA_ERR_DBUS_ADD_FILTER (MS_MEDIA_ERR_NONE - MS_ERROR(0x0b)) +#define MS_MEDIA_ERR_DBUS_GET (MS_MEDIA_ERR_NONE - MS_ERROR(0x0c)) + #define MS_MEDIA_ERR_UNKNOWN (MS_MEDIA_ERR_NONE - MS_ERROR(0x10)) /** +* @return This function returns 0 on success, and -1 on failure. +* @param[in] none +* @remark This function is recommandation for other application being aware of database updating.
+* @par example +* @code + +#include +#include +#include + +void callback() +{ + printf("listen dbus from media-server\n"); +} + +int +main (int argc, char **argv) +{ + GMainLoop *loop; + + loop = g_main_loop_new (NULL, FALSE); + + media_db_update_subscribe(callback); + + g_main_loop_run (loop); + + return 0; +} + +*/ + +typedef void (*db_update_cb)(void); + +int media_db_update_subscribe(db_update_cb user_cb); + + /** * @} */ diff --git a/lib/media-util-noti.c b/lib/media-util-noti.c index d647aa9..cdda750 100755 --- a/lib/media-util-noti.c +++ b/lib/media-util-noti.c @@ -32,12 +32,39 @@ #include #include #include +#include +#include +#include +#include #include "media-util-dbg.h" #include "media-util-err.h" #include "media-util-internal.h" #include "media-util-noti.h" +static DBusHandlerResult +__message_filter (DBusConnection *connection, DBusMessage *message, void *user_data) +{ + db_update_cb user_cb = user_data; + + /* A Ping signal on the com.burtonini.dbus.Signal interface */ + if (dbus_message_is_signal (message, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME)) { + DBusError error; + dbus_uint16_t noti_type; + + dbus_error_init (&error); + if (dbus_message_get_args (message, &error, DBUS_TYPE_UINT16, ¬i_type, DBUS_TYPE_INVALID)) { + MSAPI_DBG("noti type: %d\n", noti_type); + user_cb(); + } else { + MSAPI_DBG("messgae received, but error getting message: %s\n", error.message); + dbus_error_free (&error); + } + return DBUS_HANDLER_RESULT_HANDLED; + } + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + int ms_noti_update_complete(void) { int ret; @@ -52,3 +79,29 @@ return err; } +int media_db_update_subscribe(db_update_cb user_cb) +{ + DBusConnection *bus; + DBusError error; + + dbus_g_thread_init(); + + dbus_error_init (&error); + + bus = dbus_bus_get (DBUS_BUS_SESSION, &error); + if (!bus) { + MSAPI_DBG ("Failed to connect to the D-BUS daemon: %s", error.message); + dbus_error_free (&error); + return MS_MEDIA_ERR_DBUS_GET; + } + + dbus_connection_setup_with_g_main (bus, NULL); + + /* listening to messages from all objects as no path is specified */ + dbus_bus_add_match (bus, MS_MEDIA_DBUS_MATCH_RULE, &error); + if( !dbus_connection_add_filter (bus, __message_filter, user_cb, NULL)) + return MS_MEDIA_ERR_DBUS_ADD_FILTER; + + return MS_MEDIA_ERR_NONE; +} + diff --git a/lib/media-util-register.c b/lib/media-util-register.c index 7f0a24d..1d3a946 100755 --- a/lib/media-util-register.c +++ b/lib/media-util-register.c @@ -182,7 +182,7 @@ int media_list_free(media_list list) for(i = 0; i < len; i++) { data = g_array_index(list, char*, i); - free(data); + MS_SAFE_FREE(data); } g_array_free(list, TRUE); -- cgit v1.2.3