improve debugging macro
[project/netifd.git] / netifd.h
1 #ifndef __NETIFD_H
2 #define __NETIFD_H
3
4 #include <sys/socket.h>
5 #include <net/if.h>
6
7 #include <stdbool.h>
8 #include <stdio.h>
9
10 #include <libubox/uloop.h>
11
12 #include <libubus.h>
13
14 #include "utils.h"
15
16 extern unsigned int debug_mask;
17
18 enum {
19         DEBUG_SYSTEM    = 0,
20         DEBUG_DEVICE    = 1,
21         DEBUG_INTERFACE = 2,
22 };
23
24 #ifdef DEBUG
25 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
26 #define D(level, format, ...) do { \
27                 if (debug_mask & (1 << (DEBUG_ ## level))) \
28                                 DPRINTF(format, ##__VA_ARGS__); \
29         } while (0)
30 #else
31 #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
32 #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
33 #endif
34
35 static inline void no_debug(int level, const char *fmt, ...)
36 {
37 }
38
39 struct device;
40 struct interface;
41
42 extern const char *main_path;
43 void netifd_restart(void);
44 void netifd_reload(void);
45
46 #endif