mbgtools-lx  4.2.8
mbgddmsg.c
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbgddmsg.c 1.5 2018/11/22 14:12:48 martin TRASH $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Functions called from user space to access Meinberg device drivers.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: mbgddmsg.c $
13  * Revision 1.5 2018/11/22 14:12:48 martin
14  * Support QNX target.
15  * Assume DEBUG_MSG_SLEEP is always defined but evaluates to 'true' or 'false'.
16  * Revision 1.4 2018/09/21 14:46:12 martin
17  * More consistent naming.
18  * Revision 1.3 2018/06/25 11:05:51 martin
19  * Unified kernel driver messages.
20  * Conditionally support DEBUG_MSG_SLEEP.
21  * Added mbg_kdd_snprintf() for Linux and Windows.
22  * mbg_kdd_msg() also takes a log level.
23  * Support log levels on Windows.
24  * Evaluate log level under Linux.
25  * Includes some headers already in mbgddmsg.h.
26  * Revision 1.2 2017/07/05 14:27:43 martin
27  * Distinguish more between Windows and Linux targets.
28  * Revision 1.1 2014/04/09 15:41:33 martin
29  * Initial version.
30  *
31  **************************************************************************/
32 
33 #define _MBGDDMSG
34  #include <mbgddmsg.h>
35 #undef _MBGDDMSG
36 
37 #if defined( MBG_TGT_KERNEL )
38 
39  #if defined( MBG_TGT_WIN32 )
40 
41  extern void KddReportEventA( int lvl, const char *info );
42 
43  #elif defined( MBG_TGT_LINUX )
44 
45  #if DEBUG_MSG_SLEEP
46  #include <linux/delay.h>
47  #endif
48 
49  extern const char driver_name[];
50 
51  #elif defined( MBG_TGT_BSD )
52 
53  extern const char driver_name[];
54 
55  #endif
56 
57 #endif
58 
59 
60 #if USE_MBG_KDD_MSG
61 
62 /*HDR*/
63 __attribute__( ( format( printf, 3, 4 ) ) )
64 int mbg_kdd_snprintf( char *buf, size_t size, const char *fmt, ... )
65 {
66  va_list args;
67  int n;
68 
69  va_start( args, fmt );
70  n = mbg_kdd_vsnprintf( buf, size, fmt, args );
71  va_end( args );
72 
73  return n;
74 
75 } // mbg_kdd_snprintf
76 
77 
78 
79 /*HDR*/
80 __attribute__( ( format( printf, 2, 3 ) ) )
81 void mbg_kdd_msg( int lvl, const char *fmt, ... )
82 {
83  va_list args;
84  char s[256];
85 
86  va_start( args, fmt );
87  mbg_kdd_vsnprintf( s, sizeof( s ), fmt, args );
88  va_end( args );
89 
90  #if defined( MBG_TGT_WIN32 )
91 
92  KddReportEventA( lvl, s );
93 
94  #elif defined( MBG_TGT_LINUX )
95  {
96  const char *cp;
97 
98  switch ( lvl ) // see linux/kern_levels.h
99  {
100  case MBG_LOG_ERR:
101  cp = KERN_ERR;
102  break;
103 
104  case MBG_LOG_WARN:
105  cp = KERN_WARNING;
106  break;
107 
108  case MBG_LOG_INFO:
109  cp = KERN_INFO;
110  break;
111 
112  case MBG_LOG_DEBUG:
113  cp = KERN_DEBUG;
114  break;
115 
116  default:
117  #if defined( KERN_DEFAULT )
118  cp = KERN_DEFAULT;
119  #else
120  cp = KERN_WARNING;
121  #endif
122  break;
123  }
124 
125  printk( "%s%s: %s\n", cp, driver_name, s );
126 
127  #if DEBUG_MSG_SLEEP
128  msleep( debug_msg_sleep );
129  #endif
130  }
131  #elif defined( MBG_TGT_BSD )
132 
133  printf( "%s: %s\n", driver_name, s );
134 
135  #elif defined( MBG_TGT_QNX )
136 
137  printf( "%s\n", s );
138 
139  #elif defined( MBG_TGT_DOS )
140 
141  printf( "%s\n", s );
142 
143  #else
144 
145  #error Not implemented for this target.
146 
147  #endif
148 
149 } // mbg_kdd_msg
150 
151 #endif // USE_MBG_KDD_MSG
152 
int mbg_kdd_snprintf(char *buf, size_t size, const char *fmt,...)
void mbg_kdd_msg(int lvl, const char *fmt,...)
const char driver_name[]
static __mbg_inline int mbg_kdd_vsnprintf(char *s, size_t max_len, const char *fmt, va_list args)
Definition: mbgddmsg.h:526