/**************************************************************************** NAME inquiry_start_discovery - Begin inquiry procedure */ void inquiry_start_discovery(void) { INQUIRY_DEBUG(("INQUIRY: inquiry_start_discovery\n")); if (theSource->inquiry_data == NULL) { theSource->inquiry_data = (INQUIRY_SCAN_DATA_T *) memory_create(sizeof(INQUIRY_SCAN_DATA_T)); if (theSource->inquiry_data) { /* set read and write indexes */ theSource->inquiry_data->read_idx = 0; theSource->inquiry_data->write_idx = 0; theSource->inquiry_data->search_idx = 0; theSource->inquiry_data->inquiry_state_timeout = 0; if (theSource->ps_config->ps_timers.inquiry_state_timer != TIMER_NO_TIMEOUT) { MessageSendLater(&theSource->app_data.appTask, APP_INQUIRY_STATE_TIMEOUT, 0, D_SEC(theSource->ps_config->ps_timers.inquiry_state_timer)); } } } if (theSource->inquiry_data) { /* start Bluetooth inquiry */ ConnectionInquire(&theSource->connectionTask, INQUIRY_LAP, INQUIRY_MAX_RESPONSES, INQUIRY_TIMEOUT, (uint32)COD_MAJOR_AV); } else { /* memory should exist here issue a Panic */ Panic(); } }
NetStream *net_stream_create (NetStreamOnAdd on_add, NetStreamOnClose on_close, NetStreamOnRead on_read, void *tag) { NetStream *stream; if (!(stream = memory_create (sizeof (NetStream)))) { error_code (FunctionCall, 1); return NULL; } if (!(stream->poll = net_poll_create (&poll_on_monitor, &poll_on_close, &poll_on_read, &poll_on_write))) { memory_destroy (stream); error_code (FunctionCall, 2); return NULL; } if (!(stream->worker = net_stream_worker_create (stream->poll))) { net_poll_destroy (stream->poll); memory_destroy (stream); error_code (FunctionCall, 3); return NULL; } stream->on_add = on_add; stream->on_close = on_close; stream->on_read = on_read; stream->poll->tag = stream; stream->tag = tag; return stream; }
DisplayPlugin *display_plugin_create (const char *path) { DisplayPlugin *display_plugin; if (!path) { error (InvalidArgument); return NULL; } if (!(display_plugin = memory_create (sizeof (DisplayPlugin)))) { error_code (FunctionCall, 1); return NULL; } if (!(display_plugin->plugin = plugin_create (path))) { memory_destroy (display_plugin); error_code (FunctionCall, 2); return NULL; } if (!(plugin_set_function (display_plugin->plugin, (void **)&display_plugin->display_canvas, "display_canvas"))) { plugin_destroy (display_plugin->plugin); memory_destroy (display_plugin); error_code (FunctionCall, 3); return NULL; } if (!display_plugin->plugin->load ()) { plugin_destroy (display_plugin->plugin); memory_destroy (display_plugin); error_code (FunctionCall, 4); return NULL; } return display_plugin; }
static bool tokenize_or (const char *pattern, size_t length, size_t *i, PatternToken **token) { if (!(*token)) { error (PatternOrMissingLeftOperand); return false; } if ((*token)->type != PatternTokenTypeParenthesesClose && (*token)->type != PatternTokenTypeRepeat && (*token)->type != PatternTokenTypeRange && (*token)->type != PatternTokenTypeSet && (*token)->type != PatternTokenTypeValue) { error (PatternOrInvalidLeftOperand); return false; } if (*i + 1 >= length) { error (PatternOrMissingRightOperand); return false; } if (pattern[*i + 1] == ')' || pattern[*i + 1] == '|' || pattern[*i + 1] == '{' || pattern[*i + 1] == '}' || pattern[*i + 1] == ']' || pattern[*i + 1] == '>') { error (PatternOrInvalidRightOperand); return false; } if (!(*token = memory_create (sizeof (PatternToken)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeOr; (*i)++; return true; }
static bool tokenize_range (const char *pattern, size_t length, size_t *i, PatternToken **token) { unsigned char from; unsigned char to; if (++(*i) >= length) { error (PatternRangeMissingFrom); return false; } if (pattern[*i] == '-') { from = 0; } else { if (!pattern_token_string_to_value (pattern, length, i, &from)) { error (PatternRangeInvalidFrom); return false; } if (*i >= length) { error (PatternRangeMissingHyphen); return false; } if (pattern[*i] != '-') { error (PatternRangeMissingHyphen); return false; } } if (++(*i) >= length) { error (PatternRangeMissingTo); return false; } if (pattern[*i] == ']') { to = UCHAR_MAX; } else { if (!pattern_token_string_to_value (pattern, length, i, &to)) { error (PatternRangeInvalidTo); return false; } if (*i >= length) { error (PatternRangeMissingCloseBracket); return false; } if (pattern[*i] != ']') { error (PatternRangeMissingCloseBracket); return false; } } if (!(*token = memory_create (sizeof (PatternTokenRange)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeRange; ((PatternTokenRange *)(*token))->from = from; ((PatternTokenRange *)(*token))->to = to; (*i)++; return true; }
static bool tokenize_set (const char *pattern, size_t length, size_t *i, PatternToken **token) { size_t values_length; size_t seek; unsigned char value; if (++(*i) >= length) { error_code (PatternSetMissingValue, 1); return false; } for (seek = *i, values_length = 0; seek < length && pattern[seek] != '>'; values_length++) { if (!pattern_token_string_to_value (pattern, length, &seek, &value)) { error_code (PatternSetValueInvalid, 1); return false; } } if (values_length == 0) { error_code (PatternSetMissingValue, 2); return false; } if (seek >= length) { error (PatternSetMissingClosingBracket); return false; } if (!(*token = memory_create (sizeof (PatternTokenSet)))) { error_code (FunctionCall, 1); return false; } (*token)->type = PatternTokenTypeSet; if (!(((PatternTokenSet *)(*token))->values = memory_create (values_length))) { memory_destroy (*token); *token = NULL; error_code (FunctionCall, 2); return false; } ((PatternTokenSet *)(*token))->values_length = values_length; for (values_length = 0; pattern[*i] != '>'; values_length++) { (void)pattern_token_string_to_value (pattern, length, i, &value); ((PatternTokenSet *)(*token))->values[values_length] = value; } (*i)++; return true; }
static bool tokenize_not (size_t *i, PatternToken **token) { if (!(*token = memory_create (sizeof (PatternToken)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeNot; (*i)++; return true; }
static bool tokenize_parentheses_open (size_t *i, PatternToken **token) { if (!(*token = memory_create (sizeof (PatternToken)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeParenthesesOpen; (*i)++; return true; }
bool net_websocket_frame_create (NetWebsocketFrame *frame) { if (!(frame->buffer = memory_create (1024))) { error (FunctionCall); return false; } frame->size = 1024; frame->length = 0; return true; }
void client_start (size_t count, size_t _package_size, size_t _seconds) { connections_max = count; package_size = _package_size; seconds = _seconds; buffer = memory_create (sizeof (char) * package_size); connections = memory_create (sizeof (NetClientConnection) * count); streams = memory_create (sizeof (NetStreamConnection *) * count); stream = net_stream_create (&client_stream_on_add, &client_stream_on_close, &client_stream_on_read, NULL); client = net_client_create (&client_on_connect, &client_on_connect_error, &client_on_error, NULL); (void)thread_create (&worker, NULL); }
Tree *tree_create () { Tree *tree; if (!(tree = memory_create (sizeof (Tree)))) { error (FunctionCall); return NULL; } if (!(tree->nil = memory_create (sizeof (TreeNode)))) { memory_destroy (tree); error (FunctionCall); return NULL; } tree->nil->level = 0; tree->nil->key = NULL; tree->nil->value = NULL; tree->nil->link[0] = tree->nil->link[1] = tree->nil; tree->root = tree->nil; tree->count = 0; return tree; }
TreeIterator *tree_iterator_create (Tree *tree) { TreeIterator *iterator; if (!(iterator = memory_create (sizeof (TreeIterator)))) { error (FunctionCall); return NULL; } if (!(iterator->path = memory_create (sizeof (TreeNode *) * iterator_path_size))) { memory_destroy (iterator); error (FunctionCall); return NULL; } iterator->tree = tree; iterator->index = 0; iterator->index_is_set = false; iterator->node = NULL; iterator->key = NULL; iterator->value = NULL; return iterator; }
computer_t *computer_create () { computer_t *computer = (computer_t*) malloc (sizeof (computer_t)); computer->cpu = cpu_create (computer); computer->memory = memory_create (computer); computer->devices = device_list_create (); graphic_card_register (computer); return computer; }
Canvas *canvas_create (Size size) { Canvas *canvas; if (size.width == 0) { error_code (InvalidArgument, 1); return NULL; } if (size.height == 0) { error_code (InvalidArgument, 2); return NULL; } if (!size_t_mul (size.width, size.height, NULL)) { error_code (Overflow, 1); return NULL; } if (!size_t_mul (size.width * size.height, sizeof (Color), NULL)) { error_code (Overflow, 2); return NULL; } if (!(canvas = memory_create (sizeof (Canvas)))) { error_code (FunctionCall, 1); return NULL; } if (!thread_lock_create (&canvas->lock)) { memory_destroy (canvas); error_code (FunctionCall, 2); return NULL; } if (!(canvas->image.map = memory_create (size.width * size.height * sizeof (Color)))) { thread_lock_destroy (&canvas->lock); memory_destroy (canvas); error_code (FunctionCall, 3); return NULL; } canvas->image.width = size.width; canvas->image.height = size.height; canvas->changed = false; return canvas; }
static TreeNode *node_create (Tree *tree, Object *key, size_t level) { TreeNode *node; if (!(node = memory_create (sizeof (TreeNode)))) { error (FunctionCall); return NULL; } node->key = key; node->level = level; node->link[0] = node->link[1] = tree->nil; return node; }
List *list_create (void) { List *list; if (!(list = memory_create (sizeof (List)))) { error (FunctionCall); return NULL; } list->first = NULL; list->last = NULL; list->count = 0; return list; }
static bool tokenize_value (const char *pattern, size_t length, size_t *i, PatternToken **token) { unsigned char value; if (!pattern_token_string_to_value (pattern, length, i, &value)) { error (PatternValueInvalid); return false; } if (!(*token = memory_create (sizeof (PatternTokenValue)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeValue; ((PatternTokenValue *)(*token))->value = value; return true; }
static int get_buffer(AVCodecContext *vcodec_ctx, AVFrame *vcodec_picture) { VideoDecoder *vdec = (VideoDecoder *)vcodec_ctx->opaque; struct videodecoder_avcodec *vdm = (struct videodecoder_avcodec *)vdec->opaque; int width, height; Picture_buffer *buf; /* alignment */ width = (vcodec_ctx->width + 15) & ~15; height = (vcodec_ctx->height + 15) & ~15; if (vcodec_ctx->pix_fmt != PIX_FMT_YUV420P || width != vcodec_ctx->width || height != vcodec_ctx->height) { debug_message_fnc("avcodec: unsupported frame format, DR1 disabled.\n"); vdm->vcodec_ctx->get_buffer = avcodec_default_get_buffer; vdm->vcodec_ctx->reget_buffer = avcodec_default_reget_buffer; vdm->vcodec_ctx->release_buffer = avcodec_default_release_buffer; return avcodec_default_get_buffer(vcodec_ctx, vcodec_picture); } buf = &vdm->picture_buffer[vdm->picture_buffer_count]; if (buf->base == NULL) { int datasize = image_bpl(vdm->p) * image_height(vdm->p); int size = sizeof(struct pic_buf) + datasize; struct pic_buf *pb; if ((buf->base = memory_create()) == NULL) { err_message_fnc("No enough memory for Memory object buf->base.\n"); return -1; } if ((pb = memory_alloc(buf->base, size)) == NULL) { err_message_fnc("Cannot allocate %d bytes. No enough memory for pic_buf.\n", size); return -1; } pb->idx = vdm->picture_buffer_count; pb->mem = buf->base; memset(pb->data, 128, datasize); buf->pb = pb; buf->linesize[0] = image_width(vdm->p); buf->linesize[1] = image_width(vdm->p) >> 1; buf->linesize[2] = image_width(vdm->p) >> 1; }
NetPollEvents *net_poll_events_create (void) { NetPollEvents *events; struct epoll_event event = { 0 }; if (!(events = memory_create (sizeof (NetPollEvents)))) { error_code (FunctionCall, 1); return NULL; } events->file = -1; events->internal_event = -1; events->event_index = 0; events->event_count = 0; events->queue_got_events = false; if (!queue_create (&events->queue, 1024, sizeof (NetPollEvent), QUEUE_SIZE_DYNAMIC)) { memory_destroy (events); error_code (FunctionCall, 2); return NULL; } if ((events->file = epoll_create1 (0)) == -1) { net_poll_events_destroy (events); error_code (SystemCall, 1); return NULL; } if ((events->internal_event = eventfd (0, EFD_NONBLOCK)) == -1) { error_code (SystemCall, 2); net_poll_events_destroy (events); return NULL; } event.data.ptr = &events->internal_event; event.events = EPOLLIN | EPOLLET; if (epoll_ctl (events->file, EPOLL_CTL_ADD, events->internal_event, &event) == -1) { net_poll_events_destroy (events); error_code (SystemCall, 3); return NULL; } return events; }
ListNode *list_append (List *list, void *data) { ListNode *node; if (!list) { error (InvalidArgument); return NULL; } if (!size_t_add (list->count, 1, NULL)) { error (Overflow); return NULL; } if (!(node = memory_create (sizeof (ListNode)))) { error (FunctionCall); return NULL; } node->data = data; return (ListNode *)list_item_append (list, (ListItem *)node); }
CompileProject *compile_project_create (const char *path) { CompileProject *project = NULL; if (!file_path_is_valid (path)) { compile_print ("The path is not valid: %s\n", path); error_code (FunctionCall, 1); return NULL; } if (!(project = memory_create (sizeof (CompileProject)))) { error_code (FunctionCall, 2); return NULL; } if (!(project->topological = topological_create ())) { compile_project_destroy (project); error_code (FunctionCall, 3); return NULL; } if (!(project->nodes = list_create ())) { compile_project_destroy (project); error_code (FunctionCall, 4); return NULL; } if (!(project->directory_to_compile = tree_create ())) { compile_project_destroy (project); error_code (FunctionCall, 5); return NULL; } if (!(project->directory = directory_open (path))) { compile_print ("Failed to open the directory: %s\n", path); compile_project_destroy (project); error_code (FunctionCall, 6); return NULL; } if (!string_begins_with (project->directory->name, "project.")) { compile_print ("The directory name must begin with 'project.'.\n"); compile_project_destroy (project); error_code (FunctionCall, 7); return NULL; } project->sorted = NULL; return project; }
NetClient *net_client_create (NetClientOnConnect on_connect, NetClientOnConnectError on_connect_error, NetClientOnError on_error, void *tag) { NetClient *client; signal (SIGPIPE, SIG_IGN); if (!on_connect) { error_code (InvalidArgument, 1); return NULL; } if (!on_connect_error) { error_code (InvalidArgument, 2); return NULL; } if (!on_error) { error_code (InvalidArgument, 3); return NULL; } if (!(client = memory_create (sizeof (NetClient)))) { error_code (FunctionCall, 1); return NULL; } client->on_connect = on_connect; client->on_connect_error = on_connect_error; client->on_error = on_error; client->tag = tag; if (!(client->epoll = net_client_epoll_allocate ())) { net_client_destroy (client); error_code (FunctionCall, 2); return NULL; } if (!(client->thread = thread_create (&worker, client))) { net_client_destroy (client); error_code (FunctionCall, 3); return NULL; } return client; }
FileReader *file_reader_create (const char *path) { FileReader *reader; struct stat st; if (!file_path_is_valid (path)) { error_code (FunctionCall, 1); return NULL; } if (!(reader = memory_create (sizeof (FileReader)))) { error_code (FunctionCall, 2); return NULL; } reader->file_descriptor = -1; if (stat (path, &st) != 0) { file_reader_destroy (reader); error_code (SystemCall, 1); return NULL; } reader->size = st.st_size; if ((reader->file_descriptor = open (path, O_RDONLY, 0)) == -1) { file_reader_destroy (reader); error_code (SystemCall, 2); return NULL; } if ((reader->map = (unsigned char *)mmap (NULL, (size_t)reader->size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, reader->file_descriptor, 0)) == MAP_FAILED) { file_reader_destroy (reader); error_code (SystemCall, 3); return NULL; } return reader; }
bool test_poll_write_2 (Test *test) { NetPoll *poll; NetServer *server; NetClient *client; NetClientConnection connect; size_t i; TITLE (); poll_client.closed = false; poll_server.closed = false; read_count = 0; CATCH (!(server = net_server_create ("127.0.0.1", 8888, &server_on_connect, &server_on_error, NULL))); CATCH (!(client = net_client_create (&client_on_connect, &client_on_connect_error, &client_on_error, NULL))); CATCH (!(poll = net_poll_create (&poll_on_monitor, &poll_on_close, &poll_on_read, &poll_on_write))); // Allocate buffer CATCH (!(write_buffer = memory_create (BufferSize))); for (i = 0; i < BufferSize; i++) { write_buffer[i] = (unsigned char)i; } // Connect client. connect.ip = "127.0.0.1"; connect.port = 8888; net_client_connect (client, &connect); // Wait for connections to be completed. thread_signal_wait (&client_connect_signal); thread_signal_wait (&server_connect_signal); // Poll client and server connection. poll_client.socket = client_socket; poll_server.socket = server_socket; CATCH (!net_poll_monitor (poll, &poll_client)); CATCH (!net_poll_monitor (poll, &poll_server)); // Wait for monitors to be completed. thread_signal_wait (&client_monitor_signal); thread_signal_wait (&server_monitor_signal); // Write and wait. CATCH (!net_poll_write (poll, &poll_server, write_buffer, BufferSize)); thread_signal_wait (&client_read_signal); // We're done, let's close poll client. net_poll_close (poll, &poll_client); // Now wait for client and server poll to close. thread_signal_wait (&client_close_signal); thread_signal_wait (&server_close_signal); net_poll_destroy (poll); net_server_destroy (server); net_client_destroy (client); memory_destroy (write_buffer); CATCH (error_count () != 0); PASS (); }
static bool tokenize_repeat (const char *pattern, size_t length, size_t *i, PatternToken **token) { unsigned long long from; unsigned long long to; size_t digits; if (!(*token)) { error (PatternRepeatMissingOperand); return false; } if ((*token)->type != PatternTokenTypeParenthesesClose && (*token)->type != PatternTokenTypeRepeat && (*token)->type != PatternTokenTypeRange && (*token)->type != PatternTokenTypeSet && (*token)->type != PatternTokenTypeValue) { error (PatternRepeatInvalidOperand); return false; } if (++(*i) >= length) { error (PatternRepeatMissingFrom); return false; } if (pattern[*i] == '-') { from = 0; } else { if (!convert_string_to_unsigned_long_long (pattern + *i, &from, &digits)) { error (PatternRepeatInvalidFrom); return false; } *i += digits; if (*i >= length) { error (PatternRepeatMissingCloseBracket); return false; } if (pattern[*i] == '}') { if (!(*token = memory_create (sizeof (PatternTokenRepeat)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeRepeat; ((PatternTokenRepeat *)(*token))->from = from; ((PatternTokenRepeat *)(*token))->to = from; (*i)++; return true; } if (pattern[*i] != '-') { error (PatternRepeatMissingHyphen); return false; } } if (++(*i) >= length) { error (PatternRepeatMissingTo); return false; } if (pattern[*i] == '}') { to = ULLONG_MAX; } else { if (!convert_string_to_unsigned_long_long (pattern + *i, &to, &digits)) { error (PatternRepeatInvalidTo); return false; } *i += digits; if (*i >= length) { error (PatternRepeatMissingCloseBracket); return false; } if (pattern[*i] != '}') { error (PatternRepeatMissingCloseBracket); return false; } } if (!(*token = memory_create (sizeof (PatternTokenRepeat)))) { error (FunctionCall); return false; } (*token)->type = PatternTokenTypeRepeat; ((PatternTokenRepeat *)(*token))->from = from; ((PatternTokenRepeat *)(*token))->to = to; (*i)++; return true; }
/* converts giflib format image into enfle format image */ static int gif_convert(Image *p, GIF_info *g_info, GIF_image *image) { GIF_ct *ct; int i, if_animated; //int transparent_disposal; #if 0 if (image->next != NULL) { if ((p->next = image_create()) == NULL) { image_destroy(p); return 0; } if (!gif_convert(p->next, g_info, image->next)) { image_destroy(p); return 0; } } else p->next = NULL; #endif //swidth = g_info->sd->width; //sheight = g_info->sd->height; image_left(p) = image->id->left; image_top(p) = image->id->top; image_width(p) = image->id->width; image_height(p) = image->id->height; #if 0 if (image_width(p) > swidth || image_height(p) > sheight) { show_message("screen (%dx%d) but image (%dx%d)\n", swidth, sheight, p->width, p->height); swidth = image_width(p); sheight = image_height(p); } #endif p->ncolors = image->id->lct_follows ? 1 << image->id->depth : 1 << g_info->sd->depth; p->type = _INDEX; //p->delay = image->gc->delay ? image->gc->delay : 1; if_animated = g_info->npics > 1 ? 1 : 0; debug_message("GIF: %d pics animation %d\n", g_info->npics, if_animated); #if 0 if (image->gc->transparent) { p->transparent_disposal = if_animated ? _TRANSPARENT : transparent_disposal; p->transparent.index = image->gc->transparent_index; } else p->transparent_disposal = _DONOTHING; p->image_disposal = image->gc->disposal; p->background.index = g_info->sd->back; #endif if (image->id->lct_follows) ct = image->id->lct; else if (g_info->sd->gct_follows) ct = g_info->sd->gct; else { fprintf(stderr, "Null color table..\n"); ct = NULL; } for (i = 0; i < (int)p->ncolors; i++) { p->colormap[i][0] = ct->cell[i]->value[0]; p->colormap[i][1] = ct->cell[i]->value[1]; p->colormap[i][2] = ct->cell[i]->value[2]; } image_bpl(p) = image_width(p); if (!image_image(p)) image_image(p) = memory_create(); if (memory_alloc(image_image(p), image_bpl(p) * image_height(p)) == NULL) return 0; memcpy(memory_ptr(image_image(p)), image->data, image_bpl(p) * image_height(p)); return 1; }
/**************************************************************************** NAME inquiry_write_eir_data - Write devices EIR data */ void inquiry_write_eir_data(const CL_DM_LOCAL_NAME_COMPLETE_T *data) { /* Determine length of EIR data */ uint16 total_eir_size = 0; uint16 size_uuids = 0; uint8 *eir = NULL; if (AGHFP_PROFILE_IS_ENABLED) { size_uuids += sizeof(eir_hfp_uuids); } if (A2DP_PROFILE_IS_ENABLED) { size_uuids += sizeof(eir_a2dp_uuids); } if (AVRCP_PROFILE_IS_ENABLED) { size_uuids += sizeof(eir_avrcp_uuids); } total_eir_size = EIR_BLOCK_SIZE(EIR_DATA_SIZE_FULL(data->size_local_name) + EIR_DATA_SIZE_FULL(sizeof(uint8)) + EIR_DATA_SIZE_FULL(size_uuids)); /* Allocate space for EIR data */ eir = (uint8 *)memory_create(total_eir_size); if (eir) { uint8 *p = eir; /* Device Name Field */ *p++ = EIR_DATA_SIZE(data->size_local_name); *p++ = EIR_TYPE_LOCAL_NAME_COMPLETE; memmove(p, data->local_name, data->size_local_name); p += data->size_local_name; /* Inquiry Tx Field */ *p++ = EIR_DATA_SIZE(sizeof(int8)); *p++ = EIR_TYPE_INQUIRY_TX; *p++ = theSource->inquiry_mode.inquiry_tx; /* UUID16 field */ *p++ = EIR_DATA_SIZE(sizeof(eir_uuids)); *p++ = EIR_TYPE_UUID16_COMPLETE; if (AGHFP_PROFILE_IS_ENABLED) { memmove(p, eir_hfp_uuids, sizeof(eir_hfp_uuids)); p += sizeof(eir_hfp_uuids); } if (A2DP_PROFILE_IS_ENABLED) { memmove(p, eir_a2dp_uuids, sizeof(eir_a2dp_uuids)); p += sizeof(eir_a2dp_uuids); } if (AVRCP_PROFILE_IS_ENABLED) { memmove(p, eir_avrcp_uuids, sizeof(eir_avrcp_uuids)); p += sizeof(eir_avrcp_uuids); } /* NULL Termination */ *p++ = 0x00; /* Register and free EIR data */ ConnectionWriteEirData(FALSE, total_eir_size, eir); memory_free(eir); INQUIRY_DEBUG(("INQUIRY: inquiry_write_eir_data\n")); } }
void memory_typicall(void) { AbstractMemory *mem; StatisticsInfo *info; ConfigFile *cfg; MemoryCell cells[8]; char conf_file[] = "test_config_file.txt"; FILE *cfg_f = NULL; cfg_f = fopen(conf_file, "w"); fprintf(cfg_f, "memory_size = %d\n memory_read_time = 4\n memory_write_time = 8\n memory_width = 4\n", 16 * KiB); fclose(cfg_f); cfg = config_file_parse(conf_file, stderr); unlink(conf_file); info = statistics_create(cfg); mem = memory_create(cfg, NULL, info); CU_ASSERT_NOT_EQUAL(mem, NULL); mem->ops->read(mem, 15, 1, cells); CU_ASSERT_EQUAL(cells[0].flags, 0); CU_ASSERT_EQUAL(info->clock_counter, 4); mem->ops->read(mem, 13, 4, cells); CU_ASSERT_EQUAL(cells[0].flags, 0); CU_ASSERT_EQUAL(cells[1].flags, 0); CU_ASSERT_EQUAL(cells[2].flags, 0); CU_ASSERT_EQUAL(cells[3].flags, 0); CU_ASSERT_EQUAL(info->clock_counter, 8); mem->ops->read(mem, 13, 8, cells); CU_ASSERT_EQUAL(info->clock_counter, 16); cells[0].flags = 1; cells[0].value = 0xFF; cells[1].flags = 1; cells[1].value = 183; cells[2].flags = 0; mem->ops->write(mem, 1, 2, cells); CU_ASSERT_EQUAL(info->clock_counter, 24); memset(cells, 0, sizeof(cells)); mem->ops->read(mem, 1, 2, cells); CU_ASSERT_EQUAL(cells[0].value, 0xFF); CU_ASSERT_EQUAL(cells[0].flags, 1); CU_ASSERT_EQUAL(cells[1].value, 183); CU_ASSERT_EQUAL(cells[1].flags, 1); CU_ASSERT_EQUAL(cells[2].flags, 0); CU_ASSERT_EQUAL(info->clock_counter, 28); cells[0].flags = 1; cells[0].value = 0; cells[1].flags = 1; cells[1].value = 73; cells[2].flags = 0; mem->ops->reveal(mem, 0, 2, cells); CU_ASSERT_EQUAL(info->clock_counter, 28); memset(cells, 0, sizeof(cells)); mem->ops->read(mem, 0, 4, cells); CU_ASSERT_EQUAL(cells[0].value, 0); CU_ASSERT_EQUAL(cells[0].flags, 1); CU_ASSERT_EQUAL(cells[1].value, 73); CU_ASSERT_EQUAL(cells[1].flags, 1); CU_ASSERT_EQUAL(cells[2].value, 183); CU_ASSERT_EQUAL(cells[2].flags, 1); CU_ASSERT_EQUAL(cells[3].flags, 0); CU_ASSERT_EQUAL(info->clock_counter, 32); // FIXME: add tests CU_ASSERT_EQUAL(mem->ops->free(mem), NULL); }