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-08-28 05:03:34 -07:00
|
|
|
#include "eina_config.h"
|
2009-09-03 18:48:36 -07:00
|
|
|
#include "eina_private.h"
|
2009-01-23 08:11:45 -08:00
|
|
|
#include "eina_types.h"
|
|
|
|
#include "eina_main.h"
|
|
|
|
#include "eina_error.h"
|
2009-08-25 14:26:27 -07:00
|
|
|
#include "eina_log.h"
|
2009-01-23 08:11:45 -08:00
|
|
|
#include "eina_hash.h"
|
|
|
|
#include "eina_stringshare.h"
|
|
|
|
#include "eina_list.h"
|
2009-09-04 06:43:44 -07:00
|
|
|
#include "eina_matrixsparse.h"
|
2009-01-23 08:11:45 -08:00
|
|
|
#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"
|
2009-09-03 18:48:36 -07:00
|
|
|
#include "eina_safety_checks.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;
|
2009-09-03 18:48:36 -07:00
|
|
|
static int _eina_log_dom = -1;
|
2009-09-06 21:23:05 -07:00
|
|
|
|
|
|
|
#ifdef ERR
|
|
|
|
#undef ERR
|
|
|
|
#endif
|
2009-09-03 18:48:36 -07:00
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_eina_log_dom, __VA_ARGS__)
|
2009-09-06 21:23:05 -07:00
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
#undef DBG
|
|
|
|
#endif
|
2009-09-03 18:48:36 -07:00
|
|
|
#define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__)
|
2009-06-22 13:03:58 -07:00
|
|
|
|
2009-09-06 15:21:56 -07:00
|
|
|
|
|
|
|
/* place module init/shutdown functions here to avoid other modules
|
|
|
|
* calling them by mistake.
|
|
|
|
*/
|
|
|
|
#define S(x) extern Eina_Bool eina_##x##_init(void); extern Eina_Bool eina_##x##_shutdown(void)
|
|
|
|
S(log);
|
|
|
|
S(error);
|
|
|
|
S(safety_checks);
|
|
|
|
S(magic_string);
|
2009-09-06 19:33:54 -07:00
|
|
|
S(iterator);
|
|
|
|
S(accessor);
|
2009-09-06 15:21:56 -07:00
|
|
|
S(array);
|
|
|
|
S(module);
|
|
|
|
S(mempool);
|
|
|
|
S(list);
|
|
|
|
S(stringshare);
|
|
|
|
S(matrixsparse);
|
|
|
|
S(convert);
|
|
|
|
S(counter);
|
|
|
|
S(benchmark);
|
|
|
|
S(rectangle);
|
|
|
|
#undef S
|
|
|
|
|
|
|
|
struct eina_desc_setup
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
Eina_Bool (*init)(void);
|
|
|
|
Eina_Bool (*shutdown)(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct eina_desc_setup _eina_desc_setup[] = {
|
|
|
|
#define S(x) {#x, eina_##x##_init, eina_##x##_shutdown}
|
|
|
|
/* log is a special case as it needs printf */
|
|
|
|
S(error),
|
|
|
|
S(safety_checks),
|
|
|
|
S(magic_string),
|
2009-09-06 19:33:54 -07:00
|
|
|
S(iterator),
|
|
|
|
S(accessor),
|
2009-09-06 15:21:56 -07:00
|
|
|
S(array),
|
|
|
|
S(module),
|
|
|
|
S(mempool),
|
|
|
|
S(list),
|
|
|
|
S(stringshare),
|
|
|
|
S(matrixsparse),
|
|
|
|
S(convert),
|
|
|
|
S(counter),
|
|
|
|
S(benchmark),
|
|
|
|
S(rectangle)
|
|
|
|
#undef S
|
|
|
|
};
|
|
|
|
static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) / sizeof(_eina_desc_setup[0]);
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eina_shutdown_from_desc(const struct eina_desc_setup *itr)
|
|
|
|
{
|
|
|
|
for (itr--; itr >= _eina_desc_setup; itr--)
|
|
|
|
{
|
|
|
|
if (!itr->shutdown())
|
|
|
|
ERR("Problems shutting down eina module '%s', ignored.", itr->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_log_domain_unregister(_eina_log_dom);
|
|
|
|
_eina_log_dom = -1;
|
|
|
|
eina_log_shutdown();
|
|
|
|
}
|
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/**
|
|
|
|
* @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-09-06 15:21:56 -07:00
|
|
|
* called.
|
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)
|
|
|
|
{
|
2009-09-06 15:21:56 -07:00
|
|
|
const struct eina_desc_setup *itr, *itr_end;
|
|
|
|
|
|
|
|
if (EINA_LIKELY(_eina_main_count > 0))
|
|
|
|
return ++_eina_main_count;
|
2008-08-06 08:37:29 -07:00
|
|
|
|
2009-09-03 18:48:36 -07:00
|
|
|
if (!eina_log_init())
|
2009-06-05 21:22:21 -07:00
|
|
|
{
|
2009-09-03 18:48:36 -07:00
|
|
|
fprintf(stderr, "Could not initialize eina logging system.\n");
|
|
|
|
return 0;
|
2009-06-05 21:22:21 -07:00
|
|
|
}
|
2009-09-03 18:48:36 -07:00
|
|
|
_eina_log_dom = eina_log_domain_register("eina", EINA_LOG_COLOR_DEFAULT);
|
|
|
|
if (_eina_log_dom < 0)
|
2009-08-25 14:26:27 -07:00
|
|
|
{
|
2009-09-03 18:48:36 -07:00
|
|
|
EINA_LOG_ERR("Could not register log domain: eina");
|
|
|
|
eina_log_shutdown();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-06 15:21:56 -07:00
|
|
|
itr = _eina_desc_setup;
|
|
|
|
itr_end = itr + _eina_desc_setup_len;
|
|
|
|
for (; itr < itr_end; itr++)
|
2009-09-03 17:53:19 -07:00
|
|
|
{
|
2009-09-06 15:21:56 -07:00
|
|
|
if (!itr->init())
|
|
|
|
{
|
|
|
|
ERR("Could not initialize eina module '%s'.", itr->name);
|
|
|
|
_eina_shutdown_from_desc(itr);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-03 17:53:19 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 15:21:56 -07:00
|
|
|
_eina_main_count = 1;
|
|
|
|
return 1;
|
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-09-06 15:21:56 -07:00
|
|
|
* it shut down all the Eina modules.
|
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)
|
|
|
|
{
|
2009-09-06 15:21:56 -07:00
|
|
|
_eina_main_count--;
|
|
|
|
if (EINA_UNLIKELY(_eina_main_count == 0))
|
|
|
|
_eina_shutdown_from_desc(_eina_desc_setup + _eina_desc_setup_len);
|
|
|
|
return _eina_main_count;
|
2008-08-06 08:37:29 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 13:03:58 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|