33 thilo.boehm 1.1 #include "CIMError.h"
34 #include "PropertyAccessor.h"
35
36 PEGASUS_USING_STD;
37
38 PEGASUS_NAMESPACE_BEGIN
39
40 // Required property list.
41
42 static const char* _requiredProperties[] =
43 {
44 "OwningEntity",
45 "MessageID",
46 "Message",
47 "PerceivedSeverity",
48 "ProbableCause",
49 "CIMStatusCode",
50 };
51
52 static const size_t _numRequiredProperties =
53 sizeof(_requiredProperties) / sizeof(_requiredProperties[0]);
54 thilo.boehm 1.1
55 CIMError::CIMError() : _inst("CIM_Error")
56 {
57 _inst.addProperty(CIMProperty(
58 "ErrorType", CIMValue(CIMTYPE_UINT16, false)));
59 _inst.addProperty(CIMProperty(
60 "OtherErrorType", CIMValue(CIMTYPE_STRING, false)));
61 _inst.addProperty(CIMProperty(
62 "OwningEntity", CIMValue(CIMTYPE_STRING, false)));
63 _inst.addProperty(CIMProperty(
64 "MessageID", CIMValue(CIMTYPE_STRING, false)));
65 _inst.addProperty(CIMProperty(
66 "Message", CIMValue(CIMTYPE_STRING, false)));
67 _inst.addProperty(CIMProperty(
68 "MessageArguments", CIMValue(CIMTYPE_STRING, true)));
69 _inst.addProperty(CIMProperty(
70 "PerceivedSeverity", CIMValue(CIMTYPE_UINT16, false)));
71 _inst.addProperty(CIMProperty(
72 "ProbableCause", CIMValue(CIMTYPE_UINT16, false)));
73 _inst.addProperty(CIMProperty(
74 "ProbableCauseDescription", CIMValue(CIMTYPE_STRING, false)));
75 thilo.boehm 1.1 _inst.addProperty(CIMProperty(
76 "RecommendedActions", CIMValue(CIMTYPE_STRING, true)));
77 _inst.addProperty(CIMProperty(
78 "ErrorSource", CIMValue(CIMTYPE_STRING, false)));
79 _inst.addProperty(CIMProperty(
80 "ErrorSourceFormat", CIMValue(CIMTYPE_UINT16, false)));
81 _inst.addProperty(CIMProperty(
82 "OtherErrorSourceFormat", CIMValue(CIMTYPE_STRING, false)));
83 _inst.addProperty(CIMProperty(
84 "CIMStatusCode", CIMValue(CIMTYPE_UINT32, false)));
85 _inst.addProperty(CIMProperty(
86 "CIMStatusCodeDescription", CIMValue(CIMTYPE_STRING, false)));
87 }
88
89 CIMError::CIMError(const String& owningEntity,
90 const String& messageID,
91 const String& message,
92 const PerceivedSeverityEnum& perceivedSeverity,
93 const ProbableCauseEnum& probableCause,
94 const CIMStatusCodeEnum& cimStatusCode)
95 : _inst("CIM_Error")
96 thilo.boehm 1.1 {
97 _inst.addProperty(CIMProperty(
98 "ErrorType", CIMValue(CIMTYPE_UINT16, false)));
99 _inst.addProperty(CIMProperty(
100 "OtherErrorType", CIMValue(CIMTYPE_STRING, false)));
101 _inst.addProperty(CIMProperty(
102 "OwningEntity", CIMValue(owningEntity)));
103 _inst.addProperty(CIMProperty(
104 "MessageID", CIMValue(messageID)));
105 _inst.addProperty(CIMProperty(
106 "Message", CIMValue(message)));
107 _inst.addProperty(CIMProperty(
108 "MessageArguments", CIMValue(CIMTYPE_STRING, true)));
109 _inst.addProperty(CIMProperty(
110 "PerceivedSeverity", CIMValue(Uint16(perceivedSeverity))));
111 _inst.addProperty(CIMProperty(
112 "ProbableCause", CIMValue(Uint16(probableCause))));
113 _inst.addProperty(CIMProperty(
114 "ProbableCauseDescription", CIMValue(CIMTYPE_STRING, false)));
115 _inst.addProperty(CIMProperty(
116 "RecommendedActions", CIMValue(CIMTYPE_STRING, true)));
117 thilo.boehm 1.1 _inst.addProperty(CIMProperty(
118 "ErrorSource", CIMValue(CIMTYPE_STRING, false)));
119 _inst.addProperty(CIMProperty(
120 "ErrorSourceFormat", CIMValue(CIMTYPE_UINT16, false)));
121 _inst.addProperty(CIMProperty(
122 "OtherErrorSourceFormat", CIMValue(CIMTYPE_STRING, false)));
123 _inst.addProperty(CIMProperty(
124 "CIMStatusCode", CIMValue(Uint32(cimStatusCode))));
125 _inst.addProperty(CIMProperty(
126 "CIMStatusCodeDescription", CIMValue(CIMTYPE_STRING, false)));
127 }
128
129 CIMError::CIMError(const CIMError& x) : _inst(x._inst)
130 {
131 }
132
133 CIMError::~CIMError()
134 {
135 }
136
137 bool CIMError::getErrorType(ErrorTypeEnum& value) const
138 thilo.boehm 1.1 {
139 Uint16 t;
140 bool nullStat = Get(_inst, "ErrorType", t);
141 value = ErrorTypeEnum(t);
142 return nullStat;
143 }
144
145 void CIMError::setErrorType(ErrorTypeEnum value, bool null)
146 {
147 Set(_inst, "ErrorType", Uint16(value), null);
148 }
149
150 bool CIMError::getOtherErrorType(String& value) const
151 {
152 return Get(_inst, "OtherErrorType", value);
153 }
154
155 void CIMError::setOtherErrorType(const String& value, bool null)
156 {
157 Set(_inst, "OtherErrorType", value, null);
158 }
159 thilo.boehm 1.1
160 bool CIMError::getOwningEntity(String& value) const
161 {
162 return Get(_inst, "OwningEntity", value);
163 }
164
165 void CIMError::setOwningEntity(const String& value, bool null)
166 {
167 Set(_inst, "OwningEntity", value, null);
168 }
169
170 bool CIMError::getMessageID(String& value) const
171 {
172 return Get(_inst, "MessageID", value);
173 }
174
175 void CIMError::setMessageID(const String& value, bool null)
176 {
177 Set(_inst, "MessageID", value, null);
178 }
179
180 thilo.boehm 1.1 bool CIMError::getMessage(String& value) const
181 {
182 return Get(_inst, "Message", value);
183 }
184
185 void CIMError::setMessage(const String& value, bool null)
186 {
187 Set(_inst, "Message", value, null);
188 }
189
190 bool CIMError::getMessageArguments(Array<String>& value) const
191 {
192 return Get(_inst, "MessageArguments", value);
193 }
194
195 void CIMError::setMessageArguments(const Array<String>& value, bool null)
196 {
197 Set(_inst, "MessageArguments", value, null);
198 }
199
200 bool CIMError::getPerceivedSeverity(
201 thilo.boehm 1.1 PerceivedSeverityEnum& value) const
202 {
203 Uint16 t;
204 bool nullStat = Get(_inst, "PerceivedSeverity", t);
205 value = PerceivedSeverityEnum(t);
206 return nullStat;
207 }
208
209 void CIMError::setPerceivedSeverity(
210 PerceivedSeverityEnum value, bool null)
211 {
212 Set(_inst, "PerceivedSeverity", Uint16(value), null);
213 }
214
215 bool CIMError::getProbableCause(ProbableCauseEnum& value) const
216 {
217 Uint16 t;
218 bool nullStat = Get(_inst, "ProbableCause", t);
219 value = ProbableCauseEnum(t);
220 return nullStat;
221 }
222 thilo.boehm 1.1
223 void CIMError::setProbableCause(ProbableCauseEnum value, bool null)
224 {
225 Set(_inst, "ProbableCause", (Uint16)value, null);
226 }
227
228 bool CIMError::getProbableCauseDescription(String& value) const
229 {
230 return Get(_inst, "ProbableCauseDescription", value);
231 }
232
233 void CIMError::setProbableCauseDescription(const String& value, bool null)
234 {
235 Set(_inst, "ProbableCauseDescription", value, null);
236 }
237
238 bool CIMError::getRecommendedActions(Array<String>& value) const
239 {
240 return Get(_inst, "RecommendedActions", value);
241 }
242
243 thilo.boehm 1.1 void CIMError::setRecommendedActions(const Array<String>& value, bool null)
244 {
245 Set(_inst, "RecommendedActions", value, null);
246 }
247
248 bool CIMError::getErrorSource(String& value) const
249 {
250 return Get(_inst, "ErrorSource", value);
251 }
252
253 void CIMError::setErrorSource(const String& value, bool null)
254 {
255 Set(_inst, "ErrorSource", value, null);
256 }
257
258 bool CIMError::getErrorSourceFormat(
259 ErrorSourceFormatEnum& value) const
260 {
261 Uint16 t;
262 bool nullStat = Get(_inst, "ErrorSourceFormat", t);
263 value = ErrorSourceFormatEnum(t);
264 thilo.boehm 1.1 return nullStat;
265 }
266
267 void CIMError::setErrorSourceFormat(ErrorSourceFormatEnum value, bool null)
268 {
269 Set(_inst, "ErrorSourceFormat", Uint16(value), null);
270 }
271
272 bool CIMError::getOtherErrorSourceFormat(String& value) const
273 {
274 return Get(_inst, "OtherErrorSourceFormat", value);
275 }
276
277 void CIMError::setOtherErrorSourceFormat(const String& value, bool null)
278 {
279 Set(_inst, "OtherErrorSourceFormat", value, null);
280 }
281
282 bool CIMError::getCIMStatusCode(CIMStatusCodeEnum& value) const
283 {
284 Uint32 t;
285 thilo.boehm 1.1 bool nullStat = Get(_inst, "CIMStatusCode", t);
286 value = CIMStatusCodeEnum(t);
287 return nullStat;
288 }
289
290 void CIMError::setCIMStatusCode(CIMStatusCodeEnum value, bool null)
291 {
292 Set(_inst, "CIMStatusCode", Uint32(value), null);
293 }
294
295 bool CIMError::getCIMStatusCodeDescription(String& value) const
296 {
297 return Get(_inst, "CIMStatusCodeDescription", value);
298 }
299
300 void CIMError::setCIMStatusCodeDescription(const String& value, bool null)
301 {
302 Set(_inst, "CIMStatusCodeDescription", value, null);
303 }
304
305 const CIMInstance& CIMError::getInstance() const
306 thilo.boehm 1.1 {
307 return _inst;
308 }
309
310 template<class T>
311 void _Check(const String& name, CIMConstProperty& p, T* tag)
312 {
313 if (p.getName() == name)
314 {
315 if (IsArray(tag) != p.isArray() || GetType(tag) != p.getType())
316 throw CIMException(CIM_ERR_TYPE_MISMATCH, name);
317 }
318 }
319
320 void CIMError::setInstance(const CIMInstance& instance)
321 {
322 for (Uint32 i = 0; i < instance.getPropertyCount(); i++)
323 {
324 CIMConstProperty p = instance.getProperty(i);
325
326 _Check("ErrorType", p, (Uint16*)0);
327 thilo.boehm 1.1 _Check("OtherErrorType", p, (String*)0);
328 _Check("OwningEntity", p, (String*)0);
329 _Check("MessageID", p, (String*)0);
330 _Check("Message", p, (String*)0);
331 _Check("MessageArguments", p, (Array<String>*)0);
332 _Check("PerceivedSeverity", p, (Uint16*)0);
333 _Check("ProbableCause", p, (Uint16*)0);
334 _Check("ProbableCauseDescription", p, (String*)0);
335 _Check("RecommendedActions", p, (Array<String>*)0);
336 _Check("ErrorSource", p, (String*)0);
337 _Check("ErrorSourceFormat", p, (Uint16*)0);
338 _Check("OtherErrorSourceFormat", p, (String*)0);
339 _Check("CIMStatusCode", p, (Uint32*)0);
340 _Check("CIMStatusCodeDescription", p, (String*)0);
341 }
342
343 // Verify that the instance contains all of the required properties.
344
345 for (Uint32 i = 0; i < _numRequiredProperties; i++)
346 {
347 // Does inst have this property?
348 thilo.boehm 1.1
349 Uint32 pos = instance.findProperty(_requiredProperties[i]);
350
351 if (pos == PEG_NOT_FOUND)
352 {
353 char buffer[80];
354 sprintf(buffer, "required property does not exist: %s",
355 _requiredProperties[i]);
356 throw CIMException(CIM_ERR_NO_SUCH_PROPERTY, buffer);
357 }
358 // is required property non-null?
359 CIMConstProperty p = instance.getProperty(pos);
360 CIMValue v = p.getValue();
361 if (v.isNull())
362 {
363 char buffer[80];
364 sprintf(buffer, "required property MUST NOT be Null: %s",
365 _requiredProperties[i]);
366 throw CIMException(CIM_ERR_FAILED, buffer);
367 }
368 }
369 thilo.boehm 1.1 _inst = instance;
370 }
371
372 void CIMError::print() const
373 {
374 Buffer buf;
375 MofWriter::appendInstanceElement(buf, _inst);
376 printf("%.*s\n", int(buf.size()), buf.getData());
377 }
378
379 PEGASUS_NAMESPACE_END
|