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.
21 #include <zblib_service_interface.h>
23 /**< ZigBee Service interface object */
24 struct zblib_service_interface_type {
25 gchar *object_name; /**< ZigBee Service interface object name */
26 struct zblib_service_interface_methods *methods; /**< ZigBee Service interface object methods */
28 gpointer user_data; /**< ZigBee servcie interface data */
30 ZigBeeService *service; /**< ZigBee Service */
33 ZigBeeServiceInterface *zblib_service_interface_new(ZigBeeService *service,
34 const gchar *object_name,
35 struct zblib_service_interface_methods *methods)
37 ZigBeeServiceInterface *service_interface = NULL;
39 if ((NULL == service) || (NULL == object_name)) {
40 Z_LOGE("service [%p] or object_name [%p] is NULL",
41 service, object_name);
46 service_interface = g_malloc0(sizeof(ZigBeeServiceInterface));
49 service_interface->object_name = g_strdup(object_name);
50 service_interface->methods = methods;
51 service_interface->service = service;
53 Z_LOGI("Service interface created - Name [%s]",
54 service_interface->object_name);
56 return service_interface;
59 void zblib_service_interface_free(ZigBeeService *service,
60 ZigBeeServiceInterface *service_interface)
62 if ((NULL == service) || (NULL == service_interface)) {
63 Z_LOGE("service [%p] or service_interface [%p] is NULL",
64 service, service_interface);
68 Z_LOGI("Freeing Service interface - Name [%p]",
69 service_interface->object_name);
72 g_free(service_interface->object_name);
73 g_free(service_interface);
76 char *zblib_service_interface_get_name(ZigBeeServiceInterface *service_interface)
78 if (NULL == service_interface) {
79 Z_LOGE("service_interface is NULL");
83 return g_strdup(service_interface->object_name);
86 gboolean zblib_service_interface_link_user_data(ZigBeeServiceInterface *service_interface,
89 if (NULL == service_interface) {
90 Z_LOGE("service_interface is NULL");
94 service_interface->user_data = user_data;
99 gpointer zblib_service_interface_ref_user_data(ZigBeeServiceInterface *service_interface)
101 if (NULL == service_interface) {
102 Z_LOGE("service_interface is NULL");
106 return service_interface->user_data;
109 ZigBeeService *zblib_service_interface_ref_service(ZigBeeServiceInterface *service_interface)
111 if (NULL == service_interface) {
112 Z_LOGE("service_interface is NULL");
116 return service_interface->service;