phidgets 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/History.txt +10 -2
  2. data/README.rdoc +41 -18
  3. data/Rakefile +31 -20
  4. data/bin/phidget +29 -44
  5. data/ext/phidgets/extconf.rb +14 -0
  6. data/ext/phidgets/phidgets.c +272 -0
  7. data/ext/phidgets/phidgets.h +82 -0
  8. data/ext/phidgets/phidgets_accelerometer.c +165 -0
  9. data/ext/phidgets/phidgets_advanced_servo.c +567 -0
  10. data/ext/phidgets/phidgets_analog.c +139 -0
  11. data/ext/phidgets/phidgets_bridge.c +263 -0
  12. data/ext/phidgets/phidgets_common.c +454 -0
  13. data/ext/phidgets/phidgets_dictionary.c +279 -0
  14. data/ext/phidgets/phidgets_encoder.c +249 -0
  15. data/ext/phidgets/phidgets_frequency_counter.c +241 -0
  16. data/ext/phidgets/phidgets_gps.c +235 -0
  17. data/ext/phidgets/phidgets_interface_kit.c +340 -0
  18. data/ext/phidgets/phidgets_ir.c +251 -0
  19. data/ext/phidgets/phidgets_led.c +178 -0
  20. data/ext/phidgets/phidgets_manager.c +366 -0
  21. data/ext/phidgets/phidgets_motor_control.c +642 -0
  22. data/ext/phidgets/phidgets_phsensor.c +208 -0
  23. data/ext/phidgets/phidgets_rfid.c +281 -0
  24. data/ext/phidgets/phidgets_servo.c +276 -0
  25. data/ext/phidgets/phidgets_spatial.c +369 -0
  26. data/ext/phidgets/phidgets_stepper.c +560 -0
  27. data/ext/phidgets/phidgets_temp_sensor.c +295 -0
  28. data/ext/phidgets/phidgets_text_lcd.c +381 -0
  29. data/ext/phidgets/phidgets_text_led.c +107 -0
  30. data/ext/phidgets/phidgets_weight_sensor.c +113 -0
  31. data/lib/phidgets/accelerometer.rb +25 -0
  32. data/lib/phidgets/advanced_servo.rb +49 -0
  33. data/lib/phidgets/analog.rb +8 -0
  34. data/lib/phidgets/bridge.rb +25 -0
  35. data/lib/phidgets/common.rb +75 -190
  36. data/lib/phidgets/dictionary.rb +53 -0
  37. data/lib/phidgets/encoder.rb +49 -0
  38. data/lib/phidgets/frequency_counter.rb +25 -0
  39. data/lib/phidgets/gps.rb +37 -0
  40. data/lib/phidgets/interfacekit.rb +38 -128
  41. data/lib/phidgets/ir.rb +50 -0
  42. data/lib/phidgets/led.rb +8 -0
  43. data/lib/phidgets/manager.rb +67 -119
  44. data/lib/phidgets/motor_control.rb +110 -0
  45. data/lib/phidgets/ph_sensor.rb +25 -0
  46. data/lib/phidgets/rfid.rb +38 -111
  47. data/lib/phidgets/servo.rb +12 -95
  48. data/lib/phidgets/spatial.rb +25 -0
  49. data/lib/phidgets/stepper.rb +61 -0
  50. data/lib/phidgets/temperature_sensor.rb +25 -0
  51. data/lib/phidgets/text_lcd.rb +8 -0
  52. data/lib/phidgets/text_led.rb +8 -0
  53. data/lib/phidgets/weight_sensor.rb +25 -0
  54. data/lib/phidgets.rb +22 -3
  55. data/phidgets.gemspec +42 -0
  56. data/test/test_accelerometer.rb +47 -0
  57. data/test/test_advanced_servo.rb +152 -0
  58. data/test/test_analog.rb +45 -0
  59. data/test/test_bridge.rb +77 -0
  60. data/test/test_common.rb +167 -0
  61. data/test/test_dictionary.rb +82 -0
  62. data/test/test_encoder.rb +67 -0
  63. data/test/test_frequency_counter.rb +67 -0
  64. data/test/test_gps.rb +67 -0
  65. data/test/test_helper.rb +1 -0
  66. data/test/test_interfacekit.rb +86 -182
  67. data/test/test_ir.rb +57 -0
  68. data/test/test_led.rb +55 -0
  69. data/test/test_manager.rb +94 -0
  70. data/test/test_motor_control.rb +172 -0
  71. data/test/test_phidgets.rb +14 -6
  72. data/test/test_phsensor.rb +62 -0
  73. data/test/test_rfid.rb +77 -0
  74. data/test/test_servo.rb +67 -0
  75. data/test/test_spatial.rb +112 -0
  76. data/test/test_stepper.rb +163 -0
  77. data/test/test_temp_sensor.rb +87 -0
  78. data/test/test_text_lcd.rb +115 -0
  79. data/test/test_text_led.rb +35 -0
  80. data/test/test_weight_sensor.rb +32 -0
  81. metadata +165 -75
  82. data/Manifest.txt +0 -21
  83. data/PostInstall.txt +0 -3
  84. data/README.txt +0 -87
  85. data/lib/phidgets/phidgets.rb +0 -225
  86. data/script/console +0 -10
  87. data/script/destroy +0 -14
  88. data/script/generate +0 -14
@@ -0,0 +1,454 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+
5
+ VALUE ph_common_allocate(VALUE klass);
6
+ void ph_common_free(ph_data_t *ph);
7
+ VALUE ph_common_open(VALUE self, VALUE serial_number);
8
+ VALUE ph_common_open_label(VALUE self, VALUE label);
9
+ VALUE ph_common_open_remote(VALUE self, VALUE serial_number, VALUE server_id, VALUE password);
10
+ VALUE ph_common_open_label_remote(VALUE self, VALUE label, VALUE server_id, VALUE password);
11
+ VALUE ph_common_open_remote_ip(VALUE self, VALUE serial_number, VALUE address, VALUE port, VALUE password);
12
+ VALUE ph_common_open_label_remote_ip(VALUE self, VALUE label, VALUE address, VALUE port, VALUE password);
13
+ VALUE ph_common_wait_for_attachment(VALUE self, VALUE milliseconds);
14
+ VALUE ph_common_close(VALUE self);
15
+ VALUE ph_common_get_device_class(VALUE self);
16
+ VALUE ph_common_get_device_id(VALUE self);
17
+ VALUE ph_common_get_device_type(VALUE self);
18
+ VALUE ph_common_get_device_name(VALUE self);
19
+ VALUE ph_common_get_serial_number(VALUE self);
20
+ VALUE ph_common_get_device_version(VALUE self);
21
+ VALUE ph_common_get_device_status(VALUE self);
22
+ VALUE ph_common_get_device_label(VALUE self);
23
+ VALUE ph_common_set_device_label(VALUE self, VALUE label);
24
+ VALUE ph_common_get_server_id(VALUE self);
25
+ VALUE ph_common_get_server_address(VALUE self);
26
+ VALUE ph_common_get_server_status(VALUE self);
27
+
28
+ #ifdef PH_CALLBACK
29
+ VALUE ph_common_set_on_attach_handler(VALUE self, VALUE handler);
30
+ VALUE ph_common_set_on_detach_handler(VALUE self, VALUE handler);
31
+ VALUE ph_common_set_on_server_connect_handler(VALUE self, VALUE handler);
32
+ VALUE ph_common_set_on_server_disconnect_handler(VALUE self, VALUE handler);
33
+ int ph_common_on_attach(CPhidgetHandle phid, void *userPtr);
34
+ int ph_common_on_detach(CPhidgetHandle phid, void *userPtr);
35
+ int ph_common_on_server_connect(CPhidgetHandle phid, void *userPtr);
36
+ int ph_common_on_server_disconnect(CPhidgetHandle phid, void *userPtr);
37
+ #endif
38
+
39
+
40
+ VALUE Init_phidgets_common(VALUE ph_module) {
41
+ VALUE ph_common = rb_define_class_under(ph_module, "Common", rb_cObject);
42
+ rb_define_alloc_func(ph_common, ph_common_allocate);
43
+ rb_define_private_method(ph_common, "ext_open", ph_common_open, 1);
44
+
45
+ /* Document-method: openLabel
46
+ * call-seq: openLabel(label)
47
+ *
48
+ * Opens a Phidget by label.
49
+ */
50
+ rb_define_method(ph_common, "openLabel", ph_common_open_label, 1);
51
+
52
+ /* Document-method: openRemote
53
+ * call-seq: openRemote(serial, server_id, password)
54
+ *
55
+ * Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
56
+ */
57
+ rb_define_method(ph_common, "openRemote", ph_common_open_remote, 3);
58
+
59
+ /* Document-method: openLabelRemote
60
+ * call-seq: openLabelRemote(label, server_id, password)
61
+ *
62
+ * Opens a Phidget remotely by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
63
+ */
64
+ rb_define_method(ph_common, "openLabelRemote", ph_common_open_label_remote, 3);
65
+
66
+ /* Document-method: openRemoteIP
67
+ * call-seq: openRemoteIP(serial, address, port, password)
68
+ *
69
+ * Opens a Phidget remotely by address and port, with optional serial number.
70
+ */
71
+ rb_define_method(ph_common, "openRemoteIP", ph_common_open_remote_ip, 4);
72
+
73
+ /* Document-method: openLabelRemoteIP
74
+ * call-seq: openLabelRemoteIP(label, address, port, password)
75
+ *
76
+ * Opens a Phidget remotely by address and port, with optional label.
77
+ */
78
+ rb_define_method(ph_common, "openLabelRemoteIP", ph_common_open_label_remote_ip, 4);
79
+
80
+ /* Document-method: waitForAttachment
81
+ * call-seq: waitForAttachment(milliseconds)
82
+ *
83
+ * Waits for attachment to happen. This can be called right after calling open, as an alternative to using the attach handler.
84
+ */
85
+ rb_define_method(ph_common, "waitForAttachment", ph_common_wait_for_attachment, 1);
86
+
87
+ /* Document-method: close
88
+ * call-seq: close
89
+ *
90
+ * Closes a Phidget.
91
+ */
92
+ rb_define_method(ph_common, "close", ph_common_close, 0);
93
+
94
+ /* Document-method: getDeviceClass
95
+ * call-seq: getDeviceClass -> device_class
96
+ *
97
+ * Gets the class of a Phidget.
98
+ */
99
+ rb_define_method(ph_common, "getDeviceClass", ph_common_get_device_class, 0);
100
+
101
+ /* Document-method: getDeviceID
102
+ * call-seq: getDeviceID -> device_id
103
+ *
104
+ * Gets the device ID of a Phidget.
105
+ */
106
+ rb_define_method(ph_common, "getDeviceID", ph_common_get_device_id, 0);
107
+
108
+ /* Document-method: getDeviceType
109
+ * call-seq: getDeviceType -> device_type
110
+ *
111
+ * Gets the type (class) of a Phidget.
112
+ */
113
+ rb_define_method(ph_common, "getDeviceType", ph_common_get_device_type, 0);
114
+
115
+ /* Document-method: getDeviceName
116
+ * call-seq: getDeviceName -> device_name
117
+ *
118
+ * Gets the specific name of a Phidget.
119
+ */
120
+ rb_define_method(ph_common, "getDeviceName", ph_common_get_device_name, 0);
121
+
122
+ /* Document-method: getSerialNumber
123
+ * call-seq: getSerialNumber -> serial_number
124
+ *
125
+ * Gets the serial number of a Phidget.
126
+ */
127
+ rb_define_method(ph_common, "getSerialNumber", ph_common_get_serial_number, 0);
128
+
129
+ /* Document-method: getDeviceVersion
130
+ * call-seq: getDeviceVersion -> version
131
+ *
132
+ * Gets the firmware version of a Phidget.
133
+ */
134
+ rb_define_method(ph_common, "getDeviceVersion", ph_common_get_device_version, 0);
135
+
136
+ /* Document-method: getDeviceStatus
137
+ * call-seq: getDeviceStatus -> status
138
+ *
139
+ * Gets the attached status of a Phidget.
140
+ */
141
+ rb_define_method(ph_common, "getDeviceStatus", ph_common_get_device_status, 0);
142
+
143
+ /* Document-method: getDeviceLabel
144
+ * call-seq: getDeviceLabel -> label
145
+ *
146
+ * Gets the label of a Phidget.
147
+ */
148
+ rb_define_method(ph_common, "getDeviceLabel", ph_common_get_device_label, 0);
149
+
150
+ /* Document-method: setDeviceLabel
151
+ * call-seq: setDeviceLabel(label)
152
+ *
153
+ * Sets the label of a Phidget. Note that this is not supported on very old Phidgets, and not yet supported in Windows.
154
+ */
155
+ rb_define_method(ph_common, "setDeviceLabel", ph_common_set_device_label, 1);
156
+
157
+ /* Document-method: getServerID
158
+ * call-seq: getServerID -> server_id
159
+ *
160
+ * Gets the server ID of a remotely opened Phidget. This will fail if the Phidget was opened locally.
161
+ */
162
+ rb_define_method(ph_common, "getServerID", ph_common_get_server_id, 0);
163
+
164
+ /* Document-method: getServerAddress
165
+ * call-seq: getServerAddress -> [address, port]
166
+ *
167
+ * Gets the address and port of a remotely opened Phidget. This will fail if the Phidget was opened locally.
168
+ */
169
+ rb_define_method(ph_common, "getServerAddress", ph_common_get_server_address, 0);
170
+
171
+ /* Document-method: getServerStatus
172
+ * call-seq: getServerStatus -> status
173
+ *
174
+ * Gets the connected to server status of a remotely opened Phidget. This will fail if the Phidget was opened locally.
175
+ */
176
+ rb_define_method(ph_common, "getServerStatus", ph_common_get_server_status, 0);
177
+
178
+ #ifdef PH_CALLBACK
179
+ rb_define_private_method(ph_common, "ext_setOnAttachHandler", ph_common_set_on_attach_handler, 1);
180
+ rb_define_private_method(ph_common, "ext_setOnDetachHandler", ph_common_set_on_detach_handler, 1);
181
+ rb_define_private_method(ph_common, "ext_setOnServerConnectHandler", ph_common_set_on_server_connect_handler, 1);
182
+ rb_define_private_method(ph_common, "ext_setOnServerDisconnectHandler", ph_common_set_on_server_disconnect_handler, 1);
183
+ #endif
184
+
185
+ rb_define_alias(ph_common, "open_label", "openLabel");
186
+ rb_define_alias(ph_common, "open_remote", "openRemote");
187
+ rb_define_alias(ph_common, "open_label_remote", "openLabelRemote");
188
+ rb_define_alias(ph_common, "open_remote_ip", "openRemoteIP");
189
+ rb_define_alias(ph_common, "open_label_remote_ip", "openLabelRemoteIP");
190
+ rb_define_alias(ph_common, "wait_for_attachment", "waitForAttachment");
191
+ rb_define_alias(ph_common, "device_class", "getDeviceClass");
192
+ rb_define_alias(ph_common, "device_id", "getDeviceID");
193
+ rb_define_alias(ph_common, "device_type", "getDeviceType");
194
+ rb_define_alias(ph_common, "device_name", "getDeviceName");
195
+ rb_define_alias(ph_common, "serial_number", "getSerialNumber");
196
+ rb_define_alias(ph_common, "device_version", "getDeviceVersion");
197
+ rb_define_alias(ph_common, "device_status", "getDeviceStatus");
198
+ rb_define_alias(ph_common, "device_label", "getDeviceLabel");
199
+ rb_define_alias(ph_common, "device_label=", "setDeviceLabel");
200
+ rb_define_alias(ph_common, "server_id", "getServerID");
201
+ rb_define_alias(ph_common, "server_address", "getServerAddress");
202
+ rb_define_alias(ph_common, "server_status", "getServerStatus");
203
+
204
+ return ph_common;
205
+ }
206
+
207
+
208
+
209
+ VALUE ph_common_allocate(VALUE klass) {
210
+ ph_data_t *ph;
211
+ VALUE self = Data_Make_Struct(klass, ph_data_t, 0, ph_common_free, ph);
212
+ memset(ph, 0, sizeof(ph_data_t));
213
+ return self;
214
+ }
215
+
216
+ void ph_common_free(ph_data_t *ph) {
217
+ if (ph && ph->handle) {
218
+ CPhidget_close(ph->handle);
219
+ CPhidget_delete(ph->handle);
220
+ ph->handle = NULL;
221
+ }
222
+ if(ph) xfree(ph);
223
+ }
224
+
225
+ VALUE ph_common_open(VALUE self, VALUE serial_number) {
226
+ CPhidgetHandle handle = get_ph_handle(self);
227
+ ph_raise(CPhidget_open(handle, FIX2INT(serial_number)));
228
+ return Qnil;
229
+ }
230
+
231
+ VALUE ph_common_open_label(VALUE self, VALUE label) {
232
+ CPhidgetHandle handle = get_ph_handle(self);
233
+ ph_raise(CPhidget_openLabel(handle, StringValueCStr(label)));
234
+ return Qnil;
235
+ }
236
+
237
+ VALUE ph_common_open_remote(VALUE self, VALUE serial_number, VALUE server_id, VALUE password) {
238
+ CPhidgetHandle handle = get_ph_handle(self);
239
+ ph_raise(CPhidget_openRemote(handle, FIX2INT(serial_number), StringValueCStr(server_id), StringValueCStr(password)));
240
+ return Qnil;
241
+ }
242
+
243
+ VALUE ph_common_open_label_remote(VALUE self, VALUE label, VALUE server_id, VALUE password) {
244
+ CPhidgetHandle handle = get_ph_handle(self);
245
+ ph_raise(CPhidget_openLabelRemote(handle, StringValueCStr(label), StringValueCStr(server_id), StringValueCStr(password)));
246
+ return Qnil;
247
+ }
248
+
249
+ VALUE ph_common_open_remote_ip(VALUE self, VALUE serial_number, VALUE address, VALUE port, VALUE password) {
250
+ CPhidgetHandle handle = get_ph_handle(self);
251
+ ph_raise(CPhidget_openRemoteIP(handle, FIX2INT(serial_number), StringValueCStr(address), FIX2INT(port), StringValueCStr(password)));
252
+ return Qnil;
253
+ }
254
+
255
+ VALUE ph_common_open_label_remote_ip(VALUE self, VALUE label, VALUE address, VALUE port, VALUE password) {
256
+ CPhidgetHandle handle = get_ph_handle(self);
257
+ ph_raise(CPhidget_openLabelRemoteIP(handle, StringValueCStr(label), StringValueCStr(address), FIX2INT(port), StringValueCStr(password)));
258
+ return Qnil;
259
+ }
260
+
261
+ VALUE ph_common_wait_for_attachment(VALUE self, VALUE milliseconds) {
262
+ CPhidgetHandle handle = get_ph_handle(self);
263
+ ph_raise(CPhidget_waitForAttachment(handle, FIX2INT(milliseconds)));
264
+ return Qnil;
265
+ }
266
+
267
+ VALUE ph_common_close(VALUE self) {
268
+ CPhidgetHandle handle = get_ph_handle(self);
269
+ ph_raise(CPhidget_close(handle));
270
+ return Qnil;
271
+ }
272
+
273
+ VALUE ph_common_get_device_class(VALUE self) {
274
+ CPhidgetHandle handle = get_ph_handle(self);
275
+ CPhidget_DeviceClass device_class;
276
+ ph_raise(CPhidget_getDeviceClass(handle, &device_class));
277
+ return INT2FIX(device_class);
278
+ }
279
+
280
+ VALUE ph_common_get_device_id(VALUE self) {
281
+ CPhidgetHandle handle = get_ph_handle(self);
282
+ CPhidget_DeviceID device_id;
283
+ ph_raise(CPhidget_getDeviceID(handle, &device_id));
284
+ return INT2FIX(device_id);
285
+ }
286
+
287
+ VALUE ph_common_get_device_type(VALUE self) {
288
+ CPhidgetHandle handle = get_ph_handle(self);
289
+ const char *device_type;
290
+ ph_raise(CPhidget_getDeviceType(handle, &device_type));
291
+ return rb_str_new2(device_type);
292
+ }
293
+
294
+ VALUE ph_common_get_device_name(VALUE self) {
295
+ CPhidgetHandle handle = get_ph_handle(self);
296
+ const char *device_name;
297
+ ph_raise(CPhidget_getDeviceName(handle, &device_name));
298
+ return rb_str_new2(device_name);
299
+ }
300
+
301
+ VALUE ph_common_get_serial_number(VALUE self) {
302
+ CPhidgetHandle handle = get_ph_handle(self);
303
+ int serial;
304
+ ph_raise(CPhidget_getSerialNumber(handle, &serial));
305
+ return INT2FIX(serial);
306
+ }
307
+
308
+ VALUE ph_common_get_device_version(VALUE self) {
309
+ CPhidgetHandle handle = get_ph_handle(self);
310
+ int device_version;
311
+ ph_raise(CPhidget_getDeviceVersion(handle, &device_version));
312
+ return INT2FIX(device_version);
313
+ }
314
+
315
+ VALUE ph_common_get_device_status(VALUE self) {
316
+ CPhidgetHandle handle = get_ph_handle(self);
317
+ int device_status;
318
+ ph_raise(CPhidget_getDeviceStatus(handle, &device_status));
319
+ return INT2FIX(device_status);
320
+ }
321
+
322
+ VALUE ph_common_get_device_label(VALUE self) {
323
+ CPhidgetHandle handle = get_ph_handle(self);
324
+ const char *device_label;
325
+ ph_raise(CPhidget_getDeviceLabel(handle, &device_label));
326
+ return rb_str_new2(device_label);
327
+ }
328
+
329
+ VALUE ph_common_set_device_label(VALUE self, VALUE label) {
330
+ CPhidgetHandle handle = get_ph_handle(self);
331
+ ph_raise(CPhidget_setDeviceLabel(handle, StringValueCStr(label)));
332
+ return Qnil;
333
+ }
334
+
335
+ VALUE ph_common_get_server_id(VALUE self) {
336
+ CPhidgetHandle handle = get_ph_handle(self);
337
+ const char *server_id;
338
+ ph_raise(CPhidget_getServerID(handle, &server_id));
339
+ return rb_str_new2(server_id);
340
+ }
341
+
342
+ VALUE ph_common_get_server_address(VALUE self) {
343
+ CPhidgetHandle handle = get_ph_handle(self);
344
+ const char *address;
345
+ int port;
346
+ ph_raise(CPhidget_getServerAddress(handle, &address, &port));
347
+ return rb_ary_new3(2, rb_str_new2(address), INT2FIX(port));
348
+ }
349
+
350
+ VALUE ph_common_get_server_status(VALUE self) {
351
+ CPhidgetHandle handle = get_ph_handle(self);
352
+ int server_status;
353
+ ph_raise(CPhidget_getServerStatus(handle, &server_status));
354
+ return INT2FIX(server_status);
355
+ }
356
+
357
+ #ifdef PH_CALLBACK
358
+ VALUE ph_common_set_on_attach_handler(VALUE self, VALUE handler) {
359
+ ph_data_t *ph = get_ph_data(self);
360
+ ph_callback_data_t *callback_data = &ph->attach_callback;
361
+ if( TYPE(handler) == T_NIL ) {
362
+ callback_data->exit = true;
363
+ ph_raise(CPhidget_set_OnAttach_Handler(ph->handle, NULL, (void *)NULL));
364
+ } else {
365
+ callback_data->called = false;
366
+ callback_data->exit = false;
367
+ callback_data->phidget = self;
368
+ callback_data->callback = handler;
369
+ ph_raise(CPhidget_set_OnAttach_Handler(ph->handle, ph_common_on_attach, (void *)callback_data));
370
+ ph_callback_thread(callback_data);
371
+ }
372
+ return Qnil;
373
+ }
374
+
375
+ VALUE ph_common_set_on_detach_handler(VALUE self, VALUE handler) {
376
+ ph_data_t *ph = get_ph_data(self);
377
+ ph_callback_data_t *callback_data = &ph->detach_callback;
378
+ if( TYPE(handler) == T_NIL ) {
379
+ callback_data->exit = true;
380
+ ph_raise(CPhidget_set_OnDetach_Handler(ph->handle, NULL, (void *)NULL));
381
+ } else {
382
+ callback_data->called = false;
383
+ callback_data->exit = false;
384
+ callback_data->phidget = self;
385
+ callback_data->callback = handler;
386
+ ph_raise(CPhidget_set_OnDetach_Handler(ph->handle, ph_common_on_detach, (void *)callback_data));
387
+ ph_callback_thread(callback_data);
388
+ }
389
+ return Qnil;
390
+ }
391
+
392
+ VALUE ph_common_set_on_server_connect_handler(VALUE self, VALUE handler) {
393
+ ph_data_t *ph = get_ph_data(self);
394
+ ph_callback_data_t *callback_data = &ph->server_connect_callback;
395
+ if( TYPE(handler) == T_NIL ) {
396
+ callback_data->exit = true;
397
+ ph_raise(CPhidget_set_OnServerConnect_Handler(ph->handle, NULL, (void *)NULL));
398
+ } else {
399
+ callback_data->called = false;
400
+ callback_data->exit = false;
401
+ callback_data->phidget = self;
402
+ callback_data->callback = handler;
403
+ ph_raise(CPhidget_set_OnServerConnect_Handler(ph->handle, ph_common_on_server_connect, (void *)callback_data));
404
+ ph_callback_thread(callback_data);
405
+ }
406
+ return Qnil;
407
+ }
408
+
409
+ VALUE ph_common_set_on_server_disconnect_handler(VALUE self, VALUE handler) {
410
+ ph_data_t *ph = get_ph_data(self);
411
+ ph_callback_data_t *callback_data = &ph->server_disconnect_callback;
412
+ if( TYPE(handler) == T_NIL ) {
413
+ callback_data->exit = true;
414
+ ph_raise(CPhidget_set_OnServerDisconnect_Handler(ph->handle, NULL, (void *)NULL));
415
+ } else {
416
+ callback_data->called = false;
417
+ callback_data->exit = false;
418
+ callback_data->phidget = self;
419
+ callback_data->callback = handler;
420
+ ph_raise(CPhidget_set_OnServerDisconnect_Handler(ph->handle, ph_common_on_server_disconnect, (void *)callback_data));
421
+ ph_callback_thread(callback_data);
422
+ }
423
+ return Qnil;
424
+ }
425
+
426
+
427
+ int ph_common_on_attach(CPhidgetHandle phid, void *userPtr) {
428
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
429
+ callback_data->called = true;
430
+ return EPHIDGET_OK;
431
+ }
432
+
433
+
434
+ int ph_common_on_detach(CPhidgetHandle phid, void *userPtr) {
435
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
436
+ callback_data->called = true;
437
+ return EPHIDGET_OK;
438
+ }
439
+
440
+
441
+ int ph_common_on_server_connect(CPhidgetHandle phid, void *userPtr) {
442
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
443
+ callback_data->called = true;
444
+ return EPHIDGET_OK;
445
+ }
446
+
447
+
448
+ int ph_common_on_server_disconnect(CPhidgetHandle phid, void *userPtr) {
449
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
450
+ callback_data->called = true;
451
+ return EPHIDGET_OK;
452
+ }
453
+ #endif
454
+