920a51d54abfafb5791939e226b46366f4fd80cc
[strongswan.git] / Source / charon / logger_manager.h
1 /**
2 * @file logger_manager.h
3 *
4 * @brief Logger manager. Manages globaly all logger objects
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef LOGGER_MANAGER_H_
24 #define LOGGER_MANAGER_H_
25
26 #include <pthread.h>
27
28 #include "logger.h"
29
30 /**
31 * @brief Context of a specific logger
32 */
33 typedef enum logger_context_e logger_context_t;
34
35 enum logger_context_e{
36 PARSER,
37 GENERATOR,
38 IKE_SA,
39 MESSAGE,
40 WORKER_THREAD,
41 EVENT_THREAD,
42 SENDER_THREAD,
43 RECEIVER_THREAD,
44 TESTER,
45 };
46
47
48 /**
49 * @brief The logger_manager_t object
50 */
51 typedef struct logger_manager_s logger_manager_t;
52
53 struct logger_manager_s {
54
55 /**
56 * @brief Gets a logger_t object for a specific logger context.
57 *
58 * @warning logger_t objects which are not destroyed over function
59 * #logger_manager_s.destroy_logger are destroyed in logger_managers
60 * destroy function. Don't use logger_t's own destroy function with
61 * managed logger_t objects.
62 *
63 * @param this logger_manager_t object
64 * @param context logger_context to use the logger for.
65 * @param[out] logger pointer to a a place where the new logger is stored
66 * @param name name for the new logger. Context name is already included
67 * and has not to be specified.
68 * @return
69 * - SUCCESS
70 * - OUT_OF_RES
71 */
72 status_t (*get_logger) (logger_manager_t *this, logger_context_t context, logger_t **logger, char *name);
73
74
75 /**
76 * @brief Destroys a logger_t object which is not used anymore
77 *
78 * @warning logger_t objects which are not destroyed over function
79 * #logger_manager_s.destroy_logger are destroyed in logger_managers
80 * destroy function.
81 *
82 * @param this logger_manager_t object
83 * @param logger pointer to the logger which has to be destroyed
84 * @return
85 * - SUCCESS
86 * - OUT_OF_RES
87 * - NOT_FOUND
88 */
89 status_t (*destroy_logger) (logger_manager_t *this,logger_t *logger);
90
91 /**
92 * Returns the set logger_level of a specific context or 0.
93 * @param this calling object
94 * @param context context to check level
95 * @return logger_level for the given logger_context
96 */
97 logger_level_t (*get_logger_level) (logger_manager_t *this, logger_context_t context);
98
99 /**
100 * Enables a logger_level of a specific context.
101 * @param this calling object
102 * @param context context to set level
103 * @param logger_level logger_level to eanble
104 * @return SUCCESS
105 */
106 status_t (*enable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
107
108
109 /**
110 * Disables a logger_level of a specific context.
111 * @param this calling object
112 * @param context context to set level
113 * @param logger_level logger_level to disable
114 * @return SUCCESS
115 */
116 status_t (*disable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
117
118
119 /**
120 * @brief destroys a logger_manager_t object.
121 *
122 * @param this logger_manager_t object
123 * @return
124 * - SUCCESS in any case
125 */
126 status_t (*destroy) (logger_manager_t *this);
127 };
128
129 /**
130 * @brief Constructor to create a logger_manager_t object.
131 *
132 * @param default_log_level default log level for a context
133 * @return logger_manager_t object or NULL if failed
134 *
135 */
136 logger_manager_t *logger_manager_create(logger_level_t default_log_level);
137
138
139 #endif /*LOGGER_MANAGER_H_*/