2 * Copyright (c) 2011 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.
22 #include <syspopup_caller.h>
24 #include <bundle_internal.h>
26 #include "bluetooth-api.h"
27 #include "bt-internal-types.h"
29 #include "bt-service-common.h"
30 #include "bt-service-device.h"
31 #include "bt-service-util.h"
32 #include "bt-service-event.h"
33 #include "bt-service-otp.h"
35 #define BT_OTP_SERVICE_NAME "org.projectx.otp"
36 #define BT_OTP_OBJECT_PATH "/org/projectx/otp"
37 #define BT_OTP_INTERFACE_NAME "org.projectx.otp_service"
39 #define BT_OTP_BASE_DIR_PATH "/home/owner/media/otp/"
41 static GDBusProxy *otp_gproxy;
43 static GDBusProxy *_bt_core_gdbus_init_otp_proxy(void)
47 GDBusConnection *conn;
51 conn = _bt_gdbus_get_system_gconn();
55 proxy = g_dbus_proxy_new_sync(conn,
56 G_DBUS_PROXY_FLAGS_NONE, NULL,
59 BT_OTP_INTERFACE_NAME,
63 BT_ERR("Unable to create proxy: %s", err->message);
74 GDBusProxy *_bt_core_gdbus_get_otp_proxy(void)
76 return (otp_gproxy) ? otp_gproxy : _bt_core_gdbus_init_otp_proxy();
79 void server_init_cb(GObject *object, GAsyncResult *res,
82 BT_INFO("Server Init completed");
84 GVariant *result, *out_param, *param;
85 request_info_t *req_info = NULL;
86 int status = BLUETOOTH_ERROR_NONE;
87 bool server_state = false;
89 result = g_dbus_proxy_call_finish(otp_gproxy, res, &error);
92 BT_ERR("Dbus-RPC is failed\n");
94 BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
95 error->code, error->message);
96 g_clear_error(&error);
97 status = BLUETOOTH_ERROR_INTERNAL;
102 g_variant_get(result, "(i)", &status);
105 BT_DBG("Status [%d]", status);
107 if (status == BLUETOOTH_ERROR_NONE)
110 param = g_variant_new("(ib)", status, server_state);
112 req_info = _bt_get_request_info(GPOINTER_TO_INT(user_data));
114 /* Send the event to application */
115 _bt_send_event(BT_OTP_EVENT,
116 BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED,
119 out_param = g_variant_new_from_data((const GVariantType *)"i",
120 result, sizeof(int), TRUE, NULL, NULL);
122 g_dbus_method_invocation_return_value(req_info->context,
123 g_variant_new("(iv)", status, out_param));
125 _bt_delete_request_list(req_info->req_id);
126 g_variant_unref(result);
129 int bt_otp_server_init(int request_id, const char *directory)
131 BT_INFO("relative_path: [%s]", directory);
132 char *base_dir = g_strconcat(BT_OTP_BASE_DIR_PATH, directory, NULL);
136 otp_gproxy = _bt_core_gdbus_get_otp_proxy();
138 BT_DBG("Couldn't get service proxy");
140 return BLUETOOTH_ERROR_INTERNAL;
143 g_dbus_proxy_call(otp_gproxy,
147 G_DBUS_CALL_FLAGS_NONE, -1,
149 (GAsyncReadyCallback) server_init_cb,
150 GINT_TO_POINTER(request_id));
154 return BLUETOOTH_ERROR_NONE;
157 void server_deinit_cb(GObject *object, GAsyncResult *res,
160 BT_INFO("Server Deinit completed");
161 GError *error = NULL;
162 GVariant *result, *out_param, *param;
163 request_info_t *req_info = NULL;
164 int status = BLUETOOTH_ERROR_NONE;
165 bool server_state = false;
167 result = g_dbus_proxy_call_finish(otp_gproxy, res, &error);
169 if (result == NULL) {
170 BT_ERR("Dbus-RPC is failed\n");
172 BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
173 error->code, error->message);
174 g_clear_error(&error);
175 status = BLUETOOTH_ERROR_INTERNAL;
180 g_variant_get(result, "(i)", &status);
183 BT_DBG("Status [%d]", status);
185 param = g_variant_new("(ib)", status, server_state);
187 req_info = _bt_get_request_info(GPOINTER_TO_INT(user_data));
189 /* Send the event to application */
190 _bt_send_event(BT_OTP_EVENT,
191 BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED,
195 out_param = g_variant_new_from_data((const GVariantType *)"i",
196 result, sizeof(int), TRUE, NULL, NULL);
198 g_dbus_method_invocation_return_value(req_info->context,
199 g_variant_new("(iv)", status, out_param));
201 _bt_delete_request_list(req_info->req_id);
204 g_variant_unref(result);
207 g_object_unref(otp_gproxy);
212 int bt_otp_server_deinit(int request_id)
216 otp_gproxy = _bt_core_gdbus_get_otp_proxy();
218 BT_DBG("Couldn't get service proxy");
219 return BLUETOOTH_ERROR_INTERNAL;
222 g_dbus_proxy_call(otp_gproxy,
224 NULL, G_DBUS_CALL_FLAGS_NONE,
226 (GAsyncReadyCallback) server_deinit_cb,
227 GINT_TO_POINTER(request_id));
230 return BLUETOOTH_ERROR_NONE;