Ejemplo n.º 1
0
 this_type 
 decamelize() const
 {
   this_type ret;
   decamelize(ret);
   return ret;
 }
Ejemplo n.º 2
0
static VALUE
load_provider(VALUE arg)
{
  const char *classname = (const char *)arg;
  VALUE req; /* result of rb_require */
  if (classname == NULL || *classname == 0) {
    _SBLIM_TRACE(1,("Ruby: load_provider(%s) no class given", classname));
    return Qfalse;
  }
  char *filename = alloca(strlen(classname) * 2 + 1);
  decamelize(classname, filename);
  ruby_script(filename);
  _SBLIM_TRACE(1,("<%d> Ruby: loading (%s)", getpid(), filename));
  req = rb_require(filename);
  /* Qtrue == just loaded, Qfalse = already loaded, else: fail */
  if ((req != Qtrue) && (req != Qfalse)) {
    _SBLIM_TRACE(1,("<%d> require '%s' failed", getpid(), filename));
    return Qnil;
  }
  /* Get Cmpi::Provider */
  VALUE val = rb_const_get(rb_cObject, rb_intern(RB_MODULE_NAME));
  if (NIL_P(val)) {
    _SBLIM_TRACE(1,("<%d> No such module '%s'", getpid(), RB_MODULE_NAME));
    return val;
  }
  val = rb_const_get(val, rb_intern(classname));
  if (NIL_P(val)) {
    _SBLIM_TRACE(1,("<%d> No such class '%s::%s'", getpid(), RB_MODULE_NAME, classname));
  }
  return val;
}
Ejemplo n.º 3
0
/*
 * invokeMethod
 */
static CMPIStatus
invokeMethod(
        CMPIMethodMI* self,
        const CMPIContext* ctx,
        const CMPIResult* rslt,
        const CMPIObjectPath* objName,
        const char* method,
        const CMPIArgs* in,
        CMPIArgs* out)
{
    Target_Type _ctx;
    Target_Type _objName;

    CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   
    _SBLIM_TRACE(1,("invokeMethod() called, ctx %p, rslt %p, objName %p, method %s, in %p, out %p", ctx, rslt, objName, method, in, out));

    TARGET_THREAD_BEGIN_BLOCK; 
    _ctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0);
    _objName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0);
  
    /* Ruby style method invocation */
#if defined(SWIGRUBY)
  
    /* de-camelize method name, might need 2time length */
    char *methodname = alloca(strlen(method) * 2 + 1);
    decamelize(method, methodname);
  
    /* access method arguments information via <decamelized>_args */
    int argsnamesize = strlen(methodname) + 5 + 1;
    char *argsname = alloca(argsnamesize); /* "<name>_args" */
    snprintf(argsname, argsnamesize, "%s_args", methodname);
  
    /* get the args array, gives names of input and output arguments */
    VALUE args = rb_funcall(((ProviderMIHandle*)self->hdl)->implementation, rb_intern(argsname), 0);
    if (check_ruby_type(args, T_ARRAY, "invoke: <method>_args must be Array",  &status, (ProviderMIHandle*)self->hdl ) < 0)
      return status;
  
    VALUE argsin = rb_ary_entry(args, 0); /* array of input arg names */
    if (check_ruby_type(argsin, T_ARRAY, "invoke: Input arguments must be Array", &status, (ProviderMIHandle*)self->hdl ) < 0)
      return status;

    int number_of_arguments = RARRAY_LEN(argsin) / 2;
    _SBLIM_TRACE(1,("%s -> %d input args", argsname, number_of_arguments));
    /* 3 args will be added by TargetCall, 2 args are added here, others are input args to function */
    VALUE *input = alloca((3 + 2 + number_of_arguments) * sizeof(VALUE));
    input[3] = _ctx;
    input[4] = _objName;
    /* loop over input arg names and types and get CMPIData via CMGetArg() */
    int i;
    for (i = 0; i < number_of_arguments; ++i) {
      const char *argname;
      CMPIData data;
      argname = target_charptr(rb_ary_entry(argsin, i*2));
      data = CMGetArg(in, argname, &status);
      if (status.rc != CMPI_RC_OK) {
	if ((data.state & CMPI_nullValue)
	    ||(data.state & CMPI_notFound)) {
	  input[5+i] = Target_Null;
	  continue;
	} 
	_SBLIM_TRACE(1,("Failed (rc %d) to get input arg %d:%s for %s", status.rc, i>>1, argname, method));
	return status;
      }
      input[5+i] = data_value(&data);
    }

    /* actual provider call, passes output args and return value via 'result' */
    VALUE result = TargetCall((ProviderMIHandle*)self->hdl, &status, methodname, -(2+number_of_arguments), input);

    /* argsout is array of [<return_type>, <output_arg_name>, <output_arg_type>, ... */
    VALUE argsout = rb_ary_entry(args, 1);
    CMPIValue value;
    CMPIType expected_type;
    CMPIType actual_type;
    if (check_ruby_type(argsout, T_ARRAY, "invoke: Output arguments must be Array", &status, (ProviderMIHandle*)self->hdl) < 0)
      return status;
    number_of_arguments = (RARRAY_LEN(argsout) - 1);

    if (number_of_arguments > 0) {
      /* if output args are defined, result must be an array
       * result[0] is the return value
       * result[1..n] are the output args in argsout order
       */
      if (check_ruby_type(result, T_ARRAY, "invoke: function with output arguments must return Array", &status, (ProviderMIHandle*)self->hdl) < 0)
        return status;

      /* loop over output arg names and types and set CMPIData via CMSetArg() */
      for (i = 0; i < number_of_arguments; i += 2) {
	const char *argname;
	argname = target_charptr(rb_ary_entry(argsout, i+1));
	expected_type = FIX2ULONG(rb_ary_entry(argsout, i+2));
	actual_type = target_to_value(rb_ary_entry(result, (i >> 1) + 1), &value, expected_type);
	status = CMAddArg(out, argname, &value, actual_type);
	if (status.rc != CMPI_RC_OK) {
	  _SBLIM_TRACE(1,("Failed (rc %d) to set output arg %d:%s for %s; expected type %x, actual type %x", status.rc, i>>1, argname, method, expected_type, actual_type));
	  return status;
	}
      }
      /* result[0] is the return value */
      result = rb_ary_entry(result, 0);

    }