~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to glchess/src/chess-engine.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* chess-engine.c generated by valac 0.12.0, the Vala compiler
 
2
 * generated from chess-engine.vala, do not modify */
 
3
 
 
4
 
 
5
#include <glib.h>
 
6
#include <glib-object.h>
 
7
#include <stdio.h>
 
8
#include <string.h>
 
9
#include <unistd.h>
 
10
#include <stdlib.h>
 
11
 
 
12
 
 
13
#define TYPE_CHESS_ENGINE (chess_engine_get_type ())
 
14
#define CHESS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_ENGINE, ChessEngine))
 
15
#define CHESS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_ENGINE, ChessEngineClass))
 
16
#define IS_CHESS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_ENGINE))
 
17
#define IS_CHESS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_ENGINE))
 
18
#define CHESS_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_ENGINE, ChessEngineClass))
 
19
 
 
20
typedef struct _ChessEngine ChessEngine;
 
21
typedef struct _ChessEngineClass ChessEngineClass;
 
22
typedef struct _ChessEnginePrivate ChessEnginePrivate;
 
23
 
 
24
#define TYPE_CHESS_MOVE (chess_move_get_type ())
 
25
#define CHESS_MOVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_MOVE, ChessMove))
 
26
#define CHESS_MOVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_MOVE, ChessMoveClass))
 
27
#define IS_CHESS_MOVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_MOVE))
 
28
#define IS_CHESS_MOVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_MOVE))
 
29
#define CHESS_MOVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_MOVE, ChessMoveClass))
 
30
 
 
31
typedef struct _ChessMove ChessMove;
 
32
typedef struct _ChessMoveClass ChessMoveClass;
 
33
#define _g_free0(var) (var = (g_free (var), NULL))
 
34
#define _g_io_channel_unref0(var) ((var == NULL) ? NULL : (var = (g_io_channel_unref (var), NULL)))
 
35
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
36
 
 
37
struct _ChessEngine {
 
38
        GObject parent_instance;
 
39
        ChessEnginePrivate * priv;
 
40
        gchar* binary;
 
41
};
 
42
 
 
43
struct _ChessEngineClass {
 
44
        GObjectClass parent_class;
 
45
        void (*process_input) (ChessEngine* self, gchar* data, int data_length1);
 
46
        void (*start_game) (ChessEngine* self);
 
47
        void (*request_move) (ChessEngine* self);
 
48
        void (*report_move) (ChessEngine* self, ChessMove* move);
 
49
        void (*undo) (ChessEngine* self);
 
50
};
 
51
 
 
52
struct _ChessEnginePrivate {
 
53
        GPid pid;
 
54
        gint stdin_fd;
 
55
        gint stderr_fd;
 
56
        GIOChannel* stdout_channel;
 
57
        gboolean _ready;
 
58
};
 
59
 
 
60
 
 
61
static gpointer chess_engine_parent_class = NULL;
 
62
 
 
63
GType chess_engine_get_type (void) G_GNUC_CONST;
 
64
gpointer chess_move_ref (gpointer instance);
 
65
void chess_move_unref (gpointer instance);
 
66
GParamSpec* param_spec_chess_move (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
67
void value_set_chess_move (GValue* value, gpointer v_object);
 
68
void value_take_chess_move (GValue* value, gpointer v_object);
 
69
gpointer value_get_chess_move (const GValue* value);
 
70
GType chess_move_get_type (void) G_GNUC_CONST;
 
71
#define CHESS_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_CHESS_ENGINE, ChessEnginePrivate))
 
72
enum  {
 
73
        CHESS_ENGINE_DUMMY_PROPERTY,
 
74
        CHESS_ENGINE_READY
 
75
};
 
76
void chess_engine_process_input (ChessEngine* self, gchar* data, int data_length1);
 
77
static void chess_engine_real_process_input (ChessEngine* self, gchar* data, int data_length1);
 
78
gboolean chess_engine_start (ChessEngine* self);
 
79
static gboolean chess_engine_read_cb (ChessEngine* self, GIOChannel* source, GIOCondition condition);
 
80
static gboolean _chess_engine_read_cb_gio_func (GIOChannel* source, GIOCondition condition, gpointer self);
 
81
void chess_engine_start_game (ChessEngine* self);
 
82
static void chess_engine_real_start_game (ChessEngine* self);
 
83
void chess_engine_request_move (ChessEngine* self);
 
84
static void chess_engine_real_request_move (ChessEngine* self);
 
85
void chess_engine_report_move (ChessEngine* self, ChessMove* move);
 
86
static void chess_engine_real_report_move (ChessEngine* self, ChessMove* move);
 
87
void chess_engine_undo (ChessEngine* self);
 
88
static void chess_engine_real_undo (ChessEngine* self);
 
89
void chess_engine_stop (ChessEngine* self);
 
90
void chess_engine_write (ChessEngine* self, gchar* data, int data_length1);
 
91
void chess_engine_write_line (ChessEngine* self, const gchar* line);
 
92
ChessEngine* chess_engine_new (void);
 
93
ChessEngine* chess_engine_construct (GType object_type);
 
94
gboolean chess_engine_get_ready (ChessEngine* self);
 
95
void chess_engine_set_ready (ChessEngine* self, gboolean value);
 
96
static void chess_engine_finalize (GObject* obj);
 
97
static void _vala_chess_engine_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
 
98
static void _vala_chess_engine_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
 
99
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
 
100
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
 
101
 
 
102
 
 
103
static void chess_engine_real_process_input (ChessEngine* self, gchar* data, int data_length1) {
 
104
        g_return_if_fail (self != NULL);
 
105
}
 
106
 
 
107
 
 
108
void chess_engine_process_input (ChessEngine* self, gchar* data, int data_length1) {
 
109
        CHESS_ENGINE_GET_CLASS (self)->process_input (self, data, data_length1);
 
110
}
 
111
 
 
112
 
 
113
static gboolean _chess_engine_read_cb_gio_func (GIOChannel* source, GIOCondition condition, gpointer self) {
 
114
        gboolean result;
 
115
        result = chess_engine_read_cb (self, source, condition);
 
116
        return result;
 
117
}
 
118
 
 
119
 
 
120
gboolean chess_engine_start (ChessEngine* self) {
 
121
        gboolean result = FALSE;
 
122
        gchar* _tmp0_;
 
123
        gchar** _tmp1_ = NULL;
 
124
        gchar** argv;
 
125
        gint argv_length1;
 
126
        gint _argv_size_;
 
127
        gint stdout_fd = 0;
 
128
        GPid _tmp2_;
 
129
        gint _tmp3_;
 
130
        gint _tmp4_;
 
131
        gint _tmp5_;
 
132
        GIOChannel* _tmp6_ = NULL;
 
133
        GError * _inner_error_ = NULL;
 
134
        g_return_val_if_fail (self != NULL, FALSE);
 
135
        _tmp0_ = g_strdup (self->binary);
 
136
        _tmp1_ = g_new0 (gchar*, 2 + 1);
 
137
        _tmp1_[0] = _tmp0_;
 
138
        _tmp1_[1] = NULL;
 
139
        argv = _tmp1_;
 
140
        argv_length1 = 2;
 
141
        _argv_size_ = 2;
 
142
        g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp2_, &_tmp3_, &_tmp4_, &_tmp5_, &_inner_error_);
 
143
        self->priv->pid = _tmp2_;
 
144
        self->priv->stdin_fd = _tmp3_;
 
145
        stdout_fd = _tmp4_;
 
146
        self->priv->stderr_fd = _tmp5_;
 
147
        if (_inner_error_ != NULL) {
 
148
                if (_inner_error_->domain == G_SPAWN_ERROR) {
 
149
                        goto __catch9_g_spawn_error;
 
150
                }
 
151
                argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
 
152
                g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
153
                g_clear_error (&_inner_error_);
 
154
                return FALSE;
 
155
        }
 
156
        goto __finally9;
 
157
        __catch9_g_spawn_error:
 
158
        {
 
159
                GError * e;
 
160
                e = _inner_error_;
 
161
                _inner_error_ = NULL;
 
162
                fprintf (stderr, "Failed to execute chess engine: %s\n", e->message);
 
163
                result = FALSE;
 
164
                _g_error_free0 (e);
 
165
                argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
 
166
                return result;
 
167
        }
 
168
        __finally9:
 
169
        if (_inner_error_ != NULL) {
 
170
                argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
 
171
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
172
                g_clear_error (&_inner_error_);
 
173
                return FALSE;
 
174
        }
 
175
        _tmp6_ = g_io_channel_unix_new (stdout_fd);
 
176
        _g_io_channel_unref0 (self->priv->stdout_channel);
 
177
        self->priv->stdout_channel = _tmp6_;
 
178
        g_io_channel_set_flags (self->priv->stdout_channel, G_IO_FLAG_NONBLOCK, &_inner_error_);
 
179
        if (_inner_error_ != NULL) {
 
180
                if (_inner_error_->domain == G_IO_CHANNEL_ERROR) {
 
181
                        goto __catch10_g_io_channel_error;
 
182
                }
 
183
                argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
 
184
                g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
185
                g_clear_error (&_inner_error_);
 
186
                return FALSE;
 
187
        }
 
188
        goto __finally10;
 
189
        __catch10_g_io_channel_error:
 
190
        {
 
191
                GError * e;
 
192
                e = _inner_error_;
 
193
                _inner_error_ = NULL;
 
194
                fprintf (stderr, "Failed to set input from chess engine to non-blocking: %s", e->message);
 
195
                _g_error_free0 (e);
 
196
        }
 
197
        __finally10:
 
198
        if (_inner_error_ != NULL) {
 
199
                argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
 
200
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
201
                g_clear_error (&_inner_error_);
 
202
                return FALSE;
 
203
        }
 
204
        g_io_add_watch (self->priv->stdout_channel, G_IO_IN, _chess_engine_read_cb_gio_func, self);
 
205
        g_signal_emit_by_name (self, "starting");
 
206
        result = TRUE;
 
207
        argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
 
208
        return result;
 
209
}
 
210
 
 
211
 
 
212
static void chess_engine_real_start_game (ChessEngine* self) {
 
213
        g_return_if_fail (self != NULL);
 
214
}
 
215
 
 
216
 
 
217
void chess_engine_start_game (ChessEngine* self) {
 
218
        CHESS_ENGINE_GET_CLASS (self)->start_game (self);
 
219
}
 
220
 
 
221
 
 
222
static void chess_engine_real_request_move (ChessEngine* self) {
 
223
        g_return_if_fail (self != NULL);
 
224
}
 
225
 
 
226
 
 
227
void chess_engine_request_move (ChessEngine* self) {
 
228
        CHESS_ENGINE_GET_CLASS (self)->request_move (self);
 
229
}
 
230
 
 
231
 
 
232
static void chess_engine_real_report_move (ChessEngine* self, ChessMove* move) {
 
233
        g_return_if_fail (self != NULL);
 
234
        g_return_if_fail (move != NULL);
 
235
}
 
236
 
 
237
 
 
238
void chess_engine_report_move (ChessEngine* self, ChessMove* move) {
 
239
        CHESS_ENGINE_GET_CLASS (self)->report_move (self, move);
 
240
}
 
241
 
 
242
 
 
243
static void chess_engine_real_undo (ChessEngine* self) {
 
244
        g_return_if_fail (self != NULL);
 
245
}
 
246
 
 
247
 
 
248
void chess_engine_undo (ChessEngine* self) {
 
249
        CHESS_ENGINE_GET_CLASS (self)->undo (self);
 
250
}
 
251
 
 
252
 
 
253
void chess_engine_stop (ChessEngine* self) {
 
254
        g_return_if_fail (self != NULL);
 
255
        g_signal_emit_by_name (self, "stopped");
 
256
}
 
257
 
 
258
 
 
259
static gboolean chess_engine_read_cb (ChessEngine* self, GIOChannel* source, GIOCondition condition) {
 
260
        gboolean result = FALSE;
 
261
        gchar* buf = NULL;
 
262
        gint buf_length1 = 0;
 
263
        gint _buf_size_ = 0;
 
264
        gsize n_read = 0UL;
 
265
        GIOStatus status = 0;
 
266
        gchar* _tmp0_ = NULL;
 
267
        gsize _tmp1_;
 
268
        GIOStatus _tmp2_;
 
269
        GIOStatus _tmp3_;
 
270
        GError * _inner_error_ = NULL;
 
271
        g_return_val_if_fail (self != NULL, FALSE);
 
272
        g_return_val_if_fail (source != NULL, FALSE);
 
273
        _tmp0_ = g_new0 (gchar, 1024);
 
274
        buf = (g_free (buf), NULL);
 
275
        buf = _tmp0_;
 
276
        buf_length1 = 1024;
 
277
        _buf_size_ = 1024;
 
278
        _tmp2_ = g_io_channel_read_chars (source, buf, buf_length1, &_tmp1_, &_inner_error_);
 
279
        n_read = _tmp1_;
 
280
        _tmp3_ = _tmp2_;
 
281
        if (_inner_error_ != NULL) {
 
282
                if (_inner_error_->domain == G_CONVERT_ERROR) {
 
283
                        goto __catch11_g_convert_error;
 
284
                }
 
285
                if (_inner_error_->domain == G_IO_CHANNEL_ERROR) {
 
286
                        goto __catch11_g_io_channel_error;
 
287
                }
 
288
                buf = (g_free (buf), NULL);
 
289
                g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
290
                g_clear_error (&_inner_error_);
 
291
                return FALSE;
 
292
        }
 
293
        status = _tmp3_;
 
294
        goto __finally11;
 
295
        __catch11_g_convert_error:
 
296
        {
 
297
                GError * e;
 
298
                e = _inner_error_;
 
299
                _inner_error_ = NULL;
 
300
                result = FALSE;
 
301
                _g_error_free0 (e);
 
302
                buf = (g_free (buf), NULL);
 
303
                return result;
 
304
        }
 
305
        goto __finally11;
 
306
        __catch11_g_io_channel_error:
 
307
        {
 
308
                GError * e;
 
309
                e = _inner_error_;
 
310
                _inner_error_ = NULL;
 
311
                result = FALSE;
 
312
                _g_error_free0 (e);
 
313
                buf = (g_free (buf), NULL);
 
314
                return result;
 
315
        }
 
316
        __finally11:
 
317
        if (_inner_error_ != NULL) {
 
318
                buf = (g_free (buf), NULL);
 
319
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
320
                g_clear_error (&_inner_error_);
 
321
                return FALSE;
 
322
        }
 
323
        if (status == G_IO_STATUS_EOF) {
 
324
                fprintf (stdout, "EOF\n");
 
325
                result = FALSE;
 
326
                buf = (g_free (buf), NULL);
 
327
                return result;
 
328
        }
 
329
        if (status == G_IO_STATUS_NORMAL) {
 
330
                gint _tmp4_;
 
331
                _tmp4_ = (gint) n_read;
 
332
                buf = g_renew (gchar, buf, (gint) n_read);
 
333
                (_tmp4_ > buf_length1) ? memset (buf + buf_length1, 0, sizeof (gchar) * (_tmp4_ - buf_length1)) : NULL;
 
334
                buf_length1 = _tmp4_;
 
335
                _buf_size_ = _tmp4_;
 
336
                chess_engine_process_input (self, buf, buf_length1);
 
337
        }
 
338
        result = TRUE;
 
339
        buf = (g_free (buf), NULL);
 
340
        return result;
 
341
}
 
342
 
 
343
 
 
344
void chess_engine_write (ChessEngine* self, gchar* data, int data_length1) {
 
345
        gsize offset;
 
346
        gsize n_written = 0UL;
 
347
        g_return_if_fail (self != NULL);
 
348
        offset = (gsize) 0;
 
349
        while (TRUE) {
 
350
                gint _tmp0_;
 
351
                gchar* _tmp1_ = NULL;
 
352
                gchar* d;
 
353
                gint d_length1;
 
354
                gint _d_size_;
 
355
                gssize _tmp3_;
 
356
                if (!(offset < data_length1)) {
 
357
                        break;
 
358
                }
 
359
                _tmp1_ = g_new0 (gchar, _tmp0_ = data_length1 - offset);
 
360
                d = _tmp1_;
 
361
                d_length1 = _tmp0_;
 
362
                _d_size_ = _tmp0_;
 
363
                {
 
364
                        gint i;
 
365
                        i = 0;
 
366
                        {
 
367
                                gboolean _tmp2_;
 
368
                                _tmp2_ = TRUE;
 
369
                                while (TRUE) {
 
370
                                        if (!_tmp2_) {
 
371
                                                i++;
 
372
                                        }
 
373
                                        _tmp2_ = FALSE;
 
374
                                        if (!(i < (data_length1 - offset))) {
 
375
                                                break;
 
376
                                        }
 
377
                                        d[i] = data[offset + i];
 
378
                                }
 
379
                        }
 
380
                }
 
381
                _tmp3_ = write (self->priv->stdin_fd, d, (gsize) d_length1);
 
382
                n_written = (gsize) _tmp3_;
 
383
                if (n_written < 0) {
 
384
                        d = (g_free (d), NULL);
 
385
                        return;
 
386
                }
 
387
                offset = offset + n_written;
 
388
                d = (g_free (d), NULL);
 
389
        }
 
390
}
 
391
 
 
392
 
 
393
static gchar* string_to_utf8 (const gchar* self, int* result_length1) {
 
394
        gchar* result = NULL;
 
395
        gint _tmp0_;
 
396
        gchar* _tmp1_ = NULL;
 
397
        gchar* _result_;
 
398
        gint _result__length1;
 
399
        gint __result__size_;
 
400
        gint _tmp2_;
 
401
        gchar* _tmp3_;
 
402
        g_return_val_if_fail (self != NULL, NULL);
 
403
        _tmp0_ = strlen (self);
 
404
        _tmp1_ = g_new0 (gchar, _tmp0_ + 1);
 
405
        _result_ = _tmp1_;
 
406
        _result__length1 = _tmp0_ + 1;
 
407
        __result__size_ = _tmp0_ + 1;
 
408
        _result__length1--;
 
409
        _tmp2_ = strlen (self);
 
410
        memcpy (_result_, self, (gsize) _tmp2_);
 
411
        _tmp3_ = _result_;
 
412
        *result_length1 = _result__length1;
 
413
        result = _tmp3_;
 
414
        return result;
 
415
}
 
416
 
 
417
 
 
418
void chess_engine_write_line (ChessEngine* self, const gchar* line) {
 
419
        gchar* _tmp0_;
 
420
        gchar* l;
 
421
        gint _tmp1_;
 
422
        gchar* _tmp2_ = NULL;
 
423
        gchar* d;
 
424
        gint d_length1;
 
425
        gint _d_size_;
 
426
        g_return_if_fail (self != NULL);
 
427
        g_return_if_fail (line != NULL);
 
428
        _tmp0_ = g_strconcat (line, "\n", NULL);
 
429
        l = _tmp0_;
 
430
        g_debug ("chess-engine.vala:146: Writing line to engine: '%s'", line);
 
431
        _tmp2_ = string_to_utf8 (l, &_tmp1_);
 
432
        d = _tmp2_;
 
433
        d_length1 = _tmp1_;
 
434
        _d_size_ = _tmp1_;
 
435
        if (d != NULL) {
 
436
                chess_engine_write (self, d, d_length1);
 
437
        }
 
438
        d = (g_free (d), NULL);
 
439
        _g_free0 (l);
 
440
}
 
441
 
 
442
 
 
443
ChessEngine* chess_engine_construct (GType object_type) {
 
444
        ChessEngine * self = NULL;
 
445
        self = (ChessEngine*) g_object_new (object_type, NULL);
 
446
        return self;
 
447
}
 
448
 
 
449
 
 
450
ChessEngine* chess_engine_new (void) {
 
451
        return chess_engine_construct (TYPE_CHESS_ENGINE);
 
452
}
 
453
 
 
454
 
 
455
gboolean chess_engine_get_ready (ChessEngine* self) {
 
456
        gboolean result;
 
457
        g_return_val_if_fail (self != NULL, FALSE);
 
458
        result = self->priv->_ready;
 
459
        return result;
 
460
}
 
461
 
 
462
 
 
463
void chess_engine_set_ready (ChessEngine* self, gboolean value) {
 
464
        g_return_if_fail (self != NULL);
 
465
        self->priv->_ready = value;
 
466
        g_signal_emit_by_name (self, "ready-changed");
 
467
        g_object_notify ((GObject *) self, "ready");
 
468
}
 
469
 
 
470
 
 
471
static void chess_engine_class_init (ChessEngineClass * klass) {
 
472
        chess_engine_parent_class = g_type_class_peek_parent (klass);
 
473
        g_type_class_add_private (klass, sizeof (ChessEnginePrivate));
 
474
        CHESS_ENGINE_CLASS (klass)->process_input = chess_engine_real_process_input;
 
475
        CHESS_ENGINE_CLASS (klass)->start_game = chess_engine_real_start_game;
 
476
        CHESS_ENGINE_CLASS (klass)->request_move = chess_engine_real_request_move;
 
477
        CHESS_ENGINE_CLASS (klass)->report_move = chess_engine_real_report_move;
 
478
        CHESS_ENGINE_CLASS (klass)->undo = chess_engine_real_undo;
 
479
        G_OBJECT_CLASS (klass)->get_property = _vala_chess_engine_get_property;
 
480
        G_OBJECT_CLASS (klass)->set_property = _vala_chess_engine_set_property;
 
481
        G_OBJECT_CLASS (klass)->finalize = chess_engine_finalize;
 
482
        g_object_class_install_property (G_OBJECT_CLASS (klass), CHESS_ENGINE_READY, g_param_spec_boolean ("ready", "ready", "ready", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
 
483
        g_signal_new ("starting", TYPE_CHESS_ENGINE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
484
        g_signal_new ("ready_changed", TYPE_CHESS_ENGINE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
485
        g_signal_new ("moved", TYPE_CHESS_ENGINE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
 
486
        g_signal_new ("resigned", TYPE_CHESS_ENGINE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
487
        g_signal_new ("stopped", TYPE_CHESS_ENGINE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
488
}
 
489
 
 
490
 
 
491
static void chess_engine_instance_init (ChessEngine * self) {
 
492
        self->priv = CHESS_ENGINE_GET_PRIVATE (self);
 
493
        self->priv->_ready = FALSE;
 
494
}
 
495
 
 
496
 
 
497
static void chess_engine_finalize (GObject* obj) {
 
498
        ChessEngine * self;
 
499
        self = CHESS_ENGINE (obj);
 
500
        _g_free0 (self->binary);
 
501
        _g_io_channel_unref0 (self->priv->stdout_channel);
 
502
        G_OBJECT_CLASS (chess_engine_parent_class)->finalize (obj);
 
503
}
 
504
 
 
505
 
 
506
GType chess_engine_get_type (void) {
 
507
        static volatile gsize chess_engine_type_id__volatile = 0;
 
508
        if (g_once_init_enter (&chess_engine_type_id__volatile)) {
 
509
                static const GTypeInfo g_define_type_info = { sizeof (ChessEngineClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) chess_engine_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ChessEngine), 0, (GInstanceInitFunc) chess_engine_instance_init, NULL };
 
510
                GType chess_engine_type_id;
 
511
                chess_engine_type_id = g_type_register_static (G_TYPE_OBJECT, "ChessEngine", &g_define_type_info, 0);
 
512
                g_once_init_leave (&chess_engine_type_id__volatile, chess_engine_type_id);
 
513
        }
 
514
        return chess_engine_type_id__volatile;
 
515
}
 
516
 
 
517
 
 
518
static void _vala_chess_engine_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
 
519
        ChessEngine * self;
 
520
        self = CHESS_ENGINE (object);
 
521
        switch (property_id) {
 
522
                case CHESS_ENGINE_READY:
 
523
                g_value_set_boolean (value, chess_engine_get_ready (self));
 
524
                break;
 
525
                default:
 
526
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
527
                break;
 
528
        }
 
529
}
 
530
 
 
531
 
 
532
static void _vala_chess_engine_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
 
533
        ChessEngine * self;
 
534
        self = CHESS_ENGINE (object);
 
535
        switch (property_id) {
 
536
                case CHESS_ENGINE_READY:
 
537
                chess_engine_set_ready (self, g_value_get_boolean (value));
 
538
                break;
 
539
                default:
 
540
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
541
                break;
 
542
        }
 
543
}
 
544
 
 
545
 
 
546
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
 
547
        if ((array != NULL) && (destroy_func != NULL)) {
 
548
                int i;
 
549
                for (i = 0; i < array_length; i = i + 1) {
 
550
                        if (((gpointer*) array)[i] != NULL) {
 
551
                                destroy_func (((gpointer*) array)[i]);
 
552
                        }
 
553
                }
 
554
        }
 
555
}
 
556
 
 
557
 
 
558
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
 
559
        _vala_array_destroy (array, array_length, destroy_func);
 
560
        g_free (array);
 
561
}
 
562
 
 
563
 
 
564