Пример #1
0
void
mouse_secondary_click_down3(CGPoint point, uint_t sleep_quanta)
{
  CGEventRef base_event = NEW_EVENT(
				    kCGEventRightMouseDown,
				    point,
				    kCGMouseButtonRight
				    );
  POSTRELEASE(base_event);
  mouse_sleep(sleep_quanta);
}
Пример #2
0
static
void
mouse_simulation(void * unusedpointer,
          unsigned long mousenumber)
{
	int i;
	unsigned int bowl;

	/* Avoid unused variable warnings. */
	(void) unusedpointer;
	(void) mousenumber;

	/* your simulated mouse must iterate NumLoops times,
	*  sleeping (by calling mouse_sleep()) and eating
	*  (by calling mouse_eat()) on each iteration */
  for(i=0;i<NumLoops;i++) {

		/* do not synchronize calls to mouse_sleep().
       Any number of mice (and cats) should be able
       sleep at the same time. */
    mouse_sleep();
#if OPT_A1

		lock_acquire(turnDecision);

		bowl = nextBowlMouseCanUse;
		nextBowlMouseCanUse = (nextBowlMouseCanUse % NumBowls) + 1;
		
		while (cats_eating > 0 || ((int)mice_eating >= NumBowls && cats_waiting > 0)) {
			mice_waiting++;
			cv_wait(MiceAreWelcome, turnDecision);
			mice_waiting--;
		}
		mice_eating++;
		lock_release(turnDecision);
		
		lock_acquire(BowlLocks[bowl]);
		mouse_eat(bowl);
		lock_release(BowlLocks[bowl]);
		
		lock_acquire(turnDecision);
		mice_eating--;
		if (mice_eating == 0) {
			cv_broadcast(CatsAreWelcome, turnDecision);
		}
		lock_release(turnDecision);

  }

  /* indicate that this mouse is finished */
  V(CatMouseWait); 
}	
Пример #3
0
void
mouse_arbitrary_click_down3(
			    CGEventMouseSubtype button,
			    CGPoint point,
			    uint_t sleep_quanta
			    )
{
  CGEventRef base_event = NEW_EVENT(
				    kCGEventOtherMouseDown,
				    point,
				    button
				    );
  POSTRELEASE(base_event);
  mouse_sleep(sleep_quanta);
}
Пример #4
0
static
void
mouse_simulation(void * unusedpointer,
          unsigned long mousenumber)
{
  int i;
  unsigned int bowl;
  time_t before_sec, after_sec, wait_sec;
  uint32_t before_nsec, after_nsec, wait_nsec;

  /* Avoid unused variable warnings. */
  (void) unusedpointer;
  (void) mousenumber;

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

    /* make the mouse sleep */
    mouse_sleep(MouseSleepTime);

    /* choose bowl.  legal bowl numbers range from 1 to NumBowls */
    bowl = ((unsigned int)random() % NumBowls) + 1;

    gettime(&before_sec,&before_nsec);
    mouse_before_eating(bowl); /* student-implemented function */
    gettime(&after_sec,&after_nsec);

    /* make the mouse eat */
    mouse_eat(bowl, MouseEatTime, mousenumber);

    mouse_after_eating(bowl); /* student-implemented function */

    /* update wait time statistics */
    getinterval(before_sec,before_nsec,after_sec,after_nsec,&wait_sec,&wait_nsec);
    P(perf_mutex);
    mouse_total_wait_secs += wait_sec;
    mouse_total_wait_nsecs += wait_nsec;
    if (mouse_total_wait_nsecs > 1000000000) {
      mouse_total_wait_nsecs -= 1000000000;
      mouse_total_wait_secs ++;
    }
    mouse_wait_count++;
    V(perf_mutex);
  }

  /* indicate that this mouse is finished */
  V(CatMouseWait); 
}
Пример #5
0
static
void
mouse_simulation(void * unusedpointer,
          unsigned long mousenumber)
{
  int i;
  unsigned int bowl;

  /* Avoid unused variable warnings. */
  (void) unusedpointer;
  (void) mousenumber;


  /* your simulated mouse must iterate NumLoops times,
   *  sleeping (by calling mouse_sleep()) and eating
   *  (by calling mouse_eat()) on each iteration */
  for(i=0;i<NumLoops;i++) {

    /* do not synchronize calls to mouse_sleep().
       Any number of mice (and cats) should be able
       sleep at the same time. */
    mouse_sleep();

    /* for now, this mouse chooses a random bowl from
     * which to eat, and it is not synchronized with
     * other cats and mice.
     *
     * you will probably want to control which bowl this
     * mouse eats from, and you will need to provide 
     * synchronization so that the mouse does not violate
     * the rules when it eats */

#if OPT_A1
    (void)bowl; // suppress warning
    eat(1);
#else
    /* legal bowl numbers range from 1 to NumBowls */
    bowl = ((unsigned int)random() % NumBowls) + 1;
    mouse_eat(bowl);
#endif // OPT_A1

  }

  /* indicate that this mouse is finished */
  V(CatMouseWait); 
}
Пример #6
0
// Executes a linear mouse movement animation. It can be a simple cursor
// move or a drag depending on what is passed to `type`.
static
void
mouse_animate(
	      CGEventType type,
	      CGMouseButton button,
	      CGPoint start_point,
	      CGPoint end_point,
	      double duration
	      )
{
  CFDateRef current_time = NULL;
  CGPoint current_point  = start_point;
  double     xstep = (end_point.x - start_point.x) / (duration * FPS);
  double     ystep = (end_point.y - start_point.y) / (duration * FPS);
  CFDateRef  start = NOW;
  double remaining = 0.0;

  while (!CLOSE_ENOUGH(current_point, end_point)) {
    remaining  = end_point.x - current_point.x;
    current_point.x += abs(xstep) > abs(remaining) ? remaining : xstep;

    remaining  = end_point.y - current_point.y;
    current_point.y += abs(ystep) > abs(remaining) ? remaining : ystep;

    POSTRELEASE(NEW_EVENT(type, current_point, button));

    mouse_sleep(1);
    current_time = NOW;

    // this is a safety
    if (CFDateGetTimeIntervalSinceDate(NOW, start) > (duration + 1))
      break;

    RELEASE(current_time);
    current_time = NULL;

    current_point = mouse_current_position();
  }

  RELEASE(start);
  if (current_time)
    RELEASE(current_time);
}
Пример #7
0
void
mouse_click_down3(CGPoint point, uint_t sleep_quanta)
{
  POSTRELEASE(NEW_EVENT(kCGEventLeftMouseDown, point, kCGMouseButtonLeft));
  mouse_sleep(sleep_quanta);
}
static
void
mouse_simulation(void * unusedpointer,
          unsigned long mousenumber)
{
  init();
  int i;
  unsigned int bowl;

  /* Avoid unused variable warnings. */
  (void) unusedpointer;
  (void) mousenumber;



  /* your simulated mouse must iterate NumLoops times,
   *  sleeping (by calling mouse_sleep()) and eating
   *  (by calling mouse_eat()) on each iteration */
  for(i=0;i<NumLoops;i++) {

    mouse_sleep(MouseSleepTime);
    
    /* do not synchronize calls to mouse_sleep().
       Any number of mice (and cats) should be able
       sleep at the same time. */

    lock_acquire(bowlLock);
        //kprintf("Number of cats currently eating is: %d \n",numCatsEating);
        while (numCatsEating > 0){
          //kprintf("a");
          cv_wait(mouse,bowlLock);
        }

        bowl = ((unsigned int)random() % NumBowls) + 1;
    		while(bowlTaken[bowl] == true){
    	    bowl = ((unsigned int)random() % NumBowls) + 1;
    		}
        bowlTaken[bowl] = true;


        lock_acquire(mouseEatLock);
          numMouseEating = numMouseEating + 1;
        lock_release(mouseEatLock);

        lock_release(bowlLock);


        mouse_eat(bowl, MouseEatTime);
    		bowlTaken[bowl] = false;

    lock_acquire(mouseEatLock);
      numMouseEating = numMouseEating - 1;
    lock_release(mouseEatLock);


        if(numMouseEating == 0){
          cv_broadcast(cats,bowlLock);
        }



  }

  /* indicate that this mouse is finished */
  V(CatMouseWait); 
}