#include "zigbee_service_interface_common.h"
+#include <zblib_driver_service.h>
+
+static void *_service_interface_ref_zigbee_service(ZigBeeServiceInterface *service_interface)
+{
+ ZigbeeObjectSkeleton *zigbee_object = NULL;
+ ZigbeeCustomData_t *custom_data = NULL;
+ ZigbeeService *service = NULL;
+
+ custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
+ if (NULL == custom_data) {
+ Z_LOGE("D-BUS service interface custom_data is NULL!");
+ return NULL;
+ }
+
+ /* Get zigbee object */
+ zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
+ if (NULL == zigbee_object) {
+ Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
+ return NULL;
+ }
+
+ service = zigbee_object_get_service(ZIGBEE_OBJECT(zigbee_object));
+ return service;
+}
+
+static void on_service_enable_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeServiceServiceStateResp_t *payload =
+ (ZigbeeServiceServiceStateResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_enable(service_object, invocation,
+ payload->result, payload->enabled);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_enable(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_ENABLE,
+ NULL, 0,
+ on_service_enable_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_disable_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_disable(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_disable(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_DISABLE,
+ NULL, 0,
+ on_service_disable_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_zb_hw_reset(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_zb_hw_reset(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_ZB_HW_RESET,
+ NULL, 0,
+ on_service_zb_hw_reset_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_form_network_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_form_network(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_form_network(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_FORM_NETWORK,
+ NULL, 0,
+ on_service_form_network_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_coex_start(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_coex_start(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gchar channel,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceCoexStart_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(channel);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ memset(&req, 0x0, sizeof(ZigbeeServiceCoexStart_t));
+
+ /* Update request structure */
+ req.channel = channel;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_COEX_START,
+ &req, sizeof(req),
+ on_service_coex_start_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_coex_stop(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_coex_stop(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_COEX_STOP,
+ NULL, 0,
+ on_service_coex_stop_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_leave_network(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_leave_network(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_LEAVE_NETWORK,
+ NULL, 0,
+ on_service_leave_network_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+
+ ZigbeeServiceGetNetworkInfoResp_t *payload =
+ (ZigbeeServiceGetNetworkInfoResp_t*)resp_data;
+
+ GVariant *v_eui64 = NULL;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+
+ zigbee_service_complete_get_network_info(service_object, invocation,
+ payload->result, v_eui64, payload->node_id,
+ payload->pan_id, payload->channel, payload->radio_tx_power);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_network_info(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_NETWORK_INFO,
+ NULL, 0,
+ on_service_get_network_info_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_permit_join(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_permit_join(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gint duration,
- gboolean broadcast_mgmt_permit_join,
+ gboolean permit_join,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServicePermitJoin_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(duration);
- NOT_USED(broadcast_mgmt_permit_join);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ memset(&req, 0x0, sizeof(ZigbeeServicePermitJoin_t));
+
+ /* Update request structure */
+ req.duration = duration;
+ req.permit_join = permit_join;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_PERMIT_JOIN,
+ &req, sizeof(req),
+ on_service_permit_join_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t*)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_leave_request(service_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_leave_request(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
GVariant *eui64,
gchar rejoin,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceLeaveRequest_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(eui64);
- NOT_USED(remove_child);
- NOT_USED(rejoin);
+ GVariantIter *iter = NULL;
+ guint i = 0;
- /*
- * TODO -
- * Create and send request for processing
- */
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
+
+ /* Update request structure */
+ g_variant_get(eui64, "a(y)", &iter);
+ while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
+ i++;
+ if (i >= ZIGBEE_EUI64_SIZE)
+ break;
+ }
+ req.remove_child = remove_child;
+ req.rejoin = rejoin;
+
+ Z_LOGD("IEEE Address = %X:%X:%X:%X:%X:%X:%X:%X",
+ req.eui64[0], req.eui64[1], req.eui64[2], req.eui64[3],
+ req.eui64[4], req.eui64[5], req.eui64[6], req.eui64[7]);
+ Z_LOGD("remove_child [%d]", remove_child);
+ Z_LOGD("rejoin [%d]", rejoin);
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_LEAVE_REQUEST,
+ &req, sizeof(req),
+ on_service_leave_request_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_device_list_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ /* To-To : zigbee_service_complete_get_device_list */
+ //zigbee_service_complete_get_device_list(service_object, invocation, resp_data);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_device_list(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_DEVICE_LIST,
+ NULL, 0,
+ on_service_get_device_list_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeServiceGetMacResp_t *payload =
+ (ZigbeeServiceGetMacResp_t*)resp_data;
+
+ GVariant *v_eui64 = NULL;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ payload->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+
+ zigbee_service_complete_get_mac(service_object, invocation, payload->result,
+ v_eui64);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_mac(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_MAC,
+ NULL, 0,
+ on_service_get_mac_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeServiceGetDeviceInfoResp_t *payload =
+ (ZigbeeServiceGetDeviceInfoResp_t*)resp_data;
+
+ GVariant *variant = NULL;
+ GVariantBuilder* builder = NULL;
+ int i = 0;
+ int index = 0;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE ("a(qyayyay)"));
+ for (index = 0; index < payload->count; index++) {
+ ZigbeeServiceGetDeviceInfoDetailResp_t *device = &(payload->list[index]);
+ GVariantBuilder* mac_builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
+ GVariantBuilder* endpoint_builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
+
+ for (i = 0; i < ZIGBEE_EUI64_SIZE; i++) {
+ g_variant_builder_add (mac_builder, "y", device->eui64[i]);
+ }
+ for (i = 0; i < device->endpoint_count; i++) {
+ g_variant_builder_add (endpoint_builder, "y", device->endpoints[i]);
+ }
+
+ g_variant_builder_add (builder, "(qyayyay)",
+ device->node_id, device->node_type,
+ mac_builder, device->endpoint_count, endpoint_builder);
+
+ g_variant_builder_unref (mac_builder);
+ g_variant_builder_unref (endpoint_builder);
+ }
+
+ variant = g_variant_builder_end(builder);
+ zigbee_service_complete_get_device_info(service_object, invocation,
+ payload->result, variant);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_device_info(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_DEVICE_INFO,
+ NULL, 0,
+ on_service_get_device_info_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeServiceGetEndpointListResp_t *payload =
+ (ZigbeeServiceGetEndpointListResp_t*)resp_data;
+ GVariant *v_endpoints = NULL;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ payload->endpoints, payload->endpoint_count, TRUE, NULL, NULL);
+
+ zigbee_service_complete_get_endpoint_list(service_object, invocation,
+ payload->result, v_endpoints);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
GVariant *eui64,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceGetEndpointList_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(eui64);
+ GVariantIter *iter = NULL;
+ guint i = 0;
- /*
- * TODO -
- * Create and send request for processing
- */
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
+
+ /* Update request structure */
+ g_variant_get(eui64, "a(y)", &iter);
+ while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
+ i++;
+ if (i >= ZIGBEE_EUI64_SIZE)
+ break;
+ }
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST,
+ &req, sizeof(req),
+ on_service_get_endpoint_list_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeServiceGetClusterListResp_t *payload =
+ (ZigbeeServiceGetClusterListResp_t*)resp_data;
+ GVariant *v_in_clusters = NULL;
+ GVariant *v_out_clusters = NULL;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ v_in_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
+ payload->in_clusters, payload->in_cluster_count, TRUE, NULL, NULL);
+ v_out_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
+ payload->out_clusters, payload->out_cluster_count, TRUE, NULL, NULL);
+
+ zigbee_service_complete_get_cluster_list(service_object, invocation,
+ payload->result, v_in_clusters, v_out_clusters);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
GVariant *eui64,
gchar endpoint,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceGetClusterList_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(eui64);
- NOT_USED(endpoint);
+ GVariantIter *iter = NULL;
+ guint i = 0;
- /*
- * TODO -
- * Create and send request for processing
- */
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
+
+ /* Update request structure */
+ g_variant_get(eui64, "a(y)", &iter);
+ while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
+ i++;
+ if (i >= ZIGBEE_EUI64_SIZE)
+ break;
+ }
+ req.endpoint = endpoint;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST,
+ &req, sizeof(req),
+ on_service_get_cluster_list_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeService *service_object;
+ GDBusMethodInvocation *invocation;
+ ZigbeeServiceServiceNodeTypeResp_t *payload =
+ (ZigbeeServiceServiceNodeTypeResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data is null");
+ g_free(cb_data);
+ return;
+ }
+
+ service_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("service_object", service_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_service_complete_get_node_type(service_object, invocation,
+ payload->result, payload->node_type);
+
+ g_free(cb_data);
+}
+
static gboolean on_service_get_node_type(ZigbeeService *service_object,
GDBusMethodInvocation *invocation,
GVariant *eui64,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeServiceGetNodeType_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(service_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(eui64);
+ GVariantIter *iter = NULL;
+ guint i = 0;
- /*
- * TODO -
- * Create and send request for processing
- */
+ gboolean ret;
+
+ memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
+
+ /* Update request structure */
+ g_variant_get(eui64, "a(y)", &iter);
+ while (g_variant_iter_loop(iter, "(y)", req.eui64[i])) {
+ i++;
+ if (i >= ZIGBEE_EUI64_SIZE)
+ break;
+ }
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(service_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_SERVICE,
+ ZBLIB_SERVICE_OPS_GET_NODE_TYPE,
+ &req, sizeof(req),
+ on_service_get_node_type_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
-gboolean zigbee_service_dbus_interface_service_init(ZigBeeService *service,
+void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *service_interface,
+ guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
+{
+ ZigbeeService *service_object;
+
+ zblib_check_null_ret("service_interface", service_interface);
+
+ if (NULL == noti_data || 0 == noti_data_len) {
+ Z_LOGE("noti_data is NULL");
+ return;
+ }
+
+ service_object = _service_interface_ref_zigbee_service(service_interface);
+ zblib_check_null_ret("service_object", service_object);
+
+ NOT_USED(noti_cb_data);
+
+ switch(noti_id) {
+ case ZBLIB_SERVICE_NOTI_FORM_NETWORK_DONE: {
+ ZigbeeServiceServiceFormNetworkDone_t *panid_t =
+ (ZigbeeServiceServiceFormNetworkDone_t*)noti_data;
+
+ Z_LOGD("form_network_done : [0x%X]", panid_t->pan_id);
+
+ zigbee_service_emit_form_network_done(service_object, panid_t->pan_id);
+ }
+ break;
+ case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
+ ZigbeeServiceServiceChildJoined_t *child_t =
+ (ZigbeeServiceServiceChildJoined_t*)noti_data;
+
+ GVariant *v_eui64 = NULL;
+ GVariant *v_endpoints = NULL;
+
+ v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+ v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ child_t->endpoints, child_t->endpoint_count, TRUE, NULL, NULL);
+ if (NULL == v_eui64 || NULL == v_endpoints) {
+ Z_LOGE("Failed to create variant!");
+ if (v_eui64)
+ g_object_unref(v_eui64);
+ if (v_endpoints)
+ g_object_unref(v_endpoints);
+ } else {
+ zigbee_service_emit_child_joined(service_object,
+ v_eui64, child_t->endpoint_count, v_endpoints, child_t->node_id);
+ }
+ }
+ break;
+ case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
+ ZigbeeServiceServiceChildRejoined_t *child_t =
+ (ZigbeeServiceServiceChildRejoined_t*)noti_data;
+
+ GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+ if (NULL == v_eui64) {
+ Z_LOGE("Failed to create variant!");
+ } else {
+ zigbee_service_emit_child_rejoined(service_object, v_eui64);
+ }
+ }
+ break;
+ case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
+ ZigbeeServiceServiceChildLeft_t *child_left_t =
+ (ZigbeeServiceServiceChildLeft_t*)noti_data;
+
+ GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+ child_left_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+ if (NULL == v_eui64) {
+ Z_LOGE("Failed to create variant!");
+ } else {
+ zigbee_service_emit_child_left(service_object,
+ v_eui64, child_left_t->status);
+ }
+ }
+ break;
+ case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {
+ ZigbeeServiceServiceLeaveNetworkDone_t leave_net_t;
+ memcpy(&leave_net_t, noti_data, noti_data_len);
+ zigbee_service_emit_leave_network_done(service_object, leave_net_t.pan_id);
+ }
+ break;
+ default:
+ Z_LOGE("Unexpected notification [%x]", noti_id);
+ break;
+ }
+
+ /* ZigbeeService should be dereferenced */
+ g_object_unref(service_object);
+}
+
+gboolean zigbee_service_dbus_interface_service_init(ZigBeeServiceInterface *service_interface,
ZigbeeObjectSkeleton *zigbee_object)
{
ZigbeeService *service_object;
- if (NULL == service) {
- Z_LOGE("service is NULL");
+ if (NULL == service_interface) {
+ Z_LOGE("service_interface is NULL");
return FALSE;
}
*/
g_signal_connect(service_object,
"handle-enable",
- G_CALLBACK(on_service_enable), service);
+ G_CALLBACK(on_service_enable), service_interface);
g_signal_connect(service_object,
"handle-disable",
- G_CALLBACK(on_service_disable), service);
+ G_CALLBACK(on_service_disable), service_interface);
g_signal_connect(service_object,
"handle-zb-hw-reset",
- G_CALLBACK(on_service_zb_hw_reset), service);
+ G_CALLBACK(on_service_zb_hw_reset), service_interface);
g_signal_connect(service_object,
"handle-form-network",
- G_CALLBACK(on_service_form_network), service);
+ G_CALLBACK(on_service_form_network), service_interface);
g_signal_connect(service_object,
"handle-coex-start",
- G_CALLBACK(on_service_coex_start), service);
+ G_CALLBACK(on_service_coex_start), service_interface);
g_signal_connect(service_object,
"handle-coex-stop",
- G_CALLBACK(on_service_coex_stop), service);
+ G_CALLBACK(on_service_coex_stop), service_interface);
g_signal_connect(service_object,
"handle-leave-network",
- G_CALLBACK(on_service_leave_network), service);
+ G_CALLBACK(on_service_leave_network), service_interface);
g_signal_connect(service_object,
"handle-get-network-info",
- G_CALLBACK(on_service_get_network_info), service);
+ G_CALLBACK(on_service_get_network_info), service_interface);
g_signal_connect(service_object,
"handle-permit-join",
- G_CALLBACK(on_service_permit_join), service);
+ G_CALLBACK(on_service_permit_join), service_interface);
g_signal_connect(service_object,
"handle-leave-request",
- G_CALLBACK(on_service_leave_request), service);
+ G_CALLBACK(on_service_leave_request), service_interface);
g_signal_connect(service_object,
"handle-get-device-list",
- G_CALLBACK(on_service_get_device_list), service);
+ G_CALLBACK(on_service_get_device_list), service_interface);
g_signal_connect(service_object,
"handle-get-mac",
- G_CALLBACK(on_service_get_mac), service);
+ G_CALLBACK(on_service_get_mac), service_interface);
g_signal_connect(service_object,
"handle-get-device-info",
- G_CALLBACK(on_service_get_device_info), service);
+ G_CALLBACK(on_service_get_device_info), service_interface);
g_signal_connect(service_object,
"handle-get-endpoint-list",
- G_CALLBACK(on_service_get_endpoint_list), service);
+ G_CALLBACK(on_service_get_endpoint_list), service_interface);
g_signal_connect(service_object,
"handle-get-cluster-list",
- G_CALLBACK(on_service_get_cluster_list), service);
+ G_CALLBACK(on_service_get_cluster_list), service_interface);
g_signal_connect(service_object,
"handle-get-node-type",
- G_CALLBACK(on_service_get_node_type), service);
+ G_CALLBACK(on_service_get_node_type), service_interface);
return TRUE;
}