Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
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 
157 
158 
167 
168 
176 
177 
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 
288 
289 
297 
298 
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 
grassroots_util_library.h
OutputStream::SetDefaultErrorStream
void SetDefaultErrorStream(OutputStream *stream_p)
Set the Server-side OutputStream for printing error messages to.
OutputStream::PrintToOutputStream
int PrintToOutputStream(OutputStream *stream_p, const char *const filename_s, const int line_number, const char *message_s,...)
Print to a given error OutputStream.
OutputStream::FreeOutputStream
void FreeOutputStream(struct OutputStream *stream_p)
Free an OutputStream.
InitDefaultOutputStream
bool InitDefaultOutputStream(void)
Initialise the default OutputStreams ready for use.
OutputStream::SetDefaultLogStream
void SetDefaultLogStream(OutputStream *stream_p)
Set the Server-side OutputStream for printing error messages to.
typedefs.h
OutputStream::FlushOutputStream
bool FlushOutputStream(OutputStream *stream_p)
Flush an OutputStream.
OutputStream::PrintLog
int PrintLog(const uint32 level, const char *const filename_s, const int line_number, const char *message_s,...)
Print to the log OutputStream.
OutputStream::st_print_fn
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
OutputStream::PrintLogVarArgs
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.
OutputStream::GetLogOutput
OutputStream * GetLogOutput(void)
Get where logging messages will be sent.
OutputStream::PrintErrorsVarArgs
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.
OutputStream::FlushErrors
bool FlushErrors(void)
Flush the errors OutputStream.
OutputStream::FreeDefaultOutputStream
void FreeDefaultOutputStream(void)
Free the default OutputStreams.
OutputStream::FlushLog
bool FlushLog(void)
Flush the logging OutputStream.
OutputStream::PrintErrors
int PrintErrors(const uint32 level, const char *const filename_s, const int line_number, const char *message,...)
Print to the error OutputStream.
OutputStream
An datatype to abstract out the process of writing log and error messages to the appropriate processe...
Definition: streams.h:106
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47
OutputStream::st_flush_fn
bool(* st_flush_fn)(struct OutputStream *stream_p)
Flush any pending writes to an OutputStream.
Definition: streams.h:130
OutputStream::GetErrorsOutput
OutputStream * GetErrorsOutput(void)
Get where error messages will be sent.
OutputStream::st_free_stream_fn
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