void AudicleWindow::main_pick() { m_render_mode = GL_SELECT; glRenderMode( m_render_mode ); main_draw(); //return to normal m_render_mode = GL_RENDER; int nHit = glRenderMode( m_render_mode ); t_CKUINT n = 0 ; m_pick_top = NULL; m_pick_size = 0; // danger danger (I added these two variables; it used just m_*) t_CKUINT pick_size; // (**) GLuint * pick_top; // (**) for( int i = 0; i < nHit; i++ ) { // more danger #if 1 // danger danger pick_size = m_pick_buffer[n++]; // danger: used m_pick_size and m_pick_top t_CKUINT zMin = m_pick_buffer[n++]; t_CKUINT zMax = m_pick_buffer[n++]; pick_top = ( m_pick_buffer + n ); if( nHit <= 1 || pick_size > 1 ) // danger: this part was not there { m_pick_size = pick_size; m_pick_top = pick_top; } #else // (**) (= another option?) m_pick_size = m_pick_buffer[n++]; // nested danger t_CKUINT zMin = m_pick_buffer[n++]; t_CKUINT zMax = m_pick_buffer[n++]; m_pick_top = ( m_pick_buffer + n ); //m_pick_size += pick_size; // nested danger pick_size = m_pick_size; #endif #ifdef AUDICLE_DEBUG_PICK fprintf(stderr, "stack %d objs, %d %d\n", pick_size ,zMin, zMax ); // danger: m_pick_size for( int j = 0; j < pick_size ; j++ ) { fprintf(stderr, "item %u\n", m_pick_buffer[n++]); } #else n += pick_size; // danger: m_pick_size (**) #endif } #ifdef AUDICLE_DEBUG_PICK fprintf( stderr, "\n" ); #endif }
int main(int argc, char **argv) { /* Run main garbage collector when quiting the daemon */ gc_attach(main_gc); /* Catch all exit signals for gc */ gc_catch(); loglevel = LOG_INFO; log_file_disable(); log_shell_enable(); char *logfile = malloc(strlen(LOG_FILE)+1); strcpy(logfile, LOG_FILE); log_file_set(logfile); sfree((void *)&logfile); prevMessage = malloc(4); memset(prevMessage, '\0', 4); progname = malloc(14); strcpy(progname, "splash-daemon"); struct socket_callback_t socket_callback; struct options_t *options = NULL; char *args = NULL; char buffer[BUFFER_SIZE]; int f; options_add(&options, 'H', "help", no_value, 0, NULL); options_add(&options, 'V', "version", no_value, 0, NULL); options_add(&options, 'D', "nodaemon", no_value, 0, NULL); while (1) { int c; c = options_parse(&options, argc, argv, 1, &args); if (c == -1) break; switch(c) { case 'H': printf("Usage: %s [options]\n", progname); printf("\t -H --help\t\tdisplay usage summary\n"); printf("\t -V --version\t\tdisplay version\n"); printf("\t -S --settings\t\tsettings file\n"); printf("\t -D --nodaemon\t\tdo not daemonize and\n"); printf("\t\t\t\tshow debug information\n"); return (EXIT_SUCCESS); break; case 'V': printf("%s %s\n", progname, "1.0"); return (EXIT_SUCCESS); break; case 'D': nodaemon=1; break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); break; } } options_delete(options); pid_file = malloc(sizeof(PID_FILE)+1); strcpy(pid_file, PID_FILE); template_file = malloc(14); strcpy(template_file, "template.json"); if((f = open(pid_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) != -1) { if(read(f, buffer, BUFFER_SIZE) != -1) { //If the file is empty, create a new process if(!atoi(buffer)) { running = 0; } else { //Check if the process is running kill(atoi(buffer), 0); //If not, create a new process if(errno == ESRCH) { running = 0; } } } } else { logprintf(LOG_ERR, "could not open / create pid_file %s", pid_file); return EXIT_FAILURE; } close(f); if(nodaemon == 1 || running == 1) { log_level_set(LOG_DEBUG); } if(running == 1) { nodaemon=1; logprintf(LOG_NOTICE, "already active (pid %d)", atoi(buffer)); return EXIT_FAILURE; } if(nodaemon == 0) { deamonize(); socket_start(PORT); fb_init(); } else { socket_start(PORT); } if(template_read(template_file) == EXIT_FAILURE) { logprintf(LOG_NOTICE, "failed to read template file %s", template_file); main_gc(); return EXIT_FAILURE; } if(nodaemon == 1) { //template_print(); } //initialise all socket_clients and handshakes to 0 so not checked memset(socket_clients, 0, sizeof(socket_clients)); socket_callback.client_disconnected_callback = NULL; socket_callback.client_connected_callback = NULL; socket_callback.client_data_callback = &socket_parse_data; main_draw(); /* Make sure the server part is non-blocking by creating a new thread */ pthread_create(&pth, NULL, &update_progress, (void *)NULL); socket_wait((void *)&socket_callback); while(main_loop) { sleep(1); } return EXIT_FAILURE; }
/* Parse the incoming buffer from the client */ void socket_parse_data(int i, char buffer[BUFFER_SIZE]) { int sd = socket_clients[i]; struct sockaddr_in address; int addrlen = sizeof(address); char *message = NULL; JsonNode *json = json_decode(buffer); getpeername(sd, (struct sockaddr*)&address, (socklen_t*)&addrlen); if(json_find_string(json, "black", &message) == 0) { if(black == 0) { black = 1; draw_loop = 0; usleep((__useconds_t)speed); main_draw_black(); } else { main_draw(); black = 0; } } else { if(json_find_string(json, "percentage", &message) == 0) { if(black == 1) { progress_active = 0; main_draw(); black = 0; } draw_loop = 0; infinite = 0; pthread_mutex_lock(&progress_lock); percentage = atoi(message); draw_loop = 1; pthread_mutex_unlock(&progress_lock); pthread_cond_signal(&progress_signal); } else if(json_find_string(json, "infinite", &message) == 0) { if(black == 1) { progress_active = 0; main_draw(); black = 0; } draw_loop = 0; infinite = 1; pthread_mutex_lock(&progress_lock); draw_loop = 1; percentage = -1; pthread_mutex_unlock(&progress_lock); pthread_cond_signal(&progress_signal); } if(json_find_string(json, "message", &message) == 0) { struct template_t *tmp_tpl = template; while(tmp_tpl) { if(tmp_tpl->type == TEXT) { break; } tmp_tpl = tmp_tpl->next; } if(black == 1) { main_draw(); black = 0; } if(strlen(prevMessage) > 0) { main_clear_text(tmp_tpl); } main_draw_text(tmp_tpl, message); } } json_delete(json); }