EMA C++ Developers Guide : 4 Consumer Classes : 4.1 OmmConsumer Class : 4.1.8 Example: Working with Tunnel Streams
 
4.1.8 Example: Working with Tunnel Streams
The following example illustrates the use of a parent handle (as returned by OmmConsumer::registerClient(TunnelStreamRequest,…)) to open a substream from the OmmConsumerClient::onStatusMsg() callback.
 
 
void onStatusMsg(const StatusMsg& statusMsg, const OmmConsumerEvent& event)
{
    if (event.getHandle() == _tunnelStreamHandle &&
        statusMsg.hasState() &&
        statusMsg.getState().getStreamState() == OmmState::OpenEnum )
    {
        // open substream with parent handle returned when opening tunnel stream below
        _pOmmConsumer->registerClient( ReqMsg().name( "TUNNEL_IBM" ).serviceId( 1 ), *this,
                (void*)1, _tunnelStreamHandle );
    }
}
 
int main()
{
    try {
        AppClient client;
        OmmConsumer consumer( OmmConsumerConfig().username( "user" ) );
        client.setOmmConsumer( consumer );
        CosAuthentication cosAuthentication;
        cosAuthentication.type( CosAuthentication::OmmLoginEnum );
        CosDataIntegrity cosDataIntegrity;
        cosDataIntegrity.type( CosDataIntegrity::ReliableEnum );
        CosFlowControl cosFlowControl;
        cosFlowControl.type( CosFlowControl::BidirectionalEnum ).recvWindowSize( 1200
                ).sendWindowSize( 1200 );
        ClassOfService cos;
        cos.authentication( cosAuthentication ).dataIntegrity( cosDataIntegrity
                ).flowControl( cosFlowControl );
        TunnelStreamRequest tsr;
        tsr.classOfService( cos ).domainType( MMT_SYSTEM ).name( "TUNNEL" ).serviceName(
                "DIRECT_FEED" );
        /* open tunnel stream and save tunnel stream parent handle to be used for opening
        substreams in onStatusMsg() callback above */
        _tunnelStreamHandle = consumer.registerClient( tsr, client );
 
        sleep( 60000 ); // API calls onRefreshMsg(), onUpdateMsg(), or onStatusMsg()
    } catch ( const OmmException& excp ) {
        cout << excp << endl;
    }
}