de37e1e0f308d75cbf8d9b781f0b327efd52ce6b
[strongswan.git] / Source / charon / utils / 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 <utils/logger.h>
29
30 typedef enum logger_context_t logger_context_t;
31
32 /**
33 * @brief Context of a specific logger
34 */
35 enum logger_context_t {
36 PARSER,
37 GENERATOR,
38 IKE_SA,
39 IKE_SA_MANAGER,
40 MESSAGE,
41 THREAD_POOL,
42 WORKER,
43 SCHEDULER,
44 SENDER,
45 RECEIVER,
46 SOCKET,
47 TESTER,
48 DAEMON,
49 CONFIGURATION_MANAGER,
50 };
51
52 typedef struct logger_manager_t logger_manager_t;
53
54 /**
55 * @brief The logger_manager_t object
56 */
57 struct logger_manager_t {
58
59 /**
60 * @brief Gets a logger_t object for a specific logger context.
61 *
62 * @warning logger_t objects which are not destroyed over function
63 * #logger_manager_s.destroy_logger are destroyed in logger_managers
64 * destroy function. Don't use logger_t's own destroy function with
65 * managed logger_t objects.
66 *
67 * @param this logger_manager_t object
68 * @param context logger_context to use the logger for.
69 * @param[out] logger pointer to a a place where the new logger is stored
70 * @param name name for the new logger. Context name is already included
71 * and has not to be specified (so NULL is allowed).
72 * @return
73 * - logger_t on SUCCESS
74 * - NULL otherwise
75 */
76 logger_t *(*create_logger) (logger_manager_t *this, logger_context_t context, char *name);
77
78
79 /**
80 * @brief Destroys a logger_t object which is not used anymore
81 *
82 * @warning logger_t objects which are not destroyed over function
83 * #logger_manager_s.destroy_logger are destroyed in logger_managers
84 * destroy function.
85 *
86 * @param this logger_manager_t object
87 * @param logger pointer to the logger which has to be destroyed
88 * @return
89 * - SUCCESS
90 * - OUT_OF_RES
91 * - NOT_FOUND
92 */
93 status_t (*destroy_logger) (logger_manager_t *this,logger_t *logger);
94
95 /**
96 * Returns the set logger_level of a specific context or 0.
97 * @param this calling object
98 * @param context context to check level
99 * @return logger_level for the given logger_context
100 */
101 logger_level_t (*get_logger_level) (logger_manager_t *this, logger_context_t context);
102
103 /**
104 * Enables a logger_level of a specific context.
105 * @param this calling object
106 * @param context context to set level
107 * @param logger_level logger_level to eanble
108 * @return SUCCESS
109 */
110 status_t (*enable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
111
112
113 /**
114 * Disables a logger_level of a specific context.
115 * @param this calling object
116 * @param context context to set level
117 * @param logger_level logger_level to disable
118 * @return SUCCESS
119 */
120 status_t (*disable_logger_level) (logger_manager_t *this, logger_context_t context,logger_level_t logger_level);
121
122
123 /**
124 * @brief destroys a logger_manager_t object.
125 *
126 * @param this logger_manager_t object
127 * @return
128 * - SUCCESS in any case
129 */
130 status_t (*destroy) (logger_manager_t *this);
131 };
132
133 /**
134 * @brief Constructor to create a logger_manager_t object.
135 *
136 * @param default_log_level default log level for a context
137 * @return logger_manager_t object or NULL if failed
138 *
139 */
140 logger_manager_t *logger_manager_create(logger_level_t default_log_level);
141
142
143 #endif /*LOGGER_MANAGER_H_*/