#define NUMBER_OF_FLAGS 10
GDBusConnection *g_conn;
-GDBusNodeInfo *obj_info;
guint owner_id;
guint manager_id;
static gboolean new_service = FALSE;
#define GATT_CHAR_INTERFACE "org.bluez.GattCharacteristic1"
#define GATT_DESC_INTERFACE "org.bluez.GattDescriptor1"
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
#define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
#define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
#define PROPERTIES_CHANGED "PropertiesChanged"
BT_DBG("-");
}
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
static int __bt_send_event_to_hps(int event, GVariant *var)
{
GError *error = NULL;
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- GSList *l1;
+ GSList *l1 = NULL;
int len = 0;
int i = 0;
GVariantBuilder *svc_builder = NULL;
GVariantBuilder *inner_builder = NULL;
- if (register_pending_cnt > 1) {
+ if (register_pending_cnt > 1)
l1 = g_slist_nth(gatt_services, len - register_pending_cnt);
- } else {
+ else
l1 = g_slist_last(gatt_services);
- }
+
register_pending_cnt--;
+ if (l1 == NULL) {
+ BT_ERR("gatt service list is NULL");
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
+ }
+
struct gatt_service_info *serv_info = l1->data;
if (serv_info == NULL) {
BT_ERR("service info value is NULL");
if (svc_info != NULL) {
read_req.service_handle = g_strdup(svc_info->serv_path);
user_info = _bt_get_user_data(BT_COMMON);
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
GVariant *param = NULL;
#endif
BLUETOOTH_ERROR_NONE, &read_req,
user_info->cb, user_info->user_data);
}
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
param = g_variant_new("(sssyq)",
read_req.att_handle,
read_req.service_handle,
int len = 0;
struct gatt_service_info *svc_info = NULL;
struct gatt_req_info *req_info = NULL;
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
GVariant *param = NULL;
#endif
BLUETOOTH_ERROR_NONE, &value_change,
user_info->cb, user_info->user_data);
}
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
if (len > 0) {
gchar *svc_path;
svc_path = g_strdup(svc_info->serv_path);
const gchar *introspection_data)
{
GError *err = NULL;
+ GDBusNodeInfo *node_info = NULL;
if (introspection_data == NULL)
return NULL;
- if (obj_info == NULL) {
- BT_DBG("Create new node info");
- obj_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
- if (err) {
- BT_ERR("Unable to create node: %s", err->message);
- g_clear_error(&err);
- return NULL;
- }
+ BT_DBG("Create new node info");
+ node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
+
+ if (err) {
+ BT_ERR("Unable to create node: %s", err->message);
+ g_clear_error(&err);
+ return NULL;
}
- return obj_info;
+ return node_info;
}
static struct gatt_service_info *__bt_gatt_find_gatt_service_info(
for (l = gatt_requests; l != NULL; l = l->next) {
struct gatt_req_info *req_info = l->data;
- if (req_info && req_info->request_id == request_id) {
+ if (req_info && req_info->request_id == request_id)
return req_info;
- }
}
BT_ERR("Gatt Request not found");
return NULL;
error->code, error->message);
g_clear_error(&error);
}
+ } else {
+ g_variant_unref(result);
}
}
error->code, error->message);
g_clear_error(&error);
}
+ } else {
+ g_variant_unref(result);
}
}
return BLUETOOTH_ERROR_NONE;
failed:
- if (obj_info)
- g_dbus_node_info_unref(obj_info);
-
if (owner_id)
g_bus_unown_name(owner_id);
g_free(app_path);
- obj_info = NULL;
app_path = NULL;
owner_id = 0;
g_object_unref(manager_gproxy);
manager_gproxy = NULL;
- /* Temperary block under codes to avoid TC blocking issue.
- But we should unref node info in later. */
-#if 0
- g_dbus_node_info_unref(obj_info);
- obj_info = NULL;
-#endif
__bt_gatt_close_gdbus_connection();
return ret;
char_info->char_id = object_id;
char_info->char_uuid = g_strdup(char_uuid);
- for (i = 0; i < flag_count; i++) {
+ for (i = 0; i < flag_count; i++)
char_info->char_flags[i] = char_flags[i];
- }
+
char_info->flags_length = flag_count;
builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < flag_count; i++) {
+ for (i = 0; i < flag_count; i++)
g_variant_builder_add(builder2, "s", char_flags[i]);
- }
flags_val = g_variant_new("as", builder2);
g_variant_builder_add(inner_builder, "{sv}", "Flags",
builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
- for (i = 0; i < value_length; i++) {
+ for (i = 0; i < value_length; i++)
g_variant_builder_add(builder1, "y", char_value[i]);
- }
char_val = g_variant_new("ay", builder1);
g_variant_builder_add(inner_builder, "{sv}", "Value", char_val);
char_info = __bt_gatt_find_gatt_char_info(serv_path, char_path);
if (char_info == NULL) {
g_strfreev(line_argv);
+ g_free(serv_path);
return BLUETOOTH_ERROR_INVALID_PARAM;
}
if (node_info == NULL) {
g_strfreev(line_argv);
+ g_free(serv_path);
return BLUETOOTH_ERROR_INTERNAL;
}
g_error_free(error);
g_free(path);
g_strfreev(line_argv);
+ g_free(serv_path);
return BLUETOOTH_ERROR_INTERNAL;
}
desc_info->desc_id = object_id;
desc_info->desc_uuid = g_strdup(desc_uuid);
- for (i = 0; i < flag_count; i++) {
+ for (i = 0; i < flag_count; i++)
desc_info->desc_flags[i] = desc_flags[i];
- }
desc_info->flags_length = flag_count;
builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < flag_count; i++) {
+ for (i = 0; i < flag_count; i++)
g_variant_builder_add(builder2, "s", desc_flags[i]);
- }
flags_val = g_variant_new("as", builder2);
g_variant_builder_add(inner_builder, "{sv}", "Flags",
*desc_path = g_strdup(path);
g_free(path);
+ g_free(serv_path);
g_strfreev(line_argv);
g_variant_builder_unref(inner_builder);
g_variant_builder_unref(builder);
builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
- for (i = 0; i < value_length; i++) {
+ for (i = 0; i < value_length; i++)
g_variant_builder_add(builder1, "y", desc_value[i]);
- }
+
desc_val = g_variant_new("ay", builder1);
g_variant_builder_add(inner_builder, "{sv}", "Value", desc_val);
if (!__bt_gatt_get_service_state(serv_path)) {
BT_DBG("service not registered for this characteristic \n");
+ g_free(serv_path);
g_strfreev(line_argv);
return BLUETOOTH_ERROR_INTERNAL;
}
invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
inner_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
- for (i = 0; i < value_length; i++) {
+ for (i = 0; i < value_length; i++)
g_variant_builder_add(inner_builder, "y", char_value[i]);
- }
update_value = g_variant_new("ay", inner_builder);
char_info = __bt_gatt_find_gatt_char_info(serv_path, char_path);
if (char_info == NULL) {
+ g_free(serv_path);
+ g_strfreev(line_argv);
+ g_variant_builder_unref(inner_builder);
+ g_variant_builder_unref(outer_builder);
+ g_variant_builder_unref(invalidated_builder);
+
return BLUETOOTH_ERROR_INVALID_DATA;
}
char_info->char_value = (char *)realloc(char_info->char_value, value_length);
if (char_info->char_value) {
- for (i = 0; i < value_length; i++) {
+ for (i = 0; i < value_length; i++)
char_info->char_value[i] = char_value[i];
- }
}
}
+ g_free(serv_path);
g_strfreev(line_argv);
g_variant_builder_unref(inner_builder);
g_variant_builder_unref(outer_builder);
return err;
}
+static void __bt_gatt_free_descriptor_info(struct gatt_desc_info *desc_info)
+{
+ int i;
+
+ if (!desc_info)
+ return;
+
+ g_free(desc_info->desc_path);
+ g_free(desc_info->desc_uuid);
+ g_free(desc_info->desc_value);
+
+ for (i = 0; i < desc_info->flags_length; i++)
+ g_free(desc_info->desc_flags[i]);
+
+ g_free(desc_info);
+}
+
+static void __bt_gatt_free_characteristic_info(struct gatt_char_info *char_info)
+{
+ int i;
+
+ if (!char_info)
+ return;
+
+ g_free(char_info->char_path);
+ g_free(char_info->char_uuid);
+ g_free(char_info->char_value);
+
+ for (i = 0; i < char_info->flags_length; i++)
+ g_free(char_info->char_flags[i]);
+
+ g_free(char_info);
+}
+
+static void __bt_gatt_free_service_info(struct gatt_service_info *svc_info)
+{
+ if (!svc_info)
+ return;
+
+ g_free(svc_info->serv_path);
+ g_free(svc_info->service_uuid);
+ g_free(svc_info);
+}
+
BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
{
- int i = 0;
GSList *l, *l1;
struct gatt_service_info *svc_info;
gboolean ret;
int err = BLUETOOTH_ERROR_NONE;
- GSList *tmp;
BT_DBG("svc_path %s", svc_path);
svc_info = __bt_gatt_find_gatt_service_info(svc_path);
err = BLUETOOTH_ERROR_INTERNAL;
}
+ /* list remove & free */
char_info->desc_data = g_slist_remove(char_info->desc_data, desc_info);
-
- g_free(desc_info->desc_path);
- g_free(desc_info->desc_uuid);
- g_free(desc_info->desc_value);
-
- for (i = 0; i < desc_info->flags_length; i++)
- g_free(desc_info->desc_flags[i]);
-
- g_free(desc_info);
+ __bt_gatt_free_descriptor_info(desc_info);
}
g_slist_free(char_info->desc_data);
err = BLUETOOTH_ERROR_INTERNAL;
}
- g_free(char_info->char_path);
- g_free(char_info->char_uuid);
- g_free(char_info->char_value);
-
- for (i = 0; i < char_info->flags_length; i++)
- g_free(char_info->char_flags[i]);
+ /* list remove & free */
+ svc_info->char_data = g_slist_remove(svc_info->char_data, char_info);
+ __bt_gatt_free_characteristic_info(char_info);
}
g_slist_free(svc_info->char_data);
}
ret = g_dbus_connection_unregister_object(g_conn, svc_info->prop_id);
- if (ret) {
+ if (ret)
BT_DBG("Unregistered the service on properties interface");
- }
- for (tmp = gatt_services; tmp != NULL; tmp = tmp->next) {
- struct gatt_service_info *info = tmp->data;
-
- if (g_strcmp0(info->serv_path, svc_path) == 0) {
- gatt_services = g_slist_remove(gatt_services, tmp->data);
- g_free(info->serv_path);
- g_free(info->service_uuid);
- g_free(info);
- }
- }
+ /* list remove & free */
+ gatt_services = g_slist_remove(gatt_services, svc_info);
+ __bt_gatt_free_service_info(svc_info);
new_service = FALSE;
- if (gatt_services == NULL) {
+ if (gatt_services == NULL)
serv_id = 1;
- } else if (gatt_services->next == NULL) {
+ else if (gatt_services->next == NULL)
serv_id--;
- }
return err;
}
if (req_info) {
if (resp_state != BLUETOOTH_ERROR_NONE) {
-
- GQuark quark = g_quark_from_string("gatt-server");
- GError *err = g_error_new(quark, 0, "Application Error");
- g_dbus_method_invocation_return_gerror(req_info->context, err);
- g_error_free(err);
+ g_dbus_method_invocation_return_dbus_error(req_info->context,
+ "org.bluez.Error.Failed", "Application Error");
gatt_requests = g_slist_remove(gatt_requests, req_info);
if (!__bt_gatt_get_service_state(serv_path)) {
BT_DBG("service not registered for this characteristic \n");
+ g_free(serv_path);
g_strfreev(line_argv);
return BLUETOOTH_ERROR_INTERNAL;
}
+ g_free(serv_path);
+
outer_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));