Exemplo n.º 1
0
void SimpleConduit::serviceIncomingEvents(){
    
    shared_ptr<Clock> clock = Clock::instance(false);
    
    bool finished = false;
    
    while(!finished){
        
        bool _stopping = false;
        
        {
            boost::mutex::scoped_lock lock(stopping_mutex);
            _stopping = stopping;
        }
        
        
        if(_stopping){
            
            {
                boost::mutex::scoped_lock lock(stopping_mutex);
                stopped = true;
            }
            finished = true;
            break;
        }
        
        
        if(transport == NULL){
            throw SimpleException("Attempt to receive on a NULL event transport");
        }
        
        shared_ptr<Event> incoming_event = transport->receiveEventAsynchronous();
        if(incoming_event == NULL){
            //boost::thread::yield();
            //boost::thread::sleep(boost::posix_time::microsec_clock::local_time() + boost::posix_time::microseconds(conduit_idle_quantum));
            clock->sleepUS(conduit_idle_quantum_us);
            continue;
        }
        
        
        if(correct_incoming_timestamps){
            // if a clock offset has been stored from the other side of the conduit 
            // apply the offset here:
            incoming_event->setTime( incoming_event->getTime() - remote_clock_offset ); 
        }
                
        handleCallbacks(incoming_event);
        
    }
}
Exemplo n.º 2
0
void Client::handleEvent(shared_ptr<Event> evt) { 
	int code = evt->getEventCode();
    
    switch (code) {
        case RESERVED_CODEC_CODE:
            registry->updateFromCodecDatum(evt->getData());
            // Request updated values for all variables
            putEvent(SystemEventFactory::requestVariablesUpdateControl());
            break;
            
        case RESERVED_SYSTEM_EVENT_CODE: {
            auto &sysEvent = evt->getData();
            if (sysEvent.getElement(M_SYSTEM_PAYLOAD_TYPE).getInteger() == M_SERVER_CONNECTED_CLIENT) {
                long clientID = sysEvent.getElement(M_SYSTEM_PAYLOAD).getInteger();
                std::lock_guard<std::mutex> lock(connectedEventReceivedMutex);
                if (remoteConnection &&
                    clientID == reinterpret_cast<long>(remoteConnection.get()))
                {
                    // Received connection acknowledgement from server.  Notify any thread waiting
                    // in connectToServer.
                    connectedEventReceived = true;
                    connectedEventReceivedCondition.notify_all();
                }
            }
            break;
        }
            
        case RESERVED_TERMINATION_CODE:
            mwarning(M_CLIENT_MESSAGE_DOMAIN, "Received termination notification from server; disconnecting");
            (void)disconnectClient();
            break;
            
        default:
            break;
    }
    
    handleCallbacks(evt);

    if(code >= N_RESERVED_CODEC_CODES && code < registry->getNVariables() + N_RESERVED_CODEC_CODES) {
        shared_ptr <Variable> var = registry->getVariable(code);
        if(var) {
            var->setSilentValue(evt->getData());
		} else {
			mwarning(M_CLIENT_MESSAGE_DOMAIN, "Invalid variable, client not processing event code: %d", code);
		}
	}
}
Exemplo n.º 3
0
void Server::handleEvent(shared_ptr<Event> evt) {
	handleCallbacks(evt);
}