Ejemplo n.º 1
0
static void subscribeToSymbols ()
{
    int i       = 0;

    mamaMsgCallbacks callbacks;
    memset(&callbacks, 0, sizeof(callbacks));
    callbacks.onCreate  = subscriptionOnCreate;
    callbacks.onError   = subscriptionOnError;
    callbacks.onMsg     = subscriptionOnMsg;
    callbacks.onQuality = NULL;
    callbacks.onGap     = NULL;
    callbacks.onRecapRequest = NULL;

    gSubscriptionList = (pubCache*)calloc (gNumSymbols,
                                           sizeof (pubCache));


    for (i = 0; i < gNumSymbols; i++)
    {
        mamaSubscription_allocate (&gSubscriptionList[i].sub);
        mamaSubscription_create (gSubscriptionList[i].sub,
                                 gSubDefaultQueue,
                                 &callbacks,
                                 gSubscriptionSource,
                                 gSymbolList[i],
                                 (void*)i);

        gSubscriptionList[i].symbol = gSymbolList[i];
        mamaMsg_create(&gSubscriptionList[i].cachedMsg);
    }
}
Ejemplo n.º 2
0
static mama_status subscribeToSymbols (mamaCaptureConfig subCapture,
                                       mamaCaptureList captureList)
{
    mamaCapture * capture = (mamaCapture*)subCapture;
    mamaCaptureSourceList * sourceList
        = (mamaCaptureSourceList*)captureList;

    int counter = 0;
    int howMany = 0;

    mama_status status;

    mamaMsgCallbacks callbacks;
    if (capture == NULL) return MAMA_STATUS_NULL_ARG;
    if (sourceList == NULL) return MAMA_STATUS_NULL_ARG;

    callbacks.onCreate          = listenerCreateCb;
    callbacks.onError           = listenerErrorCb;
    callbacks.onMsg             = listenerMsgCb;
    callbacks.onQuality         = NULL;
    callbacks.onGap             = NULL;
    callbacks.onRecapRequest    = NULL;

    printf ("Subscribe to [%d] Symbols \n", gCounter);

    for (counter = 0; counter < gCounter; counter++)
    {
        mamaSubscription_allocate (&sourceList[counter].mySubscription);

        mamaSubscription_setTimeout (sourceList[counter].mySubscription,
                                     capture->myTimeout);
        /* Create a regular market data subscription.  */
        mamaSubscription_setRequiresInitial (sourceList[counter].mySubscription,
                                             capture->myRequireInitial);

        mamaSubscription_setDebugLevel (sourceList[counter].mySubscription,
                                        capture->mySubscLogLevel);

        status =
           mamaSubscription_create (sourceList[counter].mySubscription,
                                    capture->myDefaultQueue,
                                    &callbacks,
                                    sourceList[counter].mySource,
                                    sourceList[counter].mySymbol,
                                    (void*)&sourceList[counter]);

       if (status != MAMA_STATUS_OK)
       {
           mama_log (MAMA_LOG_LEVEL_NORMAL,
                     "Error creating subscription for %s. STATUS: %d\n",
                      sourceList[counter].mySymbol, status);
           continue;
       }
       mama_log (MAMA_LOG_LEVEL_FINE, "Listening on %s.", sourceList[counter].mySymbol);

       if (++howMany % 1000 == 0)
       {
           mama_logStdout (MAMA_LOG_LEVEL_NORMAL,
                           "Subscribed to %d subjects.\n",
                           howMany);
       }
    }
    return MAMA_STATUS_OK;
}