summaryrefslogtreecommitdiffstats
path: root/adal_common.h
blob: 25bf22606f6fa3d919e8af5d5766f21604168046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*                                                                        */
/*                  OpenPOWER fsp-trace Project                           */
/* Contributors Listed Below - COPYRIGHT 2004,2012                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */

#ifndef _ADAL_COMMON_H
#define _ADAL_COMMON_H

#include <stdint.h>
#include <inttypes.h>
//#include <sys/types.h>
#include <ctype.h>
#include "trace_adal.h"

#define TYPE_UINT64	1
#define TYPE_FLOAT	2
#define TYPE_STRING	3

#define DEFAULT_FMT_SZ		256
extern char g_time_format[DEFAULT_FMT_SZ];

/*
 * @brief Time stamp contains seconds and microseconds
 */
#define TRACE_TIME_REAL   0
/*
 * @brief Time stamp contains a 64 bit counter from a 50MHZ cpu
 */
#define TRACE_TIME_50MHZ  1
/*
 * @brief Time stamp contains a 64 bit counter from a 167MHZ cpu (1000/6)
 */
#define TRACE_TIME_167MHZ 3
/*
 * @brief Time stamp contains a 64 bit counter from a 200MHZ cpu
 */
#define TRACE_TIME_200MHZ 2
#define TRACE_TIME_TIMESPEC 4
/*
 * @brief Time stamp is "Epoch" based (0 equals 1970-01-01 00:00:00 UTC)
 */
#define TRACE_TIME_EPOCH 128

#define TRACE_TIME_UNKNOWN 255

#define TRACE_TIME_MAX 3

/*
 * @brief maximum value of arguments to trace_adal_write_all.
 */
#define MAX_ARGS 9

/* a trace entry with args
 * the args can be accessed via h.args[..] too
 */
struct trace_write_entry {
    trace_entry_head_t h;
    uint32_t args[9];
};
typedef struct trace_write_entry trace_write_entry_t;

/* struct for SET_DEBUG/CONSOLE/PIPE ioctl calls */
struct trace_set_config {
	union {
		const char *name;
		trace_desc_t td;
	} u;
	int newlevel;
};

/* trace descriptor with console level
 */
struct trace_set_console {
    trace_desc_t td;
    uint32_t level;
};
typedef struct trace_set_console trace_set_console_t;

#ifdef __cplusplus
extern "C" {
#endif

/*
 * @brief change case to upper
 */
static inline void toupper_string(char *text)
{
	size_t j;

	for (j = 0; j < strlen(text); j++) {
		text[j] = toupper(text[j]);
	}
}


/*
 * @brief print to stdout dump of src
 */
void print_dump(const char *src, int len);

#ifdef __cplusplus
}
#endif

// verbose types
#define TRACE_TYPE_ERROR		1	//  error descriptions
#define TRACE_TYPE_PERROR		2	//  error descriptions with perror call
#define TRACE_TYPE_INFO		4	//  runtime info
#define TRACE_TYPE_VARS		8	//  interpreted data output
#define TRACE_TYPE_FUNC		16	//  functions entry/leave
#define TRACE_TYPE_RAW		32	//  raw data output
#define TRACE_TYPE_DEBUG		64	//  other debug output

// verbose levels (-v parameter)
#define TRACE_LVL0		0
#define TRACE_LVL1		TRACE_TYPE_ERROR | TRACE_TYPE_PERROR;
#define TRACE_LVL2		TRACE_TYPE_ERROR | TRACE_TYPE_PERROR | TRACE_TYPE_INFO;
#define TRACE_LVL3		TRACE_TYPE_ERROR | TRACE_TYPE_PERROR | TRACE_TYPE_INFO | TRACE_TYPE_VARS;
#define TRACE_LVL4		TRACE_TYPE_ERROR | TRACE_TYPE_PERROR | TRACE_TYPE_INFO | TRACE_TYPE_VARS | TRACE_TYPE_FUNC;
#define TRACE_LVL5		TRACE_TYPE_ERROR | TRACE_TYPE_PERROR | TRACE_TYPE_INFO | TRACE_TYPE_VARS | TRACE_TYPE_FUNC | TRACE_TYPE_RAW;
#define TRACE_LVL6		TRACE_TYPE_ERROR | TRACE_TYPE_PERROR | TRACE_TYPE_INFO | TRACE_TYPE_VARS | TRACE_TYPE_FUNC | TRACE_TYPE_RAW | TRACE_TYPE_DEBUG;

#define TRACE_LVL_ALL	TRACE_LVL6;

// verbose macroses
#define TRACE( TYPE, LVL, FMT, args...) \
	if( TYPE & LVL ) \
	{\
		if( TYPE & (TRACE_TYPE_INFO | TRACE_TYPE_VARS | TRACE_TYPE_FUNC | TRACE_TYPE_RAW | TRACE_TYPE_DEBUG) ) \
			printf("%s %s: " FMT, __FILE__, __func__ , ## args);\
		\
		else if( TYPE & TRACE_TYPE_DEBUG ) \
			printf("D: %s %s: " FMT, __FILE__, __func__ , ## args);\
		\
		else if( TYPE & TRACE_TYPE_ERROR ) \
			fprintf(stderr, "%s %s: " FMT, __FILE__, __func__ , ## args);\
		\
		else if( TYPE & TRACE_TYPE_PERROR ) \
		{\
			char __data__[256];                                             \
			memset(__data__,0,256);                                         \
			snprintf(__data__,255,"%s %s [%d]: " FMT, __FILE__, __func__,__LINE__, ## args);   \
			perror(__data__);                                               \
		}\
	}

#define TRACEE( FMT, args... ) TRACE( TRACE_TYPE_ERROR, g_verbose_level, FMT, ## args )
#define TRACEPE( FMT, args... ) TRACE( TRACE_TYPE_PERROR, g_verbose_level, FMT, ## args )
#define TRACEI( FMT, args... ) TRACE( TRACE_TYPE_INFO, g_verbose_level, FMT, ## args )
#define TRACEV( FMT, args... ) TRACE( TRACE_TYPE_VARS, g_verbose_level, FMT, ## args )
#define TRACEF( FMT, args... ) TRACE( TRACE_TYPE_FUNC, g_verbose_level, FMT, ## args )
#define TRACER( FMT, args... ) TRACE( TRACE_TYPE_RAW, g_verbose_level, FMT, ## args )
#define TRACED( FMT, args... ) TRACE( TRACE_TYPE_DEBUG, g_verbose_level, FMT, ## args )

#endif				//_ADAL_COMMON_H
OpenPOWER on IntegriCloud