#include <zblib.h>
#include <zblib_service_interface.h>
+#include <zblib_request.h>
+#include <zblib_service.h>
/**< ZigBee Service interface object */
struct zblib_service_interface_type {
gchar *object_name; /**< ZigBee Service interface object name */
- struct zblib_service_interface_methods *methods; /**< ZigBee Service interface object methods */
gpointer user_data; /**< ZigBee servcie interface data */
};
ZigBeeServiceInterface *zblib_service_interface_new(ZigBeeService *service,
- const gchar *object_name,
- struct zblib_service_interface_methods *methods)
+ const gchar *object_name)
{
ZigBeeServiceInterface *service_interface = NULL;
- if ((NULL == service) || (NULL == object_name)) {
- Z_LOGE("service [%p] or object_name [%p] is NULL",
- service, object_name);
- return NULL;
- }
+ zblib_check_null_ret_error("service", service, NULL);
+ zblib_check_null_ret_error("object_name", object_name, NULL);
/* Allocate memory */
service_interface = g_malloc0(sizeof(ZigBeeServiceInterface));
/* Update fields */
service_interface->object_name = g_strdup(object_name);
- service_interface->methods = methods;
service_interface->service = service;
Z_LOGI("Service interface created - Name [%s]",
void zblib_service_interface_free(ZigBeeService *service,
ZigBeeServiceInterface *service_interface)
{
- if ((NULL == service) || (NULL == service_interface)) {
- Z_LOGE("service [%p] or service_interface [%p] is NULL",
- service, service_interface);
- return;
- }
+ zblib_check_null_ret("service", service);
+ zblib_check_null_ret("service_interface", service_interface);
Z_LOGI("Freeing Service interface - Name [%p]",
service_interface->object_name);
char *zblib_service_interface_get_name(ZigBeeServiceInterface *service_interface)
{
- if (NULL == service_interface) {
- Z_LOGE("service_interface is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("service_interface", service_interface, NULL);
return g_strdup(service_interface->object_name);
}
gboolean zblib_service_interface_link_user_data(ZigBeeServiceInterface *service_interface,
gpointer user_data)
{
- if (NULL == service_interface) {
- Z_LOGE("service_interface is NULL");
- return FALSE;
- }
+ zblib_check_null_ret_error("service_interface", service_interface, FALSE);
service_interface->user_data = user_data;
gpointer zblib_service_interface_ref_user_data(ZigBeeServiceInterface *service_interface)
{
- if (NULL == service_interface) {
- Z_LOGE("service_interface is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("service_interface", service_interface, NULL);
return service_interface->user_data;
}
ZigBeeService *zblib_service_interface_ref_service(ZigBeeServiceInterface *service_interface)
{
- if (NULL == service_interface) {
- Z_LOGE("service_interface is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("service_interface", service_interface, NULL);
return service_interface->service;
}
+
+gint zblib_service_interface_new_request(ZigBeeServiceInterface *service_interface,
+ guint request_type,
+ gpointer request_data, guint request_data_len,
+ ZblibServiceInterfaceResponseCb_t resp_cb, gpointer resp_cb_data)
+{
+ gint request_id = 0;
+ gboolean ret;
+
+ zblib_check_null_ret_error("service_interface", service_interface, -1);
+
+ /* Create new request */
+ request_id = zblib_request_new(service_interface,
+ request_type,
+ request_data, request_data_len);
+
+ /* Set response callback */
+ ret = zblib_request_set_response_cb(service_interface,
+ request_id,
+ (gpointer)resp_cb, (gpointer)resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zblib_request_set_response_cb failed!");
+
+ /* Free request_id */
+ zblib_request_free(service_interface, request_id);
+ request_id = -1;
+ }
+
+ return request_id;
+}
+
+gboolean zblib_service_interface_dispatch_request(ZigBeeServiceInterface *service_interface,
+ guint request_id)
+{
+ ZigBeeService *service = NULL;
+
+ zblib_check_null_ret_error("service_interface", service_interface, FALSE);
+
+ /* Fetch service */
+ service = service_interface->service;
+ zblib_check_null_ret_error("service", service, FALSE);
+
+ /* Dispatch request to service */
+ return zblib_service_dispatch_request(service, request_id);
+}
+
+void zblib_service_interface_send_response(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len)
+{
+ ZblibServiceInterfaceResponseCb_t resp_cb;
+ gpointer resp_cb_data;
+
+ zblib_check_null_ret("service_interface", service_interface);
+
+ /* Fetch response callback and response callback data from request_id */
+ resp_cb = zblib_request_ref_response_cb(service_interface,
+ request_id, &resp_cb_data);
+ zblib_check_null_ret("resp_cb", resp_cb);
+
+ /* Invoke send response function */
+ resp_cb(service_interface,
+ request_id, resp_data, resp_data_len, resp_cb_data);
+
+ /* Free request */
+ zblib_request_free(service_interface, request_id);
+}