if (TRUE == custom_data->name_acquired) {
/* TODO - Emit zigbee_state signal */
}
+
OUT:
g_free(path);
}
-/**< ZigBee D-BUS Service interface methods */
-struct zblib_service_interface_methods dbus_service_interface_methods = {
- .send_response = NULL,
- .send_notification = NULL,
-};
-
-
/**< Zigbee service dbus interface initialization */
gboolean zigbee_service_dbus_interface_init(ZigBeeService *service)
{
* Create ZigBee service interface object
*/
service_interface = zblib_service_interface_new(service,
- ZIGBEE_DBUS_SERVICE_INTERFACE_NAME,
- &dbus_service_interface_methods);
+ ZIGBEE_DBUS_SERVICE_INTERFACE_NAME);
if (NULL == service_interface) {
Z_LOGE("Create D-BUS service interface failed!");
gboolean zblib_driver_dispatch_request(ZigBeeDriver *driver, guint request_id);
+void zblib_driver_send_response(ZigBeeDriver *driver,
+ guint request_id, gpointer resp_data, guint resp_data_len);
+
#endif /* __ZIGBEE_LIB_DRIVER_H__ */
#define __ZIGBEE_LIB_PLUGIN_H__
/**< ZigBee plug-in descriptor */
-struct zblib_plugin_descriptor {
+typedef struct {
const gchar *name;
int version;
gboolean (*is_implemented)(); /**< Is plug-in implemented */
gboolean (*load)(); /**< Load plugin */
gboolean (*init)(ZigBeePlugin *); /**< Initialize plugin */
void (*unload)(ZigBeePlugin *); /**< Unload plugin */
-};
+} ZblibPluginDescriptor_t;
/* ZigBee vendor plug-in APIs */
ZigBeePlugin *zblib_plugin_new(ZigBeeService *service,
const gchar *plugin_name,
- const struct zblib_plugin_descriptor *descriptor,
+ const ZblibPluginDescriptor_t *descriptor,
void *plugin_handle);
void zblib_plugin_free(ZigBeePlugin *plugin);
-const struct zblib_plugin_descriptor *zblib_plugin_get_descriptor(ZigBeePlugin *plugin);
+const ZblibPluginDescriptor_t *zblib_plugin_get_descriptor(ZigBeePlugin *plugin);
char *zblib_plugin_get_plugin_name(ZigBeePlugin *plugin);
ZigBeeDriver *zblib_plugin_ref_driver(ZigBeePlugin *plugin, ZblibDriverType_e driver_type);
+gboolean zblib_plugin_dispatch_request(ZigBeePlugin *plugin,
+ guint request_id);
+void zblib_plugin_send_response(ZigBeePlugin *plugin,
+ guint request_id, gpointer resp_data, guint resp_data_len);
+
#endif /* __ZIGBEE_LIB_PLUGIN_H__ */
void zblib_request_free(ZigBeeServiceInterface *service_interface,
guint request_id);
+gboolean zblib_request_set_response_cb(ZigBeeServiceInterface *service_interface,
+ guint request_id,
+ gpointer resp_cb, gpointer resp_cb_data);
+gpointer zblib_request_ref_response_cb(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer *resp_cb_data);
+
ZigBeeRequest *zblib_request_ref(ZigBeeRequest *request);
void zblib_request_unref(ZigBeeRequest *request);
guint zblib_request_ref_request_type(ZigBeeRequest *request);
-ZigBeeServiceInterface *zblib_request_ref_service_interface(ZigBeeRequest *request);
+ZigBeeServiceInterface *zblib_request_ref_service_interface(ZigBeeService *service,
+ guint request_id);
gpointer zblib_request_ref_request_data(ZigBeeRequest *request);
guint zblib_request_generate_request_type(ZblibDriverType_e driver_type,
GHashTable *zblib_service_ref_request_hash_table(ZigBeeService *service);
gint zblib_service_generate_request_id(ZigBeeService *service);
+gboolean zblib_service_dispatch_request(ZigBeeService *service,
+ guint request_id);
+void zblib_service_send_response(ZigBeeService *service,
+ guint request_id, gpointer resp_data, guint resp_data_len);
+
#endif /* __ZIGBEE_LIB_SERVICE_H__ */
#ifndef __ZIGBEE_LIB_SERVICE_INTERFACE_H__
#define __ZIGBEE_LIB_SERVICE_INTERFACE_H__
-/**< Service interface methods */
-struct zblib_service_interface_methods {
- gboolean (*send_response)();
- gboolean (*send_notification)();
-};
+/**< ZigBee Service interface response callback function pointer */
+typedef gboolean (*ZblibServiceInterfaceResponseCb_t)(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data);
/**< Service interface APIs */
ZigBeeServiceInterface *zblib_service_interface_new(ZigBeeService *service,
- const gchar *object_name,
- struct zblib_service_interface_methods *methods);
+ const gchar *object_name);
void zblib_service_interface_free(ZigBeeService *service,
ZigBeeServiceInterface *service_interface);
ZigBeeService *zblib_service_interface_ref_service(ZigBeeServiceInterface *service_interface);
+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);
+
+gboolean zblib_service_interface_dispatch_request(ZigBeeServiceInterface *service_interface,
+ guint request_id);
+void zblib_service_interface_send_response(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len);
+
#endif /* __ZIGBEE_LIB_SERVICE_INTERFACE_H__ */
#include <zblib.h>
#include <zblib_driver.h>
+#include <zblib_plugin.h>
+#include <zblib_service.h>
/**< ZigBee driver object */
struct zblib_driver_type {
/* Dispatch request to driver dispatcher function */
return driver->dispatcher_fn(driver, request_id);
}
+
+void zblib_driver_send_response(ZigBeeDriver *driver,
+ guint request_id, gpointer resp_data, guint resp_data_len)
+{
+ ZigBeePlugin *plugin = NULL;
+
+ zblib_check_null_ret("driver", driver);
+
+ plugin = driver->plugin;
+ zblib_check_null_ret("plugin", plugin);
+
+ /* Send response to plugin */
+ zblib_plugin_send_response(plugin,
+ request_id, resp_data, resp_data_len);
+}
#include <zblib.h>
#include <zblib_plugin.h>
#include <zblib_driver.h>
+#include <zblib_service.h>
+#include <zblib_request.h>
/**< ZigBee plug-in object */
struct zblib_plugin_type {
gchar *plugin_name; /**< ZigBee plug-in name */
- const struct zblib_plugin_descriptor *descriptor; /**< ZigBee plug-in descriptor */
+ const ZblibPluginDescriptor_t *descriptor; /**< ZigBee plug-in descriptor */
void *plugin_handle; /**< ZigBee Plug-in .so handle */
GSList *driver_list; /**< List of ZigBee drivers */
ZigBeePlugin *zblib_plugin_new(ZigBeeService *service,
const gchar *plugin_name,
- const struct zblib_plugin_descriptor *descriptor,
+ const ZblibPluginDescriptor_t *descriptor,
void *plugin_handle)
{
ZigBeePlugin *plugin = NULL;
void zblib_plugin_free(ZigBeePlugin *plugin)
{
- if (NULL == plugin) {
- Z_LOGE("ZigBee vendor plug-in is NULL");
- return;
- }
+ zblib_check_null_ret("plugin", plugin);
Z_LOGI("Freeing Vendor plug-in - Name [%s]", plugin->descriptor->name);
g_free(plugin);
}
-const struct zblib_plugin_descriptor *zblib_plugin_get_descriptor(ZigBeePlugin *plugin)
+const ZblibPluginDescriptor_t *zblib_plugin_get_descriptor(ZigBeePlugin *plugin)
{
- if (NULL == plugin) {
- Z_LOGE("ZigBee vendor plug-in is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("plugin", plugin, NULL);
return plugin->descriptor;
}
char *zblib_plugin_get_plugin_name(ZigBeePlugin *plugin)
{
- if (NULL == plugin) {
- Z_LOGE("ZigBee vendor plug-in is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("plugin", plugin, NULL);
return g_strdup(plugin->plugin_name);
}
ZblibDriverType_e _driver_type;
GSList *list = NULL;
- if (NULL == plugin) {
- Z_LOGE("ZigBee vendor plug-in is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("plugin", plugin, NULL);
list = plugin->driver_list;
while (list) {
return driver;
}
+
+gboolean zblib_plugin_dispatch_request(ZigBeePlugin *plugin,
+ guint request_id)
+{
+ ZigBeeService *service = NULL;
+ ZigBeeDriver *driver = NULL;
+ ZblibDriverType_e driver_type;
+
+ zblib_check_null_ret_error("plugin", plugin, FALSE);
+
+ /* Fetch service */
+ service = plugin->service;
+ zblib_check_null_ret_error("service", service, FALSE);
+
+ /* Fetch driver type */
+ driver_type = (ZblibDriverType_e)zblib_request_ref_request_type_by_request_id(service, request_id);
+
+ /* Fetch driver */
+ driver = zblib_plugin_ref_driver(plugin, driver_type);
+ zblib_check_null_ret_error("driver", driver, FALSE);
+
+ /* Dispatch request to driver */
+ return zblib_driver_dispatch_request(driver, request_id);
+}
+
+void zblib_plugin_send_response(ZigBeePlugin *plugin,
+ guint request_id, gpointer resp_data, guint resp_data_len)
+{
+ ZigBeeService *service = NULL;
+
+ zblib_check_null_ret("plugin", plugin);
+
+ service = plugin->service;
+ zblib_check_null_ret("service", service);
+
+ /* Send response to service */
+ zblib_service_send_response(service,
+ request_id, resp_data, resp_data_len);
+}
guint ref_count; /* Reference count */
gpointer request_data; /**< Request data */
+ gpointer resp_cb; /**< Response callback */
+ gpointer resp_cb_data; /**< Response callback data */
ZigBeeServiceInterface *service_interface; /* Service interface */
};
return ops_id;
}
-static gint __zblib_request_ref_request_type_by_request_id(ZigBeeService *service,
+static ZigBeeRequest *__zblib_request_ref_request_by_by_request_id(ZigBeeService *service,
guint request_id)
{
ZigBeeRequest *request = NULL;
request_table = zblib_service_ref_request_hash_table(service);
if (NULL == request_table) {
Z_LOGE("zblib_service_ref_request_hash_table failed!");
- return -1;
+ return NULL;
}
/* Look-up requets_id in request hash table */
request = (ZigBeeRequest *)g_hash_table_lookup(request_table, (gconstpointer)request_id);
- if (NULL == request_table) {
- Z_LOGE("No request availabel for request_id: [%d]", request_id);
+ if (NULL == request) {
+ Z_LOGE("No request available for request_id: [%d]", request_id);
+ return NULL;
+ }
+
+ return request;
+}
+
+static gint __zblib_request_ref_request_type_by_request_id(ZigBeeService *service,
+ guint request_id)
+{
+ ZigBeeRequest *request = NULL;
+
+ /* Fetch request based on request_id */
+ request = __zblib_request_ref_request_by_by_request_id(service, request_id);
+ if (NULL == request) {
+ Z_LOGE("No request available for request_id: [%d]", request_id);
return -1;
}
zblib_check_null_ret("service_interface", service_interface);
+ /* Fetch service */
service = zblib_service_interface_ref_service(service_interface);
zblib_check_null_ret("service", service);
+ /* Fetch request based on request_id */
request = __zblib_request_ref_request_by_request_id(service, request_id);
zblib_check_null_ret("request", request);
g_free(request);
}
+gboolean zblib_request_set_response_cb(ZigBeeServiceInterface *service_interface,
+ guint request_id,
+ gpointer resp_cb, gpointer resp_cb_data)
+{
+ ZigBeeService *service = NULL;
+ ZigBeeRequest *request = NULL;
+
+ zblib_check_null_ret_error("request", request, FALSE);
+
+ /* Fetch service */
+ service = zblib_service_interface_ref_service(service_interface);
+ zblib_check_null_ret_error("service", service, FALSE);
+
+ /* Fetch request based on request_id */
+ request = __zblib_request_ref_request_by_by_request_id(service, request_id);
+ if (NULL == request) {
+ Z_LOGE("No request available for request_id: [%d]", request_id);
+ return FALSE;
+ }
+
+ /* Update response callback and response callback data */
+ request->resp_cb = resp_cb;
+ request->resp_cb_data = resp_cb_data;
+
+ return TRUE;
+}
+
+gpointer zblib_request_ref_response_cb(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer *resp_cb_data)
+{
+ ZigBeeService *service = NULL;
+ ZigBeeRequest *request = NULL;
+
+ zblib_check_null_ret_error("request", request, NULL);
+
+ /* Fetch service */
+ service = zblib_service_interface_ref_service(service_interface);
+ zblib_check_null_ret_error("service", service, NULL);
+
+ /* Fetch request based on request_id */
+ request = __zblib_request_ref_request_by_by_request_id(service, request_id);
+ if (NULL == request) {
+ Z_LOGE("No request available for request_id: [%d]", request_id);
+ return NULL;
+ }
+
+ /* Response callback data */
+ *resp_cb_data = request->resp_cb_data;
+
+ /* Return response callback */
+ return request->resp_cb;
+}
+
ZigBeeRequest *zblib_request_ref(ZigBeeRequest *request)
{
zblib_check_null_ret_error("request", request, NULL);
return request->request_type;
}
-ZigBeeServiceInterface *zblib_request_ref_service_interface(ZigBeeRequest *request)
+ZigBeeServiceInterface *zblib_request_ref_service_interface(ZigBeeService *service,
+ guint request_id)
{
- zblib_check_null_ret_error("request", request, NULL);
+ ZigBeeRequest *request = NULL;
+
+ zblib_check_null_ret_error("service", service, NULL);
+
+ /* Fetch request based on request_id */
+ request = __zblib_request_ref_request_by_by_request_id(service, request_id);
+ if (NULL == request) {
+ Z_LOGE("No request available for request_id: [%d]", request_id);
+ return NULL;
+ }
return request->service_interface;
}
gpointer zblib_request_ref_request_data(ZigBeeRequest *request)
{
- if (NULL == request) {
- Z_LOGE("request is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("request", request, NULL);
return request->request_data;
}
#include <zblib_service.h>
#include <zblib_plugin.h>
#include <zblib_service_interface.h>
+#include <zblib_request.h>
/**< ZigBee Service object */
struct zblib_service_type {
};
static void *__zblib_service_load_plugin(gchar *filename,
- struct zblib_plugin_descriptor **descriptor_out)
+ ZblibPluginDescriptor_t **descriptor_out)
{
- struct zblib_plugin_descriptor *descriptor = NULL;
+ ZblibPluginDescriptor_t *descriptor = NULL;
void *handle = NULL;
struct stat stat_buf;
char file_date[27];
- if (G_UNLIKELY(NULL == descriptor_out)) {
- Z_LOGE("descriptor_out is NULL!!!");
- return FALSE;
- }
+ zblib_check_null_ret_error("descriptor_out", descriptor_out, NULL);
/* Open .so */
handle = dlopen(filename, RTLD_LAZY);
static gboolean __zblib_service_init_plugin(ZigBeePlugin *plugin)
{
- const struct zblib_plugin_descriptor *descriptor = zblib_plugin_get_descriptor(plugin);
+ const ZblibPluginDescriptor_t *descriptor = zblib_plugin_get_descriptor(plugin);
- if ((NULL == descriptor) || (NULL == descriptor->init)) {
- Z_LOGE("descriptor OR init function is NULL!!!");
- return FALSE;
- }
+ zblib_check_null_ret_error("descriptor", descriptor, FALSE);
+ zblib_check_null_ret_error("descriptor->init", descriptor->init, FALSE);
if (G_UNLIKELY(FALSE == descriptor->init(plugin))) {
char *plugin_name = zblib_plugin_get_plugin_name(plugin);
static gboolean __zblib_service_unload_plugin(ZigBeePlugin *plugin)
{
- const struct zblib_plugin_descriptor *descriptor = zblib_plugin_get_descriptor(plugin);
+ const ZblibPluginDescriptor_t *descriptor = zblib_plugin_get_descriptor(plugin);
char *plugin_name = zblib_plugin_get_plugin_name(plugin);
- if ((NULL == descriptor) || (NULL == descriptor->unload)) {
- Z_LOGE("descriptor OR unload function is NULL!!!");
- return FALSE;
- }
-
+ zblib_check_null_ret_error("descriptor", descriptor, FALSE);
+ zblib_check_null_ret_error("descriptor->unload", descriptor->unload, FALSE);
descriptor->unload(plugin);
Z_LOGI("plugin(%s) unloaded!", plugin_name);
void zblib_service_free(ZigBeeService *service)
{
- if (NULL == service) {
- Z_LOGE("service is NULL");
- return;
- }
+ zblib_check_null_ret("service", service);
/* Free plug-ins */
if (service->plugins) {
gboolean zblib_service_run(ZigBeeService *service)
{
- if ((NULL == service) || (NULL == service->main_loop)) {
- Z_LOGE("service or mainloop is NULL");
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
g_main_loop_run(service->main_loop);
gboolean zblib_service_exit(ZigBeeService *service)
{
- if ((NULL == service) || (NULL == service->main_loop)) {
- Z_LOGE("service or mainloop is NULL");
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
g_main_loop_quit(service->main_loop);
{
gchar *plugin_name;
- if ((NULL == service) || (plugin == NULL)) {
- Z_LOGE("service: [%p] plugin: [%p]", service, plugin);
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("plugin", plugin, FALSE);
plugin_name = zblib_plugin_get_plugin_name(plugin);
gboolean zblib_service_remove_plugin(ZigBeeService *service, ZigBeePlugin *plugin)
{
- if ((NULL == service) || (plugin == NULL)) {
- Z_LOGE("service: [%p] plugin: [%p]", service, plugin);
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("plugin", plugin, FALSE);
/* Specific vendor plug-in would be removed */
service->plugins = g_slist_remove(service->plugins, plugin);
gchar *filename = NULL;
GDir *dir = NULL;
void *handle = NULL;
- struct zblib_plugin_descriptor *descriptor = NULL;
+ ZblibPluginDescriptor_t *descriptor = NULL;
ZigBeePlugin *plugin = NULL;
gboolean ret;
- if ((NULL == service) || (NULL == plugin_path)) {
- Z_LOGE("service: [%p] plugin_path: [%p]", service, plugin_path);
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("plugin_path", plugin_path, FALSE);
/* Open plug-in directory */
dir = g_dir_open(plugin_path, 0, NULL);
{
GSList *list;
- if (NULL == service) {
- Z_LOGE("service is NULL");
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
/* Refer plug-in list */
list = zblib_service_ref_plugins(service);
{
GSList *list;
- if (NULL == service) {
- Z_LOGE("service is NULL");
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
list = zblib_service_ref_plugins(service);
while (list != NULL) {
GSList *zblib_service_ref_plugins(ZigBeeService *service)
{
- if (NULL == service) {
- Z_LOGE("service is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("service", service, NULL);
return service->plugins;
}
{
gchar *object_name;
- if ((NULL == service) || (NULL == service_interface)) {
- Z_LOGE("service: [%p] service_interface: [%p]", service, service_interface);
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("service_interface_name", service_interface, FALSE);
object_name = zblib_service_interface_get_name(service_interface);
gboolean zblib_service_remove_service_interface(ZigBeeService *service,
ZigBeeServiceInterface *service_interface)
{
- if ((NULL == service) || (NULL == service_interface)) {
- Z_LOGE("service: [%p] service_interface: [%p]", service, service_interface);
- return FALSE;
- }
+ zblib_check_null_ret_error("service", service, FALSE);
+ zblib_check_null_ret_error("service_interface_name", service_interface, FALSE);
/*
* service interface object would be removed
GSList *list;
- if ((NULL == service) || (NULL == service_interface_name)) {
- Z_LOGE("service: [%p] service_interface_name: [%p]", service, service_interface_name);
- return NULL;
- }
+ zblib_check_null_ret_error("service", service, NULL);
+ zblib_check_null_ret_error("service_interface_name", service_interface_name, NULL);
list = service->interface_objs;
while (list) {
GHashTable *zblib_service_ref_request_hash_table(ZigBeeService *service)
{
- if (NULL == service) {
- Z_LOGE("service is NULL");
- return NULL;
- }
+ zblib_check_null_ret_error("service", service, NULL);
return service->request_table;
}
gint zblib_service_generate_request_id(ZigBeeService *service)
{
- if (NULL == service) {
- Z_LOGE("service is NULL");
- return -1;
- }
+ zblib_check_null_ret_error("service", service, -1);
/* Increment request ID */
service->request_id++;
return (gint)service->request_id;
-}
\ No newline at end of file
+}
+
+gboolean zblib_service_dispatch_request(ZigBeeService *service,
+ guint request_id)
+{
+ ZigBeePlugin *plugin = NULL;
+ GSList *plugin_list = NULL;
+ gboolean ret = FALSE;
+
+ zblib_check_null_ret_error("service", service, FALSE);
+
+ /* Fetch plugin_list */
+ plugin_list = service->plugins;
+ zblib_check_null_ret_error("plugin_list", plugin_list, FALSE);
+
+ while (plugin_list) {
+ plugin = (ZigBeePlugin *)plugin_list->data;
+
+ /* Dispatch request to plugin */
+ ret = zblib_plugin_dispatch_request(plugin, request_id);
+
+ /* Move to next plugin */
+ plugin_list = g_slist_next(plugin_list);
+ }
+
+ return ret;
+}
+
+void zblib_service_send_response(ZigBeeService *service,
+ guint request_id, gpointer resp_data, guint resp_data_len)
+{
+ ZigBeeServiceInterface *service_interface = NULL;
+
+ service_interface = zblib_request_ref_service_interface(service, request_id);
+ zblib_check_null_ret("service_interface", service_interface);
+
+ /* Send response to service interface */
+ zblib_service_interface_send_response(service_interface,
+ request_id, resp_data, resp_data_len);
+}
#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);
+}