Example #1
0
// student simulation
void* student(){
   

    enter_bar();
    int tid = thread_getId();
    int i;
    for(i = 0; i < tid % 5; i++){
      printf(1,"Student %d is for i: %d\n",tid,i+1);
      struct Action* drink_action = malloc(sizeof(struct Action));
      memset(drink_action,0,sizeof(struct Action));
      drink_action->action_type = DRINK_ORDER;
      drink_action->cup = 0;
      drink_action->tid = tid;
      place_action(drink_action);//Order a Drink
      struct Cup * cup = get_drink();	//get the drink from the BB
      //need to write to file intsead of screen TODO
      printf(1,"Student %d is having his %d drink, with cup %d\n",tid,i+1,cup->id);
      sleep(1);
      struct Action* return_action = malloc(sizeof(struct Action));
      memset(return_action,0,sizeof(struct Action));
      return_action->action_type = RETURN_CUP;
      return_action->cup=cup;
      return_action->tid = tid;
      place_action(return_action);
    }
    //need to write to file intsead of screen TODO
    printf(1,"Student %d is drunk, and trying to go home\n",thread_getId());
    leave_bar();
    thread_exit(0);
    return 0;
}
Example #2
0
void get_drink() {
  ROS_INFO("Running drink task");
  //run the drink task
  actionlib::SimpleActionClient<serve_drink::ServeDrinkAction> client("serve_drink_action", true); // true -> don't need ros::spin()
  client.waitForServer();
  serve_drink::ServeDrinkGoal goal;
  client.sendGoal(goal, &drinkActionDoneCb,&drinkActionActiveCb,&drinkActionFeedbackCb);
  //wait until success or failure
  client.waitForResult();
  //see if drink task failed and we need to do teleop
  if (drink_needs_teleop) {
    should_restart_drink=false;
    ros::Rate rate(5);
    //spin until you receive a resume drink message/servicecall, then restart get_drink   
    while (!should_restart_drink) {
      ros::spinOnce();
      rate.sleep();
    }
    drink_needs_teleop=false;
    get_drink();
  }

  //if success, finish
  drink_needs_teleop=false;
  should_restart_drink=false;

  ROS_INFO("Drink task finished");
}
Example #3
0
void executeTask(hackathon_scheduler::Event task) {
  taskName=task.taskName;
  startTime=task.startTime;
  if (strstr(task.taskType.c_str(),"medicine")) {
    get_medicine();
  }
  else if (strstr(task.taskType.c_str(),"lunch")) {
    get_lunch(task.parameters);
  }
  else if (strstr(task.taskType.c_str(),"drink")) {
    get_drink();
  }
  else if (strstr(task.taskType.c_str(),"dummytask")) {
    int c;
    if (!sscanf(task.parameters.c_str(),"%d",&c)) c=5;
    dummy_action(c);
  }
}
Example #4
0
void* student_work(){
	int k=thread_getId() % 5;
	
	enter_bar();
	int i;
	for(i=0; i<k; i++){
		// create action
		printf(1, "creating order...\n");
		struct Action* action=malloc(sizeof(struct Action));
		action->type=1;
		action->cup=0;
		action->tid=thread_getId();
		
		place_action(action);
		printf(1, "placed order\n");
		
		struct Cup* cup=get_drink();
		
		printf(fileOut, "Student %d is having his %d drink, with cup %d\n",
				 thread_getId(), i, cup->id);
		
		sleep(1);
		
		action=malloc(sizeof(struct Action));
		action->type=2;
		action->cup=cup;
		action->tid=thread_getId();
		
		printf(1, "returning cup...\n");
		place_action(action);
	}
	
	printf(fileOut, "Student %d is drunk, and trying to go home", thread_getId());
	leave_bar();
	printf(1, "left bar... left=%d\n", left_counter);
	
	thread_exit(&i);
	return 0;
}