0f5b90968e8898f59162cb1fcb14f70126976494
[platform/upstream/pygobject2.git] / tests / test-thread.c
1 #include "test-thread.h"
2
3 enum
4 {
5   /* methods */
6   SIGNAL_EMIT_SIGNAL,
7   SIGNAL_FROM_THREAD,
8   LAST_SIGNAL
9 };
10
11 static guint test_thread_signals[LAST_SIGNAL] = { 0 };
12
13 typedef enum {
14   TEST_THREAD_A,
15   TEST_THREAD_B
16 } ThreadEnumType;
17
18 static GType
19 test_thread_enum_get_type (void)
20 {
21   static GType enum_type = 0;
22   static GEnumValue enum_values[] = {
23     {TEST_THREAD_A, "TEST_THREAD_A", "a as in apple"},
24     {0, NULL, NULL},
25   };
26
27   if (!enum_type) {
28     enum_type =
29         g_enum_register_static ("TestThreadEnum", enum_values);
30   }
31   return enum_type;
32 }
33
34 G_DEFINE_TYPE(TestThread, test_thread, G_TYPE_OBJECT);
35
36 static void
37 other_thread_cb (TestThread *self)
38 {
39   g_signal_emit_by_name (self, "from-thread", 0, NULL);
40   g_thread_exit (0);
41 }
42
43 static void
44 test_thread_emit_signal (TestThread *self)
45 {
46   self->thread = g_thread_create ((GThreadFunc)other_thread_cb,
47                                   self, TRUE, NULL);
48 }
49
50 static void test_thread_init (TestThread *self) {}
51 static void test_thread_class_init (TestThreadClass *klass)
52 {
53   test_thread_signals[SIGNAL_EMIT_SIGNAL] =
54     g_signal_new ("emit-signal", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
55                   G_STRUCT_OFFSET (TestThreadClass, emit_signal),
56                   NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
57   test_thread_signals[SIGNAL_FROM_THREAD] =
58     g_signal_new ("from-thread", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
59                   G_STRUCT_OFFSET (TestThreadClass, from_thread),
60                   NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1,
61                   test_thread_enum_get_type ());
62
63   klass->emit_signal = test_thread_emit_signal;
64 }