示例#1
0
int main()
{
  ArSyncTask *task;
  UserTaskTest test;
  ArRobot robot;

  ArFunctorC<UserTaskTest> userTaskOne(&test, &UserTaskTest::userTaskOne);
  ArFunctorC<UserTaskTest> userTaskTwo(&test, &UserTaskTest::userTaskTwo);
  ArFunctorC<UserTaskTest> userTaskThree(&test, &UserTaskTest::userTaskThree);
  ArFunctorC<UserTaskTest> userTaskFour(&test, &UserTaskTest::userTaskFour);


  printf("Before tasks added:\n");
  robot.logUserTasks();
  printf("---------------------------------------------------------------\n");

  // the order you add tasks doesn't matter, it goes off of the integer
  // you give the function call to add them 
  // Caveat: if you give the function call the same number it goes off of order
  robot.addUserTask("procTwo", 20, &userTaskTwo);
  robot.addUserTask("procFour", 40, &userTaskFour, &test.myTaskFourState);
  robot.addUserTask("procThree", 30, &userTaskThree);
  robot.addUserTask("procOne", 10, &userTaskOne);

  printf("After tasks added:\n");
  robot.logUserTasks();
  printf("---------------------------------------------------------------\n");
  printf("What happens when these are run:\n");
  robot.loopOnce();

  printf("---------------------------------------------------------------\n");

  printf("After tasks removed by name:\n");
  printf("---------------------------------------------------------------\n");
  robot.remUserTask("procOne");
  robot.remUserTask("procTwo");
  robot.remUserTask("procThree");
  robot.remUserTask("procFour");
  robot.logUserTasks();


  printf("\nAfter they are added again, procThree is found by name and set to SUSPEND and procFour is found by functor and set to FAILURE:\n");
  printf("---------------------------------------------------------------\n");

  printf("---------------------------------------------------------------\n");
  robot.addUserTask("procTwo", 20, &userTaskTwo);
  robot.addUserTask("procFour", 40, &userTaskFour, &test.myTaskFourState);
  robot.addUserTask("procThree", 30, &userTaskThree);
  robot.addUserTask("procOne", 10, &userTaskOne);
  task = robot.findUserTask("procThree");
  if (task != NULL)
    task->setState(ArTaskState::SUSPEND);

  task = robot.findUserTask(&userTaskFour);
  if (task != NULL) 
    task->setState(ArTaskState::FAILURE);

  robot.logUserTasks();

  task = robot.findUserTask(&userTaskFour);
  if (task != NULL)
  {
    printf("---------------------------------------------------------------\n");

    printf("Did the real state on procFourState get set:\n");
    printf("getState: %d realState: %d\n", task->getState(), 
	   test.myTaskFourState);
  }


  printf("---------------------------------------------------------------\n");
  printf("What happens when these are run:\n");
  robot.loopOnce();

  printf("---------------------------------------------------------------\n");


  printf("After tasks removed by functor:\n");
  printf("---------------------------------------------------------------\n");
  robot.remUserTask(&userTaskOne);
  robot.remUserTask(&userTaskTwo);
  robot.remUserTask(&userTaskThree);
  robot.remUserTask(&userTaskFour);
  robot.logUserTasks();
  
  
}