4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@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.
27 #include <communicator.h>
28 #include <user_request.h>
30 #include "generated-code.h"
31 #include "dtapi_common.h"
33 #define TYPE_FACTORY (0x00020000)
34 #define MAKE_REQ_CMD(id) (TREQ_CUSTOM | TYPE_FACTORY | id)
35 #define GET_OEM_ID(cmd) (cmd & 0x0000FFFF)
37 static void _emit_oem_response(struct dbus_request_info *dbus_info,
38 int oem_id, const void *data, unsigned int data_len)
40 if (!dbus_info || !oem_id || !data || !data_len) {
41 dbg("Invalid Data! dbus_info=%p, oem_id=0x%x, data=%p, data_len=%d",
42 dbus_info, oem_id, data, data_len);
46 if (dbus_info->interface_object) {
47 gchar *encoded_data = g_base64_encode((const guchar*)data, data_len);
50 * Send Response if invocation is non-null,
51 * else Send Notification.
53 dbg("oem_id=0x%x, data=%p, data_len=%d", oem_id, data, data_len);
54 if (dbus_info->invocation) {
55 telephony_oem_complete_send_oem_data_with_response(dbus_info->interface_object,
56 dbus_info->invocation, oem_id, encoded_data);
58 telephony_oem_emit_oem_data(dbus_info->interface_object, oem_id, encoded_data);
65 static void _emit_oem_notification(TelephonyOEM *oem,
66 int oem_id, const void *data, unsigned int data_len)
68 gchar *encoded_data = NULL;
70 if (!oem || !oem_id || !data || !data_len) {
71 dbg("Invalid Data! oem_id=0x%x, data=%p, data_len=%d",
72 oem_id, data, data_len);
76 dbg("oem_id=0x%x, data=%p, data_len=%d", oem_id, data, data_len);
77 encoded_data = g_base64_encode((const guchar*)data, data_len);
78 telephony_oem_emit_oem_data(oem, oem_id, encoded_data);
82 static gboolean send_oem_data(TelephonyOEM *oem,
83 GDBusMethodInvocation *invocation,
85 const gchar *arg_data,
87 gboolean remove_invocation)
89 struct custom_data *ctx = user_data;
90 UserRequest *ur = NULL;
93 guchar *decoded_data = NULL;
96 ur = MAKE_UR(ctx, oem, invocation);
98 decoded_data = g_base64_decode(arg_data, &length);
99 tcore_user_request_set_data(ur, length, decoded_data);
100 g_free(decoded_data);
102 tcore_user_request_set_command(ur, MAKE_REQ_CMD(arg_oem_id));
104 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
105 if (ret != TCORE_RETURN_SUCCESS) {
106 FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
107 tcore_user_request_unref(ur);
111 if (remove_invocation) {
112 struct dbus_request_info *dbus_info = tcore_user_request_ref_user_info(ur);
114 dbus_info->invocation = NULL;
116 telephony_oem_complete_send_oem_data(oem, invocation, result);
122 static gboolean on_send_oem_data(TelephonyOEM *oem,
123 GDBusMethodInvocation *invocation,
125 const gchar *arg_data,
128 return send_oem_data(oem, invocation, arg_oem_id, arg_data, user_data, TRUE);
131 static gboolean on_send_oem_data_with_response(TelephonyOEM *oem,
132 GDBusMethodInvocation *invocation,
134 const gchar *arg_data,
137 return send_oem_data(oem, invocation, arg_oem_id, arg_data, user_data, FALSE);
140 gboolean dbus_plugin_setup_oem_interface(TelephonyObjectSkeleton *object,
141 struct custom_data *ctx)
145 oem = telephony_oem_skeleton_new();
146 telephony_object_skeleton_set_oem(object, oem);
150 dbg("oem = %p", oem);
153 * Register signal handlers for OEM interface
155 g_signal_connect(oem,
156 "handle-send-oem-data",
157 G_CALLBACK(on_send_oem_data), ctx);
159 g_signal_connect(oem,
160 "handle-send-oem-data-with-response",
161 G_CALLBACK(on_send_oem_data_with_response), ctx);
166 gboolean dbus_plugin_oem_response(struct custom_data *ctx,
167 UserRequest *ur, struct dbus_request_info *dbus_info,
168 enum tcore_response_command command, unsigned int data_len, const void *data)
170 _emit_oem_response(dbus_info, GET_OEM_ID(command), data, data_len);
175 gboolean dbus_plugin_oem_notification(struct custom_data *ctx,
176 CoreObject *source, TelephonyObjectSkeleton *object,
177 enum tcore_notification_command command, unsigned int data_len, const void *data)
179 _emit_oem_notification(telephony_object_peek_oem(TELEPHONY_OBJECT(object)),
180 GET_OEM_ID(command), data, data_len);