2008-08-06 11:15:24 -07:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2008 Cedric Bail
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-06-05 21:22:21 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-08-28 00:46:42 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-01-23 08:11:45 -08:00
|
|
|
#include "eina_types.h"
|
|
|
|
#include "eina_main.h"
|
|
|
|
#include "eina_error.h"
|
|
|
|
#include "eina_hash.h"
|
|
|
|
#include "eina_stringshare.h"
|
|
|
|
#include "eina_list.h"
|
|
|
|
#include "eina_array.h"
|
|
|
|
#include "eina_counter.h"
|
|
|
|
#include "eina_benchmark.h"
|
|
|
|
#include "eina_magic.h"
|
2009-04-09 08:51:32 -07:00
|
|
|
#include "eina_rectangle.h"
|
2008-08-06 08:37:29 -07:00
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/*============================================================================*
|
|
|
|
* Local *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @cond LOCAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int _eina_main_count = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
2008-08-28 00:46:42 -07:00
|
|
|
/*============================================================================*
|
|
|
|
* Global *
|
|
|
|
*============================================================================*/
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* API *
|
|
|
|
*============================================================================*/
|
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/**
|
|
|
|
* @addtogroup Eina_Main_Group Main
|
|
|
|
*
|
|
|
|
* @brief These functions provide general initialisation and shut down
|
|
|
|
* functions.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2008-10-27 13:24:12 -07:00
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/**
|
|
|
|
* @brief Initialize the Eina library.
|
|
|
|
*
|
|
|
|
* @return 1 or greater on success, 0 on error.
|
|
|
|
*
|
|
|
|
* This function sets up all the eina modules. It returns 0 on
|
|
|
|
* failure (that is, when one of the module fails to initialize),
|
|
|
|
* otherwise it returns the number of times it has already been
|
2009-06-27 23:29:11 -07:00
|
|
|
* called. The list of initialisation functions that are called are
|
|
|
|
* (in that order):
|
|
|
|
*
|
|
|
|
* @li eina_error_init()
|
|
|
|
* @li eina_hash_init()
|
|
|
|
* @li eina_stringshare_init()
|
|
|
|
* @li eina_list_init()
|
|
|
|
* @li eina_array_init()
|
|
|
|
* @li eina_counter_init()
|
|
|
|
* @li eina_benchmark_init()
|
|
|
|
* @li eina_magic_string_init()
|
|
|
|
* @li eina_rectangle_init()
|
2009-06-22 13:03:58 -07:00
|
|
|
*
|
|
|
|
* When Eina is not used anymore, call eina_shutdown() to shut down
|
|
|
|
* the Eina library.
|
|
|
|
*/
|
2008-08-06 08:37:29 -07:00
|
|
|
EAPI int
|
|
|
|
eina_init(void)
|
|
|
|
{
|
2008-10-27 13:24:12 -07:00
|
|
|
if (_eina_main_count) goto finish_init;
|
2008-08-06 08:37:29 -07:00
|
|
|
|
2009-06-05 21:22:21 -07:00
|
|
|
if (!eina_error_init())
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not initialize eina error module.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!eina_hash_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina hash module.\n");
|
|
|
|
goto hash_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_stringshare_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina stringshare module.\n");
|
|
|
|
goto stringshare_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_list_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina list module.\n");
|
|
|
|
goto list_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_array_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina array module.\n");
|
|
|
|
goto array_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_counter_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina counter module.\n");
|
|
|
|
goto counter_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_benchmark_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina benchmark module.\n");
|
|
|
|
goto benchmark_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_magic_string_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina magic string module.\n");
|
|
|
|
goto magic_string_init_error;
|
|
|
|
}
|
|
|
|
if (!eina_rectangle_init())
|
|
|
|
{
|
|
|
|
EINA_ERROR_PERR("Could not initialize eina rectangle module.\n");
|
|
|
|
goto rectangle_init_error;
|
|
|
|
}
|
2008-08-06 08:37:29 -07:00
|
|
|
|
2008-10-27 13:24:12 -07:00
|
|
|
finish_init:
|
|
|
|
return ++_eina_main_count;
|
2009-06-05 21:22:21 -07:00
|
|
|
|
|
|
|
rectangle_init_error:
|
|
|
|
eina_magic_string_shutdown();
|
|
|
|
magic_string_init_error:
|
|
|
|
eina_benchmark_shutdown();
|
|
|
|
benchmark_init_error:
|
|
|
|
eina_counter_shutdown();
|
|
|
|
counter_init_error:
|
|
|
|
eina_array_shutdown();
|
|
|
|
array_init_error:
|
|
|
|
eina_list_shutdown();
|
|
|
|
list_init_error:
|
|
|
|
eina_stringshare_shutdown();
|
|
|
|
stringshare_init_error:
|
|
|
|
eina_hash_shutdown();
|
|
|
|
hash_init_error:
|
|
|
|
eina_error_shutdown();
|
|
|
|
return 0;
|
2008-08-06 08:37:29 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/**
|
|
|
|
* @brief Shut down the Eina library.
|
|
|
|
*
|
|
|
|
* @return 0 when all the modules is completely shut down, 1 or
|
|
|
|
* greater otherwise.
|
|
|
|
*
|
|
|
|
* This function shuts down the Eina library. It returns 0 when it has
|
|
|
|
* been called the same number of times than eina_init(). In that case
|
2009-06-27 23:29:11 -07:00
|
|
|
* it shut down all the Eina modules. The list of shut down functions
|
|
|
|
* that are called are (in that order):
|
|
|
|
*
|
|
|
|
* @li eina_rectangle_init()
|
|
|
|
* @li eina_magic_string_init()
|
|
|
|
* @li eina_benchmark_init()
|
|
|
|
* @li eina_counter_init()
|
|
|
|
* @li eina_array_init()
|
|
|
|
* @li eina_list_init()
|
|
|
|
* @li eina_stringshare_init()
|
|
|
|
* @li eina_hash_init()
|
|
|
|
* @li eina_error_init()
|
2009-06-22 13:03:58 -07:00
|
|
|
*
|
|
|
|
* Once this function succeeds (that is, @c 0 is returned), you must
|
|
|
|
* not call any of the Eina function anymore. You must call
|
|
|
|
* eina_init() again to use the Eina functions again.
|
|
|
|
*/
|
2008-08-06 08:37:29 -07:00
|
|
|
EAPI int
|
|
|
|
eina_shutdown(void)
|
|
|
|
{
|
2008-10-27 13:24:12 -07:00
|
|
|
if (_eina_main_count != 1) goto finish_shutdown;
|
2008-08-06 08:37:29 -07:00
|
|
|
|
2009-04-09 08:51:32 -07:00
|
|
|
eina_rectangle_shutdown();
|
2008-09-24 10:21:53 -07:00
|
|
|
eina_magic_string_shutdown();
|
2008-09-18 03:04:46 -07:00
|
|
|
eina_benchmark_shutdown();
|
|
|
|
eina_counter_shutdown();
|
2008-08-07 06:12:57 -07:00
|
|
|
eina_array_shutdown();
|
|
|
|
eina_list_shutdown();
|
2008-09-03 05:06:50 -07:00
|
|
|
eina_stringshare_shutdown();
|
|
|
|
eina_hash_shutdown();
|
2008-10-27 13:24:12 -07:00
|
|
|
eina_error_shutdown();
|
2008-08-06 08:37:29 -07:00
|
|
|
|
2008-10-27 13:24:12 -07:00
|
|
|
finish_shutdown:
|
|
|
|
return --_eina_main_count;
|
2008-08-06 08:37:29 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|