Ignore:
Timestamp:
03/31/15 16:02:53 (6 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
4007dbb
Parents:
58bfabf
Message:

Add a quick mockup of shanes interface using functions for each message

I.e. set a function for MESSAGE_PACKET etc. which only receives packets.

Ported tracestats_parallel to use this interface.

Note it is not yet complete, however should give a feel of how it will work.
And provide a good work around to the thread issues on older machines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace_parallel.c

    rd3849c7 r76291d1  
    377377                t->accepted_packets++;
    378378                libtrace_generic_t data = {.pkt = *packet};
    379                 *packet = (*trace->per_pkt)(trace, t, MESSAGE_PACKET, data, t);
     379                if (trace->callbacks.message_packet)
     380                        *packet = (*trace->callbacks.message_packet)(trace, t, data, trace->global_blob, t->user_data);
     381                else
     382                        *packet = (*trace->per_pkt)(trace, t, MESSAGE_PACKET, data, t);
    380383                trace_fin_packet(*packet);
    381384        } else {
     
    535538
    536539        /* Let the per_packet function know we have started */
    537         (*trace->per_pkt)(trace, t, MESSAGE_STARTING, (libtrace_generic_t){0}, t);
    538         (*trace->per_pkt)(trace, t, MESSAGE_RESUMING, (libtrace_generic_t){0}, t);
     540        if (trace->callbacks.message_starting)
     541                (*trace->callbacks.message_starting)(trace, t, (libtrace_generic_t){0}, trace->global_blob, t->user_data);
     542        else
     543                (*trace->per_pkt)(trace, t, MESSAGE_STARTING, (libtrace_generic_t){0}, t);
     544
     545        if (trace->callbacks.message_resuming)
     546                (*trace->callbacks.message_resuming)(trace, t, (libtrace_generic_t){0}, trace->global_blob, t->user_data);
     547        else
     548                (*trace->per_pkt)(trace, t, MESSAGE_RESUMING, (libtrace_generic_t){0}, t);
    539549
    540550        for (;;) {
     
    619629
    620630        // Let the per_packet function know we have stopped
    621         (*trace->per_pkt)(trace, t, MESSAGE_PAUSING, (libtrace_generic_t){0}, t);
    622         (*trace->per_pkt)(trace, t, MESSAGE_STOPPING, (libtrace_generic_t){0}, t);
     631        if (trace->callbacks.message_pausing)
     632                (*trace->callbacks.message_pausing)(trace, t, (libtrace_generic_t){0}, trace->global_blob, t->user_data);
     633        else
     634                (*trace->per_pkt)(trace, t, MESSAGE_PAUSING, (libtrace_generic_t){0}, t);
     635        if (trace->callbacks.message_stopping)
     636                (*trace->callbacks.message_stopping)(trace, t, (libtrace_generic_t){0}, trace->global_blob, t->user_data);
     637        else
     638                (*trace->per_pkt)(trace, t, MESSAGE_STOPPING, (libtrace_generic_t){0}, t);
     639
    623640
    624641        // Free any remaining packets
     
    17191736        return ret;
    17201737}
     1738
     1739DLLEXPORT int trace_set_handler(libtrace_t *libtrace, enum libtrace_messages message, fn_handler handler) {
     1740        switch (message) {
     1741        case MESSAGE_STARTING:
     1742                libtrace->callbacks.message_starting = handler;
     1743                return 0;
     1744        case MESSAGE_STOPPING:
     1745                libtrace->callbacks.message_stopping = handler;
     1746                return 0;
     1747        case MESSAGE_RESUMING:
     1748                libtrace->callbacks.message_resuming = handler;
     1749                return 0;
     1750        case MESSAGE_PAUSING:
     1751                libtrace->callbacks.message_pausing = handler;
     1752                return 0;
     1753        case MESSAGE_PACKET:
     1754                libtrace->callbacks.message_packet = handler;
     1755                return 0;
     1756        default:
     1757                return -1;
     1758        }
     1759        return -1;
     1760}
     1761
    17211762
    17221763/*
Note: See TracChangeset for help on using the changeset viewer.