pelican/comms/src/PelicanProtocol.cpp
/**
 * @details
 * Creates a server request object based on the request received from the
 * PelicanServerClient using the PelicanClientProtocol
 */
@details
Creates a server request object based on the request received from the
PelicanServerClient using the PelicanClientProtocol
@details Creates a server request object based on the request received from the PelicanServerClient using the PelicanClientProtocol
boost::shared_ptr<ServerRequest> PelicanProtocol::request(QTcpSocket& socket)
{
    int timeout = 1000;
    ServerRequest::Request type = ServerRequest::Error;
    while (socket.bytesAvailable() < (int)sizeof(quint16))
    {
        if ( !socket.waitForReadyRead(timeout)) {
            return boost::shared_ptr<ServerRequest>(new ServerRequest(type,
                    socket.errorString()));
        }
    }
    QDataStream in(&socket);
    quint16 tmp;
    in.setVersion(QDataStream::Qt_4_0);
    in >> tmp;
    type=(ServerRequest::Request)tmp;
    switch(type)
    {
        case ServerRequest::Acknowledge:
        {
            return boost::shared_ptr<AcknowledgementRequest>(
                    new AcknowledgementRequest());
            break;
        }
        case ServerRequest::ServiceData:
        {
            boost::shared_ptr<ServiceDataRequest> s(new ServiceDataRequest);
            quint16 num; 
            in >> (quint16&)num;
            for(int i=0; i < num; ++i)
            {
                QString dtype;
                QString version;
                in >> dtype >> version;
                s->request(dtype,version);
            }
            return s;
        }
        case ServerRequest::StreamData:
        {
            boost::shared_ptr<StreamDataRequest> s(new StreamDataRequest);
            quint16 num;
            in >> num; 
            for(int i = 0; i < num; ++i )
            {
                QSet<QString> serviceData;
                QSet<QString> streamData;
                in >> serviceData;
                in >> streamData;
                DataSpec dr;
                dr.addServiceData(serviceData);
                dr.addStreamData(streamData);
                s->addDataOption(dr);
            }
            return s;
        }
        case ServerRequest::DataSupport:
        {
            boost::shared_ptr<DataSupportRequest> s(new DataSupportRequest);
            return s;
        }
        default:
            break;
    }
    return boost::shared_ptr<ServerRequest>(new ServerRequest(ServerRequest::Error, "PelicanProtocol: Unknown type passed"));
}
boost :: shared_ptr < ServerRequest > PelicanProtocol :: request ( QTcpSocket & socket ) { int timeout = 1000 ; ServerRequest :: Request type = ServerRequest :: Error ; while ( socket . bytesAvailable ( ) < ( int ) sizeof ( quint16 ) ) { if ( ! socket . waitForReadyRead ( timeout ) ) { return boost :: shared_ptr < ServerRequest > ( new ServerRequest ( type , socket . errorString ( ) ) ) ; } } QDataStream in ( & socket ) ; quint16 tmp ; in . setVersion ( QDataStream :: Qt_4_0 ) ; in >> tmp ; type = ( ServerRequest :: Request ) tmp ; switch ( type ) { case ServerRequest :: Acknowledge : { return boost :: shared_ptr < AcknowledgementRequest > ( new AcknowledgementRequest ( ) ) ; break ; } case ServerRequest :: ServiceData : { boost :: shared_ptr < ServiceDataRequest > s ( new ServiceDataRequest ) ; quint16 num ; in >> ( quint16 & ) num ; for ( int i = 0 ; i < num ; ++ i ) { QString dtype ; QString version ; in >> dtype >> version ; s -> request ( dtype , version ) ; } return s ; } case ServerRequest :: StreamData : { boost :: shared_ptr < StreamDataRequest > s ( new StreamDataRequest ) ; quint16 num ; in >> num ; for ( int i = 0 ; i < num ; ++ i ) { QSet < QString > serviceData ; QSet < QString > streamData ; in >> serviceData ; in >> streamData ; DataSpec dr ; dr . addServiceData ( serviceData ) ; dr . addStreamData ( streamData ) ; s -> addDataOption ( dr ) ; } return s ; } case ServerRequest :: DataSupport : { boost :: shared_ptr < DataSupportRequest > s ( new DataSupportRequest ) ; return s ; } default : break ; } return boost :: shared_ptr < ServerRequest > ( new ServerRequest ( ServerRequest :: Error , " " ) ) ; }
@details
 Creates a server request object based on the request received from the
 PelicanServerClient using the PelicanClientProtocol
@details Creates a server request object based on the request received from the PelicanServerClient using the PelicanClientProtocol
// If there are not enough bytes in the socket to hold the request type // return a error (bad) request. // Read the request type and return an appropriate server request object. /// \todo really good variable name!? /// \todo really good variable name!?