ClientMessageBus* ClientProtocolThread::initialize()
{
        start();
        qxt_d().waiter.wait(&_mutex);
        _protocol->moveToThread(_bus->thread());
		//Connect all the signals and slots that make the communication work....

		//disconnect signal
	connect(_protocol, SIGNAL(disconnected()), _bus, SIGNAL(disconnected()), Qt::DirectConnection);

		//server calls callback on client
	connect(_protocol, SIGNAL(sendCallback(Message)), _bus, SIGNAL(sendCallback(Message)), Qt::DirectConnection);

		//server sends return to client
	connect(_protocol, SIGNAL(returnReceived(Message)), &_bus->qxt_d(), SLOT(returnReceived(Message)), Qt::DirectConnection);

		//server sends event to client
	connect(_protocol, SIGNAL(sendEvent(Message)), _bus, SIGNAL(sendEvent(Message)), Qt::DirectConnection);

		//client sends return to server
	connect(_bus, SIGNAL(callbackReturn(Message)), _protocol, SLOT(callbackReturn(Message)), Qt::DirectConnection);

		//client calls function on server (thread boundary)
	connect(_bus, SIGNAL(sendFunction(Message)), _protocol, SLOT(sendFunction(Message)), Qt::QueuedConnection);

	qxt_d().waiter.wakeAll();
	_mutex.unlock();
	_initMutex.unlock();
	return _bus;
}
Exemple #2
0
void OtherDataMessage::sendData()
{
    char buffer[30] = "";
    static Time sentTime;
    static int interval = 0;
    NumbersAndSizes stats;

    int messageNumber = OtherDataMessage::newMessageNumber(streamNumber);

    stats.number = messageNumber;

    fillMessageContents(buffer, messageNumber);

    if(ranvarSize == 0)
    {
        stats.size = this->messageSize;
    }
    else
    {
        stats.size = ranvarSize->GetInteger();
    }  

    if(ranvarForwardSize == 0)
    {
        if(useRcvSize)
            stats.forwardSize = stats.size;
        else
            stats.forwardSize = this->forwardSize;
    }
    else
    {
        stats.forwardSize = ranvarForwardSize->GetInteger();
    }

    numbersAndSizes.at(streamNumber).at(OTHER_DATA).push_back(stats);

    sentTime = Simulator::Now();

    StatisticsCollector::logMessagesSentFromServer(messageNumber, sentTime, streamNumber, clientTimeRequirement,
                                                   OtherDataMessage::getODMNameIndex(name), messageID, stats.size);

    if(!sendFunction(this, (uint8_t*)buffer))
        PRINT_ERROR("Problems with socket buffer" << std::endl);

    if(ranvarTimeInterval != 0)
    {
        interval = ranvarTimeInterval->GetInteger();

        if(interval <= 0)
            interval = 1;
    }

    if(running)
    {
        if(ranvarTimeInterval == 0)
            sendEvent = Simulator::Schedule(Time(MilliSeconds(timeInterval)), &OtherDataMessage::sendData, this);
        else
            sendEvent = Simulator::Schedule(Time(MilliSeconds(interval)), &OtherDataMessage::sendData, this);
    }
}