MS_MEDIA_OTHER = 4, /**< Invalid Content*/
} media_type_e;
-typedef void (*db_update_cb)(int pid, /* mandatory */
+typedef void (*db_updated_cb)(int pid, /* mandatory */
media_item_type_e item, /* mandatory */
media_item_update_type_e update_type, /* mandatory */
- char* path, /* mandatory */
- char* uuid, /* optional */
+ char *path, /* mandatory */
+ char *uuid, /* optional */
media_type_e media_type, /* optional */
char *mime_type, /* optional */
void *user_data);
typedef void *MediaNotiHandle; /**< Handle */
-#define MS_MEDIA_DBUS_PATH "/com/mediaserver/dbus/notify"
-#define MS_MEDIA_DBUS_INTERFACE "com.mediaserver.dbus.Signal"
-#define MS_MEDIA_DBUS_MATCH_RULE "type='signal',interface='com.mediaserver.dbus.Signal'"
-
-
-int media_db_update_send_internal(int pid, /* mandatory */
+int media_db_update_send(int pid, /* mandatory */
media_item_type_e item, /* mandatory */
media_item_update_type_e update_type, /* mandatory */
- char* path, /* mandatory */
- char* uuid, /* optional */
+ const char *path, /* mandatory */
+ const char *uuid, /* optional */
media_type_e media_type, /* optional */
- char *mime_type /* optional */
+ const char *mime_type /* optional */
);
-int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb user_cb, void *user_data);
+int media_db_update_subscribe(MediaNotiHandle *handle, db_updated_cb user_cb, void *user_data);
-int media_db_update_unsubscribe_internal(MediaNotiHandle handle);
+int media_db_update_unsubscribe(MediaNotiHandle handle);
/**
#include "private.h"
static GList *handle_list;
-static GMutex mutex_internal;
+static GMutex noti_mutex;
-#define MS_MEDIA_DBUS_NAME_INTERNAL "ms_db_updated_internal"
+#define MS_DBUS_NAME "ms_db_updated"
+#define MS_DBUS_PATH "/com/mediaserver/dbus/notify"
+#define MS_DBUS_INTERFACE "com.mediaserver.dbus.Signal"
-typedef struct internal_noti_cb_data {
+typedef struct noti_cb_data {
GDBusConnection *gdbus;
int handler;
- db_update_cb user_callback;
+ db_updated_cb user_callback;
void *user_data;
-} internal_noti_cb_data;
+} noti_cb_data;
-int media_db_update_send_internal(int pid, /* mandatory */
+int media_db_update_send(int pid, /* mandatory */
media_item_type_e item, /* mandatory */
media_item_update_type_e update_type, /* mandatory */
- char* path, /* mandatory */
- char* uuid, /* optional */
+ const char *path, /* mandatory */
+ const char *uuid, /* optional */
media_type_e media_type, /* optional */
- char *mime_type /* optional */
+ const char *mime_type /* optional */
)
{
GVariant *message = NULL;
GDBusConnection *bus = NULL;
GError *error = NULL;
+ gboolean ret = FALSE;
bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!bus) {
if (item == MS_MEDIA_ITEM_FILE) {
MSAPI_DBG("FILE CHANGED");
- if (uuid != NULL && mime_type != NULL) {
- /* fill all datas */
+ if (uuid && mime_type)
message = g_variant_new("(iiissis)", item, pid, update_type, path, uuid, media_type, mime_type);
- } else {
+ else
MSAPI_DBG_ERR("uuid or mime_type is NULL");
- return MS_MEDIA_ERR_INTERNAL;
- }
} else if (item == MS_MEDIA_ITEM_DIRECTORY) {
MSAPI_DBG("DIRECTORY CHANGED");
- /* fill all datas */
- if (uuid != NULL)
+ if (uuid)
message = g_variant_new("(iiiss)", item, pid, update_type, path, uuid);
else
message = g_variant_new("(iiis)", item, pid, update_type, path);
MSAPI_DBG("this request is wrong");
}
- if (message == NULL) {
- MSAPI_DBG_ERR("g_dbus_message_new_signal failed");
- return MS_MEDIA_ERR_INTERNAL;
+ if (!message) {
+ g_object_unref(bus);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
/* Send the signal */
- gboolean emmiting = g_dbus_connection_emit_signal(
- bus,
- NULL,
- MS_MEDIA_DBUS_PATH,
- MS_MEDIA_DBUS_INTERFACE,
- MS_MEDIA_DBUS_NAME_INTERNAL,
- message,
- &error);
- if (!emmiting) {
- MSAPI_DBG_ERR("g_dbus_connection_emit_signal failed : %s", error ? error->message : "none");
- if (error) {
- MSAPI_DBG_ERR("Error in g_dbus_connection_emit_signal");
- g_object_unref(bus);
- g_error_free(error);
- }
+ ret = g_dbus_connection_emit_signal(bus, NULL, MS_DBUS_PATH, MS_DBUS_INTERFACE, MS_DBUS_NAME, message, &error);
+ g_object_unref(bus);
+ if (!ret) {
+ MSAPI_DBG_ERR("g_dbus_connection_emit_signal failed : %s", error->message);
+ g_error_free(error);
return MS_MEDIA_ERR_INTERNAL;
}
-
- g_object_unref(bus);
-
return MS_MEDIA_ERR_NONE;
}
static bool __gdbus_message_is_signal(const char *iface, const char *signal)
{
- if ((strcmp(iface, MS_MEDIA_DBUS_INTERFACE) == 0) && (strcmp(signal, MS_MEDIA_DBUS_NAME_INTERNAL) == 0))
- return TRUE;
+ if ((strcmp(iface, MS_DBUS_INTERFACE) == 0) && (strcmp(signal, MS_DBUS_NAME) == 0))
+ return true;
return false;
}
-static void __get_message_internal(GVariant *message, db_update_cb user_cb, void *userdata)
+static void __get_message(GVariant *message, db_updated_cb user_cb, void *userdata)
{
gint32 item = -1;
gint32 pid = 0;
content_type = MS_MEDIA_UNKNOWN;
/* getting data complete */
- user_cb(pid,
- item,
- update_type,
- update_path,
- uuid,
- content_type,
- mime_type,
- userdata);
+ user_cb(pid, item, update_type, update_path, uuid, content_type, mime_type, userdata);
MS_SAFE_FREE(update_path);
MS_SAFE_FREE(uuid);
MS_SAFE_FREE(mime_type);
-
}
-static void __message_filter_internal(GDBusConnection* connection,
- const gchar* sender_name,
- const gchar* object_path,
- const gchar* interface_name,
- const gchar* signal_name,
- GVariant* parameters,
+static void __message_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
gpointer user_data)
{
if (__gdbus_message_is_signal(interface_name, signal_name)) {
- db_update_cb user_cb = ((internal_noti_cb_data*)user_data)->user_callback;
- void *userdata = ((internal_noti_cb_data*)user_data)->user_data;
+ db_updated_cb user_cb = ((noti_cb_data *)user_data)->user_callback;
+ void *userdata = ((noti_cb_data *)user_data)->user_data;
- __get_message_internal(parameters, user_cb, userdata);
+ __get_message(parameters, user_cb, userdata);
}
}
-int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb user_cb, void *user_data)
+int media_db_update_subscribe(MediaNotiHandle *handle, db_updated_cb user_cb, void *user_data)
{
- int ret = MS_MEDIA_ERR_NONE;
int handler = 0;
- internal_noti_cb_data *noti_data = NULL;
+ noti_cb_data *noti_data = NULL;
GError *error = NULL;
GDBusConnection *gdbus = NULL;
if (gdbus == NULL) {
gdbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!gdbus) {
- MSAPI_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error ? error->message : "none");
+ MSAPI_DBG_ERR("Failed to connect to the g D-BUS daemon: %s", error->message);
g_error_free(error);
return MS_MEDIA_ERR_INTERNAL;
}
}
- MS_MALLOC(noti_data, sizeof(internal_noti_cb_data));
+ MS_MALLOC(noti_data, sizeof(noti_cb_data));
if (noti_data == NULL) {
MSAPI_DBG_ERR("MS_MALLOC failed");
- ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
- goto ERROR;
+ g_object_unref(gdbus);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
noti_data->user_callback = user_cb;
noti_data->user_data = user_data;
handler = g_dbus_connection_signal_subscribe(
gdbus,
NULL,
- MS_MEDIA_DBUS_INTERFACE,
- MS_MEDIA_DBUS_NAME_INTERNAL,
- MS_MEDIA_DBUS_PATH,
+ MS_DBUS_INTERFACE,
+ MS_DBUS_NAME,
+ MS_DBUS_PATH,
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
- __message_filter_internal,
+ __message_filter,
noti_data,
NULL);
noti_data->handler = handler;
*handle = noti_data;
- g_mutex_lock(&mutex_internal);
+ g_mutex_lock(¬i_mutex);
handle_list = g_list_append(handle_list, *handle);
- g_mutex_unlock(&mutex_internal);
+ g_mutex_unlock(¬i_mutex);
return MS_MEDIA_ERR_NONE;
-
-ERROR:
-
- if (gdbus != NULL) {
- g_object_unref(gdbus);
- gdbus = NULL;
- }
-
- MS_SAFE_FREE(noti_data);
-
- return ret;
}
-int media_db_update_unsubscribe_internal(MediaNotiHandle handle)
+int media_db_update_unsubscribe(MediaNotiHandle handle)
{
- internal_noti_cb_data *_handle = (internal_noti_cb_data *)handle;
+ noti_cb_data *_handle = (noti_cb_data *)handle;
GList *found = NULL;
MSAPI_RETVM_IF(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
- g_mutex_lock(&mutex_internal);
+ g_mutex_lock(¬i_mutex);
found = g_list_find(handle_list, handle);
if (!found) {
- g_mutex_unlock(&mutex_internal);
+ g_mutex_unlock(¬i_mutex);
MSAPI_DBG_ERR("Does not found handle");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
MS_SAFE_FREE(_handle->user_data);
MS_SAFE_FREE(_handle);
- g_mutex_unlock(&mutex_internal);
+ g_mutex_unlock(¬i_mutex);
return MS_MEDIA_ERR_NONE;
}