pelican/server/src/DataReceiver.cpp
/**
 * @details
 * Runs the thread owned by the DataReceiver object.
 * The thread creates and opens the socket and connects the readyRead()
 * socket signal to the private _processIncomingData() slot using a direct
 * connection, before entering its own event loop.
 */
@details
Runs the thread owned by the DataReceiver object.
The thread creates and opens the socket and connects the readyRead()
socket signal to the private _processIncomingData() slot using a direct
connection, before entering its own event loop.
@details Runs the thread owned by the DataReceiver object . The thread creates and opens the socket and connects the readyRead () socket signal to the private _processIncomingData () slot using a direct connection before entering its own event loop .
void DataReceiver::run()
{
    _active = true;
    _setupDevice();
    if (_device) {
        if (_device->bytesAvailable() > 0) {
            _processIncomingData();
        }
    }
#if 0
    cout << "DataReceiver starting event loop for chunker. "
         << "(" << _chunker->chunkTypes()[0].toStdString() << ", "
         << _chunker->name().toStdString() << ")" << endl;
#endif
#if USE_SIGNALS
    exec();
#else
    while (_active) {
        if (!_device) {
            cerr << "DataReceiver ERROR: Invalid device pointer!" << endl;
            _active = false;
            break;
        }
        if (_device && _device->bytesAvailable() > 0) {
            _chunker->next(_device);
        }
        if (QAbstractSocket* s = dynamic_cast<QAbstractSocket*>(_device)) {
            if (s->state() == QAbstractSocket::UnconnectedState)
                _reconnect();
        }
        else if (!_device->isReadable()) {
            cerr << "DataReceiver ERROR: Device not readable!" << endl;
            _active = false;
            break;
        }
        usleep(1); 
    }
#endif
}
void DataReceiver :: run ( ) { _active = true ; _setupDevice ( ) ; if ( _device ) { if ( _device -> bytesAvailable ( ) > 0 ) { _processIncomingData ( ) ; } } #if 0 cout << " " << " " << _chunker -> chunkTypes ( ) [ 0 ] . toStdString ( ) << " " << _chunker -> name ( ) . toStdString ( ) << " " << endl ; #endif #if USE_SIGNALS exec ( ) ; #else while ( _active ) { if ( ! _device ) { cerr << " " << endl ; _active = false ; break ; } if ( _device && _device -> bytesAvailable ( ) > 0 ) { _chunker -> next ( _device ) ; } if ( QAbstractSocket * s = dynamic_cast < QAbstractSocket * > ( _device ) ) { if ( s -> state ( ) == QAbstractSocket :: UnconnectedState ) _reconnect ( ) ; } else if ( ! _device -> isReadable ( ) ) { cerr << " " << endl ; _active = false ; break ; } usleep ( 1 ) ; } #endif }
@details
 Runs the thread owned by the DataReceiver object.
@details Runs the thread owned by the DataReceiver object .
// Open up the device to use. // N.B. must be done in this thread (i.e. in run()) // process any existing data on the stream // At this point the event loop takes over to call the chunker // next method // enter main event loop (until quit() is called) //cout << "DataReceiver: checking for data ... " << endl; // NOTE while this check seems like a good idea it fails in some of // the unit tests... // If the device is a socket handle error conditions //            if (s->error()) //                _processError(); // For devices with no reconnect exit the event loop if the // device becomes unreadable. // how long should this be.