int main (int argc, const char **argv)
{
    setbuf (stdout, NULL);
    try
    {
        CommonCommandLineParser     cmdLine (argc, argv);
        // Initialize the MAMA API
        mamaBridge bridge = cmdLine.getBridge();
        Mama::open ();

        const vector<const char*>&  symbolList    = cmdLine.getSymbolList ();
        MamaSource*                 source        = cmdLine.getSource();
        MamaQueueGroup              queues (cmdLine.getNumThreads(), bridge);
        DictRequester               dictRequester (bridge);
        bool                        processEntries = true;

        // We might as well enforce strict checking of order book updates
        // (at the expense of some performance).
        MamdaOrderBook::setStrictChecking (true);

        signal (SIGINT, finish);         /* arrange interrupts to terminate */
        bool useColor = !cmdLine.getOptBool ('b');  /* check for blk & white */
        start (useColor);

        // Get and initialize the dictionary
        dictRequester.requestDictionary     (cmdLine.getDictSource());
        MamdaCommonFields::setDictionary    (*dictRequester.getDictionary ());
        MamdaOrderBookFields::setDictionary (*dictRequester.getDictionary ());

        const char* symbolMapFile = cmdLine.getSymbolMapFile ();
        if (symbolMapFile)
        {
            MamaSymbolMapFile* aMap = new MamaSymbolMapFile;
            if (MAMA_STATUS_OK == aMap->load (symbolMapFile))
            {
                source->getTransport()->setSymbolMap (aMap);
            }
        }

        int subscCount = 0;

        for (vector<const char*>::const_iterator i = symbolList.begin ();
             i != symbolList.end ();
             ++i)
        {
            const char* symbol = *i;
            MamdaSubscription*      aSubscription = new MamdaSubscription;
            MamdaOrderBookListener* aBookListener = new MamdaOrderBookListener;
            BookViewer* aViewer = 
                new BookViewer (*aBookListener->getOrderBook());

            aBookListener->setProcessEntries  (true);
            aBookListener->addHandler         (aViewer);
            aSubscription->addMsgListener     (aBookListener);
            aSubscription->addQualityListener (aViewer);
            aSubscription->addErrorListener   (aViewer);
            aSubscription->setType            (MAMA_SUBSC_TYPE_BOOK);
            aSubscription->setMdDataType      (MAMA_MD_DATA_TYPE_ORDER_BOOK);
            aSubscription->create             (queues.getNextQueue (),
                                               source,
                                               symbol);

            aViewer->setShowEntries (false);

            (new MamaIo ())->create (queues.getNextQueue (),
                                aViewer,
                                0,  /* stdin */
                                MAMA_IO_READ);
        }

        Mama::start (bridge);
    }
    catch (MamaStatus &e)
    {
        /*
           This exception can be thrown from Mama::start ().
           Mama::createTransport (transportName) and from
           MamdaSubscription constructor when entitlements is enabled.
        */
        cerr << "MamaStatus exception in main (): " << e.toString () << endl;
        exit (1);
    }
    catch (std::exception &ex)
    {
        cerr << "Exception in main (): " << ex.what () << endl;
        exit (1);
    }
    catch (...)
    {
        cerr << "Unknown Exception in main ()." << endl;
        exit (1);
    }

    return 1;
}
Esempio n. 2
0
int main (int argc, const char **argv)
{
    setbuf (stdout, NULL);
    try
    {
        // Process some command line arguments:
        CommonCommandLineParser     cmdLine (argc, argv);
        // Initialise the MAMA API
        mamaBridge bridge = cmdLine.getBridge();
        Mama::open ();

        const vector<const char*>& symbolList = cmdLine.getSymbolList ();
        MamaSource*                source     = cmdLine.getSource();
        MamaQueueGroup   queues (cmdLine.getNumThreads(), bridge);

        DictRequester    dictRequester (bridge);
        dictRequester.requestDictionary (cmdLine.getDictSource());
        MamdaCommonFields::setDictionary (*dictRequester.getDictionary());
        MamdaSecStatusFields::setDictionary (*dictRequester.getDictionary());

        const char* symbolMapFile = cmdLine.getSymbolMapFile ();
        if (symbolMapFile)
        {
            MamaSymbolMapFile* aMap = new MamaSymbolMapFile;
            if (MAMA_STATUS_OK == aMap->load (symbolMapFile))
            {
                source->getTransport()->setSymbolMap (aMap);
            }
        }

        for (vector<const char*>::const_iterator i = symbolList.begin ();
            i != symbolList.end ();
            ++i)
        {
            const char* symbol = *i;
            MamdaSubscription*  aSubscription  = new MamdaSubscription;
            MamdaSecStatusListener* aSecStatusListener = 
                new MamdaSecStatusListener;
            SecStatusTicker*    aTicker = new SecStatusTicker;

            aSecStatusListener->addHandler (aTicker);
            aSubscription->addMsgListener (aSecStatusListener);
            aSubscription->create (queues.getNextQueue(), source, symbol);
        }
        Mama::start (bridge);
    }
    catch (MamaStatus &e)
    {
        
        // This exception can be thrown from Mama.open (),
        // Mama::createTransport (transportName) and from 
        // MamdaSubscription constructor when entitlements is enabled.
        cerr << "MamaStatus exception in main (): " << e.toString () << endl;
        exit (1);
    }
    catch (exception &ex)
    {
        cerr << "Exception in main (): " << ex.what () << endl;
        exit (1);
    }
    catch (...)
    {
        cerr << "Unknown Exception in main ()." << endl;
        exit (1);
    }

    return 1;
}