######################################################
lib_LTLIBRARIES = libmedia-utils.la
libmedia_utils_la_SOURCES = lib/media-util-noti-internal.c \
- lib/media-util-noti.c \
lib/media-util-ipc.c \
lib/media-util-db.c \
lib/media-util-register.c \
### includeheaders ###
includeheadersdir = $(includedir)/media-utils
-includeheaders_HEADERS = lib/include/media-util-noti-common.h \
- lib/include/media-util-noti-internal.h \
- lib/include/media-util-noti.h \
+includeheaders_HEADERS = lib/include/media-util-noti-internal.h \
lib/include/media-util-register.h \
lib/include/media-util-err.h \
lib/include/media-util-db.h \
+++ /dev/null
-/*
- * Media Utility
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _MEDIA_UTIL_NOTI_COMMON_H_
-#define _MEDIA_UTIL_NOTI_COMMON_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- MS_MEDIA_ITEM_FILE = 0,
- MS_MEDIA_ITEM_DIRECTORY = 1,
-} media_item_type_e;
-
-typedef enum {
- MS_MEDIA_ITEM_INSERT = 0,
- MS_MEDIA_ITEM_DELETE = 1,
- MS_MEDIA_ITEM_UPDATE = 2,
-} media_item_update_type_e;
-
-typedef enum {
- MS_MEDIA_UNKNOWN = -1, /**< Unknown Conntent*/
- MS_MEDIA_IMAGE = 0, /**< Image Content*/
- MS_MEDIA_VIDEO = 1, /**< Video Content*/
- MS_MEDIA_SOUND = 2, /**< Sound Content like Ringtone*/
- MS_MEDIA_MUSIC = 3, /**< Music Content like mp3*/
- MS_MEDIA_OTHER = 4, /**< Invalid Content*/
-} media_type_e;
-
-typedef void (*db_update_cb)(int pid, /* mandatory */
- media_item_type_e item, /* mandatory */
- media_item_update_type_e update_type, /* mandatory */
- char* path, /* mandatory */
- char* uuid, /* optional */
- media_type_e media_type, /* optional */
- char *mime_type, /* optional */
- void *user_data);
-
-typedef void (*clear_user_data_cb)(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'"
-
-/**
-* @}
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_MEDIA_UTIL_NOTI_COMMON_H_*/
extern "C" {
#endif
-#include "media-util-noti-common.h"
-
-/**
-* @fn int media_db_update_subscribe(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);
+typedef enum {
+ MS_MEDIA_ITEM_FILE = 0,
+ MS_MEDIA_ITEM_DIRECTORY = 1,
+} media_item_type_e;
+
+typedef enum {
+ MS_MEDIA_ITEM_INSERT = 0,
+ MS_MEDIA_ITEM_DELETE = 1,
+ MS_MEDIA_ITEM_UPDATE = 2,
+} media_item_update_type_e;
+
+typedef enum {
+ MS_MEDIA_UNKNOWN = -1, /**< Unknown Conntent*/
+ MS_MEDIA_IMAGE = 0, /**< Image Content*/
+ MS_MEDIA_VIDEO = 1, /**< Video Content*/
+ MS_MEDIA_SOUND = 2, /**< Sound Content like Ringtone*/
+ MS_MEDIA_MUSIC = 3, /**< Music Content like mp3*/
+ MS_MEDIA_OTHER = 4, /**< Invalid Content*/
+} media_type_e;
+
+typedef void (*db_update_cb)(int pid, /* mandatory */
+ media_item_type_e item, /* mandatory */
+ media_item_update_type_e update_type, /* mandatory */
+ char* path, /* mandatory */
+ char* uuid, /* optional */
+ media_type_e media_type, /* optional */
+ char *mime_type, /* optional */
+ void *user_data);
- media_db_update_subscribe(callback);
+typedef void (*clear_user_data_cb)(void * user_data);
- g_main_loop_run (loop);
+typedef void *MediaNotiHandle; /**< Handle */
- return 0;
-}
+#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 */
media_item_type_e item, /* mandatory */
+++ /dev/null
-/*
- * Media Utility
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _MEDIA_UTIL_NOTI_H_
-#define _MEDIA_UTIL_NOTI_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "media-util-noti-common.h"
-
-/**
-* @fn int media_db_update_subscribe(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;
-}
-
-*/
-
-int media_db_update_subscribe(db_update_cb user_cb, void *user_data);
-
-int media_db_update_unsubscribe(void);
-
-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 */
- media_type_e media_type, /* optional */
- char *mime_type /* optional */
- );
-
-/**
-* @}
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_MEDIA_UTIL_NOTI_H_*/
#include <media-util-err.h>
#include <media-util-register.h>
#include <media-util-db.h>
-#include <media-util-noti.h>
#include <media-util-noti-internal.h>
#include <media-util-ipc.h>
#include <media-util-cynara.h>
GDBusConnection *gdbus = NULL;
if (gdbus == NULL) {
-#if 0
- gchar *address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!address) {
- MSAPI_DBG_ERR("Failed to get the address: %s", error ? error->message : "none");
- g_error_free(error);
- return MS_MEDIA_ERR_INTERNAL;
- }
- MSAPI_DBG("\tType(%s)", address);
- gdbus = g_dbus_connection_new_for_address_sync(address, G_DBUS_CONNECTION_FLAGS_NONE, NULL, NULL, &error);
-#endif
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");
+++ /dev/null
-/*
- * Media Utility
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "media-util-internal.h"
-#include "media-util-dbg.h"
-#include "media-util.h"
-
-#include "private.h"
-
-static GDBusConnection *g_bus = NULL;
-static guint g_handler = 0;
-static void *g_data_store = NULL;
-static GMutex noti_mutex;
-static int ref_count = 0;
-
-#define MS_MEDIA_DBUS_NAME "ms_db_updated"
-
-typedef struct noti_callback_data {
- db_update_cb user_callback;
- void *user_data;
-} noti_callback_data;
-
-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) == 0))
- return TRUE;
-
- return FALSE;
-}
-
-static void __get_message(GVariant *message, db_update_cb user_cb, void *userdata)
-{
- gint32 item = -1;
- gint32 pid = 0;
- gint32 update_type = MS_MEDIA_UNKNOWN;
- gint32 content_type = -1;
- char *update_path = NULL;
- char *uuid = NULL;
- char *mime_type = NULL;
-
- int item_number = g_variant_n_children(message);
-
- if (item_number == 7)
- g_variant_get(message, "(iiissis)", &item, &pid, &update_type, &update_path, &uuid, &content_type, &mime_type);
- else if (item_number == 5)
- g_variant_get(message, "(iiiss)", &item, &pid, &update_type, &update_path, &uuid);
- else if (item_number == 4)
- g_variant_get(message, "(iiis)", &item, &pid, &update_type, &update_path);
-
- if (item == MS_MEDIA_ITEM_DIRECTORY)
- content_type = MS_MEDIA_UNKNOWN;
-
- /* getting data complete */
- 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(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 = ((noti_callback_data*)user_data)->user_callback;
- void *userdata = ((noti_callback_data*)user_data)->user_data;
-
- __get_message(parameters, user_cb, userdata);
- }
-}
-
-int media_db_update_subscribe(db_update_cb user_cb, void *user_data)
-{
- int ret = MS_MEDIA_ERR_NONE;
- GError *error = NULL;
- noti_callback_data *callback_data = NULL;
-
- g_mutex_lock(¬i_mutex);
-
- if (g_bus == NULL) {
- g_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!g_bus) {
- MSAPI_DBG("Failed to connect to the g D-BUS daemon: %s", error->message);
- g_error_free(error);
- ret = MS_MEDIA_ERR_INTERNAL;
- goto ERROR;
- }
-
- MS_MALLOC(callback_data, sizeof(noti_callback_data));
- if (callback_data == NULL) {
- MSAPI_DBG_ERR("MS_MALLOC failed");
- ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
- goto ERROR;
- }
- callback_data->user_callback = user_cb;
- callback_data->user_data = user_data;
-
- /* listening to messages from all objects as no path is specified */
- g_handler = g_dbus_connection_signal_subscribe(
- g_bus,
- NULL,
- MS_MEDIA_DBUS_INTERFACE,
- MS_MEDIA_DBUS_NAME,
- MS_MEDIA_DBUS_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- __message_filter,
- callback_data,
- NULL);
- g_data_store = (void *)callback_data;
- }
-
- ref_count++;
-
- g_mutex_unlock(¬i_mutex);
-
- return MS_MEDIA_ERR_NONE;
-
-ERROR:
-
- if (g_bus != NULL) {
- g_object_unref(g_bus);
- g_bus = NULL;
- }
- MS_SAFE_FREE(callback_data);
-
- g_mutex_unlock(¬i_mutex);
-
- return ret;
-}
-
-int media_db_update_unsubscribe(void)
-{
- if (g_bus == NULL)
- return MS_MEDIA_ERR_NONE;
-
- g_mutex_lock(¬i_mutex);
-
- if (ref_count == 1) {
- g_dbus_connection_signal_unsubscribe(g_bus, g_handler);
- g_object_unref(g_bus);
- g_bus = NULL;
-
- /*Release Callback*/
- MS_SAFE_FREE(g_data_store);
- g_data_store = NULL;
- }
-
- ref_count--;
-
- g_mutex_unlock(¬i_mutex);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-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 */
- media_type_e media_type, /* optional */
- char *mime_type /* optional */
- )
-{
- GVariant *message = NULL;
- GDBusConnection *bus = NULL;
- GError *error = NULL;
- char repl_path[MAX_FILEPATH_LEN] = {0, };
-#if !defined(_USE_SENIOR_MODE)
- char *tmp_path = NULL;
- const char *old_path = "/opt/usr/media";
-#endif
-
- bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!bus) {
- MSAPI_DBG("Failed to get gdbus connection: %s", error->message);
- g_error_free(error);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- memset(repl_path, 0, sizeof(repl_path));
-#if !defined(_USE_SENIOR_MODE)
- if (!_USE_TV_PATH) {
- /* Need uid to change path */
- if (strncmp(path, "/opt/usr/home", strlen("/opt/usr/home")) == 0) {
- tmp_path = strstr(path, MEDIA_CONTENT_PATH);
- snprintf(repl_path, sizeof(repl_path), "%s%s", old_path, tmp_path + strlen(MEDIA_CONTENT_PATH));
- } else {
- snprintf(repl_path, sizeof(repl_path), "%s", path);
- }
-
- MSAPI_DBG("New path: [%s]", repl_path);
- } else
-#endif
- {
- snprintf(repl_path, sizeof(repl_path), "%s", path);
- }
-
- if (item == MS_MEDIA_ITEM_FILE) {
- MSAPI_DBG("FILE CHANGED");
- if (uuid != NULL && mime_type != NULL) {
- /* fill all datas */
- message = g_variant_new("(iiissis)", item, pid, update_type, repl_path, uuid, media_type, mime_type);
- } else {
- MSAPI_DBG_ERR("uuid or mime_type is NULL");
- g_object_unref(bus);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- } else if (item == MS_MEDIA_ITEM_DIRECTORY) {
- MSAPI_DBG("DIRECTORY CHANGED");
- /* fill all datas */
- if (uuid != NULL)
- message = g_variant_new("(iiiss)", item, pid, update_type, repl_path, uuid);
- else
- message = g_variant_new("(iiis)", item, pid, update_type, repl_path);
- } else {
- MSAPI_DBG("this request is wrong");
- }
-
- gboolean emmiting = g_dbus_connection_emit_signal(
- bus,
- NULL,
- MS_MEDIA_DBUS_PATH,
- MS_MEDIA_DBUS_INTERFACE,
- MS_MEDIA_DBUS_NAME,
- 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);
- }
- return MS_MEDIA_ERR_INTERNAL;
- }
- MSAPI_DBG("success send notification");
-
- gboolean flush = FALSE;
- flush = g_dbus_connection_flush_sync(bus, NULL, &error);
- if (!flush) {
- MSAPI_DBG_ERR("g_dbus_connection_flush_sync failed");
- if (error) {
- MSAPI_DBG_ERR("error : [%s]", error->message);
- g_object_unref(bus);
- g_error_free(error);
- return MS_MEDIA_ERR_INTERNAL;
- }
- }
-
- g_object_unref(bus);
-
- /* Return TRUE to tell the event loop we want to be called again */
- return MS_MEDIA_ERR_NONE;
-}