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_types.h"
26 #include "eina_main.h"
27 #include "eina_error.h"
28 #include "eina_hash.h"
29 #include "eina_stringshare.h"
30 #include "eina_list.h"
31 #include "eina_array.h"
32 #include "eina_counter.h"
33 #include "eina_benchmark.h"
34 #include "eina_magic.h"
35 #include "eina_rectangle.h"
37 /*============================================================================*
39 *============================================================================*/
45 static int _eina_main_count = 0;
51 /*============================================================================*
53 *============================================================================*/
55 /*============================================================================*
57 *============================================================================*/
60 * @addtogroup Eina_Main_Group Main
62 * @brief These functions provide general initialisation and shut down
69 * @brief Initialize the Eina library.
71 * @return 1 or greater on success, 0 on error.
73 * This function sets up all the eina modules. It returns 0 on
74 * failure (that is, when one of the module fails to initialize),
75 * otherwise it returns the number of times it has already been
76 * called. The list of initialisation functions that are called are
79 * @li eina_error_init()
80 * @li eina_hash_init()
81 * @li eina_stringshare_init()
82 * @li eina_list_init()
83 * @li eina_array_init()
84 * @li eina_counter_init()
85 * @li eina_benchmark_init()
86 * @li eina_magic_string_init()
87 * @li eina_rectangle_init()
89 * When Eina is not used anymore, call eina_shutdown() to shut down
95 if (_eina_main_count) goto finish_init;
97 if (!eina_error_init())
99 fprintf(stderr, "Could not initialize eina error module.\n");
102 if (!eina_hash_init())
104 EINA_ERROR_PERR("Could not initialize eina hash module.\n");
105 goto hash_init_error;
107 if (!eina_stringshare_init())
109 EINA_ERROR_PERR("Could not initialize eina stringshare module.\n");
110 goto stringshare_init_error;
112 if (!eina_list_init())
114 EINA_ERROR_PERR("Could not initialize eina list module.\n");
115 goto list_init_error;
117 if (!eina_array_init())
119 EINA_ERROR_PERR("Could not initialize eina array module.\n");
120 goto array_init_error;
122 if (!eina_counter_init())
124 EINA_ERROR_PERR("Could not initialize eina counter module.\n");
125 goto counter_init_error;
127 if (!eina_benchmark_init())
129 EINA_ERROR_PERR("Could not initialize eina benchmark module.\n");
130 goto benchmark_init_error;
132 if (!eina_magic_string_init())
134 EINA_ERROR_PERR("Could not initialize eina magic string module.\n");
135 goto magic_string_init_error;
137 if (!eina_rectangle_init())
139 EINA_ERROR_PERR("Could not initialize eina rectangle module.\n");
140 goto rectangle_init_error;
144 return ++_eina_main_count;
146 rectangle_init_error:
147 eina_magic_string_shutdown();
148 magic_string_init_error:
149 eina_benchmark_shutdown();
150 benchmark_init_error:
151 eina_counter_shutdown();
153 eina_array_shutdown();
155 eina_list_shutdown();
157 eina_stringshare_shutdown();
158 stringshare_init_error:
159 eina_hash_shutdown();
161 eina_error_shutdown();
166 * @brief Shut down the Eina library.
168 * @return 0 when all the modules is completely shut down, 1 or
171 * This function shuts down the Eina library. It returns 0 when it has
172 * been called the same number of times than eina_init(). In that case
173 * it shut down all the Eina modules. The list of shut down functions
174 * that are called are (in that order):
176 * @li eina_rectangle_init()
177 * @li eina_magic_string_init()
178 * @li eina_benchmark_init()
179 * @li eina_counter_init()
180 * @li eina_array_init()
181 * @li eina_list_init()
182 * @li eina_stringshare_init()
183 * @li eina_hash_init()
184 * @li eina_error_init()
186 * Once this function succeeds (that is, @c 0 is returned), you must
187 * not call any of the Eina function anymore. You must call
188 * eina_init() again to use the Eina functions again.
193 if (_eina_main_count != 1) goto finish_shutdown;
195 eina_rectangle_shutdown();
196 eina_magic_string_shutdown();
197 eina_benchmark_shutdown();
198 eina_counter_shutdown();
199 eina_array_shutdown();
200 eina_list_shutdown();
201 eina_stringshare_shutdown();
202 eina_hash_shutdown();
203 eina_error_shutdown();
206 return --_eina_main_count;