Replace () with (void) in function prototypes
[platform/core/system/dlog.git] / include / logprint.h
1 /* MIT License
2  *
3  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is furnished
10  * to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE. */
22
23 #ifndef _LOGPRINT_H
24 #define _LOGPRINT_H
25
26 #include <stdbool.h>
27 #include <time.h>
28 #include <pthread.h>
29
30 #include <logcommon.h>
31 #include <ptrs_list.h>
32 #include <queued_entry.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 typedef enum {
39         FORMAT_OFF = 0,
40         FORMAT_BRIEF,
41         FORMAT_PROCESS,
42         FORMAT_TAG,
43         FORMAT_THREAD,
44         FORMAT_RAW,
45         FORMAT_TIME,
46         FORMAT_THREADTIME,
47         FORMAT_KERNELTIME,
48         FORMAT_RECV_REALTIME,
49         FORMAT_RWTIME,
50         FORMAT_LONG,
51         FORMAT_JSON,
52 } log_print_format;
53
54 struct log_format {
55         log_print_format format;
56         bool color;
57 };
58
59 struct log_write_buffer {
60         char *data;
61         size_t position;
62         size_t size;
63         struct timespec oldest_log;
64 };
65 struct log_filter *log_filter_new(void);
66
67 void log_filter_free(struct log_filter *p_filter);
68 struct log_filter {
69         list_head filters;
70         log_priority global_pri;
71         bool exact_global_pri;
72         bool need_apply_default;
73 };
74
75 void log_filter_init(struct log_filter *p_filter);
76
77 struct log_write_buffer log_write_buffer_new(void);
78
79 void log_write_buffer_free(struct log_write_buffer *buf);
80
81 /**
82  * Returns a deep copy of the passed object.
83  */
84 struct log_filter *log_filter_from_filter(const struct log_filter *p_filter);
85
86 struct log_filter *log_filter_move(struct log_filter *p_filter);
87
88 /**
89  * Returns FORMAT_OFF on invalid string
90  */
91 log_print_format log_format_from_string(const char *s);
92
93 /**
94  * filterExpression: a single filter expression
95  * eg "AT:d"
96  *
97  * returns 0 on success and -1 on invalid expression
98  *
99  * Assumes single threaded execution
100  *
101  */
102
103 int log_add_filter_rule(struct log_filter *p_filter, const char *filterExpression);
104
105 void log_filter_clear(struct log_filter *p_filter);
106
107 struct tag_and_prio {
108         char *tag;
109         size_t tagLength;
110         log_priority pri;
111         bool exactPri;
112         bool prefix;
113 };
114
115 typedef struct FilterInfo_t {
116         enum {
117                 FILTER_TAG_AND_PRIO,
118                 FILTER_PID,
119                 FILTER_TID,
120         } type;
121         union {
122                 struct tag_and_prio tnp;
123                 pid_t pid;
124                 pid_t tid;
125         };
126 } FilterInfo;
127
128 list_head log_filter_get_list(struct log_filter *p_filter);
129
130 log_priority log_filter_get_global_priority(struct log_filter *p_filter, bool *is_exact);
131
132 int log_filter_set_filterspec(struct log_filter *p_filter,
133                 const char *filterString);
134 int log_filter_set_pid(struct log_filter *p_filter, pid_t pid);
135 int log_filter_set_tid(struct log_filter *p_filter, pid_t tid);
136
137 bool log_filter_need_apply_default(struct log_filter *p_filter);
138
139 /**
140  * returns true if this log line should be printed based on its entry
141  * data (priority, tag, pid and tid), and false if it should not
142  */
143 bool log_should_print_line(
144                 struct log_filter *p_filter, const dlogutil_entry_s *entry);
145
146 /**
147  * Formats a log message into a buffer
148  *
149  * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
150  * If return value != defaultBuffer, caller must call free()
151  * Returns NULL on malloc error
152  */
153
154 char *log_format_log_line(
155                 const struct log_format p_format,
156                 char *defaultBuffer,
157                 size_t defaultBufferSize,
158                 const dlogutil_entry_s *p_line,
159                 size_t *p_outLength);
160
161 /**
162  * Either print or do not print log line, based on filter
163  *
164  * Assumes single threaded execution
165  *
166  */
167 int log_print_log_line(
168                 struct log_format p_format,
169                 int fd,
170                 const dlogutil_entry_s *entry,
171                 struct log_write_buffer *buf);
172
173 dlogutil_sorting_order_e get_format_sorting(log_print_format format);
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif /*_LOGPRINT_H*/