version 1.1.2.2, 2007/10/02 14:28:38
|
version 1.1.2.7, 2007/10/03 00:14:06
|
|
|
#include <cassert> | #include <cassert> |
#include "MetaRepository.h" | #include "MetaRepository.h" |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
|
#include "MetaTypes.h" |
| |
#define TEST_META_REPOSITORY |
PEGASUS_NAMESPACE_BEGIN |
|
|
#if defined(TEST_META_REPOSITORY) |
|
# include "root_cimv2_namespace.h" |
|
# include "root_PG_Internal_namespace.h" |
|
# include "root_PG_InterOp_namespace.h" |
|
#endif |
|
|
|
PEGASUS_NAMESPACE_BEGIN |
|
|
|
static const size_t _MAX_NAMESPACES = 32; |
|
static const MetaNameSpace* _nameSpaces[_MAX_NAMESPACES]; |
|
static size_t _nameSpacesSize = 0; |
|
|
|
static const size_t _MAX_FEATURES = 1024; |
|
static const size_t _MAX_QUALIFIERS = 1024; |
|
|
|
#if defined(TEST_META_REPOSITORY) |
|
static void _init() |
|
{ |
|
if (_nameSpacesSize == 0) |
|
{ |
|
MetaRepository::addNameSpace(&root_PG_InterOp_namespace); |
|
MetaRepository::addNameSpace(&root_cimv2_namespace); |
|
MetaRepository::addNameSpace(&root_PG_Internal_namespace); |
|
} |
|
} |
|
#endif |
|
|
|
static bool _eqi(const char* s1, const char* s2) |
|
{ |
|
return System::strcasecmp(s1, s2) == 0; |
|
} |
|
|
|
//============================================================================== |
|
// |
|
// Local definitions: |
|
// |
|
//============================================================================== |
|
|
|
class Str |
|
{ |
|
public: |
|
Str(const String& s) : _cstr(s.getCString()) { } |
|
Str(const CIMName& n) : _cstr(n.getString().getCString()) { } |
|
Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { } |
|
Str(const Exception& e) : _cstr(e.getMessage().getCString()) { } |
|
Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { } |
|
Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { } |
|
const char* operator*() const { return (const char*)_cstr; } |
|
operator const char*() const { return (const char*)_cstr; } |
|
private: |
|
CString _cstr; |
|
}; |
|
|
|
PEGASUS_FORMAT(2, 3) |
|
static void _throw(CIMStatusCode code, const char* format, ...) |
|
{ |
|
char buffer[4096]; |
|
|
|
va_list ap; |
|
va_start(ap, format); |
|
vsprintf(buffer, format, ap); |
|
va_end(ap); |
|
throw CIMException(code, buffer); |
|
} |
|
|
|
static const MetaNameSpace* _findNameSpace(const char* name) |
|
{ |
|
for (size_t i = 0; i < _nameSpacesSize; i++) |
|
{ |
|
if (_eqi(_nameSpaces[i]->name, name)) |
|
return _nameSpaces[i]; |
|
} |
|
|
|
// Not found! |
|
return 0; |
|
} |
|
|
|
static bool _isSubClass(const MetaClass* super, const MetaClass* sub) |
|
{ |
|
if (!super) |
|
return true; |
|
|
|
for (MetaClass* p = sub->super; p; p = p->super) |
|
{ |
|
if (p == super) |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
static inline bool _isDirectSubClass( |
|
const MetaClass* super, |
|
const MetaClass* sub) |
|
{ |
|
return sub->super == super; |
|
} |
|
|
|
static const MetaClass* _findClass( |
|
const MetaNameSpace* ns, |
|
const char* name) |
|
{ |
|
for (size_t i = 0; ns->classes[i]; i++) |
|
{ |
|
const MetaClass* sc = ns->classes[i]; |
|
|
|
if (_eqi(sc->name, name)) |
|
return sc; |
|
} |
|
|
|
// Not found! |
|
return 0; |
|
} |
|
|
|
static inline void _readBoolean(const char*& value, Boolean& x) |
|
{ |
|
unsigned const char* p = (unsigned const char*)value; |
|
x = Boolean(p[0]); |
|
value++; |
|
} |
|
|
|
static inline void _readUint8(const char*& value, Uint8& x) |
|
{ |
|
unsigned const char* p = (unsigned const char*)value; |
|
x = Uint8(p[0]); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readSint8(const char*& value, Sint8& x) |
|
{ |
|
_readUint8(value, *((Uint8*)&x)); |
|
} |
|
|
|
static inline void _readUint16(const char*& value, Uint16& x) |
|
{ |
|
unsigned const char* p = (unsigned const char*)value; |
|
Uint16 x0 = Uint16(p[0]) << 8; |
|
Uint16 x1 = Uint16(p[1]) << 0; |
|
x = Uint16(x0 | x1); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readSint16(const char*& value, Sint16& x) |
|
{ |
|
_readUint16(value, *((Uint16*)&x)); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readUint32(const char*& value, Uint32& x) |
|
{ |
|
unsigned const char* p = (unsigned const char*)value; |
|
Uint32 x0 = Uint32(p[0]) << 24; |
|
Uint32 x1 = Uint32(p[1]) << 16; |
|
Uint32 x2 = Uint32(p[0]) << 8; |
|
Uint32 x3 = Uint32(p[1]) << 0; |
|
x = Uint32(x0 | x1 | x2 | x3); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readSint32(const char*& value, Sint32& x) |
|
{ |
|
_readUint32(value, *((Uint32*)&x)); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readUint64(const char*& value, Uint64& x) |
|
{ |
|
unsigned const char* p = (unsigned const char*)value; |
|
Uint64 x0 = Uint64(p[0]) << 56; |
|
Uint64 x1 = Uint64(p[1]) << 48; |
|
Uint64 x2 = Uint64(p[2]) << 40; |
|
Uint64 x3 = Uint64(p[3]) << 32; |
|
Uint64 x4 = Uint64(p[4]) << 24; |
|
Uint64 x5 = Uint64(p[5]) << 16; |
|
Uint64 x6 = Uint64(p[6]) << 8; |
|
Uint64 x7 = Uint64(p[7]) << 0; |
|
x = Uint64(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readSint64(const char*& value, Sint64& x) |
|
{ |
|
_readUint64(value, *((Uint64*)&x)); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readReal32(const char*& value, Real32& x) |
|
{ |
|
_readUint32(value, *((Uint32*)&x)); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readReal64(const char*& value, Real64& x) |
|
{ |
|
_readUint64(value, *((Uint64*)&x)); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readChar16(const char*& value, Char16& x) |
|
{ |
|
_readUint16(value, *((Uint16*)&x)); |
|
value += sizeof(x); |
|
} |
|
|
|
static inline void _readString(const char*& value, String& x) |
|
{ |
|
size_t n = strlen(value); |
|
x.assign(value, n); |
|
value += n + 1; |
|
} |
|
|
|
static inline void _readDateTime(const char*& value, CIMDateTime& x) |
|
{ |
|
size_t n = strlen(value); |
|
x.set(value); |
|
value += n + 1; |
|
} |
|
|
|
static int _makeValue( |
|
CIMValue& cv, |
|
Uint16 type, |
|
Sint16 subscript, |
|
const char* value) |
|
{ |
|
// If null value: |
|
|
|
if (value == 0) |
|
{ |
|
if (subscript == -1) |
|
cv.setNullValue(CIMType(type), false); |
|
else |
|
cv.setNullValue(CIMType(type), true, subscript); |
|
|
|
return 0; |
|
} |
|
|
|
// If scalar, else array: |
|
|
|
if (subscript == -1) |
|
{ |
|
switch (CIMType(type)) |
|
{ |
|
case CIMTYPE_BOOLEAN: |
|
{ |
|
Boolean x; |
|
_readBoolean(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT8: |
|
{ |
|
Uint8 x; |
|
_readUint8(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT8: |
|
{ |
|
Sint8 x; |
|
_readSint8(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT16: |
|
{ |
|
Uint16 x; |
|
_readUint16(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT16: |
|
{ |
|
Sint16 x; |
|
_readSint16(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT32: |
|
{ |
|
Uint32 x; |
|
_readUint32(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT32: |
|
{ |
|
Sint32 x; |
|
_readSint32(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT64: |
|
{ |
|
Uint64 x; |
|
_readUint64(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT64: |
|
{ |
|
Sint64 x; |
|
_readSint64(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_REAL32: |
|
{ |
|
Real32 x; |
|
_readReal32(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_REAL64: |
|
{ |
|
Real64 x; |
|
_readReal64(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_CHAR16: |
|
{ |
|
Char16 x; |
|
_readChar16(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_STRING: |
|
{ |
|
String x; |
|
_readString(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
case CIMTYPE_DATETIME: |
|
{ |
|
CIMDateTime x; |
|
_readDateTime(value, x); |
|
cv.set(x); |
|
return 0; |
|
} |
|
|
|
default: |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
} |
|
else |
|
{ |
|
// Read array size: |
|
|
|
Uint16 size; |
|
_readUint16(value, size); |
|
|
|
// Read array elements: |
|
|
|
switch (CIMType(type)) |
|
{ |
|
case CIMTYPE_BOOLEAN: |
|
{ |
|
Array<Boolean> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Boolean x; |
|
_readBoolean(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT8: |
|
{ |
|
Array<Uint8> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Uint8 x; |
|
_readUint8(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT8: |
|
{ |
|
Array<Sint8> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Sint8 x; |
|
_readSint8(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT16: |
|
{ |
|
Array<Uint16> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Uint16 x; |
|
_readUint16(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT16: |
|
{ |
|
Array<Sint16> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Sint16 x; |
|
_readSint16(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT32: |
|
{ |
|
Array<Uint32> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Uint32 x; |
|
_readUint32(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT32: |
|
{ |
|
Array<Sint32> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Sint32 x; |
|
_readSint32(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_UINT64: |
|
{ |
|
Array<Uint64> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Uint64 x; |
|
_readUint64(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_SINT64: |
|
{ |
|
Array<Sint64> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Sint64 x; |
|
_readSint64(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_REAL32: |
|
{ |
|
Array<Real32> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Real32 x; |
|
_readReal32(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_REAL64: |
|
{ |
|
Array<Real64> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Real64 x; |
|
_readReal64(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_CHAR16: |
|
{ |
|
Array<Char16> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
Char16 x; |
|
_readChar16(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_STRING: |
|
{ |
|
Array<String> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
String x; |
|
_readString(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
case CIMTYPE_DATETIME: |
|
{ |
|
Array<CIMDateTime> a; |
|
|
|
for (Uint16 i = 0; i < size; i++) |
|
{ |
|
CIMDateTime x; |
|
_readDateTime(value, x); |
|
a.append(x); |
|
} |
|
|
|
cv.set(a); |
|
return 0; |
|
} |
|
|
|
default: |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
} |
|
|
|
// Unreachable! |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
struct FeatureInfo |
|
{ |
|
const MetaFeature* sf; |
|
const MetaClass* sc; |
|
}; |
|
|
|
static int _mergeFeatures( |
|
const MetaClass* sc, |
|
FeatureInfo features[_MAX_FEATURES], |
|
size_t& numFeatures) |
|
{ |
|
if (sc->super) |
|
{ |
|
if (_mergeFeatures(sc->super, features, numFeatures) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
} |
|
|
|
// Process all features of this class: |
|
|
|
for (size_t i = 0; sc->features[i]; i++) |
|
{ |
|
const MetaFeature* sf = sc->features[i]; |
|
|
|
// Override feature if defined by ancestor class: |
|
|
|
bool found = false; |
|
|
|
for (size_t j = 0; j < numFeatures; j++) |
|
{ |
|
const MetaFeature* tmp = features[j].sf; |
|
|
|
if (_eqi(sf->name, tmp->name)) |
|
{ |
|
features[j].sf = sf; |
|
features[j].sc = sc; |
|
found = true; |
|
break; |
|
} |
|
} |
|
|
|
// Add new feature if not not defined by ancestor class: |
|
|
|
if (!found) |
|
{ |
|
if (numFeatures == _MAX_FEATURES) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
features[numFeatures].sf = sf; |
|
features[numFeatures].sc = sc; |
|
numFeatures++; |
|
} |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
struct QualifierInfo |
|
{ |
|
const char* qualifier; |
|
const MetaClass* sc; |
|
}; |
|
|
|
static const MetaFeature* _findFeature( |
|
const MetaClass* sc, |
|
const char* name) |
|
{ |
|
for (size_t i = 0; sc->features[i]; i++) |
|
{ |
|
const MetaFeature* sf = sc->features[i]; |
|
|
|
if (_eqi(sf->name, name)) |
|
return sf; |
|
} |
|
|
|
// Not found! |
|
return 0; |
|
} |
|
|
|
static const MetaFeature* _findParameter( |
|
const MetaMethod* sm, |
|
const char* name) |
|
{ |
|
for (size_t i = 0; sm->parameters[i]; i++) |
|
{ |
|
const MetaFeature* sf = sm->parameters[i]; |
|
|
|
if (_eqi(sm->name, name)) |
|
return sf; |
|
} |
|
|
|
// Not found! |
|
return 0; |
|
} |
|
|
|
static int _mergeQualifiers( |
|
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const char* featureName, |
|
const char* parameterName, |
|
bool depth, |
|
QualifierInfo qualifiers[_MAX_QUALIFIERS], |
|
size_t& numQualifiers) |
|
{ |
|
// Merge super-class qualifiers: |
|
|
|
if (sc->super) |
|
{ |
|
_mergeQualifiers(ns, sc->super, featureName, parameterName, depth + 1, |
|
qualifiers, numQualifiers); |
|
} |
|
|
|
const char** quals = 0; |
|
|
|
// Find qualifiers of the given object: |
|
|
|
if (!featureName && !parameterName) |
|
{ |
|
// Case 1: get class qualifiers: |
|
quals = sc->qualifiers; |
|
} |
|
else if (featureName && !parameterName) |
|
{ |
|
// Case 2: get feature qualifiers: |
|
|
|
const MetaFeature* sf = _findFeature(sc, featureName); |
|
|
|
if (sf) |
|
quals = sf->qualifiers; |
|
} |
|
else if (featureName && parameterName) |
|
{ |
|
// Case 3: get parameter qualifiers: |
|
|
|
const MetaFeature* sf = _findFeature(sc, featureName); |
|
|
|
if (sf && (sf->flags & META_FLAG_METHOD)) |
|
{ |
|
const MetaMethod* sm = (const MetaMethod*)sf; |
|
const MetaFeature* p = _findParameter(sm, parameterName); |
|
|
|
if (p) |
|
quals = p->qualifiers; |
|
} |
|
} |
|
|
|
// Merge quals into the qualifiers array: |
|
|
|
if (!quals) |
|
return 0; |
|
|
|
for (size_t i = 0; quals[i]; i++) |
|
{ |
|
const char* qi = quals[i]; |
|
|
|
// Override existing qualifier if any: |
|
|
|
bool found = false; |
|
|
|
for (size_t j = 0; j < numQualifiers; j++) |
|
{ |
|
const char* qj = qualifiers[j].qualifier; |
|
|
|
if (qi[0] == qj[0]) |
|
{ |
|
qualifiers[j].qualifier = qi; |
|
qualifiers[j].sc = sc; |
|
found = true; |
|
break; |
|
} |
|
} |
|
|
|
// Inject this qualifier not found: |
|
|
|
if (!found) |
|
{ |
|
MetaQualifierDecl* qd = ns->qualifiers[qi[0]]; |
|
|
|
if (depth == 0 || !(qd->flavor & META_FLAVOR_RESTRICTED)) |
|
{ |
|
if (numQualifiers == _MAX_QUALIFIERS) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
qualifiers[numQualifiers].qualifier = qi; |
|
qualifiers[numQualifiers].sc = sc; |
|
numQualifiers++; |
|
} |
|
} |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
template<class C> |
|
static int _addQualifiers( |
|
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const char* featureName, |
|
const char* parameterName, |
|
C& c) |
|
{ |
|
QualifierInfo qualifiers[_MAX_QUALIFIERS]; |
|
size_t numQualifiers = 0; |
|
|
|
if (_mergeQualifiers( |
|
ns, sc, featureName, parameterName, 0, qualifiers, numQualifiers) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
// Add qualifiers to container: |
|
|
|
for (size_t i = 0; i < numQualifiers; i++) |
|
{ |
|
const char* q = qualifiers[i].qualifier; |
|
|
|
// Get qualifier id: |
|
|
|
Uint8 qid = Uint8(q[0]); |
|
|
|
// Get qualifier declaration: |
|
|
|
MetaQualifierDecl* qd = ns->qualifiers[qid]; |
|
|
|
// Make CIMValue: |
|
|
|
CIMValue cv; |
|
|
|
if (_makeValue(cv, qd->type, qd->subscript, q + 1) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
// Add qualifier: |
|
|
|
c.addQualifier(CIMQualifier(qd->name, cv)); |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
static int _addProperty( |
|
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const MetaProperty* sp, |
|
const char* classOrigin, |
|
bool propagated, |
|
CIMClass& cc) |
|
{ |
|
// Make CIMvalue: |
|
|
|
CIMValue cv; |
|
|
|
if (_makeValue(cv, sp->type, sp->subscript, sp->value) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
// Create property: |
|
|
|
CIMProperty cp(sp->name, cv); |
|
cp.setClassOrigin(classOrigin); |
|
cp.setPropagated(propagated); |
|
|
|
// Add qualifiers: |
|
|
|
if (_addQualifiers(ns, sc, sp->name, 0, cp) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
// Add to class: |
|
|
|
cc.addProperty(cp); |
|
return 0; |
|
} |
|
|
|
static int _addReference( |
|
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const MetaReference* sr, |
|
const char* classOrigin, |
|
bool propagated, |
|
CIMClass& cc) |
|
{ |
|
// Set isArray and arraySize: |
|
|
|
Boolean isArray; |
|
Uint32 arraySize; |
|
|
|
if (sr->subscript == -1) |
|
{ |
|
isArray = false; |
|
arraySize = 0; |
|
} |
|
else |
|
{ |
|
isArray = true; |
|
arraySize = sr->subscript; |
|
} |
|
|
|
// Set referenceClassName: |
|
|
|
CIMName rcn = sr->ref->name; |
|
|
|
// Create value: |
|
|
|
CIMValue cv(CIMTYPE_REFERENCE, isArray, arraySize); |
|
|
|
// Create property: |
|
|
|
CIMProperty cp(sr->name, cv, arraySize, rcn, classOrigin, propagated); |
|
|
|
// Add qualifiers: |
|
|
|
if (_addQualifiers(ns, sc, sr->name, 0, cp) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
// Add to class: |
|
|
|
cc.addProperty(cp); |
|
return 0; |
|
} |
|
|
|
static int _addPropertyParameter( |
|
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const MetaMethod* sm, |
|
const MetaProperty* sp, |
|
CIMMethod& cm) |
|
{ |
|
// Create property: |
|
|
|
bool isArray; |
|
Uint32 arraySize; |
|
|
|
if (sp->subscript == -1) |
|
{ |
|
isArray = false; |
|
arraySize = 0; |
|
} |
|
else |
|
{ |
|
isArray = true; |
|
arraySize = Uint32(sp->subscript); |
|
} |
|
|
|
CIMParameter cp(sp->name, CIMType(sp->type), isArray, arraySize); |
|
|
|
// Add qualifiers: |
|
|
|
if (_addQualifiers(ns, sc, sm->name, sp->name, cm) != 0) |
|
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
|
|
// Add to method: |
|
|
|
cm.addParameter(cp); |
|
return 0; |
|
} |
|
|
|
static int _addReferenceParameter( |
|
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const MetaMethod* sm, |
|
const MetaReference* sr, |
|
CIMMethod& cm) |
|
{ |
|
// Create property: |
|
|
|
bool isArray; |
|
Uint32 arraySize; |
|
|
|
if (sr->subscript == -1) |
|
{ |
|
isArray = false; |
|
arraySize = 0; |
|
} |
|
else |
|
{ |
|
isArray = true; |
|
arraySize = Uint32(sr->subscript); |
|
} |
|
| |
CIMName rcn = sr->ref->name; |
static const size_t _MAX_NAMESPACES = 32; |
CIMParameter cp(sr->name, CIMTYPE_REFERENCE, isArray, arraySize, rcn); |
static const MetaNameSpace* _nameSpaces[_MAX_NAMESPACES]; |
|
static size_t _nameSpacesSize = 0; |
| |
// Add qualifiers: |
static const size_t _MAX_FEATURES = 1024; |
|
static const size_t _MAX_QUALIFIERS = 1024; |
| |
if (_addQualifiers(ns, sc, sm->name, sr->name, cm) != 0) |
//============================================================================== |
{ |
// |
printf("T[%u]\n", __LINE__); |
// Local definitions: |
return -1; |
// |
} |
//============================================================================== |
| |
// Add to method: |
PEGASUS_FORMAT(2, 3) |
|
static void _throw(CIMStatusCode code, const char* format, ...) |
|
{ |
|
char buffer[4096]; |
| |
cm.addParameter(cp); |
va_list ap; |
return 0; |
va_start(ap, format); |
|
vsprintf(buffer, format, ap); |
|
va_end(ap); |
|
throw CIMException(code, buffer); |
} | } |
| |
static int _addMethod( |
static bool _eqi(const char* s1, const char* s2) |
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
const MetaMethod* sm, |
|
const char* classOrigin, |
|
bool propagated, |
|
CIMClass& cc) |
|
{ | { |
// Create method: |
return System::strcasecmp(s1, s2) == 0; |
|
} |
CIMMethod cm(sm->name, CIMType(sm->type)); |
|
cm.setClassOrigin(classOrigin); |
|
cm.setPropagated(propagated); |
|
|
|
// Add parameters: |
|
| |
for (size_t i = 0; sm->parameters[i]; i++) |
class Str |
{ | { |
MetaFeature* sf = sm->parameters[i]; |
public: |
|
Str(const String& s) : _cstr(s.getCString()) { } |
|
Str(const CIMName& n) : _cstr(n.getString().getCString()) { } |
|
Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { } |
|
Str(const Exception& e) : _cstr(e.getMessage().getCString()) { } |
|
Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { } |
|
Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { } |
|
const char* operator*() const { return (const char*)_cstr; } |
|
operator const char*() const { return (const char*)_cstr; } |
|
private: |
|
CString _cstr; |
|
}; |
| |
if (sf->flags & META_FLAG_PROPERTY) |
static const MetaNameSpace* _findNameSpace(const char* name) |
{ |
|
MetaProperty* sp = (MetaProperty*)sf; |
|
_addPropertyParameter(ns, sc, sm, sp, cm); |
|
} |
|
else if (sf->flags & META_FLAG_REFERENCE) |
|
{ | { |
MetaReference* sr = (MetaReference*)sf; |
for (size_t i = 0; i < _nameSpacesSize; i++) |
_addReferenceParameter(ns, sc, sm, sr, cm); |
|
} |
|
} |
|
|
|
// Add qualifiers: |
|
|
|
if (_addQualifiers(ns, sc, sm->name, 0, cm) != 0) |
|
{ | { |
printf("T[%u]\n", __LINE__); |
if (_eqi(_nameSpaces[i]->name, name)) |
return -1; |
return _nameSpaces[i]; |
} | } |
| |
// Add to class: |
// Not found! |
|
|
cc.addMethod(cm); |
|
return 0; | return 0; |
} | } |
| |
static int _addFeatures( |
static bool _isSubClass(const MetaClass* super, const MetaClass* sub) |
const MetaNameSpace* ns, |
|
const MetaClass* sc, |
|
CIMClass& cc) |
|
{ | { |
|
if (!super) |
|
return true; |
| |
// Merge features from all inheritance levels into a single array: |
for (MetaClass* p = sub->super; p; p = p->super) |
|
|
FeatureInfo features[_MAX_FEATURES]; |
|
size_t numFeatures = 0; |
|
|
|
if (_mergeFeatures(sc, features, numFeatures) != 0) |
|
{ | { |
printf("T[%u]\n", __LINE__); |
if (p == super) |
return -1; |
return true; |
} | } |
| |
// For each feature: |
return false; |
|
} |
| |
for (size_t i = 0; i < numFeatures; i++) |
static inline bool _isDirectSubClass( |
|
const MetaClass* super, |
|
const MetaClass* sub) |
{ | { |
const FeatureInfo& fi = features[i]; |
return sub->super == super; |
|
} |
// Set propagated flag: |
|
|
|
bool propagated = fi.sc != sc; |
|
|
|
// Set classOrigin: |
|
|
|
const char* classOrigin = fi.sc->name; |
|
|
|
// Add the feature: |
|
|
|
const MetaFeature* sf = fi.sf; |
|
| |
if (sf->flags & META_FLAG_PROPERTY) |
static const MetaClass* _findClass( |
|
const MetaNameSpace* ns, |
|
const char* name) |
{ | { |
MetaProperty* sp = (MetaProperty*)sf; |
for (size_t i = 0; ns->classes[i]; i++) |
|
|
if (_addProperty(ns, sc, sp, classOrigin, propagated, cc) != 0) |
|
{ | { |
printf("T[%u]\n", __LINE__); |
const MetaClass* mc = ns->classes[i]; |
return -1; |
|
|
if (_eqi(mc->name, name)) |
|
return mc; |
} | } |
|
|
|
// Not found! |
|
return 0; |
} | } |
else if (sf->flags & META_FLAG_REFERENCE) |
|
{ |
|
MetaReference* sr = (MetaReference*)sf; |
|
| |
if (_addReference(ns, sc, sr, classOrigin, propagated, cc) != 0) |
static const MetaQualifierDecl* _findQualifierDecl( |
|
const MetaNameSpace* ns, |
|
const char* name) |
{ | { |
printf("T[%u]\n", __LINE__); |
for (size_t i = 0; ns->classes[i]; i++) |
return -1; |
|
} |
|
} |
|
else if (sf->flags & META_FLAG_METHOD) |
|
{ | { |
MetaMethod* sm = (MetaMethod*)sf; |
const MetaQualifierDecl* mqd = ns->qualifiers[i]; |
| |
if (_addMethod(ns, sc, sm, classOrigin, propagated, cc) != 0) |
if (_eqi(mqd->name, name)) |
{ |
return mqd; |
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} |
|
} |
|
} | } |
| |
|
// Not found! |
return 0; | return 0; |
} | } |
| |
static int _makeClass( |
static char** _makePropertyList(const CIMPropertyList& propertyList) |
const MetaNameSpace* ns, |
|
CIMClass& cc, |
|
const MetaClass* sc) |
|
{ |
|
try |
|
{ | { |
// Create class: |
if (propertyList.isNull()) |
{ |
return 0; |
CIMName scn; |
|
| |
if (sc->super) |
size_t size = propertyList.size(); |
scn = sc->super->name; |
char** pl = (char**)malloc(sizeof(char*) * (size + 1)); |
| |
cc = CIMClass(sc->name, scn); |
for (size_t i = 0; i < size; i++) |
} |
pl[i] = strdup(*Str(propertyList[i])); |
| |
// Add qualifiers: |
pl[size] = 0; |
| |
if (_addQualifiers(ns, sc, 0, 0, cc) != 0) |
return pl; |
{ |
|
printf("T[%u]\n", __LINE__); |
|
return -1; |
|
} | } |
| |
// Features: |
static void _freePropertyList(char** pl) |
|
{ |
|
if (!pl) |
|
return; |
| |
if (_addFeatures(ns, sc, cc) != 0) |
for (size_t i = 0; pl[i]; i++) |
{ | { |
printf("T[%u]\n", __LINE__); |
free(pl[i]); |
return -1; |
|
} |
|
} | } |
catch (Exception& e) |
|
{ |
free(pl); |
printf("EXCEPTION[%s]\n", *Str(e)); |
|
return -1; |
|
} | } |
catch (...) |
|
|
static void _printPropertyList(const char* const* pl) |
{ | { |
printf("T[%u]\n", __LINE__); |
if (!pl) |
return -1; |
return; |
} |
|
| |
return 0; |
for (size_t i = 0; pl[i]; i++) |
|
printf("pl[%s]\n", pl[i]); |
} | } |
| |
//============================================================================== | //============================================================================== |
|
|
Boolean includeClassOrigin, | Boolean includeClassOrigin, |
const CIMPropertyList& propertyList) | const CIMPropertyList& propertyList) |
{ | { |
return CIMClass(); |
printf("===== MetaRepository::getClass()\n"); |
|
|
|
// Lookup namespace: |
|
|
|
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
_throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)); |
|
|
|
// Lookup class: |
|
|
|
const MetaClass* mc = _findClass(ns, *Str(className)); |
|
|
|
if (!mc) |
|
_throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)); |
|
|
|
// Build property list: |
|
|
|
char** pl = _makePropertyList(propertyList); |
|
|
|
// Make class: |
|
|
|
CIMClass cc; |
|
|
|
if (MakeClass(ns, mc, localOnly, includeQualifiers, |
|
includeQualifiers, pl, cc) != 0) |
|
{ |
|
_freePropertyList(pl); |
|
_throw(CIM_ERR_FAILED, "conversion failed: %s", mc->name); |
|
} |
|
|
|
_freePropertyList(pl); |
|
return cc; |
} | } |
| |
Array<CIMClass> MetaRepository::enumerateClasses( | Array<CIMClass> MetaRepository::enumerateClasses( |
|
|
Boolean includeQualifiers, | Boolean includeQualifiers, |
Boolean includeClassOrigin) | Boolean includeClassOrigin) |
{ | { |
#if defined(TEST_META_REPOSITORY) |
printf("===== MetaRepository::enumerateClasses()\n"); |
_init(); |
|
#endif |
|
|
|
printf("MetaRepository::enumerateClasses()\n"); |
|
| |
// Lookup namespace: | // Lookup namespace: |
| |
|
|
| |
for (size_t i = 0; ns->classes[i]; i++) | for (size_t i = 0; ns->classes[i]; i++) |
{ | { |
MetaClass* sc = ns->classes[i]; |
MetaClass* mc = ns->classes[i]; |
| |
// printf("CLASSNAME[%s]\n", sc->name); |
bool flag = false; |
| |
if (deepInheritance) | if (deepInheritance) |
{ | { |
if (_isSubClass(super, sc)) |
if (_isSubClass(super, mc)) |
{ |
flag = true; |
CIMClass cc; |
|
|
|
if (_makeClass(ns, cc, sc) != 0) |
|
_throw(CIM_ERR_FAILED, "conversion failed: %s", sc->name); |
|
else |
|
result.append(cc); |
|
} |
|
} | } |
else | else |
{ | { |
if (_isDirectSubClass(super, sc)) |
if (_isDirectSubClass(super, mc)) |
|
flag = true; |
|
} |
|
|
|
if (flag) |
{ | { |
CIMClass cc; | CIMClass cc; |
| |
if (_makeClass(ns, cc, sc) != 0) |
if (MakeClass(ns, mc, localOnly, includeQualifiers, |
_throw(CIM_ERR_FAILED, "conversion failed: %s", sc->name); |
includeQualifiers, 0, cc) != 0) |
|
{ |
|
_throw(CIM_ERR_FAILED, "conversion failed: %s", mc->name); |
|
} |
else | else |
result.append(cc); | result.append(cc); |
} | } |
} | } |
} |
|
| |
return result; | return result; |
} | } |
|
|
const CIMName& className, | const CIMName& className, |
Boolean deepInheritance) | Boolean deepInheritance) |
{ | { |
|
printf("===== MetaRepository::enumerateClassNames()\n"); |
|
|
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); | const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
| |
for (size_t i = 0; ns->classes[i]; i++) | for (size_t i = 0; ns->classes[i]; i++) |
{ | { |
MetaClass* sc = ns->classes[i]; |
MetaClass* mc = ns->classes[i]; |
| |
if (deepInheritance) | if (deepInheritance) |
{ | { |
if (_isSubClass(super, sc)) |
if (_isSubClass(super, mc)) |
result.append(sc->name); |
result.append(mc->name); |
} | } |
else | else |
{ | { |
if (_isDirectSubClass(super, sc)) |
if (_isDirectSubClass(super, mc)) |
result.append(sc->name); |
result.append(mc->name); |
} | } |
} | } |
| |
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "modifyClass()"); | _throw(CIM_ERR_NOT_SUPPORTED, "modifyClass()"); |
} | } |
| |
|
void MetaRepository::getSubClassNames( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
Boolean deepInheritance, |
|
Array<CIMName>& subClassNames) |
|
{ |
|
printf("===== MetaRepository::getSubClassNames()\n"); |
|
|
|
subClassNames = MetaRepository::enumerateClassNames( |
|
nameSpace, className, deepInheritance); |
|
} |
|
|
|
void MetaRepository::getSuperClassNames( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
Array<CIMName>& superClassNames) |
|
{ |
|
printf("===== MetaRepository::getSuperClassNames()\n"); |
|
|
|
superClassNames.clear(); |
|
|
|
// Lookup namespace: |
|
|
|
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
_throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)); |
|
|
|
// Lookup class: |
|
|
|
const MetaClass* mc = _findClass(ns, *Str(className)); |
|
|
|
if (!mc) |
|
_throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className)); |
|
|
|
// Append superclass names: |
|
|
|
for (const MetaClass* p = mc->super; p; p = p->super) |
|
superClassNames.append(p->name); |
|
} |
|
|
|
void MetaRepository::createNameSpace( |
|
const CIMNamespaceName& nameSpace, |
|
const NameSpaceAttributes& attributes) |
|
{ |
|
printf("===== MetaRepository::createNameSpace()\n"); |
|
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "createNameSpace()"); |
|
} |
|
|
|
void MetaRepository::modifyNameSpace( |
|
const CIMNamespaceName& nameSpace, |
|
const NameSpaceAttributes& attributes) |
|
{ |
|
printf("===== MetaRepository::modifyNameSpace()\n"); |
|
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "modifyNameSpace()"); |
|
} |
|
|
|
Array<CIMNamespaceName> MetaRepository::enumerateNameSpaces() |
|
{ |
|
printf("===== MetaRepository::enumerateNameSpaces()\n"); |
|
|
|
Array<CIMNamespaceName> nameSpaces; |
|
|
|
for (size_t i = 0; i < _nameSpacesSize; i++) |
|
nameSpaces.append(_nameSpaces[i]->name); |
|
|
|
return Array<CIMNamespaceName>(); |
|
} |
|
|
|
void MetaRepository::deleteNameSpace( |
|
const CIMNamespaceName& nameSpace) |
|
{ |
|
printf("===== MetaRepository::deleteNameSpace()\n"); |
|
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "deleteNameSpace()"); |
|
} |
|
|
|
Boolean MetaRepository::getNameSpaceAttributes( |
|
const CIMNamespaceName& nameSpace, |
|
NameSpaceAttributes& attributes) |
|
{ |
|
printf("===== MetaRepository::getNameSpaceAttributes()\n"); |
|
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "getNameSpaceAttributes()"); |
|
|
|
return false; |
|
} |
|
|
|
Boolean MetaRepository::isRemoteNameSpace( |
|
const CIMNamespaceName& nameSpace, |
|
String& remoteInfo) |
|
{ |
|
printf("===== MetaRepository::isRemoteNameSpace()\n"); |
|
|
|
return false; |
|
} |
|
|
|
CIMQualifierDecl MetaRepository::getQualifier( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& qualifierName) |
|
{ |
|
printf("===== MetaRepository::getQualifier()\n"); |
|
|
|
// Lookup namespace: |
|
|
|
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
_throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)); |
|
|
|
// Lookup qualifier: |
|
|
|
const MetaQualifierDecl* mqd = _findQualifierDecl(ns, *Str(qualifierName)); |
|
|
|
if (!mqd) |
|
_throw(CIM_ERR_NOT_FOUND, "unknown qualifier: %s", *Str(qualifierName)); |
|
|
|
// Make the qualifier declaration: |
|
|
|
CIMQualifierDecl cqd; |
|
|
|
if (MakeQualifierDecl(ns, mqd, cqd) != 0) |
|
{ |
|
_throw(CIM_ERR_FAILED, "conversion failed: %s", mqd->name); |
|
} |
|
|
|
return cqd; |
|
} |
|
|
|
void MetaRepository::setQualifier( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMQualifierDecl& qualifierDecl) |
|
{ |
|
printf("===== MetaRepository::setQualifier()\n"); |
|
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "setQualifier()"); |
|
|
|
} |
|
|
|
void MetaRepository::deleteQualifier( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& qualifierName) |
|
{ |
|
printf("===== MetaRepository::deleteQualifier()\n"); |
|
|
|
_throw(CIM_ERR_NOT_SUPPORTED, "deleteQualifier()"); |
|
} |
|
|
|
Array<CIMQualifierDecl> MetaRepository::enumerateQualifiers( |
|
const CIMNamespaceName& nameSpace) |
|
{ |
|
printf("===== MetaRepository::enumerateQualifiers()\n"); |
|
|
|
// Lookup namespace: |
|
|
|
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
_throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace)); |
|
|
|
// Build the array of qualifier declarations: |
|
|
|
Array<CIMQualifierDecl> result; |
|
|
|
for (size_t i = 0; ns->qualifiers[i]; i++) |
|
{ |
|
const MetaQualifierDecl* mqd = ns->qualifiers[i]; |
|
CIMQualifierDecl cqd; |
|
|
|
if (MakeQualifierDecl(ns, mqd, cqd) != 0) |
|
{ |
|
_throw(CIM_ERR_FAILED, "conversion failed: %s", mqd->name); |
|
} |
|
|
|
result.append(cqd); |
|
} |
|
|
|
return result; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |