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