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);
123 g_dbus_method_invocation_return_value(req_info->context,
124 g_variant_new("(iv)", status, out_param));
126 _bt_delete_request_list(req_info->req_id);
128 g_variant_unref(result);
131 int bt_otp_server_init(int request_id, const char *directory)
133 BT_INFO("relative_path: [%s]", directory);
134 char *base_dir = g_strconcat(BT_OTP_BASE_DIR_PATH, directory, NULL);
138 otp_gproxy = _bt_core_gdbus_get_otp_proxy();
140 BT_DBG("Couldn't get service proxy");
142 return BLUETOOTH_ERROR_INTERNAL;
145 g_dbus_proxy_call(otp_gproxy,
149 G_DBUS_CALL_FLAGS_NONE, -1,
151 (GAsyncReadyCallback) server_init_cb,
152 GINT_TO_POINTER(request_id));
156 return BLUETOOTH_ERROR_NONE;
159 void server_deinit_cb(GObject *object, GAsyncResult *res,
162 BT_INFO("Server Deinit completed");
163 GError *error = NULL;
164 GVariant *result, *out_param, *param;
165 request_info_t *req_info = NULL;
166 int status = BLUETOOTH_ERROR_NONE;
167 bool server_state = false;
169 result = g_dbus_proxy_call_finish(otp_gproxy, res, &error);
171 if (result == NULL) {
172 BT_ERR("Dbus-RPC is failed\n");
174 BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
175 error->code, error->message);
176 g_clear_error(&error);
177 status = BLUETOOTH_ERROR_INTERNAL;
182 g_variant_get(result, "(i)", &status);
185 BT_DBG("Status [%d]", status);
187 param = g_variant_new("(ib)", status, server_state);
189 req_info = _bt_get_request_info(GPOINTER_TO_INT(user_data));
191 /* Send the event to application */
192 _bt_send_event(BT_OTP_EVENT,
193 BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED,
197 out_param = g_variant_new_from_data((const GVariantType *)"i",
198 result, sizeof(int), TRUE, NULL, NULL);
200 g_dbus_method_invocation_return_value(req_info->context,
201 g_variant_new("(iv)", status, out_param));
203 _bt_delete_request_list(req_info->req_id);
206 g_variant_unref(result);
209 g_object_unref(otp_gproxy);
214 int bt_otp_server_deinit(int request_id)
218 otp_gproxy = _bt_core_gdbus_get_otp_proxy();
220 BT_DBG("Couldn't get service proxy");
221 return BLUETOOTH_ERROR_INTERNAL;
224 g_dbus_proxy_call(otp_gproxy,
226 NULL, G_DBUS_CALL_FLAGS_NONE,
228 (GAsyncReadyCallback) server_deinit_cb,
229 GINT_TO_POINTER(request_id));
232 return BLUETOOTH_ERROR_NONE;