コード例 #1
0
ファイル: terminador.cpp プロジェクト: serpi90/RedesIV2014
int main()
{
    Queue<struct iMessage> * q;

    q = new Queue<struct iMessage>(PATH, Q_FROM_INTERFACE, "terminador", false);
    q->get();
    q->remove();
    q = new Queue<struct iMessage>(PATH, Q_TO_INTERFACE, "terminador", false);
    q->get();
    q->remove();

    Semaphore * s;

    s = new Semaphore(PATH, SEM_MUTEX, "terminador", false);
    s->get();
    s->remove();
    s->post();
    s = new Semaphore(PATH, SEM_LECTORES, "terminador", false);
    s->get();
    s->remove();
    s = new Semaphore(PATH, SEM_ESCRITORES, "terminador", false);
    s->get();
    s->remove();
    s = new Semaphore(PATH, SEM_COTIZ, "terminador", false);
    s->get();
    s->remove();
    s->post();


    SharedMemory<struct registro> * shm;
    shm = new SharedMemory<struct registro>(PATH, SHM_REGISTRO, "terminador", false);
    shm->get();
    shm->remove();
}
コード例 #2
0
ファイル: shmstat.cpp プロジェクト: serpi90/RedesIV2014
int main( ) {
    SharedMemory * shm = new SharedMemory(PATH, SHM_PLAT, sizeof (struct plate), "shmstat");
    shm->get();
    struct plate * plate = (struct plate*) shm->attach();
    std::stringstream status;
    Semaphore * mutex = new Semaphore(PATH, SEM_MUTEX, "shmstat");
    mutex->get();
    mutex->wait();
    status << "RobotsA: " << plate->activeRobotsA << std::endl;
    status << "RobotsB: " << plate->activeRobotsB << std::endl;
    status << "Dispositivos: " << plate->storedAmount << std::endl;
    for (int i = 0; i < ROBOT_AMOUNT; i++)
    {
        status << "A" << i << ": " << msgRobot( plate->statusA[i] ) << ", " << msgWait( plate->statusE[i] ) << std::endl;
        status << "B" << i << ": " << msgRobot( plate->statusB[i] ) << std::endl;
    }
    for (int i = 0; i < PLAT_SIZE; i++)
    {
	status << i << ": " << msgSlot(plate->slots[i].state) << ", " << msgDisp(plate->slots[i].dispositive.status) << std::endl;
    }
    mutex->post();
    write(fileno(stdout),status.str().c_str(),status.str().size());
    shm->dettach();
}
コード例 #3
0
ファイル: terminador.cpp プロジェクト: serpi90/RedesIV2014
int main() {
	std::string owner = "terminador";

	Queue<ColaPlataforma::message> * pIn, *pOut;
	Queue<ColaExclusion::message> * eIn, *eOut;
	Queue<ColaActivado::message> * act;
	Queue<ColaArmado::message> * arm;
	Queue<ColaDispositivo::message> * disp;
	Queue<ColaSalida::message> * sal;

	Semaphore * mutexPlat;
	SemaphoreArray * semEspera;

	SharedMemory<ColaPlataforma::shared> * shmP;

	Semaphore * mutexExcl;
	SemaphoreArray * semExcl;

	SharedMemory<ColaExclusion::shared> * shmE;

	pIn = new Queue<ColaPlataforma::message>(path, (long) QueueIdentifier::PLATAFORMA_FROM_INTERFACE, owner, false);
	pIn->get();
	pIn->remove();
	pOut = new Queue<ColaPlataforma::message>(path, (long) QueueIdentifier::PLATAFORMA_TO_INTERFACE, owner, false);
	pOut->get();
	pOut->remove();
	eIn = new Queue<ColaExclusion::message>(path, (long) QueueIdentifier::EXCLUSION_FROM_INTERFACE, owner, false);
	eIn->get();
	eIn->remove();
	eOut = new Queue<ColaExclusion::message>(path, (long) QueueIdentifier::EXCLUSION_TO_INTERFACE, owner, false);
	eOut->get();
	eOut->remove();
	act = new Queue<ColaActivado::message>(path, (long) QueueIdentifier::ACTIVADO, owner, false);
	act->get();
	act->remove();
	arm = new Queue<ColaArmado::message>(path, (long) QueueIdentifier::ARMADO, owner, false);
	arm->get();
	arm->remove();
	disp = new Queue<ColaDispositivo::message>(path, (long) QueueIdentifier::DISPOSITIVOS, owner, false);
	disp->get();
	disp->remove();
	sal = new Queue<ColaSalida::message>(path, (long) QueueIdentifier::SALIDA, owner, false);
	sal->get();
	sal->remove();

	mutexPlat = new Semaphore(path, (int) (long) SemaphoreIdentifier::MUTEX_PLATAFORMA, owner, false);
	mutexPlat->get();
	mutexPlat->remove();
	mutexPlat->post();
	semEspera = new SemaphoreArray(path, (int) (long) SemaphoreIdentifier::SEM_ESPERA, ROBOT_AMOUNT, owner, false);
	semEspera->get();
	semEspera->remove();
	shmP = new SharedMemory<ColaPlataforma::shared>(path, (int) (long) SharedMemoryIdentifier::PLATAFORMA, owner, false);
	shmP->get();
	shmP->remove();

	mutexExcl = new Semaphore(path, (int) (long) SemaphoreIdentifier::MUTEX_EXCLUSION, owner, false);
	mutexExcl->get();
	mutexExcl->remove();
	mutexExcl->post();
	semExcl = new SemaphoreArray(path, (int) (long) SemaphoreIdentifier::SEM_EXCLUSION, ROBOT_AMOUNT, owner, false);
	semExcl->get();
	semExcl->remove();
	shmE = new SharedMemory<ColaExclusion::shared>(path, (int) (long) SharedMemoryIdentifier::EXCLUSION, owner, false);
	shmE->get();
	shmE->remove();
}