X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Fhook.h;h=197184a6d4ce9333be659c31ecb5a5408b0e0add;hb=13059e8417b063b84a34c5e17f4b91025fa81bcd;hp=803304c0e3606fa99bb19b272377bc7623a67379;hpb=d8f124de0295aea546b6debf5945bfeea2bbeb2a;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/hook.h b/ltt/branches/poly/lttv/lttv/hook.h index 803304c0..197184a6 100644 --- a/ltt/branches/poly/lttv/lttv/hook.h +++ b/ltt/branches/poly/lttv/lttv/hook.h @@ -1,6 +1,8 @@ /* This file is part of the Linux Trace Toolkit viewer * Copyright (C) 2003-2004 Michel Dagenais * + * 25/05/2004 Mathieu Desnoyers : Hook priorities + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as * published by the Free Software Foundation; @@ -20,6 +22,7 @@ #define HOOK_H #include +#include /* A hook is a function to call with the supplied hook data, and with call site specific data (e.g., hooks for events are called with a @@ -32,6 +35,18 @@ typedef gboolean (*LttvHook)(void *hook_data, void *call_data); typedef GArray LttvHooks; +/* A priority associated with each hook, from -19 (high prio) to 20 (low prio) + * 0 being the default priority. + * + * Priority ordering is done in the lttv_hooks_add and lttv_hooks_add_list + * functions. Hook removal does not change list order. + */ + +#define LTTV_PRIO_DEFAULT 50 +#define LTTV_PRIO_HIGH 0 +#define LTTV_PRIO_LOW 99 + +typedef gint LttvHookPrio; /* Create and destroy a list of hooks */ @@ -42,12 +57,12 @@ void lttv_hooks_destroy(LttvHooks *h); /* Add a hook and its hook data to the list */ -void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data); +void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data, LttvHookPrio p); /* Add a list of hooks to the list h */ -void lttv_hooks_add_list(LttvHooks *h, LttvHooks *list); +void lttv_hooks_add_list(LttvHooks *h, const LttvHooks *list); /* Remove a hook from the list. Return the hook data. */ @@ -62,7 +77,7 @@ void lttv_hooks_remove_data(LttvHooks *h, LttvHook f, void *hook_data); /* Remove a list of hooks from the hooks list in h. */ -void lttv_hooks_remove_data_list(LttvHooks *h, LttvHook *list); +void lttv_hooks_remove_list(LttvHooks *h, LttvHooks *list); /* Return the number of hooks in the list */ @@ -70,33 +85,52 @@ void lttv_hooks_remove_data_list(LttvHooks *h, LttvHook *list); unsigned lttv_hooks_number(LttvHooks *h); -/* Return the hook at the specified position in the list */ +/* Return the hook at the specified position in the list. + * *f and *hook_data are NULL if no hook exists at that position. */ -void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data); +void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data, + LttvHookPrio *p); /* Remove the specified hook. The position of the following hooks may change */ +/* The hook is removed from the list event if its ref_count is higher than 1 */ void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i); /* Call all the hooks in the list, each with its hook data, - with the specified call data. Return TRUE if one hook returned TRUE. */ + with the specified call data, in priority order. Return TRUE if one hook + returned TRUE. */ gboolean lttv_hooks_call(LttvHooks *h, void *call_data); -/* Call the hooks in the list until one returns true, in which case TRUE is - returned. */ +/* Call the hooks in the list in priority order until one returns true, + * in which case TRUE is returned. */ gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data); +/* Call hooks from two lists in priority order. If priority is the same, + * hooks from h1 are called first. */ + +gboolean lttv_hooks_call_merge(LttvHooks *h1, void *call_data1, + LttvHooks *h2, void *call_data2); + +gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1, + LttvHooks *h2, void *call_data2); + /* Sometimes different hooks need to be called based on the case. The case is represented by an unsigned integer id */ -typedef GPtrArray LttvHooksById; +typedef struct _LttvHooksById { + GPtrArray *index; + GArray *array; +} LttvHooksById; +/* macro to calculate the hook ID of a facility/event pair. */ +#define GET_HOOK_ID(fac_id, ev_id) \ + ( (guint)fac_id | ((guint)ev_id << FACILITIES_BITS) ) /* Create and destroy a hooks by id list */ @@ -117,7 +151,14 @@ unsigned lttv_hooks_by_id_max_id(LttvHooksById *h); /* Get the list of hooks for an id, NULL if none exists */ -LttvHooks *lttv_hooks_by_id_get(LttvHooksById *h, unsigned id); +static inline LttvHooks *lttv_hooks_by_id_get(LttvHooksById *h, unsigned id) +{ + LttvHooks *ret; + if(likely(id < h->index->len)) ret = h->index->pdata[id]; + else ret = NULL; + + return ret; +} /* Remove the list of hooks associated with an id */