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"
23 static void *sst_utils_handle;
24 static const char* const sst_utils_library = SETTING_UTILS_SO_FILE_PATH;
26 static void* _utils_load_lib()
29 return sst_utils_handle;
31 sst_utils_handle = dlopen(sst_utils_library, RTLD_LAZY | RTLD_GLOBAL);
32 if (NULL == sst_utils_handle) {
33 ERR("dlopen(%s) Fail", sst_utils_library);
36 return sst_utils_handle;
39 bool sstu_set_font_config(const char *font_name)
41 static bool (*fn_impl)(const char*);
43 return fn_impl(font_name);
45 void *handle = _utils_load_lib();
47 ERR("No Utils Library Handle");
51 fn_impl = dlsym(handle, "sstu_set_font_config");
52 char *error = dlerror();
54 ERR("dlsym(sstu_set_font_config) Fail(%s)", error);
58 return fn_impl(font_name);
61 int sstu_is_available_font(const char *font_name)
63 static int (*fn_impl)(const char*) = NULL;
65 return fn_impl(font_name);
67 void *handle = _utils_load_lib();
69 ERR("No Utils Library Handle");
73 fn_impl = dlsym(handle, "sstu_is_available_font");
74 char *error = dlerror();
76 ERR("dlsym(sstu_is_available_font) Fail(%s)", error);
80 return fn_impl(font_name);
83 char* sstu_get_default_font()
85 static char* (*fn_impl)(void) = NULL;
89 void *handle = _utils_load_lib();
91 ERR("No Utils Library Handle");
95 fn_impl = dlsym(handle, "sstu_get_default_font");
96 char *error = dlerror();
98 ERR("dlsym(sstu_get_default_font) Fail(%s)", error);
105 bool sstu_is_valid_image(const char *path)
107 if (!sst_misc_file_exists(path))
110 char *ext_list[10] = {"jif", "jfif", "jpe", "jpeg", "jpg",
111 "bmp", "dib", "gif", "png", "webp",
113 char *filename = strrchr(path, '/');
114 if (NULL == filename || '\0' == filename[1])
116 char *ext = strrchr(filename + 1, '.');
117 if (NULL == ext || '\0' == ext[1])
119 for (int i = 0; i < 10; i++) {
120 if (!strcmp(ext + 1, ext_list[i]))
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;