blob: 0ce916707593b2ad19636cccb4b0aa9488c12d33 [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
Lucas De Marchi88e9c122011-11-23 12:23:46 -02007#include "macro.h"
Lucas De Marchi586fc302011-11-21 14:35:35 -02008#include "libkmod.h"
9
Lucas De Marchif87081b2011-11-23 12:21:29 -020010static __always_inline __printf_format(2, 3) void
Lucas De Marchi586fc302011-11-21 14:35:35 -020011 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
35void 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 Marchi6924e472011-11-22 05:38:28 -020039struct list_node {
40 struct list_node *next, *prev;
41};
42
43struct kmod_list {
44 struct list_node node;
45 void *data;
46};
47
Lucas De Marchif87081b2011-11-23 12:21:29 -020048struct kmod_list *kmod_list_append(struct kmod_list *list, void *data) __must_check;
49struct kmod_list *kmod_list_prepend(struct kmod_list *list, void *data) __must_check;
Lucas De Marchi6924e472011-11-22 05:38:28 -020050struct kmod_list *kmod_list_remove(struct kmod_list *list);
51struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
Lucas De Marchif87081b2011-11-23 12:21:29 -020052 const void *data) __must_check;
Lucas De Marchi6924e472011-11-22 05:38:28 -020053
Lucas De Marchi586fc302011-11-21 14:35:35 -020054#endif