DrQueueRubyBindings 0.1

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 (4) hide show
  1. data/COPYING +674 -0
  2. data/ext/extconf.rb +61 -0
  3. data/ext/libdrqueue_ruby.i +734 -0
  4. metadata +53 -0
data/ext/extconf.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'mkmf'
2
+ require 'ftools'
3
+
4
+ # check if Subversion, SWIG and SCons are installed
5
+ if xsystem('which svn') == false
6
+ puts 'Subversion is not installed'
7
+ exit 1
8
+ end
9
+ if xsystem('which swig') == false
10
+ puts 'SWIG is not installed'
11
+ exit 1
12
+ end
13
+ if xsystem('which scons') == false
14
+ puts 'SCons is not installed'
15
+ exit 1
16
+ end
17
+
18
+ # determine os name
19
+ if RUBY_PLATFORM =~ /darwin/i
20
+ rb_os = '__OSX'
21
+ elsif RUBY_PLATFORM =~ /cygwin/i
22
+ rb_os = '__CYGWIN'
23
+ elsif RUBY_PLATFORM =~ /win32/i
24
+ rb_os = '__CYGWIN'
25
+ elsif RUBY_PLATFORM =~ /linux/i
26
+ rb_os = '__LINUX'
27
+ elsif RUBY_PLATFORM =~ /irix6/i
28
+ rb_os = '__IRIX'
29
+ end
30
+
31
+ # try to do a SVN checkout
32
+ if xsystem('svn co --non-interactive https://ssl.drqueue.org/svn/branches/0.64.x') == false
33
+ puts 'SVN checkout failed'
34
+ exit 1
35
+ end
36
+
37
+ # try to build drqueue
38
+ Dir::chdir '0.64.x'
39
+ if xsystem('scons build_drqman=false') == false
40
+ puts 'DrQueue build failed'
41
+ exit 1
42
+ end
43
+ Dir::chdir '..'
44
+
45
+ # create swig wrapper
46
+ puts 'generating swig interface file'
47
+ puts 'swig -ruby -I0.64.x/ -I0.64.x/libdrqueue -D'+rb_os+' -Wall -autorename libdrqueue_ruby.i'
48
+ xsystem('swig -ruby -I0.64.x/ -I0.64.x/libdrqueue -D'+rb_os+' -Wall -autorename libdrqueue_ruby.i')
49
+ puts 'look for output in mkmf.log'
50
+
51
+ # build for os
52
+ $CFLAGS += ' -D'+rb_os
53
+
54
+ # include the headers
55
+ $CFLAGS += ' -I0.64.x/ -I0.64.x/libdrqueue'
56
+
57
+ # path to the drqueue lib
58
+ $LOCAL_LIBS += '0.64.x/libdrqueue/libdrqueue.a'
59
+
60
+ # create the makefile
61
+ create_makefile('drqueue')
@@ -0,0 +1,734 @@
1
+ //
2
+ // Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Jorge Daza Garcia-Blanes
3
+ // Copyright (C) 2007,2008 Andreas Schroeder
4
+ //
5
+ // This file is part of DrQueue
6
+ //
7
+ // DrQueue is free software; you can redistribute it and/or modify
8
+ // it under the terms of the GNU General Public License as published by
9
+ // the Free Software Foundation; either version 2 of the License, or
10
+ // (at your option) any later version.
11
+ //
12
+ // DrQueue is distributed in the hope that it will be useful,
13
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ // GNU General Public License for more details.
16
+ //
17
+ // You should have received a copy of the GNU General Public License
18
+ // along with this program; if not, write to the Free Software
19
+ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
+ // USA
21
+ //
22
+ //
23
+
24
+
25
+ %define DOCSTRING
26
+ "The drqueue module allows the access to the libdrqueue library responsible
27
+ of all major operations that can be applied remotely to drqueue master and
28
+ slaves. Also provides access to all data structures of DrQueue."
29
+ %enddef
30
+ %module (docstring=DOCSTRING) drqueue
31
+ %{
32
+ #include "libdrqueue.h"
33
+ %}
34
+
35
+
36
+ // Tell SWIG to keep track of mappings between C/C++ structs/classes
37
+ //%trackobjects;
38
+
39
+
40
+ %include "typemaps.i"
41
+
42
+ %typemap(in,numinputs=0) struct computer **computer (struct computer *computer) {
43
+ $1 = &computer;
44
+ }
45
+ %typemap(argout) struct computer **computer {
46
+ if (result < 0) {
47
+ rb_raise(rb_eIOError,drerrno_str());
48
+ $result = (VALUE)NULL;
49
+ } else {
50
+ int i;
51
+ VALUE l = rb_ary_new();
52
+ struct computer *c = malloc (sizeof(struct computer)*result);
53
+ if (!c) {
54
+ rb_raise(rb_eNoMemError,"out of memory");
55
+ return (VALUE)NULL;
56
+ }
57
+ struct computer *tc = c;
58
+ memcpy (c,*$1,sizeof(struct computer)*result);
59
+ for (i=0; i<result; i++) {
60
+ VALUE o = SWIG_NewPointerObj((void*)(tc), SWIGTYPE_p_computer, 1);
61
+ rb_ary_push(l,o);
62
+ tc++;
63
+ }
64
+ free (*$1);
65
+ $result = l;
66
+ }
67
+ }
68
+
69
+
70
+ %typemap(in,numinputs=0) struct job **job (struct job *job) {
71
+ $1 = &job;
72
+ }
73
+ %typemap(argout) struct job **job {
74
+ if (result < 0) {
75
+ rb_raise(rb_eIOError,drerrno_str());
76
+ $result = (VALUE)NULL;
77
+ } else {
78
+ int i;
79
+ VALUE l = rb_ary_new();
80
+ struct job *j = malloc (sizeof(struct job)*result);
81
+ if (!j) {
82
+ rb_raise(rb_eNoMemError,"out of memory");
83
+ return (VALUE)NULL;
84
+ }
85
+ struct job *tj = j;
86
+ memcpy (j,*$1,sizeof(struct job)*result);
87
+ for (i=0; i<result; i++) {
88
+ VALUE o = SWIG_NewPointerObj((void*)(tj), SWIGTYPE_p_job, 1);
89
+ rb_ary_push(l,o);
90
+ tj++;
91
+ }
92
+ free(*$1);
93
+ $result = l;
94
+ }
95
+ }
96
+
97
+
98
+ %include "pointer.h"
99
+ %include "libdrqueue.h"
100
+ %include "computer.h"
101
+ %include "computer_info.h"
102
+ %include "computer_status.h"
103
+ %include "task.h"
104
+ %include "request.h"
105
+ %include "constants.h"
106
+ %include "job.h"
107
+ %include "envvars.h"
108
+ %include "common.h"
109
+ %include "computer_pool.h"
110
+
111
+ // for jobscript generators
112
+ %include "blendersg.h"
113
+ %include "mentalraysg.h"
114
+ %include "cinema4dsg.h"
115
+ %include "luxrendersg.h"
116
+ %include "mayasg.h"
117
+ %include "vraysg.h"
118
+
119
+ // type mapppings
120
+ typedef unsigned int time_t;
121
+ typedef unsigned short int uint16_t;
122
+ typedef unsigned long int uint32_t;
123
+ typedef unsigned char uint8_t;
124
+
125
+
126
+ // these methods generate new objects
127
+ %newobject *::request_job_list;
128
+ %newobject *::request_computer_list;
129
+
130
+
131
+ // JOB
132
+ %extend job {
133
+ job ()
134
+ {
135
+ struct job *j;
136
+ j = (struct job *)malloc (sizeof(struct job));
137
+ if (!j) {
138
+ rb_raise(rb_eNoMemError,"out of memory");
139
+ return (VALUE)NULL;
140
+ }
141
+ job_init (j);
142
+ return j;
143
+ }
144
+
145
+ ~job ()
146
+ {
147
+ job_init(self);
148
+ //free (self);
149
+ job_frame_info_free (self);
150
+ job_delete (self);
151
+ }
152
+
153
+ int environment_variable_add (char *name, char *value)
154
+ {
155
+ return envvars_variable_add (&self->envvars,name,value);
156
+ }
157
+
158
+ int environment_variable_delete (char *name)
159
+ {
160
+ return envvars_variable_delete (&self->envvars,name);
161
+ }
162
+
163
+ char *environment_variable_find (char *name)
164
+ {
165
+ struct envvar *variable;
166
+
167
+ variable = envvars_variable_find (&self->envvars,name);
168
+
169
+ if (!variable) {
170
+ rb_raise(rb_eIndexError,"No such variable");
171
+ return (VALUE)NULL;
172
+ }
173
+
174
+ return variable->value;
175
+ }
176
+
177
+ VALUE request_frame_list (int who)
178
+ {
179
+ VALUE l = rb_ary_new();
180
+ int nframes = job_nframes(self);
181
+ int i;
182
+ if (nframes) {
183
+ struct frame_info *fi = (struct frame_info *)malloc (sizeof(struct frame_info) * nframes);
184
+ if (!fi) {
185
+ rb_raise(rb_eNoMemError,"out of memory");
186
+ return (VALUE)NULL;
187
+ }
188
+ if (!request_job_xferfi (self->id,fi,nframes,who)) {
189
+ rb_raise(rb_eIOError,drerrno_str());
190
+ return (VALUE)NULL;
191
+ }
192
+ for (i=0; i<nframes; i++) {
193
+ VALUE o = SWIG_NewPointerObj((void*)(&fi[i]), SWIGTYPE_p_frame_info, 0);
194
+ rb_ary_push(l,o);
195
+ }
196
+ }
197
+ return l;
198
+ }
199
+
200
+ int job_frame_index_to_number (int index)
201
+ {
202
+ if ((index < 0) || (index >= job_nframes(self))) {
203
+ rb_raise(rb_eIndexError,"frame index out of range");
204
+ return -1;
205
+ }
206
+
207
+ return job_frame_index_to_number (self,index);
208
+ }
209
+
210
+ int request_stop (int who)
211
+ {
212
+ if (!request_job_stop (self->id,who)) {
213
+ rb_raise(rb_eIOError,drerrno_str());
214
+ return 0;
215
+ }
216
+ return 1;
217
+ }
218
+
219
+ int request_rerun (int who)
220
+ {
221
+ if (!request_job_rerun (self->id,who)) {
222
+ rb_raise(rb_eIOError,drerrno_str());
223
+ return 0;
224
+ }
225
+ return 1;
226
+ }
227
+
228
+ int request_hard_stop (int who)
229
+ {
230
+ if (!request_job_hstop (self->id,who)) {
231
+ rb_raise(rb_eIOError,drerrno_str());
232
+ return 0;
233
+ }
234
+ return 1;
235
+ }
236
+
237
+ int request_delete (int who)
238
+ {
239
+ if (!request_job_delete (self->id,who)) {
240
+ rb_raise(rb_eIOError,drerrno_str());
241
+ return 0;
242
+ }
243
+ return 1;
244
+ }
245
+
246
+ int request_continue (int who)
247
+ {
248
+ if (!request_job_continue (self->id,who)) {
249
+ rb_raise(rb_eIOError,drerrno_str());
250
+ return 0;
251
+ }
252
+ return 1;
253
+ }
254
+
255
+ int send_to_queue (void)
256
+ {
257
+ if (!register_job (self)) {
258
+ rb_raise(rb_eIOError,drerrno_str());
259
+ return 0;
260
+ }
261
+ return 1;
262
+ }
263
+
264
+ int update (int who)
265
+ {
266
+ if (!request_job_xfer(self->id,self,who)) {
267
+ rb_raise(rb_eIOError,drerrno_str());
268
+ return 0;
269
+ }
270
+ return 1;
271
+ }
272
+
273
+
274
+ /* Blender script file generation */
275
+ char *blendersg (char *scene, char *scriptdir, uint8_t kind)
276
+ {
277
+ struct blendersgi *blend = (struct blendersgi *)malloc (sizeof(struct blendersgi));
278
+ if (!blend) {
279
+ rb_raise(rb_eNoMemError,"out of memory");
280
+ return NULL;
281
+ }
282
+
283
+ char *outfile = (char *)malloc(sizeof(char *));
284
+ if (!outfile) {
285
+ rb_raise(rb_eNoMemError,"out of memory");
286
+ return NULL;
287
+ }
288
+
289
+ memset (blend,0,sizeof(struct blendersgi));
290
+
291
+ strncpy(blend->scene, scene, BUFFERLEN-1);
292
+ strncpy(blend->scriptdir, scriptdir, BUFFERLEN-1);
293
+ blend->kind = kind;
294
+
295
+ outfile = blendersg_create(blend);
296
+
297
+ if (!outfile) {
298
+ rb_raise(rb_eException,"Problem creating script file");
299
+ return NULL;
300
+ }
301
+
302
+ return outfile;
303
+ }
304
+
305
+ /* blenderlux script file generation */
306
+ char *blenderluxsg (char *scene, char *scriptdir)
307
+ {
308
+ struct blenderluxsgi *luxren = (struct blenderluxsgi *)malloc (sizeof(struct blenderluxsgi));
309
+ if (!luxren) {
310
+ rb_raise(rb_eNoMemError,"out of memory");
311
+ return NULL;
312
+ }
313
+
314
+ char *outfile = (char *)malloc(sizeof(char *));
315
+ if (!outfile) {
316
+ rb_raise(rb_eNoMemError,"out of memory");
317
+ return NULL;
318
+ }
319
+
320
+ memset (luxren,0,sizeof(struct blenderluxsgi));
321
+
322
+ strncpy(luxren->scene, scene, BUFFERLEN-1);
323
+ strncpy(luxren->scriptdir, scriptdir, BUFFERLEN-1);
324
+
325
+ outfile = blenderluxsg_create(luxren);
326
+
327
+ if (!outfile) {
328
+ rb_raise(rb_eException,"Problem creating script file");
329
+ return NULL;
330
+ }
331
+
332
+ return outfile;
333
+ }
334
+
335
+ /* MentalRay script file generation */
336
+ char *mentalraysg (char *scene, char *scriptdir, char *renderdir, char *image, char *file_owner, char *camera, int res_x, int res_y, char *format, uint8_t kind)
337
+ {
338
+ struct mentalraysgi *ment = (struct mentalraysgi *)malloc (sizeof(struct mentalraysgi));
339
+ if (!ment) {
340
+ rb_raise(rb_eNoMemError,"out of memory");
341
+ return NULL;
342
+ }
343
+
344
+ char *outfile = (char *)malloc(sizeof(char *));
345
+ if (!outfile) {
346
+ rb_raise(rb_eNoMemError,"out of memory");
347
+ return NULL;
348
+ }
349
+
350
+ memset (ment,0,sizeof(struct mentalraysgi));
351
+
352
+ strncpy(ment->renderdir, renderdir, BUFFERLEN-1);
353
+ strncpy(ment->scene, scene, BUFFERLEN-1);
354
+ strncpy(ment->image, image, BUFFERLEN-1);
355
+ strncpy(ment->scriptdir, scriptdir, BUFFERLEN-1);
356
+ strncpy(ment->file_owner, file_owner, BUFFERLEN-1);
357
+ strncpy(ment->camera, camera, BUFFERLEN-1);
358
+ ment->res_x = res_x;
359
+ ment->res_y = res_y;
360
+ strncpy(ment->format, format, BUFFERLEN-1);
361
+ ment->kind = kind;
362
+
363
+ outfile = mentalraysg_create(ment);
364
+
365
+ if (!outfile) {
366
+ rb_raise(rb_eException,"Problem creating script file");
367
+ return NULL;
368
+ }
369
+
370
+ return outfile;
371
+ }
372
+
373
+ /* Cinema4D script file generation */
374
+ char *cinema4dsg (char *scene, char *scriptdir, char *file_owner, uint8_t kind)
375
+ {
376
+ struct cinema4dsgi *cine = (struct cinema4dsgi *)malloc (sizeof(struct cinema4dsgi));
377
+ if (!cine) {
378
+ rb_raise(rb_eNoMemError,"out of memory");
379
+ return NULL;
380
+ }
381
+
382
+ char *outfile = (char *)malloc(sizeof(char *));
383
+ if (!outfile) {
384
+ rb_raise(rb_eNoMemError,"out of memory");
385
+ return NULL;
386
+ }
387
+
388
+ memset (cine,0,sizeof(struct cinema4dsgi));
389
+
390
+ strncpy(cine->scene, scene, BUFFERLEN-1);
391
+ strncpy(cine->scriptdir, scriptdir, BUFFERLEN-1);
392
+ strncpy(cine->file_owner, file_owner, BUFFERLEN-1);
393
+ cine->kind = kind;
394
+
395
+ outfile = cinema4dsg_create(cine);
396
+
397
+ if (!outfile) {
398
+ rb_raise(rb_eException,"Problem creating script file");
399
+ return NULL;
400
+ }
401
+
402
+ return outfile;
403
+ }
404
+
405
+ /* LuxRender script file generation */
406
+ char *luxrendersg (char *scene, char *scriptdir)
407
+ {
408
+ struct luxrendersgi *luxren = (struct luxrendersgi *)malloc (sizeof(struct luxrendersgi));
409
+ if (!luxren) {
410
+ rb_raise(rb_eNoMemError,"out of memory");
411
+ return NULL;
412
+ }
413
+
414
+ char *outfile = (char *)malloc(sizeof(char *));
415
+ if (!outfile) {
416
+ rb_raise(rb_eNoMemError,"out of memory");
417
+ return NULL;
418
+ }
419
+
420
+ memset (luxren,0,sizeof(struct luxrendersgi));
421
+
422
+ strncpy(luxren->scene, scene, BUFFERLEN-1);
423
+ strncpy(luxren->scriptdir, scriptdir, BUFFERLEN-1);
424
+
425
+ outfile = luxrendersg_create(luxren);
426
+
427
+ if (!outfile) {
428
+ rb_raise(rb_eException,"Problem creating script file");
429
+ return NULL;
430
+ }
431
+
432
+ return outfile;
433
+ }
434
+
435
+ /* Maya script file generation */
436
+ char *mayasg (char *scene, char *projectdir, char *scriptdir, char *renderdir, char *image, char *file_owner, char *camera, int res_x, int res_y, char *format, uint8_t mentalray)
437
+ {
438
+ struct mayasgi *mayast = (struct mayasgi *)malloc (sizeof(struct mayasgi));
439
+ if (!mayast) {
440
+ rb_raise(rb_eNoMemError,"out of memory");
441
+ return NULL;
442
+ }
443
+
444
+ char *outfile = (char *)malloc(sizeof(char *));
445
+ if (!outfile) {
446
+ rb_raise(rb_eNoMemError,"out of memory");
447
+ return NULL;
448
+ }
449
+
450
+ memset (mayast,0,sizeof(struct mayasgi));
451
+
452
+
453
+ strncpy(mayast->scene, scene, BUFFERLEN-1);
454
+ strncpy(mayast->projectdir, projectdir, BUFFERLEN-1);
455
+ strncpy(mayast->scriptdir, scriptdir, BUFFERLEN-1);
456
+ strncpy(mayast->renderdir, renderdir, BUFFERLEN-1);
457
+ strncpy(mayast->image, image, BUFFERLEN-1);
458
+ strncpy(mayast->file_owner, file_owner, BUFFERLEN-1);
459
+ strncpy(mayast->camera, camera, BUFFERLEN-1);
460
+ mayast->res_x = res_x;
461
+ mayast->res_y = res_y;
462
+ strncpy(mayast->format, format, BUFFERLEN-1);
463
+ mayast->mentalray = mentalray;
464
+
465
+ outfile = mayasg_create(mayast);
466
+
467
+ if (!outfile) {
468
+ rb_raise(rb_eException,"Problem creating script file");
469
+ return NULL;
470
+ }
471
+
472
+ return outfile;
473
+ }
474
+
475
+ /* V-Ray script file generation */
476
+ char *vraysg (char *scene, char *scriptdir)
477
+ {
478
+ struct vraysgi *vray = (struct vraysgi *)malloc (sizeof(struct vraysgi));
479
+ if (!vray) {
480
+ rb_raise(rb_eNoMemError,"out of memory");
481
+ return NULL;
482
+ }
483
+
484
+ char *outfile = (char *)malloc(sizeof(char *));
485
+ if (!outfile) {
486
+ rb_raise(rb_eNoMemError,"out of memory");
487
+ return NULL;
488
+ }
489
+
490
+ memset (vray,0,sizeof(struct vraysgi));
491
+
492
+ strncpy(vray->scene, scene, BUFFERLEN-1);
493
+ strncpy(vray->scriptdir, scriptdir, BUFFERLEN-1);
494
+
495
+ outfile = vraysg_create(vray);
496
+
497
+ if (!outfile) {
498
+ rb_raise(rb_eException,"Problem creating script file");
499
+ return NULL;
500
+ }
501
+
502
+ return outfile;
503
+ }
504
+
505
+ }
506
+
507
+
508
+
509
+ /* COMPUTER LIMITS */
510
+ %extend computer_limits {
511
+ %exception get_pool {
512
+ $action
513
+ if ((!result) || (result == (void *)-1)) {
514
+ rb_raise(rb_eIndexError,"Index out of range");
515
+ return (VALUE)NULL;
516
+ }
517
+ }
518
+ %newobject get_pool;
519
+ struct pool *get_pool (int n)
520
+ {
521
+ struct pool *pool;
522
+
523
+ if (n >= self->npools) {
524
+ return (VALUE)NULL;
525
+ } else if ( n < 0 ) {
526
+ return (VALUE)NULL;
527
+ }
528
+
529
+ pool = (struct pool *)malloc (sizeof (struct pool));
530
+ if (!pool) {
531
+ rb_raise(rb_eNoMemError,"out of memory");
532
+ return (VALUE)NULL;
533
+ }
534
+
535
+ if (self->npools) {
536
+ if ((self->pool.ptr = (struct pool *) computer_pool_attach_shared_memory(self)) == (void*)-1) {
537
+ return pool;
538
+ }
539
+ }
540
+ memcpy(pool,&self->pool.ptr[n],sizeof(struct pool));
541
+
542
+ computer_pool_detach_shared_memory (self);
543
+
544
+ return pool;
545
+ }
546
+
547
+ void pool_add (char *computer_name, char *pool_name, int who)
548
+ {
549
+ if (!request_slave_limits_pool_add(computer_name,pool_name,who)) {
550
+ rb_raise(rb_eIOError,drerrno_str());
551
+ }
552
+ }
553
+
554
+ void pool_remove (char *computer_name, char *pool_name, int who)
555
+ {
556
+ if (!request_slave_limits_pool_remove(computer_name,pool_name,who)) {
557
+ rb_raise(rb_eIOError,drerrno_str());
558
+ }
559
+ }
560
+
561
+ void pool_list ()
562
+ {
563
+ computer_pool_list (self);
564
+ }
565
+ }
566
+
567
+ /* COMPUTER STATUS */
568
+ %extend computer_status {
569
+ %exception get_loadavg {
570
+ $action
571
+ if (result == (uint16_t)-1) {
572
+ rb_raise(rb_eIndexError,"Index out of range");
573
+ return (VALUE)NULL;
574
+ }
575
+ }
576
+ uint16_t get_loadavg (int index)
577
+ {
578
+ if ((index < 0) || (index > 2)) {
579
+ return -1;
580
+ }
581
+
582
+ return self->loadavg[index];
583
+ }
584
+
585
+ %exception get_task {
586
+ $action
587
+ if (!result) {
588
+ rb_raise(rb_eIndexError,"Index out of range");
589
+ return (VALUE)NULL;
590
+ }
591
+ }
592
+ struct task *get_task (int index)
593
+ {
594
+ if ((index < 0) || (index >= MAXTASKS)) {
595
+ return (VALUE)NULL;
596
+ }
597
+ return &self->task[index];
598
+ }
599
+ }
600
+
601
+ // struct pool
602
+ %extend pool {
603
+ pool (char *name)
604
+ {
605
+ struct pool *p;
606
+ p = (struct pool *)malloc (sizeof(struct pool));
607
+ if (!p) {
608
+ rb_raise(rb_eNoMemError,"out of memory");
609
+ return (VALUE)NULL;
610
+ }
611
+ memset (p,0,sizeof(struct pool));
612
+ strncpy (p->name,name,MAXNAMELEN-1);
613
+ return p;
614
+ }
615
+
616
+ ~pool ()
617
+ {
618
+ //free (self);
619
+ computer_pool_free (self);
620
+ }
621
+ }
622
+
623
+
624
+ // COMPUTER
625
+ %extend computer {
626
+ computer ()
627
+ {
628
+ struct computer *c;
629
+ c = (struct computer *)malloc (sizeof(struct computer));
630
+ if (!c) {
631
+ rb_raise(rb_eNoMemError,"out of memory");
632
+ return (VALUE)NULL;
633
+ }
634
+ computer_init(c);
635
+ return c;
636
+ }
637
+
638
+ ~computer ()
639
+ {
640
+ //free (self);
641
+ computer_free (self);
642
+ }
643
+
644
+ VALUE list_pools (void)
645
+ {
646
+ VALUE l = rb_ary_new();
647
+ int npools = self->limits.npools;
648
+
649
+ if ((self->limits.pool.ptr = (struct pool *) computer_pool_attach_shared_memory(&self->limits)) == (void*)-1) {
650
+ rb_raise(rb_eException,drerrno_str());
651
+ return (VALUE)NULL;
652
+ }
653
+
654
+ int i;
655
+ for (i=0;i<npools;i++) {
656
+ struct pool *pool_i = (struct pool *)malloc (sizeof(struct pool));
657
+ if (!pool_i) {
658
+ rb_raise(rb_eNoMemError,"out of memory");
659
+ return (VALUE)NULL;
660
+ }
661
+ memcpy (pool_i,&self->limits.pool.ptr[i],sizeof(struct pool));
662
+ VALUE o = SWIG_NewPointerObj((void*)(pool_i), SWIGTYPE_p_pool, 0);
663
+ rb_ary_push(l,o);
664
+ }
665
+
666
+ computer_pool_detach_shared_memory (&self->limits);
667
+ return l;
668
+ }
669
+
670
+ VALUE set_pools (VALUE pool_list) {
671
+ int i;
672
+ if (RARRAY(pool_list)->len >0) {
673
+ rb_raise(rb_eException,"Expecting a list");
674
+ return (VALUE)NULL;
675
+ }
676
+ int npools = RARRAY(pool_list)->len;
677
+ VALUE old_list = computer_list_pools(self);
678
+ if (RARRAY(old_list)->len >0) {
679
+ rb_raise(rb_eException,"Expecting a list");
680
+ return (VALUE)NULL;
681
+ }
682
+ for (i=0;i<npools;i++) {
683
+ VALUE pool_obj = rb_ary_entry(pool_list,i);
684
+ struct pool *tpool = NULL;
685
+ SWIG_ConvertPtr(pool_obj,(void **)&tpool, SWIGTYPE_p_pool, SWIG_POINTER_EXCEPTION | 0 );
686
+ request_slave_limits_pool_add(self->hwinfo.name,tpool->name,CLIENT);
687
+ }
688
+ int onpools = RARRAY(old_list)->len;
689
+ for (i=0;i<onpools;i++) {
690
+ VALUE pool_obj = rb_ary_entry(old_list,i);
691
+ struct pool *tpool = NULL;
692
+ SWIG_ConvertPtr(pool_obj,(void **)&tpool, SWIGTYPE_p_pool, SWIG_POINTER_EXCEPTION | 0 );
693
+ request_slave_limits_pool_remove(self->hwinfo.name,tpool->name,CLIENT);
694
+ }
695
+ VALUE last_list = computer_list_pools(self);
696
+ return last_list;
697
+ }
698
+
699
+ void request_enable (int who)
700
+ {
701
+ if (!request_slave_limits_enabled_set (self->hwinfo.name,1,who)) {
702
+ rb_raise(rb_eIOError,drerrno_str());
703
+ }
704
+ }
705
+
706
+ void request_disable (int who)
707
+ {
708
+ if (!request_slave_limits_enabled_set (self->hwinfo.name,0,who)) {
709
+ rb_raise(rb_eIOError,drerrno_str());
710
+ }
711
+ }
712
+
713
+ void update (int who)
714
+ {
715
+ if (!request_comp_xfer(self->hwinfo.id,self,who)) {
716
+ rb_raise(rb_eIOError,drerrno_str());
717
+ }
718
+ }
719
+
720
+ void add_pool (char *pool_name, int who)
721
+ {
722
+ if (!request_slave_limits_pool_add(self->hwinfo.name,pool_name,who)) {
723
+ rb_raise(rb_eIOError,drerrno_str());
724
+ }
725
+ }
726
+
727
+ void remove_pool (char *pool_name, int who)
728
+ {
729
+ if (!request_slave_limits_pool_remove(self->hwinfo.name,pool_name,who)) {
730
+ rb_raise(rb_eIOError,drerrno_str());
731
+ }
732
+ }
733
+ }
734
+