4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
23 * email-core-signal.c
\r
25 * Created on: 2012. 11. 22.
\r
26 * Author: kyuho.jo@samsung.com
\r
28 #include <dbus/dbus.h>
\r
30 #include "email-core-signal.h"
\r
31 #include "email-core-utils.h"
\r
32 #include "email-internal-types.h"
\r
33 #include "email-debug-log.h"
\r
35 #define EMAIL_STORAGE_CHANGE_NOTI "User.Email.StorageChange"
\r
36 #define EMAIL_NETOWRK_CHANGE_NOTI "User.Email.NetworkStatus"
\r
37 #define EMAIL_RESPONSE_TO_API_NOTI "User.Email.ResponseToAPI"
\r
39 #define DBUS_SIGNAL_PATH_FOR_TASK_STATUS "/User/Email/TaskStatus"
\r
40 #define DBUS_SIGNAL_INTERFACE_FOR_TASK_STATUS "User.Email.TaskStatus"
\r
41 #define DBUS_SIGNAL_NAME_FOR_TASK_STATUS "email"
\r
43 static pthread_mutex_t _dbus_noti_lock = PTHREAD_MUTEX_INITIALIZER;
\r
47 _NOTI_TYPE_STORAGE = 0,
\r
48 _NOTI_TYPE_NETWORK = 1,
\r
49 _NOTI_TYPE_RESPONSE_TO_API = 2,
\r
52 INTERNAL_FUNC int emcore_initialize_signal()
\r
54 return EMAIL_ERROR_NONE;
\r
57 INTERNAL_FUNC int emcore_finalize_signal()
\r
59 DELETE_CRITICAL_SECTION(_dbus_noti_lock);
\r
60 return EMAIL_ERROR_NONE;
\r
63 static int emcore_send_signal(enotitype_t notiType, int subType, int data1, int data2, char *data3, int data4)
\r
65 EM_DEBUG_FUNC_BEGIN();
\r
66 EM_PROFILE_BEGIN(profile_emcore_send_signal);
\r
69 DBusConnection *connection;
\r
70 DBusMessage *signal = NULL;
\r
71 DBusError dbus_error;
\r
72 dbus_uint32_t error;
\r
73 const char *nullString = "";
\r
75 ENTER_CRITICAL_SECTION(_dbus_noti_lock);
\r
77 dbus_error_init (&dbus_error);
\r
78 connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
\r
80 if (connection == NULL) {
\r
81 EM_DEBUG_LOG("dbus_bus_get is failed");
\r
85 if (notiType == _NOTI_TYPE_STORAGE) {
\r
86 signal = dbus_message_new_signal("/User/Email/StorageChange", EMAIL_STORAGE_CHANGE_NOTI, "email");
\r
88 if (signal == NULL) {
\r
89 EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
\r
92 EM_DEBUG_LOG("/User/Email/StorageChange Signal is created by dbus_message_new_signal");
\r
94 dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
\r
95 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
\r
96 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
\r
98 dbus_message_append_args(signal, DBUS_TYPE_STRING, &nullString, DBUS_TYPE_INVALID);
\r
100 dbus_message_append_args(signal, DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID);
\r
101 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
\r
103 else if (notiType == _NOTI_TYPE_NETWORK) {
\r
104 signal = dbus_message_new_signal("/User/Email/NetworkStatus", EMAIL_NETOWRK_CHANGE_NOTI, "email");
\r
106 if (signal == NULL) {
\r
107 EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
\r
111 EM_DEBUG_LOG("/User/Email/NetworkStatus Signal is created by dbus_message_new_signal");
\r
113 dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
\r
114 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
\r
116 dbus_message_append_args(signal, DBUS_TYPE_STRING, &nullString, DBUS_TYPE_INVALID);
\r
118 dbus_message_append_args(signal, DBUS_TYPE_STRING, &data3, DBUS_TYPE_INVALID);
\r
119 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
\r
120 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
\r
122 else if (notiType == _NOTI_TYPE_RESPONSE_TO_API) {
\r
123 signal = dbus_message_new_signal("/User/Email/ResponseToAPI", EMAIL_RESPONSE_TO_API_NOTI, "email");
\r
125 if (signal == NULL) {
\r
126 EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
\r
130 EM_DEBUG_LOG("/User/Email/ResponseToAPI Signal is created by dbus_message_new_signal");
\r
132 dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
\r
133 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
\r
134 dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
\r
137 EM_DEBUG_EXCEPTION("Wrong notification type [%d]", notiType);
\r
138 error = EMAIL_ERROR_IPC_CRASH;
\r
142 if (!dbus_connection_send(connection, signal, &error)) {
\r
143 EM_DEBUG_LOG("dbus_connection_send is failed [%d]", error);
\r
146 EM_DEBUG_LOG("dbus_connection_send is successful");
\r
150 /* EM_DEBUG_LOG("Before dbus_connection_flush"); */
\r
151 /* dbus_connection_flush(connection); */
\r
152 /* EM_DEBUG_LOG("After dbus_connection_flush"); */
\r
157 dbus_message_unref(signal);
\r
159 LEAVE_CRITICAL_SECTION(_dbus_noti_lock);
\r
160 EM_PROFILE_END(profile_emcore_send_signal);
\r
161 EM_DEBUG_FUNC_END("ret [%d]", ret);
\r
166 INTERNAL_FUNC int emcore_notify_storage_event(email_noti_on_storage_event transaction_type, int data1, int data2 , char *data3, int data4)
\r
168 EM_DEBUG_FUNC_BEGIN("transaction_type[%d], data1[%d], data2[%d], data3[%p], data4[%d]", transaction_type, data1, data2, data3, data4);
\r
169 return emcore_send_signal(_NOTI_TYPE_STORAGE, (int)transaction_type, data1, data2, data3, data4);
\r
172 INTERNAL_FUNC int emcore_notify_network_event(email_noti_on_network_event status_type, int data1, char *data2, int data3, int data4)
\r
174 EM_DEBUG_FUNC_BEGIN("status_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", status_type, data1, data2, data3, data4);
\r
175 return emcore_send_signal(_NOTI_TYPE_NETWORK, (int)status_type, data1, data3, data2, data4);
\r
178 INTERNAL_FUNC int emcore_notify_response_to_api(email_event_type_t event_type, int data1, int data2)
\r
180 EM_DEBUG_FUNC_BEGIN("event_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", event_type, data1, data2);
\r
181 return emcore_send_signal(_NOTI_TYPE_RESPONSE_TO_API, (int)event_type, data1, data2, NULL, 0);
\r
184 INTERNAL_FUNC int emcore_send_task_status_signal(email_task_type_t input_task_type, int input_task_id, email_task_status_type_t input_task_status, int input_param_1, int input_param_2)
\r
186 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_id [%d] input_task_status [%d] input_param_1 [%d] input_param_2 [%d]", input_task_type, input_task_id, input_task_status, input_param_1, input_param_2);
\r
188 int err = EMAIL_ERROR_NONE;
\r
189 DBusConnection *connection;
\r
190 DBusMessage *signal = NULL;
\r
191 DBusError dbus_error;
\r
192 dbus_uint32_t error;
\r
194 ENTER_CRITICAL_SECTION(_dbus_noti_lock);
\r
196 dbus_error_init (&dbus_error);
\r
197 connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
\r
199 if (connection == NULL) {
\r
200 EM_DEBUG_LOG("dbus_bus_get is failed");
\r
204 signal = dbus_message_new_signal(DBUS_SIGNAL_PATH_FOR_TASK_STATUS, DBUS_SIGNAL_INTERFACE_FOR_TASK_STATUS, DBUS_SIGNAL_NAME_FOR_TASK_STATUS);
\r
206 if (signal == NULL) {
\r
207 EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
\r
210 EM_DEBUG_LOG("Signal for task status has been created by dbus_message_new_signal");
\r
212 dbus_message_append_args(signal, DBUS_TYPE_INT32, &input_task_type, DBUS_TYPE_INVALID);
\r
213 dbus_message_append_args(signal, DBUS_TYPE_INT32, &input_task_id, DBUS_TYPE_INVALID);
\r
214 dbus_message_append_args(signal, DBUS_TYPE_INT32, &input_task_status, DBUS_TYPE_INVALID);
\r
215 dbus_message_append_args(signal, DBUS_TYPE_INT32, &input_param_1, DBUS_TYPE_INVALID);
\r
216 dbus_message_append_args(signal, DBUS_TYPE_INT32, &input_param_2, DBUS_TYPE_INVALID);
\r
218 if (!dbus_connection_send(connection, signal, &error)) {
\r
219 EM_DEBUG_LOG("dbus_connection_send is failed [%d]", error);
\r
222 EM_DEBUG_LOG("dbus_connection_send is successful");
\r
225 /* EM_DEBUG_LOG("Before dbus_connection_flush"); */
\r
226 /* dbus_connection_flush(connection); */
\r
227 /* EM_DEBUG_LOG("After dbus_connection_flush"); */
\r
231 dbus_message_unref(signal);
\r
233 LEAVE_CRITICAL_SECTION(_dbus_noti_lock);
\r
234 EM_DEBUG_FUNC_END("err [%d]", err);
\r