Class: Sfcc::Cim::ObjectPath

Inherits:
Object
  • Object
show all
Defined in:
lib/sfcc/object_path.rb,
ext/sfcc/cim_object_path.c

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Catch-all for ObjectPath.<key> or ObjectPath.<method>(<args>)


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sfcc/object_path.rb', line 71

def method_missing name, *args
  if args.empty?
    begin
      self.key name
    rescue Sfcc::Cim::ErrorNoSuchProperty
      self.invoke name
    end
  else
    self.invoke name, *args
  end
end

Class Method Details

.new(namespace, classname) ⇒ ObjectPath

Creates an object path from namespace and classname


471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'ext/sfcc/cim_object_path.c', line 471

static VALUE new(int argc, VALUE *argv, VALUE self)
{
  VALUE namespace;
  VALUE class_name;
  VALUE client;

  CIMCStatus status = { 0, NULL };
  CIMCObjectPath *ptr;

  rb_scan_args(argc, argv, "12", &namespace, &class_name, &client);

  ptr = cimcEnv->ft->newObjectPath(cimcEnv, to_charptr(namespace), to_charptr(class_name), &status);

  if (!status.rc)
    return Sfcc_wrap_cim_object_path(ptr, client);
  sfcc_rb_raise_if_error(status, "Can't create object path");
  return Qnil;
}

Instance Method Details

#[](name) ⇒ Object

ObjectPath# Get key value Alias for ObjectPath#key(value)


12
13
14
# File 'lib/sfcc/object_path.rb', line 12

def [] name
	self.key(name)
end

#add_key(name, value) ⇒ Object

adds a named key value


187
188
189
190
191
192
193
194
195
196
197
198
# File 'ext/sfcc/cim_object_path.c', line 187

static VALUE add_key(VALUE self, VALUE name, VALUE value)
{
  CIMCObjectPath *ptr;
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  data = sfcc_value_to_cimdata(value);
  ptr->ft->addKey(ptr, to_charptr(name), &data.value, data.type);
  return value;
}

#class_qualifier(qualifier_name) ⇒ Object

Get class qualifier value


345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'ext/sfcc/cim_object_path.c', line 345

static VALUE class_qualifier(VALUE self, VALUE qualifier_name)
{
  CIMCObjectPath *ptr;
  CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  if (ptr->ft->getClassQualifier) { /* might be missing in sfcc/backend/cimxml/objectpath.c */
    data = ptr->ft->getClassQualifier(ptr, to_charptr(qualifier_name), &status);
    if ( !status.rc )
      return sfcc_cimdata_to_value(&data, rso->client);
  }
  sfcc_rb_raise_if_error(status, "Can't retrieve class qualifier '%s'", to_charptr(qualifier_name));
  return Qnil;
}

#classnameObject

Get the class name component


131
132
133
134
135
136
137
138
139
140
141
# File 'ext/sfcc/cim_object_path.c', line 131

static VALUE classname(VALUE self)
{
  CIMCObjectPath *ptr;
  CIMCString *cimstr;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  cimstr = ptr->ft->getClassName(ptr, NULL);
  return CIMSTR_2_RUBYSTR(cimstr);
}

#classname=(ns) ⇒ Object

Set/replace the class name component


114
115
116
117
118
119
120
121
122
123
# File 'ext/sfcc/cim_object_path.c', line 114

static VALUE set_classname(VALUE self, VALUE val)
{
  CIMCObjectPath *ptr;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  ptr->ft->setClassName(ptr, to_charptr(val));
  return val;
}

#clientClient

Get the client component


173
174
175
176
177
178
179
# File 'ext/sfcc/cim_object_path.c', line 173

static VALUE get_client(VALUE self)
{
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  return rso->client;
}

#client=(Client) ⇒ Object

Set/replace the client component


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/sfcc/cim_object_path.c', line 149

static VALUE set_client(VALUE self, VALUE client)
{
  CIMCStatus status;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  if ((TYPE(client) == T_DATA)
      && (CLASS_OF(client) == cSfccCimClient)) {
    rso->client = client;
    return client;
  }
  else {
    status.rc = CIMC_RC_ERR_TYPE_MISMATCH;
    sfcc_rb_raise_if_error(status, "Argument must be Cim::Client");
  }
  return Qnil;
}

#do(|name, value|) ⇒ Object

end

enumerates properties yielding the key name and its value


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'ext/sfcc/cim_object_path.c', line 233

static VALUE each_key(VALUE self)
{
  CIMCObjectPath *ptr;
  CIMCStatus status;
  int k=0;
  int num_props=0;
  CIMCString *key_name = NULL;
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;

  num_props = ptr->ft->getKeyCount(ptr, &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getKeyAt(ptr, k, &key_name, &status);
      if (!status.rc) {
        rb_yield_values(2, rb_str_intern(CIMSTR_2_RUBYSTR(key_name)), sfcc_cimdata_to_value(&data, rso->client));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve key #%d", k);
      }
      if (key_name) key_name->ft->release(key_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve key count");
  }
  return Qnil;
}

#hostnameObject

Get the hostname component


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/sfcc/cim_object_path.c', line 93

static VALUE hostname(VALUE self)
{
  CIMCObjectPath *ptr;
  CIMCString *cimstr;
  CIMCStatus status;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  cimstr = ptr->ft->getHostname(ptr, &status);
  if (!status.rc)
    return CIMSTR_2_RUBYSTR(cimstr);
  sfcc_rb_raise_if_error(status, "Can't get hostname");
  return Qnil;
}

#hostname=(ns) ⇒ Object

Set/replace the hostname component


72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'ext/sfcc/cim_object_path.c', line 72

static VALUE set_hostname(VALUE self, VALUE val)
{
  CIMCObjectPath *ptr;
  CIMCStatus status;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  status = ptr->ft->setHostname(ptr, to_charptr(val));
  if (!status.rc)
    return val;
  sfcc_rb_raise_if_error(status, "Can't set hostname");
  return Qnil;
}

#invoke(name, *args) ⇒ Object

invoke name, *args Class or instance method invocation


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sfcc/object_path.rb', line 22

def invoke name, *args
  raise "Cannot invoke, ObjectPath has no client associated" unless self.client
	classname = self.classname  # get method input parameter information

	s = "mof/#{classname}"
	begin
	  require s
	rescue LoadError
	  STDERR.puts "ruby-sfcc(invoke): Cannot load #{s} for type information"
	  return
	end
	methods = MOF.class_eval "#{classname}::METHODS"
	method = methods[name.to_s]
	raise "Unknown method #{name} for #{classname}" unless method
	type = method[:type]
	parameters = method[:parameters] || {}
	input = parameters[:in]
	output = parameters[:out]
	argsin = {}
	i = 0
  if input
    while i < input.size
      value = args.shift
      raise "Argument for #{input[i]} is nil, not allowed !" unless value
      argsin[input[i]] = value      # FIXME more typecheck of args ?

      i += 2
    end
  end
  argsout = nil
	if output
	  if args.empty?
	    raise "Function #{name} has output arguments, please add an empty hash to the call"
	  end
	  argsout = args.shift
	  unless argsout.kind_of? Hash
	    raise "Function #{name} has output arguments, last argument must be a Hash"
	  end
	  unless args.empty?
	    raise "Function call to #{name} has excess arguments"
	  end
	end
  res = self.client.invoke_method(self, name, argsin, argsout)
  return res
end

#key(name) ⇒ Object

Gets a named key value


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/sfcc/cim_object_path.c', line 206

static VALUE key(VALUE self, VALUE name)
{
  CIMCObjectPath *ptr;
  CIMCStatus status;
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  data = ptr->ft->getKey(ptr, to_charptr(name), &status);
  if ( !status.rc )
    return sfcc_cimdata_to_value(&data, rso->client);

  sfcc_rb_raise_if_error(status, "Can't retrieve key '%s'", to_charptr(name));
  return Qnil;
}

#key_countObject

Gets the number of properties contained in this ObjectPath


271
272
273
274
275
276
277
278
279
# File 'ext/sfcc/cim_object_path.c', line 271

static VALUE key_count(VALUE self)
{
  CIMCObjectPath *ptr;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  return UINT2NUM(ptr->ft->getKeyCount(ptr, NULL));
}

#method_qualifier(method_name, qualifier_name) ⇒ Object

Get method qualifier value


394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'ext/sfcc/cim_object_path.c', line 394

static VALUE method_qualifier(VALUE self, VALUE method_name, VALUE qualifier_name)
{
  CIMCObjectPath *ptr;
  CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  if (ptr->ft->getMethodQualifier) { /* might be missing in sfcc/backend/cimxml/objectpath.c */
    data = ptr->ft->getMethodQualifier(ptr, to_charptr(method_name),
                                       to_charptr(qualifier_name), &status);
    if ( !status.rc )
      return sfcc_cimdata_to_value(&data, rso->client);
  }
  sfcc_rb_raise_if_error(status, "Can't retrieve method qualifier '%s' for method '%s'", to_charptr(qualifier_name), to_charptr(method_name));
  return Qnil;
}

#namespaceObject

Get the namespace component


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/sfcc/cim_object_path.c', line 50

static VALUE namespace(VALUE self)
{
  CIMCObjectPath *ptr;
  CIMCString *cimstr;
  CIMCStatus status;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  cimstr = ptr->ft->getNameSpace(ptr, &status);
  if (!status.rc)
    return CIMSTR_2_RUBYSTR(cimstr);
  sfcc_rb_raise_if_error(status, "Can't get namespace");
  return Qnil;
}

#namespace=(ns) ⇒ Object

Set/replace the namespace component


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/sfcc/cim_object_path.c', line 30

static VALUE set_namespace(VALUE self, VALUE val)
{
  CIMCObjectPath *ptr;
  CIMCStatus status;
  rb_sfcc_object_path *rso;
  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  status = ptr->ft->setNameSpace(ptr, to_charptr(val));
  if (!status.rc)
    return val;
  sfcc_rb_raise_if_error(status, "Can't set namespace");
  return Qnil;
}

#parameter_qualifier(parameter_name, qualifier_name) ⇒ Object

Get parameter qualifier value


419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'ext/sfcc/cim_object_path.c', line 419

static VALUE parameter_qualifier(VALUE self,
                                 VALUE method_name,
                                 VALUE parameter_name,
                                 VALUE qualifier_name)
{
  CIMCObjectPath *ptr;
  CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  if (ptr->ft->getParameterQualifier) { /* might be missing in sfcc/backend/cimxml/objectpath.c */
    data = ptr->ft->getParameterQualifier(ptr,
                                          to_charptr(method_name),
                                          to_charptr(parameter_name),
                                          to_charptr(qualifier_name), &status);
    if ( !status.rc )
      return sfcc_cimdata_to_value(&data, rso->client);
  }
  sfcc_rb_raise_if_error(status, "Can't retrieve parameter qualifier '%s' for '%s'/'%s'", to_charptr(qualifier_name), to_charptr(method_name), to_charptr(parameter_name));
  return Qnil;
}

#property_qualifier(property_name, qualifier_name) ⇒ Object

Get property qualifier value


369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'ext/sfcc/cim_object_path.c', line 369

static VALUE property_qualifier(VALUE self, VALUE property_name, VALUE qualifier_name)
{
  CIMCObjectPath *ptr;
  CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };
  CIMCData data;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  if (ptr->ft->getPropertyQualifier) { /* might be missing in sfcc/backend/cimxml/objectpath.c */
    data = ptr->ft->getPropertyQualifier(ptr, to_charptr(property_name),
                                         to_charptr(qualifier_name), &status);
    if ( !status.rc )
      return sfcc_cimdata_to_value(&data, rso->client);
  }
  sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier '%s' for property '%s'", to_charptr(qualifier_name), to_charptr(property_name));
  return Qnil;
}

#set_host_and_namespace_from(object_path) ⇒ Object

Set/replace the hostname namespace and classname components from object_path


316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'ext/sfcc/cim_object_path.c', line 316

static VALUE set_host_and_namespace_from(VALUE self, VALUE object_path)
{
  CIMCObjectPath *ptr;
  CIMCObjectPath *src;
  CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };
  rb_sfcc_object_path *rso, *rso1;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  Data_Get_Struct(object_path, rb_sfcc_object_path, rso1);
  src = rso1->op;

  if (ptr->ft->setHostAndNameSpaceFromObjectPath) { /* might be missing in sfcc/backend/cimxml/objectpath.c */
    status = ptr->ft->setHostAndNameSpaceFromObjectPath(ptr, src);
  }

  if (!status.rc)
    return self;

  sfcc_rb_raise_if_error(status, "Can't set namespace and hostname");
  return Qnil;
}

#set_namespace_from(object_path) ⇒ Object

Set/replace the namespace and classname components from object_path


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'ext/sfcc/cim_object_path.c', line 288

static VALUE set_namespace_from(VALUE self, VALUE object_path)
{
  CIMCObjectPath *ptr;
  CIMCObjectPath *src;
  CIMCStatus status;
  rb_sfcc_object_path *rso, *rso1;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;
  Data_Get_Struct(object_path, rb_sfcc_object_path, rso1);
  src = rso1->op;

  status = ptr->ft->setNameSpaceFromObjectPath(ptr, src);

  if (!status.rc)
    return self;

  sfcc_rb_raise_if_error(status, "Can't set namespace");
  return Qnil;
}

#to_sObject

Generates a well formed string representation of this ObjectPath


448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'ext/sfcc/cim_object_path.c', line 448

static VALUE to_s(VALUE self)
{
  VALUE ret;
  CIMCObjectPath *ptr;
  CIMCString *cimstr;
  rb_sfcc_object_path *rso;

  Data_Get_Struct(self, rb_sfcc_object_path, rso);
  ptr = rso->op;

  cimstr = ptr->ft->toString(ptr, NULL);
  ret = CIMSTR_2_RUBYSTR(cimstr);
  cimstr->ft->release(cimstr);
  return ret;
}