예제 #1
0
int main(int argc, char *argv[]) {
  nsock_pool nsp;
  enum nsock_loopstatus loopret;
  int num_loops = 0;

  srand(time(NULL));
  /* OK, we start with creating a p00l */
  if ((nsp = nsp_new(NULL)) == NULL) {
    fprintf(stderr, "Failed to create new pool.  QUITTING.\n");
    exit(1);
  }

  ev_ids[num_ids++] = request_timer(nsp, timer_handler, 1800, NULL);
  ev_ids[num_ids++] = request_timer(nsp, timer_handler, 800, NULL);
  ev_ids[num_ids++] = request_timer(nsp, timer_handler, 1300, NULL);
  ev_ids[num_ids++] = request_timer(nsp, timer_handler, 0, NULL);
  ev_ids[num_ids++] = request_timer(nsp, timer_handler, 100, NULL);

  /* Now lets get this party started right! */
  while (num_loops++ < 5) {
    loopret = nsock_loop(nsp, 1500);
    if (loopret == NSOCK_LOOP_TIMEOUT)
      printf("Finished l00p #%d due to l00p timeout :)  I may do another\n", num_loops);
    else if (loopret == NSOCK_LOOP_NOEVENTS) {
      printf("SUCCESS -- NO EVENTS LEFT\n");
      exit(0);
    } else {
      printf("nsock_loop FAILED!\n");
      exit(1);
    }
  }
  printf("Trying to kill my msp!\n");
  nsp_delete(nsp);
  printf("SUCCESS -- completed %d l00ps.\n", num_loops);

  return 0;
}
예제 #2
0
void timer_handler(nsock_pool nsp, nsock_event nse, void *mydata) {
  enum nse_status status = nse_status(nse);
  enum nse_type type = nse_type(nse);
  int rnd, rnd2;

  printf("%ld:timer_handler: Received callback of type %s; status %s; id %li\n", time(NULL), nse_type2str(type), nse_status2str(status), nse_id(nse));

  rnd = rand() % num_ids;
  rnd2 = rand() % 3;

  if (num_ids > (sizeof(ev_ids) / sizeof(nsock_event_id)) - 3) {
    printf("\n\nSUCCEEDED DUE TO CREATING ENOUGH EVENTS THAT IT WAS GOING TO OVERFLOW MY BUFFER :)\n\n");
    exit(0);
  }

  if (status == NSE_STATUS_SUCCESS) {
    switch (rnd2) {
    case 0:
      /* do nothing */
      /* Actually I think I'll create two timers :) */
      ev_ids[num_ids++] = request_timer(nsp, timer_handler, rand() % 3000, NULL);
      ev_ids[num_ids++] = request_timer(nsp, timer_handler, rand() % 3000, NULL);
      break;
    case 1:
      /* Kill another id (which may or may not be active */
      try_cancel_timer(nsp, rnd, rand() % 2);
      break;
    case 2:
      /* Create a new timer */
      ev_ids[num_ids++] = request_timer(nsp, timer_handler, rand() % 3000, NULL);
      break;
    default:
      assert(0);
    }
  }
}
예제 #3
0
/* The first thing that the user will see. */
void focus_screen_mainproc()
{
	timer_handle_t wait_timer;
	volatile int two_seconds_passed = 0; /* I wonder if this is undefined 
	behavior... as long as the variable doesn't go out of scope while the 
	timer's in effect, I should be okay... */
	
	
	//setmem((void*)BGMap(0), 0x00, 0x2000); /* Just use the zeroth char for all tiles */
	//copymem((void*)CharSeg0, (void*)char_line, 16); /* Only need to use 1 char! */
	
	/* Give time for mirrors to adjust... */
	
	load_warning_scr();
	vbDisplayShow();
	
	/* Failure of this function is grounds for halting the program! */
	wait_timer = request_timer(200, set_true, &two_seconds_passed);
	//while(!(two_seconds_passed && vbPadKeyDown()));
	fade_and_wait();
	vbDisplayHide();
	remove_timer(wait_timer);
	
	load_ipdfoc_scr();
	fade_and_wait();
	//vbDisplayOn();
	
	//curr_game_
	//vbPadKeyDown();
	//while(vbPadKeyDown() != K_BTNS);
	
	/* jump_to_reset(); */
	/* return TRI_DEMO; */
	
	
}