• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/omcproxy/src/omcproxy.h

  1 /*
  2  * Author: Steven Barth <steven at midlink.org>
  3  *
  4  * Copyright 2015 Deutsche Telekom AG
  5  *
  6  * Licensed under the Apache License, Version 2.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at
  9  *
 10  *  http://www.apache.org/licenses/LICENSE-2.0
 11  *
 12  * Unless required by applicable law or agreed to in writing, software
 13  * distributed under the License is distributed on an "AS IS" BASIS,
 14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing permissions and
 16  * limitations under the License.
 17  *
 18  */
 19 
 20 #ifndef OMGPROXY_H_
 21 #define OMGPROXY_H_
 22 
 23 #define OMGPROXY_DEFAULT_L_LEVEL 7
 24 
 25 #ifndef L_LEVEL
 26 #define L_LEVEL OMGPROXY_DEFAULT_L_LEVEL
 27 #endif /* !L_LEVEL */
 28 
 29 #ifndef L_PREFIX
 30 #define L_PREFIX ""
 31 #endif /* !L_PREFIX */
 32 
 33 #ifdef __APPLE__
 34 
 35 #define __APPLE_USE_RFC_3542
 36 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
 37 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
 38 
 39 #include <sys/queue.h>
 40 #ifdef LIST_HEAD
 41 #undef LIST_HEAD
 42 #endif /* LIST_HEAD */
 43 
 44 #endif /* __APPLE__ */
 45 
 46 #include <stddef.h>
 47 #include <stdint.h>
 48 #include <time.h>
 49 #include <syslog.h>
 50 #include <sys/types.h>
 51 #include <libubox/utils.h>
 52 
 53 #define STR_EXPAND(tok) #tok
 54 #define STR(tok) STR_EXPAND(tok)
 55 
 56 typedef int64_t omgp_time_t;
 57 #define OMGP_TIME_MAX INT64_MAX
 58 #define OMGP_TIME_PER_SECOND INT64_C(1000)
 59 
 60 static inline omgp_time_t omgp_time(void) {
 61         struct timespec ts;
 62         clock_gettime(CLOCK_MONOTONIC, &ts);
 63         return ((omgp_time_t)ts.tv_sec * OMGP_TIME_PER_SECOND) +
 64                         ((omgp_time_t)ts.tv_nsec / (1000000000 / OMGP_TIME_PER_SECOND));
 65 }
 66 
 67 extern int log_level;
 68 
 69 // Logging macros
 70 
 71 #define L_INTERNAL(level, ...)                  \
 72 do {                                            \
 73   if (log_level >= level)                       \
 74     syslog(level, L_PREFIX __VA_ARGS__);        \
 75  } while(0)
 76 
 77 #if L_LEVEL >= LOG_ERR
 78 #define L_ERR(...) L_INTERNAL(LOG_ERR, __VA_ARGS__)
 79 #else
 80 #define L_ERR(...) do {} while(0)
 81 #endif
 82 
 83 #if L_LEVEL >= LOG_WARNING
 84 #define L_WARN(...) L_INTERNAL(LOG_WARNING, __VA_ARGS__)
 85 #else
 86 #define L_WARN(...) do {} while(0)
 87 #endif
 88 
 89 #if L_LEVEL >= LOG_NOTICE
 90 #define L_NOTICE(...) L_INTERNAL(LOG_NOTICE, __VA_ARGS__)
 91 #else
 92 #define L_NOTICE(...) do {} while(0)
 93 #endif
 94 
 95 #if L_LEVEL >= LOG_INFO
 96 #define L_INFO(...) L_INTERNAL(LOG_INFO, __VA_ARGS__)
 97 #else
 98 #define L_INFO(...) do {} while(0)
 99 #endif
100 
101 #if L_LEVEL >= LOG_DEBUG
102 #define L_DEBUG(...) L_INTERNAL(LOG_DEBUG, __VA_ARGS__)
103 #else
104 #define L_DEBUG(...) do {} while(0)
105 #endif
106 
107 
108 // Some C99 compatibility
109 #ifndef typeof
110 #define typeof __typeof
111 #endif
112 
113 #ifndef container_of
114 #define container_of(ptr, type, member) (           \
115     (type *)( (char *)ptr - offsetof(type,member) ))
116 #endif
117 
118 #ifndef __unused
119 #define __unused __attribute__((unused))
120 #endif
121 
122 #endif /* PIMBD_H_ */
123 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt