Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 1 | #ifndef _LIBKMOD_PRIVATE_H_ |
| 2 | #define _LIBKMOD_PRIVATE_H_ |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <syslog.h> |
| 6 | |
Lucas De Marchi | 88e9c12 | 2011-11-23 12:23:46 -0200 | [diff] [blame^] | 7 | #include "macro.h" |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 8 | #include "libkmod.h" |
| 9 | |
Lucas De Marchi | f87081b | 2011-11-23 12:21:29 -0200 | [diff] [blame] | 10 | static __always_inline __printf_format(2, 3) void |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 11 | kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} |
| 12 | |
| 13 | #define kmod_log_cond(ctx, prio, arg...) \ |
| 14 | do { \ |
| 15 | if (kmod_get_log_priority(ctx) >= prio) \ |
| 16 | kmod_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg);\ |
| 17 | } while (0) |
| 18 | |
| 19 | #ifdef ENABLE_LOGGING |
| 20 | # ifdef ENABLE_DEBUG |
| 21 | # define dbg(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg) |
| 22 | # else |
| 23 | # define dbg(ctx, arg...) kmod_log_null(ctx, ## arg) |
| 24 | # endif |
| 25 | # define info(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg) |
| 26 | # define err(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg) |
| 27 | #else |
| 28 | # define dbg(ctx, arg...) kmod_log_null(ctx, ## arg) |
| 29 | # define info(ctx, arg...) kmod_log_null(ctx, ## arg) |
| 30 | # define err(ctx, arg...) kmod_log_null(ctx, ## arg) |
| 31 | #endif |
| 32 | |
| 33 | #define KMOD_EXPORT __attribute__ ((visibility("default"))) |
| 34 | |
| 35 | void kmod_log(struct kmod_ctx *ctx, |
| 36 | int priority, const char *file, int line, const char *fn, |
| 37 | const char *format, ...) __attribute__((format(printf, 6, 7))); |
| 38 | |
Lucas De Marchi | 6924e47 | 2011-11-22 05:38:28 -0200 | [diff] [blame] | 39 | struct list_node { |
| 40 | struct list_node *next, *prev; |
| 41 | }; |
| 42 | |
| 43 | struct kmod_list { |
| 44 | struct list_node node; |
| 45 | void *data; |
| 46 | }; |
| 47 | |
Lucas De Marchi | f87081b | 2011-11-23 12:21:29 -0200 | [diff] [blame] | 48 | struct kmod_list *kmod_list_append(struct kmod_list *list, void *data) __must_check; |
| 49 | struct kmod_list *kmod_list_prepend(struct kmod_list *list, void *data) __must_check; |
Lucas De Marchi | 6924e47 | 2011-11-22 05:38:28 -0200 | [diff] [blame] | 50 | struct kmod_list *kmod_list_remove(struct kmod_list *list); |
| 51 | struct kmod_list *kmod_list_remove_data(struct kmod_list *list, |
Lucas De Marchi | f87081b | 2011-11-23 12:21:29 -0200 | [diff] [blame] | 52 | const void *data) __must_check; |
Lucas De Marchi | 6924e47 | 2011-11-22 05:38:28 -0200 | [diff] [blame] | 53 | |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 54 | #endif |