コード例 #1
0
ファイル: rb-grn-expression.c プロジェクト: kenhys/rroonga
/*
 * _expression_ で使用可能な変数を作成する。
 *
 * @overload define_variable(options={})
 *   @param [::Hash] options The name and value
 *     pairs. Omitted names are initialized as the default value.
 *   @option options :name [String] (nil)
 *     変数の名前。省略した場合は名前を付けない。
 *   @option options :domain [Groonga::Table] (nil)
 *     テーブルを指定すると、そのテーブル用のレコードとして初期化する。
 *   @option options :reference [Bool] (nil)
 *     Initializes this variable as reference hold variable if
 *     @:[email protected] is true. Reference hold variable is GRN_PTR type
 *     in groonga. You can't use @:[email protected] with @:[email protected]
 * @return [Groonga::Variable]
 *
 */
static VALUE
rb_grn_expression_define_variable (int argc, VALUE *argv, VALUE self)
{
    grn_ctx *context = NULL;
    grn_obj *expression, *variable;
    char *name = NULL;
    unsigned name_size = 0;
    VALUE options, rb_name, rb_domain, rb_variable, rb_reference;

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

    rb_grn_expression_deconstruct(SELF(self), &expression, &context,
                                  NULL, NULL,
                                  NULL, NULL, NULL);

    rb_grn_scan_options(options,
                        "name", &rb_name,
                        "domain", &rb_domain,
                        "reference", &rb_reference,
                        NULL);

    if (!NIL_P(rb_name)) {
        name = StringValuePtr(rb_name);
        name_size = RSTRING_LEN(rb_name);
    }

    variable = grn_expr_add_var(context, expression, name, name_size);
    rb_variable = GRNVARIABLE2RVAL(context, variable);

    if (RVAL2CBOOL(rb_obj_is_kind_of(rb_domain, rb_cGrnTable))) {
        grn_id domain_id;
        domain_id = NUM2UINT(rb_funcall(rb_domain, rb_intern("id"), 0));
        GRN_RECORD_INIT(variable, 0, domain_id);
    } else if (!NIL_P(rb_reference) && RVAL2CBOOL(rb_reference)) {
        GRN_PTR_INIT(variable, 0, GRN_DB_OBJECT);
    }

    return rb_variable;
}
コード例 #2
0
static VALUE
rb_grn_double_array_trie_update_by_id (VALUE self, VALUE rb_id, VALUE rb_new_key)
{
    grn_ctx *context;
    grn_obj *table;
    grn_id id, domain_id;
    grn_obj *new_key, *domain;
    grn_rc rc;

    rb_grn_double_array_trie_deconstruct(SELF(self), &table, &context,
                                         NULL, &new_key, &domain_id, &domain,
                                         NULL, NULL, NULL,
                                         NULL);

    id = NUM2UINT(rb_id);
    RVAL2GRNKEY(rb_new_key, context, new_key, domain_id, domain, self);
    rc = grn_table_update_by_id(context, table, id,
                                GRN_BULK_HEAD(new_key), GRN_BULK_VSIZE(new_key));
    rb_grn_rc_check(rc, self);

    return Qnil;
}
コード例 #3
0
ファイル: rb_call.c プロジェクト: Abioy/kythe
static VALUE grpc_rb_call_add_metadata(int argc, VALUE *argv, VALUE self) {
  VALUE metadata;
  VALUE flags = Qnil;
  ID id_size = rb_intern("size");

  /* "11" == 1 mandatory args, 1 (flags) is optional */
  rb_scan_args(argc, argv, "11", &metadata, &flags);
  if (NIL_P(flags)) {
    flags = UINT2NUM(0); /* Default to no flags */
  }
  if (TYPE(metadata) != T_HASH) {
    rb_raise(rb_eTypeError, "add metadata failed: metadata should be a hash");
    return Qnil;
  }
  if (NUM2UINT(rb_funcall(metadata, id_size, 0)) == 0) {
    return Qnil;
  }
  rb_ivar_set(self, id_flags, flags);
  rb_ivar_set(self, id_input_md, metadata);
  rb_hash_foreach(metadata, grpc_rb_call_add_metadata_hash_cb, self);
  return Qnil;
}
コード例 #4
0
ファイル: cbson.c プロジェクト: DanPatey/TeleSign-QA
static VALUE objectid_generate(int argc, VALUE* args, VALUE self)
{
    VALUE oid;
    unsigned char oid_bytes[12];
    unsigned long t, inc;
    unsigned short pid;
    int i;

    if(argc == 0 || (argc == 1 && *args == Qnil)) {
        t = htonl((int)time(NULL));
    } else {
        t = htonl(NUM2UINT(rb_funcall(*args, rb_intern("to_i"), 0)));
    }
    MEMCPY(&oid_bytes, &t, unsigned char, 4);

    MEMCPY(&oid_bytes[4], hostname_digest, unsigned char, 3);

    pid = htons(getpid());
    MEMCPY(&oid_bytes[7], &pid, unsigned char, 2);

    /* No need to synchronize modification of this counter between threads;
     * MRI global interpreter lock guarantees serializability.
     *
     * Compiler should optimize out impossible branch.
     */
    if (sizeof(unsigned int) == 4) {
        object_id_inc++;
    } else {
        object_id_inc = (object_id_inc + 1) % 0xFFFFFF;
    }
    inc = htonl(object_id_inc);
    MEMCPY(&oid_bytes[9], ((unsigned char*)&inc + 1), unsigned char, 3);

    oid = rb_ary_new2(12);
    for(i = 0; i < 12; i++) {
        rb_ary_store(oid, i, INT2FIX((unsigned int)oid_bytes[i]));
    }
    return oid;
}
コード例 #5
0
ファイル: epeg_image.c プロジェクト: nelsond/ruby-epeg
/*
 * call-seq:
 *  intialize()
 *
 * See Epeg::Image.open
 */
static VALUE rb_epeg_image_initialize(VALUE self)
{
  Epeg_Image *image;
  Data_Get_Struct(self, Epeg_Image, image);

  VALUE q = rb_cv_get(CLASS_OF(self), "@@quality");
  epeg_quality_set(image, NUM2UINT(q));
  rb_iv_set(self, "@quality", q);

  epeg_comment_set(image, (char *)NULL);

  int w, h;
  epeg_size_get(image, &w, &h);

  rb_iv_set(self, "@width",     INT2NUM(w));
  rb_iv_set(self, "@height",    INT2NUM(h));

  rb_iv_set(self, "epeg_file_closed", Qfalse);
  rb_iv_set(self, "epeg_trimmed",     Qfalse);

  return self;
}
コード例 #6
0
ファイル: BuiltIns.cpp プロジェクト: browserplus/bp-ruby
static VALUE
trans_complete(int argc, VALUE * argv, VALUE obj)
{
    VALUE tidVal = rb_ivar_get(obj, rb_intern("tid"));

    if (TYPE(tidVal) != T_FIXNUM && TYPE(tidVal) != T_BIGNUM) {
        rb_raise(rb_eException, "internal error, incorrect 'tid' ivar");
    } else if (argc > 1) {
        rb_raise(rb_eArgError, "wrong number of arguments");
    }
    
    unsigned int tid = NUM2UINT(tidVal);

    bp::Object * data = NULL;
    if (argc == 1) data = rubyToBPObject(argv[0]);
    const BPElement * e = (data == NULL) ? NULL : data->elemPtr();
    g_bpCoreFunctions->postResults(tid, e);
    
    if (data != NULL) delete data;

    return Qnil;
}
コード例 #7
0
ファイル: DynamicLibrary.c プロジェクト: Flameeyes/ffi
static VALUE
library_initialize(VALUE self, VALUE libname, VALUE libflags)
{
    Library* library;
    int flags;

    Check_Type(libflags, T_FIXNUM);

    Data_Get_Struct(self, Library, library);
    flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
    
    library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
    if (library->handle == NULL) {
        char errmsg[1024];
        dl_error(errmsg, sizeof(errmsg));
        rb_raise(rb_eLoadError, "Could not open library '%s': %s",
                libname != Qnil ? StringValueCStr(libname) : "[current process]",
                errmsg);
    }
    rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
    return self;
}
コード例 #8
0
static VALUE sdl_listModes(VALUE mod,VALUE flags)
{
  SDL_Rect **modes;
  int i;
  VALUE modesArray;
  
  modes=SDL_ListModes(NULL,NUM2UINT(flags));

  if( modes == NULL )
    return Qnil;/* no modes available */
  if( modes == (SDL_Rect **)-1)
    return Qtrue;/* all resolutions available */

  /* available modes into modesArray */
  modesArray=rb_ary_new();
  
  for(i=0;modes[i]!=NULL;++i){
    rb_ary_push( modesArray,
		 rb_ary_new3( 2, INT2NUM(modes[i]->w), INT2NUM(modes[i]->h)) );
  }
  return modesArray;
}
コード例 #9
0
ファイル: rmilist.c プロジェクト: ABaumgaertner/rmagick
VALUE
ImageList_animate(int argc, VALUE *argv, VALUE self)
{
    Image *images;
    Info *info;
    VALUE info_obj;

    if (argc > 1)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
    }

    // Create a new Info object to use with this call
    info_obj = rm_info_new();

    // Convert the images array to an images sequence.
    images = images_from_imagelist(self);

    if (argc == 1)
    {
        Image *img;
        unsigned int delay;

        delay = NUM2UINT(argv[0]);
        for (img = images; img; img = GetNextImageInList(img))
        {
            img->delay = delay;
        }
    }

    Data_Get_Struct(info_obj, Info, info);
    (void) AnimateImages(info, images);
    rm_check_image_exception(images, RetainOnError);
    rm_split(images);

    RB_GC_GUARD(info_obj);

    return self;
}
コード例 #10
0
ファイル: rb_cairo_pattern.c プロジェクト: jdlehman/rcairo
static VALUE
cr_mesh_pattern_set_corner_color_generic (int argc, VALUE *argv, VALUE self)
{
  cairo_pattern_t *pattern;
  VALUE rb_nth_corner, rb_red, rb_green, rb_blue, rb_alpha;
  unsigned int nth_corner;
  double red, green, blue, alpha;

  rb_scan_args (argc, argv, "41",
                &rb_nth_corner, &rb_red, &rb_green, &rb_blue, &rb_alpha);

  nth_corner = NUM2UINT (rb_nth_corner);
  if (nth_corner > 3)
    {
      VALUE inspected;

      inspected = rb_funcall (rb_ary_new4 (argc, argv), id_inspect, 0);
      rb_raise (rb_eArgError, "nth_corner must be 0, 1, 2 or 3: <%u>: <%s>",
                nth_corner, RVAL2CSTR (inspected));
    }

  pattern = _SELF (self);
  red = NUM2DBL (rb_red);
  green = NUM2DBL (rb_green);
  blue = NUM2DBL (rb_blue);
  if (NIL_P (rb_alpha))
    {
      cairo_mesh_pattern_set_corner_color_rgb (pattern, nth_corner,
                                               red, green, blue);
    }
  else
    {
      alpha = NUM2DBL (rb_alpha);
      cairo_mesh_pattern_set_corner_color_rgba (pattern, nth_corner,
                                                red, green, blue, alpha);
    }
  cr_pattern_check_status (pattern);
  return self;
}
コード例 #11
0
ファイル: BuiltIns.cpp プロジェクト: browserplus/bp-ruby
static VALUE
trans_prompt(int argc, VALUE * argv, VALUE obj)
{
    VALUE tidVal = rb_ivar_get(obj, rb_intern("tid"));

    if (TYPE(tidVal) != T_FIXNUM && TYPE(tidVal) != T_BIGNUM) {
        rb_raise(rb_eException, "internal error, incorrect 'tid' ivar");
    } else if (argc != 2) {
        rb_raise(rb_eArgError, "wrong number of arguments");
    } else if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "block required for prompt method");
    } else if (TYPE(argv[0]) != T_STRING) {
        rb_raise(rb_eException,
                 "transaction.prompt requires a string path argument");
    }
    
    unsigned int tid = NUM2UINT(tidVal);
    std::string path(RSTRING_PTR(argv[0]));
    bp::Object * data = rubyToBPObject(argv[1]);
    const BPElement * e = (data == NULL) ? NULL : data->elemPtr();

    s_lock.lock();
    unsigned int x = g_bpCoreFunctions->prompt(tid, (BPPath) path.c_str(), e,
                                               dummyCB, NULL);

    // grab the passed in block and increment a reference to it
    VALUE val = rb_block_proc();
    s_outstandingPrompts[x] = val;
    rb_gc_register_address(&s_outstandingPrompts[x]);
    s_lock.unlock();

    // now call the block!
    
    if (data != NULL) delete data;

    // return the prompt id!
    return Qnil;
}
コード例 #12
0
static VALUE
client_set_default_unix_socket_mode (VALUE self, VALUE rb_mode)
{
    guint mode;

    if (NIL_P(rb_mode)) {
        mode = 0;
    } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_mode, rb_cString))) {
        gchar *error_message = NULL;
        if (!milter_utils_parse_file_mode(RVAL2CSTR(rb_mode),
                                          &mode, &error_message)) {
            VALUE rb_error_message;
            rb_error_message = CSTR2RVAL(error_message);
            g_free(error_message);
            rb_raise(rb_eArgError, "%s", RSTRING_PTR(rb_error_message));
        }
    } else {
        mode = NUM2UINT(rb_mode);
    }

    milter_client_set_default_unix_socket_mode(SELF(self), mode);
    return self;
}
コード例 #13
0
ファイル: mouse.c プロジェクト: AXElements/mouse
/*
 * Generate the up click part of an arbitrary click event
 *
 * This might be useful in concert with {Mouse.arbitrary_click_down} if
 * you want to inject some behaviour between the down and up click events.
 *
 * You can optionally specify a point to click; the mouse cursor will
 * instantly jump to the given point; otherwise the click event happens
 * at the current cursor position.
 *
 * @overload arbitrary_click_up()
 *   @return [CGPoint]
 * @overload arbitrary_click_up(point)
 *   @param point [CGPoint]
 *   @return [CGPoint]
 */
static
VALUE
rb_mouse_arbitrary_click_up(const int argc,
                            VALUE* const argv,
                            UNUSED const VALUE self)
{
    if (argc == 0)
        rb_raise(rb_eArgError,
                 "arbitrary_click_up requires at least one arg");

    const uint_t button = NUM2UINT(argv[0]);

    switch (argc) {
    case 1:
        mouse_arbitrary_click_up(button);
        break;
    case 2:
    default:
        mouse_arbitrary_click_up2(button, rb_mouse_unwrap_point(argv[1]));
    }

    return CURRENT_POSITION;
}
コード例 #14
0
ファイル: console.c プロジェクト: DashYang/sim
static VALUE
console_key_pressed_p(VALUE io, VALUE k)
{
    int vk = -1;

    if (FIXNUM_P(k)) {
	vk = NUM2UINT(k);
    }
    else {
	const struct vktable *t;
	if (SYMBOL_P(k)) {
	    k = rb_sym2str(k);
	}
	else {
	    StringValueCStr(k);
	}
	t = console_win32_vk(RSTRING_PTR(k), RSTRING_LEN(k));
	if (!t || (vk = (short)t->vk) == -1) {
	    rb_raise(rb_eArgError, "unknown virtual key code: %"PRIsVALUE, k);
	}
    }
    return GetKeyState(vk) & 0x80 ? Qtrue : Qfalse;
}
コード例 #15
0
ファイル: rb_call.c プロジェクト: Abioy/kythe
/*
  call-seq:
     call.start_write(byte_buffer, tag, flags=nil)

   Queue a byte buffer for writing.
   flags is a bit-field combination of the write flags defined above.
   A write with byte_buffer null is allowed, and will not send any bytes on the
   wire. If this is performed without GRPC_WRITE_BUFFER_HINT flag it provides
   a mechanism to flush any previously buffered writes to outgoing flow control.
   REQUIRES: No other writes are pending on the call. It is only safe to
             start the next write after the corresponding write_accepted event
             is received.
             GRPC_INVOKE_ACCEPTED must have been received by the application
             prior to calling this on the client. On the server,
             grpc_call_accept must have been called successfully.
   Produces a GRPC_WRITE_ACCEPTED event. */
static VALUE grpc_rb_call_start_write(int argc, VALUE *argv, VALUE self) {
  VALUE byte_buffer = Qnil;
  VALUE tag = Qnil;
  VALUE flags = Qnil;
  grpc_call *call = NULL;
  grpc_byte_buffer *bfr = NULL;
  grpc_call_error err;

  /* "21" == 2 mandatory args, 1 (flags) is optional */
  rb_scan_args(argc, argv, "21", &byte_buffer, &tag, &flags);
  if (NIL_P(flags)) {
    flags = UINT2NUM(0); /* Default to no flags */
  }
  bfr = grpc_rb_get_wrapped_byte_buffer(byte_buffer);
  Data_Get_Struct(self, grpc_call, call);
  err = grpc_call_start_write_old(call, bfr, ROBJECT(tag), NUM2UINT(flags));
  if (err != GRPC_CALL_OK) {
    rb_raise(rb_eCallError, "start write failed: %s (code=%d)",
             grpc_call_error_detail_of(err), err);
  }

  return Qnil;
}
コード例 #16
0
ファイル: rb-grn-column.c プロジェクト: nobu/rroonga
/*
 * Document-method: locked?
 *
 * call-seq:
 *   column.locked?(options={})
 *
 * _column_がロックされていれば+true+を返す。
 *
 * 利用可能なオプションは以下の通り。
 *
 * [_:id_]
 *   _:id_で指定したレコードがロックされていれば+true+を返す。
 *   (注: groonga側が未実装のため、現在は無視される。実装さ
 *   れるのではないかと思っているが、実装されないかもしれな
 *   い。)
 */
static VALUE
rb_grn_column_is_locked (int argc, VALUE *argv, VALUE self)
{
    grn_id id = GRN_ID_NIL;
    grn_ctx *context;
    grn_obj *column;
    VALUE options, rb_id;

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

    rb_grn_column_deconstruct(SELF(self), &column, &context,
			     NULL, NULL,
			     NULL, NULL, NULL);

    rb_grn_scan_options(options,
			"id", &rb_id,
			NULL);

    if (!NIL_P(rb_id))
	id = NUM2UINT(rb_id);

    return CBOOL2RVAL(grn_obj_is_locked(context, column));
}
コード例 #17
0
ファイル: lob.c プロジェクト: aq1018/ruby-oci8
static VALUE oci8_lob_seek(int argc, VALUE *argv, VALUE self)
{
    oci8_lob_t *lob = DATA_PTR(self);
    VALUE position, whence;

    rb_scan_args(argc, argv, "11", &position, &whence);
    if (argc == 2 && (whence != seek_set && whence != seek_cur && whence != seek_end)) {
        if (FIXNUM_P(whence)) {
            rb_raise(rb_eArgError, "expect IO::SEEK_SET, IO::SEEK_CUR or IO::SEEK_END but %d",
                     FIX2INT(whence));
        } else {
            rb_raise(rb_eArgError, "expect IO::SEEK_SET, IO::SEEK_CUR or IO::SEEK_END but %s",
                     rb_class2name(CLASS_OF(whence)));
        }
    }
    if (whence == seek_cur) {
        position = rb_funcall(UB4_TO_NUM(lob->pos), id_plus, 1, position);
    } else if (whence == seek_end) {
        position = rb_funcall(UB4_TO_NUM(oci8_lob_get_length(lob)), id_plus, 1, position);
    }
    lob->pos = NUM2UINT(position);
    return self;
}
コード例 #18
0
ファイル: rbsigar.c プロジェクト: mdkent/sigar
static VALUE rb_sigar_net_connection_list(VALUE obj, VALUE flags)
{
    int status;
    unsigned int i;
    sigar_t *sigar = rb_sigar_get(obj);
    sigar_net_connection_list_t connlist;
    VALUE RETVAL;

    status = sigar_net_connection_list_get(sigar, &connlist, NUM2UINT(flags));

    if (status != SIGAR_OK) {
        RB_SIGAR_CROAK;
    }

    RETVAL = rb_sigar_new_list((char *)&connlist.data[0],
                               connlist.number,
                               sizeof(*connlist.data),
                               rb_cSigarNetConnection);

    sigar_net_connection_list_destroy(sigar, &connlist);

    return RETVAL;
}
コード例 #19
0
ファイル: rbgtkspinbutton.c プロジェクト: msakai/ruby-gnome2
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE arg1, arg2, arg3;
    GtkAdjustment *adj = NULL;
    gfloat climb_rate;
    gint digits;
    GtkWidget *widget;

    rb_scan_args(argc, argv, "03", &arg1, &arg2, &arg3);

    if (NIL_P(arg1) || RVAL2GTYPE(arg1) == GTK_TYPE_ADJUSTMENT){
        if (!NIL_P(arg1)) adj = GTK_ADJUSTMENT(RVAL2GOBJ(arg1));
        climb_rate = (NIL_P(arg2))? 0.0: NUM2DBL(arg2);
        digits     = (NIL_P(arg3))?   0: NUM2UINT(arg3);
        widget = gtk_spin_button_new(adj, climb_rate, digits);
    } else {
        widget = gtk_spin_button_new_with_range(NUM2DBL(arg1), 
                                                NUM2DBL(arg2), NUM2DBL(arg3));
    }
    RBGTK_INITIALIZE(self, widget);
    return Qnil;
}
コード例 #20
0
ファイル: ArrayType.c プロジェクト: AHOUSAIN/sample_app
/*
 * call-seq: initialize(component_type, length)
 * @param [Type] component_type
 * @param [Numeric] length
 * @return [self]
 * A new instance of ArrayType.
 */
static VALUE
array_type_initialize(VALUE self, VALUE rbComponentType, VALUE rbLength)
{
    ArrayType* array;
    int i;

    Data_Get_Struct(self, ArrayType, array);

    array->length = NUM2UINT(rbLength);
    array->rbComponentType = rbComponentType;
    Data_Get_Struct(rbComponentType, Type, array->componentType);
    
    array->ffiTypes = xcalloc(array->length + 1, sizeof(*array->ffiTypes));
    array->base.ffiType->elements = array->ffiTypes;
    array->base.ffiType->size = array->componentType->ffiType->size * array->length;
    array->base.ffiType->alignment = array->componentType->ffiType->alignment;

    for (i = 0; i < array->length; ++i) {
        array->ffiTypes[i] = array->componentType->ffiType;
    }

    return self;
}
コード例 #21
0
static VALUE
rg_find(int argc, VALUE *argv, VALUE self)
{
    GIBaseInfo *info;

    if (argc == 1) {
	VALUE rb_gtype;
	GType gtype;
	rb_gtype = argv[0];
	gtype = NUM2UINT(rb_gtype);
	info = g_irepository_find_by_gtype(SELF(self), gtype);
    } else {
	VALUE rb_namespace, rb_name;
	const gchar *namespace_, *name;

	rb_scan_args(argc, argv, "2", &rb_namespace, &rb_name);
	namespace_ = RVAL2CSTR(rb_namespace);
	name = RVAL2CSTR(rb_name);
	info = g_irepository_find_by_name(SELF(self), namespace_, name);
    }

    return GI_BASE_INFO2RVAL(info);
}
コード例 #22
0
ファイル: oci8.c プロジェクト: ashleysharpe/ruby-oci8
/*
 * call-seq:
 *   logon2(username, password, dbname, mode) -> connection
 *
 * <b>internal use only</b>
 *
 * Creates a simple logon session by the OCI function OCILogon2().
 */
static VALUE oci8_logon2(VALUE self, VALUE username, VALUE password, VALUE dbname, VALUE mode)
{
    oci8_svcctx_t *svcctx = DATA_PTR(self);

    if (svcctx->logoff_strategy != NULL) {
        rb_raise(rb_eRuntimeError, "Could not reuse the session.");
    }

    /* check arugmnets */
    OCI8SafeStringValue(username);
    OCI8SafeStringValue(password);
    if (!NIL_P(dbname)) {
        OCI8SafeStringValue(dbname);
    }

    /* logon */
    svcctx->base.type = OCI_HTYPE_SVCCTX;
    chker2(OCILogon2_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc,
                        RSTRING_ORATEXT(username), RSTRING_LEN(username),
                        RSTRING_ORATEXT(password), RSTRING_LEN(password),
                        NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
                        NIL_P(dbname) ? 0 : RSTRING_LEN(dbname), NUM2UINT(mode)),
           &svcctx->base);
    svcctx->logoff_strategy = &simple_logoff;

    /* setup the session handle */
    chker2(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->usrhp, 0, OCI_ATTR_SESSION, oci8_errhp),
           &svcctx->base);
    copy_session_handle(svcctx);

    /* setup the server handle */
    chker2(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->srvhp, 0, OCI_ATTR_SERVER, oci8_errhp),
           &svcctx->base);
    copy_server_handle(svcctx);

    return Qnil;
}
コード例 #23
0
ファイル: service.c プロジェクト: brianwells/dnssd
static VALUE
dnssd_service_add_record(VALUE self, VALUE _flags, VALUE _rrtype, VALUE _rdata,
    VALUE _ttl) {
  VALUE _record = Qnil;
  DNSServiceRef *client;
  DNSRecordRef *record;
  DNSServiceFlags flags;
  DNSServiceErrorType e;
  uint16_t rrtype;
  uint16_t rdlen;
  const void *rdata;
  uint32_t ttl;

  _rdata = rb_str_to_str(_rdata);
  flags = (DNSServiceFlags)NUM2ULONG(_flags);
  rrtype = NUM2UINT(_rrtype);
  rdlen = RSTRING_LEN(_rdata);
  rdata = (void *)RSTRING_PTR(_rdata);
  ttl = (uint32_t)NUM2ULONG(_ttl);

  get(cDNSSDService, self, DNSServiceRef, client);

  _record = rb_class_new_instance(0, NULL, cDNSSDRecord);

  get(cDNSSDRecord, _record, DNSRecordRef, record);

  e = DNSServiceAddRecord(*client, record, flags, rrtype, rdlen, rdata, ttl);

  dnssd_check_error_code(e);

  /* record will become invalid when this service is destroyed */
  rb_ivar_set(_record, dnssd_iv_service, self);
  rb_ary_push(rb_ivar_get(self, dnssd_iv_records), _record);

  return _record;
}
コード例 #24
0
ファイル: rbglib_iochannel.c プロジェクト: htrb/ruby-gnome2
static VALUE
rg_read(gint argc, VALUE *argv, VALUE self)
{
    VALUE rbcount;
    gsize count;
    gchar *buffer;
    gsize bytes_read;
    GIOChannel *channel = _SELF(self);
    GError *error = NULL;
    GIOStatus status;

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

    if (NIL_P(rbcount)) {
        status = g_io_channel_read_to_end(channel, &buffer, &bytes_read, &error);
        ioc_error(status, error);

        return buffer != NULL ? CSTR2RVAL_LEN_FREE(buffer, bytes_read) : CSTR2RVAL("");
    }

    count = NUM2UINT(rbcount);

    buffer = g_new(gchar, count);
    memset(buffer, '\0', count);

    status = g_io_channel_read_chars(channel, buffer, count, &bytes_read, &error);
    if (status == G_IO_STATUS_NORMAL)
        return CSTR2RVAL_LEN_FREE(buffer, bytes_read);
    else if (status == G_IO_STATUS_EOF)
        return CSTR2RVAL("");

    ioc_error(status, error);

    /* Not reached. */
    return Qnil;
}
コード例 #25
0
ファイル: rb-grn-context.c プロジェクト: nobu/rroonga
/*
 * call-seq:
 *   context[name] -> Groonga::Object or nil
 *   context[id]   -> Groonga::Object or nil
 *
 * コンテキスト管理下にあるオブジェクトを返す。
 *
 * _name_として文字列を指定した場合はオブジェクト名でオブジェ
 * クトを検索する。
 *
 * _id_として数値を指定した場合はオブジェクトIDでオブジェク
 * トを検索する。
 */
static VALUE
rb_grn_context_array_reference (VALUE self, VALUE name_or_id)
{
    grn_ctx *context;
    grn_obj *object;
    const char *name;
    unsigned int name_size;
    grn_id id;

    context = SELF(self);
    switch (TYPE(name_or_id)) {
      case T_SYMBOL:
	name = rb_id2name(SYM2ID(name_or_id));
	name_size = strlen(name);
	object = rb_grn_context_get_backward_compatibility(context,
							   name, name_size);
	break;
      case T_STRING:
	name = StringValuePtr(name_or_id);
	name_size = RSTRING_LEN(name_or_id);
	object = rb_grn_context_get_backward_compatibility(context,
							   name, name_size);
	break;
      case T_FIXNUM:
	id = NUM2UINT(name_or_id);
	object = grn_ctx_at(context, id);
	break;
      default:
	rb_raise(rb_eArgError,
		 "should be String, Symbol or unsigned integer: %s",
		 rb_grn_inspect(name_or_id));
	break;
    }

    return GRNOBJECT2RVAL(Qnil, context, object, RB_GRN_FALSE);
}
コード例 #26
0
ファイル: rbgdkkeymap.c プロジェクト: Vasfed/ruby-gnome2
static VALUE
rg_get_entries_for_keyval(VALUE self, VALUE keyval)
{
  GdkKeymapKey* keys;
  gint n_keys;
  gboolean ret;
  ret = gdk_keymap_get_entries_for_keyval(_SELF(self),
                                          NUM2UINT(keyval), &keys, &n_keys);

  if (ret){
    VALUE key;
    VALUE ary = rb_ary_new();
    gint i;
    for (i = 0; i < n_keys; i++){
      key = rb_ary_new3(3, UINT2NUM(keys[i].keycode), INT2NUM(keys[i].group), 
                        INT2NUM(keys[i].level));
      rb_ary_push(ary, key);
    }
    g_free(keys);
    return ary;
  } else {
    return Qnil;
  }
}
コード例 #27
0
ファイル: rbpango.c プロジェクト: Vasfed/pango
static VALUE
rg_s_unichar_direction(G_GNUC_UNUSED VALUE self, VALUE ch)
{
    return PANGODIRECTION2RVAL(pango_unichar_direction(NUM2UINT(ch)));
}
コード例 #28
0
ファイル: match.c プロジェクト: Epictetus/trema
/*
 * Creates a {Match} instance which describe fields such as MAC addresses, IP
 * addresses, TCP/UDP ports of a flow to match against. An exact match 
 * flow would match on all fields whereas don't care bits are wildcarded and
 * ignored.
 *
 * @overload initialize(options={})
 *
 *   @example 
 *     Match.new(
 *       :in_port => port_no,
 *       :dl_src => "xx:xx:xx;xx:xx:xx",
 *       :dl_dst => "xx:xx:xx:xx:xx:xx",
 *       :dl_type => ethertype,
 *       :dl_vlan => vlan,
 *       :dl_vlan_pcp => priority,
 *       :nw_tos => tos,
 *       :nw_proto => proto,
 *       :nw_src => ip_address/netmask,
 *       :nw_dst => ip_address/netmask,
 *       :tp_src => port,
 *       :tp_dst => port,
 *     )
 *
 *   @param [Hash] options the options hash.
 *
 *   @option options [Symbol] :inport
 *     the physical port number to match.
 *
 *   @option options [Symbol] :dl_src
 *     the source ethernet address to match specified either as 6 pairs of
 *     hexadecimal digits delimited by colon or as a hexadecimal number.
 *     (eg. "00:11:22:33:44:55" or 0x001122334455).
 *
 *   @option options [Symbol] :dl_dst
 *     the destination ethernet address to match specified either as a 6 pairs of
 *     hexadecimal digits delimited by colon or as a hexadecimal number.
 *     (eg. "00:11:22:33:44:55" or 0x001122334455).
 *
 *   @option options [Symbol] :dl_type
 *     the Ethernet protocol type to match. Can be specified either as a decimal
 *     or hexadecimal number. (eg 0x0800 to match IP packets, 0x08006 to match
 *     ARP packets, 0x88cc for LLDP packets).
 *
 *   @option options [Symbol] :dl_vlan
 *     the IEEE 802.1q virtual VLAN tag to match specified as a 12-bit number
 *     0 to 4095 inclusive.
 *
 *   @option options [Symbol] :dl_vlan_pcp
 *     the IEEE 802.1q Priority Code Point (PCP) to match specified as a value of
 *     0 to 7 inclusive. A higher value indicates a higher priority frame.
 *
 *   @option options [Symbol] :nw_tos
 *     the IP ToS/DSCP field to match specified as a decimal number between 0 and
 *     255 inclusive.
 *
 *   @option options [Symbol] :nw_proto
 *     Depending on the dl_type the IP protocol type to match. (eg if dl_type
 *     equals 0x0800 UDP packets can be match by setting nw_proto to 17.)
 *     to match TCP packets). When dl_type = 0x0806 is set to arp it matches the
 *     lower 8 bits of the ARP opcode.
 *
 *   @option options [Symbol] :nw_src
 *     the IPv4 source address to match if dl_type is set to 0x0800.
 *
 *   @option options [Symbol] :nw_dst
 *     the IPv4 destination address to match if dl_type is set to 0x0800.
 *
 *   @option options [Symbol] :tp_src
 *     the source TCP/UDP port number to match specified as a decimal number
 *     between 0 and 65535 inclusive. The value dl_type and nw_proto must be set
 *     to specify TCP or UDP.
 *
 *   @option options [Symbol] :tp_dst
 *     the destination TCP/UDP port number to match specified as a decimal number
 *     between 0 and 65535 inclusive.
 *
 * @return [Match] self
 *   an object that encapsulates and wraps the +struct ofp_match+
 */
static VALUE
match_init( int argc, VALUE *argv, VALUE self ) {
  struct ofp_match *match;
  VALUE options;

  // Always clear the memory as the unused memory locations are
  // exposed to both the user and the OpenFlow controller.
  Data_Get_Struct( self, struct ofp_match, match );
  memset( match, 0, sizeof ( *match ) );

  // Default matches all packets.
  match->wildcards = ( OFPFW_ALL & ~( OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK ) )
    | OFPFW_NW_SRC_ALL | OFPFW_NW_DST_ALL;

  if ( rb_scan_args( argc, argv, "01", &options ) >= 1 ) {
    if ( options != Qnil ) {
      VALUE in_port = rb_hash_aref( options, ID2SYM( rb_intern( "in_port" ) ) );
      if ( in_port != Qnil ) {
        match->in_port = ( uint16_t ) NUM2UINT( in_port );
        match->wildcards &= ( uint32_t ) ~OFPFW_IN_PORT;
      }

      VALUE dl_src = rb_hash_aref( options, ID2SYM( rb_intern( "dl_src" ) ) );
      if ( dl_src != Qnil ) {
        VALUE dl_addr = rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, dl_src );
        dl_addr_short( dl_addr, match->dl_src );
        match->wildcards &= ( uint32_t ) ~OFPFW_DL_SRC;
      }

      VALUE dl_dst = rb_hash_aref( options, ID2SYM( rb_intern( "dl_dst" ) ) );
      if ( dl_dst != Qnil ) {
        VALUE dl_addr = rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, dl_dst );
        dl_addr_short( dl_addr, match->dl_dst );
        match->wildcards &= ( uint32_t ) ~OFPFW_DL_DST;
      }

      VALUE dl_type = rb_hash_aref( options, ID2SYM( rb_intern( "dl_type" ) ) );
      if ( dl_type != Qnil ) {
        match->dl_type = ( uint16_t ) NUM2UINT( dl_type );
        match->wildcards &= ( uint32_t ) ~OFPFW_DL_TYPE;
      }

      VALUE dl_vlan = rb_hash_aref( options, ID2SYM( rb_intern( "dl_vlan" ) ) );
      if ( dl_vlan != Qnil ) {
        match->dl_vlan = ( uint16_t ) NUM2UINT( dl_vlan );
        match->wildcards &= ( uint32_t ) ~OFPFW_DL_VLAN;
      }

      VALUE dl_vlan_pcp = rb_hash_aref( options, ID2SYM( rb_intern( "dl_vlan_pcp" ) ) );
      if ( dl_vlan_pcp != Qnil ) {
        match->dl_vlan_pcp = ( uint8_t ) NUM2UINT( dl_vlan_pcp );
        match->wildcards &= ( uint32_t ) ~OFPFW_DL_VLAN_PCP;
      }

      VALUE nw_tos = rb_hash_aref( options, ID2SYM( rb_intern( "nw_tos" ) ) );
      if ( nw_tos != Qnil ) {
        match->nw_tos = ( uint8_t ) NUM2UINT( nw_tos );
        match->wildcards &= ( uint32_t ) ~OFPFW_NW_TOS;
      }

      VALUE nw_proto = rb_hash_aref( options, ID2SYM( rb_intern( "nw_proto" ) ) );
      if ( nw_proto != Qnil ) {
        match->nw_proto = ( uint8_t ) NUM2UINT( nw_proto );
        match->wildcards &= ( uint32_t ) ~OFPFW_NW_PROTO;
      }

      VALUE nw_src = rb_hash_aref( options, ID2SYM( rb_intern( "nw_src" ) ) );
      if ( nw_src != Qnil ) {
        VALUE nw_addr = rb_funcall( rb_eval_string( "Trema::IP" ), rb_intern( "new" ), 1, nw_src );
        match->nw_src = nw_addr_to_i( nw_addr );
        match->wildcards &= ( uint32_t ) ~OFPFW_NW_SRC_MASK;
      }

      VALUE nw_dst = rb_hash_aref( options, ID2SYM( rb_intern( "nw_dst" ) ) );
      if ( nw_dst != Qnil ) {
        VALUE nw_addr = rb_funcall( rb_eval_string( "Trema::IP" ), rb_intern( "new" ), 1, nw_dst );
        match->nw_dst = nw_addr_to_i( nw_addr );
        match->wildcards &= ( uint32_t ) ~OFPFW_NW_DST_MASK;
      }

      VALUE tp_src = rb_hash_aref( options, ID2SYM( rb_intern( "tp_src" ) ) );
      if ( tp_src != Qnil ) {
        match->tp_src = ( uint16_t ) NUM2UINT( tp_src );
        match->wildcards &= ( uint32_t ) ~OFPFW_TP_SRC;
      }

      VALUE tp_dst = rb_hash_aref( options, ID2SYM( rb_intern( "tp_dst" ) ) );
      if ( tp_dst != Qnil ) {
        match->tp_dst = ( uint16_t ) NUM2UINT( tp_dst );
        match->wildcards &= ( uint32_t ) ~OFPFW_TP_DST;
      }
    }
  }
  return self;
}
コード例 #29
0
uint32_t
nw_addr_to_i( VALUE nw_addr ) {
  return ( uint32_t ) NUM2UINT( rb_funcall( nw_addr, rb_intern( "to_i" ), 0 ) );
}
コード例 #30
0
ファイル: rbgobj_value.c プロジェクト: dmaciejak/ruby-gnome2
void
rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
{
    GType type, fundamental_type;

    type = G_VALUE_TYPE(result);
    if (rbgobj_convert_rvalue2gvalue(type, val, result))
        return;

    fundamental_type = G_TYPE_FUNDAMENTAL(type);
    switch (fundamental_type) {
      case G_TYPE_NONE:
        return;
      case G_TYPE_CHAR:
        g_value_set_char(result, NUM2INT(val));
        return;
      case G_TYPE_UCHAR:
        g_value_set_uchar(result, NUM2UINT(val));
        return;
      case G_TYPE_BOOLEAN:
        g_value_set_boolean(result, RVAL2CBOOL(val));
        return;
      case G_TYPE_INT:
        g_value_set_int(result, NUM2INT(val));
        return;
      case G_TYPE_UINT:
        g_value_set_uint(result, NUM2UINT(val));
        return;
      case G_TYPE_LONG:
        g_value_set_long(result, NUM2LONG(val));
        return;
      case G_TYPE_ULONG:
        g_value_set_ulong(result, NUM2ULONG(val));
        return;
      case G_TYPE_INT64:
        g_value_set_int64(result, rbglib_num_to_int64(val));
        return;
      case G_TYPE_UINT64:
        g_value_set_uint64(result, rbglib_num_to_uint64(val));
        return;
      case G_TYPE_ENUM:
        g_value_set_enum(result, rbgobj_get_enum(val, G_VALUE_TYPE(result)));
        return;
      case G_TYPE_FLAGS:
        g_value_set_flags(result, rbgobj_get_flags(val, G_VALUE_TYPE(result)));
        return;
      case G_TYPE_FLOAT:
        g_value_set_float(result, NUM2DBL(val));
        return;
      case G_TYPE_DOUBLE:
        g_value_set_double(result, NUM2DBL(val));
        return;
      case G_TYPE_STRING:
        {
            if (SYMBOL_P(val))
                val = rb_funcall(val, id_to_s, 0);
            g_value_set_string(result, RVAL2CSTR_ACCEPT_NIL(val));
            return;
        }
      case G_TYPE_OBJECT:
      case G_TYPE_INTERFACE:
        g_value_set_object(result, NIL_P(val) ? NULL : RVAL2GOBJ(val));
        return;
      case G_TYPE_PARAM:
        g_value_set_param(result, NIL_P(val) ? NULL : RVAL2GOBJ(val));
        return;
      case G_TYPE_POINTER:
        g_value_set_pointer(result, NIL_P(val) ? NULL : rbgobj_ptr2cptr(val));
        return;
      case G_TYPE_BOXED:
        {
            GType gtype;
            for (gtype = type;
                 gtype != G_TYPE_INVALID;
                 gtype = g_type_parent(gtype))
            {
                RValueToGValueFunc func =
                    g_type_get_qdata(gtype, qRValueToGValueFunc);
                if (!func)
                    continue;
                func(val, result);
                return;
            }
        }

      default:
        if (!rbgobj_convert_rvalue2gvalue(fundamental_type, val, result)) {
            RValueToGValueFunc func =
                g_type_get_qdata(type, qRValueToGValueFunc);
            if (!func){
                g_warning("rbgobj_rvalue_to_gvalue: unsupported type: %s\n",
                          g_type_name(type));
            } else {
                func(val, result);
            }
        }
    }
}