Exemplo n.º 1
0
/*******************************************************************
* Function Name: outputFunction
* Description: 
********************************************************************/
Model &cola::outputFunction( const CollectMessage &msg )
{

	if( (elements().size() > 0)  && ocupado()==0 )
	{ 
		this->sendOutput( msg.time(), out, elements().front() ) ;
		elements().pop_front() ;
	}
	return *this ;
}
Exemplo n.º 2
0
/*******************************************************************
* Function Name: externalFunction
* Description: 
********************************************************************/
Model &cola::externalFunction( const ExternalMessage &msg )
{
	if( msg.port() == in )
	{
		elements().push_back( msg.value() ) ;
		this->holdIn( AtomicState::active, preparationTime );
	}

	if( msg.port() == done )
	{
		ocupado (0);
		this->holdIn( AtomicState::active, preparationTime );
	}

	if( msg.port() == stop )
	{ 
		ocupado (1);
		this->passivate();
	}

	return *this;
}
Exemplo n.º 3
0
/************************************************************************************************
    handleTCP()
Arguments:
        tcpSocket - socket created for the tcp communications
Description: In this function the accept of the TCP socket is done case a chat is not alread
running with other user. In this case, a busy signal is sent back.
*************************************************************************************************/
int handleTCP(int *tcpSocket){

	struct sockaddr_in addr;
	int newTCP;
	socklen_t  addrlen;

	memset((void*)&addr, (int) '\0', sizeof(addr));

	addrlen=sizeof(addr);
	if((newTCP=accept(*tcpSocket,(struct sockaddr*)&addr, &addrlen)) <0){
		perror("\n>accept failed\n");
		return -1;
	}

	if(talkSock != -1){
        ocupado(newTCP);
        return -1;
	}

    printf("\n>Entered conversation\n");

	return newTCP;
}
Exemplo n.º 4
0
/*******************************************************************
* Function Name: initFunction

********************************************************************/
Model &cola::initFunction()
{
	ocupado (0);
	elements().erase( elements().begin(), elements().end() ) ;
	return *this ;
}