2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <sys/types.h>
25 #include <notification.h>
26 #include <notification_db.h>
27 #include <notification_list.h>
28 #include <notification_noti.h>
29 #include <notification_debug.h>
30 #include <notification_private.h>
31 #include <notification_status.h>
32 #include <notification_status_internal.h>
34 #define PATH_NAME "/Org/Tizen/System/Notification/Status_message"
35 #define INTERFACE_NAME "org.tizen.system.notification.status_message"
36 #define MEMBER_NAME "status_message"
38 struct _message_cb_data {
39 notification_status_message_cb callback;
41 GDBusConnection *conn;
45 static struct _message_cb_data md;
47 static void __notification_status_message_dbus_callback(GDBusConnection *connection,
48 const gchar *sender_name,
49 const gchar *object_path,
50 const gchar *interface_name,
51 const gchar *signal_name,
57 g_variant_get(parameters, "(&s)", &message);
58 if (strlen(message) <= 0) {
60 ERR("message is NULL");
72 md.callback(message, md.data);
76 int notification_status_monitor_message_cb_set(notification_status_message_cb callback, void *user_data)
81 return NOTIFICATION_ERROR_INVALID_PARAMETER;
83 if (md.conn == NULL) {
84 md.conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
85 if (md.conn == NULL) {
87 ERR("Failed to connect to the D-BUS Daemon[%s]",
90 return NOTIFICATION_ERROR_FROM_DBUS;
96 md.message_id = g_dbus_connection_signal_subscribe(md.conn,
102 G_DBUS_SIGNAL_FLAGS_NONE,
103 __notification_status_message_dbus_callback,
106 if (md.message_id == 0) {
107 /* LCOV_EXCL_START */
108 ERR("Failed to subscribe signal");
109 g_object_unref(md.conn);
110 return NOTIFICATION_ERROR_FROM_DBUS;
115 md.callback = callback;
118 return NOTIFICATION_ERROR_NONE;
122 int notification_status_monitor_message_cb_unset(void)
125 g_dbus_connection_signal_unsubscribe(md.conn, md.message_id);
130 g_object_unref(md.conn);
137 return NOTIFICATION_ERROR_NONE;
141 int notification_status_message_post(const char *message)
144 GDBusConnection *conn;
146 int ret = NOTIFICATION_ERROR_NONE;
149 ERR("message is NULL");
150 return NOTIFICATION_ERROR_INVALID_PARAMETER;
153 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
155 /* LCOV_EXCL_START */
156 ERR("Failed to connect to the D-BUS Daemon[%s]",
158 ret = NOTIFICATION_ERROR_FROM_DBUS;
163 param = g_variant_new("(s)", message);
165 if (g_dbus_connection_emit_signal(conn,
172 /* LCOV_EXCL_START */
173 ERR("Failed to emit signal[%s]",
175 ret = NOTIFICATION_ERROR_FROM_DBUS;
180 if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) {
181 /* LCOV_EXCL_START */
182 ERR("Failed to flush connection sync[%s]",
184 ret = NOTIFICATION_ERROR_FROM_DBUS;
191 g_error_free(err); /* LCOV_EXCL_LINE */
194 g_object_unref(conn);