1 /* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
25 #include "eina_config.h"
26 #include "eina_private.h"
27 #include "eina_types.h"
28 #include "eina_main.h"
29 #include "eina_error.h"
31 #include "eina_hash.h"
32 #include "eina_stringshare.h"
33 #include "eina_list.h"
34 #include "eina_array.h"
35 #include "eina_counter.h"
36 #include "eina_benchmark.h"
37 #include "eina_magic.h"
38 #include "eina_rectangle.h"
39 #include "eina_safety_checks.h"
41 /*============================================================================*
43 *============================================================================*/
49 static int _eina_main_count = 0;
50 static int _eina_log_dom = -1;
51 #define ERR(...) EINA_LOG_DOM_ERR(_eina_log_dom, __VA_ARGS__)
52 #define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__)
58 /*============================================================================*
60 *============================================================================*/
62 /*============================================================================*
64 *============================================================================*/
67 * @addtogroup Eina_Main_Group Main
69 * @brief These functions provide general initialisation and shut down
76 * @brief Initialize the Eina library.
78 * @return 1 or greater on success, 0 on error.
80 * This function sets up all the eina modules. It returns 0 on
81 * failure (that is, when one of the module fails to initialize),
82 * otherwise it returns the number of times it has already been
83 * called. The list of initialisation functions that are called are
87 * @li eina_error_init()
88 * @li eina_safety_checks_init()
89 * @li eina_hash_init()
90 * @li eina_stringshare_init()
91 * @li eina_list_init()
92 * @li eina_array_init()
93 * @li eina_counter_init()
94 * @li eina_benchmark_init()
95 * @li eina_magic_string_init()
96 * @li eina_rectangle_init()
98 * When Eina is not used anymore, call eina_shutdown() to shut down
104 if (_eina_main_count) goto finish_init;
106 if (!eina_log_init())
108 fprintf(stderr, "Could not initialize eina logging system.\n");
112 _eina_log_dom = eina_log_domain_register("eina", EINA_LOG_COLOR_DEFAULT);
113 if (_eina_log_dom < 0)
115 EINA_LOG_ERR("Could not register log domain: eina");
120 if (!eina_error_init())
122 ERR("Could not initialize eina error module.");
123 goto eina_init_error;
126 if (!eina_safety_checks_init())
128 ERR("Could not initialize eina safety checks module.");
129 goto safety_checks_init_error;
132 if (!eina_hash_init())
134 ERR("Could not initialize eina hash module.");
135 goto hash_init_error;
137 if (!eina_stringshare_init())
139 ERR("Could not initialize eina stringshare module.");
140 goto stringshare_init_error;
142 if (!eina_list_init())
144 ERR("Could not initialize eina list module.");
145 goto list_init_error;
147 if (!eina_array_init())
149 ERR("Could not initialize eina array module.");
150 goto array_init_error;
152 if (!eina_counter_init())
154 ERR("Could not initialize eina counter module.");
155 goto counter_init_error;
157 if (!eina_benchmark_init())
159 ERR("Could not initialize eina benchmark module.");
160 goto benchmark_init_error;
162 if (!eina_magic_string_init())
164 ERR("Could not initialize eina magic string module.");
165 goto magic_string_init_error;
167 if (!eina_rectangle_init())
169 ERR("Could not initialize eina rectangle module.");
170 goto rectangle_init_error;
174 return ++_eina_main_count;
176 rectangle_init_error:
177 eina_magic_string_shutdown();
178 magic_string_init_error:
179 eina_benchmark_shutdown();
180 benchmark_init_error:
181 eina_counter_shutdown();
183 eina_array_shutdown();
185 eina_list_shutdown();
187 eina_stringshare_shutdown();
188 stringshare_init_error:
189 eina_hash_shutdown();
191 eina_safety_checks_shutdown();
192 safety_checks_init_error:
193 eina_error_shutdown();
202 * @brief Shut down the Eina library.
204 * @return 0 when all the modules is completely shut down, 1 or
207 * This function shuts down the Eina library. It returns 0 when it has
208 * been called the same number of times than eina_init(). In that case
209 * it shut down all the Eina modules. The list of shut down functions
210 * that are called are (in that order):
212 * @li eina_rectangle_shutdown()
213 * @li eina_magic_string_shutdown()
214 * @li eina_benchmark_shutdown()
215 * @li eina_counter_shutdown()
216 * @li eina_array_shutdown()
217 * @li eina_list_shutdown()
218 * @li eina_stringshare_shutdown()
219 * @li eina_hash_shutdown()
220 * @li eina_safety_checks_shutdown()
221 * @li eina_error_shutdown()
222 * @li eina_log_shutdown()
224 * Once this function succeeds (that is, @c 0 is returned), you must
225 * not call any of the Eina function anymore. You must call
226 * eina_init() again to use the Eina functions again.
231 if (_eina_main_count != 1) goto finish_shutdown;
233 eina_rectangle_shutdown();
234 eina_magic_string_shutdown();
235 eina_benchmark_shutdown();
236 eina_counter_shutdown();
237 eina_array_shutdown();
238 eina_list_shutdown();
239 eina_stringshare_shutdown();
240 eina_hash_shutdown();
241 eina_safety_checks_shutdown();
242 eina_error_shutdown();
243 eina_log_domain_unregister(_eina_log_dom);
248 return --_eina_main_count;