Fix init error handling of array, benchmark, counter,main,
[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  *                                 Global                                     *
39  *============================================================================*/
40
41 /*============================================================================*
42  *                                   API                                      *
43  *============================================================================*/
44
45 static int _eina_main_count = 0;
46
47 EAPI int
48 eina_init(void)
49 {
50    if (_eina_main_count) goto finish_init;
51
52    if (!eina_error_init())
53      {
54         fprintf(stderr, "Could not initialize eina error module.\n");
55         return 0;
56      }
57    if (!eina_hash_init())
58      {
59         EINA_ERROR_PERR("Could not initialize eina hash module.\n");
60         goto hash_init_error;
61      }
62    if (!eina_stringshare_init())
63      {
64         EINA_ERROR_PERR("Could not initialize eina stringshare module.\n");
65         goto stringshare_init_error;
66      }
67    if (!eina_list_init())
68      {
69         EINA_ERROR_PERR("Could not initialize eina list module.\n");
70         goto list_init_error;
71      }
72    if (!eina_array_init())
73      {
74         EINA_ERROR_PERR("Could not initialize eina array module.\n");
75         goto array_init_error;
76      }
77    if (!eina_counter_init())
78      {
79         EINA_ERROR_PERR("Could not initialize eina counter module.\n");
80         goto counter_init_error;
81      }
82    if (!eina_benchmark_init())
83      {
84         EINA_ERROR_PERR("Could not initialize eina benchmark module.\n");
85         goto benchmark_init_error;
86      }
87    if (!eina_magic_string_init())
88      {
89         EINA_ERROR_PERR("Could not initialize eina magic string module.\n");
90         goto magic_string_init_error;
91      }
92    if (!eina_rectangle_init())
93      {
94         EINA_ERROR_PERR("Could not initialize eina rectangle module.\n");
95         goto rectangle_init_error;
96      }
97
98  finish_init:
99    return ++_eina_main_count;
100
101  rectangle_init_error:
102    eina_magic_string_shutdown();
103  magic_string_init_error:
104    eina_benchmark_shutdown();
105  benchmark_init_error:
106    eina_counter_shutdown();
107  counter_init_error:
108    eina_array_shutdown();
109  array_init_error:
110    eina_list_shutdown();
111  list_init_error:
112    eina_stringshare_shutdown();
113  stringshare_init_error:
114    eina_hash_shutdown();
115  hash_init_error:
116    eina_error_shutdown();
117    return 0;
118 }
119
120 EAPI int
121 eina_shutdown(void)
122 {
123    if (_eina_main_count != 1) goto finish_shutdown;
124
125    eina_rectangle_shutdown();
126    eina_magic_string_shutdown();
127    eina_benchmark_shutdown();
128    eina_counter_shutdown();
129    eina_array_shutdown();
130    eina_list_shutdown();
131    eina_stringshare_shutdown();
132    eina_hash_shutdown();
133    eina_error_shutdown();
134
135  finish_shutdown:
136    return --_eina_main_count;
137 }
138