Exemple #1
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
static void handle_connection(struct httpd_state *s)
{
	handle_input(s);
	if(s->state == STATE_OUTPUT)
	{
		handle_output(s);
	}
}
Exemple #2
0
void SceneEdit::scene_update() {
    handle_input();
    camera->update();

    UI->update_UIObject();
    chess_board->find_select_cube();
    chess_board->winner=chess_board->check_winner(chess_board->chess_board);
}
Exemple #3
0
void handle_events() {
	handle_input();
	move();
	kb.keys[SDLK_UP] =
	kb.keys[SDLK_RIGHT] =
	kb.keys[SDLK_DOWN] =
	kb.keys[SDLK_LEFT] = 0; 
}
Exemple #4
0
void P2pEndpoint::read()
{
    if (! isOpened()) {
        return;
    }

    (void)handle_input(0);
}
Exemple #5
0
// The Mouse functions    (1-Oct-2000, Matthew Weathers)
bool mouseup() {
    while (handle_input(false));
	if (bMouseUp) {
		bMouseUp=false;
		return true;
	} else {
		return false;
	}
}
Exemple #6
0
bool mousedown() {
    while (handle_input(false));
	if (bMouseDown) {
		bMouseDown=false;
		return true;
	} else {
		return false;
	}
}
Exemple #7
0
static bool
handle_my_getc(DIALOG_CALLBACK * cb, int ch, int fkey, int *result)
{
    MY_OBJ *obj = (MY_OBJ *) cb;
    bool done = FALSE;

    if (!fkey && dlg_char_to_button(ch, obj->buttons) == 0) {
	ch = DLGK_ENTER;
	fkey = TRUE;
    }

    if (fkey) {
	switch (ch) {
	case DLGK_ENTER:
	    *result = DLG_EXIT_OK;
	    done = TRUE;
	    break;
	case DLGK_BEGIN:	/* Beginning of line */
	    obj->hscroll = 0;
	    break;
	case DLGK_GRID_LEFT:	/* Scroll left */
	    if (obj->hscroll > 0) {
		obj->hscroll -= 1;
	    }
	    break;
	case DLGK_GRID_RIGHT:	/* Scroll right */
	    if (obj->hscroll < MAX_LEN)
		obj->hscroll += 1;
	    break;
	default:
	    beep();
	    break;
	}
	if ((obj->hscroll != obj->old_hscroll))
	    repaint_text(obj);
    } else {
	switch (ch) {
	case ERR:
	    clearerr(cb->input);
	    ch = getc(cb->input);
	    (void) ungetc(ch, cb->input);
	    if (ch != EOF) {
		handle_input(cb);
	    }
	    break;
	case ESC:
	    done = TRUE;
	    *result = DLG_EXIT_ESC;
	    break;
	default:
	    beep();
	    break;
	}
    }

    return !done;
}
int CCSocketHandler::InputNotify(void)
{
	int stage = handle_input();
	switch (stage)
	{
		case CONN_DATA_ERROR:
			log_warning("input decode error, netfd[%d], stage[%d]", netfd, stage);
			this->OnClose();
			if(GetReconnectFlag()==false){//����Ҫ����
				delete this;
			}
			else{
				Reset();
			}
			return POLLER_COMPLETE;

		case CONN_DISCONNECT:
			log_notice("input disconnect by user, netfd[%d], stage[%d]", netfd, stage);
			this->OnClose();
			if(this->GetReconnectFlag()== false)
			{
				delete this;
			}
			else{
				Reset();
			}
			return POLLER_COMPLETE;

		case CONN_DATA_RECVING:
		case CONN_IDLE:
		case CONN_RECV_DONE:			
			return POLLER_SUCC;

		case CONN_FATAL_ERROR:
			log_error("input fatal error, netfd[%d], stage[%d]", netfd, stage);
			this->OnClose();
			if(GetReconnectFlag()==false){//����Ҫ����
				delete this;
			}
			else{
				Reset();
			}
			return POLLER_COMPLETE;

		default:
			log_error("input unknow status, netfd[%d], stage[%d]", netfd, stage);
			this->OnClose();
			if(GetReconnectFlag()==false){//����Ҫ����
				delete this;
			}
			else{
				Reset();
			}
			return POLLER_COMPLETE;
		}
}
char* do_exec(char* ch1, char* ch2, char* ch3, char* ch4)
{
    char t[2048];
    strcat(t, ch1);
    strcat(t, "\n");

    handle_input(t);

    return NULL;
}
Exemple #10
0
/**
 * Part B: Info
 * Checks if a sound file provided is in the proper format.  If it is, various pieces of
 * information about the file are output.  A filename can be provided as a command line
 * parameter, but if it is not, then the input is taken from standard input.
 *
 * Command Line Variables: file name (optional)
 * Return Values: 0 - Success; 1 - Failure (error written to stderr)
 */
int main(int argc, char *argv[])
{
	char filename[MAX_FILE_NAME_LEN];
	FILE *inp;
	FileInfoPtr info = (FileInfoPtr)malloc(sizeof(FileInfo));
	int ret_val;
	
	if(argc > 1)
	{
		strncpy(filename, argv[1], MAX_FILE_NAME_LEN);
		if((inp = fopen(filename, "r")) == NULL)
		{
			fprintf(stderr, "Cannot open: %s\n", filename);
			free(info);
			return 1;
		}
		strncpy(info->file_name, filename, MAX_FILE_NAME_LEN);
	}
	else
	{
		inp = stdin;
		strncpy(info->file_name, "stdin", 5);
	}
	/*The handle_input call does most of the work in checking data format etc.*/
	ret_val = handle_input(inp, info, NONE);
	/*Output the required information about the file if the file is valid*/
	if(ret_val == 0)
	{
		/*It was said on WebCT that we shouldn't output a filename if input is stdin.*/
		if(strncmp(info->file_name, "stdin", 5) != 0)
		{
			printf("Filename: %s\n", info->file_name);
		}
		
		printf("Frequency: %d\n", info->frequency);
		if(info->mono_or_stereo == MONO)
		{
			printf("Channels: MONO\n");
		}
		else
		{
			printf("Channels: STEREO\n");
		}
		printf("Bits per sample: %d\n", info->bit_size);
		printf("Number of samples: %d\n", info->num_samples);
	}
	
	/*Close the file if needed*/
	if(argc > 1)
	{
		fclose(inp);
	}
	free(info);
	return ret_val;
}
Exemple #11
0
int main(int argc, char **argv) {
    init_sdl();
    init_opengl();

    while (1) {
        render_frame();
        handle_input();
    }
    
    return 0;
}
Exemple #12
0
/*---------------------------------------------------------------------------*/
static void
appcall(void *state)
{
  if(uip_closed() || uip_aborted() || uip_timedout()) {
    ctkmode();
  } else if(uip_connected()) {
  } else {
    handle_input();
    handle_output();   
  }
}
Exemple #13
0
/*---------------------------------------------------------------------------*/
static void
handle_connection(struct httpd_state *s)
{
#if DEBUGLOGIC
  handle_output(s);
#endif
  handle_input(s);
  if (s->state == STATE_OUTPUT) {
    handle_output(s);
  }
}
Exemple #14
0
int main(int argc, char *argv[])
{
	struct input_state	in = { };
	int			fd_out;
	char const		*event_filename = NULL;
	int			rc;
	int			repeat_params[2] = { 250 ,100 };

	for (;;) {
		int	c;

		c = getopt_long(argc, argv, "e:D:R:", CMDLINE_OPTIONS, NULL);
		if (c == -1)
			break;

		switch (c) {
		case 'k':
			rc = read_keymap(optarg);
			if (rc != EX_OK)
				return rc;
			break;

		case 'D':
			repeat_params[0] = atoi(optarg);
			break;

		case 'R':
			repeat_params[1] = atoi(optarg);
			break;

		default:
			fprintf(stderr, "unknown option\n");
			return EX_USAGE;
		}
	}

	if (argc < optind + 1) {
		fprintf(stderr, "missing parameters\n");
		return EX_USAGE;
	} else {
		event_filename = argv[optind + 0];
	}

	if (!open_input(&in, event_filename, repeat_params))
		return EX_OSERR;

	fd_out = open_uinput(&in);
	if (fd_out < 0)
		return EX_OSERR;

	while (handle_input(&in, fd_out))
		;
}
Exemple #15
0
static void curses_pre(void)
{
	for (;;) {
		int ch = getch();

		if (ch == -1)
			break;

		if (handle_input(ch))
			curses_draw();
	}
}
Exemple #16
0
void app_surface_event(u8 type, u8 padIndex, u8 value)
{
	if (game_state == GameState_INIT)
	{
		game_state = GameState_RUNNING;
		update_score_LEDs();
		update_LEDs();
	}
	else if (game_state == GameState_RUNNING)
	{
		handle_input(type, padIndex, value);
	}
}
void interact() {
    printf("*\n* %s\n*\n%s\n> ", module.name, module.info);
    fflush(stdout);
    static char buf[4096];
    while (1) {
        if (fgets(buf, 4096, stdin) != NULL) {
            handle_input(buf);
            printf("> ");
        } else {
            break;
        }
    }
}
Exemple #18
0
void game_loop() {
  while (game_running) {
    // do things
    update_keys();
    handle_input();
    // draw things
    blank_screen(&renderer);
    draw_player();
    SDL_RenderPresent(renderer);
    // keep things at a normal pace
    SDL_Delay(10);
  }
}
Exemple #19
0
void read_from_socket(int connfd, char* ptr){
	int status;
	char* result = malloc(20);
	memset(result, '\0', sizeof(result));
	status = read(connfd, result, sizeof(result));
	if(status < 0){
		error("Error in reading.");
		exit(0);
	}
	strcpy(ptr, result);
	ptr[14] = '\0';
	handle_input(connfd, ptr);
}
Exemple #20
0
/*
 *  Execution of the clock window
 */
int clock_loop() {
	time_t now, prev = 0;
	struct tm* tm;
	char buff[50];
	int ret, lightlevel, brightness;

	SDL_FreeSurface(window_label.surface);
	picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 30);

//	picframe_gen_text(&window_label.surface, fg, bg, window_labels[0]);
	window_label.rect.x = (WIDTH / 2) - (window_label.surface->clip_rect.w / 2);

	while (1) {
		ret = handle_input();
		if (ret)
			return ret;

		now = time(0);
		if (now > prev) {
			tm = localtime(&now);
			sprintf(buff, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
					tm->tm_sec);
			picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 80);

			picframe_gen_text(&time_disp.surface, fg, bg, buff);

			// FREE_FONT
			/*
			debug_printf("Setting time_disp surface to: %p\n",
					time_disp.surface);
			*/
			prev = now;

			lightlevel = picframe_get_lightsensor();
			brightness = picframe_get_backlight();

			sprintf(buff, "Light level: %d\tBrightness: %d", lightlevel,
					brightness);
			picframe_load_font("/usr/share/fonts/Ubuntu-L.ttf", 20);
			picframe_gen_text(&info_disp.surface, fg, bg, buff);
			/*
			debug_printf("Setting info_disp surface to: %p\n",
					info_disp.surface);
			*/
		}

		picframe_update(curr_window);
		SDL_Delay(1);
	}
	return 0;
}
Exemple #21
0
/**
 * @brief Application task
 */
static void app_task(void)
{
	int8_t input_char;

	/* Check for incoming characters from terminal program. */
	input_char = sio2host_getchar_nowait();
	if (input_char != -1) {
		if (nwk_stack_idle()) {
			handle_input((uint8_t)toupper(input_char));
		} else {
			printf("Network stack is busy \r\n");
		}
	}
}
Exemple #22
0
int main(int argc, char* argv[])
{
    if (argc > 1 && strcmp(argv[1], "--version") == 0) {
        printf("sgreen %s\n", PACKAGE_VERSION);
        return 0;
    }

    if (argc > 1 && strcmp(argv[1], "--help") == 0) {
        printf("Usage: sgreen [-s port]\n");
        printf("A green server\n");
        printf("\n");
        printf("Options\n");
        printf("  --help            output this help message and exit\n");
        printf("  --version         output version information and exit\n");
        printf("  -s port           use port as the host port\n");
        printf("\n");
        return 0;
    }

    char* port = NULL;
    if (argc > 2 && strcmp(argv[1], "-s") == 0) {
        port = argv[2];
    }

    int width;
    int height;

    CNSL_Event event = CNSL_RecvEvent(stdcon);
    if (!CNSL_IsResize(event, &width, &height)) {
        fprintf(stderr, "sgreen: expected resize event. Got %i\n", event.type);
        return 1;
    }

    green = GRN_CreateGreen(width, height);


    int lsfd = start_server(port);
    if (lsfd < 0) {
        return 1;
    }

    pthread_t scthread;
    pthread_create(&scthread, NULL, (void* (*)(void*))&serve_clients_thread, &lsfd);

    shell_client_create();
    handle_input();

    close(lsfd);
    return 0;
}
Exemple #23
0
void outbreak(SDL_Surface * screen) {
  Outbreak outbreak;
  init_outbreak(&outbreak, screen);

  while (!outbreak.quit) {
    handle_input(&outbreak);
    update_gamestate(&outbreak);
    render(&outbreak);

    SDL_Delay(1);
  }

  cleanup_outbreak(&outbreak);
}
Exemple #24
0
void handle_player(int sock) {
  int z, prevx, prevy;
  struct plyr *p = malloc(sizeof(struct plyr));
  
  p->fd = sock;
  p->x = p->y = p->lastdump = 0;
  p->worldx = p->worldy = 0;
  p->location = NULL;
  p->location = (struct loc *) get_world(p, 0,0);

  if(p->location == NULL)
  {
    printf("FAILED TO GET WORLD!\n");
    close(p->fd);
    return;
  }

  startmsg(p->fd);
  
  while( read_byte(p->fd) == 0);
  dump_world(p);
  
  while(1){
    prevx = p->x;
    prevy = p->y;   
  
    //handle input
    if(handle_input(p)){
     printf("disconnecting client\n");
     break;   
    }

    //display
    if(p->x != prevx || p->y != prevy)
    {
      //printf("trying to display @ %d, %d: %d\n", prevx, prevy, CHARAT(p,prevx, prevy));
      write_byte(p->fd, CHARAT(p,prevx, prevy));
    
      move_cursor(p->fd, p->x, p->y);
      //printf("now at %d,%d: %d\n",p->x,p->y, CHARAT(p,p->x,p->y));
      
    }
    
    check_updates(p);
    
  } 
 
  send(p->fd, "Goodbye\n", 8, 0);
  close(p->fd); 
}
Exemple #25
0
void fast_pwm_tick()
{
	if(term_in > 0) {
		handle_input(term_in);
		term_in = 0;
	}

	if(timeout()) {
		// simple servo sweep test
		if(sweep)
			servo_sweep();

	}
}
Exemple #26
0
/* function */
void main()
{
	uint8 key;
	
	init_board();	

	while(1) {
		if (GPIO_KEY != NO_KEY_PRESS) {
			key = Scan_key();
			/* handle input in func handle_input() */
			handle_input(key);
		}

	}
}
Exemple #27
0
int app_loop() {
	int ret;

	while (1) {

		if ((ret = handle_input()) != 0) {
			break;
		}

		SDL_Delay(10);

	}

	return ret;
}
Exemple #28
0
Fichier : game.c Projet : rlt3/fast
void
main_update(struct Game *game)
{
  /* set the of the player */
  game->input = gather_input();

  handle_input(game);

  /* save the opposite of the player's input so we can 'replay' it */
  game->past_input_frame = ++game->past_input_frame % INPUT_FRAMES;
  game->past_input[game->past_input_frame] = opposite_input(game->input);

  handle_asteroids(game->asteroids, game->speed, game->current_max_asteroids);
  handle_stars(game->stars, game->speed);
}
Exemple #29
0
void send_raw(char *str) {
	char buf[513];
	ssize_t tosend, sent;
	tosend = strlen(str);

	logfmt(LOG_RAW, "-> %s", str);
	strbufcpy(buf, str);
	while (tosend) {
		sent = send(conn, str, tosend, 0);
		if (sent < 0)
			POSIXERR("Error in sending data");
		tosend -= sent;
	}
	handle_input(buf);
}
Exemple #30
0
void jl_input_line_callback(char *input)
{
    if (input) {
        jl_value_t *ast = jl_parse_input_line(input);
        int line_done = !ast || !jl_is_expr(ast) ||
            (((jl_expr_t*)ast)->head != jl_continue_sym);
        if (line_done) {
            jl_deprep_terminal();
            int doprint = !ends_with_semicolon(input);
            stdin_buf[0] = 0; //also sets input[0] == 0
            stdin_buf_len = 0;
            handle_input(ast, 0, doprint);
        }
    }
}