From f940a1d7112293bb70af563b40f1982cbb475289 Mon Sep 17 00:00:00 2001 From: "jinwang.an" Date: Mon, 24 Jun 2019 14:20:35 +0900 Subject: [PATCH] Reduce global variables in system-settings-util Change-Id: Ic6e8f181f8fea504d48a3c770efceb2e0e30fbe4 Signed-off-by: jinwang.an --- .../include/system_settings_font.h | 120 ++++++------- system-settings-util/src/system_settings_util.c | 185 +++++++++++---------- 2 files changed, 161 insertions(+), 144 deletions(-) diff --git a/system-settings-util/include/system_settings_font.h b/system-settings-util/include/system_settings_font.h index 34aef1c..a8ab88b 100644 --- a/system-settings-util/include/system_settings_font.h +++ b/system-settings-util/include/system_settings_font.h @@ -16,83 +16,91 @@ #include #include -FcConfig * -(*d_FcInitLoadConfigAndFonts) (void); +typedef struct _f_libs { + FcConfig * + (*d_FcInitLoadConfigAndFonts) (void); -FcPattern * -(*d_FcPatternBuild) (FcPattern *p, ...); + FcPattern * + (*d_FcPatternBuild) (FcPattern *p, ...); -void -(*d_FcConfigDestroy) (FcConfig *config); + void + (*d_FcConfigDestroy) (FcConfig *config); -FcBool -(*d_FcConfigSubstitute) (FcConfig *config, - FcPattern *p, - FcMatchKind kind); + FcBool + (*d_FcConfigSubstitute) (FcConfig *config, + FcPattern *p, + FcMatchKind kind); -void -(*d_FcDefaultSubstitute) (FcPattern *pattern); + void + (*d_FcDefaultSubstitute) (FcPattern *pattern); -FcFontSet * -(*d_FcFontSort) (FcConfig *config, - FcPattern *p, - FcBool trim, - FcCharSet **csp, - FcResult *result); + FcFontSet * + (*d_FcFontSort) (FcConfig *config, + FcPattern *p, + FcBool trim, + FcCharSet **csp, + FcResult *result); -FcResult -(*d_FcPatternGetString) (const FcPattern *p, const char *object, int n, FcChar8 ** s); + FcResult + (*d_FcPatternGetString) (const FcPattern *p, const char *object, int n, FcChar8 ** s); -void -(*d_FcFontSetDestroy) (FcFontSet *s); + void + (*d_FcFontSetDestroy) (FcFontSet *s); -void -(*d_FcPatternDestroy) (FcPattern *p); + void + (*d_FcPatternDestroy) (FcPattern *p); -FcPattern * -(*d_FcPatternCreate) (void); + FcPattern * + (*d_FcPatternCreate) (void); -FcObjectSet * -(*d_FcObjectSetBuild) (const char *first, ...); + FcObjectSet * + (*d_FcObjectSetBuild) (const char *first, ...); -FcFontSet * -(*d_FcFontList) (FcConfig *config, - FcPattern *p, - FcObjectSet *os); + FcFontSet * + (*d_FcFontList) (FcConfig *config, + FcPattern *p, + FcObjectSet *os); -void -(*d_FcObjectSetDestroy) (FcObjectSet *os); + void + (*d_FcObjectSetDestroy) (FcObjectSet *os); +}f_libs; -int -(*d_evas_init) (void); -void * -(*d_ecore_evas_new) (const char *engine_name, int x, int y, int w, int h, const char *extra_options); +typedef struct _e_libs { + int + (*d_evas_init) (void); -void * -(*d_ecore_evas_get) (const void *ee); + void * + (*d_ecore_evas_new) (const char *engine_name, int x, int y, int w, int h, const char *extra_options); -void * -(*d_evas_object_image_add) (void *eo_e); + void * + (*d_ecore_evas_get) (const void *ee); -void -(*d_evas_object_image_file_set) (void *obj, const char *file, const char *key); + void * + (*d_evas_object_image_add) (void *eo_e); -int -(*d_evas_object_image_load_error_get) (const void *obj); + void + (*d_evas_object_image_file_set) (void *obj, const char *file, const char *key); -void -(*d_ecore_evas_free) (void *ee); + int + (*d_evas_object_image_load_error_get) (const void *obj); -int -(*d_evas_shutdown) (void); + void + (*d_ecore_evas_free) (void *ee); + int + (*d_evas_shutdown) (void); -bool -(*d_eext_config_font_set)(char *name, int size); + int + (*d_ecore_evas_init) (void); -int -(*d_ecore_evas_init) (void); + int + (*d_ecore_evas_shutdown) (void); +}e_libs; + + +typedef struct _eext_libs { + bool + (*d_eext_config_font_set)(char *name, int size); +}ex_libs; -int -(*d_ecore_evas_shutdown) (void); diff --git a/system-settings-util/src/system_settings_util.c b/system-settings-util/src/system_settings_util.c index 410bbe4..93067b2 100644 --- a/system-settings-util/src/system_settings_util.c +++ b/system-settings-util/src/system_settings_util.c @@ -64,61 +64,63 @@ void *d_efl_eext_handle = NULL; #define DYM_FUNC_LOADING(error, handle, pfunc, func_name) do { \ - pfunc = (void*)dlsym(handle, func_name); \ - if ((error = dlerror()) != NULL) { \ - SETTING_TRACE("ERROR!! canNOT find %s function at %s", func_name, #handle); \ - if (handle) \ - dlclose(handle); \ - return false; \ - } \ - } while (0) + pfunc = (void*)dlsym(handle, func_name); \ + if ((error = dlerror()) != NULL) { \ + SETTING_TRACE("ERROR!! canNOT find %s function at %s", func_name, #handle); \ + if (handle) \ + dlclose(handle); \ + return false; \ + } \ +} while (0) #define DYM_CLOSE_HANDLE(handle) do { \ - if (handle) { \ - dlclose(handle); \ - handle = NULL; \ - } \ - } while (0) + if (handle) { \ + dlclose(handle); \ + handle = NULL; \ + } \ +} while (0) - - - -int loading_dym_font() +int loading_dym_font(f_libs *font_lib) { char *error = NULL; + if (!font_lib) + return false; + if (!d_font_handle) { - d_font_handle = dlopen(SETTING_FONT_CONFIG_SO_PATH, RTLD_LAZY); + d_font_handle = dlopen(SETTING_FONT_CONFIG_SO_PATH, RTLD_LAZY); if (!d_font_handle) { SETTING_TRACE("ERROR!! canNOT find "SETTING_FONT_CONFIG_SO_PATH); return false; } } - DYM_FUNC_LOADING(error, d_font_handle, d_FcInitLoadConfigAndFonts, "FcInitLoadConfigAndFonts"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcPatternBuild, "FcPatternBuild"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcConfigDestroy, "FcConfigDestroy"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcConfigSubstitute, "FcConfigSubstitute"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcDefaultSubstitute, "FcDefaultSubstitute"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcFontSort, "FcFontSort"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcPatternGetString, "FcPatternGetString"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcFontSetDestroy, "FcFontSetDestroy"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcPatternDestroy, "FcPatternDestroy"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcPatternCreate, "FcPatternCreate"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcObjectSetBuild, "FcObjectSetBuild"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcFontList, "FcFontList"); - DYM_FUNC_LOADING(error, d_font_handle, d_FcObjectSetDestroy, "FcObjectSetDestroy"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcInitLoadConfigAndFonts, "FcInitLoadConfigAndFonts"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcPatternBuild, "FcPatternBuild"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcConfigDestroy, "FcConfigDestroy"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcConfigSubstitute, "FcConfigSubstitute"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcDefaultSubstitute, "FcDefaultSubstitute"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcFontSort, "FcFontSort"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcPatternGetString, "FcPatternGetString"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcFontSetDestroy, "FcFontSetDestroy"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcPatternDestroy, "FcPatternDestroy"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcPatternCreate, "FcPatternCreate"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcObjectSetBuild, "FcObjectSetBuild"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcFontList, "FcFontList"); + DYM_FUNC_LOADING(error, d_font_handle, font_lib->d_FcObjectSetDestroy, "FcObjectSetDestroy"); return true; - } -int loading_dym_efl() +int loading_dym_efl(e_libs *efl_libs) { char *error = NULL; + if (!efl_libs) + return false; + if (!d_ecore_evas_handle) { - d_ecore_evas_handle = dlopen(SETTING_ECORE_EVAS_SO_PATH, RTLD_LAZY); + d_ecore_evas_handle = dlopen(SETTING_ECORE_EVAS_SO_PATH, RTLD_LAZY); if (!d_ecore_evas_handle) { SETTING_TRACE("ERROR!! canNOT find "SETTING_ECORE_EVAS_SO_PATH" %s", dlerror()); @@ -127,24 +129,24 @@ int loading_dym_efl() } if (!d_evas_handle) { - d_evas_handle = dlopen(SETTING_EVAS_SO_PATH, RTLD_LAZY); + d_evas_handle = dlopen(SETTING_EVAS_SO_PATH, RTLD_LAZY); if (!d_evas_handle) { SETTING_TRACE("ERROR!! canNOT find "SETTING_EVAS_SO_PATH" %s", dlerror()); return false; } } - DYM_FUNC_LOADING(error, d_evas_handle, d_evas_init, "evas_init"); - DYM_FUNC_LOADING(error, d_evas_handle, d_evas_object_image_add, "evas_object_image_add"); - DYM_FUNC_LOADING(error, d_evas_handle, d_evas_object_image_file_set, "evas_object_image_file_set"); - DYM_FUNC_LOADING(error, d_evas_handle, d_evas_object_image_load_error_get, "evas_object_image_load_error_get"); - DYM_FUNC_LOADING(error, d_evas_handle, d_evas_shutdown, "evas_shutdown"); + DYM_FUNC_LOADING(error, d_evas_handle, efl_libs->d_evas_init, "evas_init"); + DYM_FUNC_LOADING(error, d_evas_handle, efl_libs->d_evas_object_image_add, "evas_object_image_add"); + DYM_FUNC_LOADING(error, d_evas_handle, efl_libs->d_evas_object_image_file_set, "evas_object_image_file_set"); + DYM_FUNC_LOADING(error, d_evas_handle, efl_libs->d_evas_object_image_load_error_get, "evas_object_image_load_error_get"); + DYM_FUNC_LOADING(error, d_evas_handle, efl_libs->d_evas_shutdown, "evas_shutdown"); - DYM_FUNC_LOADING(error, d_ecore_evas_handle, d_ecore_evas_init, "ecore_evas_init"); - DYM_FUNC_LOADING(error, d_ecore_evas_handle, d_ecore_evas_shutdown, "ecore_evas_shutdown"); - DYM_FUNC_LOADING(error, d_ecore_evas_handle, d_ecore_evas_new, "ecore_evas_new"); - DYM_FUNC_LOADING(error, d_ecore_evas_handle, d_ecore_evas_get, "ecore_evas_get"); - DYM_FUNC_LOADING(error, d_ecore_evas_handle, d_ecore_evas_free, "ecore_evas_free"); + DYM_FUNC_LOADING(error, d_ecore_evas_handle, efl_libs->d_ecore_evas_init, "ecore_evas_init"); + DYM_FUNC_LOADING(error, d_ecore_evas_handle, efl_libs->d_ecore_evas_shutdown, "ecore_evas_shutdown"); + DYM_FUNC_LOADING(error, d_ecore_evas_handle, efl_libs->d_ecore_evas_new, "ecore_evas_new"); + DYM_FUNC_LOADING(error, d_ecore_evas_handle, efl_libs->d_ecore_evas_get, "ecore_evas_get"); + DYM_FUNC_LOADING(error, d_ecore_evas_handle, efl_libs->d_ecore_evas_free, "ecore_evas_free"); return true; } @@ -155,10 +157,13 @@ void close_dym_efl() DYM_CLOSE_HANDLE(d_ecore_evas_handle); } -int loading_dym_efl_eext() +int loading_dym_efl_eext(ex_libs *eext_libs) { char *error = NULL; + if (!eext_libs) + return false; + if (!d_efl_eext_handle) { d_efl_eext_handle = dlopen(SETTING_EFL_EXTENSION_SO_PATH, RTLD_LAZY); if (!d_efl_eext_handle) { @@ -167,8 +172,7 @@ int loading_dym_efl_eext() } } - - DYM_FUNC_LOADING(error, d_efl_eext_handle, d_eext_config_font_set, "eext_config_font_set"); + DYM_FUNC_LOADING(error, d_efl_eext_handle, eext_libs->d_eext_config_font_set, "eext_config_font_set"); return true; } @@ -183,53 +187,54 @@ char *__get_main_font_family_name_by_alias(char *alias) FcChar8 *family = NULL; char *ret = NULL; FcResult res = 0; + f_libs font_libs; - if (!loading_dym_font()) + if (!loading_dym_font(&font_libs)) return NULL; - font_config = d_FcInitLoadConfigAndFonts(); + font_config = font_libs.d_FcInitLoadConfigAndFonts(); if (font_config == NULL) { DYM_CLOSE_HANDLE(d_font_handle); return ret; } - pat = d_FcPatternBuild(0, FC_FAMILY, FcTypeString, alias, (char *)0); + pat = font_libs.d_FcPatternBuild(0, FC_FAMILY, FcTypeString, alias, (char *)0); if (pat == NULL) { if (font_config != NULL) { - d_FcConfigDestroy(font_config); + font_libs.d_FcConfigDestroy(font_config); font_config = NULL; } DYM_CLOSE_HANDLE(d_font_handle); return ret; } - d_FcConfigSubstitute(font_config, pat, FcMatchPattern); - d_FcDefaultSubstitute(pat); + font_libs.d_FcConfigSubstitute(font_config, pat, FcMatchPattern); + font_libs.d_FcDefaultSubstitute(pat); /* do matching */ - set = d_FcFontSort(font_config, pat, FcTrue, NULL, &res); + set = font_libs.d_FcFontSort(font_config, pat, FcTrue, NULL, &res); if (set != NULL && (set->nfont > 0)) { - d_FcPatternGetString(set->fonts[0], FC_FAMILY, 0, &family); + font_libs.d_FcPatternGetString(set->fonts[0], FC_FAMILY, 0, &family); ret = g_strdup((char *)family); - d_FcFontSetDestroy(set); + font_libs.d_FcFontSetDestroy(set); set = NULL; } if (set != NULL) { - d_FcFontSetDestroy(set); + font_libs.d_FcFontSetDestroy(set); set = NULL; } if (pat != NULL) { - d_FcPatternDestroy(pat); + font_libs.d_FcPatternDestroy(pat); pat = NULL; } if (font_config != NULL) { - d_FcConfigDestroy(font_config); + font_libs.d_FcConfigDestroy(font_config); font_config = NULL; } DYM_CLOSE_HANDLE(d_font_handle); @@ -240,7 +245,8 @@ char *__get_main_font_family_name_by_alias(char *alias) bool __is_supported_image_type_load(char *path) { SETTING_TRACE_BEGIN; - if (!loading_dym_efl()) { + e_libs efl_libs; + if (!loading_dym_efl(&efl_libs)) { SETTING_TRACE("ERROR!! canNOT loading efl!!"); return false; } @@ -248,17 +254,17 @@ bool __is_supported_image_type_load(char *path) void *ee; void *evas; - if (!d_ecore_evas_init()) { + if (!efl_libs.d_ecore_evas_init()) { close_dym_efl(); return false; } - ee = d_ecore_evas_new(NULL, 0, 0, 100, 100, NULL); - evas = d_ecore_evas_get(ee); + ee = efl_libs.d_ecore_evas_new(NULL, 0, 0, 100, 100, NULL); + evas = efl_libs.d_ecore_evas_get(ee); - void *img = d_evas_object_image_add(evas); - d_evas_object_image_file_set(img, path, NULL); - int ret = d_evas_object_image_load_error_get(img); + void *img = efl_libs.d_evas_object_image_add(evas); + efl_libs.d_evas_object_image_file_set(img, path, NULL); + int ret = efl_libs.d_evas_object_image_load_error_get(img); bool result = false; if (ret == 0) { @@ -268,8 +274,8 @@ bool __is_supported_image_type_load(char *path) SETTING_TRACE("%s - NO", path); result = false; } - d_ecore_evas_free(ee); - d_ecore_evas_shutdown(); + efl_libs.d_ecore_evas_free(ee); + efl_libs.d_ecore_evas_shutdown(); close_dym_efl(); return result; } @@ -291,8 +297,9 @@ int __is_available_font(char *font_name) FcPattern *pat = NULL; FcConfig *font_config = NULL; int ret = 0; + f_libs font_libs = {0}; - if (!loading_dym_font()) + if (!loading_dym_font(&font_libs)) return -1; if (font_name == NULL) { @@ -300,24 +307,24 @@ int __is_available_font(char *font_name) return -1; } - font_config = d_FcInitLoadConfigAndFonts(); + font_config = font_libs.d_FcInitLoadConfigAndFonts(); /*setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts"); */ char *locale = setlocale(0, NULL); - pat = d_FcPatternCreate(); + pat = font_libs.d_FcPatternCreate(); - os = d_FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, (char *) 0); + os = font_libs.d_FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, (char *) 0); if (os) { - fs = d_FcFontList(font_config, pat, os); - d_FcObjectSetDestroy(os); + fs = font_libs.d_FcFontList(font_config, pat, os); + font_libs.d_FcObjectSetDestroy(os); os = NULL; } if (pat) { - d_FcPatternDestroy(pat); + font_libs.d_FcPatternDestroy(pat); pat = NULL; } @@ -329,19 +336,19 @@ int __is_available_font(char *font_name) FcChar8 *family = NULL; FcChar8 *file = NULL; - if (d_FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) { + if (font_libs.d_FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) { int preload_path_len = strlen(SETTING_FONT_PRELOAD_FONT_PATH); int download_path_len = strlen(SETTING_FONT_DOWNLOADED_FONT_PATH); if (file && (!strncmp((const char *)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len) - || !strncmp((const char *)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len))) { + || !strncmp((const char *)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len))) { char *family_result = NULL; FcChar8 *lang = NULL; int id = 0; - if (d_FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) { + if (font_libs.d_FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) { break; } - if (d_FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) { + if (font_libs.d_FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) { break; } family_result = (char *)family; @@ -360,10 +367,10 @@ int __is_available_font(char *font_name) family_result = (char *)family; } id++; - if (d_FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) { + if (font_libs.d_FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) { break; } - if (d_FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) { + if (font_libs.d_FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) { break; } } @@ -378,10 +385,10 @@ int __is_available_font(char *font_name) } } } - d_FcFontSetDestroy(fs); + font_libs.d_FcFontSetDestroy(fs); fs = NULL; } - d_FcConfigDestroy(font_config); + font_libs.d_FcConfigDestroy(font_config); font_config = NULL; DYM_CLOSE_HANDLE(d_font_handle); return ret; @@ -399,10 +406,11 @@ char *_get_default_font() bool font_config_set(char *font_name) { SETTING_TRACE_BEGIN; - if (!loading_dym_efl_eext()) + ex_libs eext_libs; + if (!loading_dym_efl_eext(&eext_libs)) return false; int font_size = __font_size_get(); - bool ret = d_eext_config_font_set(font_name, font_size); + bool ret = eext_libs.d_eext_config_font_set(font_name, font_size); DYM_CLOSE_HANDLE(d_efl_eext_handle); return ret; } @@ -412,13 +420,14 @@ bool font_config_set(char *font_name) void __font_size_set() { SETTING_TRACE_BEGIN; - if (!loading_dym_efl_eext()) + ex_libs eext_libs; + if (!loading_dym_efl_eext(&eext_libs)) return; int font_size = __font_size_get(); char *font_name = NULL; font_name = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME); - d_eext_config_font_set(font_name, font_size); + eext_libs.d_eext_config_font_set(font_name, font_size); DYM_CLOSE_HANDLE(d_efl_eext_handle); g_free(font_name); -- 2.7.4