fix a bit the documentation, but there are still
[profile/ivi/eina.git] / src / lib / eina_main.c
1 /* EINA - EFL data type library
2  * Copyright (C) 2008 Cedric Bail
3  *
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.
8  *
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.
13  *
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/>.
17  */
18
19 #include <stdio.h>
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
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"
36
37 /*============================================================================*
38  *                                  Local                                     *
39  *============================================================================*/
40
41 /**
42  * @cond LOCAL
43  */
44
45 static int _eina_main_count = 0;
46
47 /**
48  * @endcond
49  */
50
51 /*============================================================================*
52  *                                 Global                                     *
53  *============================================================================*/
54
55 /*============================================================================*
56  *                                   API                                      *
57  *============================================================================*/
58
59 /**
60  * @addtogroup Eina_Main_Group Main
61  *
62  * @brief These functions provide general initialisation and shut down
63  * functions.
64  *
65  * @{
66  */
67
68 /**
69  * @brief Initialize the Eina library.
70  *
71  * @return 1 or greater on success, 0 on error.
72  *
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.
77  *
78  * When Eina is not used anymore, call eina_shutdown() to shut down
79  * the Eina library.
80  */
81 EAPI int
82 eina_init(void)
83 {
84    if (_eina_main_count) goto finish_init;
85
86    if (!eina_error_init())
87      {
88         fprintf(stderr, "Could not initialize eina error module.\n");
89         return 0;
90      }
91    if (!eina_hash_init())
92      {
93         EINA_ERROR_PERR("Could not initialize eina hash module.\n");
94         goto hash_init_error;
95      }
96    if (!eina_stringshare_init())
97      {
98         EINA_ERROR_PERR("Could not initialize eina stringshare module.\n");
99         goto stringshare_init_error;
100      }
101    if (!eina_list_init())
102      {
103         EINA_ERROR_PERR("Could not initialize eina list module.\n");
104         goto list_init_error;
105      }
106    if (!eina_array_init())
107      {
108         EINA_ERROR_PERR("Could not initialize eina array module.\n");
109         goto array_init_error;
110      }
111    if (!eina_counter_init())
112      {
113         EINA_ERROR_PERR("Could not initialize eina counter module.\n");
114         goto counter_init_error;
115      }
116    if (!eina_benchmark_init())
117      {
118         EINA_ERROR_PERR("Could not initialize eina benchmark module.\n");
119         goto benchmark_init_error;
120      }
121    if (!eina_magic_string_init())
122      {
123         EINA_ERROR_PERR("Could not initialize eina magic string module.\n");
124         goto magic_string_init_error;
125      }
126    if (!eina_rectangle_init())
127      {
128         EINA_ERROR_PERR("Could not initialize eina rectangle module.\n");
129         goto rectangle_init_error;
130      }
131
132  finish_init:
133    return ++_eina_main_count;
134
135  rectangle_init_error:
136    eina_magic_string_shutdown();
137  magic_string_init_error:
138    eina_benchmark_shutdown();
139  benchmark_init_error:
140    eina_counter_shutdown();
141  counter_init_error:
142    eina_array_shutdown();
143  array_init_error:
144    eina_list_shutdown();
145  list_init_error:
146    eina_stringshare_shutdown();
147  stringshare_init_error:
148    eina_hash_shutdown();
149  hash_init_error:
150    eina_error_shutdown();
151    return 0;
152 }
153
154 /**
155  * @brief Shut down the Eina library.
156  *
157  * @return 0 when all the modules is completely shut down, 1 or
158  * greater otherwise.
159  *
160  * This function shuts down the Eina library. It returns 0 when it has
161  * been called the same number of times than eina_init(). In that case
162  * it shut down all the Eina modules.
163  *
164  * Once this function succeeds (that is, @c 0 is returned), you must
165  * not call any of the Eina function anymore. You must call
166  * eina_init() again to use the Eina functions again.
167  */
168 EAPI int
169 eina_shutdown(void)
170 {
171    if (_eina_main_count != 1) goto finish_shutdown;
172
173    eina_rectangle_shutdown();
174    eina_magic_string_shutdown();
175    eina_benchmark_shutdown();
176    eina_counter_shutdown();
177    eina_array_shutdown();
178    eina_list_shutdown();
179    eina_stringshare_shutdown();
180    eina_hash_shutdown();
181    eina_error_shutdown();
182
183  finish_shutdown:
184    return --_eina_main_count;
185 }
186
187 /**
188  * @}
189  */