Imported Upstream version 3.13.92
[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_new ("t", (GThreadFunc)other_thread_cb, self);
47 }
48
49 static void test_thread_init (TestThread *self) {}
50 static void test_thread_class_init (TestThreadClass *klass)
51 {
52   test_thread_signals[SIGNAL_EMIT_SIGNAL] =
53     g_signal_new ("emit-signal", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
54                   G_STRUCT_OFFSET (TestThreadClass, emit_signal),
55                   NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
56   test_thread_signals[SIGNAL_FROM_THREAD] =
57     g_signal_new ("from-thread", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
58                   G_STRUCT_OFFSET (TestThreadClass, from_thread),
59                   NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1,
60                   test_thread_enum_get_type ());
61
62   klass->emit_signal = test_thread_emit_signal;
63 }