4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * This file defines api utilities of contents manager engines.
25 * @file media-util-noti.c
26 * @author Yong Yeon Kim(yy9875.kim@samsung.com)
31 #include <sys/errno.h>
32 #include <sys/types.h>
36 #include <dbus/dbus-glib.h>
37 #include <dbus/dbus.h>
38 #include <dbus/dbus-glib-lowlevel.h>
40 #include "media-util-internal.h"
41 #include "media-util-dbg.h"
42 #include "media-util.h"
44 static DBusHandlerResult
45 __message_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
47 db_update_cb user_cb = user_data;
49 /* A Ping signal on the com.burtonini.dbus.Signal interface */
50 if (dbus_message_is_signal (message, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME)) {
52 dbus_uint16_t noti_type;
54 dbus_error_init (&error);
55 if (dbus_message_get_args (message, &error, DBUS_TYPE_UINT16, ¬i_type, DBUS_TYPE_INVALID)) {
56 MSAPI_DBG("noti type: %d\n", noti_type);
59 MSAPI_DBG("messgae received, but error getting message: %s\n", error.message);
60 dbus_error_free (&error);
62 return DBUS_HANDLER_RESULT_HANDLED;
64 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
67 int media_db_update_subscribe(db_update_cb user_cb)
74 dbus_error_init (&error);
76 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
78 MSAPI_DBG ("Failed to connect to the D-BUS daemon: %s", error.message);
79 dbus_error_free (&error);
80 return MS_MEDIA_ERR_DBUS_GET;
83 dbus_connection_setup_with_g_main (bus, NULL);
85 /* listening to messages from all objects as no path is specified */
86 dbus_bus_add_match (bus, MS_MEDIA_DBUS_MATCH_RULE, &error);
87 if( !dbus_connection_add_filter (bus, __message_filter, user_cb, NULL))
88 return MS_MEDIA_ERR_DBUS_ADD_FILTER;
90 return MS_MEDIA_ERR_NONE;