sfcc 0.1.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,6 @@
7
7
  void init_cim_client();
8
8
 
9
9
  extern VALUE cSfccCimClient;
10
- VALUE Sfcc_wrap_cim_client(CMCIClient *client);
10
+ VALUE Sfcc_wrap_cim_client(CIMCClient *client);
11
11
 
12
12
  #endif
@@ -1,12 +1,12 @@
1
1
 
2
- #include "sfcc.h"
3
2
  #include "cim_enumeration.h"
4
3
  #include "cim_object_path.h"
5
4
 
6
5
  static void
7
- dealloc(CMPIEnumeration *enm)
6
+ dealloc(CIMCEnumeration *enm)
8
7
  {
9
- SFCC_DEC_REFCOUNT(enm);
8
+ /* fprintf(stderr, "Sfcc_dealloc_cim_enumeration %p\n", enm); */
9
+ enm->ft->release(enm);
10
10
  }
11
11
 
12
12
  /**
@@ -20,34 +20,119 @@ dealloc(CMPIEnumeration *enm)
20
20
  */
21
21
  static VALUE each(VALUE self)
22
22
  {
23
- CMPIStatus status;
24
- CMPIEnumeration *ptr = NULL;
25
- CMPIData next;
26
- Data_Get_Struct(self, CMPIEnumeration, ptr);
23
+ CIMCStatus status;
24
+ CIMCEnumeration *ptr;
25
+ CIMCArray *ary;
26
+ CIMCData data;
27
+ Data_Get_Struct(self, CIMCEnumeration, ptr);
27
28
 
28
- CMPIEnumeration *tmp = ptr->ft->clone(ptr, &status);
29
-
29
+ /* since getNext() changes the Enumeration, we cannot iterate
30
+ use Array representation instead */
31
+ ary = ptr->ft->toArray(ptr, &status);
30
32
  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);
33
+ CIMCCount count = ary->ft->getSize(ary, NULL);
34
+ CIMCCount idx;
35
+ for (idx = 0; idx < count; ++idx) {
36
+ VALUE value;
37
+ data = ary->ft->getElementAt(ary, idx, NULL);
38
+ value = sfcc_cimdata_to_value(data);
39
+ rb_yield(value);
39
40
  }
41
+ return Qnil;
40
42
  }
41
43
 
42
- tmp->ft->release(tmp);
43
44
  sfcc_rb_raise_if_error(status, "Can't iterate enumeration");
44
45
  return Qnil;
45
46
  }
46
47
 
48
+
49
+ /**
50
+ * call-seq:
51
+ * enumeration.to_a -> Array
52
+ *
53
+ * returns an Array representation of the enumeration
54
+ *
55
+ */
56
+ static VALUE to_a(VALUE self)
57
+ {
58
+ CIMCStatus status;
59
+ CIMCEnumeration *ptr;
60
+ CIMCArray *ary;
61
+ Data_Get_Struct(self, CIMCEnumeration, ptr);
62
+
63
+ ary = ptr->ft->toArray(ptr, &status);
64
+ if (!status.rc) {
65
+ CIMCData data;
66
+ CIMCCount count = ary->ft->getSize(ary, NULL);
67
+ VALUE array = rb_ary_new2(count);
68
+ CIMCCount idx;
69
+ for (idx = 0; idx < count; ++idx) {
70
+ VALUE value;
71
+ data = ary->ft->getElementAt(ary, idx, NULL);
72
+ value = sfcc_cimdata_to_value(data);
73
+ rb_ary_store(array, idx, value);
74
+ }
75
+ return array;
76
+ }
77
+
78
+ sfcc_rb_raise_if_error(status, "Can't convert enumeration to Array");
79
+ return Qnil;
80
+ }
81
+
82
+
83
+ /**
84
+ * call-seq:
85
+ * enumeration.size -> int
86
+ *
87
+ * returns the size (number of elements) of the enumeration
88
+ *
89
+ */
90
+ static VALUE size(VALUE self)
91
+ {
92
+ CIMCStatus status;
93
+ CIMCEnumeration *ptr;
94
+ CIMCArray *ary;
95
+ Data_Get_Struct(self, CIMCEnumeration, ptr);
96
+
97
+ ary = ptr->ft->toArray(ptr, &status);
98
+ if (!status.rc) {
99
+ CIMCCount count = ary->ft->getSize(ary, NULL);
100
+ return INT2NUM(count);
101
+ }
102
+
103
+ sfcc_rb_raise_if_error(status, "Can't get enumeration size");
104
+ return Qnil;
105
+ }
106
+
107
+
108
+ /**
109
+ * call-seq:
110
+ * enumeration.simple_type -> int
111
+ *
112
+ * returns the element type of the enumeration elements
113
+ *
114
+ */
115
+ static VALUE simple_type(VALUE self)
116
+ {
117
+ CIMCStatus status;
118
+ CIMCEnumeration *ptr;
119
+ CIMCArray *ary;
120
+ Data_Get_Struct(self, CIMCEnumeration, ptr);
121
+
122
+ ary = ptr->ft->toArray(ptr, &status);
123
+ if (!status.rc) {
124
+ CIMCType type = ary->ft->getSimpleType(ary, NULL);
125
+ return INT2NUM(type);
126
+ }
127
+
128
+ sfcc_rb_raise_if_error(status, "Can't get enumeration type");
129
+ return Qnil;
130
+ }
131
+
132
+
47
133
  VALUE
48
- Sfcc_wrap_cim_enumeration(CMPIEnumeration *enm)
134
+ Sfcc_wrap_cim_enumeration(CIMCEnumeration *enm)
49
135
  {
50
- SFCC_INC_REFCOUNT(enm);
51
136
  return Data_Wrap_Struct(cSfccCimEnumeration, NULL, dealloc, enm);
52
137
  }
53
138
 
@@ -60,6 +145,9 @@ void init_cim_enumeration()
60
145
  VALUE klass = rb_define_class_under(cimc, "Enumeration", rb_cObject);
61
146
  cSfccCimEnumeration = klass;
62
147
 
148
+ rb_include_module(klass, rb_const_get(rb_cObject, rb_intern("Enumerable")));
63
149
  rb_define_method(klass, "each", each, 0);
64
- rb_include_module(klass, rb_const_get(rb_cObject, rb_intern("Enumerable")));
150
+ rb_define_method(klass, "to_a", to_a, 0);
151
+ rb_define_method(klass, "size", size, 0);
152
+ rb_define_method(klass, "simple_type", simple_type, 0);
65
153
  }
@@ -7,6 +7,6 @@
7
7
  void init_cim_enumeration();
8
8
 
9
9
  extern VALUE cSfccCimEnumeration;
10
- VALUE Sfcc_wrap_cim_enumeration(CMPIEnumeration *enm);
10
+ VALUE Sfcc_wrap_cim_enumeration(CIMCEnumeration *enm);
11
11
 
12
12
  #endif
@@ -3,9 +3,10 @@
3
3
  #include "cim_object_path.h"
4
4
 
5
5
  static void
6
- dealloc(CMPIInstance *instance)
6
+ dealloc(CIMCInstance *inst)
7
7
  {
8
- SFCC_DEC_REFCOUNT(instance);
8
+ /* fprintf(stderr, "Sfcc_dealloc_cim_instance %p\n", inst); */
9
+ inst->ft->release(inst);
9
10
  }
10
11
 
11
12
  /**
@@ -16,15 +17,14 @@ dealloc(CMPIInstance *instance)
16
17
  */
17
18
  static VALUE property(VALUE self, VALUE name)
18
19
  {
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);
20
+ CIMCInstance *ptr;
21
+ CIMCStatus status;
22
+ CIMCData data;
23
+ Data_Get_Struct(self, CIMCInstance, ptr);
24
+ data = ptr->ft->getProperty(ptr, to_charptr(name), &status);
24
25
  if ( !status.rc )
25
26
  return sfcc_cimdata_to_value(data);
26
-
27
- sfcc_rb_raise_if_error(status, "Can't retrieve property '%s'", StringValuePtr(name));
27
+ sfcc_rb_raise_if_error(status, "Can't retrieve property '%s'", to_charptr(name));
28
28
  return Qnil;
29
29
  }
30
30
 
@@ -40,13 +40,13 @@ static VALUE property(VALUE self, VALUE name)
40
40
  */
41
41
  static VALUE each_property(VALUE self)
42
42
  {
43
- CMPIInstance *ptr = NULL;
44
- CMPIStatus status;
43
+ CIMCInstance *ptr;
44
+ CIMCStatus status;
45
45
  int k=0;
46
46
  int num_props=0;
47
- CMPIString *property_name = NULL;
48
- CMPIData data;
49
- Data_Get_Struct(self, CMPIInstance, ptr);
47
+ CIMCString *property_name = NULL;
48
+ CIMCData data;
49
+ Data_Get_Struct(self, CIMCInstance, ptr);
50
50
 
51
51
  num_props = ptr->ft->getPropertyCount(ptr, &status);
52
52
  if (!status.rc) {
@@ -57,7 +57,7 @@ static VALUE each_property(VALUE self)
57
57
  }
58
58
  else {
59
59
  sfcc_rb_raise_if_error(status, "Can't retrieve property #%d", k);
60
- }
60
+ }
61
61
  if (property_name) CMRelease(property_name);
62
62
  }
63
63
  }
@@ -75,8 +75,8 @@ static VALUE each_property(VALUE self)
75
75
  */
76
76
  static VALUE property_count(VALUE self)
77
77
  {
78
- CMPIInstance *ptr = NULL;
79
- Data_Get_Struct(self, CMPIInstance, ptr);
78
+ CIMCInstance *ptr;
79
+ Data_Get_Struct(self, CIMCInstance, ptr);
80
80
  return UINT2NUM(ptr->ft->getPropertyCount(ptr, NULL));
81
81
  }
82
82
 
@@ -88,11 +88,11 @@ static VALUE property_count(VALUE self)
88
88
  */
89
89
  static VALUE set_property(VALUE self, VALUE name, VALUE value)
90
90
  {
91
- CMPIInstance *ptr = NULL;
92
- CMPIData data;
93
- Data_Get_Struct(self, CMPIInstance, ptr);
91
+ CIMCInstance *ptr;
92
+ CIMCData data;
93
+ Data_Get_Struct(self, CIMCInstance, ptr);
94
94
  data = sfcc_value_to_cimdata(value);
95
- ptr->ft->setProperty(ptr, StringValuePtr(name), &data.value, data.type);
95
+ ptr->ft->setProperty(ptr, to_charptr(name), &data.value, data.type);
96
96
 
97
97
  return value;
98
98
  }
@@ -106,21 +106,18 @@ static VALUE set_property(VALUE self, VALUE name, VALUE value)
106
106
  */
107
107
  static VALUE object_path(VALUE self)
108
108
  {
109
- CMPIInstance *ptr = NULL;
110
- CMPIObjectPath *op;
111
- CMPIObjectPath *newop;
112
- Data_Get_Struct(self, CMPIInstance, ptr);
109
+ CIMCInstance *ptr;
110
+ CIMCObjectPath *op;
111
+ Data_Get_Struct(self, CIMCInstance, ptr);
113
112
  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);
113
+ return Sfcc_wrap_cim_object_path(op);
117
114
  }
118
115
 
119
116
  /**
120
117
  * call-seq:
121
118
  * set_property_filter(property_list, keys)
122
119
  *
123
- * Directs CMPI to ignore any setProperty operations for this
120
+ * Directs CIMC to ignore any setProperty operations for this
124
121
  * instance for any properties not in this list.
125
122
  *
126
123
  * +property_list+ If not nil, the members of the array define one
@@ -132,12 +129,12 @@ static VALUE object_path(VALUE self)
132
129
  */
133
130
  static VALUE set_property_filter(VALUE self, VALUE property_list, VALUE keys)
134
131
  {
135
- CMPIStatus status;
136
- CMPIInstance *ptr = NULL;
132
+ CIMCStatus status;
133
+ CIMCInstance *ptr;
137
134
  char **prop_a;
138
135
  char **key_a;
139
136
 
140
- Data_Get_Struct(self, CMPIInstance, ptr);
137
+ Data_Get_Struct(self, CIMCInstance, ptr);
141
138
 
142
139
  prop_a = sfcc_value_array_to_string_array(property_list);
143
140
  key_a = sfcc_value_array_to_string_array(keys);
@@ -158,16 +155,16 @@ static VALUE set_property_filter(VALUE self, VALUE property_list, VALUE keys)
158
155
  */
159
156
  static VALUE qualifier(VALUE self, VALUE name)
160
157
  {
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);
158
+ CIMCInstance *ptr;
159
+ CIMCStatus status;
160
+ CIMCData data;
161
+ memset(&status, 0, sizeof(CIMCStatus));
162
+ Data_Get_Struct(self, CIMCInstance, ptr);
163
+ data = ptr->ft->getQualifier(ptr, to_charptr(name), &status);
167
164
  if ( !status.rc )
168
165
  return sfcc_cimdata_to_value(data);
169
166
 
170
- sfcc_rb_raise_if_error(status, "Can't retrieve qualifier '%s'", StringValuePtr(name));
167
+ sfcc_rb_raise_if_error(status, "Can't retrieve qualifier '%s'", to_charptr(name));
171
168
  return Qnil;
172
169
  }
173
170
 
@@ -183,13 +180,13 @@ static VALUE qualifier(VALUE self, VALUE name)
183
180
  */
184
181
  static VALUE each_qualifier(VALUE self)
185
182
  {
186
- CMPIInstance *ptr = NULL;
187
- CMPIStatus status;
183
+ CIMCInstance *ptr;
184
+ CIMCStatus status;
188
185
  int k=0;
189
186
  int num_props=0;
190
- CMPIString *qualifier_name = NULL;
191
- CMPIData data;
192
- Data_Get_Struct(self, CMPIInstance, ptr);
187
+ CIMCString *qualifier_name = NULL;
188
+ CIMCData data;
189
+ Data_Get_Struct(self, CIMCInstance, ptr);
193
190
 
194
191
  num_props = ptr->ft->getQualifierCount(ptr, &status);
195
192
  if (!status.rc) {
@@ -200,7 +197,7 @@ static VALUE each_qualifier(VALUE self)
200
197
  }
201
198
  else {
202
199
  sfcc_rb_raise_if_error(status, "Can't retrieve qualifier #%d", k);
203
- }
200
+ }
204
201
  if (qualifier_name) CMRelease(qualifier_name);
205
202
  }
206
203
  }
@@ -218,8 +215,8 @@ static VALUE each_qualifier(VALUE self)
218
215
  */
219
216
  static VALUE qualifier_count(VALUE self)
220
217
  {
221
- CMPIInstance *ptr = NULL;
222
- Data_Get_Struct(self, CMPIInstance, ptr);
218
+ CIMCInstance *ptr;
219
+ Data_Get_Struct(self, CIMCInstance, ptr);
223
220
  return UINT2NUM(ptr->ft->getQualifierCount(ptr, NULL));
224
221
  }
225
222
 
@@ -231,17 +228,17 @@ static VALUE qualifier_count(VALUE self)
231
228
  */
232
229
  static VALUE property_qualifier(VALUE self, VALUE property_name, VALUE qualifier_name)
233
230
  {
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);
231
+ CIMCInstance *ptr;
232
+ CIMCStatus status;
233
+ CIMCData data;
234
+ memset(&status, 0, sizeof(CIMCStatus));
235
+ Data_Get_Struct(self, CIMCInstance, ptr);
236
+ data = ptr->ft->getPropertyQualifier(ptr, to_charptr(property_name),
237
+ to_charptr(qualifier_name), &status);
241
238
  if ( !status.rc )
242
239
  return sfcc_cimdata_to_value(data);
243
240
 
244
- sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier '%s'", StringValuePtr(qualifier_name));
241
+ sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier '%s'", to_charptr(qualifier_name));
245
242
  return Qnil;
246
243
  }
247
244
 
@@ -257,24 +254,24 @@ static VALUE property_qualifier(VALUE self, VALUE property_name, VALUE qualifier
257
254
  */
258
255
  static VALUE each_property_qualifier(VALUE self, VALUE property_name)
259
256
  {
260
- CMPIInstance *ptr = NULL;
261
- CMPIStatus status;
257
+ CIMCInstance *ptr;
258
+ CIMCStatus status;
262
259
  int k=0;
263
260
  int num_props=0;
264
- CMPIString *property_qualifier_name = NULL;
265
- CMPIData data;
266
- Data_Get_Struct(self, CMPIInstance, ptr);
261
+ CIMCString *property_qualifier_name = NULL;
262
+ CIMCData data;
263
+ Data_Get_Struct(self, CIMCInstance, ptr);
267
264
 
268
- num_props = ptr->ft->getPropertyQualifierCount(ptr, StringValuePtr(property_name), &status);
265
+ num_props = ptr->ft->getPropertyQualifierCount(ptr, to_charptr(property_name), &status);
269
266
  if (!status.rc) {
270
267
  for (; k < num_props; ++k) {
271
- data = ptr->ft->getPropertyQualifierAt(ptr, StringValuePtr(property_name), k, &property_qualifier_name, &status);
268
+ data = ptr->ft->getPropertyQualifierAt(ptr, to_charptr(property_name), k, &property_qualifier_name, &status);
272
269
  if (!status.rc) {
273
270
  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
271
  }
275
272
  else {
276
273
  sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier #%d", k);
277
- }
274
+ }
278
275
  if (property_qualifier_name) CMRelease(property_qualifier_name);
279
276
  }
280
277
  }
@@ -292,9 +289,9 @@ static VALUE each_property_qualifier(VALUE self, VALUE property_name)
292
289
  */
293
290
  static VALUE property_qualifier_count(VALUE self, VALUE property_name)
294
291
  {
295
- CMPIInstance *ptr = NULL;
296
- Data_Get_Struct(self, CMPIInstance, ptr);
297
- return UINT2NUM(ptr->ft->getPropertyQualifierCount(ptr, StringValuePtr(property_name), NULL));
292
+ CIMCInstance *ptr;
293
+ Data_Get_Struct(self, CIMCInstance, ptr);
294
+ return UINT2NUM(ptr->ft->getPropertyQualifierCount(ptr, to_charptr(property_name), NULL));
298
295
  }
299
296
 
300
297
  /**
@@ -306,26 +303,22 @@ static VALUE property_qualifier_count(VALUE self, VALUE property_name)
306
303
  */
307
304
  static VALUE new(VALUE klass, VALUE object_path)
308
305
  {
309
- CMPIStatus status;
310
- CMPIInstance *ptr;
311
- CMPIInstance *newins;
312
- CMPIObjectPath *op;
306
+ CIMCStatus status;
307
+ CIMCInstance *ptr;
308
+ CIMCObjectPath *op;
313
309
 
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);
310
+ Data_Get_Struct(object_path, CIMCObjectPath, op);
311
+ ptr = cimcEnv->ft->newInstance(cimcEnv, op, &status);
318
312
 
319
313
  if (!status.rc)
320
- return Sfcc_wrap_cim_instance(newins);
314
+ return Sfcc_wrap_cim_instance(ptr);
321
315
  sfcc_rb_raise_if_error(status, "Can't create instance");
322
316
  return Qnil;
323
317
  }
324
318
 
325
319
  VALUE
326
- Sfcc_wrap_cim_instance(CMPIInstance *instance)
320
+ Sfcc_wrap_cim_instance(CIMCInstance *instance)
327
321
  {
328
- SFCC_INC_REFCOUNT(instance);
329
322
  return Data_Wrap_Struct(cSfccCimInstance, NULL, dealloc, instance);
330
323
  }
331
324