예제 #1
0
파일: rb_call.c 프로젝트: makdharma/grpc
/* grpc_rb_op_update_status_from_server adds the values in a ruby status
   struct to the 'send_status_from_server' portion of an op.
*/
static void grpc_rb_op_update_status_from_server(
    grpc_op *op, grpc_metadata_array *md_ary, grpc_slice *send_status_details,
    VALUE status) {
  VALUE code = rb_struct_aref(status, sym_code);
  VALUE details = rb_struct_aref(status, sym_details);
  VALUE metadata_hash = rb_struct_aref(status, sym_metadata);

  /* TODO: add check to ensure status is the correct struct type */
  if (TYPE(code) != T_FIXNUM) {
    rb_raise(rb_eTypeError, "invalid code : got <%s>, want <Fixnum>",
             rb_obj_classname(code));
    return;
  }
  if (TYPE(details) != T_STRING) {
    rb_raise(rb_eTypeError, "invalid details : got <%s>, want <String>",
             rb_obj_classname(code));
    return;
  }

  *send_status_details =
      grpc_slice_from_copied_buffer(RSTRING_PTR(details), RSTRING_LEN(details));

  op->data.send_status_from_server.status = NUM2INT(code);
  op->data.send_status_from_server.status_details = send_status_details;
  grpc_rb_md_ary_convert(metadata_hash, md_ary);
  op->data.send_status_from_server.trailing_metadata_count = md_ary->count;
  op->data.send_status_from_server.trailing_metadata = md_ary->metadata;
}
예제 #2
0
GimpParamDef
rb2GimpParamDef (VALUE param)
{
    if (!rb_obj_is_kind_of(param, sGimpParamDef))
        rb_raise(rb_eArgError, "Parameters must be of type Gimp::ParamDef");

    VALUE type = rb_struct_aref(param, ID2SYM(id_type));
    VALUE name = rb_struct_aref(param, ID2SYM(id_name));
    VALUE dscr = rb_struct_aref(param, ID2SYM(id_dscr));

    GimpParamDef result;
    result.type = NUM2INT(type);
    result.name = StringValuePtr(name);
    result.description = StringValuePtr(dscr);

/*  printf("%d %s %s\n", result.type, result.name, result.description); //PRINTF*/
    return result;
}
예제 #3
0
GimpParasite
rb2GimpParasite (VALUE leech)
{
  GimpParasite result;


  VALUE rbname = rb_struct_aref(leech, ID2SYM(id_name));
  result.name = g_strdup(StringValuePtr(rbname));

  result.flags = NUM2UINT(rb_struct_aref(leech, ID2SYM(id_flags)));

  VALUE rbdata = rb_struct_aref(leech, ID2SYM(id_data));
  Check_Type(rbdata, T_STRING);

  result.size = RSTRING_LEN(RSTRING(rbdata));
  result.data = g_memdup(RSTRING_PTR(RSTRING(rbdata)), result.size);

  return result;
}
예제 #4
0
VALUE
rb_struct_fields( int argc, VALUE *argv, VALUE strct)
{
    VALUE ary;
    int i;

    ary = rb_ary_new2( argc);
    for (i = 0; i < argc; i++)
        rb_ary_push( ary, rb_struct_aref( strct, argv[ i]));
    return ary;
}
예제 #5
0
static VALUE struct_spec_rb_struct_aref(VALUE self, VALUE st, VALUE key) {
  return rb_struct_aref(st, key);
}
예제 #6
0
파일: struct.c 프로젝트: Chatto/VGdesk
static VALUE
struct_entry(VALUE s, long n)
{
    return rb_struct_aref(s, LONG2NUM(n));
}
예제 #7
0
GimpParam
rb2GimpParam (VALUE rbparam)
{
  if (!rb_obj_is_kind_of(rbparam, sGimpParam))
    rb_raise(rb_eTypeError, "Parameter is not a Gimp::Param");

  int type = NUM2INT(rb_struct_aref(rbparam, ID2SYM(id_type)));
  VALUE rbdata = rb_struct_aref(rbparam, ID2SYM(id_data));

  GimpParam result;
  result.type = (GimpPDBArgType)type;

  switch (type)
    {
    case GIMP_PDB_INT32:
      result.data.d_int32 = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_INT16:
      result.data.d_int16 = (gint16)NUM2INT(rbdata);
      break;

    case GIMP_PDB_INT8:
      result.data.d_int8 = (gint8)NUM2INT(rbdata);
      break;

    case GIMP_PDB_FLOAT:
      result.data.d_float = (gdouble)NUM2DBL(rbdata);
      break;

    case GIMP_PDB_STRING:
      result.data.d_string = g_strdup(StringValuePtr(rbdata));
      break;

    case GIMP_PDB_INT32ARRAY:
      result.data.d_int32array = rb2gimp_array(type, rbdata);
      break;

    case GIMP_PDB_INT16ARRAY:
      result.data.d_int16array = rb2gimp_array(type, rbdata);
      break;

    case GIMP_PDB_INT8ARRAY:
      result.data.d_int8array = str2gint8(rbdata);
      break;

    case GIMP_PDB_FLOATARRAY:
      result.data.d_floatarray = rb2gimp_array(type, rbdata);
      break;

    case GIMP_PDB_STRINGARRAY:
      result.data.d_stringarray = rb2gimp_array(type, rbdata);
      break;

    case GIMP_PDB_COLOR:
      result.data.d_color = rb2GimpRGB(rbdata);
      break;

    case GIMP_PDB_DISPLAY:
      result.data.d_display = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_IMAGE:
      result.data.d_image = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_LAYER:
      result.data.d_layer = (gint32)NUM2INT(rbdata);
      break;

/*   case GIMP_PDB_LAYER_MASK:
     result.data.d_layer_mask = (gint32)NUM2INT(rbdata);
     break;*/

    case GIMP_PDB_CHANNEL:
      result.data.d_channel = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_DRAWABLE:
      result.data.d_drawable = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_SELECTION:
      result.data.d_selection = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_BOUNDARY:
      result.data.d_boundary = (gint32)NUM2INT(rbdata);
      break;

    case GIMP_PDB_VECTORS:
      result.data.d_vectors = (gint32)NUM2INT(rbdata);
      break;

/*   case GIMP_PDB_UNIT:
     result.data.d_unit = (gint32)NUM2INT(rbdata);
     break;*/

    case GIMP_PDB_PARASITE:
      result.data.d_parasite = rb2GimpParasite(rbdata);
      break;

/*   case GIMP_PDB_TATTOO:
     result.data.d_tattoo = (gint32)NUM2INT(rbdata);
     break;*/

    case GIMP_PDB_STATUS:
      result.data.d_status = (GimpPDBStatusType)NUM2INT(rbdata);
      break;
    }

  return result;
}