09/11/15 15:00:27 (6 years ago)
Shane Alcock <salcock@…>
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

Reworked callback API and removed old per_msg and reporter functions

Updated tracertstats to use the new callback API.

Extended the callback approach to the reporter thread as well as the per
packet threads.

Added libtrace_callback_set_t structure, which is used to register the
user callback functions.

Added callback functionality for MESSAGE_RESULT (needed now that reporter
threads also do callbacks) and MESSAGE_USER (for user-defined messages). The
MESSAGE_USER callback is essentially the same as the old per_msg function

Updated combiners to use send_message to pass results to the reporter thread.
send_message itself is now no longer static, so that combiners can use it.

Disabled building of tracestats_parallel as it was using the older version
of the callback API. Will update in a future commit.

1 edited


  • lib/libtrace_parallel.h

    r3dd5acc rf625817  
    460460 * @param libtrace The input trace to start
    461461 * @param global_blob Global data related to this trace accessible using trace_get_global()
    462  * @param per_msg A user supplied function called when a message is ready
    463  * @param reporter A user supplied function called when a result is ready.
     462 * @param per_packet_cbs A set of user supplied functions to be called in response to events being observed by the per_pkt threads.
     463 * @param reporter_cbs A set of user supplied functions to be called in response to events / results being seen by the reporter thread.
    464464 * Optional if NULL the reporter thread will not be started.
    465465 * @return 0 on success, otherwise -1 to indicate an error has occurred
    467467 * This can also be used to restart an existing parallel trace,
    468468 * that has previously been paused using trace_ppause().
    469  * In this case global_blob,per_msg and reporter will only be updated
    470  * if they are non-null. Otherwise their previous values will be maintained.
     469 * In this case global_blob, per_packet_cbs and reporter_cbs will only be
     470 * updated if they are non-null. Otherwise their previous values will be
     471 * maintained.
    471472 *
    472473 */
    473474DLLEXPORT int trace_pstart(libtrace_t *libtrace, void* global_blob,
    474                            fn_cb_msg per_msg, fn_reporter reporter);
     475                           libtrace_callback_set_t *per_packet_cbs,
     476                           libtrace_callback_set_t *reporter_cbs);
    539541                                           libtrace_packet_t *packet);
     544 * Callback for handling a result message. Should only be required by the
     545 * reporter thread.
     546 *
     547 * @param libtrace The parallel trace
     548 * @param sender The thread that generated this result
     549 * @param global The global storage
     550 * @param tls The thread local storage
     551 * @param result The result associated with the message
     552 *
     553 */
     554typedef void (*fn_cb_result)(libtrace_t *libtrace, libtrace_thread_t *sender,
     555                void *global, void *tls, libtrace_result_t *result);
     559 * Callback for handling any user-defined message types. This will handle
     560 * any messages with a type >= MESSAGE_USER.
     561 *
     562 * @param libtrace The parallel trace
     563 * @param t The thread
     564 * @param global The global storage
     565 * @param tls The thread local storage
     566 * @param mesg The code identifying the message type
     567 * @param data The data associated with the message
     568 *
     569 */
     570typedef void (*fn_cb_usermessage) (libtrace_t *libtrace, libtrace_thread_t *t,
     571                void *global, void *tls, int mesg, libtrace_generic_t data);
    541573/** Registers a built-in message with a handler.
    542574 * Note we do not include the sending thread as an argument to the reporter.
    548580 */
    550 DLLEXPORT int trace_cb_starting(libtrace_t *libtrace, fn_cb_starting handler);
    551 DLLEXPORT int trace_cb_stopping(libtrace_t *libtrace, fn_cb_dataless handler);
    552 DLLEXPORT int trace_cb_resuming(libtrace_t *libtrace, fn_cb_dataless handler);
    553 DLLEXPORT int trace_cb_pausing(libtrace_t *libtrace, fn_cb_dataless handler);
    554 DLLEXPORT int trace_cb_packet(libtrace_t *libtrace, fn_cb_packet handler);
    555 DLLEXPORT int trace_cb_first_packet(libtrace_t *libtrace, fn_cb_first_packet handler);
    556 DLLEXPORT int trace_cb_tick_count(libtrace_t *libtrace, fn_cb_tick handler);
    557 DLLEXPORT int trace_cb_tick_interval(libtrace_t *libtrace, fn_cb_tick handler);
     582DLLEXPORT int trace_set_starting_cb(libtrace_callback_set_t *cbset,
     583                fn_cb_starting handler);
     585DLLEXPORT int trace_set_stopping_cb(libtrace_callback_set_t *cbset,
     586                fn_cb_dataless handler);
     588DLLEXPORT int trace_set_resuming_cb(libtrace_callback_set_t *cbset,
     589                fn_cb_dataless handler);
     591DLLEXPORT int trace_set_pausing_cb(libtrace_callback_set_t *cbset,
     592                fn_cb_dataless handler);
     594DLLEXPORT int trace_set_packet_cb(libtrace_callback_set_t *cbset,
     595                fn_cb_packet handler);
     597DLLEXPORT int trace_set_first_packet_cb(libtrace_callback_set_t *cbset,
     598                fn_cb_first_packet handler);
     600DLLEXPORT int trace_set_result_cb(libtrace_callback_set_t *cbset,
     601                fn_cb_result handler);
     603DLLEXPORT int trace_set_tick_count_cb(libtrace_callback_set_t *cbset,
     604                fn_cb_tick handler);
     606DLLEXPORT int trace_set_tick_interval_cb(libtrace_callback_set_t *cbset,
     607                fn_cb_tick handler);
     609DLLEXPORT int trace_set_user_message_cb(libtrace_callback_set_t *cbset,
     610                fn_cb_usermessage handler);
    559612/** Pauses a trace previously started with trace_pstart()
Note: See TracChangeset for help on using the changeset viewer.