Method: RCSimCinterface.rcsim_make_timeWait
- Defined in:
- ext/hruby_sim/hruby_rcsim_build.c
.rcsim_make_timeWait(unitV, delayV) ⇒ Object
Creating a time wait C object.
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 543
VALUE rcsim_make_timeWait(VALUE mod, VALUE unitV, VALUE delayV) {
// printf("rcsim_make_timeWait\n");
/* Allocates the time wait. */
TimeWait timeWait = (TimeWait)malloc(sizeof(TimeWaitS));
// printf("timeWait=%p\n",timeWait);
/* Set it up. */
timeWait->kind = TIME_WAIT;
timeWait->owner = NULL;
/* Compute the delay. */
unsigned long long delay;
delay = NUM2LL(delayV);
/* Adjust the delay depending on the unit. */
const char* unit = rb_id2name(SYM2ID(unitV));
switch(unit[0]) {
case 'f': delay /= 1000; break;
case 'p': /* Ok as is. */ break;
case 'n': delay *= 1000; break;
case 'u': delay *= 1000000; break;
case 'm': delay *= 1000000000; break;
case 's': delay *= 1000000000000; break;
default:
perror("Invalid delay unit.");
}
timeWait->delay = delay;
/* Returns the C time wait embedded into a ruby VALUE. */
VALUE res;
rcsim_to_value(TimeWaitS,timeWait,res);
return res;
}
|