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_types.h"
27 #include "eina_main.h"
28 #include "eina_error.h"
29 #include "eina_safety_checks.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"
40 /*============================================================================*
42 *============================================================================*/
48 static int _eina_main_count = 0;
54 /*============================================================================*
56 *============================================================================*/
58 /*============================================================================*
60 *============================================================================*/
63 * @addtogroup Eina_Main_Group Main
65 * @brief These functions provide general initialisation and shut down
72 * @brief Initialize the Eina library.
74 * @return 1 or greater on success, 0 on error.
76 * This function sets up all the eina modules. It returns 0 on
77 * failure (that is, when one of the module fails to initialize),
78 * otherwise it returns the number of times it has already been
79 * called. The list of initialisation functions that are called are
82 * @li eina_error_init()
84 * @li eina_safety_checks_init()
85 * @li eina_hash_init()
86 * @li eina_stringshare_init()
87 * @li eina_list_init()
88 * @li eina_array_init()
89 * @li eina_counter_init()
90 * @li eina_benchmark_init()
91 * @li eina_magic_string_init()
92 * @li eina_rectangle_init()
94 * When Eina is not used anymore, call eina_shutdown() to shut down
100 if (_eina_main_count) goto finish_init;
102 if (!eina_error_init())
104 fprintf(stderr, "Could not initialize eina error module.\n");
108 if (!eina_log_init())
110 fprintf(stderr, "Could not initialize eina log module.\n");
114 if (!eina_safety_checks_init())
116 EINA_ERROR_PERR("Could not initialize eina safety checks module.\n");
117 goto safety_checks_init_error;
120 if (!eina_hash_init())
122 EINA_ERROR_PERR("Could not initialize eina hash module.\n");
123 goto hash_init_error;
125 if (!eina_stringshare_init())
127 EINA_ERROR_PERR("Could not initialize eina stringshare module.\n");
128 goto stringshare_init_error;
130 if (!eina_list_init())
132 EINA_ERROR_PERR("Could not initialize eina list module.\n");
133 goto list_init_error;
135 if (!eina_array_init())
137 EINA_ERROR_PERR("Could not initialize eina array module.\n");
138 goto array_init_error;
140 if (!eina_counter_init())
142 EINA_ERROR_PERR("Could not initialize eina counter module.\n");
143 goto counter_init_error;
145 if (!eina_benchmark_init())
147 EINA_ERROR_PERR("Could not initialize eina benchmark module.\n");
148 goto benchmark_init_error;
150 if (!eina_magic_string_init())
152 EINA_ERROR_PERR("Could not initialize eina magic string module.\n");
153 goto magic_string_init_error;
155 if (!eina_rectangle_init())
157 EINA_ERROR_PERR("Could not initialize eina rectangle module.\n");
158 goto rectangle_init_error;
162 return ++_eina_main_count;
164 rectangle_init_error:
165 eina_magic_string_shutdown();
166 magic_string_init_error:
167 eina_benchmark_shutdown();
168 benchmark_init_error:
169 eina_counter_shutdown();
171 eina_array_shutdown();
173 eina_list_shutdown();
175 eina_stringshare_shutdown();
176 stringshare_init_error:
177 eina_hash_shutdown();
180 safety_checks_init_error:
181 eina_safety_checks_shutdown();
183 eina_error_shutdown();
189 * @brief Shut down the Eina library.
191 * @return 0 when all the modules is completely shut down, 1 or
194 * This function shuts down the Eina library. It returns 0 when it has
195 * been called the same number of times than eina_init(). In that case
196 * it shut down all the Eina modules. The list of shut down functions
197 * that are called are (in that order):
199 * @li eina_rectangle_shutdown()
200 * @li eina_magic_string_shutdown()
201 * @li eina_benchmark_shutdown()
202 * @li eina_counter_shutdown()
203 * @li eina_array_shutdown()
204 * @li eina_list_shutdown()
205 * @li eina_stringshare_shutdown()
206 * @li eina_hash_shutdown()
207 * @li eina_safety_checks_shutdown()
208 * @li eina_log_shutdown()
209 * @li eina_error_shutdown()
211 * Once this function succeeds (that is, @c 0 is returned), you must
212 * not call any of the Eina function anymore. You must call
213 * eina_init() again to use the Eina functions again.
218 if (_eina_main_count != 1) goto finish_shutdown;
220 eina_rectangle_shutdown();
221 eina_magic_string_shutdown();
222 eina_benchmark_shutdown();
223 eina_counter_shutdown();
224 eina_array_shutdown();
225 eina_list_shutdown();
226 eina_stringshare_shutdown();
227 eina_hash_shutdown();
228 eina_safety_checks_shutdown();
230 eina_error_shutdown();
233 return --_eina_main_count;