sfcc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,862 @@
1
+ #include "cim_client.h"
2
+ #include "cim_enumeration.h"
3
+ #include "cim_object_path.h"
4
+ #include "cim_class.h"
5
+ #include "cim_instance.h"
6
+
7
+ static void
8
+ dealloc(CMCIClient *client)
9
+ {
10
+ SFCC_DEC_REFCOUNT(client);
11
+ }
12
+
13
+ /**
14
+ * call-seq:
15
+ * get_class(object_path, flags=0, properties=nil)
16
+ *
17
+ * Get Class using +object_path+ as reference. Class structure can be
18
+ * controled using the flags parameter.
19
+ *
20
+ * +object_path+ ObjectPath containing nameSpace and classname components.
21
+ *
22
+ * +flags+ Any combination of the following flags are supported:
23
+ * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
24
+ *
25
+ * +properties+ If not nil, the members of the array define one or more Property
26
+ * names. Each returned Object MUST NOT include elements for any Properties
27
+ * missing from this list
28
+ */
29
+ static VALUE get_class(int argc, VALUE *argv, VALUE self)
30
+ {
31
+ VALUE object_path;
32
+ VALUE flags;
33
+ VALUE properties;
34
+
35
+ CMPIStatus status;
36
+ CMPIObjectPath *op = NULL;
37
+ CMCIClient *client = NULL;
38
+ CMPIConstClass *cimclass = NULL;
39
+ CMPIConstClass *cimclassnew = NULL;
40
+ char **props;
41
+
42
+ rb_scan_args(argc, argv, "12", &object_path, &flags, &properties);
43
+
44
+ if (NIL_P(flags)) flags = INT2NUM(0);
45
+
46
+ memset(&status, 0, sizeof(CMPIStatus));
47
+ Data_Get_Struct(self, CMCIClient, client);
48
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
49
+
50
+ props = sfcc_value_array_to_string_array(properties);
51
+ cimclass = client->ft->getClass(client, op, NUM2INT(flags), props, &status);
52
+ free(props);
53
+
54
+ cimclassnew = cimclass->ft->clone(cimclass, NULL);
55
+ cimclass->ft->release(cimclass);
56
+
57
+ sfcc_rb_raise_if_error(status, "Can't get class");
58
+ return Sfcc_wrap_cim_class(cimclassnew);
59
+ }
60
+
61
+ /**
62
+ * call-seq:
63
+ * class_names(object_path, flags=0)
64
+ *
65
+ * return the available class names for the given
66
+ * +object_path+ and +flags+
67
+ */
68
+ static VALUE class_names(int argc, VALUE *argv, VALUE self)
69
+ {
70
+ VALUE object_path;
71
+ VALUE flags;
72
+
73
+ CMPIStatus status;
74
+ CMPIObjectPath *op = NULL;
75
+ CMCIClient *client = NULL;
76
+ VALUE rbenm = Qnil;
77
+
78
+ rb_scan_args(argc, argv, "11", &object_path, &flags);
79
+ if (NIL_P(flags)) flags = INT2NUM(0);
80
+
81
+ memset(&status, 0, sizeof(CMPIStatus));
82
+ Data_Get_Struct(self, CMCIClient, client);
83
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
84
+
85
+ CMPIEnumeration *enm = client->ft->enumClassNames(client, op, NUM2INT(flags), &status);
86
+ if (enm && !status.rc ) {
87
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
88
+ enm->ft->release(enm);
89
+ return rbenm;
90
+ }
91
+
92
+ sfcc_rb_raise_if_error(status, "Can't get class names");
93
+ return Qnil;
94
+ }
95
+
96
+ /**
97
+ * call-seq:
98
+ * classes(object_path, flags=0)
99
+ *
100
+ * classes and subclasses in the namespace defined by +object_path+.
101
+ *
102
+ * Class structure and inheritance scope can be controled using the +flags+ parameter
103
+ * Any combination of the following flags are supported:
104
+ * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
105
+ */
106
+ static VALUE classes(int argc, VALUE *argv, VALUE self)
107
+ {
108
+ VALUE object_path;
109
+ VALUE flags;
110
+
111
+ CMPIStatus status;
112
+ CMPIObjectPath *op = NULL;
113
+ CMCIClient *client = NULL;
114
+ VALUE rbenm = Qnil;
115
+
116
+ rb_scan_args(argc, argv, "11", &object_path, &flags);
117
+ if (NIL_P(flags)) flags = INT2NUM(0);
118
+
119
+ memset(&status, 0, sizeof(CMPIStatus));
120
+ Data_Get_Struct(self, CMCIClient, client);
121
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
122
+
123
+ CMPIEnumeration *enm = client->ft->enumClasses(client, op, NUM2INT(flags), &status);
124
+ if (enm && !status.rc ) {
125
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
126
+ enm->ft->release(enm);
127
+ return rbenm;
128
+ }
129
+
130
+ sfcc_rb_raise_if_error(status, "Can't get classes");
131
+ return Qnil;
132
+ }
133
+
134
+ /**
135
+ * call-seq:
136
+ * get_instance(object_path, flags=0, properties=nil)
137
+ *
138
+ * get instance using +object_path+ as reference. Instance structure
139
+ * can be controlled using the flags parameter.
140
+ *
141
+ * +object_path+ an ObjectPath containing namespace, class name and key
142
+ * components.
143
+ *
144
+ * +flags+ Any combination of the following flags are supported:
145
+ * Flags::LocalOnly, Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
146
+ *
147
+ * +properties+ If not nil, the members of the array define one or more Property
148
+ * names. Each returned Object MUST NOT include elements for any Properties
149
+ * missing from this list
150
+ */
151
+ static VALUE get_instance(int argc, VALUE *argv, VALUE self)
152
+ {
153
+ VALUE object_path;
154
+ VALUE flags;
155
+ VALUE properties;
156
+
157
+ CMPIStatus status;
158
+ CMPIObjectPath *op = NULL;
159
+ CMCIClient *client = NULL;
160
+ CMPIInstance *ciminstance = NULL;
161
+ char **props;
162
+
163
+ rb_scan_args(argc, argv, "12", &object_path, &flags, &properties);
164
+ if (NIL_P(flags)) flags = INT2NUM(0);
165
+
166
+ memset(&status, 0, sizeof(CMPIStatus));
167
+ Data_Get_Struct(self, CMCIClient, client);
168
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
169
+
170
+ props = sfcc_value_array_to_string_array(properties);
171
+
172
+ ciminstance = client->ft->getInstance(client, op, NUM2INT(flags), props, &status);
173
+ free(props);
174
+
175
+ if (!status.rc)
176
+ return Sfcc_wrap_cim_instance(ciminstance->ft->clone(ciminstance, NULL));
177
+
178
+ sfcc_rb_raise_if_error(status, "Can't get instance");
179
+ return Qnil;
180
+ }
181
+
182
+ /**
183
+ * call-seq:
184
+ * create_instance(object_path, instance)
185
+ *
186
+ * Create Instance from +object_path+ as reference.
187
+ *
188
+ * +object_path+ ObjectPath containing nameSpace, classname and key components.
189
+ *
190
+ * +instance+ Complete instance.
191
+ *
192
+ * returns the assigned instance reference (object path)
193
+ */
194
+ static VALUE create_instance(VALUE self, VALUE object_path, VALUE instance)
195
+ {
196
+ CMPIStatus status;
197
+ CMCIClient *ptr = NULL;
198
+ CMPIObjectPath *op = NULL;
199
+ CMPIObjectPath *new_op = NULL;
200
+ CMPIInstance *inst = NULL;
201
+
202
+ Data_Get_Struct(self, CMCIClient, ptr);
203
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
204
+ Data_Get_Struct(instance, CMPIInstance, inst);
205
+ new_op = ptr->ft->createInstance(ptr, op, inst, &status);
206
+
207
+ if (!status.rc)
208
+ return Sfcc_wrap_cim_object_path(new_op->ft->clone(new_op, NULL));
209
+
210
+ sfcc_rb_raise_if_error(status, "Can't create instance");
211
+ return Qnil;
212
+ }
213
+
214
+ /**
215
+ * call-seq:
216
+ * set_instance(object_path, instance, flags=0, properties=nil)
217
+ *
218
+ * Replace an existing Instance from +instance+, using +object_path+ as reference.
219
+ *
220
+ * +object_path+ ObjectPath containing nameSpace, classname and key components.
221
+ *
222
+ * +instance+ Complete instance.
223
+ *
224
+ * +flags+ The following flag is supported: Flags::IncludeQualifiers.
225
+ *
226
+ * + properties+ If not nil, the members of the array define one or more Property
227
+ * names, only those properties will be updated. Else, all properties will be updated.
228
+ */
229
+ static VALUE set_instance(int argc, VALUE *argv, VALUE self)
230
+ {
231
+ VALUE object_path;
232
+ VALUE instance;
233
+ VALUE flags;
234
+ VALUE properties;
235
+
236
+ CMPIStatus status;
237
+ CMPIObjectPath *op = NULL;
238
+ CMPIInstance *inst = NULL;
239
+ CMCIClient *client = NULL;
240
+ char **props;
241
+
242
+ rb_scan_args(argc, argv, "22", &object_path, &instance, &flags, &properties);
243
+ if (NIL_P(flags)) flags = INT2NUM(0);
244
+
245
+ Data_Get_Struct(self, CMCIClient, client);
246
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
247
+ Data_Get_Struct(instance, CMPIInstance, inst);
248
+
249
+ props = sfcc_value_array_to_string_array(properties);
250
+
251
+ status = client->ft->setInstance(client, op, inst, NUM2INT(flags), props);
252
+ free(props);
253
+
254
+ sfcc_rb_raise_if_error(status, "Can't set instance");
255
+ return instance;
256
+ }
257
+
258
+ /**
259
+ * call-seq:
260
+ * delete_instance(object_path)
261
+ *
262
+ * Delete an existing Instance using +object_path+ as reference.
263
+ * +object_path+ ObjectPath containing nameSpace, classname and key components.
264
+ */
265
+ static VALUE delete_instance(VALUE self, VALUE object_path)
266
+ {
267
+ CMPIStatus status;
268
+ CMPIObjectPath *op = NULL;
269
+ CMCIClient *client = NULL;
270
+
271
+ Data_Get_Struct(self, CMCIClient, client);
272
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
273
+
274
+ status = client->ft->deleteInstance(client, op);
275
+ sfcc_rb_raise_if_error(status, "Can't delete instance '%s'", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
276
+ return Qnil;
277
+ }
278
+
279
+ /**
280
+ * call-seq:
281
+ * query(object_path, query, lang)
282
+ *
283
+ * Query the enumeration of instances of the class (and subclasses) defined
284
+ * by +object_path+ using +query+ expression.
285
+ *
286
+ * +object_path+ ObjectPath containing nameSpace and classname components.
287
+ *
288
+ * +query+ Query expression
289
+ *
290
+ * +lang+ Query Language
291
+ *
292
+ * returns resulting eumeration of instances
293
+ */
294
+ static VALUE query(VALUE self,
295
+ VALUE object_path,
296
+ VALUE query,
297
+ VALUE lang)
298
+ {
299
+ CMPIStatus status;
300
+ CMPIObjectPath *op = NULL;
301
+ CMCIClient *client = NULL;
302
+
303
+ memset(&status, 0, sizeof(CMPIStatus));
304
+ Data_Get_Struct(self, CMCIClient, client);
305
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
306
+ VALUE rbenm = Qnil;
307
+
308
+ CMPIEnumeration *enm = client->ft->execQuery(client,
309
+ op,
310
+ StringValuePtr(query),
311
+ StringValuePtr(lang),
312
+ &status);
313
+ if (enm && !status.rc ) {
314
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
315
+ enm->ft->release(enm);
316
+ return rbenm;
317
+ }
318
+
319
+ sfcc_rb_raise_if_error(status, "Can't get instances from query");
320
+ return Qnil;
321
+ }
322
+
323
+ /**
324
+ * call-seq:
325
+ * instance_names(object_path, flags)
326
+ *
327
+ * instance names of the class defined by +object_path+
328
+ */
329
+ static VALUE instance_names(VALUE self, VALUE object_path)
330
+ {
331
+ CMPIStatus status;
332
+ CMPIObjectPath *op = NULL;
333
+ CMCIClient *client = NULL;
334
+ VALUE rbenm = Qnil;
335
+
336
+ memset(&status, 0, sizeof(CMPIStatus));
337
+ Data_Get_Struct(self, CMCIClient, client);
338
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
339
+
340
+ CMPIEnumeration *enm = client->ft->enumInstanceNames(client, op, &status);
341
+
342
+ if (enm && !status.rc ) {
343
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
344
+ enm->ft->release(enm);
345
+ return rbenm;
346
+ }
347
+ sfcc_rb_raise_if_error(status, "Can't get instance names");
348
+ return Qnil;
349
+ }
350
+
351
+ /**
352
+ * call-seq:
353
+ * instances(object_path, flags=0, properties=nil)
354
+ *
355
+ * Enumerate the instance names of the class defined by +object_path+
356
+ *
357
+ * +object_path+ ObjectPath containing nameSpace and classname components.
358
+ *
359
+ * +flags+ Any combination of the following flags are supported:
360
+ * Flags::LocalOnly, Flags::DeepInheritance,
361
+ * Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
362
+ *
363
+ * +properties+ If not NULL, the members of the array define one or more
364
+ * Property names.
365
+ * Each returned Object MUST NOT include elements for any Properties
366
+ * missing from this list
367
+ *
368
+ */
369
+ static VALUE instances(int argc, VALUE *argv, VALUE self)
370
+ {
371
+ VALUE object_path;
372
+ VALUE flags;
373
+ VALUE properties;
374
+
375
+ CMPIStatus status;
376
+ CMPIObjectPath *op = NULL;
377
+ CMCIClient *client = NULL;
378
+ char **props;
379
+ VALUE rbenm = Qnil;
380
+
381
+ rb_scan_args(argc, argv, "12", &object_path, &flags, &properties);
382
+ if (NIL_P(flags)) flags = INT2NUM(0);
383
+
384
+ memset(&status, 0, sizeof(CMPIStatus));
385
+ Data_Get_Struct(self, CMCIClient, client);
386
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
387
+
388
+ props = sfcc_value_array_to_string_array(properties);
389
+
390
+ CMPIEnumeration *enm = client->ft->enumInstances(client, op, NUM2INT(flags), props, &status);
391
+
392
+ free(props);
393
+
394
+ if (enm && !status.rc ) {
395
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
396
+ enm->ft->release(enm);
397
+ return rbenm;
398
+ }
399
+
400
+ sfcc_rb_raise_if_error(status, "Can't get instances");
401
+ return Qnil;
402
+ }
403
+
404
+ /**
405
+ * call-seq:
406
+ * associators(object_path, association_class=nil,
407
+ * result_class=nil, role=nil, result_role=nil, flags=0
408
+ * properties=nil)
409
+ *
410
+ * Enumerate instances associated with the Instance defined by the +object_path+
411
+ *
412
+ * +object_path+ Source ObjectPath containing nameSpace, classname
413
+ * and key components.
414
+ *
415
+ * +association_class+ If not nil, MUST be a valid Association Class name.
416
+ * It acts as a filter on the returned set of Objects by mandating that
417
+ * each returned Object MUST be associated to the source Object via an
418
+ * Instance of this Class or one of its subclasses.
419
+ *
420
+ * +result_class+ If not nil, MUST be a valid Class name.
421
+ * It acts as a filter on the returned set of Objects by mandating that
422
+ * each returned Object MUST be either an Instance of this Class (or one
423
+ * of its subclasses).
424
+ *
425
+ * +role+ If not nil, MUST be a valid Property name.
426
+ * It acts as a filter on the returned set of Objects by mandating
427
+ * that each returned Object MUST be associated to the source Object
428
+ * via an Association in which the source Object plays the specified role
429
+ * (i.e. the name of the Property in the Association Class that refers
430
+ * to the source Object MUST match the value of this parameter).
431
+ *
432
+ * +result_role+ If not nil, MUST be a valid Property name.
433
+ * It acts as a filter on the returned set of Objects by mandating
434
+ * that each returned Object MUST be associated to the source Object
435
+ * via an Association in which the returned Object plays the specified role
436
+ * (i.e. the name of the Property in the Association Class that refers to
437
+ * the returned Object MUST match the value of this parameter).
438
+ *
439
+ * +flags+ Any combination of the following flags are supported:
440
+ * Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
441
+ *
442
+ * +properties+ If not nil, the members of the array define one or more Property
443
+ * names. Each returned Object MUST NOT include elements for any Properties
444
+ * missing from this list
445
+ *
446
+ * returns enumeration of instances
447
+ */
448
+ static VALUE associators(int argc, VALUE *argv, VALUE self)
449
+ {
450
+ VALUE object_path;
451
+ VALUE assoc_class;
452
+ VALUE result_class;
453
+ VALUE role;
454
+ VALUE result_role;
455
+ VALUE flags;
456
+ VALUE properties;
457
+
458
+ CMPIStatus status;
459
+ CMPIObjectPath *op = NULL;
460
+ CMCIClient *client = NULL;
461
+ char **props;
462
+ CMPIEnumeration *enm = NULL;
463
+ VALUE rbenm = Qnil;
464
+
465
+ rb_scan_args(argc, argv, "16", &object_path,
466
+ &assoc_class, &result_class,
467
+ &role, &result_role, &flags, &properties);
468
+
469
+ if (NIL_P(flags)) flags = INT2NUM(0);
470
+ memset(&status, 0, sizeof(CMPIStatus));
471
+ Data_Get_Struct(self, CMCIClient, client);
472
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
473
+
474
+ props = sfcc_value_array_to_string_array(properties);
475
+
476
+ enm = client->ft->associators(client,
477
+ op,
478
+ NIL_P(assoc_class) ? NULL : StringValuePtr(assoc_class),
479
+ NIL_P(result_class) ? NULL : StringValuePtr(result_class),
480
+ NIL_P(role) ? NULL : StringValuePtr(role),
481
+ NIL_P(result_role) ? NULL : StringValuePtr(result_role),
482
+ NUM2INT(flags), props, &status);
483
+ free(props);
484
+ if (enm && !status.rc ) {
485
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
486
+ enm->ft->release(enm);
487
+ return rbenm;
488
+ }
489
+
490
+ sfcc_rb_raise_if_error(status, "Can't get associators for '%s'", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
491
+ return Qnil;
492
+ }
493
+
494
+ /**
495
+ * call-seq:
496
+ * associator_names(object_path, association_class=nil,
497
+ * result_class=nil, role=nil, result_role=nil, flags=0
498
+ * properties=nil)
499
+ *
500
+ * Enumerate object paths associated with the Instance defined by the
501
+ * +object_path+
502
+ *
503
+ * +object_path+ Source ObjectPath containing nameSpace, classname
504
+ * and key components.
505
+ *
506
+ * +association_class+ If not nil, MUST be a valid Association Class name.
507
+ * It acts as a filter on the returned set of Objects by mandating that
508
+ * each returned Object MUST be associated to the source Object via an
509
+ * Instance of this Class or one of its subclasses.
510
+ *
511
+ * +result_class+ If not nil, MUST be a valid Class name.
512
+ * It acts as a filter on the returned set of Objects by mandating that
513
+ * each returned Object MUST be either an Instance of this Class (or one
514
+ * of its subclasses).
515
+ *
516
+ * +role+ If not nil, MUST be a valid Property name.
517
+ * It acts as a filter on the returned set of Objects by mandating
518
+ * that each returned Object MUST be associated to the source Object
519
+ * via an Association in which the source Object plays the specified role
520
+ * (i.e. the name of the Property in the Association Class that refers
521
+ * to the source Object MUST match the value of this parameter).
522
+ *
523
+ * +result_role+ If not nil, MUST be a valid Property name.
524
+ * It acts as a filter on the returned set of Objects by mandating
525
+ * that each returned Object MUST be associated to the source Object
526
+ * via an Association in which the returned Object plays the specified role
527
+ * (i.e. the name of the Property in the Association Class that refers to
528
+ * the returned Object MUST match the value of this parameter).
529
+ *
530
+ * returns enumeration of object paths
531
+ */
532
+ static VALUE associator_names(int argc, VALUE *argv, VALUE self)
533
+ {
534
+ VALUE object_path;
535
+ VALUE assoc_class;
536
+ VALUE result_class;
537
+ VALUE role;
538
+ VALUE result_role;
539
+
540
+ CMPIStatus status;
541
+ CMPIObjectPath *op = NULL;
542
+ CMCIClient *client = NULL;
543
+ CMPIEnumeration *enm = NULL;
544
+ VALUE rbenm = Qnil;
545
+
546
+ rb_scan_args(argc, argv, "14", &object_path,
547
+ &assoc_class, &result_class,
548
+ &role, &result_role);
549
+
550
+ memset(&status, 0, sizeof(CMPIStatus));
551
+ Data_Get_Struct(self, CMCIClient, client);
552
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
553
+
554
+ enm = client->ft->associatorNames(client,
555
+ op,
556
+ NIL_P(assoc_class) ? NULL : StringValuePtr(assoc_class),
557
+ NIL_P(result_class) ? NULL : StringValuePtr(result_class),
558
+ NIL_P(role) ? NULL : StringValuePtr(role),
559
+ NIL_P(result_role) ? NULL : StringValuePtr(result_role),
560
+ &status);
561
+ if (enm && !status.rc ) {
562
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
563
+ enm->ft->release(enm);
564
+ return rbenm;
565
+ }
566
+ sfcc_rb_raise_if_error(status, "Can't get associator names for '%s'", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
567
+ return Qnil;
568
+ }
569
+
570
+ /**
571
+ * call-seq:
572
+ * references(object_path, result_class=nil, role=nil, flags=0, properties=nil)
573
+ *
574
+ * Enumerates the association instances that refer to the instance defined by
575
+ * +object_path+
576
+ *
577
+ * +object_path+ Source ObjectPath containing nameSpace, classname and key components.
578
+ *
579
+ * +result_class+ If not nil, MUST be a valid Class name.
580
+ * It acts as a filter on the returned set of Objects by mandating that
581
+ * each returned Object MUST be either an Instance of this Class (or one
582
+ * of its subclasses).
583
+ *
584
+ * +role+ If not nil, MUST be a valid Property name.
585
+ * It acts as a filter on the returned set of Objects by mandating
586
+ * that each returned Object MUST be associated to the source Object
587
+ * via an Association in which the source Object plays the specified role
588
+ * (i.e. the name of the Property in the Association Class that refers
589
+ * to the source Object MUST match the value of this parameter).
590
+ *
591
+ * +flags+ Any combination of the following flags are supported:
592
+ * Flags::IncludeQualifiers and Flags::IncludeClassOrigin.
593
+ *
594
+ * +properties+ If not nil, the members of the array define one or more Property
595
+ * names. Each returned Object MUST NOT include elements for any Properties
596
+ * missing from this list
597
+ *
598
+ * returns enumeration of ObjectPaths
599
+ */
600
+ static VALUE references(int argc, VALUE *argv, VALUE self)
601
+ {
602
+ VALUE object_path;
603
+ VALUE result_class;
604
+ VALUE role;
605
+ VALUE flags;
606
+ VALUE properties;
607
+
608
+ CMPIStatus status;
609
+ CMPIObjectPath *op = NULL;
610
+ CMCIClient *client = NULL;
611
+ char **props;
612
+ CMPIEnumeration *enm = NULL;
613
+ VALUE rbenm = Qnil;
614
+
615
+ rb_scan_args(argc, argv, "14", &object_path,
616
+ &result_class, &role,
617
+ &flags, &properties);
618
+
619
+ if (NIL_P(flags)) flags = INT2NUM(0);
620
+ memset(&status, 0, sizeof(CMPIStatus));
621
+ Data_Get_Struct(self, CMCIClient, client);
622
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
623
+
624
+ props = sfcc_value_array_to_string_array(properties);
625
+
626
+ enm = client->ft->references(client,
627
+ op,
628
+ NIL_P(result_class) ? NULL : StringValuePtr(result_class),
629
+ NIL_P(role) ? NULL : StringValuePtr(role),
630
+ NUM2INT(flags), props, &status);
631
+ free(props);
632
+ if (enm && !status.rc ) {
633
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, NULL));
634
+ enm->ft->release(enm);
635
+ return rbenm;
636
+ }
637
+ sfcc_rb_raise_if_error(status, "Can't get references for '%s'", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
638
+ return Qnil;
639
+ }
640
+
641
+ /**
642
+ * call-seq:
643
+ * reference_names(object_path, result_class=nil, role=nil, flags=0, properties=nil)
644
+ *
645
+ * Enumerates the association instances that refer to the instance defined by
646
+ * +object_path+
647
+ *
648
+ * +object_path+ Source ObjectPath containing nameSpace, classname and key components.
649
+ *
650
+ * +result_class+ If not nil, MUST be a valid Class name.
651
+ * It acts as a filter on the returned set of Objects by mandating that
652
+ * each returned Object MUST be either an Instance of this Class (or one
653
+ * of its subclasses).
654
+ *
655
+ * +role+ If not nil, MUST be a valid Property name.
656
+ * It acts as a filter on the returned set of Objects by mandating
657
+ * that each returned Object MUST be associated to the source Object
658
+ * via an Association in which the source Object plays the specified role
659
+ * (i.e. the name of the Property in the Association Class that refers
660
+ * to the source Object MUST match the value of this parameter).
661
+ *
662
+ * returns enumeration of ObjectPaths
663
+ */
664
+ static VALUE reference_names(int argc, VALUE *argv, VALUE self)
665
+ {
666
+ VALUE object_path = Qnil;
667
+ VALUE result_class = Qnil;
668
+ VALUE role = Qnil;
669
+
670
+ CMPIStatus status;
671
+ CMPIObjectPath *op = NULL;
672
+ CMCIClient *client = NULL;
673
+ CMPIEnumeration *enm = NULL;
674
+ VALUE rbenm = Qnil;
675
+
676
+ rb_scan_args(argc, argv, "14", &object_path,
677
+ &result_class, &role);
678
+
679
+ memset(&status, 0, sizeof(CMPIStatus));
680
+ Data_Get_Struct(self, CMCIClient, client);
681
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
682
+
683
+ enm = client->ft->referenceNames(client,
684
+ op,
685
+ NIL_P(result_class) ? NULL : StringValuePtr(result_class),
686
+ NIL_P(role) ? NULL : StringValuePtr(role),
687
+ &status);
688
+ if (enm && !status.rc ) {
689
+ rbenm = Sfcc_wrap_cim_enumeration(enm->ft->clone(enm, &status));
690
+ enm->ft->release(enm);
691
+ return rbenm;
692
+ }
693
+ sfcc_rb_raise_if_error(status, "Can't get reference names for '%s'", CMGetCharsPtr(CMObjectPathToString(op, NULL), NULL));
694
+ return Qnil;
695
+ }
696
+
697
+ /**
698
+ * call-seq:
699
+ * invoke_method(object_path, method_name, argin, argout)
700
+ *
701
+ * Invoke a named, extrinsic method of an instance defined by +object_path+
702
+ *
703
+ * +object_path+ containing namespace, classname, and key
704
+ * components.
705
+ *
706
+ * +argin+ hash containing the input parameters (keys can be symbols) or
707
+ * strings.
708
+ *
709
+ * +argout+ hash where output parameters will be returned
710
+ */
711
+ static VALUE invoke_method(VALUE self,
712
+ VALUE object_path,
713
+ VALUE method_name,
714
+ VALUE argin,
715
+ VALUE argout)
716
+ {
717
+ CMPIStatus status;
718
+ CMCIClient *ptr = NULL;
719
+ CMPIObjectPath *op = NULL;
720
+ CMPIArgs *cmpiargsout;
721
+ VALUE method_name_str;
722
+ char *method_name_cstr;
723
+ CMPIData ret;
724
+ Check_Type(argin, T_HASH);
725
+ memset(&status, 0, sizeof(CMPIStatus));
726
+
727
+ cmpiargsout = newCMPIArgs(NULL);
728
+
729
+ Data_Get_Struct(self, CMCIClient, ptr);
730
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
731
+
732
+ method_name_str = rb_funcall(method_name, rb_intern("to_s"), 0);
733
+ method_name_cstr = StringValuePtr(method_name_str);
734
+ ret = ptr->ft->invokeMethod(ptr,
735
+ op,
736
+ method_name_cstr,
737
+ sfcc_hash_to_cimargs(argin),
738
+ cmpiargsout,
739
+ &status);
740
+ if (!status.rc) {
741
+ if (cmpiargsout && ! NIL_P(argout)) {
742
+ Check_Type(argout, T_HASH);
743
+ rb_funcall(argout, rb_intern("merge!"), 1, sfcc_cimargs_to_hash(cmpiargsout));
744
+ }
745
+ return sfcc_cimdata_to_value(ret);
746
+ }
747
+ sfcc_rb_raise_if_error(status, "Can't invoke method '%s'", method_name_cstr);
748
+ return Qnil;
749
+ }
750
+
751
+ /**
752
+ * call-seq:
753
+ * set_property(object_path, name, value)
754
+ *
755
+ * Sets the named property value of an instance defined by
756
+ * +object_path+
757
+ *
758
+ * +object_path+ containing namespace, classname, and key
759
+ * components.
760
+ */
761
+ static VALUE set_property(VALUE self,
762
+ VALUE object_path,
763
+ VALUE name,
764
+ VALUE value)
765
+ {
766
+ CMPIStatus status;
767
+ CMCIClient *ptr = NULL;
768
+ CMPIObjectPath *op = NULL;
769
+ CMPIData data;
770
+ Data_Get_Struct(self, CMCIClient, ptr);
771
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
772
+ data = sfcc_value_to_cimdata(value);
773
+ status = ptr->ft->setProperty(ptr, op, StringValuePtr(name), &data.value, data.type);
774
+
775
+ if ( !status.rc )
776
+ return value;
777
+ sfcc_rb_raise_if_error(status, "Can't set property '%s'", StringValuePtr(name));
778
+ return Qnil;
779
+ }
780
+
781
+ /**
782
+ * call-seq:
783
+ * property(object_path, name)
784
+ *
785
+ * Gets the named property value of an instance defined by
786
+ * +object_path+
787
+ *
788
+ * +object_path+ containing namespace, classname, and key
789
+ * components.
790
+ */
791
+ static VALUE property(VALUE self, VALUE object_path, VALUE name)
792
+ {
793
+ CMCIClient *ptr = NULL;
794
+ CMPIObjectPath *op = NULL;
795
+ CMPIStatus status;
796
+ CMPIData data;
797
+ memset(&status, 0, sizeof(CMPIStatus));
798
+ Data_Get_Struct(self, CMCIClient, ptr);
799
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
800
+ data = ptr->ft->getProperty(ptr, op, StringValuePtr(name), &status);
801
+ if ( !status.rc )
802
+ return sfcc_cimdata_to_value(data);
803
+
804
+ sfcc_rb_raise_if_error(status, "Can't retrieve property '%s'", StringValuePtr(name));
805
+ return Qnil;
806
+ }
807
+
808
+ static VALUE connect(VALUE klass, VALUE host, VALUE scheme, VALUE port, VALUE user, VALUE pwd)
809
+ {
810
+ CMCIClient *client = NULL;
811
+ CMPIStatus status;
812
+ client = cmciConnect(NIL_P(host) ? NULL : StringValuePtr(host),
813
+ NIL_P(scheme) ? NULL : StringValuePtr(scheme),
814
+ NIL_P(port) ? NULL : StringValuePtr(port),
815
+ NIL_P(user) ? NULL : StringValuePtr(user),
816
+ NIL_P(pwd) ? NULL : StringValuePtr(pwd),
817
+ &status);
818
+ if ( !status.rc )
819
+ return Sfcc_wrap_cim_client(client);
820
+ sfcc_rb_raise_if_error(status, "Can't create CIM client");
821
+ return Qnil;
822
+ }
823
+
824
+ VALUE
825
+ Sfcc_wrap_cim_client(CMCIClient *client)
826
+ {
827
+ assert(client);
828
+ SFCC_INC_REFCOUNT(client);
829
+ return Data_Wrap_Struct(cSfccCimClient, NULL, dealloc, client);
830
+ }
831
+
832
+ VALUE cSfccCimClient;
833
+ void init_cim_client()
834
+ {
835
+ VALUE sfcc = rb_define_module("Sfcc");
836
+ VALUE cimc = rb_define_module_under(sfcc, "Cim");
837
+
838
+ /**
839
+ * CIM client which can communicate with a CIMOM
840
+ */
841
+ VALUE klass = rb_define_class_under(cimc, "Client", rb_cObject);
842
+ cSfccCimClient = klass;
843
+
844
+ rb_define_singleton_method(klass, "native_connect", connect, 5);
845
+ rb_define_method(klass, "get_class", get_class, -1);
846
+ rb_define_method(klass, "class_names", class_names, -1);
847
+ rb_define_method(klass, "classes", classes, -1);
848
+ rb_define_method(klass, "get_instance", get_instance, -1);
849
+ rb_define_method(klass, "create_instance", create_instance, 2);
850
+ rb_define_method(klass, "set_instance", set_instance, -1);
851
+ rb_define_method(klass, "delete_instance", delete_instance, 1);
852
+ rb_define_method(klass, "query", query, 3);
853
+ rb_define_method(klass, "instance_names", instance_names, 1);
854
+ rb_define_method(klass, "instances", instances, -1);
855
+ rb_define_method(klass, "associators", associators, -1);
856
+ rb_define_method(klass, "associator_names", associator_names, -1);
857
+ rb_define_method(klass, "references", references, -1);
858
+ rb_define_method(klass, "reference_names", reference_names, -1);
859
+ rb_define_method(klass, "invoke_method", invoke_method, 4);
860
+ rb_define_method(klass, "set_property", set_property, 3);
861
+ rb_define_method(klass, "property", property, 2);
862
+ }