Example #1
0
int main( int argc, char** argv ) 
{
  int state  = 0;
  int rc     = 0;
  int opt_mv = 0;

  crate_app ca;

  /** startup items from ruby's original main.c */
#ifdef _WIN32
  NtInitialize(&argc, &argv);
#endif
#if defined(__MACOS__) && defined(__MWERKS__)
  argc = ccommand(&argv);
#endif

  /* setup ruby */
  ruby_init();
  ruby_script( argv[0] );
  ruby_init_loadpath();

  /* strip out the crate specific arguments from argv using --crate- */
  opt_mv = crate_init_from_options( &ca, argc, argv );
  argc -= opt_mv;
  argv += opt_mv;
 
  /* printf("crate file  : %s\n", ca.file_name);   */
  /* printf("crate class : %s\n", ca.class_name);  */
  /* printf("crate method: %s\n", ca.method_name); */

  /* make ARGV available */
  ruby_set_argv( argc, argv );

  /* initialize all extensions */
  Init_ext();

  /* load up the amalgalite libs */
  am_bootstrap_lift( cARB, Qnil );
 
  /* remove the current LOAD_PATH */
  rb_ary_clear( rb_gv_get( "$LOAD_PATH" ) );

  /* invoke the class / method passing in ARGV and ENV */
  rb_protect( crate_wrap_app, (VALUE)&ca, &state );

  /* check the results */
  if ( state ) {

    /* exception was raised, check the $! var */
    VALUE lasterr  = rb_gv_get("$!");
   
    /* system exit was called so just propogate that up to our exit */
    if ( rb_obj_is_instance_of( lasterr, rb_eSystemExit ) ) {

      rc = NUM2INT( rb_attr_get( lasterr, rb_intern("status") ) );
      /*printf(" Caught SystemExit -> $? will be %d\n", rc ); */

    } else {

      /* some other exception was raised so dump that out */
      VALUE klass     = rb_class_path( CLASS_OF( lasterr ) );
      VALUE message   = rb_obj_as_string( lasterr );
      VALUE backtrace = rb_funcall( lasterr, rb_intern("backtrace"), 0 );

      fprintf( stderr, "%s: %s\n", RSTRING( klass )->ptr, RSTRING( message )->ptr );
      rb_iterate( rb_each, backtrace, dump_backtrace, Qnil );

      rc = state;
    }
  } 

  free( ca.file_name );
  free( ca.class_name );
  free( ca.method_name );

  /* shut down ruby */
  ruby_finalize();

  /* exit the program */
  exit( rc );
}
Example #2
0
static VALUE
syserr_errno(VALUE self)
{
    return rb_attr_get(self, rb_intern("errno"));
}
Example #3
0
VALUE
rb_exc_new_str(VALUE etype, VALUE str)
{
    StringValue(str);
    return rb_funcall(etype, rb_intern("new"), 1, str);
}
Example #4
0
static VALUE rldap_search(int argc, VALUE *argv, VALUE obj)
{
	RLDAP_WRAP *wrapper;
	char *base, *filter;
	int retval, count, i, scope;
	LDAPMessage *res, *msg;
	VALUE ary, rbase, rfilter, rscope;
	ID iscope;
	
	rb_scan_args(argc, argv, "21", &rbase, &rfilter, &rscope);

	switch(TYPE(rscope)) {
		case T_NIL:
			scope = LDAP_SCOPE_SUBTREE;
			break;
		case T_FIXNUM:
			scope = FIX2INT(rscope);
			break;
		case T_SYMBOL:
		case T_STRING:
			iscope = rb_to_id(rscope);
			if (iscope == rb_intern("subtree"))
				scope = LDAP_SCOPE_SUBTREE;
			if (iscope == rb_intern("base"))
				scope = LDAP_SCOPE_BASE;
			if (iscope == rb_intern("one"))
				scope = LDAP_SCOPE_ONE;
			break;
		default:
			rb_raise(rb_eTypeError, "not a valid scope");
			break;
	}
	
	wrapper = get_wrapper(obj);
	base = StringValuePtr(rbase);
	filter = StringValuePtr(rfilter);

	retval = ldap_search_ext_s(wrapper->ld, base, scope, filter, NULL, 0, NULL, NULL, NULL, 0, &res);

	if (retval != LDAP_SUCCESS)
		rldap_raise(retval);

	count = ldap_count_entries(wrapper->ld, res);
	
	if (count == -1) {
		int errno;
		ldap_get_option(wrapper->ld, LDAP_OPT_RESULT_CODE, &errno);
		rldap_raise(errno);
	}
	
	ary = rb_ary_new2((long)count);
	
	msg = ldap_first_entry(wrapper->ld, res);
	
	for (i=0; i<count; i++) {
		rb_ary_store(ary, (long)i, ldapmessage2obj(wrapper->ld, msg));
		msg = ldap_next_entry(wrapper->ld, msg);
	}
	
	return ary;
}
Example #5
0
static VALUE
name_err_name(VALUE self)
{
    return rb_attr_get(self, rb_intern("name"));
}
Example #6
0
jobject event_cast<jobject, VALUE>(VALUE rEvent)
{
    if (NIL_P(rEvent))
        return NULL;

    RHO_TRACE("eventFromRuby (1)");
    JNIEnv *env = jnienv();
    if (!init_event_stuff(env))
        return NULL;

    RHO_TRACE("eventFromRuby (2)");
    VALUE rId = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_ID));
    if (NIL_P(rId))
        rId = rb_str_new2("");
    Check_Type(rId, T_STRING);

    RHO_TRACE("eventFromRuby (3)");
    jmethodID mid = getJNIClassMethod(env, clsEvent, "<init>", "(Ljava/lang/String;)V");
    if (!mid) return NULL;

    jhstring jhId = rho_cast<jstring>(env, rId);
    jobject jEvent = env->NewObject(clsEvent, mid, jhId.get());
    if (!jEvent) return NULL;

    RHO_TRACE("eventFromRuby (4)");
    VALUE rTitle = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_TITLE));
    if (!NIL_P(rTitle))
    {
        Check_Type(rTitle, T_STRING);
        jhstring jhTitle = rho_cast<jstring>(env, rTitle);
        env->SetObjectField(jEvent, fidTitle, jhTitle.get());
    }

    RHO_TRACE("eventFromRuby (5)");
    VALUE rStartDate = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_START_DATE));
    if (!NIL_P(rStartDate))
        env->SetObjectField(jEvent, fidStartDate, date_cast<jobject>(rStartDate));

    RHO_TRACE("eventFromRuby (6)");
    VALUE rEndDate = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_END_DATE));
    if (!NIL_P(rEndDate))
        env->SetObjectField(jEvent, fidEndDate, date_cast<jobject>(rEndDate));

    RHO_TRACE("eventFromRuby (7)");
    VALUE rLastModified = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_LAST_MODIFIED));
    if (!NIL_P(rLastModified))
        env->SetObjectField(jEvent, fidLastModified, date_cast<jobject>(rLastModified));

    RHO_TRACE("eventFromRuby (8)");
    VALUE rLocation = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_LOCATION));
    if (!NIL_P(rLocation))
    {
        Check_Type(rLocation, T_STRING);
        jhstring jhLocation = rho_cast<jstring>(env, rLocation);
        env->SetObjectField(jEvent, fidLocation, jhLocation.get());
    }

    RHO_TRACE("eventFromRuby (9)");
    VALUE rNotes = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_NOTES));
    if (!NIL_P(rNotes))
    {
        Check_Type(rNotes, T_STRING);
        jhstring jhNotes = rho_cast<jstring>(env, rNotes);
        env->SetObjectField(jEvent, fidNotes, jhNotes.get());
    }

    RHO_TRACE("eventFromRuby privacy");
    VALUE rPrivacy = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_PRIVACY));
    if (!NIL_P(rPrivacy))
    {
        Check_Type(rPrivacy, T_STRING);
        jhstring jhPrivacy = rho_cast<jstring>(env, rPrivacy);
        env->SetObjectField(jEvent, fidPrivacy, jhPrivacy.get());
    }

    RHO_TRACE("eventFromRuby recurrence");
    VALUE rRecurrence = rb_hash_aref(rEvent, rb_str_new2(RUBY_EV_RECURRENCE));
    if (!NIL_P(rRecurrence)) {
        Check_Type(rRecurrence, T_HASH);

        VALUE rFrequency = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_FREQUENCY));
        Check_Type(rFrequency, T_STRING);
        const char *frequency = RSTRING_PTR(rFrequency);
        if (   strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_DAILY) != 0
        	&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_WEEKLY) != 0
        	&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_MONTHLY) != 0
        	&& strcasecmp(frequency, RUBY_EV_RECURRENCE_FREQUENCY_YEARLY) != 0)
        {
        	rb_raise(rb_eArgError, "Wrong recurrence frequency: %s", frequency);
        }
        jhstring jhFreq = rho_cast<jstring>(env, rFrequency);
        env->SetObjectField(jEvent, fidFrequency, jhFreq.get());

        VALUE rInterval = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_INTERVAL));
        rInterval = rb_funcall(rInterval, rb_intern("to_i"), 0);
        int interval = NUM2INT(rInterval);
        env->SetIntField(jEvent, fidInterval, interval);
        RAWTRACE1("eventFromRuby recurrence interval: %d", interval);

        VALUE rUntilDate = rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_END));
        if (!NIL_P(rUntilDate))
        {
            env->SetObjectField(jEvent, fidRecurrenceEnd, date_cast<jobject>(rUntilDate));
            RAWTRACE("eventFromRuby recurrence until date");
        }

        VALUE rTimes = rb_funcall(rb_hash_aref(rRecurrence, rb_str_new2(RUBY_EV_RECURRENCE_COUNT)), rb_intern("to_i"), 0);;
        int times = NUM2INT(rTimes);
        env->SetIntField(jEvent, fidRecurrenceTimes, times);
        RAWTRACE1("eventFromRuby recurrence count: %d", times);
    }

    RHO_TRACE("eventFromRuby: return");
    return jEvent;
}
Example #7
0
static VALUE
range_eqq(VALUE range, VALUE val)
{
    return rb_funcall(range, rb_intern("include?"), 1, val);
}
Example #8
0
/* Create a new selector. This is more or less the pure Ruby version
   translated into an MRI cext */
static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
{
    ID backend_id;
    VALUE backend;
    VALUE lock;

    struct NIO_Selector *selector;
    unsigned int flags = 0;

    Data_Get_Struct(self, struct NIO_Selector, selector);

    rb_scan_args(argc, argv, "01", &backend);

    if(backend != Qnil) {
        if(!rb_ary_includes(NIO_Selector_supported_backends(CLASS_OF(self)), backend)) {
            rb_raise(rb_eArgError, "unsupported backend: %s",
                RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
        }

        backend_id = SYM2ID(backend);

        if(backend_id == rb_intern("epoll")) {
            flags = EVBACKEND_EPOLL;
        } else if(backend_id == rb_intern("poll")) {
            flags = EVBACKEND_POLL;
        } else if(backend_id == rb_intern("kqueue")) {
            flags = EVBACKEND_KQUEUE;
        } else if(backend_id == rb_intern("select")) {
            flags = EVBACKEND_SELECT;
        } else if(backend_id == rb_intern("port")) {
            flags = EVBACKEND_PORT;
        } else {
            rb_raise(rb_eArgError, "unsupported backend: %s",
                RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
        }
    }

    /* Ensure the selector loop has not yet been initialized */
    assert(!selector->ev_loop);

    selector->ev_loop = ev_loop_new(flags);
    if(!selector->ev_loop) {
        rb_raise(rb_eIOError, "error initializing event loop");
    }

    ev_io_start(selector->ev_loop, &selector->wakeup);

    rb_ivar_set(self, rb_intern("selectables"), rb_hash_new());
    rb_ivar_set(self, rb_intern("lock_holder"), Qnil);

    lock = rb_class_new_instance(0, 0, rb_const_get(rb_cObject, rb_intern("Mutex")));
    rb_ivar_set(self, rb_intern("lock"), lock);
    rb_ivar_set(self, rb_intern("lock_holder"), Qnil);

    return Qnil;
}
Example #9
0
/* True if there are monitors on the loop */
static VALUE NIO_Selector_is_empty(VALUE self)
{
    VALUE selectables = rb_ivar_get(self, rb_intern("selectables"));

    return rb_funcall(selectables, rb_intern("empty?"), 0) == Qtrue ? Qtrue : Qfalse;
}
Example #10
0
void
Init_Enumerator(void)
{
    id_rewind = rb_intern("rewind");
    id_each = rb_intern("each");
    id_call = rb_intern("call");
    id_size = rb_intern("size");
    id_yield = rb_intern("yield");
    id_new = rb_intern("new");
    id_initialize = rb_intern("initialize");
    id_next = rb_intern("next");
    id_result = rb_intern("result");
    id_lazy = rb_intern("lazy");
    id_eqq = rb_intern("===");
    id_receiver = rb_intern("receiver");
    id_arguments = rb_intern("arguments");
    id_memo = rb_intern("memo");
    id_method = rb_intern("method");
    id_force = rb_intern("force");
    id_to_enum = rb_intern("to_enum");
    sym_each = ID2SYM(id_each);
    sym_cycle = ID2SYM(rb_intern("cycle"));

    InitVM(Enumerator);
}
Example #11
0
static VALUE rb_fastadd_add_one(int argc, VALUE *argv, VALUE self)
{
  int n = NUM2INT(rb_funcall(self, rb_intern("n"), 0));
  return INT2NUM(n + 1);
}
Example #12
0
/* GravityFind {{{ */
static VALUE
GravityFind(char *source,
  int flags)
{
  int ngravities = 0;
  char **gravities = NULL;
  VALUE ret = Qnil;

  subSubtlextConnect(NULL); ///< Implicit open connection

  /* Get gravity list */
  if((gravities = subSharedPropertyGetStrings(display, DefaultRootWindow(display),
      XInternAtom(display, "SUBTLE_GRAVITY_LIST", False), &ngravities)))
    {
      int i, selid = -1;
      XRectangle geometry = { 0 };
      char buf[30] = { 0 };
      VALUE klass_grav = Qnil, klass_geom = Qnil, meth = Qnil;
      VALUE gravity = Qnil, geom = Qnil;
      regex_t *preg = NULL;

      /* Fetch data */
      klass_grav = rb_const_get(mod, rb_intern("Gravity"));
      klass_geom = rb_const_get(mod, rb_intern("Geometry"));
      meth       = rb_intern("new");

      /* Create if source is given */
      if(source)
        {
          if(isdigit(source[0])) selid = atoi(source);
          preg = subSharedRegexNew(source);
        }

      /* Create gravity list */
      for(i = 0; i < ngravities; i++)
        {
          sscanf(gravities[i], "%hdx%hd+%hd+%hd#%s", &geometry.x, &geometry.y,
            &geometry.width, &geometry.height, buf);

          /* Check if gravity matches */
          if(!source || (source && (selid == i || (-1 == selid &&
              ((flags & SUB_MATCH_EXACT && 0 == strcmp(source, buf)) ||
              (preg && !(flags & SUB_MATCH_EXACT) &&
                subSharedRegexMatch(preg, buf)))))))
            {
              /* Create new gravity */
              gravity = rb_funcall(klass_grav, meth, 1, rb_str_new2(buf));
              geom    = rb_funcall(klass_geom, meth, 4, INT2FIX(geometry.x),
                INT2FIX(geometry.y), INT2FIX(geometry.width),
                INT2FIX(geometry.height));

              rb_iv_set(gravity, "@id",       INT2FIX(i));
              rb_iv_set(gravity, "@geometry", geom);

              ret = subSubtlextOneOrMany(gravity, ret);
            }
        }

      if(preg)    subSharedRegexKill(preg);
      XFreeStringList(gravities);
    }
  else rb_raise(rb_eStandardError, "Failed getting gravity list");

  return NIL_P(ret) ? rb_ary_new() : ret;
} /* }}} */
Example #13
0
static VALUE
rb_hash_delete(VALUE hash, VALUE key)
{
  return rb_funcall(hash, rb_intern("delete"), 1, key);
}
Example #14
0
static VALUE
exit_status(VALUE exc, SEL sel)
{
    return rb_attr_get(exc, rb_intern("status"));
}
Example #15
0
/* 
 * Returns the record in this DtraceBufdata. Records are returned as
 * either DtraceRecords or DtraceStackRecords as appropriate for the
 * type of action.
 */
VALUE dtracebufdata_record(VALUE self)
{
  dtrace_bufdata_t *bufdata;
  const dtrace_recdesc_t *rec;
  dtrace_actkind_t act = DTRACEACT_NONE;
  const char *s;
  VALUE v = Qnil;
  VALUE dtracerecord;
  VALUE dtraceaggdata;
  VALUE dtracerecdesc;

  Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
  
  if (bufdata->dtbda_aggdata) {
    dtraceaggdata = Data_Wrap_Struct(cDtraceAggData, 0, NULL, (dtrace_bufdata_t *)bufdata);
    return dtraceaggdata;
  }

  s = bufdata->dtbda_buffered;
  if (s == NULL) {
    return Qnil;
  }
  
  rec = bufdata->dtbda_recdesc;
  if (rec) {
    act = rec->dtrd_action;
  }
  
  switch (act) {
  case DTRACEACT_DIFEXPR:
    /* trace() action */
    break;
  case DTRACEACT_PRINTF:
    /* printf action, not available in probedata */
    v = rb_str_new2(s);
    dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::PrintfRecord"));
    rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
    rb_iv_set(dtracerecord, "@value", v);
    return (dtracerecord);
    break;
  case DTRACEACT_STACK:
  case DTRACEACT_USTACK:
  case DTRACEACT_JSTACK:
    /* stand-alone stack(), ustack(), or jstack() action */
    v = rb_str_new2(s);
    dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::StackRecord"));
    rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
    rb_funcall(dtracerecord, rb_intern("parse"), 1, v);
    return (dtracerecord);
    break;
  case DTRACEACT_USYM:
  case DTRACEACT_UADDR:
  case DTRACEACT_UMOD:
  case DTRACEACT_SYM:
  case DTRACEACT_MOD:
    v = rb_str_new2(s);
    break;
  case DTRACEACT_PRINTA:
    v = rb_str_new2(s);
    break;
  default:
    /*
     * The record handle defers nothing else to this
     * bufhandler.
     */
    break;
  }

  if (!NIL_P(v)) {
    dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("Dtrace::Record"));
    rb_iv_set(dtracerecord, "@value", v);
    rb_iv_set(dtracerecord, "@action", INT2FIX(act));
    rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
    return (dtracerecord);
  }
  else {
    return Qnil;
  }
}
Example #16
0
static void
dict_each_key (const char *key, xmmsv_t *value, void *udata)
{
	rb_yield (ID2SYM (rb_intern (key)));
}
Example #17
0
mpc_rnd_t r_get_default_mpc_rounding_mode()
{
  return r_get_mpc_rounding_mode (rb_const_get (cMPC, rb_intern ("MPC_RNDNN")));
}
Example #18
0
File: init.c Project: Carroll/vying
void Init_boardext() {

  /* Map Coord */

  Coord = rb_define_class( "Coord", rb_cObject );
  
  rb_define_singleton_method( Coord, "[]", coord_class_subscript, -1 );
                                                              /* in coord.c */
  rb_define_method( Coord, "+", coord_addition, 1 );          /* in coord.c */
  rb_define_method( Coord, "direction_to", coord_direction_to, 1 ); 
                                                              /* in coord.c */

  /* Map Coords */

  Coords = rb_define_class( "Coords", rb_cObject );

  rb_define_method( Coords, "include?", coords_include, 1 ); /* in coords.c */
  rb_define_method( Coords, "next", coords_next, 2 );        /* in coords.c */


  /* Map Board */

  Board = rb_define_class( "Board", rb_cObject );

  rb_define_method( Board, "in_bounds?", board_in_bounds, 2 );
                                                              /* in board.c */
  rb_define_method( Board, "[]", board_subscript, -1 );       /* in board.c */
  rb_define_method( Board, "[]=", board_subscript_assign, -1 );
                                                              /* in board.c */
  rb_define_method( Board, "get", board_get, 2 );             /* in board.c */
  rb_define_method( Board, "set", board_set, 3 );             /* in board.c */

  rb_define_method( Board, "ci", board_ci, 2 );               /* in board.c */


  /* Plugins namespace. */

  Plugins  = rb_define_module_under( Board, "Plugins" );


  /* Map Board::Plugins::Frontier */

  Frontier = rb_define_module_under( Plugins, "Frontier" );

  rb_define_method( Frontier, "update_frontier", frontier_update, 2 );
                                                           /* in frontier.c */

  /* Map Board::Plugins::CustodialFlip */

  CustodialFlip = rb_define_module_under( Plugins, "CustodialFlip" );

  rb_define_method( CustodialFlip, "will_flip?", custodial_flip_valid, 2 );
                                                     /* in custodial_flip.c */
  rb_define_method( CustodialFlip, "custodial_flip", custodial_flip, 2 );
                                                     /* in custodial_flip.c */

  /* Look up all our ids */

  id_dup = rb_intern("dup");
  id_x = rb_intern("x");
  id_y = rb_intern("y");
  id_subscript = rb_intern("[]");
  id_subscript_assign = rb_intern("[]=");
  id_new = rb_intern("new");
  id_hash = rb_intern("hash");
  id_include = rb_intern("include?");
  id_n = rb_intern("n");
  id_s = rb_intern("s");
  id_w = rb_intern("w");
  id_e = rb_intern("e");
  id_se = rb_intern("se");
  id_nw = rb_intern("nw");
  id_sw = rb_intern("sw");
  id_ne = rb_intern("ne");
  id_DIRECTIONS = rb_intern("DIRECTIONS");
  id_white = rb_intern("white");
  id_black = rb_intern("black");
  id_delete = rb_intern("delete");
  id_uniq_ex = rb_intern("uniq!");
  id_to_s = rb_intern( "to_s" );
  id_before_set = rb_intern( "before_set" );
  id_after_set = rb_intern( "after_set" );

  /* Look up all our symbols */

  sym_white = ID2SYM(id_white);
  sym_black = ID2SYM(id_black);
  sym_n = ID2SYM(id_n);
  sym_s = ID2SYM(id_s);
  sym_w = ID2SYM(id_w);
  sym_e = ID2SYM(id_e);
  sym_se = ID2SYM(id_se);
  sym_nw = ID2SYM(id_nw);
  sym_sw = ID2SYM(id_sw);
  sym_ne = ID2SYM(id_ne);

}
Example #19
0
static VALUE
range_step(int argc, VALUE *argv, VALUE range)
{
    VALUE b, e, step, tmp;

    RETURN_ENUMERATOR(range, argc, argv);

    b = RANGE_BEG(range);
    e = RANGE_END(range);
    if (argc == 0) {
	step = INT2FIX(1);
    }
    else {
	rb_scan_args(argc, argv, "01", &step);
	if (!rb_obj_is_kind_of(step, rb_cNumeric)) {
	    step = rb_to_int(step);
	}
	if (rb_funcall(step, '<', 1, INT2FIX(0))) {
	    rb_raise(rb_eArgError, "step can't be negative");
	}
	else if (!rb_funcall(step, '>', 1, INT2FIX(0))) {
	    rb_raise(rb_eArgError, "step can't be 0");
	}
    }

    if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */
	long end = FIX2LONG(e);
	long i, unit = FIX2LONG(step);

	if (!EXCL(range))
	    end += 1;
	i = FIX2LONG(b);
	while (i < end) {
	    rb_yield(LONG2NUM(i));
	    if (i + unit < i) break;
	    i += unit;
	}

    }
    else if (SYMBOL_P(b) && SYMBOL_P(e)) { /* symbols are special */
	VALUE args[2], iter[2];

	args[0] = rb_sym_to_s(e);
	args[1] = EXCL(range) ? Qtrue : Qfalse;
	iter[0] = INT2FIX(1);
	iter[1] = step;
	rb_block_call(rb_sym_to_s(b), rb_intern("upto"), 2, args, sym_step_i, (VALUE)iter);
    }
    else if (ruby_float_step(b, e, step, EXCL(range))) {
	/* done */
    }
    else if (rb_obj_is_kind_of(b, rb_cNumeric) ||
	     !NIL_P(rb_check_to_integer(b, "to_int")) ||
	     !NIL_P(rb_check_to_integer(e, "to_int"))) {
	ID op = EXCL(range) ? '<' : rb_intern("<=");
	VALUE v = b;
	int i = 0;

	while (RTEST(rb_funcall(v, op, 1, e))) {
	    rb_yield(v);
	    i++;
	    v = rb_funcall(b, '+', 1, rb_funcall(INT2NUM(i), '*', 1, step));
	}
    }
    else {
	tmp = rb_check_string_type(b);

	if (!NIL_P(tmp)) {
	    VALUE args[2], iter[2];

	    b = tmp;
	    args[0] = e;
	    args[1] = EXCL(range) ? Qtrue : Qfalse;
	    iter[0] = INT2FIX(1);
	    iter[1] = step;
	    rb_block_call(b, rb_intern("upto"), 2, args, step_i, (VALUE)iter);
	}
	else {
	    VALUE args[2];

	    if (!rb_respond_to(b, id_succ)) {
		rb_raise(rb_eTypeError, "can't iterate from %s",
			 rb_obj_classname(b));
	    }
	    args[0] = INT2FIX(1);
	    args[1] = step;
	    range_each_func(range, step_i, args);
	}
    }
    return range;
}
Example #20
0
ASN1_TYPE*
ossl_asn1_get_asn1type(VALUE obj)
{
    ASN1_TYPE *ret;
    VALUE value, rflag;
    void *ptr;
    void (*free_func)();
    long tag, flag;

    tag = ossl_asn1_default_tag(obj);
    value = ossl_asn1_get_value(obj);
    switch(tag){
    case V_ASN1_BOOLEAN:
	ptr = (void*)obj_to_asn1bool(value);
	free_func = NULL;
	break;
    case V_ASN1_INTEGER:         /* FALLTHROUGH */
    case V_ASN1_ENUMERATED:
	ptr = obj_to_asn1int(value);
	free_func = ASN1_INTEGER_free;
	break;
    case V_ASN1_BIT_STRING:
        rflag = rb_attr_get(obj, rb_intern("@unused_bits"));
        flag = NIL_P(rflag) ? -1 : NUM2INT(rflag);
	ptr = obj_to_asn1bstr(value, flag);
	free_func = ASN1_BIT_STRING_free;
	break;
    case V_ASN1_NULL:
	ptr = obj_to_asn1null(value);
	free_func = ASN1_NULL_free;
	break;
    case V_ASN1_OCTET_STRING:    /* FALLTHROUGH */
    case V_ASN1_UTF8STRING:      /* FALLTHROUGH */
    case V_ASN1_NUMERICSTRING:   /* FALLTHROUGH */
    case V_ASN1_PRINTABLESTRING: /* FALLTHROUGH */
    case V_ASN1_T61STRING:       /* FALLTHROUGH */
    case V_ASN1_VIDEOTEXSTRING:  /* FALLTHROUGH */
    case V_ASN1_IA5STRING:       /* FALLTHROUGH */
    case V_ASN1_GRAPHICSTRING:   /* FALLTHROUGH */
    case V_ASN1_ISO64STRING:     /* FALLTHROUGH */
    case V_ASN1_GENERALSTRING:   /* FALLTHROUGH */
    case V_ASN1_UNIVERSALSTRING: /* FALLTHROUGH */
    case V_ASN1_BMPSTRING:   
	ptr = obj_to_asn1str(value);
	free_func = ASN1_STRING_free;
	break;
    case V_ASN1_OBJECT:
	ptr = obj_to_asn1obj(value);
	free_func = ASN1_OBJECT_free;
	break;
    case V_ASN1_UTCTIME:
	ptr = obj_to_asn1utime(value);
	free_func = ASN1_TIME_free;
	break;
    case V_ASN1_GENERALIZEDTIME:
	ptr = obj_to_asn1gtime(value);
	free_func = ASN1_TIME_free;
	break;
    case V_ASN1_SET:             /* FALLTHROUGH */
    case V_ASN1_SEQUENCE:
	ptr = obj_to_asn1derstr(obj);
	free_func = ASN1_STRING_free;
	break;
    default:
	ossl_raise(eASN1Error, "unsupported ASN.1 type");
    }
    if(!(ret = OPENSSL_malloc(sizeof(ASN1_TYPE)))){
	if(free_func) free_func(ptr);
	ossl_raise(eASN1Error, "ASN1_TYPE alloc failure");
    }
    memset(ret, 0, sizeof(ASN1_TYPE));
    ASN1_TYPE_set(ret, tag, ptr);

    return ret;
}
Example #21
0
/*  call-seq:
 *     OpenSSL::PKey::EC.new()
 *     OpenSSL::PKey::EC.new(ec_key)
 *     OpenSSL::PKey::EC.new(ec_group)
 *     OpenSSL::PKey::EC.new("secp112r1")
 *     OpenSSL::PKey::EC.new(pem_string)
 *     OpenSSL::PKey::EC.new(pem_string [, pwd])
 *     OpenSSL::PKey::EC.new(der_string)
 *
 *  See the OpenSSL documentation for:
 *     EC_KEY_*
 */
static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
{
    EVP_PKEY *pkey;
    EC_KEY *ec = NULL;
    VALUE arg, pass;
    VALUE group = Qnil;
    char *passwd = NULL;

    GetPKey(self, pkey);
    if (pkey->pkey.ec)
        ossl_raise(eECError, "EC_KEY already initialized");

    rb_scan_args(argc, argv, "02", &arg, &pass);

    if (NIL_P(arg)) {
        ec = EC_KEY_new();
    } else {
        if (rb_obj_is_kind_of(arg, cEC)) {
            EC_KEY *other_ec = NULL;

            SafeRequire_EC_KEY(arg, other_ec);
            ec = EC_KEY_dup(other_ec);
        } else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
        	ec = EC_KEY_new();
        	group = arg;
        } else {
            BIO *in = ossl_obj2bio(arg);

            if (!NIL_P(pass)) {
		passwd = StringValuePtr(pass);
	    }
	    ec = PEM_read_bio_ECPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
            if (!ec) {
		OSSL_BIO_reset(in);
		ec = PEM_read_bio_EC_PUBKEY(in, NULL, ossl_pem_passwd_cb, passwd);
            }
            if (!ec) {
		OSSL_BIO_reset(in);
                ec = d2i_ECPrivateKey_bio(in, NULL);
            }
            if (!ec) {
		OSSL_BIO_reset(in);
                ec = d2i_EC_PUBKEY_bio(in, NULL);
            }

            BIO_free(in);

            if (ec == NULL) {
                const char *name = StringValueCStr(arg);
                int nid = OBJ_sn2nid(name);

                (void)ERR_get_error();
                if (nid == NID_undef)
                    ossl_raise(eECError, "unknown curve name (%s)\n", name);

                if ((ec = EC_KEY_new_by_curve_name(nid)) == NULL)
                    ossl_raise(eECError, "unable to create curve (%s)\n", name);

                EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
                EC_KEY_set_conv_form(ec, POINT_CONVERSION_UNCOMPRESSED);
            }
        }
    }

    if (ec == NULL)
        ossl_raise(eECError, NULL);

    if (!EVP_PKEY_assign_EC_KEY(pkey, ec)) {
	EC_KEY_free(ec);
	ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY");
    }

    rb_iv_set(self, "@group", Qnil);

    if (!NIL_P(group))
        rb_funcall(self, rb_intern("group="), 1, arg);

    return self;
}
Example #22
0
static VALUE
ossl_asn1_decode0(unsigned char **pp, long length, long *offset, long depth,
		  int once, int yield)
{
    unsigned char *start, *p;
    const unsigned char *p0;
    long len, off = *offset;
    int hlen, tag, tc, j;
    VALUE ary, asn1data, value, tag_class;

    ary = rb_ary_new();
    p = *pp;
    while(length > 0){
	start = p;
	p0 = p;
	j = ASN1_get_object(&p0, &len, &tag, &tc, length);
	p = (unsigned char *)p0;
	if(j & 0x80) ossl_raise(eASN1Error, NULL);
	hlen = p - start;
	if(yield){
	    VALUE arg = rb_ary_new();
	    rb_ary_push(arg, LONG2NUM(depth));
	    rb_ary_push(arg, LONG2NUM(off));
	    rb_ary_push(arg, LONG2NUM(hlen));
	    rb_ary_push(arg, LONG2NUM(len));
	    rb_ary_push(arg, (j & V_ASN1_CONSTRUCTED) ? Qtrue : Qfalse);
	    rb_ary_push(arg, ossl_asn1_class2sym(tc));
	    rb_ary_push(arg, INT2NUM(tag));
	    rb_yield(arg);
	}
	length -= hlen;
	off += hlen; 
	if(len > length) ossl_raise(eASN1Error, "value is too short");
	if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
	    tag_class = sPRIVATE;
	else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
	    tag_class = sCONTEXT_SPECIFIC;
	else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
	    tag_class = sAPPLICATION;
	else
	    tag_class = sUNIVERSAL;
	if(j & V_ASN1_CONSTRUCTED){
	    /* TODO: if j == 0x21 it is indefinite length object. */
	    if((j == 0x21) && (len == 0)){
		long lastoff = off;
		value = ossl_asn1_decode0(&p, length, &off, depth+1, 0, yield);
		len = off - lastoff;
	    }
	    else value = ossl_asn1_decode0(&p, len, &off, depth+1, 0, yield);
	}
	else{
	    value = rb_str_new((const char *)p, len);
	    p += len;
	    off += len;
	}
	if(tag_class == sUNIVERSAL &&
	   tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass){
	    VALUE klass = *ossl_asn1_info[tag].klass;
	    long flag = 0;
	    if(!rb_obj_is_kind_of(value, rb_cArray)){
		switch(tag){
		case V_ASN1_BOOLEAN:
		    value = decode_bool(start, hlen+len);
		    break;
		case V_ASN1_INTEGER:
		    value = decode_int(start, hlen+len);
		    break;
		case V_ASN1_BIT_STRING:
		    value = decode_bstr(start, hlen+len, &flag);
		    break;
		case V_ASN1_NULL:
		    value = decode_null(start, hlen+len);
		    break;
		case V_ASN1_ENUMERATED:
		    value = decode_enum(start, hlen+len);
		    break;
		case V_ASN1_OBJECT:
		    value = decode_obj(start, hlen+len);
		    break;
		case V_ASN1_UTCTIME:           /* FALLTHROUGH */
		case V_ASN1_GENERALIZEDTIME:
		    value = decode_time(start, hlen+len);
		    break;
		default:
		    /* use original value */
		    break;
		}
	    }
	    asn1data = rb_funcall(klass, rb_intern("new"), 1, value);
	    if(tag == V_ASN1_BIT_STRING){
		rb_iv_set(asn1data, "@unused_bits", LONG2NUM(flag));
	    }
	}
	else{
	    asn1data = rb_funcall(cASN1Data, rb_intern("new"), 3,
				  value, INT2NUM(tag), ID2SYM(tag_class));
	}
	rb_ary_push(ary, asn1data);
	length -= len;
        if(once) break;
    }
    *pp = p;
    *offset = off;

    return ary;
}
Example #23
0
static VALUE rldap_msg_keys(VALUE obj)
{
	return rb_funcall(rb_iv_get(obj, "@attrs"), rb_intern("keys"), 0);
}
Example #24
0
static VALUE
rg_s_type_register(int argc, VALUE* argv, VALUE self)
{
    VALUE type_name, flags;
    volatile VALUE class_init_proc = Qnil;
    GType parent_type;
    GTypeInfo* info;

    rb_scan_args(argc, argv, "03", &type_name, &info, &flags);

    {
        const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
        if (cinfo->klass == self)
            rb_raise(rb_eTypeError, "already registered");
    }

    {
        VALUE superclass = rb_funcall(self, rb_intern("superclass"), 0);
        const RGObjClassInfo* cinfo = rbgobj_lookup_class(superclass);
        if (cinfo->klass != superclass)
            rb_raise(rb_eTypeError, "super class must be registered to GLib");
        parent_type = cinfo->gtype;
    }

    if (NIL_P(type_name)) {
        VALUE s = rb_funcall(self, rb_intern("name"), 0);

        if (strlen(StringValuePtr(s)) == 0)
            rb_raise(rb_eTypeError, "can't determine type name");

        type_name = rb_funcall(
                        rb_eval_string("lambda{|x| x.gsub(/::/,'') }"),
                        rb_intern("call"), 1, s);
    }

    {
        GTypeQuery query;
        g_type_query(parent_type, &query);

        /* TODO: Why new?  g_type_register_static() doesn’t retain a copy, so
         * this should be allocated on the stack. */
        info = g_new0(GTypeInfo, 1);
        info->class_size     = query.class_size;
        info->base_init      = NULL;
        info->base_finalize  = NULL;
        info->class_init     = class_init_func;
        info->class_finalize = NULL;
        info->class_data     = (gpointer)class_init_proc;
        info->instance_size  = query.instance_size;
        info->n_preallocs    = 0;
        info->instance_init  = NULL;
        info->value_table    = NULL;
    }

    {
        GType type = g_type_register_static(parent_type,
                                            StringValuePtr(type_name),
                                            info,
                                            NIL_P(flags) ? 0 : NUM2INT(flags));
        G_RELATIVE(self, class_init_proc);

        rbgobj_register_class(self, type, TRUE, TRUE);

        {
            RGObjClassInfo* cinfo = (RGObjClassInfo*)rbgobj_lookup_class(self);
            cinfo->flags |= RBGOBJ_DEFINED_BY_RUBY;
        }

        {
            GType parent = g_type_parent(type);
            const RGObjClassInfo* cinfo =  GTYPE2CINFO(parent);
            VALUE m = rb_define_module_under(self, RubyGObjectHookModule);

            if (! (cinfo->flags & RBGOBJ_DEFINED_BY_RUBY)) {
                rbg_define_method(m, "initialize", rg_initialize, -1);
            }

            rb_include_module(self, m);
        }

        return Qnil;
    }
}
Example #25
0
static VALUE
nometh_err_args(VALUE self)
{
    return rb_attr_get(self, rb_intern("args"));
}
void Init_voltage_ratio_input() {
  VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
  VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
  VALUE ph_voltage_ratio_input = rb_define_class_under(ph_module, "VoltageRatioInput", ph_common);


  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_VOLTAGERATIO", INT2NUM(SENSOR_TYPE_VOLTAGERATIO));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1101_SHARP_2D120X", INT2NUM(SENSOR_TYPE_1101_SHARP_2D120X));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1101_SHARP_2Y0A21", INT2NUM(SENSOR_TYPE_1101_SHARP_2Y0A21));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1101_SHARP_2Y0A02", INT2NUM(SENSOR_TYPE_1101_SHARP_2Y0A02));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1102", INT2NUM(SENSOR_TYPE_1102));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1103", INT2NUM(SENSOR_TYPE_1103));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1104", INT2NUM(SENSOR_TYPE_1104));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1105", INT2NUM(SENSOR_TYPE_1105));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1106", INT2NUM(SENSOR_TYPE_1106));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1107", INT2NUM(SENSOR_TYPE_1107));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1108", INT2NUM(SENSOR_TYPE_1108));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1109", INT2NUM(SENSOR_TYPE_1109));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1110", INT2NUM(SENSOR_TYPE_1110));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1111", INT2NUM(SENSOR_TYPE_1111));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1112", INT2NUM(SENSOR_TYPE_1112));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1113", INT2NUM(SENSOR_TYPE_1113));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1115", INT2NUM(SENSOR_TYPE_1115));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1116", INT2NUM(SENSOR_TYPE_1116));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1118_AC", INT2NUM(SENSOR_TYPE_1118_AC));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1118_DC", INT2NUM(SENSOR_TYPE_1118_DC));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1119_AC", INT2NUM(SENSOR_TYPE_1119_AC));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1119_DC", INT2NUM(SENSOR_TYPE_1119_DC));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1120", INT2NUM(SENSOR_TYPE_1120));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1121", INT2NUM(SENSOR_TYPE_1121));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1122_AC", INT2NUM(SENSOR_TYPE_1122_AC));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1122_DC", INT2NUM(SENSOR_TYPE_1122_DC));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1124", INT2NUM(SENSOR_TYPE_1124));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1125_HUMIDITY", INT2NUM(SENSOR_TYPE_1125_HUMIDITY));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1125_TEMPERATURE", INT2NUM(SENSOR_TYPE_1125_TEMPERATURE));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1126", INT2NUM(SENSOR_TYPE_1126));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1128", INT2NUM(SENSOR_TYPE_1128));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1129", INT2NUM(SENSOR_TYPE_1129));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1131", INT2NUM(SENSOR_TYPE_1131));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1134", INT2NUM(SENSOR_TYPE_1134));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1136", INT2NUM(SENSOR_TYPE_1136));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1137", INT2NUM(SENSOR_TYPE_1137));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1138", INT2NUM(SENSOR_TYPE_1138));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1139", INT2NUM(SENSOR_TYPE_1139));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1140", INT2NUM(SENSOR_TYPE_1140));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1141", INT2NUM(SENSOR_TYPE_1141));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_1146", INT2NUM(SENSOR_TYPE_1146));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3120", INT2NUM(SENSOR_TYPE_3120));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3121", INT2NUM(SENSOR_TYPE_3121));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3122", INT2NUM(SENSOR_TYPE_3122));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3123", INT2NUM(SENSOR_TYPE_3123));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3130", INT2NUM(SENSOR_TYPE_3130));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3520", INT2NUM(SENSOR_TYPE_3520));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3521", INT2NUM(SENSOR_TYPE_3521));
  rb_define_const(ph_voltage_ratio_input, "SENSOR_TYPE_3522", INT2NUM(SENSOR_TYPE_3522));

  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_1", INT2NUM(BRIDGE_GAIN_1));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_2", INT2NUM(BRIDGE_GAIN_2));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_4", INT2NUM(BRIDGE_GAIN_4));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_8", INT2NUM(BRIDGE_GAIN_8));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_16", INT2NUM(BRIDGE_GAIN_16));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_32", INT2NUM(BRIDGE_GAIN_32));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_64", INT2NUM(BRIDGE_GAIN_64));
  rb_define_const(ph_voltage_ratio_input, "BRIDGE_GAIN_128", INT2NUM(BRIDGE_GAIN_128));


  /* Document-method: new
   * call-seq: new
   *
   * Creates a Phidget VoltageInput object.
   */
  rb_define_method(ph_voltage_ratio_input, "initialize", ph_voltage_ratio_input_init, 0);

  /* Document-method: getBridgeEnabled
   * call-seq: getBridgeEnabled -> bridge_enabled
   *
   * Enable power to and data from the input by setting BridgeEnabled to true.
   */
  rb_define_method(ph_voltage_ratio_input, "getBridgeEnabled", ph_voltage_ratio_input_get_bridge_enabled, 0);
  rb_define_alias(ph_voltage_ratio_input, "bridge_enabled?", "getBridgeEnabled");

  /* Document-method: setBridgeEnabled
   * call-seq: setBridgeEnabled(bridge_enabled)
   *
   * Enable power to and data from the input by setting BridgeEnabled to true.
   */
  rb_define_method(ph_voltage_ratio_input, "setBridgeEnabled", ph_voltage_ratio_input_set_bridge_enabled, 1);
  rb_define_alias(ph_voltage_ratio_input, "bridge_enabled=", "setBridgeEnabled");

  /* Document-method: getBridgeGain
   * call-seq: getBridgeGain -> bridge_gain
   *
   * Choose a BridgeGain that best suits your application.
   * For more information about the range and accuracy of each BridgeGain to decide which best suits your application, see your device's User Guide.
   */
  rb_define_method(ph_voltage_ratio_input, "getBridgeGain", ph_voltage_ratio_input_get_bridge_gain, 0);
  rb_define_alias(ph_voltage_ratio_input, "bridge_gain", "getBridgeGain");

  /* Document-method: setBridgeGain
   * call-seq: setBridgeGain(bridge_gain)
   *
   * Choose a BridgeGain that best suits your application.
   * For more information about the range and accuracy of each BridgeGain to decide which best suits your application, see your device's User Guide.
   */
  rb_define_method(ph_voltage_ratio_input, "setBridgeGain", ph_voltage_ratio_input_set_bridge_gain, 1);
  rb_define_alias(ph_voltage_ratio_input, "bridge_gain=", "setBridgeGain");

  /* Document-method: getDataInterval
   * call-seq: getDataInterval -> interval
   *
   * The DataInterval is the time that must elapse before the channel will fire another event.
   * The data interval is bounded by MinDataInterval and MaxDataInterval.
   * The timing between events can also affected by the change trigger values.
   */
  rb_define_method(ph_voltage_ratio_input, "getDataInterval", ph_voltage_ratio_input_get_data_interval, 0);
  rb_define_alias(ph_voltage_ratio_input, "data_interval", "getDataInterval");

  /* Document-method: setDataInterval
   * call-seq: setDataInterval(interval)
   *
   * The DataInterval is the time that must elapse before the channel will fire another event.
   * The data interval is bounded by MinDataInterval and MaxDataInterval.
   * The timing between events can also affected by the change trigger values.
   */
  rb_define_method(ph_voltage_ratio_input, "setDataInterval", ph_voltage_ratio_input_set_data_interval, 1);
  rb_define_alias(ph_voltage_ratio_input, "data_interval=", "setDataInterval");

  /* Document-method: getMinDataInterval
   * call-seq: getMinDataInterval -> interval
   *
   * The minimum value that DataInterval can be set to.
   */
  rb_define_method(ph_voltage_ratio_input, "getMinDataInterval", ph_voltage_ratio_input_get_min_data_interval, 0);
  rb_define_alias(ph_voltage_ratio_input, "min_data_interval", "getMinDataInterval");

  /* Document-method: getMaxDataInterval
   * call-seq: getMaxDataInterval -> interval
   *
   * The maximum value that DataInterval can be set to.
   */
  rb_define_method(ph_voltage_ratio_input, "getMaxDataInterval", ph_voltage_ratio_input_get_max_data_interval, 0);
  rb_define_alias(ph_voltage_ratio_input, "max_data_interval", "getMaxDataInterval");

  /* Document-method: getSensorType
   * call-seq: getSensorType -> sensor_type
   *
   * We sell a variety of analog sensors that do not have their own API, they simply output a voltage that can be converted to a digital value using a specific formula.
   * By matching the SensorType to your analog sensor, the correct formula will automatically be applied to data when you get the SensorValue or subscribe to the SensorChange event.
   * The SensorChange event has its own change trigger associated with it: SensorValueChangeTrigger.
   * Any data from getting the SensorValue or subscribing to the SensorChange event will have a SensorUnit associated with it.
   * Note: Unlike other properties such as DeviceSerialNumber or Channel, SensorType is set after the device is opened, not before.
   */
  rb_define_method(ph_voltage_ratio_input, "getSensorType", ph_voltage_ratio_input_get_sensor_type, 0);
  rb_define_alias(ph_voltage_ratio_input, "sensor_type", "getSensorType");

  /* Document-method: setSensorType
   * call-seq: setSensorType(sensor_type)
   *
   * We sell a variety of analog sensors that do not have their own API, they simply output a voltage that can be converted to a digital value using a specific formula.
   * By matching the SensorType to your analog sensor, the correct formula will automatically be applied to data when you get the SensorValue or subscribe to the SensorChange event.
   * The SensorChange event has its own change trigger associated with it: SensorValueChangeTrigger.
   * Any data from getting the SensorValue or subscribing to the SensorChange event will have a SensorUnit associated with it.
   * Note: Unlike other properties such as DeviceSerialNumber or Channel, SensorType is set after the device is opened, not before.
   */
  rb_define_method(ph_voltage_ratio_input, "setSensorType", ph_voltage_ratio_input_set_sensor_type, 1);
  rb_define_alias(ph_voltage_ratio_input, "sensor_type=", "setSensorType");

  /* Document-method: getSensorUnit
   * call-seq: getSensorUnit -> sensor_unit
   *
   * The unit of measurement that applies to the sensor values of the SensorType that has been selected.
   * Helps keep track of the type of information being calculated from the voltage ratio input.
   */
  rb_define_method(ph_voltage_ratio_input, "getSensorUnit", ph_voltage_ratio_input_get_sensor_unit, 0);
  rb_define_alias(ph_voltage_ratio_input, "sensor_unit", "getSensorUnit");

  /* Document-method: getSensorValue
   * call-seq: getSensorValue -> sensor_value
   *
   * The most recent sensor value that the channel has reported.
   * Use SensorUnit to get the measurement units that are associated with the SensorValue.
   */
  rb_define_method(ph_voltage_ratio_input, "getSensorValue", ph_voltage_ratio_input_get_sensor_value, 0);
  rb_define_alias(ph_voltage_ratio_input, "sensor_value", "getSensorValue");

  /* Document-method: getSensorValueChangeTrigger
   * call-seq: getSensorValueChangeTrigger -> trigger
   *
   * The channel will not issue a SensorChange event until the sensor value has changed by the amount specified by the SensorValueChangeTrigger.
   * Setting the SensorChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
   */
  rb_define_method(ph_voltage_ratio_input, "getSensorValueChangeTrigger", ph_voltage_ratio_input_get_sensor_value_change_trigger, 0);
  rb_define_alias(ph_voltage_ratio_input, "sensor_value_change_trigger", "getSensorValueChangeTrigger");

  /* Document-method: setSensorValueChangeTrigger
   * call-seq: setSensorValueChangeTrigger(trigger)
   *
   * The channel will not issue a SensorChange event until the sensor value has changed by the amount specified by the SensorValueChangeTrigger.
   * Setting the SensorChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
   */
  rb_define_method(ph_voltage_ratio_input, "setSensorValueChangeTrigger", ph_voltage_ratio_input_set_sensor_value_change_trigger, 1);
  rb_define_alias(ph_voltage_ratio_input, "sensor_value_change_trigger=", "setSensorValueChangeTrigger");

  /* Document-method: getVoltageRatio
   * call-seq: getVoltageRatio -> voltage_ratio
   *
   * The most recent voltage ratio value that the channel has reported.
   * This value will always be between MinVoltageRatio and MaxVoltageRatio.
   */
  rb_define_method(ph_voltage_ratio_input, "getVoltageRatio", ph_voltage_ratio_input_get_voltage_ratio, 0);
  rb_define_alias(ph_voltage_ratio_input, "voltage_ratio", "getVoltageRatio");

  /* Document-method: getMinVoltageRatio
   * call-seq: getMinVoltageRatio -> voltage_ratio
   *
   * The minimum value the VoltageRatioChange event will report.
   */
  rb_define_method(ph_voltage_ratio_input, "getMinVoltageRatio", ph_voltage_ratio_input_get_min_voltage_ratio, 0);
  rb_define_alias(ph_voltage_ratio_input, "min_voltage_ratio", "getMinVoltageRatio");

  /* Document-method: getMaxVoltageRatio
   * call-seq: getMaxVoltageRatio -> voltage_ratio
   *
   * The maximum value the VoltageRatioChange event will report.
   */
  rb_define_method(ph_voltage_ratio_input, "getMaxVoltageRatio", ph_voltage_ratio_input_get_max_voltage_ratio, 0);
  rb_define_alias(ph_voltage_ratio_input, "max_voltage_ratio", "getMaxVoltageRatio");

  /* Document-method: getVoltageRatioChangeTrigger
   * call-seq: getVoltageRatioChangeTrigger -> trigger
   *
   * The channel will not issue a VoltageRatioChange event until the voltage ratio value has changed by the amount specified by the VoltageRatioChangeTrigger.
   * Setting the VoltageRatioChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
   */
  rb_define_method(ph_voltage_ratio_input, "getVoltageRatioChangeTrigger", ph_voltage_ratio_input_get_voltage_ratio_change_trigger, 0);
  rb_define_alias(ph_voltage_ratio_input, "voltage_ratio_change_trigger", "getVoltageRatioChangeTrigger");

  /* Document-method: setVoltageRatioChangeTrigger
   * call-seq: setVoltageRatioChangeTrigger(trigger)
   *
   * The channel will not issue a VoltageRatioChange event until the voltage value has changed by the amount specified by the VoltageRatioChangeTrigger.
   * Setting the VoltageRatioChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
   */
  rb_define_method(ph_voltage_ratio_input, "setVoltageRatioChangeTrigger", ph_voltage_ratio_input_set_voltage_ratio_change_trigger, 1);
  rb_define_alias(ph_voltage_ratio_input, "voltage_ratio_change_trigger=", "setVoltageRatioChangeTrigger");

  /* Document-method: getMinVoltageRatioChangeTrigger
   * call-seq: getMinVoltageRatioChangeTrigger -> trigger
   *
   * The minimum value that VoltageRatioChangeTrigger can be set to.
   */
  rb_define_method(ph_voltage_ratio_input, "getMinVoltageRatioChangeTrigger", ph_voltage_ratio_input_get_min_voltage_ratio_change_trigger, 0);
  rb_define_alias(ph_voltage_ratio_input, "min_voltage_ratio_change_trigger", "getMinVoltageRatioChangeTrigger");

  /* Document-method: getMaxVoltageRatioChangeTrigger
   * call-seq: getMaxVoltageRatioChangeTrigger -> trigger
   *
   * The maximum value that VoltageRatioChangeTrigger can be set to.
   */
  rb_define_method(ph_voltage_ratio_input, "getMaxVoltageRatioChangeTrigger", ph_voltage_ratio_input_get_max_voltage_ratio_change_trigger, 0);
  rb_define_alias(ph_voltage_ratio_input, "max_voltage_ratio_change_trigger", "getMaxVoltageRatioChangeTrigger");


  rb_define_private_method(ph_voltage_ratio_input, "ext_setOnSensorChangeHandler", ph_voltage_ratio_input_set_on_sensor_change_handler, 1);
  rb_define_private_method(ph_voltage_ratio_input, "ext_setOnVoltageRatioChangeHandler", ph_voltage_ratio_input_set_on_voltage_ratio_change_handler, 1);
}
Example #27
0
VALUE
rb_exc_new(VALUE etype, const char *ptr, long len)
{
    return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
}
Example #28
0
/*
 * call-seq:
 *   combatible?(obj)
 *
 * Return compatibility to CvPoint3D32f. Return true if object have method #x and #y and #z.
 *
 * For example.
 *   class MyPoint3D32f
 *     def x
 *       95.7
 *     end
 *     def y
 *       70.2
 *     end
 *     def z
 *       10.0
 *     end
 *   end
 *   mp = MyPoint3D32f.new
 *   CvPoint3D32f.compatible?(mp)  #=> true
 *   CvPoint3D32f.new(mp)          #=> same as CvPoint3D32f(95.7, 70.2)
 */
VALUE
rb_compatible_q(VALUE klass, VALUE object)
{
  return (rb_respond_to(object, rb_intern("x")) && rb_respond_to(object, rb_intern("y"))) ? Qtrue : Qfalse;
}
Example #29
0
static VALUE
exc_message(VALUE exc)
{
    return rb_funcall(exc, rb_intern("to_s"), 0, 0);
}
Example #30
0
uint32_t
nw_addr_to_i( VALUE nw_addr ) {
  return ( uint32_t ) NUM2UINT( rb_funcall( nw_addr, rb_intern( "to_i" ), 0 ) );
}