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