2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Suresh Kumar N (suresh.n@samsung.com)
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include <zblib_service.h>
28 #include <zblib_service_interface.h>
30 #include "zigbee_service_interface.h"
31 #include "zigbee_service_interface_common.h"
32 #include "zigbee_service_dbus_interface.h"
34 /**< ZigBee D-BUS response callback data */
35 struct zigbee_service_interface_resp_cb_type {
36 void *interface_object; /**< D-BUS interface object */
37 GDBusMethodInvocation *invocation; /**< D-BUS invocation */
38 char user_data[0]; /* Additional user data base pointer */
41 ZigbeeServiceInterfaceRespCbData_t *
42 zigbee_service_dbus_interface_create_resp_cb_data(void *interface_object,
43 GDBusMethodInvocation *invocation,
44 void *user_data, unsigned int user_data_len)
46 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
48 /* Allocate memory for response callback data */
49 resp_cb_data = g_malloc0(sizeof(ZigbeeServiceInterfaceRespCbData_t) + user_data_len);
51 /* Update interface object and invocation */
52 resp_cb_data->interface_object = interface_object;
53 resp_cb_data->invocation = invocation;
55 /* Update user data */
56 if ((user_data != NULL) && (user_data_len > 0))
57 memcpy(resp_cb_data->user_data, user_data, user_data_len);
62 void zigbee_service_dbus_interface_destroy_resp_cb_data(ZigbeeServiceInterfaceRespCbData_t *resp_cb_data)
64 if (NULL == resp_cb_data) {
65 Z_LOGE("resp_cb_data is NULL");
69 /* Free response callback data */
73 void *zigbee_service_dbus_interface_ref_interface_object(ZigbeeServiceInterfaceRespCbData_t *resp_cb_data)
75 zblib_check_null_ret_error("resp_cb_data", resp_cb_data, NULL);
76 return resp_cb_data->interface_object;
79 GDBusMethodInvocation *
80 zigbee_service_dbus_interface_ref_invocation(ZigbeeServiceInterfaceRespCbData_t *resp_cb_data)
82 zblib_check_null_ret_error("resp_cb_data", resp_cb_data, NULL);
83 return resp_cb_data->invocation;
86 gboolean zigbee_service_dbus_interface_dispatch_request(ZigBeeServiceInterface *service_interface,
87 ZblibDriverType_e driver_type, guint ops_id,
88 gpointer request_data, guint request_data_len,
89 ZblibServiceInterfaceResponseCb_t resp_cb, gpointer resp_cb_data)
94 /* Create request_id */
95 request_id = zblib_service_interface_new_request(service_interface,
98 request_data, request_data_len,
99 resp_cb, resp_cb_data);
100 if (ZIGBEE_SERVICE_INTERFACE_INVALID_REQUEST_ID == request_id) {
101 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
106 /* Dispatch request */
107 ret = zblib_service_interface_dispatch_request(service_interface, request_id);
109 Z_LOGE("zblib_service_interface_dispatch_request failed!");
111 /* Free request_id */
112 zblib_service_interface_free_request(service_interface, request_id);