library/src/datastructures/BP-DataLists.cc
// Add a new element at the end of the list
Add a new element at the end of the list
Add a new element at the end of the list
BP_ERROR_T BP_DataListAddEntry
(
	P_BP_DATA_LIST     data_list,
	char               *description,
	unsigned char *    data,
	size_t             data_size,
	BP_DATA_ENTRY_TYPE data_type,
	void            (* custom_prepare)(void *, void *),
	void              *custom_prepare_param,
	void            (* custom_read)(void *, void *),
	void             * custom_read_param,
	void            (* custom_write)(void *, void *),
	void             * custom_write_param,
	void            (* custom_post)(void *, void *),
	void             * custom_post_param
)
{
	if(!data_list || !data_type)
		return ERR_FAILURE;
	data_list->entries_n++;
	data_list->entries = (P_BP_DATA_LIST_ENTRY) tq_realloc(data_list->tq, data_list->entries, sizeof(BP_DATA_LIST_ENTRY) * data_list->entries_n, BPLN);
	if(!data_list->entries)
	{
		return ERR_FAILURE;
	}
	memset(&data_list->entries[data_list->entries_n-1], 0x00, sizeof(BP_DATA_LIST_ENTRY));
	P_BP_DATA_LIST_ENTRY tmp = (P_BP_DATA_LIST_ENTRY) &data_list->entries[data_list->entries_n-1];
	if(custom_prepare)
	{
		tmp->custom_prepare = custom_prepare;
		tmp->custom_prepare_params = custom_prepare_param;
	}
	if(custom_read)
	{
		tmp->custom_read = custom_read;
		tmp->custom_read_params = custom_read_param;
	}
	if(custom_write)
	{
		tmp->custom_write = custom_write;
		tmp->custom_write_params = custom_write_param;
	}
	if(custom_post)
	{
		tmp->custom_post = custom_post;
		tmp->custom_post_params = custom_post_param;
	}
	tmp->data = (unsigned char *) tq_realloc(data_list->tq, tmp->data, data_size, BPLN);
	if(data)
	{
		memcpy(tmp->data, data, data_size);
	}
	else 
	{
		memset(tmp->data, 0x00, data_size);
	}
	tmp->size = data_size;
	if(description)
		tmp->description = (char *) tq_strndup(data_list->tq, description, strnlen(description, 512), BPLN);
	switch(data_type)
	{
		case BP_DATA_ENTRY_TYPE_INT8:
			tmp->data_type = BP_DATA_ENTRY_TYPE_INT8;
			break;
		case BP_DATA_ENTRY_TYPE_INT16:
			tmp->data_type = BP_DATA_ENTRY_TYPE_INT16;
			break;
		case BP_DATA_ENTRY_TYPE_INT32:
			tmp->data_type = BP_DATA_ENTRY_TYPE_INT32;
			break;
		case BP_DATA_ENTRY_TYPE_INT64:
			tmp->data_type = BP_DATA_ENTRY_TYPE_INT64;
			break;
		case BP_DATA_ENTRY_TYPE_UINT8:
			tmp->data_type = BP_DATA_ENTRY_TYPE_UINT8;
			break;
		case BP_DATA_ENTRY_TYPE_UINT16:
			tmp->data_type = BP_DATA_ENTRY_TYPE_UINT16;
			break;
		case BP_DATA_ENTRY_TYPE_UINT32:
			tmp->data_type = BP_DATA_ENTRY_TYPE_UINT32;
			break;
		case BP_DATA_ENTRY_TYPE_UINT64:
			tmp->data_type = BP_DATA_ENTRY_TYPE_UINT64;
			break;
		case BP_DATA_ENTRY_TYPE_BINARY:
			tmp->data_type = BP_DATA_ENTRY_TYPE_BINARY;
			break;
		case BP_DATA_ENTRY_TYPE_ASCII:
			tmp->data_type = BP_DATA_ENTRY_TYPE_ASCII;
			break;
		case BP_DATA_ENTRY_TYPE_FORMAT:
			tmp->data_type = BP_DATA_ENTRY_TYPE_FORMAT;
			break;
		case BP_DATA_ENTRY_TYPE_RANDOM:
			tmp->data_type = BP_DATA_ENTRY_TYPE_RANDOM;
			break;
		case BP_DATA_ENTRY_TYPE_SEQUENCE:
			tmp->data_type = BP_DATA_ENTRY_TYPE_SEQUENCE;
			break;
		case BP_DATA_ENTRY_TYPE_READ:
			tmp->data_type = BP_DATA_ENTRY_TYPE_READ;
			break;
		default:
			tmp->data_type = BP_DATA_ENTRY_TYPE_UNSET;
			break;
	}
	tmp->activation_enabled   = BP_TRUE;
	if(data_list->prevent_activations == BP_TRUE)
		tmp->activation_administratively_prevented = BP_TRUE;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DataListAddEntry ( P_BP_DATA_LIST data_list , char * description , unsigned char * data , size_t data_size , BP_DATA_ENTRY_TYPE data_type , void ( * custom_prepare ) ( void * , void * ) , void * custom_prepare_param , void ( * custom_read ) ( void * , void * ) , void * custom_read_param , void ( * custom_write ) ( void * , void * ) , void * custom_write_param , void ( * custom_post ) ( void * , void * ) , void * custom_post_param ) { if ( ! data_list || ! data_type ) return ERR_FAILURE ; data_list -> entries_n ++ ; data_list -> entries = ( P_BP_DATA_LIST_ENTRY ) tq_realloc ( data_list -> tq , data_list -> entries , sizeof ( BP_DATA_LIST_ENTRY ) * data_list -> entries_n , BPLN ) ; if ( ! data_list -> entries ) { return ERR_FAILURE ; } memset ( & data_list -> entries [ data_list -> entries_n - 1 ] , 0x00 , sizeof ( BP_DATA_LIST_ENTRY ) ) ; P_BP_DATA_LIST_ENTRY tmp = ( P_BP_DATA_LIST_ENTRY ) & data_list -> entries [ data_list -> entries_n - 1 ] ; if ( custom_prepare ) { tmp -> custom_prepare = custom_prepare ; tmp -> custom_prepare_params = custom_prepare_param ; } if ( custom_read ) { tmp -> custom_read = custom_read ; tmp -> custom_read_params = custom_read_param ; } if ( custom_write ) { tmp -> custom_write = custom_write ; tmp -> custom_write_params = custom_write_param ; } if ( custom_post ) { tmp -> custom_post = custom_post ; tmp -> custom_post_params = custom_post_param ; } tmp -> data = ( unsigned char * ) tq_realloc ( data_list -> tq , tmp -> data , data_size , BPLN ) ; if ( data ) { memcpy ( tmp -> data , data , data_size ) ; } else { memset ( tmp -> data , 0x00 , data_size ) ; } tmp -> size = data_size ; if ( description ) tmp -> description = ( char * ) tq_strndup ( data_list -> tq , description , strnlen ( description , 512 ) , BPLN ) ; switch ( data_type ) { case BP_DATA_ENTRY_TYPE_INT8 : tmp -> data_type = BP_DATA_ENTRY_TYPE_INT8 ; break ; case BP_DATA_ENTRY_TYPE_INT16 : tmp -> data_type = BP_DATA_ENTRY_TYPE_INT16 ; break ; case BP_DATA_ENTRY_TYPE_INT32 : tmp -> data_type = BP_DATA_ENTRY_TYPE_INT32 ; break ; case BP_DATA_ENTRY_TYPE_INT64 : tmp -> data_type = BP_DATA_ENTRY_TYPE_INT64 ; break ; case BP_DATA_ENTRY_TYPE_UINT8 : tmp -> data_type = BP_DATA_ENTRY_TYPE_UINT8 ; break ; case BP_DATA_ENTRY_TYPE_UINT16 : tmp -> data_type = BP_DATA_ENTRY_TYPE_UINT16 ; break ; case BP_DATA_ENTRY_TYPE_UINT32 : tmp -> data_type = BP_DATA_ENTRY_TYPE_UINT32 ; break ; case BP_DATA_ENTRY_TYPE_UINT64 : tmp -> data_type = BP_DATA_ENTRY_TYPE_UINT64 ; break ; case BP_DATA_ENTRY_TYPE_BINARY : tmp -> data_type = BP_DATA_ENTRY_TYPE_BINARY ; break ; case BP_DATA_ENTRY_TYPE_ASCII : tmp -> data_type = BP_DATA_ENTRY_TYPE_ASCII ; break ; case BP_DATA_ENTRY_TYPE_FORMAT : tmp -> data_type = BP_DATA_ENTRY_TYPE_FORMAT ; break ; case BP_DATA_ENTRY_TYPE_RANDOM : tmp -> data_type = BP_DATA_ENTRY_TYPE_RANDOM ; break ; case BP_DATA_ENTRY_TYPE_SEQUENCE : tmp -> data_type = BP_DATA_ENTRY_TYPE_SEQUENCE ; break ; case BP_DATA_ENTRY_TYPE_READ : tmp -> data_type = BP_DATA_ENTRY_TYPE_READ ; break ; default : tmp -> data_type = BP_DATA_ENTRY_TYPE_UNSET ; break ; } tmp -> activation_enabled = BP_TRUE ; if ( data_list -> prevent_activations == BP_TRUE ) tmp -> activation_administratively_prevented = BP_TRUE ; return ERR_SUCCESS ; }
Add a new element at the end of the list
Add a new element at the end of the list
// ensure we have a datalist and a data type // increment entries count // reallocate space for entries // create space for item // return indicating failure if we cannot allocate space for the chunk // zero out the structure data // create temporary pointer // set custom prepare callback // set custom read // set custom write // set custom post // reallocate space for data // copy in data if necessary (read chunks do not need to perform this step) // zero out memory if not assigning // set data size // set description // switch on the data type // signed 8 bit integer // signed 16 bit integer // signed 32 bit integer // signed 64 bit integer // unsigned 8 bit integer // unsigned 16bit integer // unsigned 32bit integer // unsigned 64bit integer // arbitrary binary entry // ascii entry // format specifiers // random data // arbitrary sequence data // read entry // default is a bad/unset type // set activation flags // set disabled flag if necessary // return indicating success