pelican/server/src/Session.cpp
/**
 * @details
 * Processes a general ServerRequest, calling the appropriate working and then
 * passes this on to the protocol to be returned to the client.
 */
@details
Processes a general ServerRequest, calling the appropriate working and then
passes this on to the protocol to be returned to the client.
@details Processes a general ServerRequest calling the appropriate working and then passes this on to the protocol to be returned to the client .
void Session::processRequest(const ServerRequest& req, QIODevice& out,
        const unsigned timeout)
{
    try {
        switch(req.type())
        {
            case ServerRequest::Acknowledge:
            {
                _protocol->send(out,"ACK");
                verbose("Sent acknowledgement");
                break;
            }
            case ServerRequest::DataSupport:
            {
                verbose("DataSupport request received");
                DataSupportResponse r( _dataManager->dataSpec() );
                _protocol->send(out, r);
                break;
            }
            case ServerRequest::StreamData:
            {
                QList<LockedData> dataList = processStreamDataRequest(
                        static_cast<const StreamDataRequest&>(req), timeout);
                if (dataList.size() > 0)
                {
                    AbstractProtocol::StreamData_t data;
                    for (int i = 0; i < dataList.size(); ++i) {
                        LockableStreamData* lockedData =
                                static_cast<LockableStreamData*>(dataList[i].object());
                        data.append(static_cast<StreamData*>(lockedData->streamData()));
                    }
                    _protocol->send(out, data);
                    foreach (LockedData d, dataList) {
                        static_cast<LockableStreamData*>(d.object())->served() = true;
                    }
                }
                break;
            }
            case ServerRequest::ServiceData:
            {
                verbose("ServiceData request received");
                QList<LockedData> d =
                        processServiceDataRequest(static_cast<const ServiceDataRequest&>(req));
                if (d.size() > 0) {
                    AbstractProtocol::ServiceData_t data;
                    for (int i=0; i < d.size(); ++i)
                    {
                        LockableServiceData* lockedData =
                                static_cast<LockableServiceData*>(d[i].object());
                        data.append(lockedData->dataChunk().get());
                    }
                    _protocol->send(out, data);
                }
                break;
            }
            default:
                verbose("protocol error: " + req.message());
                _protocol->sendError(out, req.message());
                break;
        }
    }
    catch (const QString& e)
    {
        verbose("caught error: " + e );
        _protocol->sendError(out, e);
    }
}
void Session :: processRequest ( const ServerRequest & req , QIODevice & out , const unsigned timeout ) { try { switch ( req . type ( ) ) { case ServerRequest :: Acknowledge : { _protocol -> send ( out , " " ) ; verbose ( " " ) ; break ; } case ServerRequest :: DataSupport : { verbose ( " " ) ; DataSupportResponse r ( _dataManager -> dataSpec ( ) ) ; _protocol -> send ( out , r ) ; break ; } case ServerRequest :: StreamData : { QList < LockedData > dataList = processStreamDataRequest ( static_cast < const StreamDataRequest & > ( req ) , timeout ) ; if ( dataList . size ( ) > 0 ) { AbstractProtocol :: StreamData_t data ; for ( int i = 0 ; i < dataList . size ( ) ; ++ i ) { LockableStreamData * lockedData = static_cast < LockableStreamData * > ( dataList [ i ] . object ( ) ) ; data . append ( static_cast < StreamData * > ( lockedData -> streamData ( ) ) ) ; } _protocol -> send ( out , data ) ; foreach ( LockedData d , dataList ) { static_cast < LockableStreamData * > ( d . object ( ) ) -> served ( ) = true ; } } break ; } case ServerRequest :: ServiceData : { verbose ( " " ) ; QList < LockedData > d = processServiceDataRequest ( static_cast < const ServiceDataRequest & > ( req ) ) ; if ( d . size ( ) > 0 ) { AbstractProtocol :: ServiceData_t data ; for ( int i = 0 ; i < d . size ( ) ; ++ i ) { LockableServiceData * lockedData = static_cast < LockableServiceData * > ( d [ i ] . object ( ) ) ; data . append ( lockedData -> dataChunk ( ) . get ( ) ) ; } _protocol -> send ( out , data ) ; } break ; } default : verbose ( " " + req . message ( ) ) ; _protocol -> sendError ( out , req . message ( ) ) ; break ; } } catch ( const QString & e ) { verbose ( " " + e ) ; _protocol -> sendError ( out , e ) ; } }
@details
 Processes a general ServerRequest, calling the appropriate working and then
 passes this on to the protocol to be returned to the client.
@details Processes a general ServerRequest calling the appropriate working and then passes this on to the protocol to be returned to the client .
// List of data to be served. // Mark as data as being served so it can be de-activated.