2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
22 #include <sys/types.h>
33 #include "critical_log.h"
38 HAPI int util_check_ext(const char *icon, const char *ext)
42 len = strlen(icon) - 1;
43 while (len >= 0 && *ext && icon[len] == *ext) {
51 HAPI int util_get_filesize(const char *filename)
55 if (stat(filename, &buf) < 0) {
56 ErrPrint("error: %s\n", strerror(errno));
60 if (!S_ISREG(buf.st_mode)) {
61 ErrPrint("%s is not a file\n", filename);
68 HAPI double util_timestamp(void)
72 gettimeofday(&tv, NULL);
74 return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
77 HAPI const char *util_basename(const char *name)
81 length = name ? strlen(name) : 0;
85 while (--length > 0 && name[length] != '/');
87 return length <= 0 ? name : name + length + (name[length] == '/');
92 * Just trying to find the nearest module.
95 HAPI char *util_get_current_module(char **symbol)
102 unsigned int stack_boundary = 0;
103 unsigned int stack_size = 0;
106 if (!pthread_getattr_np(pthread_self(), &attr)) {
107 if (!pthread_attr_getstack(&attr, (void *)&stack_boundary, &stack_size))
108 stack_boundary += stack_size;
109 pthread_attr_destroy(&attr);
113 for (i = 0, stack = (int *)&stack; (unsigned int)stack < stack_boundary ; stack++, i++) {
114 if (!dladdr((void *)*stack, &dinfo))
117 ptr = util_basename(dinfo.dli_fname);
118 if (strncmp(ptr, "liblive-", strlen("liblive-"))) {
119 DbgPrint("[%d] fname[%s] symbol[%s]\n", i, dinfo.dli_fname, dinfo.dli_sname);
121 if (!strcmp(ptr, EXEC_NAME))
132 *symbol = strdup(dinfo.dli_sname);
142 HAPI const char *util_uri_to_path(const char *uri)
146 len = strlen(SCHEMA_FILE);
147 if (strncasecmp(uri, SCHEMA_FILE, len))
153 HAPI double util_time_delay_for_compensation(double period)
156 unsigned long long curtime;
157 unsigned long long _period;
158 unsigned long long remain;
163 gettimeofday(&tv, NULL);
164 curtime = (unsigned long long)tv.tv_sec * 1000000llu + (unsigned long long)tv.tv_usec;
166 sec = (unsigned int)period;
167 usec = (period - sec) * 1000000;
168 _period = (unsigned long long)sec * 1000000llu + usec;
170 remain = curtime % _period;
172 sec = (unsigned int)(remain / 1000000llu);
173 usec = (unsigned int)(remain % 1000000llu);
175 ret = (double)sec + (double)usec / 1000000.0f;
179 HAPI void *util_timer_add(double interval, Eina_Bool (*cb)(void *data), void *data)
184 timer = ecore_timer_add(interval, cb, data);
188 delay = util_time_delay_for_compensation(interval) - interval;
189 ecore_timer_delay(timer, delay);
190 DbgPrint("Compensate timer: %lf\n", delay);
195 HAPI void util_timer_interval_set(void *timer, double interval)
198 ecore_timer_interval_set(timer, interval);
200 delay = util_time_delay_for_compensation(interval) - interval;
201 ecore_timer_delay(timer, delay);