Esempio n. 1
0
VALUE sfcc_cimdata_to_value(CIMCData data)
{
  CIMCString *cimstr = NULL;
  VALUE rbval;
  CIMCStatus status;

  if (data.type & CMPI_ARRAY) {
    int k = 0;
    int n = 0;
    VALUE rbarray = rb_ary_new();

    if (!data.value.array)
      return rb_ary_new();

    n = data.value.array->ft->getSize(data.value.array, &status);
    if (!status.rc) {
      for (k = 0; k < n; ++k) {
        CIMCData element = data.value.array->ft->getElementAt(data.value.array, k, NULL);
        rb_ary_push(rbarray, sfcc_cimdata_to_value(element));
      }
      return rbarray;
    }
    sfcc_rb_raise_if_error(status, "Can't retrieve array size");
    return Qnil;
  }
  else if (data.type & CMPI_ENC) {
    switch (data.type) {
    case CMPI_instance:
      return data.value.inst ? Sfcc_wrap_cim_instance(data.value.inst->ft->clone(data.value.inst, NULL)) : Qnil;
    case CMPI_class:
      return data.value.cls ? Sfcc_wrap_cim_class(data.value.cls->ft->clone(data.value.cls, NULL)) : Qnil;
    case CMPI_ref:
      return data.value.ref ? Sfcc_wrap_cim_object_path(data.value.ref->ft->clone(data.value.ref, NULL)) : Qnil;
    case CMPI_args:
      return data.value.args ? sfcc_cimargs_to_hash(data.value.args) : Qnil;
    case CMPI_filter:
      return Qnil;
    case CMPI_numericString:
    case CMPI_booleanString:
    case CMPI_dateTimeString:
    case CMPI_classNameString:
      break;
    case CMPI_string:
      return data.value.string ? rb_str_new2((char*)data.value.string->ft->getCharPtr(data.value.string, NULL)) : Qnil;
    case CMPI_charsptr:
      return data.value.chars ? rb_str_new((char*)data.value.dataPtr.ptr, data.value.dataPtr.length) : Qnil;
    case CMPI_dateTime:
      cimstr = data.value.dateTime ? CMGetStringFormat(data.value.dateTime,NULL) : NULL;
      rbval = cimstr ? rb_str_new2(cimstr->ft->getCharPtr(cimstr, NULL)) : Qnil;
      if (cimstr) CMRelease(cimstr);
      return rbval;
    }
  }
  else if (data.type & CMPI_SIMPLE) {
    switch (data.type) {
    case CMPI_boolean: return data.value.boolean ? Qtrue : Qfalse;
    case CMPI_char16: return UINT2NUM(data.value.char16);
    }
  }
  else if (data.type & CMPI_INTEGER) {
    switch (data.type) {
    case CMPI_uint8: return UINT2NUM(data.value.uint8);
    case CMPI_sint8: return INT2NUM(data.value.sint8);
    case CMPI_uint16: return UINT2NUM(data.value.uint16);
    case CMPI_sint16: return INT2NUM(data.value.sint16);
    case CMPI_uint32: return UINT2NUM(data.value.uint32);
    case CMPI_sint32: return INT2NUM(data.value.sint32);
    case CMPI_uint64: return UINT2NUM(data.value.uint64);
    case CMPI_sint64: return INT2NUM(data.value.sint64);
    }
  }
  else if (data.type & CMPI_REAL) {
    switch (data.type) {
    case CMPI_real32: return LONG2NUM(data.value.real32);
    case CMPI_real64: return LONG2NUM(data.value.real64);
    }
  }
  else if (data.type & CMPI_null ) {
    return Qnil;
  }
  rb_raise(rb_eTypeError, "unsupported data data type %d", data.type);
  return Qnil;
}
Esempio n. 2
0
VALUE sfcc_cimdata_to_value(CIMCData *data, VALUE client)
{
  VALUE rbval;
  CIMCStatus status;

  if ((data->state != CIMC_goodValue)
      && (data->state != CIMC_keyValue)) {
    if (data->state & CIMC_nullValue)
      return Qnil;
    if (data->state & CIMC_notFound)
      rb_raise(rb_eRuntimeError, "Value not found");
    if (data->state & CIMC_badValue)
      rb_raise(rb_eArgError, "Bad value");
  }
  if (data->type & CIMC_ARRAY) {
    int k = 0;
    int n = 0;
    VALUE rbarray = rb_ary_new();

    if (!data->value.array)
      return rb_ary_new();

    n = data->value.array->ft->getSize(data->value.array, &status);
    if (!status.rc) {
      for (k = 0; k < n; ++k) {
        CIMCData element = data->value.array->ft->getElementAt(data->value.array, k, NULL);
        rb_ary_push(rbarray, sfcc_cimdata_to_value(&element, client));
      }
      return rbarray;
    }
    sfcc_rb_raise_if_error(status, "Can't retrieve array size");
    return Qnil;
  }
  else if (data->type & CIMC_ENC) {
    switch (data->type) {
    case CIMC_instance:
      return data->value.inst ? Sfcc_wrap_cim_instance(data->value.inst->ft->clone(data->value.inst, NULL), client) : Qnil;
    case CIMC_ref:
      return data->value.ref ? Sfcc_wrap_cim_object_path(data->value.ref->ft->clone(data->value.ref, NULL), client) : Qnil;
    case CIMC_args:
      return data->value.args ? sfcc_cimargs_to_hash(data->value.args, client) : Qnil;
    case CIMC_class:
      return data->value.cls ? Sfcc_wrap_cim_class(data->value.cls->ft->clone(data->value.cls, NULL)) : Qnil;
    case CIMC_filter:
      return Qnil;
    case CIMC_enumeration:
      return data->value.Enum ? Sfcc_wrap_cim_enumeration(data->value.Enum->ft->clone(data->value.Enum, NULL), client) : Qnil;
    case CIMC_string:
      if (data->value.string) {
        const char *strval = data->value.string->ft->getCharPtr(data->value.string, NULL);
        /* getCharPtr() might return NULL and rb_str_new2 doesn't like that */
        if (strval)
          return rb_str_new2(strval);
      }
      return Qnil;
    case CIMC_chars:
      return data->value.chars ? rb_str_new2(data->value.chars) : Qnil;
    case CIMC_charsptr:
      return data->value.chars ? rb_str_new((char*)data->value.dataPtr.ptr, data->value.dataPtr.length) : Qnil;
    case CIMC_dateTime:
      if (data->value.dateTime) {
        CIMCUint64 bintime;
        bintime = data->value.dateTime->ft->getBinaryFormat(data->value.dateTime, NULL);
        rbval = rb_time_new((time_t) (bintime / 1000000L), (time_t) (bintime % 1000000));
      }
      else {
        rbval = Qnil;
      }
      return rbval;
    default:
      rb_raise(rb_eTypeError, "Unhandled type 0x%04x", data->type);
    }
  }
  else if (data->type & CIMC_SIMPLE) {
    switch (data->type) {
    case CIMC_boolean: return data->value.boolean ? Qtrue : Qfalse;
    case CIMC_char16: return UINT2NUM(data->value.char16);
    }
  }
  else if (data->type & CIMC_INTEGER) {
    switch (data->type) {
    case CIMC_uint8: return UINT2NUM(data->value.uint8);
    case CIMC_sint8: return INT2NUM(data->value.sint8);
    case CIMC_uint16: return UINT2NUM(data->value.uint16);
    case CIMC_sint16: return INT2NUM(data->value.sint16);
    case CIMC_uint32: return UINT2NUM(data->value.uint32);
    case CIMC_sint32: return INT2NUM(data->value.sint32);
    case CIMC_uint64: return UINT2NUM(data->value.uint64);
    case CIMC_sint64: return INT2NUM(data->value.sint64);
    }
  }
  else if (data->type & CIMC_REAL) {
    switch (data->type) {
    case CIMC_real32: return rb_float_new(data->value.real32);
    case CIMC_real64: return rb_float_new(data->value.real64);
    }
  }
  else if (data->type & CIMC_null ) {
    return Qnil;
  }
  rb_raise(rb_eTypeError, "unsupported data type %d", data->type);
  return Qnil;
}