/**
*	@brief Callback function that unpacks and processes resident status messages.
*	Assistant should subscribe to the ResidentMsg topic in order for this callback to be called. ResidentMsg is published by the Resident.
*	@note Currently this callback processes only resident hunger, controlling the cooking behaviour. More behaviours 
*	can be implemented later.
*	@param msg A custom ResidentMsg message that contains information about the resident's current status.
*/
void Caregiver::delegate(se306_project1::ResidentMsg msg)
{

	if (msg.state == "caregiver") {
		if (!atResident) {
			move(msg.currentCheckpoint); //to resident

			if (true) { // next to resident
				atResident = true;
				std_msgs::String cMsg;
				std::stringstream ss;
				ss << "Here"; // Ready to start routine
				cMsg.data = ss.str();
			}
			
		}

		if (!hasShowered && atResident) {
			hasShowered = shower(msg); //Will return true when shower is completed
		}

		if (hasShowered && !hasExercised) {
			hasExercised = exercise(msg);
		}

		if (hasExercised) {
			move("FrontDoorEast"); //leave or something
		}
	}
}
static
void
girl(void *p, unsigned long which)
{
	(void)p;
	

	// Implement this function	
	lock_acquire(BrLock);
	girl_count++;
	if(mode==0)
	{
		if(boy_count>girl_count)
			mode=1;
		else
			mode=2;
	}
	kprintf("girl #%ld starting\n", which);

	while(mode==1 || BrSem->sem_count==0 || futureMode==1)
		cv_wait(girlCV,BrLock);
	P(BrSem);
	girl_count--;
	lock_release(BrLock);
	// use bathroom
	kprintf("girl #%ld entering bathroom...\n", which);	
	shower();
	kprintf("girl #%ld leaving bathroom\n", which);

	lock_acquire(BrLock);
	V(BrSem);

	if(boy_count!=0)
	{
		futureMode=1;
	}
	else
	{
		if(girl_count==0)
			futureMode=0;
		else
		{
			futureMode=2;
			cv_broadcast(girlCV,BrLock);
		}
	}

	if(BrSem->sem_count==3)
	{
		mode=futureMode;
		if(mode==1)
			cv_broadcast(boyCV,BrLock);
		else if(mode==2)
			cv_broadcast(girlCV,BrLock);
	}
	
	lock_release(BrLock);
	V(doneSem);
}
static
void
boy(void *p, unsigned long which)
{
	(void)p;

	// Implement this function
	lock_acquire(BrLock);
	boy_count++;
	if(mode==0)
	{
		if(boy_count>girl_count)
			mode=1;
		else
			mode=2;
	}
	kprintf("boy #%ld starting\n", which);
	//mode prevents boys entering girls' room
	//futureMode is needed, to prevent consecutive boys keep on entering

	while(mode==2 || BrSem->sem_count==0 || futureMode==2)
		cv_wait(boyCV,BrLock);
	P(BrSem);
	boy_count--;
	lock_release(BrLock);
	// use bathroom
	kprintf("boy #%ld entering bathroom...\n", which);	
	shower();
	kprintf("boy #%ld leaving bathroom\n", which);

	lock_acquire(BrLock);
	V(BrSem);
	if(girl_count!=0)
	{
		futureMode=2;
	}
	else
	{
		if(boy_count==0)
			futureMode=0;
		else
		{
			futureMode=1;
			cv_broadcast(boyCV,BrLock);
		}
	}
	if(BrSem->sem_count==3)
	{
		mode=futureMode;
		if(mode==1)
			cv_broadcast(boyCV,BrLock);
		else if(mode==2)
			cv_broadcast(girlCV,BrLock);
	}

	lock_release(BrLock);
	V(doneSem);
}
int main ( int argc, char **argv )
{
  if ( argc>1 )
  {
    jdkmidi::MIDIFileReadStreamFile rs ( argv[1] );
    jdkmidi::MIDIFileShow shower ( stdout );
    jdkmidi::MIDIFileRead reader ( &rs, &shower );
    
    reader.Parse();
  }
  
  return 0;
}
Exemple #5
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QString engine = "Raster";
    QString file;
    for (int i = 1; i < argc; ++i) {
        QString opt = argv[i];
        if (opt == "-engine") {
            ++i;
            engine = QString(argv[i]);
        } else if (opt.startsWith('-')) {
            qDebug()<<"Unsupported option "<<opt;
        } else
            file = QString(argv[i]);
    }

    bool engineExists = false;
    QStringList engineNames;
    foreach(QEngine *qengine, QtEngines::self()->engines()) {
        if (qengine->name() == engine) {
            engineExists = true;
        }
        engineNames.append(qengine->name());
    }

    if (file.isEmpty() || engine.isEmpty()) {
        usage();
        return 1;
    }

    if (!engineExists) {
        qDebug()<<"Engine "<<engine<<" doesn't exist!\n"
                <<"Available engines: "<<engineNames;
        usage();
        return 1;
    }
    if (!QFile::exists(file)) {
        qDebug()<<"Specified file "<<file<<" doesn't exist!";
        return 1;
    }

    qDebug()<<"Using engine: "<<engine;
    Shower shower(file, engine);
    shower.show();

    return app.exec();
}