summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoryy9875-kim <yy9875-kim@yy9875-kim-Desktop.(none)>2012-08-21 17:50:44 +0900
committeryy9875-kim <yy9875-kim@yy9875-kim-Desktop.(none)>2012-08-21 17:50:44 +0900
commitf28d880d2f69e252e8355b06517bc3062dd2e34a (patch)
tree8f8dfc60be34732da93dd4e8bb7bc75037393cb0 /lib
parentf48e5455f367ed6e53b5978071c2b36c32817c4a (diff)
downloadmedia-server-f28d880d2f69e252e8355b06517bc3062dd2e34a.tar.gz
media-server-f28d880d2f69e252e8355b06517bc3062dd2e34a.tar.bz2
media-server-f28d880d2f69e252e8355b06517bc3062dd2e34a.zip
update latest code of media-server
Diffstat (limited to 'lib')
-rw-r--r--lib/include/.media-util-register.h.swpbin12288 -> 0 bytes
-rwxr-xr-xlib/include/media-util-err.h5
-rwxr-xr-xlib/include/media-util-internal.h7
-rwxr-xr-xlib/include/media-util-noti.h39
-rwxr-xr-xlib/media-util-noti.c53
-rwxr-xr-xlib/media-util-register.c2
6 files changed, 104 insertions, 2 deletions
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
--- a/lib/include/.media-util-register.h.swp
+++ /dev/null
Binary files 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)) /**<Unknown error*/
#endif /*_MEDIA_UTIL_ERR_H_*/
diff --git a/lib/include/media-util-internal.h b/lib/include/media-util-internal.h
index 690a367..f1922dd 100755
--- a/lib/include/media-util-internal.h
+++ b/lib/include/media-util-internal.h
@@ -31,6 +31,8 @@
#ifndef _MEDIA_UTIL_GLOBAL_H_
#define _MEDIA_UTIL_GLOBAL_H_
+#define MS_SAFE_FREE(src) { if(src) {free(src); src = NULL;} }
+
#define MS_MEDIA_TIMEOUT_SEC 10 /*timeout of waiting reponse for IPC*/
#define MS_MEDIA_UPDATE_NOTI_PATH "/opt/data/file-manager-service/_FILEOPERATION_END"
@@ -40,4 +42,9 @@
#define MS_MEDIA_PHONE_ROOT_PATH "/opt/media"
#define MS_MEDIA_MMC_ROOT_PATH "/opt/storage/sdcard"
+#define MS_MEDIA_DBUS_PATH "/com/mediaserver/dbus/notify"
+#define MS_MEDIA_DBUS_INTERFACE "com.mediaserver.dbus.Signal"
+#define MS_MEDIA_DBUS_NAME "ms_db_updated"
+#define MS_MEDIA_DBUS_MATCH_RULE "type='signal',interface='com.mediaserver.dbus.Signal'"
+
#endif /*_MEDIA_UTIL_GLOBAL_H_*/
diff --git a/lib/include/media-util-noti.h b/lib/include/media-util-noti.h
index 27535d8..3ebb97b 100755
--- a/lib/include/media-util-noti.h
+++ b/lib/include/media-util-noti.h
@@ -75,6 +75,45 @@ extern "C" {
int ms_noti_update_complete(void);
/**
+* @fn int ms_noti_db_update_complete(void);
+* @brief This function announce media database is updated to other applications.<br>
+* @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.<br>
+* @par example
+* @code
+
+#include <stdio.h>
+#include <glib.h>
+#include <media-util-noti.h>
+
+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 <sys/types.h>
#include <sys/stat.h>
#include <string.h>
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
#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, &noti_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);