[Openais] [PATCH 5/9] logsys: add macros to pack/unpack rec_ident
Steven Dake
sdake at redhat.com
Wed Jun 17 08:48:03 PDT 2009
All defines operations should always be in () for example:
#define LOGSYS_LEVEL_END 3 should be
#define LOGSYS_LEVEL_END (3)
While in this particular case it isn't necessary it is in any time an
operation is done and is good practice to follow.
The bitmask generation also looks complicated (I prefer hardcoded
defines, easier to read) but its documented above so it doesn't matter.
If you could fix this little nit looks good for merge
Regards
-steve
On Wed, 2009-06-17 at 12:53 +0200, Fabio M. Di Nitto wrote:
> rec_ident should contain 3 info: log level, subsystem id and
> message type.
>
> Signed-off-by: Fabio M. Di Nitto <fdinitto at redhat.com>
> ---
> :100644 100644 ea53cac... 5629879... M include/corosync/engine/logsys.h
> include/corosync/engine/logsys.h | 71 ++++++++++++++++++++++++++++++++------
> 1 files changed, 60 insertions(+), 11 deletions(-)
>
> diff --git a/include/corosync/engine/logsys.h b/include/corosync/engine/logsys.h
> index ea53cac..5629879 100644
> --- a/include/corosync/engine/logsys.h
> +++ b/include/corosync/engine/logsys.h
> @@ -77,17 +77,20 @@ extern "C" {
> * RECID_LOG indicates a message that should be sent to log. Anything else
> * is stored only in the flight recorder.
> */
> -#define LOGSYS_RECID_LOG UINT_MAX - 1
> -#define LOGSYS_RECID_ENTER UINT_MAX - 2
> -#define LOGSYS_RECID_LEAVE UINT_MAX - 3
> -#define LOGSYS_RECID_TRACE1 UINT_MAX - 4
> -#define LOGSYS_RECID_TRACE2 UINT_MAX - 5
> -#define LOGSYS_RECID_TRACE3 UINT_MAX - 6
> -#define LOGSYS_RECID_TRACE4 UINT_MAX - 7
> -#define LOGSYS_RECID_TRACE5 UINT_MAX - 8
> -#define LOGSYS_RECID_TRACE6 UINT_MAX - 9
> -#define LOGSYS_RECID_TRACE7 UINT_MAX - 10
> -#define LOGSYS_RECID_TRACE8 UINT_MAX - 11
> +
> +#define LOGSYS_RECID_MAX LOGSYS_RECID_RECID_MASK
> +
> +#define LOGSYS_RECID_LOG LOGSYS_RECID_MAX - 1
> +#define LOGSYS_RECID_ENTER LOGSYS_RECID_MAX - 2
> +#define LOGSYS_RECID_LEAVE LOGSYS_RECID_MAX - 3
> +#define LOGSYS_RECID_TRACE1 LOGSYS_RECID_MAX - 4
> +#define LOGSYS_RECID_TRACE2 LOGSYS_RECID_MAX - 5
> +#define LOGSYS_RECID_TRACE3 LOGSYS_RECID_MAX - 6
> +#define LOGSYS_RECID_TRACE4 LOGSYS_RECID_MAX - 7
> +#define LOGSYS_RECID_TRACE5 LOGSYS_RECID_MAX - 8
> +#define LOGSYS_RECID_TRACE6 LOGSYS_RECID_MAX - 9
> +#define LOGSYS_RECID_TRACE7 LOGSYS_RECID_MAX - 10
> +#define LOGSYS_RECID_TRACE8 LOGSYS_RECID_MAX - 11
>
>
> /*
> @@ -104,6 +107,52 @@ extern "C" {
> #define LOGSYS_MAX_SUBSYS_COUNT 64
> #define LOGSYS_MAX_SUBSYS_NAMELEN 64
>
> +/*
> + * rec_ident explained:
> + *
> + * rec_ident is an unsigned int and carries bitfields information
> + * on subsys_id, log priority (level) and type of message (RECID).
> + *
> + * level values are imported from syslog.h.
> + * At the time of writing it's a 3 bits value (0 to 7).
> + *
> + * subsys_id is any value between 0 and 64 (LOGSYS_MAX_SUBSYS_COUNT)
> + *
> + * RECID identifies the type of message. A set of predefined values
> + * are available via logsys, but other custom values can be defined
> + * by users.
> + *
> + * ----
> + * bitfields:
> + *
> + * 0 - 2 level
> + * 3 - 9 subsysid
> + * 10 - n RECID
> + */
> +
> +#define LOGSYS_LEVEL_END 3
> +#define LOGSYS_SUBSYSID_END (LOGSYS_LEVEL_END + 7)
> +
> +#define LOGSYS_RECID_LEVEL_MASK LOG_PRIMASK
> +#define LOGSYS_RECID_SUBSYSID_MASK ((2 << (LOGSYS_SUBSYSID_END - 1)) - \
> + (LOG_PRIMASK + 1))
> +#define LOGSYS_RECID_RECID_MASK (UINT_MAX - \
> + (LOGSYS_RECID_SUBSYSID_MASK + LOG_PRIMASK))
> +
> +#define LOGSYS_ENCODE_RECID(level,subsysid,recid) \
> + (((recid) << LOGSYS_SUBSYSID_END) | \
> + ((subsysid) << LOGSYS_LEVEL_END) | \
> + (level))
> +
> +#define LOGSYS_DECODE_LEVEL(rec_ident) \
> + ((rec_ident) & LOGSYS_RECID_LEVEL_MASK)
> +
> +#define LOGSYS_DECODE_SUBSYSID(rec_ident) \
> + (((rec_ident) & LOGSYS_RECID_SUBSYSID_MASK) >> LOGSYS_LEVEL_END)
> +
> +#define LOGSYS_DECODE_RECID(rec_ident) \
> + (((rec_ident) & LOGSYS_RECID_RECID_MASK) >> LOGSYS_SUBSYSID_END)
> +
> #ifndef LOGSYS_UTILS_ONLY
>
> extern int _logsys_system_setup(
More information about the Openais
mailing list