Exemplo n.º 1
0
Arquivo: input06.c Projeto: kraj/ltp
static int parse_key(struct input_event *iev)
{
	int autorep_count = 0;

	if (!check_event(iev, EV_KEY, KEY_X, 1) || !check_sync_event(next_event())) {
		tst_resm(TFAIL, "Didn't get expected key press for KEY_X");
		return 0;
	}

	iev = next_event();
	while (check_event(iev, EV_KEY, KEY_X, 2) && check_sync_event(next_event())) {
		autorep_count++;
		iev = next_event();
	}

	/* make sure we have atleast one auto-repeated key event */
	if (!autorep_count) {
		tst_resm(TFAIL,
			 "Didn't get autorepeat events for the key - KEY_X");
		return 0;
	}

	if (!check_event(iev, EV_KEY, KEY_X, 0) || !check_sync_event(next_event())) {
		tst_resm(TFAIL,
			 "Didn't get expected key release for KEY_X");
		return 0;
	}

	tst_resm(TINFO,
		 "Received %d repititions for KEY_X", autorep_count);

	return 1;
}
Exemplo n.º 2
0
static void RunEventsIfNeeded() {
  unique_ptr<WStatus> pStatus(session()->status_manager()->GetStatus());
  if (!IsEquals(date(), pStatus->GetLastDate())) {
    if ((session()->GetBeginDayNodeNumber() == 0) 
        || (session()->instance_number() == session()->GetBeginDayNodeNumber())) {
      cleanup_events();
      beginday(true);
    }
  }

  if (!do_event) {
    check_event();
  }

  while (do_event) {
    run_event(do_event - 1);
    check_event();
  }

  session()->SetCurrentSpeed("KB");
  static time_t last_time_c = 0;
  time_t lCurrentTime = time(nullptr);
  if ((((rand() % 8000) == 0) || (lCurrentTime - last_time_c > 1200)) && net_sysnum) {
    lCurrentTime = last_time_c;
    attempt_callout();
  }
}
Exemplo n.º 3
0
static int sleep_until_event(struct dwc_otg2 *otg,
			u32 otg_mask, u32 user_mask,
			u32 *otg_events, u32 *user_events,
			int timeout)
{
	int rc = 0;

	pm_runtime_mark_last_busy(otg->dev);
	pm_runtime_put_autosuspend(otg->dev);
	/* Wait until it occurs, or timeout, or interrupt. */
	if (timeout) {
		otg_dbg(otg, "Waiting for event (timeout=%d)...\n", timeout);
		rc = sleep_main_thread_until_condition_timeout(otg,
				check_event(otg, otg_mask,
				user_mask, otg_events, user_events), timeout);
	} else {
		otg_dbg(otg, "Waiting for event (no timeout)...\n");
		rc = sleep_main_thread_until_condition(otg,
				check_event(otg, otg_mask,
					user_mask, otg_events, user_events));
	}
	pm_runtime_get_sync(otg->dev);

	/* Disable the events */
	otg_write(otg, OEVTEN, 0);
	otg_write(otg, ADPEVTEN, 0);

	otg_dbg(otg, "Woke up rc=%d\n", rc);

	return rc;
}
Exemplo n.º 4
0
void start_monitor(){
	struct timeval *currenttime;
	exec_count = 0;

	currenttime = (struct timeval*)malloc(sizeof(struct timeval));

	exec_events = (t_event*)calloc(NUM_EVENTS, sizeof(t_event));

	/*Keep waiting for new X events for a given screen*/
	while(1){
		XNextEvent(dis, (XEvent*) &event);

		XRRNotifyEvent *ev = (XRRNotifyEvent*)&event;

		gettimeofday(currenttime, NULL);

		if(!check_event(ev, currenttime)){
			logMessage(WARNING, "Event already executed within threshold parameters..skiping this round\n");
			continue;
		}

		insert_event(ev, currenttime);
		
		execute_events(&event);
	}

	free(currenttime);
	free(exec_events);
}
Exemplo n.º 5
0
Arquivo: gamin.c Projeto: GNOME/gamin
static void
do_connection(void)
{
    FAMConnection fc;
    FAMRequest fr;
    int data;
    int loop;
    int ret;

    ret = FAMOpen(&fc);

    if (ret < 0) {
        fprintf(stderr, "Failed to connect to the FAM server\n");
        exit(1);
    }
    for (loop = 0; loop < 1; loop++) {

        ret = FAMMonitorDirectory(&fc, "/u/veillard/test", &fr, &data);
        if (ret != 0) {
            fprintf(stderr, "Failed register monitor for /tmp\n");
            exit(1);
        }
        sleep(1);
        check_event(&fc);
    }
    ret = FAMClose(&fc);
    if (ret < 0) {
        fprintf(stderr, "Failed to close connection to the FAM server\n");
        exit(1);
    }
}
Exemplo n.º 6
0
// calculate the current mandelbrot set
static void calculate_mandel()
{		
	const GR_COLOR * the_palette = GRAY_palette;

	const int sx = screen_width;
	const int sy = screen_height;
	const int iter = iterations-1;
	
	const double xmin=xMin;
	const double ymin=yMin;
	const double xmax=xMax;
	const double ymax=yMax;

	const double xs=(xmax-xmin)/sx;
	const double ys=(ymax-ymin)/sy;

	register long x0,y0,p,q,xn,tot;
	register int i=0,x=0,y=0;

	const int depth = current_depth;

	if( screen_info.bpp == 16 )
		the_palette = color_palette;
	
	rendering=1;
	show_cursor=0;
	active_renderer++;
	
	// start main loop
	for (y=0;y<sy;y++) {
		for (x=0;x<sx;x++) { 
			p=fixpt(xmin+x*xs);
			q=fixpt(ymin+y*ys);
			xn=0;
			x0=0;
			y0=0;
			i=0;
			while ((mul(xn,xn)+mul(y0,y0))<fixpt(4) && ++i<iter)  {
				xn=mul((x0+y0),(x0-y0)) +p;
				y0=mul(fixpt(2),mul(x0,y0)) +q;
				x0=xn;
			}
			tot+=i;
		
			GrSetGCForeground(mandel_gc, the_palette[i%8]);
			GrPoint(level[depth].mandel_buffer, mandel_gc,x,y);
		}
		
		// for every line only:
		// check if we had an event
		check_event();
		// check if we need to quit
		if (!rendering) return;
		// update the screen
		draw_mandel();
	}
	// end main loop
	
	active_renderer--;
}
Exemplo n.º 7
0
GRAPHICS_EVENT *find_event(                 /*wait for event */
                           INT16 &fd,       /*window to wait on */
                           BOOL8 wait,      /*waiting flag */
                           INT8 event_type  /*type to look for */
                          ) {
  GRAPHICS_EVENT *event;         /*return event */

                                 /*look for one */
  event = search_event_queue (fd, event_type);
  if (event == NULL) {
    do {
      #ifdef __UNIX__
      if (check_event (fd, wait))
      #elif defined (__MSW32__)
        if (wait)
          Sleep (50);
      if (event_waiting)
      #endif
      {
        //                              fprintf(stderr,"Got an event:searching queue %d\n",fd);
                                 /*try after reading */
        event = search_event_queue (fd, event_type);
      }
    }
    while (wait && event == NULL);
  }
  //      if (event!=NULL)
  //              event->fd=&sbfds[fd];
  return event;                  /*event located */
}
Exemplo n.º 8
0
int main()
{
  InputEvent  ev;

  __Set( BEEP_VOLUME, 0);
  __Clear_Screen( WHITE);

  attach_handler( TIMER3_INTERRUPT, when_counter3_overflows);

  while( true)
  {
    check_event( &ev);
    if ( INPUT_PRESSED == ev.state)
    {
      switch( ev.input)
      {
        case BUTTON1:
          __Set( BACKLIGHT, 10);
          break;
        case BUTTON2:
          __Set( BACKLIGHT, 100);
          break;
        default:
          break;
      }
    }
  }
}
Exemplo n.º 9
0
int main()
{
  InputEvent  ev;
  Input static const buttons[] = { BUTTON1, BUTTON2, BUTTON3, BUTTON4, LROCKER_LEFT, LROCKER_RIGHT, RROCKER_LEFT, RROCKER_RIGHT};

  __Set( BEEP_VOLUME, 0);

  //chosen_slot = UNDEFINED;
  //chosen_page = UNDEFINED;

  render_slot_buttons();
  render_slots();

  while( true)
  {
    check_event( &ev);

    if ( INPUT_PRESSED == ev.state)
    {
      // The four buttons and both directions of both rockers make up eight
      // buttons numbered 0..7.  Work out which ( if any) were pressed:
      Input  button_pressed = UNDEFINED;
      int  i;
      for ( i = 0;  i < ITEMS_IN_ARRAY(buttons);  i += 1)
      {
        if ( buttons[i] == ev.input)
        {
          button_pressed = i;
          break;
        }
      }

      // If the slot has not yet been chosen..
      if ( UNDEFINED == chosen_slot)
      {
        if ( button_pressed != UNDEFINED  &&  button_pressed < 4)
        {
          chosen_slot = button_pressed;
          render_page_buttons();
          render_slots();
        }
      }
      // Otherwise the slot *has* been chosen and all that it left is to choose
      // the page within the slot
      else {
        if ( button_pressed != UNDEFINED)
        {
          chosen_page = 8 * chosen_slot + button_pressed;
          VoidFunction **reset_vector = (VoidFunction**)( FIRST_PAGE + (PAGE_SIZE * chosen_page) + 0x4);
          (*reset_vector)();
        }
      }
    }

    // Go to sleep until it's time to check the buttons again
    __WFE();
  }
}
Exemplo n.º 10
0
void WFE_main()
{
  InputEvent  ev;
  while( should_run)
  {
    check_event( &ev);
    if ( BUTTON4 == ev.input)
      should_run = false;
    __WFE();
  }
}
Exemplo n.º 11
0
// pause
static void pause_drawing() {

#ifdef MANDELPOD_STATUS
	draw_idle_status();
#endif
	while (paused) {
		check_event();
		usleep(100);
	}

}
Exemplo n.º 12
0
int main(int argc, char* argv[]) {

    if (init() != RTN_OK) return 0;

    while(1) {
        if (check_event() == RTN_OK) {
            handle_event();
        }
        usleep(1);
    }
    return 1;
}
Exemplo n.º 13
0
static void resolve_events(void)
{
	size_t count;
	size_t i, j;
	size_t * counter_map;
	size_t nr_counters = op_get_nr_counters(cpu_type);
	struct op_event const * selected_events[nr_counters];

	count = parse_events(parsed_events, nr_counters, chosen_events);
	if (count > nr_counters) {
		fprintf(stderr, "Not enough hardware counters.\n");
		exit(EXIT_FAILURE);
	}

	for (i = 0; i < count; ++i) {
		for (j = i + 1; j < count; ++j) {
			struct parsed_event * pev1 = &parsed_events[i];
			struct parsed_event * pev2 = &parsed_events[j];

			if (!strcmp(pev1->name, pev2->name) &&
			    pev1->count == pev2->count &&
			    pev1->unit_mask == pev2->unit_mask &&
			    pev1->kernel == pev2->kernel &&
			    pev1->user == pev2->user) {
				fprintf(stderr, "All events must be distinct.\n");
				exit(EXIT_FAILURE);
			}
		}
	}

	for (i = 0; i < count; ++i) {
		struct parsed_event * pev = &parsed_events[i];

		selected_events[i] = find_event_by_name(pev->name);

		check_event(pev, selected_events[i]);
	}

	counter_map = map_event_to_counter(selected_events, count, cpu_type);

	if (!counter_map) {
		fprintf(stderr, "Couldn't allocate hardware counters for the selected events.\n");
		exit(EXIT_FAILURE);
	}

	for (i = 0; i < count; ++i) {
		printf("%d ", (unsigned int) counter_map[i]);
	}
	printf("\n");

	free(counter_map);
}
Exemplo n.º 14
0
int			do_select(t_server *server)
{
  if (select(server->fd_max + 1, &server->fd_read,
	     &server->fd_write, NULL, NULL) == -1)
    {
      printf("Erreur select\n");
      return (0);
    }
  check_event(server);
  del_food(server);
  check_eggs(server);
  return (1);
}
Exemplo n.º 15
0
bool
edit_graphics_rep::mouse_graphics (string type, SI x, SI y, int m, time_t t) {
  //cout << type << ", " << x << ", " << y << ", " << m << ", " << t << "\n";
  //cout << "et= " << et << "\n";
  //cout << "tp= " << tp << "\n";
  //cout << "gp= " << graphics_path () << "\n";
  (void) t;
  // apply_changes (); // FIXME: remove after review of synchronization
  frame f= find_frame ();
  if (!is_nil (f)) {
    if (!over_graphics (x, y))
      return false;
    if (type == "move" || type == "dragging-left")
      if (check_event (MOTION_EVENT))
	return true;
    point p = f [point (x, y)];
    graphical_select (p[0], p[1]); // init the caching for adjust().
    p= adjust (p);
    gr_x= p[0];
    gr_y= p[1];
    string sx= as_string (p[0]);
    string sy= as_string (p[1]);
    invalidate_graphical_object ();
    call ("set-keyboard-modifiers", object (m));
    if (type == "move")
      call ("graphics-move", sx, sy);
    else if (type == "release-left" || type == "double-left")
      call ("graphics-release-left", sx, sy);
    else if (type == "release-middle")
      call ("graphics-release-middle", sx, sy);
    else if (type == "release-right" || type == "double-right")
      call ("graphics-release-right", sx, sy);
    else if (type == "start-drag-left")
      call ("graphics-start-drag-left", sx, sy);
    else if (type == "dragging-left")
      call ("graphics-dragging-left", sx, sy);
    else if (type == "end-drag-left")
      call ("graphics-end-drag-left", sx, sy);
    else if (type == "start-drag-right")
      call ("graphics-start-drag-right", sx, sy);
    else if (type == "dragging-right")
      call ("graphics-dragging-right", sx, sy);
    else if (type == "end-drag-right")
      call ("graphics-end-drag-right", sx, sy);
    invalidate_graphical_object ();
    notify_change (THE_CURSOR);
    return true;
  }
  //cout << "No frame " << tp << ", " << subtree (et, path_up (tp)) << "\n";
  return false;
}
Exemplo n.º 16
0
bool
edit_graphics_rep::mouse_graphics (string type, SI x, SI y, int m, time_t t) {
  (void) t;
  // apply_changes (); // FIXME: remove after review of synchronization
  frame f= find_frame ();
  if (!is_nil (f)) {
    if (!over_graphics (x, y)) return false;
    if (type == "move" || type == "dragging")
      if (check_event (MOTION_EVENT))
	return true;
    point p = f [point (x, y)];
    graphical_select (p[0], p[1]); // init the caching for adjust().
    p = adjust (p);
    gr_x= p[0];
    gr_y= p[1];
    string sx= as_string (p[0]);
    string sy= as_string (p[1]);
    invalidate_graphical_object ();
    call ("set-keyboard-modifiers", object (m));
    if (type == "move")
      call ("graphics-move-point", sx, sy);
    else if (type == "release-left")
      call ("graphics-insert-point", sx, sy);
    else if (type == "release-middle")
      call ("graphics-remove-point", sx, sy);
    else if (type == "release-right")
      call ("graphics-last-point", sx, sy);
    else if (type == "start-drag")
      call ("graphics-start-drag", sx, sy);
    else if (type == "dragging")
      call ("graphics-dragging", sx, sy);
    else if (type == "end-drag")
      call ("graphics-end-drag", sx, sy);
    else if (type == "start-right-drag")
      call ("graphics-start-right-drag", sx, sy);
    else if (type == "right-dragging")
      call ("graphics-right-dragging", sx, sy);
    else if (type == "end-right-drag")
      call ("graphics-end-right-drag", sx, sy);
    invalidate_graphical_object ();
    notify_change (THE_CURSOR);
    return true;
  }
  return false;
}
Exemplo n.º 17
0
static ptid_t
fbsd_thread_wait (struct target_ops *ops,
		  ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
  struct target_ops *beneath = find_target_beneath (ops);
  ptid_t ret;
  long lwp;
  CORE_ADDR stop_pc;
  td_thrhandle_t th;
  td_thrinfo_t ti;

  ret = beneath->to_wait (beneath, ptid, ourstatus, options);
  if (GET_PID(ret) >= 0 && ourstatus->kind == TARGET_WAITKIND_STOPPED)
    {
      lwp = get_current_lwp (GET_PID(ret));
      ret = thread_from_lwp (BUILD_LWP(lwp, GET_PID(ret)),
         &th, &ti);
      if (!in_thread_list(ret)) {
        /*
         * We have to enable event reporting for initial thread
         * which was not mapped before.
	 */
        attach_thread(ret, &th, &ti, 1);
      }
      if (ourstatus->value.sig == TARGET_SIGNAL_TRAP)
        check_event(ret);
      /* this is a hack, if an event won't cause gdb to stop, for example,
         SIGALRM, gdb resumes the process immediatly without setting
         inferior_ptid to the new thread returned here, this is a bug
         because inferior_ptid may already not exist there, and passing
         a non-existing thread to fbsd_thread_resume causes error. However,
         if the exiting thread is the currently selected thread,
         then that is handled later in handle_inferior_event(), and we must
         not delete the currently selected thread. 
      */
      if (!fbsd_thread_alive (ops, inferior_ptid) && !ptid_equal(inferior_ptid, ret))
        {
          delete_thread (inferior_ptid);
          inferior_ptid = ret;
        }
    }

  return (ret);
}
Exemplo n.º 18
0
int main()
{
  InputEvent  ev;

  __Set( BEEP_VOLUME, 0);

  attach_handler( TIMER3_INTERRUPT, when_counter3_overflows);

  initial_render();

  while( true)
  {
    check_event( &ev);
    if ( INPUT_PRESSED == ev.state)
    {
      switch( ev.input)
      {
        case LROCKER_LEFT:
          slot_cursor = (slot_cursor - 10) & (SLOTS - 1);
          break;
        case LROCKER_RIGHT:
          slot_cursor = (slot_cursor + 10) & (SLOTS - 1);
          break;
        case RROCKER_LEFT:
          slot_cursor = (slot_cursor - 1) & (SLOTS - 1);
          break;
        case RROCKER_RIGHT:
          slot_cursor = (slot_cursor + 1) & (SLOTS - 1);
          break;
        case RROCKER_DOWN:
          {
          VoidFunction **reset_vector = (VoidFunction**)( FIRST_SLOT + SLOT_SIZE*slot_cursor + 0x4);
          (*reset_vector)();
          }
          break;
        default:
          break;
      }
    }

    render();
  }
}
Exemplo n.º 19
0
static int check_events(void)
{
    int tick_time = 0, curr_time, tt;

    curr_time = time(NULL);
restart:
    any_closed=false;
    for (struct session *sp = sessionlist; sp; sp = sp->next)
    {
        tt = check_event(curr_time, sp);
        if (any_closed)
            goto restart;
        /* printf("#%s %d(%d)\n", sp->name, tt, curr_time); */
        if (tt > curr_time && (tick_time == 0 || tt < tick_time))
            tick_time = tt;
    }

    if (tick_time > curr_time)
        return tick_time - curr_time;
    return 0;
}
Exemplo n.º 20
0
static ptid_t
fbsd_thread_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
{
  ptid_t ret;
  long lwp;
  CORE_ADDR stop_pc;
  td_thrhandle_t th;
  td_thrinfo_t ti;

  ret = child_ops.to_wait (ptid, ourstatus);
  if (GET_PID(ret) >= 0 && ourstatus->kind == TARGET_WAITKIND_STOPPED)
    {
      lwp = get_current_lwp (GET_PID(ret));
      ret = thread_from_lwp (BUILD_LWP(lwp, GET_PID(ret)),
         &th, &ti);
      if (!in_thread_list(ret)) {
        /*
         * We have to enable event reporting for initial thread
         * which was not mapped before.
	 */
        attach_thread(ret, &th, &ti, 1);
      }
      if (ourstatus->value.sig == TARGET_SIGNAL_TRAP)
        check_event(ret);
      /* this is a hack, if an event won't cause gdb to stop, for example,
         SIGARLM, gdb resumes the process immediatly without setting
         inferior_ptid to the new thread returned here, this is a bug
         because inferior_ptid may already not exist there, and passing
         a none existing thread to fbsd_thread_resume causes error. */
      if (!fbsd_thread_alive (inferior_ptid))
        {
          delete_thread (inferior_ptid);
          inferior_ptid = ret;
        }
    }

  return (ret);
}
Exemplo n.º 21
0
void backlight_main()
{
  InputEvent  ev;

  counter3_overflow_hook = when_counter3_overflows;

  draw_text( FONT_WIDTH*(50-20)/2, FONT_HEIGHT*(17-1)/2, WHITE, 1, "Backlight-experiment");

  value = 0;
  target_value = 100;
  while ( value != target_value)
  {
    __WFE(); // Go to low-power mode until counter3 overflows
    __Set( BEEP_VOLUME, value);
  }
  target_value = 0;
  while ( value != target_value)
  {
    __WFE();
    __Set( BEEP_VOLUME, value);
  }

  while( should_run)
  {
    check_event( &ev);
    if ( BUTTON4 == ev.input)
      should_run = false;

    while ( value != target_value)
    {
      __WFE();
      __Set( BACKLIGHT, value);
    }
    target_value = (100 == value) ? 0 : 100;
  }
}
Exemplo n.º 22
0
void SysTick_main()
{
  InputEvent  ev;

  attach_handler( SYSTICK_INTERRUPT, when_systick_is_zero);

  SysTick_Config( SYSTICK_MAXCOUNT);

  while( should_run)
  {
    check_event( &ev);
    switch( ev.input)
    {
      case BUTTON4:
        should_run = false;
        break;
      default:
        break;
    }
    render();
  }
  // Disable SysTick and its interrupt:
  SysTick->CTRL &= ~ ((1 << SYSTICK_ENABLE) | (1 << SYSTICK_TICKINT));
}
Exemplo n.º 23
0
void *run_listener(void *startarg) 
{
  GList *action_item, *glob_item;
  monwatch *watch;
  monwatch_entry *entry, *new_entry;
  monconf_action_entry *action_entry;
  int newstr_len;
  char buffer[EVENT_BUF_LEN];
  int elength, i, num_entries;
  int idx, msgsize;
  short matched_glob;
  monevent evt;  
  lua_State *L;  
  char *msgbuf;
  size_t msgbufsize;

  liststart *start = (liststart *)startarg;  
  watch = monwatch_create();
  start->watch = watch;
  monwatch_process_config(watch,start->conf);
  printf("Listening for events...\n");
  num_entries = monwatch_num_entries(watch);
 
  void *pub_socket = zmq_socket(start->zmq_context, ZMQ_PUB);
  if(zmq_bind(pub_socket, "inproc://file_events"))
  {
    start->active = 0;
    fprintf(stderr,"Error opening the inotify listener: %d\n",zmq_errno());
    pthread_exit(NULL);
    exit(-2);
    return;
  }    
  start->socket_bound = 1;
  zmq_msg_t message;
  
  while(!start->usr_interrupt)
  {
    idx++;
    elength = read(watch->inotify_fd, buffer, EVENT_BUF_LEN);
    i = 0;
    while(i < elength) 
    {
      struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
      if(event->len)
      {
        entry = (monwatch_entry *)g_hash_table_lookup(watch->wdescr_map,(gpointer)event->wd);
        char *full_path = g_strdup_printf("%s/%s",entry->file_name,event->name);
        evt.event = check_event(event->mask,entry->conf_entry->events);
        if(evt.event && check_filters_for_event(event, entry)) 
        {
          if(event->mask & IN_ISDIR && ((event->mask & IN_CREATE) || (event->mask & IN_MOVED_TO))
              && (entry->conf_entry->recursive)) 
          {
            _monwatch_add_item(watch, entry->conf_entry, full_path);
          }
          action_item = g_list_first(entry->conf_entry->actions);
          while(action_item)
          {
            action_entry = (monconf_action_entry *)action_item->data;    
            if(evt.event & entry->conf_entry->events)
            {
              if(!monconf_entry_match_ignores(entry->conf_entry,event->name)
                  && monconf_action_match_entry_globs(action_entry, full_path))
              {
                evt.action_name = action_entry->action->name;
                evt.timestamp = time(NULL);
                evt.base_path = entry->file_name;
                evt.file_path = event->name;
                evt.is_dir = ((event->mask & IN_ISDIR) ? 1 : 0);
                zmq_msg_init(&message);
                monevent_serialize(&evt, &msgbuf, &msgbufsize);
                zmq_msg_init_size(&message,msgbufsize);
                memcpy(zmq_msg_data(&message), msgbuf, msgbufsize);
                if(zmq_send(pub_socket, &message, 0))
                {
                  fprintf(stderr,"Error %d sending message\n",zmq_errno());
                }
                free(msgbuf);
                zmq_msg_close(&message);      
              }
            }
            action_item = action_item->next;
          }
          g_free(full_path);
        }
        if(event->mask & IN_ISDIR && ((event->mask & IN_DELETE) || (event->mask & IN_MOVED_FROM)))
        {
          _monwatch_delete_item(watch, entry, event->name);
        }
      }
      i += EVENT_SIZE + event->len;
    }
    usleep(500);
  }
  printf("Closing listener...\n");
  zmq_close(pub_socket);
  monwatch_free(watch);
  start->socket_bound = 0;
  start->active = 0;
  pthread_exit(NULL);
}
Exemplo n.º 24
0
Arquivo: snake.c Projeto: tedluo/snake
////////////////////////主程序//////////////////////////////
void main(int argc,char* argv[])
{	
	int key;
	snake_element* snake_mark;
	Creat_screen();
	Load_first_snake();
	Load_bmp_show();
	while(!(key=PressQuit())); // 没有按键时等待..
	if(key == 1) // 按下退出键时退出程序,否则执行下一条语句
		exit(1);
	event_mark=check_event();
	while((event_mark == 0) || (event_mark == 5)||(event_mark % 2 == event_PreMark % 2)||event_mark == 7)
		{
			Clear_bmp(length);
			snake_mark = key_RightMove(snake_main);//开始游戏,初始化向右行驶,当查询到左右键或者无操作时循环,退出键时退出程序	
			Load_snake(length,snake_main);         //查询到上下键时,退出本循环,并在下一个循环对此次按键进行处理
			Load_bmp_show();
			event_mark = check_event() ;
			Rand_food(&food_place);
			Eat_food();
			if(event_mark == 6)
				exit(1);
			if((event_mark % 2 == event_PreMark % 2)|| event_mark == 5|| event_mark == 0||event_mark == 7)//如果当前方向与前一次的移动方向相同,或相反,则不做处理,装载下一位				
				continue ;
			break;
		}

	while(event_mark!=6)//主循环,不断扫描键盘,并根据扫描到的相应的值,进行相应的操作
		{
			switch(event_mark)
			{
				case 1:
					while(event_mark!= 6)
					{
						Clear_bmp(length);
						key_UpMove(snake_main);
						Load_snake(length,snake_main);
						Load_bmp_show();
						Rand_food(&food_place);//当检测到果子标志位为0时,随机刷果子
						Eat_food();//检测到是否吃到果子?如果吃到了,清零果子标志位
						if(Space_pause() ==1)//暂停功能
							exit(1);
						if(Check_over(snake_main) == 1)//游戏失败?,失败则退出游戏
							{		
								SDL_Delay(5000);
								exit(1);
							}
						event_mark = check_event() ;//查询事件
						if((event_mark % 2 == event_PreMark % 2)||event_mark == 0)//根据不同事件采取不同操作
							continue ;
						if(event_mark %2 != event_PreMark %2)
							break ;				
					}
				break ;	
				case 2:
					while(event_mark!= 6 )
					{
						Clear_bmp(length);
						key_LeftMove(snake_main);
						Load_snake(length,snake_main);
						Load_bmp_show();
						Rand_food(&food_place);
						Eat_food();
						if(Space_pause() ==1)//暂停功能
							exit(1);
						if(Check_over(snake_main) == 1)
							{		
								SDL_Delay(5000);
								exit(1);
							}

						event_mark = check_event() ;
						if((event_mark % 2 == event_PreMark % 2)||event_mark == 5||event_mark == 7)
							continue ;
						if(event_mark %2 != event_PreMark %2)
							break ;						
					}
				break;
				case 3:
					while(event_mark!= 6 )
					{
						Clear_bmp(length);
						key_DownMove(snake_main);
						Load_snake(length,snake_main);
						Load_bmp_show();
						Rand_food(&food_place);
						Eat_food();
						if(Space_pause() ==1)
							exit(1);
						if(Check_over(snake_main) == 1)
							{		
								SDL_Delay(5000);
								exit(1);
							}
						event_mark = check_event() ;
						if((event_mark % 2 == event_PreMark % 2)||event_mark == 0)
							continue ;
						if(event_mark %2 != event_PreMark %2)
							break ;	
			

					}
				break;
				case 4:
					while(event_mark!= 6)
					{
						Clear_bmp(length);
						key_RightMove(snake_main);
						Load_snake(length,snake_main);
						Load_bmp_show();
						Rand_food(&food_place);
						Eat_food();
						if(Space_pause() ==1)
							exit(1);
						if(Check_over(snake_main) == 1)
							{		
								SDL_Delay(5000);
								exit(1);
							}
						event_mark = check_event() ;
						if((event_mark % 2 == event_PreMark % 2)||event_mark == 5||event_mark == 7)
							continue ;
						if(event_mark %2 != event_PreMark %2)
							break ;	
					}
				break;
			}
		}	
}
Exemplo n.º 25
0
static int
evport_dispatch(struct event_base *base, struct timeval *tv)
{
	int i, res;
	struct evport_data *epdp = base->evbase;
	port_event_t pevtlist[EVENTS_PER_GETN];

	/*
	 * port_getn will block until it has at least nevents events. It will
	 * also return how many it's given us (which may be more than we asked
	 * for, as long as it's less than our maximum (EVENTS_PER_GETN)) in
	 * nevents.
	 */
	int nevents = 1;

	/*
	 * We have to convert a struct timeval to a struct timespec
	 * (only difference is nanoseconds vs. microseconds). If no time-based
	 * events are active, we should wait for I/O (and tv == NULL).
	 */
	struct timespec ts;
	struct timespec *ts_p = NULL;
	if (tv != NULL) {
		ts.tv_sec = tv->tv_sec;
		ts.tv_nsec = tv->tv_usec * 1000;
		ts_p = &ts;
	}

	/*
	 * Before doing anything else, we need to reassociate the events we hit
	 * last time which need reassociation. See comment at the end of the
	 * loop below.
	 */
	for (i = 0; i < EVENTS_PER_GETN; ++i) {
		struct fd_info *fdi = NULL;
		if (epdp->ed_pending[i] != -1) {
			fdi = &(epdp->ed_fds[epdp->ed_pending[i]]);
		}

		if (fdi != NULL && FDI_HAS_EVENTS(fdi)) {
			int fd = epdp->ed_pending[i];
			reassociate(epdp, fdi, fd);
			epdp->ed_pending[i] = -1;
		}
	}

	EVBASE_RELEASE_LOCK(base, th_base_lock);

	res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
	    (unsigned int *) &nevents, ts_p);

	EVBASE_ACQUIRE_LOCK(base, th_base_lock);

	if (res == -1) {
		if (errno == EINTR || errno == EAGAIN) {
			return (0);
		} else if (errno == ETIME) {
			if (nevents == 0)
				return (0);
		} else {
			event_warn("port_getn");
			return (-1);
		}
	}

	event_debug(("%s: port_getn reports %d events", __func__, nevents));

	for (i = 0; i < nevents; ++i) {
		struct fd_info *fdi;
		port_event_t *pevt = &pevtlist[i];
		int fd = (int) pevt->portev_object;

		check_evportop(epdp);
		check_event(pevt);
		epdp->ed_pending[i] = fd;

		/*
		 * Figure out what kind of event it was
		 * (because we have to pass this to the callback)
		 */
		res = 0;
		if (pevt->portev_events & (POLLERR|POLLHUP)) {
			res = EV_READ | EV_WRITE;
		} else {
			if (pevt->portev_events & POLLIN)
				res |= EV_READ;
			if (pevt->portev_events & POLLOUT)
				res |= EV_WRITE;
		}

		/*
		 * Check for the error situations or a hangup situation
		 */
		if (pevt->portev_events & (POLLERR|POLLHUP|POLLNVAL))
			res |= EV_READ|EV_WRITE;

		EVUTIL_ASSERT(epdp->ed_nevents > fd);
		fdi = &(epdp->ed_fds[fd]);

		evmap_io_active(base, fd, res);
	} /* end of all events gotten */

	check_evportop(epdp);

	return (0);
}
Exemplo n.º 26
0
static void resolve_events(void)
{
	size_t count, count_events;
	size_t i, j;
	size_t * counter_map;
	size_t nr_counters = op_get_nr_counters(cpu_type);
	struct op_event const * selected_events[num_chosen_events];

	count = parse_events(parsed_events, num_chosen_events, chosen_events,
	                     ignore_count ? 0 : 1);

	for (i = 0; i < count; ++i) {
	        op_resolve_unit_mask(&parsed_events[i], NULL);
		for (j = i + 1; j < count; ++j) {
			struct parsed_event * pev1 = &parsed_events[i];
			struct parsed_event * pev2 = &parsed_events[j];

			if (!strcmp(pev1->name, pev2->name) &&
			    pev1->count == pev2->count &&
			    pev1->unit_mask == pev2->unit_mask &&
			    pev1->kernel == pev2->kernel &&
			    pev1->user == pev2->user) {
				fprintf(stderr, "All events must be distinct.\n");
				exit(EXIT_FAILURE);
			}
		}
	}

	for (i = 0, count_events = 0; i < count; ++i) {
		struct parsed_event * pev = &parsed_events[i];

		/* For 0 unit mask always do wild card match */
		selected_events[i] = find_event_by_name(pev->name, pev->unit_mask,
					pev->unit_mask ? pev->unit_mask_valid : 0);
		check_event(pev, selected_events[i]);

		if (selected_events[i]->ext == NULL) {
			count_events++;
		}
	}
	if (count_events > nr_counters) {
		fprintf(stderr, "Not enough hardware counters. "
				"Need %lu counters but only has %lu.\n",
				(unsigned long) count_events,
				(unsigned long) nr_counters);
		exit(EXIT_FAILURE);
	}

	counter_map = map_event_to_counter(selected_events, count, cpu_type);

	if (!counter_map) {
		fprintf(stderr, "Couldn't allocate hardware counters for the selected events.\n");
		exit(EXIT_FAILURE);
	}

	for (i = 0; i < count; ++i)
		if(counter_map[i] == (size_t)-1)
			if (selected_events[i]->ext != NULL)
				printf("%s ", (char*) selected_events[i]->ext);
			else
				printf("N/A ");
		else
			if (strcmp(selected_events[i]->name, TIMER_EVENT_NAME) == 0)
				printf("timer ");
			else
				printf("%d ", (unsigned int) counter_map[i]);
	printf("\n");

	free(counter_map);
}
Exemplo n.º 27
0
int main(int argc, char **argv)
{
	int opt;
	int fd;
	int fd_d;
	int ret = 0;
	int flags = O_RDONLY;

	while ((opt = getopt(argc, argv, "t")) != -1) {
		switch (opt) {
			case 't':
				flags = (O_RDWR | O_TRUNC);
				break;

			default:
				fprintf(stderr, usage_str, argv[0]);
				exit(EXIT_FAILURE);
		}
	}

	if (optind >= argc) {
		fprintf(stderr, usage_str, argv[0]);
		exit(EXIT_FAILURE);
	}

	fd_d = open(argv[optind], flags);

	if (!(flags & O_TRUNC))
		while (read_frame(fd_d) > 0);

	fd = inotify_init();

	if (fd >= 0 && fd_d >= 0) {
		int wd;
		struct sigaction sa;

		sa.sa_handler = handle_signal;
		sigemptyset(&sa.sa_mask);
		sa.sa_flags = 0;
		sigaction(SIGINT, &sa, NULL);

		wd = inotify_add_watch(fd, argv[optind], IN_MODIFY);

		while (running) {
			if (check_event(fd) > 0)
				process_events(fd, fd_d);
			else
				break;
		}

		fprintf(stderr, " Exiting..\n");

		close(fd_d);
		inotify_rm_watch(fd, wd);
	} else {
		fprintf(stderr, "unable to open \"%s\" for reading\n", argv[optind]);
		ret = EXIT_FAILURE;
	}

	return ret;
}
Exemplo n.º 28
0
static int
evport_dispatch (struct event_base *base, void *arg, struct timeval *tv)
{
  int i, res;

  struct evport_data *epdp = arg;
  port_event_t pevtlist[EVENTS_PER_GETN];

  /*
   * port_getn will block until it has at least nevents events. It will
   * also return how many it's given us (which may be more than we asked
   * for, as long as it's less than our maximum (EVENTS_PER_GETN)) in
   * nevents.
   */
  int nevents = 1;

  /*
   * We have to convert a struct timeval to a struct timespec
   * (only difference is nanoseconds vs. microseconds). If no time-based
   * events are active, we should wait for I/O (and tv == NULL).
   */

  struct timespec ts;

  struct timespec *ts_p = NULL;

  if (tv != NULL)
    {
      ts.tv_sec = tv->tv_sec;
      ts.tv_nsec = tv->tv_usec * 1000;
      ts_p = &ts;
    }

  /*
   * Before doing anything else, we need to reassociate the events we hit
   * last time which need reassociation. See comment at the end of the
   * loop below.
   */

  for (i = 0; i < EVENTS_PER_GETN; ++i)
    {

      struct fd_info *fdi = NULL;

      if (epdp->ed_pending[i] != -1)
        {
          fdi = & (epdp->ed_fds[epdp->ed_pending[i]]);
        }

      if (fdi != NULL && FDI_HAS_EVENTS (fdi) )
        {
          int fd = FDI_HAS_READ (fdi) ? fdi->fdi_revt->ev_fd :
                   fdi->fdi_wevt->ev_fd;
          reassociate (epdp, fdi, fd);
          epdp->ed_pending[i] = -1;
        }
    }

  if ( (res = port_getn (epdp->ed_port, pevtlist, EVENTS_PER_GETN,
                         (unsigned int *) & nevents, ts_p) ) == -1)
    {
      if (errno == EINTR || errno == EAGAIN)
        {
          evsignal_process (base);
          return (0);
        }

      else if (errno == ETIME)
        {
          if (nevents == 0)
            return (0);
        }

      else
        {
          event_warn ("port_getn");
          return (-1);
        }
    }

  else if (base->sig.evsignal_caught)
    {
      evsignal_process (base);
    }

  event_debug ( ("%s: port_getn reports %d events", __func__, nevents) );

  for (i = 0; i < nevents; ++i)
    {

      struct event *ev;

      struct fd_info *fdi;
      port_event_t *pevt = &pevtlist[i];
      int fd = (int) pevt->portev_object;

      check_evportop (epdp);
      check_event (pevt);
      epdp->ed_pending[i] = fd;

      /*
       * Figure out what kind of event it was
       * (because we have to pass this to the callback)
       */
      res = 0;

      if (pevt->portev_events & POLLIN)
        res |= EV_READ;

      if (pevt->portev_events & POLLOUT)
        res |= EV_WRITE;

      assert (epdp->ed_nevents > fd);

      fdi = & (epdp->ed_fds[fd]);

      /*
       * We now check for each of the possible events (READ
       * or WRITE).  Then, we activate the event (which will
       * cause its callback to be executed).
       */

      if ( (res & EV_READ) && ( (ev = fdi->fdi_revt) != NULL) )
        {
          event_active (ev, res, 1);
        }

      if ( (res & EV_WRITE) && ( (ev = fdi->fdi_wevt) != NULL) )
        {
          event_active (ev, res, 1);
        }
    } /* end of all events gotten */

  check_evportop (epdp);

  return (0);
}
Exemplo n.º 29
0
bool OSystem_PalmBase::pollEvent(Event &event) {
	::EventType ev;
	Boolean handled;
	UInt32 keyCurrentState;
	Coord x, y;

	battery_handler();
	timer_handler();
	sound_handler();

	for(;;) {
#if defined(COMPILE_OS5) && defined(PALMOS_ARM)
		SysEventGet(&ev, evtNoWait);
#else
		EvtGetEvent(&ev, evtNoWait);
#endif
		// check for hardkey repeat for mouse emulation
		keyCurrentState = KeyCurrentState();
		// check_hard_keys();

		if (!(keyCurrentState & _keyMouseMask)) {
			_lastKeyRepeat = 0;
		} else {
			if (getMillis() >= (_keyMouseRepeat + _keyMouseDelay)) {
				_keyMouseRepeat = getMillis();

				if (gVars->arrowKeys) {				
					if (keyCurrentState & _keyMouse.bitUp)
						event.kbd.keycode = 273;
					else if (keyCurrentState & _keyMouse.bitDown)
						event.kbd.keycode = 274;
					else if (keyCurrentState & _keyMouse.bitLeft)
						event.kbd.keycode = 276;
					else if (keyCurrentState & _keyMouse.bitRight)
						event.kbd.keycode = 275;
					else if (keyCurrentState & _keyMouse.bitButLeft)
						event.kbd.keycode = chrLineFeed;

					event.type = EVENT_KEYDOWN;
					event.kbd.ascii = event.kbd.keycode;
					event.kbd.flags = 0;

				} else {
					Int8 sx = 0;
					Int8 sy = 0;

					if (keyCurrentState & _keyMouse.bitUp)
						sy = -1;
					else if (keyCurrentState & _keyMouse.bitDown)
						sy = +1;
						
					if (keyCurrentState & _keyMouse.bitLeft)
						sx = -1;
					else if (keyCurrentState & _keyMouse.bitRight)
						sx = +1;

					if (sx || sy) {
						simulate_mouse(event, sx, sy, &x, &y);
						event.type = EVENT_MOUSEMOVE;
						_lastKey = kKeyMouseMove;

					} else {			
						x = _mouseCurState.x;
						y = _mouseCurState.y;

						if (keyCurrentState & _keyMouse.bitButLeft) {
							event.type = EVENT_LBUTTONDOWN;
							_lastKey = kKeyMouseLButton;

						} else if (_lastKey == kKeyMouseLButton) {
							event.type = EVENT_LBUTTONUP;
							_lastKey = kKeyNone;
						}
					}

					event.mouse.x = x;
					event.mouse.y = y;
					warpMouse(x, y);
		//			updateCD();
				}
				return true;
			}
		}

		if (ev.eType == keyDownEvent) {
			switch (ev.data.keyDown.chr) {
			// ESC key
			case vchrLaunch:
				_lastKey = kKeyNone;
				event.type = EVENT_KEYDOWN;
				event.kbd.keycode = 27;
				event.kbd.ascii = 27;
				event.kbd.flags = 0;
				return true;

			// F5 = menu
			case vchrMenu:
				_lastKey = kKeyNone;
				event.type = EVENT_KEYDOWN;
				event.kbd.keycode = 319;
				event.kbd.ascii = 319;
				event.kbd.flags = 0;
				return true;

			// if hotsync pressed, etc...
			case vchrHardCradle:
			case vchrHardCradle2:
			case vchrLowBattery:
			case vchrFind:
//			case vchrBrightness:	// volume control on Zodiac, let other backends disable it
			case vchrContrast:
				// do nothing
				_lastKey = kKeyNone;
				return true;
			}
		}

		if (check_event(event, &ev))
			return true;
		_lastKey = kKeyNone;

		// prevent crash when alarm is raised
		handled = ((ev.eType == keyDownEvent) && 
						(ev.data.keyDown.modifiers & commandKeyMask) && 
						((ev.data.keyDown.chr == vchrAttnStateChanged) || 
						(ev.data.keyDown.chr == vchrAttnUnsnooze))); 

		// graffiti strokes, auto-off, etc...
		if (!handled)
			if (SysHandleEvent(&ev))
				continue;

		switch(ev.eType) {
		case penMoveEvent:
			get_coordinates(&ev, x, y);

			if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0)
				return false;

			if (_lastEvent != penMoveEvent && (abs(y - event.mouse.y) <= 2 || abs(x - event.mouse.x) <= 2)) // move only if
				return false;

			_lastEvent = penMoveEvent;
			event.type = EVENT_MOUSEMOVE;
			event.mouse.x = x;
			event.mouse.y = y;
			warpMouse(x, y);
			return true;

		case penDownEvent:
			get_coordinates(&ev, x, y);

			// indy fight mode
			if (_useNumPad && !_overlayVisible) {
				char num = '1';
				num += 9 -
						(3 - (3 * x / _screenWidth )) -
						(3 * (3 * y / _screenHeight));
			
				event.type = EVENT_KEYDOWN;
				event.kbd.keycode = num;
				event.kbd.ascii = num;
				event.kbd.flags = 0;

				_lastEvent = keyDownEvent;
				return true;
			}

			_lastEvent = penDownEvent;				
			if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0)
				return false;

			event.type = ((gVars->stylusClick || _overlayVisible) ? EVENT_LBUTTONDOWN : EVENT_MOUSEMOVE);
			event.mouse.x = x;
			event.mouse.y = y;
			warpMouse(x, y);
			return true;

		case penUpEvent:
			get_coordinates(&ev, x, y);

			event.type = ((gVars->stylusClick || _overlayVisible) ? EVENT_LBUTTONUP : EVENT_MOUSEMOVE);
			if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0)
				return false;

			event.mouse.x = x;
			event.mouse.y = y;
			warpMouse(x, y);
			return true;
		
		case keyDownEvent:
			if (ev.data.keyDown.chr == vchrCommand &&
				(ev.data.keyDown.modifiers & commandKeyMask)) {

				_lastKeyModifier++;
				_lastKeyModifier %= kModifierCount;

				if (_lastKeyModifier)
					draw_osd((kDrawKeyState + _lastKeyModifier - 1), 2, _screenDest.h + 2, true);
				else
					draw_osd(kDrawKeyState, 2, _screenDest.h + 2, false);

				return false;
			}

			char mask = 0;
			UInt16 key = ev.data.keyDown.chr;

			if (_lastKeyModifier == kModifierNone) {
				// for keyboard mode
				if (ev.data.keyDown.modifiers & shiftKeyMask)	mask |= KBD_SHIFT;
				if (ev.data.keyDown.modifiers & controlKeyMask)	mask |= KBD_CTRL;
				if (ev.data.keyDown.modifiers & optionKeyMask)	mask |= KBD_ALT;
				if (ev.data.keyDown.modifiers & commandKeyMask) mask |= KBD_CTRL|KBD_ALT;
			} else {
				// for grafiti mode
				if (_lastKeyModifier == kModifierCommand)	mask = KBD_CTRL|KBD_ALT;
				if (_lastKeyModifier == kModifierAlt)		mask = KBD_ALT;
				if (_lastKeyModifier == kModifierCtrl)		mask = KBD_CTRL;
			}

			if (_lastKeyModifier)
				draw_osd(kDrawKeyState, 2, _screenDest.h + 2, false);
			_lastKeyModifier = kModifierNone;

			// F1 -> F10 key
			if  (key >= '0' && key <= '9' && mask == (KBD_CTRL|KBD_ALT)) {
				key = (key == '0') ? 324 : (315 + key - '1');
				mask = 0;

			// exit
			} else if  ((key == 'z' && mask == KBD_CTRL) || (mask == KBD_ALT && key == 'x')) {
				event.type = EVENT_QUIT;
				return true;
			
			// num pad (indy fight mode)
			} else if (key == 'n' && mask == (KBD_CTRL|KBD_ALT) && !_overlayVisible) {
				_useNumPad = !_useNumPad;
				draw_osd(kDrawFight, _screenDest.w - 34, _screenDest.h + 2, _useNumPad, 1);
				displayMessageOnOSD(_useNumPad ? "Fight mode on." : "Fight mode off.");
				return false;
			}
			
			// other keys
			event.type = EVENT_KEYDOWN;
			event.kbd.keycode = key;
			event.kbd.ascii = key;
			event.kbd.flags = mask;
			return true;

		default:
			return false;
		};
	}
}
Exemplo n.º 30
0
int
main( int argc, char **argv )
{
	
    int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0;
    int retval;
    PAPI_event_info_t info, info1;
    const PAPI_hw_info_t *hwinfo = NULL;
    const PAPI_component_info_t* cmpinfo;
    char *Intel_i7;
    int event_code;
    int numcmp, cid;

    /* Set TESTS_QUIET variable */
    tests_quiet( argc, argv );

    /* Init PAPI library */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
       test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
    }

    retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available "
				"native events and hardware "
				"information.\n",
				&hwinfo );
    if ( retval != PAPI_OK ) {
       test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
    }

    numcmp = PAPI_num_components(  );

    /* we need a little exception processing if it's a Core i7 */
    /* Unfortunately, this test never succeeds... */
    Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" );

    /* Loop through all components */
    for( cid = 0; cid < numcmp; cid++ ) {


       cmpinfo = PAPI_get_component_info( cid );

        if (cmpinfo  == NULL)
        {
           test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );
        }

        if (cmpinfo->disabled)
        {
          printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);
          printf("   \\-> Disabled: %s\n",cmpinfo->disabled_reason);
          continue;
        }



       /* For platform independence, always ASK FOR the first event */
       /* Don't just assume it'll be the first numeric value */
       i = 0 | PAPI_NATIVE_MASK;
       retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid );

       do {
          retval = PAPI_get_event_info( i, &info );

	  /* Skip OFFCORE and UNCORE events  */
	  /* Adding them will fail currently */
	  if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) {
	     if ( !strncmp( info.symbol, "UNC_", 4 ) ) {
		unc_count++;
		continue;
	     }
	     if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) {
		offcore_count++;
		continue;
	     }
	  }

	  /* Enumerate all umasks */
	  k = i;
	  if ( PAPI_enum_cmp_event(&k, PAPI_NTV_ENUM_UMASKS, cid )==PAPI_OK ) {
	     do {
		retval = PAPI_get_event_info( k, &info1 );
		event_code = ( int ) info1.event_code;
		if ( check_event( event_code, info1.symbol ) ) {
		   add_count++;
		}
		else {
		   err_count++;
		}
	     } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK );
	  } else {
	    /* Event didn't have any umasks */
	    event_code = ( int ) info.event_code;
	    if ( check_event( event_code, info.symbol ) ) {
	       add_count++;
	    }
	    else {
	       err_count++;
	    }
	  }
	  
       } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK );

    }
    printf( "\n\nSuccessfully found and added %d events "
            "(in %d eventsets).\n",
	    add_count , add_count);

    if ( err_count ) {
       printf( "Failed to add %d events.\n", err_count );
    }

    if (( unc_count ) || (offcore_count)) {
       char warning[BUFSIZ];
       sprintf(warning,"%d Uncore and %d Offcore events were ignored",
		   unc_count,offcore_count);
       test_warn( __FILE__, __LINE__, warning, 1 );
    }

    if ( add_count > 0 ) {
       test_pass( __FILE__, NULL, 0 );
    }
    else {
       test_fail( __FILE__, __LINE__, "No events added", 1 );
    }

    exit( 1 );
}