10 #ifdef HAVE_LANGINFO_H
11 # include <langinfo.h>
15 #include "ecore_private.h"
21 static const char *_ecore_magic_string_get(Ecore_Magic m);
22 static int _ecore_init_count = 0;
24 int _ecore_fps_debug = 0;
26 /** OpenBSD does not define CODESET
31 # define CODESET "INVALID"
35 * Set up connections, signal handlers, sockets etc.
36 * @return 1 or greater on success, 0 otherwise
38 * This function sets up all singal handlers and the basic event loop. If it
39 * succeeds, 1 will be returned, otherwise 0 will be returned.
44 * int main(int argc, char **argv)
48 * printf("ERROR: Cannot init Ecore!\n");
51 * ecore_main_loop_begin();
59 if (++_ecore_init_count == 1)
62 setlocale(LC_CTYPE, "");
65 if (strcmp(nl_langinfo(CODESET), "UTF-8"))
67 printf("WARNING: not a utf8 locale!\n");
70 if (getenv("ECORE_FPS_DEBUG")) _ecore_fps_debug = 1;
71 if (_ecore_fps_debug) _ecore_fps_debug_init();
76 return _ecore_init_count;
80 * Shut down connections, signal handlers sockets etc.
82 * This function shuts down all things set up in ecore_init() and cleans up all
83 * event queues, handlers, filters, timers, idlers, idle enterers/exiters
84 * etc. set up after ecore_init() was called.
86 * Do not call this function from any callback that may be called from the main
87 * loop, as the main loop will then fall over and not function properly.
92 if (--_ecore_init_count)
93 return _ecore_init_count;
95 if (_ecore_fps_debug) _ecore_fps_debug_shutdown();
96 _ecore_poller_shutdown();
97 _ecore_animator_shutdown();
98 _ecore_exe_shutdown();
99 _ecore_idle_enterer_shutdown();
100 _ecore_idle_exiter_shutdown();
101 _ecore_idler_shutdown();
102 _ecore_timer_shutdown();
103 _ecore_event_shutdown();
104 _ecore_main_shutdown();
105 _ecore_signal_shutdown();
107 return _ecore_init_count;
111 _ecore_magic_fail(void *d, Ecore_Magic m, Ecore_Magic req_m, const char *fname)
115 "*** ECORE ERROR: Ecore Magic Check Failed!!!\n"
116 "*** IN FUNCTION: %s()\n", fname);
118 fprintf(stderr, " Input handle pointer is NULL!\n");
119 else if (m == ECORE_MAGIC_NONE)
120 fprintf(stderr, " Input handle has already been freed!\n");
122 fprintf(stderr, " Input handle is wrong type\n"
123 " Expected: %08x - %s\n"
124 " Supplied: %08x - %s\n",
125 (unsigned int)req_m, _ecore_magic_string_get(req_m),
126 (unsigned int)m, _ecore_magic_string_get(m));
128 "*** NAUGHTY PROGRAMMER!!!\n"
129 "*** SPANK SPANK SPANK!!!\n"
130 "*** Now go fix your code. Tut tut tut!\n"
132 if (getenv("ECORE_ERROR_ABORT")) abort();
136 _ecore_magic_string_get(Ecore_Magic m)
140 case ECORE_MAGIC_NONE:
141 return "None (Freed Object)";
143 case ECORE_MAGIC_EXE:
144 return "Ecore_Exe (Executable)";
146 case ECORE_MAGIC_TIMER:
147 return "Ecore_Timer (Timer)";
149 case ECORE_MAGIC_IDLER:
150 return "Ecore_Idler (Idler)";
152 case ECORE_MAGIC_IDLE_ENTERER:
153 return "Ecore_Idle_Enterer (Idler Enterer)";
155 case ECORE_MAGIC_IDLE_EXITER:
156 return "Ecore_Idle_Exiter (Idler Exiter)";
158 case ECORE_MAGIC_FD_HANDLER:
159 return "Ecore_Fd_Handler (Fd Handler)";
161 case ECORE_MAGIC_EVENT_HANDLER:
162 return "Ecore_Event_Handler (Event Handler)";
164 case ECORE_MAGIC_EVENT:
165 return "Ecore_Event (Event)";
173 /* fps debug calls - for debugging how much time your app actually spends */
174 /* "running" (and the inverse being time spent running)... this does not */
175 /* account for other apps and multitasking... */
177 static int _ecore_fps_debug_init_count = 0;
178 static int _ecore_fps_debug_fd = -1;
179 unsigned int *_ecore_fps_runtime_mmap = NULL;
182 _ecore_fps_debug_init(void)
188 _ecore_fps_debug_init_count++;
189 if (_ecore_fps_debug_init_count > 1) return;
194 tmp = (char *)evil_tmpdir_get ();
195 #endif /* HAVE_EVIL */
197 snprintf(buf, sizeof(buf), "%s/.ecore_fps_debug-%i", tmp, pid);
198 _ecore_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR, 0644);
199 if (_ecore_fps_debug_fd < 0)
202 _ecore_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR, 0644);
204 if (_ecore_fps_debug_fd >= 0)
206 unsigned int zero = 0;
208 write(_ecore_fps_debug_fd, &zero, sizeof(unsigned int));
209 _ecore_fps_runtime_mmap = mmap(NULL, sizeof(unsigned int),
210 PROT_READ | PROT_WRITE,
212 _ecore_fps_debug_fd, 0);
213 if (_ecore_fps_runtime_mmap == MAP_FAILED)
214 _ecore_fps_runtime_mmap = NULL;
219 _ecore_fps_debug_shutdown(void)
221 _ecore_fps_debug_init_count--;
222 if (_ecore_fps_debug_init_count > 0) return;
223 if (_ecore_fps_debug_fd >= 0)
232 tmp = (char *)evil_tmpdir_get ();
233 #endif /* HAVE_EVIL */
235 snprintf(buf, sizeof(buf), "%s/.ecore_fps_debug-%i", tmp, pid);
237 if (_ecore_fps_runtime_mmap)
239 munmap(_ecore_fps_runtime_mmap, sizeof(int));
240 _ecore_fps_runtime_mmap = NULL;
242 close(_ecore_fps_debug_fd);
243 _ecore_fps_debug_fd = -1;
248 _ecore_fps_debug_runtime_add(double t)
250 if ((_ecore_fps_debug_fd >= 0) &&
251 (_ecore_fps_runtime_mmap))
255 tm = (unsigned int)(t * 1000000.0);
256 /* i know its not 100% theoretically guaranteed, but i'd say a write */
257 /* of an int could be considered atomic for all practical purposes */
258 /* oh and since this is cumulative, 1 second = 1,000,000 ticks, so */
259 /* this can run for about 4294 seconds becore looping. if you are */
260 /* doing performance testing in one run for over an hour... well */
261 /* time to restart or handle a loop condition :) */
262 *(_ecore_fps_runtime_mmap) += tm;