2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "sst_utils_wrapper.h"
22 static void *sst_utils_handle;
23 static const char* const sst_utils_library = SETTING_UTILS_SO_FILE_PATH;
25 static void* _utils_load_lib()
28 return sst_utils_handle;
30 sst_utils_handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
31 if (NULL == sst_utils_handle) {
32 ERR("dlopen(%s) Fail", sst_utils_library);
35 return sst_utils_handle;
38 bool sstu_set_font_config(const char *font_name)
40 static bool (*fn_impl)(const char*);
42 return fn_impl(font_name);
44 void *handle = _utils_load_lib();
46 ERR("No Utils Library Handle");
50 fn_impl = dlsym(handle, "sstu_set_font_config");
51 char *error = dlerror();
53 ERR("dlsym(sstu_set_font_config) Fail(%s)", error);
57 return fn_impl(font_name);
60 int sstu_is_available_font(const char *font_name)
62 static int (*fn_impl)(const char*) = NULL;
64 return fn_impl(font_name);
66 void *handle = _utils_load_lib();
68 ERR("No Utils Library Handle");
72 fn_impl = dlsym(handle, "sstu_is_available_font");
73 char *error = dlerror();
75 ERR("dlsym(sstu_is_available_font) Fail(%s)", error);
79 return fn_impl(font_name);
82 char* sstu_get_default_font()
84 static char* (*fn_impl)(void) = NULL;
88 void *handle = _utils_load_lib();
90 ERR("No Utils Library Handle");
94 fn_impl = dlsym(handle, "sstu_get_default_font");
95 char *error = dlerror();
97 ERR("dlsym(sstu_get_default_font) Fail(%s)", error);
104 bool sstu_is_valid_image(const char *path)
106 static bool (*fn_impl)(const char*) = NULL;
108 return fn_impl(path);
110 void *handle = _utils_load_lib();
111 if (NULL == handle) {
112 ERR("No Utils Library Handle");
113 return sst_misc_file_exists(path);
116 fn_impl = dlsym(handle, "sstu_is_valid_image");
117 char *error = dlerror();
119 ERR("dlsym(sstu_is_valid_image) Fail(%s)", error);
123 return fn_impl(path);
125 void sstu_set_font_size()
127 static void (*fn_impl)() = NULL;
131 void *handle = _utils_load_lib();
132 if (NULL == handle) {
133 ERR("No Utils Library Handle");
137 fn_impl = dlsym(handle, "sstu_set_font_size");
138 char *error = dlerror();
140 ERR("dlsym(sstu_set_font_size) Fail(%s)", error);
147 void sstu_font_config_set_notification()
149 static void (*fn_impl)() = NULL;
153 void *handle = _utils_load_lib();
154 if (NULL == handle) {
155 ERR("No Utils Library Handle");
159 fn_impl = dlsym(handle, "sstu_font_config_set_notification");
160 char *error = dlerror();
162 ERR("dlsym(sstu_font_config_set_notification) Fail(%s)", error);
169 //It is called after releasing the global variable(sst_utils_handle)
170 //Therefore, It is better to leave as it is.
172 __attribute__((destructor)) static void _utils_unload_lib()
174 dlclose(sst_utils_handle);
175 sst_utils_handle = NULL;