void Setting_Menu(IDirectFBEventBuffer *p_eventbuffer) { int key=0; int grid_count, node_count; char *icon_select; //start draw menu_list init setting_node=create_menu_tree(menu_title, menu_icon_path); node_count=get_fcnode_count(setting_node); grid_count = get_grid_count(grid); if(node_count<grid_count) clone_fctree(setting_node); draw_icon_tree(setting_node, icon, menu_icon_space, gp_dfb); blit_to_frame(setting_node, slide_info, slide_info->frame, icon, gp_dfb); slide_info->frame->window->SetOpacity(slide_info->frame->window, 255); //end draw menu_list init icon_select = setting_node->brother_node->brother_node->title; draw_title_string(icon_select, font_title, rgba, title_space, title_window_surface); while(1){ key = GetInputDeviceEventByType(p_eventbuffer, PTYPE_DEFAULT_API); if( key == DIKI_UP ){ setting_node=delete_fcnode_tree(setting_node); return; }else if( key == DIKI_LEFT ){ icon_select = setting_node->brother_node->title; draw_title_string(icon_select, font_title, rgba, title_space, title_window_surface); icon=slide_left(setting_node, slide_info, icon, gp_dfb); setting_node=get_fcnode_head(setting_node); }else if( key == DIKI_RIGHT ){ icon_select = setting_node->brother_node->brother_node->brother_node->title; draw_title_string(icon_select, font_title, rgba, title_space, title_window_surface); icon=slide_right(setting_node, slide_info, icon, gp_dfb); setting_node=get_fcnode_head(setting_node); }else if( key == DIKI_ENTER ){ icon_select = setting_node->brother_node->brother_node->title; slide_info->frame->window->SetOpacity(slide_info->frame->window, 0); if(!strcmp(icon_select,TITLE_LCD_LUN_SET)) { Adjust_Luminance(p_eventbuffer, main_layer); }else if(!strcmp(icon_select,TITLE_HD_SLEEP_SET)) { Sleeptime_Saving(p_eventbuffer, main_layer,"HD"); }else if(!strcmp(icon_select,TITLE_LCD_SLEEP_SET)) { Sleeptime_Saving(p_eventbuffer, main_layer,"LCD"); }else if(!strcmp(icon_select,TITLE_CLOCK_DISPLAY_SET)) { Clock_Display_Setting(p_eventbuffer); } redraw: draw_title_string(icon_select, font_title, rgba, title_space, title_window_surface); draw_icon_tree(setting_node, icon, menu_icon_space, gp_dfb); blit_to_frame(setting_node, slide_info, slide_info->frame, icon, gp_dfb); slide_info->frame->window->SetOpacity(slide_info->frame->window, 255); }else if( key == DIKI_A || key == DIKI_B ){ Detect_USBMount(p_eventbuffer); goto redraw; } p_eventbuffer->Reset(p_eventbuffer); } }
static int insert_element (SLang_List_Type *list, SLang_Object_Type *obj, SLindex_Type indx) { Chunk_Type *c, *c1; SLang_Object_Type *elem; SLindex_Type num; int equality_ok = 0; if (indx == 0) { c = list->first; if ((c != NULL) && (c->num_elements < c->chunk_size)) { slide_right (c, 0); c->elements[0] = *obj; goto the_return; } if (list->default_chunk_size < DEFAULT_CHUNK_SIZE) list->default_chunk_size *= 2; if (NULL == (c = new_chunk (list->default_chunk_size))) return -1; c->next = list->first; if (list->first != NULL) list->first->prev = c; list->first = c; if (list->last == NULL) list->last = c; c->elements[0] = *obj; equality_ok = 1; goto the_return; } if (indx == list->length) { c = list->last; if (c->num_elements < c->chunk_size) { c->elements[c->num_elements] = *obj; goto the_return; } if (list->default_chunk_size < DEFAULT_CHUNK_SIZE) list->default_chunk_size *= 2; if (NULL == (c = new_chunk (list->default_chunk_size))) return -1; c->prev = list->last; list->last->next = c; list->last = c; c->elements[0] = *obj; goto the_return; } if (NULL == (elem = find_nth_element (list, indx, &c))) return -1; if (c->num_elements < c->chunk_size) { slide_right (c, elem - c->elements); *elem = *obj; goto the_return; } if (list->default_chunk_size < DEFAULT_CHUNK_SIZE) list->default_chunk_size *= 2; if (NULL == (c1 = new_chunk (list->default_chunk_size))) return -1; num = c->chunk_size - (elem - c->elements); if (num == c->chunk_size) { c1->next = c; c1->prev = c->prev; if (c->prev != NULL) c->prev->next = c1; c->prev = c1; if (list->first == c) list->first = c1; c = c1; c->elements[0] = *obj; equality_ok = 1; goto the_return; } c1->prev = c; c1->next = c->next; if (c->next != NULL) c->next->prev = c1; c->next = c1; if (list->last == c) list->last = c1; memcpy ((char *)c1->elements, (char *)elem, num*sizeof(SLang_Object_Type)); c1->num_elements = num; c->num_elements -= num; c->elements[c->num_elements] = *obj; /* drop */ the_return: if (list->recent != NULL) { if ((list->recent_num > indx) || ((list->recent_num == indx) && equality_ok)) list->recent_num++; } c->num_elements++; list->length++; return 0; }
/** * Computing the Fisher's Exact Test (FET) and the corresponding standard deviation for a given thread. * @param threadarg: the arguments to the thread: a thread_data struct */ void mycompute(void *threadarg) { struct thread_data *my_data; int tid; int start, stop, regend, num_windows, wsize, wstep, alen, blen, asize, bsize, totalpos, npos, nsamples, my_task_id = 0; double perc; int *apos; int *bpos; double *avals; double *bvals; double *scores; double *stddev; /* fetch data from threadarg */ my_data = (struct thread_data *) threadarg; tid = my_data->thread_id; regend = my_data->regend; num_windows = my_data->num_windows; wsize = my_data->wsize; wstep = my_data->wstep; apos = my_data->apos; bpos = my_data->bpos; avals = my_data->avals; bvals = my_data->bvals; alen = my_data->alen; blen = my_data->blen; perc = my_data->perc; scores = my_data->scores; stddev = my_data->stddev; int wcount = 0; int wstart; int wstop; int *aidx; int *bidx; int *f; int *tmp; double *results; double *fetscores = NULL; double *samples = NULL; double *stdsamples; /* get size of population a and b*/ asize = get_population_size(apos); bsize = get_population_size(bpos); wcount = 0; start = 0; stop = wsize; nsamples = 100; /* setup idx arrays */ aidx = (int*)malloc(2*sizeof(int)); bidx = (int*)malloc(2*sizeof(int)); /* setup arrays for calc. of FET */ f = (int*)malloc(4*sizeof(int)); tmp = (int*)malloc(4*sizeof(int)); results = (double*)malloc(2*sizeof(double)); stdsamples = (double*)malloc(nsamples*sizeof(double)); int idx = 0; /* generate seed for the PRNG */ unsigned short state[3] = {0,0,0}; unsigned short seed = time(NULL) + (unsigned short) pthread_self(); memcpy(state, &seed, sizeof(seed)); // fetch new tasks and calculate FET while (my_task_id < num_tasks) { // try to fetch new task pthread_mutex_lock (&mutexTASK_ID); my_task_id= task_id; task_id++; pthread_mutex_unlock(&mutexTASK_ID); // if no more tasks, break if (my_task_id > num_tasks) break; // get chromosome position of the current task get_positions(wsize, wstep, my_task_id, &start, &stop, regend); // to include the last (possibly smaller) window if (stop >= regend) { stop = regend + wstep; } wstart = start; wstop = start+wsize; aidx[0] = 0; aidx[1] = 0; bidx[0] = 0; bidx[1] = 0; // calculate FET for each window while (wstart + wsize <= stop) { slide_right(aidx, apos, wstart, wstop, alen); slide_right(bidx, bpos, wstart, wstop, blen); npos = (aidx[1] - aidx[0])/asize; if (npos > 0) { fetscores = (double*)realloc(fetscores, npos*sizeof(double)); samples = (double*)realloc(samples, npos*sizeof(double)); idx = wstart/wstep; fisher_exact_test(results, &(avals[aidx[0]]), &(bvals[bidx[0]]), asize, bsize, npos, f, tmp, samples, stdsamples, nsamples, fetscores, state, perc); scores[idx] = results[0]; stddev[idx] = results[1]; } wstart += wstep; wstop += wstep; wcount++; } } /* cleanup */ free(aidx); free(bidx); free(f); free(tmp); free(results); free(samples); free(stdsamples); free(fetscores); }