Ejemplo n.º 1
0
void on_event_read(myconn_t* c)
{
	while (sizeof(c->readbuff) - c->readbuff_len > 0) {
		ssize_t len = read(c->fd, c->readbuff + c->readbuff_len, sizeof(c->readbuff) - c->readbuff_len);
		if (len < 0) {
			if (errno == EAGAIN || errno == EWOULDBLOCK) {
				break;
			} else if (errno == EINTR) {
				continue; /* or should i check thread cancel point? */
			} else { /* most errors detected here */
				struct epoll_event e = {
					.events = EPOLLERR,
					.data.ptr = c,
				};
				handle_events(&e);
				return;
			}
		} else if (len == 0) { /* most hups detected here */
			struct epoll_event e = {
				.events = EPOLLHUP,
				.data.ptr = c,
			};
			handle_events(&e);
			return;
		} else {
			c->readbuff_len += len;
			c->last_active = time(NULL);
		}
	}
	if (deal_data(c->readbuff, &c->readbuff_len, c->writebuff, &c->writebuff_len)) {
		poll_connection(epollfd, EPOLLIN | EPOLLOUT | EPOLLET, c);
	}
}
Ejemplo n.º 2
0
void get_input_events(bool type)
{
    SDL_Event event;

    //key_press_event = 0;
    
    if (type == POLL)
        while (SDL_PollEvent(&event))
            handle_events(event);
    if (type == WAIT)
    {
        SDL_WaitEvent(&event);
        handle_events(event);
    }
}
Ejemplo n.º 3
0
XCamReturn
PollThread::poll_subdev_event_loop ()
{
    XCamReturn ret = XCAM_RETURN_NO_ERROR;
    struct v4l2_event event;
    int poll_ret = 0;

    poll_ret = _event_dev->poll_event (PollThread::default_subdev_event_timeout);

    if (poll_ret < 0) {
        XCAM_LOG_WARNING ("poll event failed but continue");
        ::usleep (100000); // 100ms
        return XCAM_RETURN_ERROR_TIMEOUT;
    }

    /* timeout */
    if (poll_ret == 0) {
        XCAM_LOG_DEBUG ("poll event timeout and continue");
        return XCAM_RETURN_ERROR_TIMEOUT;
    }

    xcam_mem_clear (event);
    ret = _event_dev->dequeue_event (event);
    if (ret != XCAM_RETURN_NO_ERROR) {
        XCAM_LOG_WARNING ("dequeue event failed on dev:%s", XCAM_STR(_event_dev->get_device_name()));
        return XCAM_RETURN_ERROR_IOCTL;
    }

    ret = handle_events (event);
    return ret;
}
Ejemplo n.º 4
0
void Game::game_loop()
{
	get_dt();
	handle_events();
	update();
	draw();
}
void Controller::start()
{
  view_.start();
  model_.create_new_game(RealTime::now());
  handle_events();
  view_.finish();
}
Ejemplo n.º 6
0
int main(int argc, char* argv[])
{
        unsigned short port = 12345; // default port
        if (argc == 2) {
		port = atoi(argv[1]);
        }

	if ((epollfd = epoll_create(MAX_EVENTS)) < 0) {
		perror("epoll_create");
		exit(1);
	}
	if (poll_connection(epollfd, EPOLLIN, make_listen_connection(port)) < 0) {
		exit(2);
	}

	struct epoll_event events[MAX_EVENTS];
	while (1) {
		int timeout = handle_timeout();
		int n = epoll_wait(epollfd, events, MAX_EVENTS, timeout);
		if (n < 0) {
			perror("epoll_pwait");
			exit(3);
		}
		int i;
		for (i = 0; i < n; i++) {
			handle_events(&events[i]);
		}
	}

	return 0;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	int i;

	ipr_sg_required = 1;

	openlog("iprinit", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);

	for (i = 1; i < argc; i++) {
		if (parse_option(argv[i]))
			continue;
		else {
			printf("Usage: iprinit [options]\n");
			printf("  Options: --version [--daemon]   Print iprinit version\n");
			return -EINVAL;
		}
	}

	init_all();

	if (daemonize) {
		ipr_daemonize();
		return handle_events(poll_ioas, 60, kevent_handler);
	}

	return 0;
}
Ejemplo n.º 8
0
void vcore_entry(void)
{
	uint32_t vcoreid = vcore_id();

/* begin: stuff userspace needs to do to handle notifications */
	struct vcore *vc = &__procinfo.vcoremap[vcoreid];
	struct preempt_data *vcpd;
	vcpd = &__procdata.vcore_preempt_data[vcoreid];
	
	/* Lets try to restart vcore0's context.  Note this doesn't do anything to
	 * set the appropriate TLS.  On x86, this will involve changing the LDT
	 * entry for this vcore to point to the TCB of the new user-thread. */
	if (vcoreid == 0) {
		handle_events(vcoreid);
		set_tls_desc(core0_tls, 0);
		assert(__vcoreid == 0); /* in case anyone uses this */
		/* Load silly state (Floating point) too */
		pop_user_ctx(&vcpd->uthread_ctx, vcoreid);
		panic("should never see me!");
	}	
/* end: stuff userspace needs to do to handle notifications */

	/* all other vcores are down here */
	core1_up = TRUE;

	while (core1_up)
		cpu_relax();
	printf("Proc %d's vcore %d is yielding\n", getpid(), vcoreid);
	sys_yield(0);

	while(1);
}
/*--------------------------------------------------
 *  Constructs the presentation window
 *--------------------------------------------------*/
PMWindow::PMWindow( const char* class_name ,
                    SHORT       id         ,
                    const char* caption    ,
                    HWND        parent     ,
                    HWND        owner      ,
                    long        x          ,
                    long        y          ,
                    long        cx         ,
                    long        cy         ,
                    ULONG       style      ,
                    PVOID       class_data )

: win_id     ( id    ),
  win_wrapper( FALSE ),

  win_default_handler(0)
{
  win_handle = WinCreateWindow( parent, class_name, caption, style,
                                x, y, cx, cy, owner, HWND_BOTTOM, id, class_data, 0 );

  if( win_handle == NULLHANDLE )
    PM_THROW_GUIERROR();

  handle_events();
}
Ejemplo n.º 10
0
int PJStunTurn::worker_thread(void* data) {
  auto context = static_cast<PJStunTurn*>(data);
  while (!context->worker_quit_) {
    context->handle_events(500, NULL);
  }
  return 0;
}
Ejemplo n.º 11
0
int main(int argc, const char ** argv) {
  struct timeval start_time, end_time;
  struct timespec tspec = {0, 0};
  struct timespec left = {0, 0};
  int error;
  long long elapsed;
  float cam_center_x, cam_center_y;

  if (swiftsure_log_init() < 0) {
    printf("Bad times, we couldn't open our log file =(\n");
    return -1;
  }

  rendering_init();

  if (input_init() < 0) {
    printf("Bad times, we couldn't initialize the input subsystem\n");
    return -1;
  }
  action_init();

  world.width = WORLD_SIZE;
  world.height = WORLD_SIZE;

  world_init(&world, 1);
  game_init();

  swiftsure_log(INFO, "Startin engines\n");

  frame = 0;
  elapsed = 16666;

  while (1) {
    gettimeofday(&start_time, NULL);

    game_get_avg_pos(&cam_center_x, &cam_center_y);
    render_set_camera(-cam_center_x, -cam_center_y, 4);

    handle_events();
    action_perform();
    render_start_frame();
    render_world(&world);
    game_render_players();
    render_end_frame();
    ++frame;

    physics_tick(&world, 10. / elapsed);

    //Rate limiting
    gettimeofday(&end_time, NULL);
    elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec);
    if (elapsed < 16666) {
      tspec.tv_nsec = (16666 - elapsed) * 1000;
      error = nanosleep(&tspec, &left);
      if (error < 0) {
        swiftsure_log(DEBUG, "We had %d seconds and %d nanoseconds left to sleep, errno %d\n", left.tv_sec, left.tv_nsec, errno);
      }
    }
  }
}
/*--------------------------------------------------
 *  Constructs the presentation window
 *--------------------------------------------------*/
PMWindow::PMWindow( SHORT       id         ,
                    const char* caption    ,
                    HWND        parent     ,
                    HWND        owner      ,
                    long        x          ,
                    long        y          ,
                    long        cx         ,
                    long        cy         ,
                    ULONG       style      )

: win_id     ( id    ),
  win_wrapper( FALSE ),

  win_default_handler(0)
{
  static BOOL initialized = FALSE;

  if( !initialized )
  {
    if( !WinRegisterClass( PMGUI::hab(), "PMWindow", WinDefWindowProc, CS_SIZEREDRAW, 4 ))
      PM_THROW_GUIERROR();

    initialized = TRUE;
  }

  win_handle = WinCreateWindow( parent, "PMWindow", caption, style,
                                x, y, cx, cy, owner, HWND_BOTTOM, id, NULL, 0 );
  if( win_handle == NULLHANDLE )
    PM_THROW_GUIERROR();

  handle_events();
}
Ejemplo n.º 13
0
int
main(int argc, char **argv) {
    if(argc != 2)
        errx(EXIT_FAILURE, "no input files");

    pthread_mutex_init(&mutex_update_image, NULL);

    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_t inotify_thread;
    if(pthread_create(&inotify_thread, &attr, monitor_file, argv[1]))
        err(EXIT_FAILURE, "pthread_create");

    font_init();
    screen_init();
    update_image(argv[1]);

    for(;;) {
        handle_events();
        draw();
    }

    SDL_Quit();

    return EXIT_SUCCESS;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[]) {
    //Create a screen context that will be used to create an EGL surface to to receive libscreen events
    screen_create_context(&screen_cxt, 0);

    //Initialize BPS library
    bps_initialize();

    //Use utility code to initialize EGL for rendering with GL ES 1.1
    if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) {
        fprintf(stderr, "bbutil_init_egl failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Initialize application logic
    if (EXIT_SUCCESS != initialize()) {
        fprintf(stderr, "initialize failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Signal BPS library that navigator and screen events will be requested
    if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
        fprintf(stderr, "screen_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "navigator_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    while (!shutdown) {
        // Handle user input and accelerometer
        handle_events();
        // Update scene contents
        update();
        // Draw Scene
        render();
    }

    //Stop requesting events from libscreen
    screen_stop_events(screen_cxt);

    //Use utility code to terminate EGL setup
    bbutil_terminate();

    //Shut down BPS library for this process
    bps_shutdown();

    //Destroy libscreen context
    screen_destroy_context(screen_cxt);
    return 0;
}
Ejemplo n.º 15
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
  ACE_OS::signal (SIGCLD, SIG_IGN);
  ACE_UNUSED_ARG (sa);

  parse_args (argc, argv);

  OUTPUT_FILE = ACE_OS::open (OUTPUT_FILE_NAME, O_CREAT | O_WRONLY, 0644);
  if (OUTPUT_FILE == 0)
    return 1;

  ACE_Reactor reactor;
  Handle_Events handle_events (UDP_PORT, MCAST_ADDR, INTERFACE, reactor);

  // main loop

  while (!done)
    reactor.handle_events ();

  ACE_OS::close (OUTPUT_FILE);
  cout << "\nbenchd done.\n";
  return 0;
}
Ejemplo n.º 16
0
Archivo: wew.c Proyecto: laserswald/opt
int
main (int argc, char **argv)
{

	char *argv0;

	ARGBEGIN {
		case 'l':
			list_events();
			exit(0);
		case 'm':
			  mask = strtoul(EARGF(usage(argv0)), NULL, 10);
			  break;
		default: usage(argv0);
	} ARGEND;

	init_xcb(&conn);
	get_screen(conn, &scr);

	handle_events();

	kill_xcb(&conn);

	return 0;
}
Ejemplo n.º 17
0
void SnakeGame::play_game() {
    SDL_Event window_event;
    program_running = true;
    game_over = false;
    while(program_running) {
        handle_events(&window_event);
        //Clear Screen
        glClearColor(0,0,0,1);
        glClear(GL_COLOR_BUFFER_BIT);

        snake->move();
        snake_eats();

        sidebar->draw(renderer);
        board->draw(renderer);
        border->draw(renderer);
        snake->draw(renderer);
        apple->draw(renderer);

        SDL_GL_SwapWindow(window);
        if(check_death()) {
            reset();
        }
    }

}
Ejemplo n.º 18
0
/* Like smp_idle(), this will put the core in a state that it can only be woken
 * up by an IPI.  For now, this is a halt.  Maybe an mwait in the future.
 *
 * This will return if an event was pending (could be the one you were waiting
 * for) or if the halt failed for some reason, such as a concurrent RKM.  If
 * successful, this will not return at all, and the vcore will restart from the
 * top next time it wakes.  Any sort of IRQ will wake the core.
 *
 * Alternatively, I might make this so it never returns, if that's easier to
 * work with (similar issues with yield). */
void vcore_idle(void)
{
    uint32_t vcoreid = vcore_id();
    /* Once we enable notifs, the calling context will be treated like a uthread
     * (saved into the uth slot).  We don't want to ever run it again, so we
     * need to make sure there's no cur_uth. */
    assert(!current_uthread);
    /* This clears notif_pending (check, signal, check again pattern). */
    if (handle_events(vcoreid))
        return;
    /* This enables notifs, but also checks notif pending.  At this point, any
     * new notifs will restart the vcore from the top. */
    enable_notifs(vcoreid);
    /* From now, til we get into the kernel, any notifs will permanently destroy
     * this context and start the VC from the top.
     *
     * Once we're in the kernel, any messages (__notify, __preempt), will be
     * RKMs.  halt will need to check for those atomically.  Checking for
     * notif_pending in the kernel (sleep only if not set) is not enough, since
     * not all reasons for the kernel to stay awak set notif_pending (e.g.,
     * __preempts and __death).
     *
     * At this point, we're out of VC ctx, so anyone who sets notif_pending
     * should also send an IPI / __notify */
    sys_halt_core(0);
    /* in case halt returns without actually restarting the VC ctx. */
    disable_notifs(vcoreid);
}
Ejemplo n.º 19
0
int main()
{
    int server_socket;
    int port;
    int epollfd;
    int ret;
    char buf[1024];

    port = 8765;
    server_socket = create_socket(port);

    /* 监听 */
    listen(server_socket, 10);

    struct epoll_event events[100];

    epollfd = epoll_create(1024);

    add_event(epollfd,server_socket,EPOLLIN);

    while(1) {
        //该函数返回已经准备好的描述符事件数目
        ret = epoll_wait(epollfd,events,EPOLLEVENTS,-1);
        //处理接收到的连接
        handle_events(epollfd,events,ret,server_socket,buf);
    }
    return 0;
}
Ejemplo n.º 20
0
void schedule(){
	int i, running;
	struct task *t;

#ifdef TRACE  
	feed_wdt();
#endif
		
	for (i=0; i<num_tasks;){

#ifdef TRACE
		cur_task = 99;
#endif  
	
		handle_events();

#ifdef TRACE
		cur_task = i;
#endif
		
		t=&(task_list[i]);
		/* Run the next thread with its own thread structure as argument */
		if (t->state == RUN) {
			running = PT_SCHEDULE( t->thread(&(t->thread_pt)) );
			i++;
		} else {
			task_del(i);
			// do not increment i, we probably have a new task at this index
		}
  	};
};
Ejemplo n.º 21
0
const ui_menu_event *ui_menu::process(UINT32 flags)
{
	// reset the menu_event
	menu_event.iptkey = IPT_INVALID;

	// first make sure our selection is valid
	validate_selection(1);

	// draw the menu
	if (numitems > 1 && (item[0].flags & MENU_FLAG_MULTILINE) != 0)
		draw_text_box();
	else
		draw(flags & UI_MENU_PROCESS_CUSTOM_ONLY);

	// process input
	if (!(flags & UI_MENU_PROCESS_NOKEYS))
	{
		// read events
		handle_events();

		// handle the keys if we don't already have an menu_event
		if (menu_event.iptkey == IPT_INVALID)
			handle_keys(flags);
	}

	// update the selected item in the menu_event
	if (menu_event.iptkey != IPT_INVALID && selected >= 0 && selected < numitems)
	{
		menu_event.itemref = item[selected].ref;
		return &menu_event;
	}
	return nullptr;
}
Ejemplo n.º 22
0
Archivo: sos.c Proyecto: xdsopl/sos
int main(int argc, char **argv)
{
	(void)argc; (void)argv;
	zoom = 1.0;
	mouse_x = -4.0;
	mouse_y = -4.0;
	focus = 1;
	rotation = m4f_ident();
	atexit(SDL_Quit);
	SDL_Init(SDL_INIT_VIDEO);
	resize_screen(640, 480);
	SDL_WM_SetCaption("SDL OpenGL Skeleton", "sos");
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
	init_gl();
	make_list();
	for (;;) {
		draw();
		if (focus)
			SDL_Delay(10);
		else
			SDL_Delay(100);
		handle_events();
	}
	return 0;
}
Ejemplo n.º 23
0
int
main(int argc, char *argv[])
{
	initialize(argc, argv);
	handle_events();
	tear_down();

	return 0;
}
Ejemplo n.º 24
0
void loop()
{
	while(!kb.keys[SDLK_ESCAPE] && !kb.exit) {
		check_timeouts();
		handle_events(); //handles input, then moves
		blit_all();
		SDL_Delay(1000/BASE_FPS);
	}
}
Ejemplo n.º 25
0
static InterruptMemberNumber
hard_irq( InterruptSetMember ISTmember, void *ref_con, UInt32 the_int_count )
{
	channel_t *ch = channels;	/* fixme */
	int running, compl_cnt, event;
	request_t *r;
	
	/* Note: Q & A DV 34 explicitly forbids the usage of secondary
	 * interrupts on the page-fault path (it leads to deadlocks).
	 */
	/* Note: The OSI call _always_ modifies the return arguments */
	if( !OSI_ABlkIRQAck( ch->channel, &compl_cnt, &running, &event ) )
		return kIsrIsNotComplete;

	ch->running = running;

	if( event )
		handle_events( ch );

	/* handle overflow buffer */
	if( ch->obuf_cnt && compl_cnt - ch->obuf_completion >= 0 ) {
		if( ch->obuf_dest ) {
			char *dest = ch->obuf_dest, *src = ch->obuf;
			int cnt = ch->obuf_cnt;
			while( cnt-- )
				*dest++ = *src++;
		}
		/* XXX: insert optimization barrier here */
		*(volatile int*)&ch->obuf_cnt = 0;
	}

	/* process completions */
	while( (r=(request_t*)dequeue(&ch->compl_queue)) ) {
		IOCommandID cmdID;

		if( r->req_num - compl_cnt > 0 ) {
			enqueue_tail( &ch->compl_queue, (queue_el_t*)r );
			break;
		}
		/* free resources... */
		if( r->mem_prepared )
			CheckpointIO( r->ioprep.preparationID, 0 );

		if( r->ablk_req & (ABLK_READ_REQ | ABLK_WRITE_REQ) )
			((IOParam*)r->pb)->ioActCount = r->xfer_cnt;
		
		cmdID = r->cmdID;
		fifo_put( &ch->free_fifo, (fifo_el_t*)r );

		/* ...and complete */
		IOCommandIsComplete( cmdID, noErr );
	}
	process_request_queue( ch );

	return kIsrIsComplete;
}
Ejemplo n.º 26
0
/*
 * This is the worker thread that polls event in the background.
 */
static int icedemo_worker_thread(void *unused)
{
    PJ_UNUSED_ARG(unused);

    while (!icedemo.thread_quit_flag) {
	handle_events(500, NULL);
    }

    return 0;
}
Ejemplo n.º 27
0
Archivo: chat.c Proyecto: rahpaere/tcpr
int main(int argc, char **argv)
{
    handle_options(argc, argv);
    setup_tcpr();
    setup_connection();
    setup_state();
    handle_events();
    teardown();
    return EXIT_SUCCESS;
}
Ejemplo n.º 28
0
// 分发事件
int dispatch_event(struct epoll_event* pEvents, int count)
{
	assert(NULL != pEvents);
	int i;
	for (i = 0; i < count; ++i) {
		handle_events(pEvents->data.fd, pEvents->events);
		++pEvents;
	}
	return 0;
}
Ejemplo n.º 29
0
Archivo: vcore.c Proyecto: 7perl/akaros
/* Like smp_idle(), this will put the core in a state that it can only be woken
 * up by an IPI.  In the future, we may halt or something.  This will return if
 * an event was pending (could be the one you were waiting for). */
void vcore_idle(void)
{
	uint32_t vcoreid = vcore_id();
	if (handle_events(vcoreid))
		return;
	enable_notifs(vcoreid);
	while (1) {
		cpu_relax();
	}
}
Ejemplo n.º 30
0
bool app_update(platform::Locator *services)
{
	auto game_state = (GameState*)services->memory.permanent_memory;

    handle_events(services);

    //Time
    game_state->time_acc += (float)services->time.delta;
	auto mod = std::abs(std::sin((float)services->time.current));
    //mod +=  1.0f ;

    //glClearColor(1+game_state->color.r*mod, game_state->color.g*mod, 1+game_state->color.b*mod, 0);
    glClearColor(game_state->color.r*mod, game_state->color.g*mod, game_state->color.b*mod, 0);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    //Calculate ortho projection via camera
    auto projection = game_state->camera.Calculate();

    //Grid
    glm::vec3 pos = {0.0f,0.0f,0.0f};
    auto box_size = game_state->box_size;
    auto stride = game_state->box_stride;

    int coloum_count = (int)(services->config.width/(box_size+stride));
    int row_count = (int)(services->config.height/(box_size+stride));

    if(game_state->highlight > (coloum_count * row_count))game_state->highlight = 0;
    else if(game_state->time_acc > 0.1)
    {
        game_state->time_acc = 0;
        game_state->highlight++;
    }

    for(int r=0;r<row_count;r++)
    {
        for(int c = 0;c<coloum_count;c++)
        {
            float color = 0.3f + (0.7f*c/coloum_count);
            if(game_state->highlight == (r*coloum_count)+c)
            {
                game_state->render_unit.Render(projection,pos,{box_size,box_size},{0,1*mod,1,1});
            }
            else
            {
                game_state->render_unit.Render(projection,pos,{box_size,box_size},{1,color*(c%2),0,1});
            }
            pos.x += box_size+stride;
        }
        pos.x = 0;
        pos.y += box_size+stride;
    }

	return true;
}