streams.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
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 
24 #ifndef STREAMS_H
25 #define STREAMS_H
26 
27 #include <stdarg.h>
28 #include <stdio.h>
30 #include "typedefs.h"
31 
41 #define STM_LEVEL_NONE (0)
42 
43 
49 #define STM_LEVEL_SEVERE (1024)
50 
56 #define STM_LEVEL_WARNING (1025)
57 
63 #define STM_LEVEL_INFO (1026)
64 
70 #define STM_LEVEL_FINE (1027)
71 
77 #define STM_LEVEL_FINER (1028)
78 
84 #define STM_LEVEL_FINEST (1029)
85 
86 
92 #define STM_LEVEL_ALL (0xFFFFFFFF)
93 
94 
95 
96 /******** FORWARD DECLARATION ******/
97 struct OutputStream;
98 
99 
106 typedef struct OutputStream
107 {
121  int (*st_print_fn) (struct OutputStream *stream_p, const uint32 level, const char * const filename_s, const int line_number, const char *message_s, va_list args);
122 
130  bool (*st_flush_fn) (struct OutputStream *stream_p);
131 
137  void (*st_free_stream_fn) (struct OutputStream *stream_p);
138 } OutputStream;
139 
140 
141 #ifdef __cplusplus
142  extern "C" {
143 #endif
144 
145 
156 GRASSROOTS_UTIL_API bool InitDefaultOutputStream (void);
157 
158 
166 GRASSROOTS_UTIL_API void FreeDefaultOutputStream (void);
167 
168 
175 GRASSROOTS_UTIL_API void SetDefaultErrorStream (OutputStream *stream_p);
176 
177 
184 GRASSROOTS_UTIL_API void SetDefaultLogStream (OutputStream *stream_p);
185 
186 
195 GRASSROOTS_UTIL_API void FreeOutputStream (struct OutputStream *stream_p);
196 
197 
213 GRASSROOTS_UTIL_API int PrintToOutputStream (OutputStream *stream_p, const char * const filename_s, const int line_number, const char *message_s, ...);
214 
215 
229 GRASSROOTS_UTIL_API int PrintErrors (const uint32 level, const char * const filename_s, const int line_number, const char *message, ...);
230 
231 
245 GRASSROOTS_UTIL_API int PrintLog (const uint32 level, const char * const filename_s, const int line_number, const char *message_s, ...);
246 
247 
262 GRASSROOTS_UTIL_API int PrintErrorsVarArgs (const uint32 level, const char * const filename_s, const int line_number, const char *message_s, va_list args);
263 
264 
279 GRASSROOTS_UTIL_API int PrintLogVarArgs (const uint32 level, const char * const filename_s, const int line_number, const char *message_s, va_list args);
280 
287 GRASSROOTS_UTIL_API OutputStream *GetLogOutput (void);
288 
289 
296 GRASSROOTS_UTIL_API OutputStream *GetErrorsOutput (void);
297 
298 
308 GRASSROOTS_UTIL_API bool FlushOutputStream (OutputStream *stream_p);
309 
310 
319 GRASSROOTS_UTIL_API bool FlushLog (void);
320 
321 
330 GRASSROOTS_UTIL_API bool FlushErrors (void);
331 
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* STREAMS_H */
338 
An datatype to abstract out the process of writing log and error messages to the appropriate processe...
Definition: streams.h:106
OutputStream * GetLogOutput(void)
Get where logging messages will be sent.
bool(* st_flush_fn)(struct OutputStream *stream_p)
Flush any pending writes to an OutputStream.
Definition: streams.h:130
bool FlushLog(void)
Flush the logging OutputStream.
bool InitDefaultOutputStream(void)
Initialise the default OutputStreams ready for use.
int(* st_print_fn)(struct OutputStream *stream_p, const uint32 level, const char *const filename_s, const int line_number, const char *message_s, va_list args)
Print to an OutputStream.
Definition: streams.h:121
int PrintLogVarArgs(const uint32 level, const char *const filename_s, const int line_number, const char *message_s, va_list args)
Print to the log OutputStream.
void FreeDefaultOutputStream(void)
Free the default OutputStreams.
int PrintErrors(const uint32 level, const char *const filename_s, const int line_number, const char *message,...)
Print to the error OutputStream.
int PrintToOutputStream(OutputStream *stream_p, const char *const filename_s, const int line_number, const char *message_s,...)
Print to a given error OutputStream.
bool FlushOutputStream(OutputStream *stream_p)
Flush an OutputStream.
int PrintLog(const uint32 level, const char *const filename_s, const int line_number, const char *message_s,...)
Print to the log OutputStream.
bool FlushErrors(void)
Flush the errors OutputStream.
OutputStream * GetErrorsOutput(void)
Get where error messages will be sent.
void FreeOutputStream(struct OutputStream *stream_p)
Free an OutputStream.
void(* st_free_stream_fn)(struct OutputStream *stream_p)
Callback function to free the OutputStream if it needs any custom behaviour.
Definition: streams.h:137
void SetDefaultErrorStream(OutputStream *stream_p)
Set the Server-side OutputStream for printing error messages to.
void SetDefaultLogStream(OutputStream *stream_p)
Set the Server-side OutputStream for printing error messages to.
int PrintErrorsVarArgs(const uint32 level, const char *const filename_s, const int line_number, const char *message_s, va_list args)
Print to the error OutputStream.