sfcc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+
2
+ #ifndef RUBY_NATIVE_SFCC_CIM_CLIENT_H
3
+ #define RUBY_NATIVE_SFCC_CIM_CLIENT_H
4
+
5
+ #include "sfcc.h"
6
+
7
+ void init_cim_client();
8
+
9
+ extern VALUE cSfccCimClient;
10
+ VALUE Sfcc_wrap_cim_client(CMCIClient *client);
11
+
12
+ #endif
@@ -0,0 +1,65 @@
1
+
2
+ #include "sfcc.h"
3
+ #include "cim_enumeration.h"
4
+ #include "cim_object_path.h"
5
+
6
+ static void
7
+ dealloc(CMPIEnumeration *enm)
8
+ {
9
+ SFCC_DEC_REFCOUNT(enm);
10
+ }
11
+
12
+ /**
13
+ * call-seq:
14
+ * enumeration.each do |value|
15
+ * ...
16
+ * end
17
+ *
18
+ * iterates over all values in the enumeration
19
+ *
20
+ */
21
+ static VALUE each(VALUE self)
22
+ {
23
+ CMPIStatus status;
24
+ CMPIEnumeration *ptr = NULL;
25
+ CMPIData next;
26
+ Data_Get_Struct(self, CMPIEnumeration, ptr);
27
+
28
+ CMPIEnumeration *tmp = ptr->ft->clone(ptr, &status);
29
+
30
+ if (!status.rc) {
31
+ while (tmp->ft->hasNext(tmp, NULL)) {
32
+ next = tmp->ft->getNext(tmp, NULL);
33
+ VALUE cimclass = sfcc_cimdata_to_value(next);
34
+ /* Strange sfcc bug, if I clone the enum, I get a NULL
35
+ class afterwards in the copy */
36
+ if (NIL_P(cimclass))
37
+ continue;
38
+ rb_yield(cimclass);
39
+ }
40
+ }
41
+
42
+ tmp->ft->release(tmp);
43
+ sfcc_rb_raise_if_error(status, "Can't iterate enumeration");
44
+ return Qnil;
45
+ }
46
+
47
+ VALUE
48
+ Sfcc_wrap_cim_enumeration(CMPIEnumeration *enm)
49
+ {
50
+ SFCC_INC_REFCOUNT(enm);
51
+ return Data_Wrap_Struct(cSfccCimEnumeration, NULL, dealloc, enm);
52
+ }
53
+
54
+ VALUE cSfccCimEnumeration;
55
+ void init_cim_enumeration()
56
+ {
57
+ VALUE sfcc = rb_define_module("Sfcc");
58
+ VALUE cimc = rb_define_module_under(sfcc, "Cim");
59
+
60
+ VALUE klass = rb_define_class_under(cimc, "Enumeration", rb_cObject);
61
+ cSfccCimEnumeration = klass;
62
+
63
+ rb_define_method(klass, "each", each, 0);
64
+ rb_include_module(klass, rb_const_get(rb_cObject, rb_intern("Enumerable")));
65
+ }
@@ -0,0 +1,12 @@
1
+
2
+ #ifndef RUBY_NATIVE_SFCC_CIM_ENUMERATION_H
3
+ #define RUBY_NATIVE_SFCC_CIM_ENUMERATION_H
4
+
5
+ #include "sfcc.h"
6
+
7
+ void init_cim_enumeration();
8
+
9
+ extern VALUE cSfccCimEnumeration;
10
+ VALUE Sfcc_wrap_cim_enumeration(CMPIEnumeration *enm);
11
+
12
+ #endif
@@ -0,0 +1,357 @@
1
+
2
+ #include "cim_instance.h"
3
+ #include "cim_object_path.h"
4
+
5
+ static void
6
+ dealloc(CMPIInstance *instance)
7
+ {
8
+ SFCC_DEC_REFCOUNT(instance);
9
+ }
10
+
11
+ /**
12
+ * call-seq:
13
+ * property(name)
14
+ *
15
+ * Gets a named property value, where name is a Symbol or String
16
+ */
17
+ static VALUE property(VALUE self, VALUE name)
18
+ {
19
+ CMPIInstance *ptr = NULL;
20
+ CMPIStatus status;
21
+ CMPIData data;
22
+ Data_Get_Struct(self, CMPIInstance, ptr);
23
+ data = ptr->ft->getProperty(ptr, StringValuePtr(name), &status);
24
+ if ( !status.rc )
25
+ return sfcc_cimdata_to_value(data);
26
+
27
+ sfcc_rb_raise_if_error(status, "Can't retrieve property '%s'", StringValuePtr(name));
28
+ return Qnil;
29
+ }
30
+
31
+ /**
32
+ * call-seq:
33
+ * instance.each_property do |name, value|
34
+ * ...
35
+ * end
36
+ *
37
+ * enumerates properties yielding the property name and
38
+ * its value
39
+ *
40
+ */
41
+ static VALUE each_property(VALUE self)
42
+ {
43
+ CMPIInstance *ptr = NULL;
44
+ CMPIStatus status;
45
+ int k=0;
46
+ int num_props=0;
47
+ CMPIString *property_name = NULL;
48
+ CMPIData data;
49
+ Data_Get_Struct(self, CMPIInstance, ptr);
50
+
51
+ num_props = ptr->ft->getPropertyCount(ptr, &status);
52
+ if (!status.rc) {
53
+ for (; k < num_props; ++k) {
54
+ data = ptr->ft->getPropertyAt(ptr, k, &property_name, &status);
55
+ if (!status.rc) {
56
+ rb_yield_values(2, (property_name ? rb_str_intern(rb_str_new2(property_name->ft->getCharPtr(property_name, NULL))) : Qnil), sfcc_cimdata_to_value(data));
57
+ }
58
+ else {
59
+ sfcc_rb_raise_if_error(status, "Can't retrieve property #%d", k);
60
+ }
61
+ if (property_name) CMRelease(property_name);
62
+ }
63
+ }
64
+ else {
65
+ sfcc_rb_raise_if_error(status, "Can't retrieve property count");
66
+ }
67
+ return Qnil;
68
+ }
69
+
70
+ /**
71
+ * call-seq:
72
+ * property_count()
73
+ *
74
+ * Gets the number of properties contained in this Instance
75
+ */
76
+ static VALUE property_count(VALUE self)
77
+ {
78
+ CMPIInstance *ptr = NULL;
79
+ Data_Get_Struct(self, CMPIInstance, ptr);
80
+ return UINT2NUM(ptr->ft->getPropertyCount(ptr, NULL));
81
+ }
82
+
83
+ /**
84
+ * call-seq:
85
+ * set_property(name, value)
86
+ *
87
+ * Adds/replaces a names property
88
+ */
89
+ static VALUE set_property(VALUE self, VALUE name, VALUE value)
90
+ {
91
+ CMPIInstance *ptr = NULL;
92
+ CMPIData data;
93
+ Data_Get_Struct(self, CMPIInstance, ptr);
94
+ data = sfcc_value_to_cimdata(value);
95
+ ptr->ft->setProperty(ptr, StringValuePtr(name), &data.value, data.type);
96
+
97
+ return value;
98
+ }
99
+
100
+ /**
101
+ * call-seq:
102
+ * object_path()
103
+ *
104
+ * Generates an ObjectPath out of the nameSpace, classname and
105
+ * key propeties of this Instance.
106
+ */
107
+ static VALUE object_path(VALUE self)
108
+ {
109
+ CMPIInstance *ptr = NULL;
110
+ CMPIObjectPath *op;
111
+ CMPIObjectPath *newop;
112
+ Data_Get_Struct(self, CMPIInstance, ptr);
113
+ op = ptr->ft->getObjectPath(ptr, NULL);
114
+ newop = op->ft->clone(op, NULL);
115
+ op->ft->release(op);
116
+ return Sfcc_wrap_cim_object_path(newop);
117
+ }
118
+
119
+ /**
120
+ * call-seq:
121
+ * set_property_filter(property_list, keys)
122
+ *
123
+ * Directs CMPI to ignore any setProperty operations for this
124
+ * instance for any properties not in this list.
125
+ *
126
+ * +property_list+ If not nil, the members of the array define one
127
+ * or more Property names to be accepted by set_property operations.
128
+ *
129
+ * +keys+ Array of key property names of this instance. This array
130
+ * must be specified.
131
+ *
132
+ */
133
+ static VALUE set_property_filter(VALUE self, VALUE property_list, VALUE keys)
134
+ {
135
+ CMPIStatus status;
136
+ CMPIInstance *ptr = NULL;
137
+ char **prop_a;
138
+ char **key_a;
139
+
140
+ Data_Get_Struct(self, CMPIInstance, ptr);
141
+
142
+ prop_a = sfcc_value_array_to_string_array(property_list);
143
+ key_a = sfcc_value_array_to_string_array(keys);
144
+
145
+ status = ptr->ft->setPropertyFilter(ptr, prop_a, key_a);
146
+ free(prop_a);
147
+ free(key_a);
148
+
149
+ sfcc_rb_raise_if_error(status, "Can't set property filter");
150
+ return self;
151
+ }
152
+
153
+ /**
154
+ * call-seq:
155
+ * qualifier(name)
156
+ *
157
+ * gets a named qualifier value
158
+ */
159
+ static VALUE qualifier(VALUE self, VALUE name)
160
+ {
161
+ CMPIInstance *ptr = NULL;
162
+ CMPIStatus status;
163
+ CMPIData data;
164
+ memset(&status, 0, sizeof(CMPIStatus));
165
+ Data_Get_Struct(self, CMPIInstance, ptr);
166
+ data = ptr->ft->getQualifier(ptr, StringValuePtr(name), &status);
167
+ if ( !status.rc )
168
+ return sfcc_cimdata_to_value(data);
169
+
170
+ sfcc_rb_raise_if_error(status, "Can't retrieve qualifier '%s'", StringValuePtr(name));
171
+ return Qnil;
172
+ }
173
+
174
+ /**
175
+ * call-seq:
176
+ * cimclass.each_qualifier do |name, value|
177
+ * ...
178
+ * end
179
+ *
180
+ * enumerates properties yielding the qualifier name and
181
+ * its value
182
+ *
183
+ */
184
+ static VALUE each_qualifier(VALUE self)
185
+ {
186
+ CMPIInstance *ptr = NULL;
187
+ CMPIStatus status;
188
+ int k=0;
189
+ int num_props=0;
190
+ CMPIString *qualifier_name = NULL;
191
+ CMPIData data;
192
+ Data_Get_Struct(self, CMPIInstance, ptr);
193
+
194
+ num_props = ptr->ft->getQualifierCount(ptr, &status);
195
+ if (!status.rc) {
196
+ for (; k < num_props; ++k) {
197
+ data = ptr->ft->getQualifierAt(ptr, k, &qualifier_name, &status);
198
+ if (!status.rc) {
199
+ rb_yield_values(2, (qualifier_name ? rb_str_new2(qualifier_name->ft->getCharPtr(qualifier_name, NULL)) : Qnil), sfcc_cimdata_to_value(data));
200
+ }
201
+ else {
202
+ sfcc_rb_raise_if_error(status, "Can't retrieve qualifier #%d", k);
203
+ }
204
+ if (qualifier_name) CMRelease(qualifier_name);
205
+ }
206
+ }
207
+ else {
208
+ sfcc_rb_raise_if_error(status, "Can't retrieve qualifier count");
209
+ }
210
+ return Qnil;
211
+ }
212
+
213
+ /**
214
+ * call-seq:
215
+ * qualifier_count()
216
+ *
217
+ * Gets the number of qualifiers in this instance
218
+ */
219
+ static VALUE qualifier_count(VALUE self)
220
+ {
221
+ CMPIInstance *ptr = NULL;
222
+ Data_Get_Struct(self, CMPIInstance, ptr);
223
+ return UINT2NUM(ptr->ft->getQualifierCount(ptr, NULL));
224
+ }
225
+
226
+ /**
227
+ * call-seq:
228
+ * property_qualifier(property_name, qualifier_name)
229
+ *
230
+ * gets a named property qualifier value
231
+ */
232
+ static VALUE property_qualifier(VALUE self, VALUE property_name, VALUE qualifier_name)
233
+ {
234
+ CMPIInstance *ptr = NULL;
235
+ CMPIStatus status;
236
+ CMPIData data;
237
+ memset(&status, 0, sizeof(CMPIStatus));
238
+ Data_Get_Struct(self, CMPIInstance, ptr);
239
+ data = ptr->ft->getPropertyQualifier(ptr, StringValuePtr(property_name),
240
+ StringValuePtr(qualifier_name), &status);
241
+ if ( !status.rc )
242
+ return sfcc_cimdata_to_value(data);
243
+
244
+ sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier '%s'", StringValuePtr(qualifier_name));
245
+ return Qnil;
246
+ }
247
+
248
+ /**
249
+ * call-seq:
250
+ * cimclass.each_property_qualifier(property_name) do |name, value|
251
+ * ...
252
+ * end
253
+ *
254
+ * enumerates properties yielding the property qualifier name and
255
+ * its value
256
+ *
257
+ */
258
+ static VALUE each_property_qualifier(VALUE self, VALUE property_name)
259
+ {
260
+ CMPIInstance *ptr = NULL;
261
+ CMPIStatus status;
262
+ int k=0;
263
+ int num_props=0;
264
+ CMPIString *property_qualifier_name = NULL;
265
+ CMPIData data;
266
+ Data_Get_Struct(self, CMPIInstance, ptr);
267
+
268
+ num_props = ptr->ft->getPropertyQualifierCount(ptr, StringValuePtr(property_name), &status);
269
+ if (!status.rc) {
270
+ for (; k < num_props; ++k) {
271
+ data = ptr->ft->getPropertyQualifierAt(ptr, StringValuePtr(property_name), k, &property_qualifier_name, &status);
272
+ if (!status.rc) {
273
+ rb_yield_values(2, (property_qualifier_name ? rb_str_new2(property_qualifier_name->ft->getCharPtr(property_qualifier_name, NULL)) : Qnil), sfcc_cimdata_to_value(data));
274
+ }
275
+ else {
276
+ sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier #%d", k);
277
+ }
278
+ if (property_qualifier_name) CMRelease(property_qualifier_name);
279
+ }
280
+ }
281
+ else {
282
+ sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier count");
283
+ }
284
+ return Qnil;
285
+ }
286
+
287
+ /**
288
+ * call-seq:
289
+ * property_qualifier_count(property_name)
290
+ *
291
+ * Gets the number of qualifiers contained in this property
292
+ */
293
+ static VALUE property_qualifier_count(VALUE self, VALUE property_name)
294
+ {
295
+ CMPIInstance *ptr = NULL;
296
+ Data_Get_Struct(self, CMPIInstance, ptr);
297
+ return UINT2NUM(ptr->ft->getPropertyQualifierCount(ptr, StringValuePtr(property_name), NULL));
298
+ }
299
+
300
+ /**
301
+ * call-seq
302
+ * new()
303
+ *
304
+ * Creates an instance from in +object_path+
305
+ *
306
+ */
307
+ static VALUE new(VALUE klass, VALUE object_path)
308
+ {
309
+ CMPIStatus status;
310
+ CMPIInstance *ptr;
311
+ CMPIInstance *newins;
312
+ CMPIObjectPath *op;
313
+
314
+ Data_Get_Struct(object_path, CMPIObjectPath, op);
315
+ ptr = newCMPIInstance(op, &status);
316
+ newins = ptr->ft->clone(ptr, &status);
317
+ ptr->ft->release(ptr);
318
+
319
+ if (!status.rc)
320
+ return Sfcc_wrap_cim_instance(newins);
321
+ sfcc_rb_raise_if_error(status, "Can't create instance");
322
+ return Qnil;
323
+ }
324
+
325
+ VALUE
326
+ Sfcc_wrap_cim_instance(CMPIInstance *instance)
327
+ {
328
+ SFCC_INC_REFCOUNT(instance);
329
+ return Data_Wrap_Struct(cSfccCimInstance, NULL, dealloc, instance);
330
+ }
331
+
332
+ VALUE cSfccCimInstance;
333
+ void init_cim_instance()
334
+ {
335
+ VALUE sfcc = rb_define_module("Sfcc");
336
+ VALUE cimc = rb_define_module_under(sfcc, "Cim");
337
+
338
+ /**
339
+ * an instance of a CIM class
340
+ */
341
+ VALUE klass = rb_define_class_under(cimc, "Instance", rb_cObject);
342
+ cSfccCimInstance = klass;
343
+
344
+ rb_define_singleton_method(klass, "new", new, 1);
345
+ rb_define_method(klass, "property", property, 1);
346
+ rb_define_method(klass, "each_property", each_property, 0);
347
+ rb_define_method(klass, "property_count", property_count, 0);
348
+ rb_define_method(klass, "set_property", set_property, 2);
349
+ rb_define_method(klass, "object_path", object_path, 0);
350
+ rb_define_method(klass, "set_property_filter", set_property_filter, 3);
351
+ rb_define_method(klass, "qualifier", qualifier, 1);
352
+ rb_define_method(klass, "each_qualifier", each_qualifier, 0);
353
+ rb_define_method(klass, "qualifier_count", qualifier_count, 0);
354
+ rb_define_method(klass, "property_qualifier", property_qualifier, 2);
355
+ rb_define_method(klass, "each_property_qualifier", each_property_qualifier, 1);
356
+ rb_define_method(klass, "property_qualifier_count", property_qualifier_count, 1);
357
+ }
@@ -0,0 +1,12 @@
1
+
2
+ #ifndef RUBY_NATIVE_SFCC_CIM_INSTANCE_H
3
+ #define RUBY_NATIVE_SFCC_CIM_INSTANCE_H
4
+
5
+ #include "sfcc.h"
6
+
7
+ void init_cim_instance();
8
+
9
+ extern VALUE cSfccCimInstance;
10
+ VALUE Sfcc_wrap_cim_instance(CMPIInstance *instance);
11
+
12
+ #endif