* API break: _shutdown() functions return an int, now

* simplify a bit and fix init/shutdown functions



SVN revision: 42996
This commit is contained in:
Vincent Torri 2009-10-10 06:19:13 +00:00
parent 4072d0b23d
commit 285297dcdd
13 changed files with 156 additions and 124 deletions

View File

@ -45,7 +45,7 @@ extern "C" {
EAPI int efreet_mime_init(void); EAPI int efreet_mime_init(void);
EAPI void efreet_mime_shutdown(void); EAPI int efreet_mime_shutdown(void);
EAPI const char *efreet_mime_type_get(const char *file); EAPI const char *efreet_mime_type_get(const char *file);
EAPI const char *efreet_mime_magic_type_get(const char *file); EAPI const char *efreet_mime_magic_type_get(const char *file);

View File

@ -42,7 +42,7 @@ extern "C" {
*/ */
EAPI int efreet_trash_init(void); EAPI int efreet_trash_init(void);
EAPI void efreet_trash_shutdown(void); EAPI int efreet_trash_shutdown(void);
EAPI const char *efreet_trash_dir_get(void); EAPI const char *efreet_trash_dir_get(void);
EAPI int efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete); EAPI int efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete);

View File

@ -14,7 +14,7 @@
#include "efreet_private.h" #include "efreet_private.h"
#include "efreet_xml.h" #include "efreet_xml.h"
static int init = 0; static int _efreet_init_count = 0;
static int efreet_parsed_locale = 0; static int efreet_parsed_locale = 0;
static char *efreet_lang = NULL; static char *efreet_lang = NULL;
static char *efreet_lang_country = NULL; static char *efreet_lang_country = NULL;
@ -30,21 +30,55 @@ static int efreet_parse_locale_setting(const char *env);
EAPI int EAPI int
efreet_init(void) efreet_init(void)
{ {
if (init++) return init; if (++_efreet_init_count != 1)
if (!eina_init()) return --init; return _efreet_init_count;
_efreet_log_domain_global = eina_log_domain_register("Efreet",EFREET_DEFAULT_LOG_COLOR);
if(_efreet_log_domain_global < 0) if (!eina_init())
{ return --_efreet_init_count;
printf("Efreet could create a general log domain.\n"); _efreet_log_domain_global = eina_log_domain_register("Efreet", EFREET_DEFAULT_LOG_COLOR);
return --init; if (_efreet_log_domain_global < 0)
} {
if (!efreet_base_init()) return --init; printf("Efreet could create a general log domain.\n");
if (!efreet_xml_init()) return --init;
if (!efreet_icon_init()) return --init; goto shutdown_eina;
if (!efreet_ini_init()) return --init; }
if (!efreet_desktop_init()) return --init;
if (!efreet_menu_init()) return --init; if (!efreet_base_init())
return init; goto unregister_log_domain;
if (!efreet_xml_init())
goto shutdown_efreet_base;
if (!efreet_icon_init())
goto shutdown_efreet_xml;
if (!efreet_ini_init())
goto shutdown_efreet_icon;
if (!efreet_desktop_init())
goto shutdown_efreet_ini;
if (!efreet_menu_init())
goto shutdown_efreet_desktop;
return _efreet_init_count;
shutdown_efreet_desktop:
efreet_desktop_shutdown();
shutdown_efreet_ini:
efreet_ini_shutdown();
shutdown_efreet_icon:
efreet_icon_shutdown();
shutdown_efreet_xml:
efreet_xml_shutdown();
shutdown_efreet_base:
efreet_base_shutdown();
unregister_log_domain:
eina_log_domain_unregister(_efreet_log_domain_global);
shutdown_eina:
eina_shutdown();
return --_efreet_init_count;
} }
/** /**
@ -56,7 +90,9 @@ efreet_init(void)
EAPI int EAPI int
efreet_shutdown(void) efreet_shutdown(void)
{ {
if (--init) return init; if (--_efreet_init_count != 0)
return _efreet_init_count;
efreet_menu_shutdown(); efreet_menu_shutdown();
efreet_desktop_shutdown(); efreet_desktop_shutdown();
efreet_ini_shutdown(); efreet_ini_shutdown();
@ -71,7 +107,7 @@ efreet_shutdown(void)
IF_FREE(efreet_lang_modifier); IF_FREE(efreet_lang_modifier);
efreet_parsed_locale = 0; /* reset this in case they init efreet again */ efreet_parsed_locale = 0; /* reset this in case they init efreet again */
return init; return _efreet_init_count;
} }
/** /**

View File

@ -44,14 +44,12 @@ static Eina_List *efreet_dirs_get(const char *key,
int int
efreet_base_init(void) efreet_base_init(void)
{ {
if (!eina_init()) return 0; _efreet_base_log_dom = eina_log_domain_register("Efreet_base", EFREET_DEFAULT_LOG_COLOR);
_efreet_base_log_dom = eina_log_domain_register("Efreet_base",EFREET_DEFAULT_LOG_COLOR); if (_efreet_base_log_dom < 0)
if(_efreet_base_log_dom < 0) {
{
ERROR("Efreet: Could not create a log domain for efreet_base.\n"); ERROR("Efreet: Could not create a log domain for efreet_base.\n");
eina_shutdown();
return 0; return 0;
} }
return 1; return 1;
} }
@ -71,7 +69,7 @@ efreet_base_shutdown(void)
IF_FREE_LIST(xdg_data_dirs, eina_stringshare_del); IF_FREE_LIST(xdg_data_dirs, eina_stringshare_del);
IF_FREE_LIST(xdg_config_dirs, eina_stringshare_del); IF_FREE_LIST(xdg_config_dirs, eina_stringshare_del);
eina_shutdown(); eina_log_domain_unregister(_efreet_base_log_dom);
} }
/** /**

View File

@ -44,7 +44,6 @@ static Eina_List *efreet_desktop_types = NULL;
*/ */
static int efreet_desktop_command_file_id = 0; static int efreet_desktop_command_file_id = 0;
static int init = 0;
static int cache_flush = 0; static int cache_flush = 0;
#ifdef EFREET_MODULE_LOG_DOM #ifdef EFREET_MODULE_LOG_DOM
@ -142,16 +141,17 @@ static void *efreet_desktop_command_execs_process(Efreet_Desktop_Command *comman
int int
efreet_desktop_init(void) efreet_desktop_init(void)
{ {
if (init++) return init; _efreet_desktop_log_dom = eina_log_domain_register("Efreet_desktop", EFREET_DEFAULT_LOG_COLOR);
if (!eina_init()) return --init; if (_efreet_desktop_log_dom < 0)
_efreet_desktop_log_dom = eina_log_domain_register("Efreet_desktop",EFREET_DEFAULT_LOG_COLOR); {
if(_efreet_desktop_log_dom<0)
{
ERROR("Efreet: Could not create a log domain for Efreet_desktop"); ERROR("Efreet: Could not create a log domain for Efreet_desktop");
eina_shutdown(); return 0;
return --init; }
} if (!ecore_file_init())
if (!ecore_file_init()) return --init; {
eina_log_domain_unregister(_efreet_desktop_log_dom);
return 0;
}
efreet_desktop_cache = eina_hash_string_superfast_new(NULL); efreet_desktop_cache = eina_hash_string_superfast_new(NULL);
efreet_desktop_types = NULL; efreet_desktop_types = NULL;
@ -166,7 +166,7 @@ efreet_desktop_init(void)
EFREET_DESKTOP_TYPE_DIRECTORY = efreet_desktop_type_add("Directory", NULL, EFREET_DESKTOP_TYPE_DIRECTORY = efreet_desktop_type_add("Directory", NULL,
NULL, NULL); NULL, NULL);
return init; return 1;
} }
/** /**
@ -174,15 +174,11 @@ efreet_desktop_init(void)
* @returns the number of initializations left for this system * @returns the number of initializations left for this system
* @brief Attempts to shut down the subsystem if nothing else is using it * @brief Attempts to shut down the subsystem if nothing else is using it
*/ */
int void
efreet_desktop_shutdown(void) efreet_desktop_shutdown(void)
{ {
Efreet_Desktop_Type_Info *info; Efreet_Desktop_Type_Info *info;
if (--init) return init;
ecore_file_shutdown();
eina_shutdown();
eina_log_domain_unregister(_efreet_desktop_log_dom);
IF_RELEASE(desktop_environment); IF_RELEASE(desktop_environment);
IF_FREE_HASH(efreet_desktop_cache); IF_FREE_HASH(efreet_desktop_cache);
while (efreet_desktop_types) while (efreet_desktop_types)
@ -192,8 +188,8 @@ efreet_desktop_shutdown(void)
efreet_desktop_types = eina_list_remove_list(efreet_desktop_types, efreet_desktop_types = eina_list_remove_list(efreet_desktop_types,
efreet_desktop_types); efreet_desktop_types);
} }
ecore_file_shutdown();
return init; eina_log_domain_unregister(_efreet_desktop_log_dom);
} }
/** /**

View File

@ -26,8 +26,6 @@ static Eina_List *efreet_icon_extensions = NULL;
static Eina_List *efreet_extra_icon_dirs = NULL; static Eina_List *efreet_extra_icon_dirs = NULL;
static Eina_Hash *efreet_icon_cache = NULL; static Eina_Hash *efreet_icon_cache = NULL;
static int efreet_icon_init_count = 0;
typedef struct Efreet_Icon_Cache Efreet_Icon_Cache; typedef struct Efreet_Icon_Cache Efreet_Icon_Cache;
struct Efreet_Icon_Cache struct Efreet_Icon_Cache
{ {
@ -121,9 +119,6 @@ _efreet_icon_cache_list_destroy(Eina_List *list)
int int
efreet_icon_init(void) efreet_icon_init(void)
{ {
if (efreet_icon_init_count++ > 0)
return efreet_icon_init_count;
if (!efreet_icon_themes) if (!efreet_icon_themes)
{ {
const char *default_exts[] = {".png", ".xpm", NULL}; const char *default_exts[] = {".png", ".xpm", NULL};
@ -131,7 +126,6 @@ efreet_icon_init(void)
if (!ecore_init()) if (!ecore_init())
{ {
efreet_icon_init_count--;
return 0; return 0;
} }
@ -156,9 +150,6 @@ efreet_icon_init(void)
void void
efreet_icon_shutdown(void) efreet_icon_shutdown(void)
{ {
if (--efreet_icon_init_count)
return;
IF_FREE(efreet_icon_user_dir); IF_FREE(efreet_icon_user_dir);
IF_FREE(efreet_icon_deprecated_user_dir); IF_FREE(efreet_icon_deprecated_user_dir);
@ -175,7 +166,6 @@ efreet_icon_shutdown(void)
} }
ecore_shutdown(); ecore_shutdown();
efreet_icon_init_count = 0;
} }
/** /**

View File

@ -46,11 +46,6 @@ efreet_ini_section_save(const Eina_Hash *hash, const void *key, void *data, void
static Eina_Bool static Eina_Bool
efreet_ini_value_save(const Eina_Hash *hash, const void *key, void *data, void *fdata); efreet_ini_value_save(const Eina_Hash *hash, const void *key, void *data, void *fdata);
/**
* The number of times the Ini subsytem has been initialized
*/
static int init = 0;
/** /**
* @internal * @internal
* @return Returns > 0 on success or 0 on failure * @return Returns > 0 on success or 0 on failure
@ -59,16 +54,13 @@ static int init = 0;
int int
efreet_ini_init(void) efreet_ini_init(void)
{ {
if (init++) return init; _efreet_ini_log_dom = eina_log_domain_register("Efreet_init", EFREET_DEFAULT_LOG_COLOR);
if (!eina_init()) return --init; if (_efreet_ini_log_dom < 0)
_efreet_ini_log_dom = eina_log_domain_register("Efreet_init",EFREET_DEFAULT_LOG_COLOR); {
if(_efreet_ini_log_dom < 0)
{
ERROR("Efreet: Could not create a log domain for efreet_init"); ERROR("Efreet: Could not create a log domain for efreet_init");
eina_shutdown(); return 0;
return --init; }
} return 1;
return init;
} }
/** /**
@ -76,13 +68,10 @@ efreet_ini_init(void)
* @returns the number of initializations left for this system * @returns the number of initializations left for this system
* @brief Attempts to shut down the subsystem if nothing else is using it * @brief Attempts to shut down the subsystem if nothing else is using it
*/ */
int void
efreet_ini_shutdown(void) efreet_ini_shutdown(void)
{ {
if (--init) return init;
eina_log_domain_unregister(_efreet_ini_log_dom); eina_log_domain_unregister(_efreet_ini_log_dom);
eina_shutdown();
return init;
} }
/** /**

View File

@ -460,15 +460,18 @@ efreet_menu_init(void)
{NULL, NULL} {NULL, NULL}
}; };
if (!eina_init()) return 0; _efreet_menu_log_dom = eina_log_domain_register("Efreet_menu", EFREET_DEFAULT_LOG_COLOR);
_efreet_menu_log_dom = eina_log_domain_register("Efreet_menu",EFREET_DEFAULT_LOG_COLOR); if (_efreet_menu_log_dom < 0)
if(_efreet_menu_log_dom < 0) {
{ ERROR("Efreet: Could not create a log domain for Efreet_menu");
ERROR("Efreet: Could not create a log domain for Efreet_mnenu");
eina_shutdown();
return 0; return 0;
} }
if (!efreet_xml_init()) return 0; if (!efreet_xml_init())
{
ERROR("Efreet: Could not init xml module");
eina_log_domain_unregister(_efreet_menu_log_dom);
return 0;
}
efreet_menu_handle_cbs = eina_hash_string_superfast_new(NULL); efreet_menu_handle_cbs = eina_hash_string_superfast_new(NULL);
efreet_menu_filter_cbs = eina_hash_string_superfast_new(NULL); efreet_menu_filter_cbs = eina_hash_string_superfast_new(NULL);
@ -476,7 +479,11 @@ efreet_menu_init(void)
efreet_menu_layout_cbs = eina_hash_string_superfast_new(NULL); efreet_menu_layout_cbs = eina_hash_string_superfast_new(NULL);
if (!efreet_menu_handle_cbs || !efreet_menu_filter_cbs if (!efreet_menu_handle_cbs || !efreet_menu_filter_cbs
|| !efreet_menu_move_cbs || !efreet_menu_layout_cbs) || !efreet_menu_move_cbs || !efreet_menu_layout_cbs)
return 0; {
efreet_xml_shutdown();
eina_log_domain_unregister(_efreet_menu_log_dom);
return 0;
}
/* set Menu into it's own so we can check the XML is valid before trying /* set Menu into it's own so we can check the XML is valid before trying
* to handle it */ * to handle it */
@ -589,7 +596,6 @@ efreet_menu_shutdown(void)
efreet_xml_shutdown(); efreet_xml_shutdown();
eina_log_domain_unregister(_efreet_menu_log_dom); eina_log_domain_unregister(_efreet_menu_log_dom);
eina_shutdown();
} }
/** /**

View File

@ -54,7 +54,7 @@ static Eina_Hash *wild = NULL; /* contains *.ext and mime.types globs*/
static Eina_Hash *monitors = NULL; /* contains file monitors */ static Eina_Hash *monitors = NULL; /* contains file monitors */
static Eina_Hash *mime_icons = NULL; /* contains cache with mime->icons */ static Eina_Hash *mime_icons = NULL; /* contains cache with mime->icons */
static Eina_Inlist *mime_icons_lru = NULL; static Eina_Inlist *mime_icons_lru = NULL;
static unsigned int _init_count = 0; static unsigned int _efreet_mime_init_count = 0;
/** /**
* @internal * @internal
@ -202,26 +202,25 @@ static void efreet_mime_icons_debug(void);
EAPI int EAPI int
efreet_mime_init(void) efreet_mime_init(void)
{ {
_init_count++; if (++_efreet_mime_init_count != 1)
if (_init_count > 1) return _efreet_mime_init_count;
return 1;
if (!ecore_init()) if (!ecore_init())
return 0; return --_efreet_mime_init_count;
if (!ecore_file_init()) if (!ecore_file_init())
return 0; goto shutdown_ecore;
if (!efreet_init()) if (!efreet_init())
return 0; goto shutdown_ecore_file;
_efreet_mime_log_dom = eina_log_domain_register("Efreet_mime",EFREET_DEFAULT_LOG_COLOR); _efreet_mime_log_dom = eina_log_domain_register("Efreet_mime", EFREET_DEFAULT_LOG_COLOR);
if(_efreet_mime_log_dom < 0) if (_efreet_mime_log_dom < 0)
{ {
ERROR("Efreet: Could not create a log domain for Efreet_mime."); ERROR("Efreet: Could not create a log domain for Efreet_mime.");
return 0; goto shutdown_efreet;
} }
efreet_mime_endianess = efreet_mime_endian_check(); efreet_mime_endianess = efreet_mime_endian_check();
@ -230,23 +229,31 @@ efreet_mime_init(void)
efreet_mime_type_cache_clear(); efreet_mime_type_cache_clear();
if (!efreet_mime_init_files()) if (!efreet_mime_init_files())
return 0; goto unregister_log_domain;
return 1; return _efreet_mime_init_count;
unregister_log_domain:
eina_log_domain_unregister(_efreet_mime_log_dom);
shutdown_efreet:
efreet_shutdown();
shutdown_ecore_file:
ecore_file_shutdown();
shutdown_ecore:
ecore_shutdown();
return --_efreet_mime_init_count;
} }
/** /**
* @return Returns no value * @return Returns no value
* @brief Cleans up the efreet mime settings system * @brief Cleans up the efreet mime settings system
*/ */
EAPI void EAPI int
efreet_mime_shutdown(void) efreet_mime_shutdown(void)
{ {
if (_init_count == 0) if (--_efreet_mime_init_count != 0)
return; return _efreet_mime_init_count;
_init_count--;
if (_init_count > 0)
return;
efreet_mime_icons_debug(); efreet_mime_icons_debug();
@ -259,6 +266,8 @@ efreet_mime_shutdown(void)
efreet_shutdown(); efreet_shutdown();
ecore_file_shutdown(); ecore_file_shutdown();
ecore_shutdown(); ecore_shutdown();
return _efreet_mime_init_count;
} }
/** /**

View File

@ -192,10 +192,10 @@ Eina_List *efreet_default_dirs_get(const char *user_dir,
const char *suffix); const char *suffix);
int efreet_ini_init(void); int efreet_ini_init(void);
int efreet_ini_shutdown(void); void efreet_ini_shutdown(void);
int efreet_desktop_init(void); int efreet_desktop_init(void);
int efreet_desktop_shutdown(void); void efreet_desktop_shutdown(void);
const char *efreet_home_dir_get(void); const char *efreet_home_dir_get(void);

View File

@ -14,6 +14,7 @@
#include "Efreet_Trash.h" #include "Efreet_Trash.h"
#include "efreet_private.h" #include "efreet_private.h"
static unsigned int _efreet_trash_init_count = 0;
static const char *efreet_trash_dir = NULL; static const char *efreet_trash_dir = NULL;
/* define macros and variable for using the eina logging system */ /* define macros and variable for using the eina logging system */
@ -31,24 +32,37 @@ static int _efreet_trash_log_dom = -1;
EAPI int EAPI int
efreet_trash_init(void) efreet_trash_init(void)
{ {
_efreet_trash_log_dom = eina_log_domain_register("Efreet_trash",EFREET_DEFAULT_LOG_COLOR); if (++_efreet_trash_init_count != 1)
if(_efreet_trash_log_dom < 0) return _efreet_trash_init_count;
{
if (!eina_init())
return --_efreet_trash_init_count;
_efreet_trash_log_dom = eina_log_domain_register("Efreet_trash", EFREET_DEFAULT_LOG_COLOR);
if (_efreet_trash_log_dom < 0)
{
ERROR("Efreet: Could not create a log domain for Efreet_trash"); ERROR("Efreet: Could not create a log domain for Efreet_trash");
return 0; eina_shutdown();
return --_efreet_trash_init_count;
} }
return 1; return _efreet_trash_init_count;
} }
/** /**
* @return Returns no value * @return Returns no value
* @brief Cleans up the efreet trash system * @brief Cleans up the efreet trash system
*/ */
EAPI void EAPI int
efreet_trash_shutdown(void) efreet_trash_shutdown(void)
{ {
if (--_efreet_trash_init_count != 0)
return _efreet_trash_init_count;
IF_RELEASE(efreet_trash_dir); IF_RELEASE(efreet_trash_dir);
eina_log_domain_unregister(_efreet_trash_log_dom); eina_log_domain_unregister(_efreet_trash_log_dom);
eina_shutdown();
return _efreet_trash_init_count;
} }
/** /**

View File

@ -36,7 +36,6 @@ static void efreet_xml_cb_attribute_free(void *data);
static void efreet_xml_comment_skip(char **data, int *size); static void efreet_xml_comment_skip(char **data, int *size);
static int error = 0; static int error = 0;
static int init = 0;
/* define macros and variable for using the eina logging system */ /* define macros and variable for using the eina logging system */
@ -55,15 +54,13 @@ static int _efreet_xml_log_dom = -1;
int int
efreet_xml_init(void) efreet_xml_init(void)
{ {
if (init++) return init; _efreet_xml_log_dom = eina_log_domain_register("Efreet_xml", EFREET_DEFAULT_LOG_COLOR);
if (!eina_init()) return --init; if (_efreet_xml_log_dom < 0)
_efreet_xml_log_dom = eina_log_domain_register("Efreet_xml",EFREET_DEFAULT_LOG_COLOR); {
if(_efreet_xml_log_dom < 0)
{
ERROR("Efreet: Could not create a log domain for Efreet_xml."); ERROR("Efreet: Could not create a log domain for Efreet_xml.");
return 0; return 0;
} }
return init; return 1;
} }
/** /**
@ -71,13 +68,10 @@ efreet_xml_init(void)
* @returns the number of initializations left for this system * @returns the number of initializations left for this system
* @brief Attempts to shut down the subsystem if nothing else is using it * @brief Attempts to shut down the subsystem if nothing else is using it
*/ */
int void
efreet_xml_shutdown(void) efreet_xml_shutdown(void)
{ {
if (--init) return init;
eina_log_domain_unregister(_efreet_xml_log_dom); eina_log_domain_unregister(_efreet_xml_log_dom);
eina_shutdown();
return init;
} }
/** /**

View File

@ -46,7 +46,7 @@ struct Efreet_Xml
}; };
int efreet_xml_init(void); int efreet_xml_init(void);
int efreet_xml_shutdown(void); void efreet_xml_shutdown(void);
Efreet_Xml *efreet_xml_new(const char *file); Efreet_Xml *efreet_xml_new(const char *file);
void efreet_xml_del(Efreet_Xml *xml); void efreet_xml_del(Efreet_Xml *xml);