unsigned int
MsgAggregatingCommunicationManager::checkPhysicalLayerForMessages(int maxNum) {
    int numberOfMessagesReceived = 0;
    bool noMessagesLeft = false;
    SerializedInstance* msg = NULL;

    while (numberOfMessagesReceived != maxNum && noMessagesLeft == false) {
        msg = retrieveMessageFromPhysicalLayer();
        if (msg == NULL) {
            // there are no messages at this time
            noMessagesLeft = true;
            waitedWithNoInputMessages++;
        } else {
            // there are messages to pick up
            numberOfMessagesReceived++;
            waitedWithNoInputMessages = 0;

            // deserialize the message and route it to the appropriate
            // receiver
            routeMessage(dynamic_cast<KernelMessage*>(msg->deserialize()));
            // since we allocated it, we delete it
            delete msg;
        }
    }// end while loop

    return numberOfMessagesReceived;
}
Пример #2
0
void JausRouter::sendMessage(Send_1_0* msg)
{
#ifdef DEBUG
		unsigned short msg_id = *((unsigned short*) msg->getBody()->getSendRec()->getMessagePayload()->getData());
		std::cout << "[JausRouter::sendMessage] Sending msg 0x" << std::hex << msg_id << std::dec << std::endl;
#endif
		
	/// Pull the destination ID
	JausAddress destination(msg->getBody()->getSendRec()->getDestSubsystemID(),
							msg->getBody()->getSendRec()->getDestNodeID(),
							msg->getBody()->getSendRec()->getDestComponentID());

	// If the destination is local, loopback to the routeMessage function
	if (destination == jausAddress)
	{
			routeMessage(destination,
				msg->getBody()->getSendRec()->getMessagePayload()->getLength(), 
				msg->getBody()->getSendRec()->getMessagePayload()->getData());
	}
	// Otherwise, forward Message to NodeManager. 
	else
		JrErrorCode ret = JrSend(jrHandle, destination.get(), 
							 msg->getBody()->getSendRec()->getMessagePayload()->getLength(), 
							 (const char*) msg->getBody()->getSendRec()->getMessagePayload()->getData());
}
Пример #3
0
void JausRouter::run()
{
	char* buffer;
	unsigned int bufsize;
	unsigned int source;
	int priority;
	int flags; 
	unsigned short msg_id;
	
	runLock.lock();
	isRunning = true;
	runLock.unlock();
	
#ifdef DEBUG
	std::cout << "[JausRouter::run]" << std::endl;
#endif
	
	while (isRunning)
	{
		/*
		 *  Transport Service receives a TransportMessage 
		 */
		if (JrReceive(jrHandle, &source, &bufsize, &buffer, &priority, &flags, &msg_id)  == Ok)
		{
#ifdef DEBUG
	std::cout << "[JausRouter::receive] Message size " << bufsize << " bytes " << std::endl;
#endif

			// See if we got an exit signal while we were pending
			if (!isRunning) break;

			// Create a component message wrapper to pass to the services...
			JausAddress sender(source);
			routeMessage(source, bufsize, (unsigned char*) buffer);
			if (buffer) 
			{
				delete[] buffer;
				buffer = NULL;
			}
		}
		else
		{
			DeVivo::Junior::JrSleep(1); // throttle
		}
	}

#ifdef DEBUG
	std::cout << "[JausRouter::shutdown]" << std::endl;
#endif
}
void
ClientMessageRouter::routeMessages()
{
    ClientConnectDaemon::connectProcess( );

    if( NetworkState::ping_timer.count() ) {
        //GameManager::requestNetworkPing();
    }

    NetPacket packet;

    Uint16 msg_len;
    NetMessage* mmessage;

    while ( CLIENT->getPacket(&packet) )
    {
        const NetMessage* message = packet.getNetMessage();
        if (message->message_class == _net_message_class_multi)
        {
            NetMessageDecoder message_decoder;
            message_decoder.setDecodeMessage( (const MultiMessage *) message, packet.size );

            NetPacket pp;
            pp.fromPlayer = packet.fromPlayer;
            pp.fromClient = packet.fromClient;

            while( (msg_len = message_decoder.decodeMessage(&mmessage)) )
            {
                memcpy(pp.data, mmessage, msg_len);
                routeMessage(&pp);
            }
        } else {
            routeMessage(&packet);
        }
    }

}