Exemplo n.º 1
0
void primary_all_cb(GSList *services, guint8 status,
                    gpointer user_data)
{
  GSList *l = NULL;
  GSList *bl_primary_list = NULL;

  printf_dbg("[CB] IN Primary_all_cb\n");
  if (status) {
    cb_ret_val = BL_REQUEST_FAIL_ERROR;
    sprintf(cb_ret_msg, "Primary callback: Failure: %s\n",
            att_ecode2str(status));
    goto error;
  }

  if (services == NULL) {
    cb_ret_val = BL_NO_ERROR;
    strcpy(cb_ret_msg, "Primary callback: Nothing found\n");
    goto exit;
  }

  for (l = services; l; l = l->next) {
    struct gatt_primary *prim = l->data;
    bl_primary_t *bl_primary = bl_primary_new(prim->uuid, prim->changed,
        prim->range.start, prim->range.end);

    g_free(prim);

    if (bl_primary == NULL) {
      cb_ret_val = BL_MALLOC_ERROR;
      strcpy(cb_ret_msg, "Primary callback: Malloc error\n");
      goto error;
    }
    if (bl_primary_list == NULL) {
      bl_primary_list = g_slist_alloc();
      if (bl_primary_list == NULL) {
        cb_ret_val = BL_MALLOC_ERROR;
        strcpy(cb_ret_msg, "Primary callback: Malloc error\n");
        goto error;
      }
      bl_primary_list->data = bl_primary;
    } else {
      bl_primary_list = g_slist_append(bl_primary_list, bl_primary);
    }
  }

  cb_ret_val = BL_NO_ERROR;
  cb_ret_pointer = bl_primary_list;
  strcpy(cb_ret_msg, "Primary callback: Sucess\n");
  goto exit;

 error:
  if (bl_primary_list)
    bl_primary_list_free(bl_primary_list);
 exit:
  if (l)
    g_slist_free(l);
  g_mutex_unlock(pending_callback);
  printf_dbg("[CB] OUT primary_all_cb\n");
}
Exemplo n.º 2
0
void primary_by_uuid_cb(GSList *ranges, guint8 status,
                        gpointer user_data)
{
    GSList   *l;
    GSList   *bl_primary_list = NULL;
    cb_ctx_t *cb_ctx = user_data;

    printf_dbg("IN primary_by_uuid_cb\n");
    if (status) {
        cb_ctx->cb_ret_val = BL_REQUEST_FAIL_ERROR;
        sprintf(cb_ctx->cb_ret_msg, "Primary by UUID callback: Failure: %s\n",
                att_ecode2str(status));
        goto error;
    }
    if (ranges == NULL) {
        cb_ctx->cb_ret_val = BL_NO_ERROR;
        strcpy(cb_ctx->cb_ret_msg,
               "Primary by UUID callback: Nothing found\n");
        goto exit;
    }

    for (l = ranges; l; l = l->next) {
        struct att_range *range = l->data;
        bl_primary_t *bl_primary = bl_primary_new(NULL, 0, range->start,
                                                  range->end);
        free(range);

        if (bl_primary == NULL) {
            cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
            strcpy(cb_ctx->cb_ret_msg,
                   "Primary by UUID callback: Malloc error\n");
            goto error;
        }
        if (bl_primary_list == NULL) {
            bl_primary_list = g_slist_alloc();

            if (bl_primary_list == NULL) {
                cb_ctx->cb_ret_val = BL_MALLOC_ERROR;
                strcpy(cb_ctx->cb_ret_msg,
                       "Primary by UUID callback: Malloc error\n");
                goto error;
            }
            bl_primary_list->data = bl_primary;
        } else {
            bl_primary_list = g_slist_append(bl_primary_list, bl_primary);
        }
    }
    cb_ctx->cb_ret_val = BL_NO_ERROR;
    cb_ctx->cb_ret_pointer = bl_primary_list;
    goto exit;

error:
    if (bl_primary_list)
        bl_primary_list_free(bl_primary_list);
exit:
    g_mutex_unlock(&cb_ctx->pending_cb_mtx);
    printf_dbg("OUT primary_by_uuid_cb\n");
}