1 /*
2  * Copyright (c) 2017 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef BSIM_DUMP_FILES_H
7 #define BSIM_DUMP_FILES_H
8 
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /* Function that will print the heading of the dump file */
18 typedef void (*bs_df_header_f_t)(FILE *);
19 
20 /* Control structure defining for 1 dump file */
21 typedef struct {
22   char *postfix; /* Postfix for the dump file filename */
23 	int dump_level; /* Level of the dump file */
24 	bool enabled; /* Is the dump file enabled or not (can be set to 1 to enable it by default) */
25 	FILE* fileptr; /* Pointer to the dump file itself */
26 	bs_df_header_f_t header_f; /* Function to print the dump file heading */
27 } bs_dumpf_ctrl_t;
28 
29 #define DUMP_FILE_PTR(FILE_IDX) (f_ctrl[FILE_IDX].fileptr)
30 #define IS_DUMP_FILE_ACTIVE(FILE_IDX) (f_ctrl[FILE_IDX].fileptr != NULL)
31 
32 /**
33  * Register a new dump file
34  *
35  * Returns the index of the file which can later be used
36  * in DUMP_FILE_PTR() & IS_DUMP_FILE_ACTIVE()
37  */
38 int bs_dump_file_register(bs_dumpf_ctrl_t *f_ctrl);
39 /* Active all registered dump files with a level < new_dump_level*/
40 void bs_dump_files_set_dump_level(int new_dump_level);
41 /* Actiavte a given dump file from its postfix */
42 void bs_dump_files_activate_file(const char *postfix);
43 /* Open all active dump files */
44 void bs_dump_files_open(const char* s, const unsigned int d);
45 /* Close all dump files */
46 void bs_dump_files_close_all(void);
47 /* Print to console the list of registered dump files */
48 void bs_dump_files_print_files(void);
49 
50 
51 extern unsigned int bsdf_dump_level;
52 void bsdf_cmd_dump_found(char * argv, int offset);
53 void bsdf_cmd_printdumps_found(char * argv, int offset);
54 void bsdf_cmd_dumplevel_found(char * argv, int offset);
55 
56 /* Command line arguments for controlling the dump files */
57 #define BS_DUMP_FILES_ARGS \
58   {false, false, false,                                            \
59   "dump", "file_postfix", 's',                                     \
60   NULL, bsdf_cmd_dump_found,                                       \
61   "Activate dump of a given file. Where <file_postfix> "           \
62   "corresponds to the file name postfix of the file to be dumped " \
63   "<file_postfix> can be \"all\" for all files, or \"none\" to "   \
64   "clear all files"},                                              \
65   {false, false, true,                                             \
66   "printdumps", "", 'b',                                           \
67   NULL, bsdf_cmd_printdumps_found,                                 \
68   "Print the list of possible dump files, their dump level, and "  \
69   "if with the current command line so far they would have been "  \
70   "dumped or not"},                                                \
71   {false, false, false,                                            \
72   "dump_level", "level", 'u',                                      \
73   (void*)&bsdf_dump_level, bsdf_cmd_dumplevel_found,               \
74   "Set file dump level to <level> (default 0; all files with dump" \
75   " level under level will be dumped)"}
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif
82