コード例 #1
0
OSStatus bt_smartbridge_att_cache_find( const mico_bt_smart_device_t* remote_device, bt_smartbridge_att_cache_t** cache )
{
    OSStatus      result;
    linked_list_node_t* node_found;

    if ( remote_device == NULL || cache == NULL )
    {
        return MICO_BT_BADARG;
    }

    if ( att_cache_manager == NULL )
    {
        return MICO_BT_ATT_CACHE_UNINITIALISED;
    }

    /* Lock protection */
    result = mico_rtos_lock_mutex( &att_cache_manager->mutex );
    if ( result != MICO_BT_SUCCESS )
    {
        return result;
    }

    result = linked_list_find_node( &att_cache_manager->used_list, smartbridge_att_cache_find_by_device_callback, (void*)remote_device, &node_found );
    if ( result == MICO_BT_SUCCESS )
    {
        *cache = (bt_smartbridge_att_cache_t*)node_found->data;
    }

    /* Unlock protection */
    mico_rtos_unlock_mutex( &att_cache_manager->mutex );
    return result;
}
// dbFind:
// Search the database for specific deviceId/regId combination
dbEntry_t *dbFind(dbEntry_t *find)
{
	linked_list_node_t *found;

	if(linked_list_find_node( &db, dbCompare, (void*) find, &found ) == WICED_SUCCESS)
		return found->data;
	else
		return NULL;
}
コード例 #3
0
static OSStatus smartbridge_att_cache_get_free_cache( bt_smartbridge_att_cache_t** free_cache )
{
    OSStatus            result;
    linked_list_node_t* node;

    if ( att_cache_manager == NULL )
    {
        return MICO_BT_ATT_CACHE_UNINITIALISED;
    }

    /* Lock protection */
    result = mico_rtos_lock_mutex( &att_cache_manager->mutex );
    if ( result != kNoErr )
    {
        return result;
    }

    /* Remove from front of free list */
    result = linked_list_remove_node_from_front( &att_cache_manager->free_list, &node );

    /* Free list is empty. Remove the oldest one from used list */
    if ( result != MICO_BT_SUCCESS )
    {
        result = linked_list_find_node( &att_cache_manager->used_list, smartbridge_att_cache_get_free_callback, NULL, &node );
        if ( result == MICO_BT_SUCCESS )
        {
            result = linked_list_remove_node( &att_cache_manager->used_list, node );
            if ( result == MICO_BT_SUCCESS )
            {
                mico_bt_smart_attribute_list_t* list = (mico_bt_smart_attribute_list_t*)node->data;

                /* Delete list and set data to NULL */
                mico_bt_smart_attribute_delete_list( list );
            }
        }
    }

    if ( result == MICO_BT_SUCCESS )
    {
        *free_cache = (bt_smartbridge_att_cache_t*)node->data;
    }

    /* Unlock protection */
    mico_rtos_unlock_mutex( &att_cache_manager->mutex );

    return result;
}