diff options
author | David Walter Seikel | 2012-04-22 09:20:32 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:20:32 +1000 |
commit | 3ad3455551be0d7859ecb02290376206d5e66498 (patch) | |
tree | 497917e12b4d7f458dff9765d9b53f64c4e03fc3 /libraries/elementary/src/examples/efl_thread_3.c | |
parent | Update EFL to latest beta. (diff) | |
download | SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.zip SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.gz SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.bz2 SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.xz |
And actually include new files, plus elementary libraries.
Diffstat (limited to 'libraries/elementary/src/examples/efl_thread_3.c')
-rw-r--r-- | libraries/elementary/src/examples/efl_thread_3.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/efl_thread_3.c b/libraries/elementary/src/examples/efl_thread_3.c new file mode 100644 index 0000000..cbc2c67 --- /dev/null +++ b/libraries/elementary/src/examples/efl_thread_3.c | |||
@@ -0,0 +1,97 @@ | |||
1 | //Compile with: | ||
2 | //gcc -o efl_thread_3 efl_thread_3.c -g `pkg-config --cflags --libs elementary` | ||
3 | #include <Elementary.h> | ||
4 | #include <pthread.h> | ||
5 | |||
6 | static Evas_Object *win = NULL; | ||
7 | static Evas_Object *rect = NULL; | ||
8 | |||
9 | struct info | ||
10 | { | ||
11 | double x, y; | ||
12 | }; | ||
13 | |||
14 | static void my_thread_mainloop_code(void *data); | ||
15 | |||
16 | static pthread_t thread_id; | ||
17 | |||
18 | // BEGIN - code running in my custom pthread instance | ||
19 | // | ||
20 | static void * | ||
21 | my_thread_run(void *arg) | ||
22 | { | ||
23 | double t = 0.0; | ||
24 | |||
25 | // inside the pthread function lets loop forever incrimenting a time point | ||
26 | for (;;) | ||
27 | { | ||
28 | struct info *inf = malloc(sizeof(struct info)); | ||
29 | |||
30 | if (inf) | ||
31 | { | ||
32 | inf->x = 200 + (200 * sin(t)); | ||
33 | inf->y = 200 + (200 * cos(t)); | ||
34 | // now call a function in the mainloop and pass it our allocated | ||
35 | // data that it will free when it gets it | ||
36 | ecore_main_loop_thread_safe_call_async | ||
37 | (my_thread_mainloop_code, inf); | ||
38 | } | ||
39 | // and sleep and loop | ||
40 | usleep(1000); | ||
41 | t += 0.02; | ||
42 | } | ||
43 | return NULL; | ||
44 | } | ||
45 | // | ||
46 | // END - code running in my custom pthread instance | ||
47 | static void | ||
48 | my_thread_new(void) | ||
49 | { | ||
50 | pthread_attr_t attr; | ||
51 | |||
52 | if (pthread_attr_init(&attr) != 0) | ||
53 | perror("pthread_attr_init"); | ||
54 | if (pthread_create(&thread_id, &attr, my_thread_run, NULL) != 0) | ||
55 | perror("pthread_create"); | ||
56 | } | ||
57 | |||
58 | static void | ||
59 | my_thread_mainloop_code(void *data) | ||
60 | { | ||
61 | struct info *inf = data; | ||
62 | evas_object_move(rect, inf->x - 50, inf->y - 50); | ||
63 | free(inf); | ||
64 | } | ||
65 | |||
66 | EAPI_MAIN int | ||
67 | elm_main(int argc, char **argv) | ||
68 | { | ||
69 | Evas_Object *o, *bg; | ||
70 | |||
71 | win = elm_win_add(NULL, "efl-thread-3", ELM_WIN_BASIC); | ||
72 | elm_win_title_set(win, "EFL Thread 3"); | ||
73 | elm_win_autodel_set(win, EINA_TRUE); | ||
74 | elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); | ||
75 | evas_object_resize(win, 400, 400); | ||
76 | evas_object_show(win); | ||
77 | |||
78 | bg = elm_bg_add(win); | ||
79 | evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
80 | elm_win_resize_object_add(win, bg); | ||
81 | evas_object_show(bg); | ||
82 | |||
83 | o = evas_object_rectangle_add(evas_object_evas_get(win)); | ||
84 | evas_object_color_set(o, 50, 80, 180, 255); | ||
85 | evas_object_resize(o, 100, 100); | ||
86 | evas_object_show(o); | ||
87 | rect = o; | ||
88 | |||
89 | // create custom thread to do some "work on the side" | ||
90 | my_thread_new(); | ||
91 | |||
92 | elm_run(); | ||
93 | elm_shutdown(); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | ELM_MAIN() | ||