95a8008915b94ab7b3d47e1cfa9fe5afed412392
[vpp.git] / src / vpp-api / vapi / vapi_dbg.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef __included_vapi_debug_h__
19 #define __included_vapi_debug_h__
20
21 /* controls debug prints */
22 #define VAPI_DEBUG (0)
23 #define VAPI_DEBUG_CONNECT (0)
24 #define VAPI_DEBUG_ALLOC (0)
25
26 #if VAPI_DEBUG
27 #include <stdio.h>
28 #define VAPI_DEBUG_FILE_DEF           \
29   static const char *__file = NULL;   \
30   {                                   \
31     __file = strrchr (__FILE__, '/'); \
32     if (__file)                       \
33       {                               \
34         ++__file;                     \
35       }                               \
36     else                              \
37       {                               \
38         __file = __FILE__;            \
39       }                               \
40   }
41
42 #define VAPI_DBG(fmt, ...)                                       \
43   do                                                             \
44     {                                                            \
45       VAPI_DEBUG_FILE_DEF                                        \
46       printf ("DBG:%s:%d:%s():" fmt, __file, __LINE__, __func__, \
47               ##__VA_ARGS__);                                    \
48       printf ("\n");                                             \
49       fflush (stdout);                                           \
50     }                                                            \
51   while (0);
52
53 #define VAPI_ERR(fmt, ...)                                       \
54   do                                                             \
55     {                                                            \
56       VAPI_DEBUG_FILE_DEF                                        \
57       printf ("ERR:%s:%d:%s():" fmt, __file, __LINE__, __func__, \
58               ##__VA_ARGS__);                                    \
59       printf ("\n");                                             \
60       fflush (stdout);                                           \
61     }                                                            \
62   while (0);
63 #else
64 #define VAPI_DBG(...)
65 #define VAPI_ERR(...)
66 #endif
67
68 #endif /* __included_vapi_debug_h__ */
69
70 /*
71  * fd.io coding-style-patch-verification: ON
72  *
73  * Local Variables:
74  * eval: (c-set-style "gnu")
75  * End:
76  */