version 1.1.2.1, 2007/10/05 01:43:41
|
version 1.1.2.7, 2007/11/08 23:20:50
|
|
|
| |
#include <cstdarg> | #include <cstdarg> |
#include <Pegasus/Common/Resolver.h> | #include <Pegasus/Common/Resolver.h> |
|
#include <Pegasus/Common/Once.h> |
|
#include <Pegasus/Common/System.h> |
#include "MemoryResidentRepository.h" | #include "MemoryResidentRepository.h" |
#include "RepositoryDeclContext.h" | #include "RepositoryDeclContext.h" |
#include "MetaRepository.h" |
|
#include "Filtering.h" | #include "Filtering.h" |
|
#include "Serialization.h" |
|
#include "SchemaTypes.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
typedef const SchemaClass* ConstSchemaClassPtr; |
|
#define PEGASUS_ARRAY_T ConstSchemaClassPtr |
|
# include <Pegasus/Common/ArrayInter.h> |
|
# include <Pegasus/Common/ArrayImpl.h> |
|
#undef PEGASUS_ARRAY_T |
|
|
|
#define PEGASUS_ARRAY_T NamespaceInstancePair |
|
# include <Pegasus/Common/ArrayImpl.h> |
|
#undef PEGASUS_ARRAY_T |
|
|
//============================================================================== | //============================================================================== |
// | // |
// Local routines: |
// Local definitions: |
// | // |
//============================================================================== | //============================================================================== |
| |
PEGASUS_FORMAT(2, 3) |
static size_t const _MAX_NAMESPACE_TABLE_SIZE = 64; |
static void _throw(CIMStatusCode code, const char* format, ...) |
static const SchemaNameSpace* _nameSpaceTable[_MAX_NAMESPACE_TABLE_SIZE]; |
|
static size_t _nameSpaceTableSize = 0; |
|
|
|
static const size_t _MAX_FEATURES = 128; |
|
static const size_t _MAX_QUALIFIERS = 128; |
|
|
|
class ThrowContext |
{ | { |
char buffer[4096]; |
public: |
| |
|
PEGASUS_FORMAT(3, 4) |
|
ThrowContext(CIMStatusCode code_, const char* format, ...) : code(code_) |
|
{ |
|
char buffer[1024]; |
va_list ap; | va_list ap; |
va_start(ap, format); | va_start(ap, format); |
vsprintf(buffer, format, ap); | vsprintf(buffer, format, ap); |
va_end(ap); | va_end(ap); |
throw CIMException(code, buffer); |
msg = buffer; |
} | } |
|
CIMStatusCode code; |
|
String msg; |
|
}; |
|
|
|
#define Throw(ARGS) \ |
|
do \ |
|
{ \ |
|
ThrowContext c ARGS; \ |
|
throw CIMException(c.code, c.msg); \ |
|
} \ |
|
while (0) |
| |
class Str | class Str |
{ | { |
|
|
} | } |
| |
static void _applyModifiedInstance( | static void _applyModifiedInstance( |
const MetaClass* mc, |
const SchemaClass* mc, |
const CIMInstance& modifiedInstance_, | const CIMInstance& modifiedInstance_, |
const CIMPropertyList& propertyList, | const CIMPropertyList& propertyList, |
CIMInstance& resultInstance) | CIMInstance& resultInstance) |
|
|
{ | { |
// Reject attempts to add properties not in class: | // Reject attempts to add properties not in class: |
| |
const MetaFeature* mf = FindFeature( |
const SchemaFeature* mf = FindFeature(mc, |
mc, *Str(cp.getName()), META_FLAG_PROPERTY|META_FLAG_REFERENCE); |
*Str(cp.getName()), SCHEMA_FLAG_PROPERTY|SCHEMA_FLAG_REFERENCE); |
| |
if (!mf) | if (!mf) |
{ | { |
_throw(CIM_ERR_NOT_FOUND, |
Throw((CIM_ERR_NOT_FOUND, |
"modifyInstance() failed: unknown property: %s", | "modifyInstance() failed: unknown property: %s", |
*Str(cp.getName())); |
*Str(cp.getName()))); |
} | } |
| |
// Reject attempts to modify key properties: | // Reject attempts to modify key properties: |
| |
if (mf->flags & META_FLAG_KEY) |
if (mf->flags & SCHEMA_FLAG_KEY) |
{ | { |
_throw(CIM_ERR_FAILED, |
Throw((CIM_ERR_FAILED, |
"modifyInstance() failed to modify key property: %s", | "modifyInstance() failed to modify key property: %s", |
*Str(cp.getName())); |
*Str(cp.getName()))); |
} | } |
| |
// Add or replace property in result instance: | // Add or replace property in result instance: |
|
|
std::cout << co.toString() << std::endl; | std::cout << co.toString() << std::endl; |
} | } |
| |
|
static Once _once = PEGASUS_ONCE_INITIALIZER; |
|
static const char* _hostName = 0; |
|
|
|
static void _initHostName() |
|
{ |
|
String hn = System::getHostName(); |
|
_hostName = strdup(*Str(hn)); |
|
} |
|
|
|
static inline const char* _getHostName() |
|
{ |
|
once(&_once, _initHostName); |
|
return _hostName; |
|
} |
|
|
|
static bool _eqi(const char* s1, const char* s2) |
|
{ |
|
return System::strcasecmp(s1, s2) == 0; |
|
} |
|
|
|
static const SchemaNameSpace* _findNameSpace(const char* name) |
|
{ |
|
for (size_t i = 0; i < _nameSpaceTableSize; i++) |
|
{ |
|
const SchemaNameSpace* ns = _nameSpaceTable[i]; |
|
|
|
if (_eqi(ns->name, name)) |
|
return ns; |
|
} |
|
|
|
// Not found! |
|
return 0; |
|
} |
|
|
|
static bool _isSubClass(const SchemaClass* super, const SchemaClass* sub) |
|
{ |
|
if (!super) |
|
return true; |
|
|
|
for (SchemaClass* p = sub->super; p; p = p->super) |
|
{ |
|
if (p == super) |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
static inline bool _isDirectSubClass( |
|
const SchemaClass* super, |
|
const SchemaClass* sub) |
|
{ |
|
return sub->super == super; |
|
} |
|
|
|
static char** _makePropertyList(const CIMPropertyList& propertyList) |
|
{ |
|
if (propertyList.isNull()) |
|
return 0; |
|
|
|
size_t size = propertyList.size(); |
|
char** pl = (char**)malloc(sizeof(char*) * (size + 1)); |
|
|
|
for (size_t i = 0; i < size; i++) |
|
pl[i] = strdup(*Str(propertyList[i])); |
|
|
|
pl[size] = 0; |
|
|
|
return pl; |
|
} |
|
|
|
static void _freePropertyList(char** pl) |
|
{ |
|
if (!pl) |
|
return; |
|
|
|
for (size_t i = 0; pl[i]; i++) |
|
{ |
|
free(pl[i]); |
|
} |
|
|
|
free(pl); |
|
} |
|
|
|
static void _printPropertyList(const char* const* pl) |
|
{ |
|
if (!pl) |
|
return; |
|
|
|
for (size_t i = 0; pl[i]; i++) |
|
printf("pl[%s]\n", pl[i]); |
|
} |
|
|
|
static bool _contains(const Array<const SchemaClass*>& x, const SchemaClass* mc) |
|
{ |
|
Uint32 n = x.size(); |
|
const SchemaClass* const* p = x.getData(); |
|
|
|
while (n--) |
|
{ |
|
if (*p++ == mc) |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
static void _associators( |
|
const SchemaNameSpace* ns, |
|
const CIMName& className, |
|
const CIMName& assocClass, |
|
const CIMName& resultClass, |
|
const String& role, |
|
const String& resultRole, |
|
Array<const SchemaClass*>& result) |
|
{ |
|
// Lookup source class: |
|
|
|
const SchemaClass* mc = FindClass(ns, *Str(className)); |
|
|
|
if (!mc) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
|
|
|
|
|
// Lookup result class (if any). |
|
|
|
const SchemaClass* rmc = 0; |
|
|
|
if (!resultClass.isNull()) |
|
{ |
|
rmc = FindClass(ns, *Str(resultClass)); |
|
|
|
if (!rmc) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(resultClass))); |
|
} |
|
|
|
// Convert these to UTF8 now to avoid doing so in loop below. |
|
|
|
Str ac(assocClass); |
|
Str r(role); |
|
Str rr(resultRole); |
|
|
|
// Process association classes: |
|
|
|
for (size_t i = 0; ns->classes[i]; i++) |
|
{ |
|
SchemaClass* amc = ns->classes[i]; |
|
|
|
// Skip non-association classes: |
|
|
|
if (!(amc->flags & SCHEMA_FLAG_ASSOCIATION)) |
|
continue; |
|
|
|
// Filter by assocClass parameter: |
|
|
|
if (!assocClass.isNull() && !_eqi(ac, amc->name)) |
|
continue; |
|
|
|
// Process reference properties: |
|
|
|
SchemaFeatureInfo features[SCHEMA_MAX_FEATURES]; |
|
size_t size = 0; |
|
MergeFeatures(amc, false, SCHEMA_FLAG_REFERENCE, features, size); |
|
|
|
for (size_t j = 0; j < size; j++) |
|
{ |
|
const SchemaFeature* mf = features[j].mf; |
|
|
|
// Skip non references: |
|
|
|
if (!(mf->flags & SCHEMA_FLAG_REFERENCE)) |
|
continue; |
|
|
|
const SchemaReference* mr = (const SchemaReference*)mf; |
|
|
|
// Filter by role parameter. |
|
|
|
if (role.size() && !_eqi(r, mf->name)) |
|
continue; |
|
|
|
// Filter by source class: |
|
|
|
if (!IsA(mr->ref, mc)) |
|
continue; |
|
|
|
// Process result reference: |
|
|
|
for (size_t k = 0; k < size; k++) |
|
{ |
|
const SchemaFeature* rmf = features[k].mf; |
|
|
|
// Skip the feature under consideration: |
|
|
|
if (rmf == mf) |
|
continue; |
|
|
|
// Skip non references: |
|
|
|
if (!(rmf->flags & SCHEMA_FLAG_REFERENCE)) |
|
continue; |
|
|
|
const SchemaReference* rmr = (const SchemaReference*)rmf; |
|
|
|
// Filter by resultRole parameter. |
|
|
|
if (resultRole.size() && !_eqi(rr, rmf->name)) |
|
continue; |
|
|
|
// Skip references not of the result class kind: |
|
|
|
if (rmc && !IsA(rmr->ref, rmc)) |
|
continue; |
|
|
|
// ATTN: should we include entire class hierarchy under |
|
// result class? |
|
|
|
// If reached, then save this one. |
|
|
|
if (!_contains(result, rmr->ref)) |
|
result.append(rmr->ref); |
|
} |
|
} |
|
} |
|
} |
|
|
|
static void _references( |
|
const SchemaNameSpace* ns, |
|
const CIMName& className, |
|
const CIMName& resultClass, |
|
const String& role, |
|
Array<const SchemaClass*>& result) |
|
{ |
|
// Lookup source class: |
|
|
|
const SchemaClass* mc = FindClass(ns, *Str(className)); |
|
|
|
if (!mc) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
|
|
|
// Lookup result class (if any). |
|
|
|
const SchemaClass* rmc = 0; |
|
|
|
if (!resultClass.isNull()) |
|
{ |
|
rmc = FindClass(ns, *Str(resultClass)); |
|
|
|
if (!rmc) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(resultClass))); |
|
} |
|
|
|
// Convert these to UTF8 now to avoid doing so in loop below. |
|
|
|
Str r(role); |
|
|
|
// Process association classes: |
|
|
|
for (size_t i = 0; ns->classes[i]; i++) |
|
{ |
|
SchemaClass* amc = ns->classes[i]; |
|
|
|
// Skip non-association classes: |
|
|
|
if (!(amc->flags & SCHEMA_FLAG_ASSOCIATION)) |
|
continue; |
|
|
|
// Filter by result class: |
|
|
|
if (rmc && !IsA(rmc, amc)) |
|
continue; |
|
|
|
// Process reference properties: |
|
|
|
SchemaFeatureInfo features[SCHEMA_MAX_FEATURES]; |
|
size_t size = 0; |
|
MergeFeatures(amc, false, SCHEMA_FLAG_REFERENCE, features, size); |
|
|
|
for (size_t j = 0; j < size; j++) |
|
{ |
|
const SchemaFeature* mf = features[j].mf; |
|
|
|
// Skip non references: |
|
|
|
if (!(mf->flags & SCHEMA_FLAG_REFERENCE)) |
|
continue; |
|
|
|
const SchemaReference* mr = (const SchemaReference*)mf; |
|
|
|
// Filter by role parameter. |
|
|
|
if (role.size() && !_eqi(r, mf->name)) |
|
continue; |
|
|
|
// Filter by source class: |
|
|
|
if (!IsA(mr->ref, mc)) |
|
continue; |
|
|
|
// Add this one to the output: |
|
|
|
if (!_contains(result, amc)) |
|
result.append((SchemaClass*)amc); |
|
} |
|
} |
|
} |
|
|
|
static const SchemaClass* _findSchemaClass( |
|
const char* nameSpace, |
|
const char* className) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(nameSpace); |
|
|
|
if (!ns) |
|
return 0; |
|
|
|
return FindClass(ns, className); |
|
} |
|
|
|
static Array<CIMName> _enumerateClassNames( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
Boolean deepInheritance) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Lookup class: |
|
|
|
const SchemaClass* super = 0; |
|
|
|
if (!className.isNull()) |
|
{ |
|
super = FindClass(ns, *Str(className)); |
|
|
|
if (!super) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
|
} |
|
|
|
// Iterate all classes looking for matches: |
|
|
|
Array<CIMName> result; |
|
|
|
for (size_t i = 0; ns->classes[i]; i++) |
|
{ |
|
SchemaClass* mc = ns->classes[i]; |
|
|
|
if (deepInheritance) |
|
{ |
|
if (_isSubClass(super, mc)) |
|
result.append(mc->name); |
|
} |
|
else |
|
{ |
|
if (_isDirectSubClass(super, mc)) |
|
result.append(mc->name); |
|
} |
|
} |
|
|
|
return result; |
|
} |
|
|
|
static void _getSubClassNames( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
Boolean deepInheritance, |
|
Array<CIMName>& subClassNames) |
|
{ |
|
subClassNames = _enumerateClassNames( |
|
nameSpace, className, deepInheritance); |
|
} |
|
|
|
static Array<CIMObject> _associatorClasses( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
const CIMName& assocClass, |
|
const CIMName& resultClass, |
|
const String& role, |
|
const String& resultRole, |
|
Boolean includeQualifiers, |
|
Boolean includeClassOrigin, |
|
const CIMPropertyList& propertyList) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Get associator schema-classes: |
|
|
|
Array<const SchemaClass*> mcs; |
|
_associators(ns, className, assocClass, resultClass, role, resultRole, mcs); |
|
|
|
// Convert schema-classes to classes. |
|
|
|
Array<CIMObject> result; |
|
|
|
char** pl = _makePropertyList(propertyList); |
|
|
|
for (Uint32 i = 0; i < mcs.size(); i++) |
|
{ |
|
const SchemaClass* mc = mcs[i]; |
|
CIMClass cc; |
|
|
|
if (MakeClass(_getHostName(), ns, mc, false, includeQualifiers, |
|
includeClassOrigin, pl, cc) != 0) |
|
{ |
|
_freePropertyList(pl); |
|
Throw((CIM_ERR_FAILED, "conversion failed: %s", mc->name)); |
|
} |
|
|
|
result.append(cc); |
|
} |
|
|
|
_freePropertyList(pl); |
|
return result; |
|
} |
|
|
|
static Array<CIMObjectPath> _associatorClassPaths( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
const CIMName& assocClass, |
|
const CIMName& resultClass, |
|
const String& role, |
|
const String& resultRole) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Get associator schema-classes: |
|
|
|
Array<const SchemaClass*> mcs; |
|
_associators(ns, className, assocClass, resultClass, role, resultRole, mcs); |
|
|
|
// Convert schema-classes to object names: |
|
|
|
Array<CIMObjectPath> result; |
|
|
|
for (Uint32 i = 0; i < mcs.size(); i++) |
|
result.append(CIMObjectPath(_getHostName(), nameSpace, mcs[i]->name)); |
|
|
|
return result; |
|
} |
|
|
|
static Array<CIMObject> _referenceClasses( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
const CIMName& resultClass, |
|
const String& role, |
|
Boolean includeQualifiers, |
|
Boolean includeClassOrigin, |
|
const CIMPropertyList& propertyList) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Get reference schema-classes: |
|
|
|
Array<const SchemaClass*> mcs; |
|
_references(ns, className, resultClass, role, mcs); |
|
|
|
// Convert schema-classes to classes. |
|
|
|
Array<CIMObject> result; |
|
|
|
char** pl = _makePropertyList(propertyList); |
|
|
|
for (Uint32 i = 0; i < mcs.size(); i++) |
|
{ |
|
const SchemaClass* mc = mcs[i]; |
|
CIMClass cc; |
|
|
|
if (MakeClass(_getHostName(), ns, mc, false, includeQualifiers, |
|
includeClassOrigin, pl, cc) != 0) |
|
{ |
|
_freePropertyList(pl); |
|
Throw((CIM_ERR_FAILED, "conversion failed: %s", mc->name)); |
|
} |
|
|
|
result.append(cc); |
|
} |
|
|
|
_freePropertyList(pl); |
|
return result; |
|
} |
|
|
|
static Array<CIMObjectPath> _referenceClassPaths( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
const CIMName& resultClass, |
|
const String& role) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Get reference schema-classes: |
|
|
|
Array<const SchemaClass*> mcs; |
|
_references(ns, className, resultClass, role, mcs); |
|
|
|
// Convert schema-classes to object paths. |
|
|
|
Array<CIMObjectPath> result; |
|
|
|
for (Uint32 i = 0; i < mcs.size(); i++) |
|
result.append(CIMObjectPath(_getHostName(), nameSpace, mcs[i]->name)); |
|
|
|
return result; |
|
} |
|
|
|
static CIMQualifierDecl _getQualifier( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& qualifierName) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Lookup qualifier: |
|
|
|
const SchemaQualifierDecl* 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; |
|
} |
|
|
|
static Array<CIMQualifierDecl> _enumerateQualifiers( |
|
const CIMNamespaceName& nameSpace) |
|
{ |
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* 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 SchemaQualifierDecl* 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; |
|
|
|
} |
|
|
|
static Array<CIMNamespaceName> _enumerateNameSpaces() |
|
{ |
|
Array<CIMNamespaceName> result; |
|
|
|
for (size_t i = 0; i < _nameSpaceTableSize; i++) |
|
{ |
|
const SchemaNameSpace* ns = _nameSpaceTable[i]; |
|
result.append(ns->name); |
|
} |
|
|
|
return result; |
|
} |
|
|
|
static void _getSuperClassNames( |
|
const CIMNamespaceName& nameSpace, |
|
const CIMName& className, |
|
Array<CIMName>& superClassNames) |
|
{ |
|
superClassNames.clear(); |
|
|
|
// Lookup namespace: |
|
|
|
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
|
|
|
if (!ns) |
|
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
|
// Lookup class: |
|
|
|
const SchemaClass* mc = FindClass(ns, *Str(className)); |
|
|
|
if (!mc) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
|
|
|
// Append superclass names: |
|
|
|
for (const SchemaClass* p = mc->super; p; p = p->super) |
|
superClassNames.append(p->name); |
|
} |
|
|
//============================================================================== | //============================================================================== |
// | // |
// class MemoryResidentRepository: | // class MemoryResidentRepository: |
// | // |
//============================================================================== | //============================================================================== |
| |
MemoryResidentRepository::MemoryResidentRepository( |
static void (*_saveCallback)(const Buffer& buffer, void* data); |
const String& repositoryRoot, |
static void* _saveData; |
Uint32 repositoryMode) |
static void (*_loadCallback)(Buffer& buffer, void* data); |
: |
static void* _loadData; |
Repository(repositoryRoot, repositoryMode) |
|
|
MemoryResidentRepository::MemoryResidentRepository() |
{ | { |
|
// Load users data if any: |
|
_processLoadHandler(); |
} | } |
| |
MemoryResidentRepository::~MemoryResidentRepository() | MemoryResidentRepository::~MemoryResidentRepository() |
|
|
Boolean includeClassOrigin, | Boolean includeClassOrigin, |
const CIMPropertyList& propertyList) | const CIMPropertyList& propertyList) |
{ | { |
return MetaRepository::getClass( |
// Lookup namespace: |
nameSpace, |
|
className, |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
localOnly, |
|
includeQualifiers, |
if (!ns) |
includeClassOrigin, |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
propertyList); |
|
|
// Lookup class: |
|
|
|
const SchemaClass* 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(_getHostName(), ns, mc, localOnly, includeQualifiers, |
|
includeClassOrigin, pl, cc) != 0) |
|
{ |
|
_freePropertyList(pl); |
|
Throw((CIM_ERR_FAILED, "conversion failed: %s", mc->name)); |
|
} |
|
|
|
_freePropertyList(pl); |
|
return cc; |
} | } |
| |
CIMInstance MemoryResidentRepository::getInstance( | CIMInstance MemoryResidentRepository::getInstance( |
|
|
Uint32 pos = _findInstance(nameSpace, instanceName); | Uint32 pos = _findInstance(nameSpace, instanceName); |
| |
if (pos == PEG_NOT_FOUND) | if (pos == PEG_NOT_FOUND) |
_throw(CIM_ERR_NOT_FOUND, "%s", *Str(instanceName)); |
Throw((CIM_ERR_NOT_FOUND, "%s", *Str(instanceName))); |
| |
CIMInstance cimInstance = _rep[pos].second.clone(); | CIMInstance cimInstance = _rep[pos].second.clone(); |
| |
|
|
const CIMNamespaceName& nameSpace, | const CIMNamespaceName& nameSpace, |
const CIMName& className) | const CIMName& className) |
{ | { |
MetaRepository::deleteClass( |
Throw((CIM_ERR_NOT_SUPPORTED, "deleteClass()")); |
nameSpace, |
|
className); |
|
} | } |
| |
void MemoryResidentRepository::deleteInstance( | void MemoryResidentRepository::deleteInstance( |
|
|
Uint32 pos = _findInstance(nameSpace, instanceName); | Uint32 pos = _findInstance(nameSpace, instanceName); |
| |
if (pos == PEG_NOT_FOUND) | if (pos == PEG_NOT_FOUND) |
_throw(CIM_ERR_NOT_FOUND, "%s", *Str(instanceName)); |
Throw((CIM_ERR_NOT_FOUND, "%s", *Str(instanceName))); |
| |
_rep.remove(pos); | _rep.remove(pos); |
|
_processSaveHandler(); |
} | } |
| |
void MemoryResidentRepository::createClass( | void MemoryResidentRepository::createClass( |
|
|
const CIMClass& newClass, | const CIMClass& newClass, |
const ContentLanguageList& contentLangs) | const ContentLanguageList& contentLangs) |
{ | { |
MetaRepository::createClass( |
Throw((CIM_ERR_NOT_SUPPORTED, "createClass()")); |
nameSpace, |
|
newClass); |
|
} | } |
| |
CIMObjectPath MemoryResidentRepository::createInstance( | CIMObjectPath MemoryResidentRepository::createInstance( |
|
|
// Reject if an instance with this name already exists: | // Reject if an instance with this name already exists: |
| |
if (_findInstance(nameSpace, cop) != PEG_NOT_FOUND) | if (_findInstance(nameSpace, cop) != PEG_NOT_FOUND) |
_throw(CIM_ERR_ALREADY_EXISTS, "%s", *Str(cop)); |
Throw((CIM_ERR_ALREADY_EXISTS, "%s", *Str(cop))); |
| |
// Add instance to array: | // Add instance to array: |
| |
_rep.append(NamespaceInstancePair(nameSpace, ci)); | _rep.append(NamespaceInstancePair(nameSpace, ci)); |
|
_processSaveHandler(); |
| |
return cop; | return cop; |
} | } |
|
|
const CIMClass& modifiedClass, | const CIMClass& modifiedClass, |
const ContentLanguageList& contentLangs) | const ContentLanguageList& contentLangs) |
{ | { |
MetaRepository::modifyClass( |
Throw((CIM_ERR_NOT_SUPPORTED, "modifyClass()")); |
nameSpace, |
|
modifiedClass); |
|
} | } |
| |
void MemoryResidentRepository::modifyInstance( | void MemoryResidentRepository::modifyInstance( |
|
|
const CIMObjectPath& cop = modifiedInstance.getPath(); | const CIMObjectPath& cop = modifiedInstance.getPath(); |
CIMName className = cop.getClassName(); | CIMName className = cop.getClassName(); |
| |
// Get the meta class for this instance. |
// Get the schema-class for this instance. |
| |
const MetaClass* mc = MetaRepository::findMetaClass( |
const SchemaClass* mc = _findSchemaClass(*Str(nameSpace), *Str(className)); |
*Str(nameSpace), *Str(className)); |
|
| |
if (!mc) | if (!mc) |
{ | { |
_throw(CIM_ERR_FAILED, |
Throw((CIM_ERR_FAILED, |
"modifyInstance() failed: unknown class: %s:%s", | "modifyInstance() failed: unknown class: %s:%s", |
*Str(nameSpace), *Str(className)); |
*Str(nameSpace), *Str(className))); |
} | } |
| |
// Get original instance to be modified: | // Get original instance to be modified: |
|
|
| |
if (pos == PEG_NOT_FOUND) | if (pos == PEG_NOT_FOUND) |
{ | { |
_throw(CIM_ERR_NOT_FOUND, "modified() failed: unknown instance: %s", |
Throw((CIM_ERR_NOT_FOUND, |
*Str(cop.toString())); |
"modifyInstance() failed: unknown instance: %s", |
|
*Str(cop.toString()))); |
} | } |
| |
CIMInstance resultInstance = _rep[pos].second.clone(); | CIMInstance resultInstance = _rep[pos].second.clone(); |
|
|
// Replace original instance. | // Replace original instance. |
| |
_rep[pos].second = resultInstance; | _rep[pos].second = resultInstance; |
|
_processSaveHandler(); |
} | } |
| |
Array<CIMClass> MemoryResidentRepository::enumerateClasses( | Array<CIMClass> MemoryResidentRepository::enumerateClasses( |
|
|
Boolean includeQualifiers, | Boolean includeQualifiers, |
Boolean includeClassOrigin) | Boolean includeClassOrigin) |
{ | { |
return MetaRepository::enumerateClasses( |
// Lookup namespace: |
nameSpace, |
|
className, |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
deepInheritance, |
|
localOnly, |
if (!ns) |
includeQualifiers, |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
includeClassOrigin); |
|
|
// Lookup class: |
|
|
|
const SchemaClass* super = 0; |
|
|
|
if (!className.isNull()) |
|
{ |
|
super = FindClass(ns, *Str(className)); |
|
|
|
if (!super) |
|
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
|
} |
|
|
|
// Iterate all classes looking for matches: |
|
|
|
Array<CIMClass> result; |
|
|
|
for (size_t i = 0; ns->classes[i]; i++) |
|
{ |
|
SchemaClass* mc = ns->classes[i]; |
|
|
|
bool flag = false; |
|
|
|
if (deepInheritance) |
|
{ |
|
if (_isSubClass(super, mc)) |
|
flag = true; |
|
} |
|
else |
|
{ |
|
if (_isDirectSubClass(super, mc)) |
|
flag = true; |
|
} |
|
|
|
if (flag) |
|
{ |
|
CIMClass cc; |
|
|
|
if (MakeClass(_getHostName(), ns, mc, localOnly, includeQualifiers, |
|
includeClassOrigin, 0, cc) != 0) |
|
{ |
|
Throw((CIM_ERR_FAILED, "conversion failed: %s", mc->name)); |
|
} |
|
|
|
result.append(cc); |
|
} |
|
} |
|
|
|
return result; |
} | } |
| |
Array<CIMName> MemoryResidentRepository::enumerateClassNames( | Array<CIMName> MemoryResidentRepository::enumerateClassNames( |
|
|
const CIMName& className, | const CIMName& className, |
Boolean deepInheritance) | Boolean deepInheritance) |
{ | { |
return MetaRepository::enumerateClassNames( |
return _enumerateClassNames(nameSpace, className, deepInheritance); |
nameSpace, |
|
className, |
|
deepInheritance); |
|
} | } |
| |
Array<CIMInstance> MemoryResidentRepository::enumerateInstancesForSubtree( | Array<CIMInstance> MemoryResidentRepository::enumerateInstancesForSubtree( |
|
|
| |
Array<CIMName> classNames; | Array<CIMName> classNames; |
classNames.append(className); | classNames.append(className); |
MetaRepository::getSubClassNames(nameSpace, className, true, classNames); |
_getSubClassNames(nameSpace, className, true, classNames); |
| |
// Get all instances for this class and all descendent classes | // Get all instances for this class and all descendent classes |
| |
|
|
| |
Array<CIMName> classNames; | Array<CIMName> classNames; |
classNames.append(className); | classNames.append(className); |
MetaRepository::getSubClassNames(nameSpace, className, true, classNames); |
_getSubClassNames(nameSpace, className, true, classNames); |
| |
// Get all instances for this class and all descendent classes | // Get all instances for this class and all descendent classes |
| |
|
|
const String& queryLanguage, | const String& queryLanguage, |
const String& query) | const String& query) |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "execQuery()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "execQuery()")); |
return Array<CIMInstance>(); | return Array<CIMInstance>(); |
} | } |
| |
|
|
{ | { |
if (objectName.getKeyBindings().size() == 0) | if (objectName.getKeyBindings().size() == 0) |
{ | { |
return MetaRepository::associatorClasses( |
return _associatorClasses( |
nameSpace, | nameSpace, |
objectName.getClassName(), | objectName.getClassName(), |
assocClass, | assocClass, |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "associators()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "associators()")); |
return Array<CIMObject>(); | return Array<CIMObject>(); |
} | } |
} | } |
|
|
{ | { |
if (objectName.getKeyBindings().size() == 0) | if (objectName.getKeyBindings().size() == 0) |
{ | { |
return MetaRepository::associatorClassPaths( |
return _associatorClassPaths( |
nameSpace, | nameSpace, |
objectName.getClassName(), | objectName.getClassName(), |
assocClass, | assocClass, |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "associatorNames()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "associatorNames()")); |
return Array<CIMObjectPath>(); | return Array<CIMObjectPath>(); |
} | } |
} | } |
|
|
{ | { |
if (objectName.getKeyBindings().size() == 0) | if (objectName.getKeyBindings().size() == 0) |
{ | { |
return MetaRepository::referenceClasses( |
return _referenceClasses( |
nameSpace, | nameSpace, |
objectName.getClassName(), | objectName.getClassName(), |
resultClass, | resultClass, |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "references()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "references()")); |
return Array<CIMObject>(); | return Array<CIMObject>(); |
} | } |
} | } |
|
|
{ | { |
if (objectName.getKeyBindings().size() == 0) | if (objectName.getKeyBindings().size() == 0) |
{ | { |
return MetaRepository::referenceClassPaths( |
return _referenceClassPaths( |
nameSpace, | nameSpace, |
objectName.getClassName(), | objectName.getClassName(), |
resultClass, | resultClass, |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "referenceNames()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "referenceNames()")); |
return Array<CIMObjectPath>(); | return Array<CIMObjectPath>(); |
} | } |
} | } |
|
|
const CIMObjectPath& instanceName, | const CIMObjectPath& instanceName, |
const CIMName& propertyName) | const CIMName& propertyName) |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "getProperty()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "getProperty()")); |
return CIMValue(); | return CIMValue(); |
} | } |
| |
|
|
const CIMValue& newValue, | const CIMValue& newValue, |
const ContentLanguageList& contentLangs) | const ContentLanguageList& contentLangs) |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "setProperty()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "setProperty()")); |
} | } |
| |
CIMQualifierDecl MemoryResidentRepository::getQualifier( | CIMQualifierDecl MemoryResidentRepository::getQualifier( |
|
|
const CIMNamespaceName& nameSpace, | const CIMNamespaceName& nameSpace, |
const CIMName& qualifierName) | const CIMName& qualifierName) |
{ | { |
return MetaRepository::getQualifier(nameSpace, qualifierName); |
return _getQualifier(nameSpace, qualifierName); |
} | } |
| |
void MemoryResidentRepository::setQualifier( | void MemoryResidentRepository::setQualifier( |
|
|
const CIMQualifierDecl& qualifierDecl, | const CIMQualifierDecl& qualifierDecl, |
const ContentLanguageList& contentLangs) | const ContentLanguageList& contentLangs) |
{ | { |
MetaRepository::setQualifier(nameSpace, qualifierDecl); |
Throw((CIM_ERR_NOT_SUPPORTED, "setQualifier()")); |
} | } |
| |
void MemoryResidentRepository::deleteQualifier( | void MemoryResidentRepository::deleteQualifier( |
|
|
const CIMNamespaceName& nameSpace, | const CIMNamespaceName& nameSpace, |
const CIMName& qualifierName) | const CIMName& qualifierName) |
{ | { |
MetaRepository::deleteQualifier(nameSpace, qualifierName); |
Throw((CIM_ERR_NOT_SUPPORTED, "deleteQualifier()")); |
} | } |
| |
Array<CIMQualifierDecl> MemoryResidentRepository::enumerateQualifiers( | Array<CIMQualifierDecl> MemoryResidentRepository::enumerateQualifiers( |
bool lock, | bool lock, |
const CIMNamespaceName& nameSpace) | const CIMNamespaceName& nameSpace) |
{ | { |
return MetaRepository::enumerateQualifiers(nameSpace); |
return _enumerateQualifiers(nameSpace); |
} | } |
| |
void MemoryResidentRepository::createNameSpace( | void MemoryResidentRepository::createNameSpace( |
|
|
const CIMNamespaceName& nameSpace, | const CIMNamespaceName& nameSpace, |
const NameSpaceAttributes& attributes) | const NameSpaceAttributes& attributes) |
{ | { |
MetaRepository::createNameSpace(nameSpace, attributes); |
Throw((CIM_ERR_NOT_SUPPORTED, "createNameSpace()")); |
} | } |
| |
void MemoryResidentRepository::modifyNameSpace( | void MemoryResidentRepository::modifyNameSpace( |
|
|
const CIMNamespaceName& nameSpace, | const CIMNamespaceName& nameSpace, |
const NameSpaceAttributes& attributes) | const NameSpaceAttributes& attributes) |
{ | { |
MetaRepository::createNameSpace(nameSpace, attributes); |
Throw((CIM_ERR_NOT_SUPPORTED, "modifyNameSpace()")); |
} | } |
| |
Array<CIMNamespaceName> MemoryResidentRepository::enumerateNameSpaces( | Array<CIMNamespaceName> MemoryResidentRepository::enumerateNameSpaces( |
bool lock) const | bool lock) const |
{ | { |
return MetaRepository::enumerateNameSpaces(); |
return _enumerateNameSpaces(); |
} | } |
| |
void MemoryResidentRepository::deleteNameSpace( | void MemoryResidentRepository::deleteNameSpace( |
bool lock, | bool lock, |
const CIMNamespaceName& nameSpace) | const CIMNamespaceName& nameSpace) |
{ | { |
MetaRepository::deleteNameSpace(nameSpace); |
Throw((CIM_ERR_NOT_SUPPORTED, "deleteNameSpace()")); |
} | } |
| |
Boolean MemoryResidentRepository::getNameSpaceAttributes( | Boolean MemoryResidentRepository::getNameSpaceAttributes( |
|
|
bool lock, | bool lock, |
RepositoryDeclContext* context) | RepositoryDeclContext* context) |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "setDeclContext()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "setDeclContext()")); |
} | } |
| |
Boolean MemoryResidentRepository::isDefaultInstanceProvider( | Boolean MemoryResidentRepository::isDefaultInstanceProvider( |
|
|
Boolean deepInheritance, | Boolean deepInheritance, |
Array<CIMName>& subClassNames) const | Array<CIMName>& subClassNames) const |
{ | { |
MetaRepository::getSubClassNames( |
_getSubClassNames(nameSpace, className, deepInheritance, subClassNames); |
nameSpace, |
|
className, |
|
deepInheritance, |
|
subClassNames); |
|
} | } |
| |
void MemoryResidentRepository::getSuperClassNames( | void MemoryResidentRepository::getSuperClassNames( |
|
|
const CIMName& className, | const CIMName& className, |
Array<CIMName>& superClassNames) const | Array<CIMName>& superClassNames) const |
{ | { |
MetaRepository::getSuperClassNames( |
_getSuperClassNames(nameSpace, className, superClassNames); |
nameSpace, |
|
className, |
|
superClassNames); |
|
} | } |
| |
Boolean MemoryResidentRepository::isRemoteNameSpace( | Boolean MemoryResidentRepository::isRemoteNameSpace( |
|
|
return PEG_NOT_FOUND; | return PEG_NOT_FOUND; |
} | } |
| |
|
void MemoryResidentRepository::installSaveCallback( |
|
void (*handler)(const Buffer& buffer, void* data), |
|
void * data) |
|
{ |
|
_saveCallback = handler; |
|
_saveData = data; |
|
} |
|
|
|
void MemoryResidentRepository::installLoadCallback( |
|
void (*handler)(Buffer& buffer, void* data), |
|
void * data) |
|
{ |
|
_loadCallback = handler; |
|
_loadData = data; |
|
} |
|
|
|
void MemoryResidentRepository::_processSaveHandler() |
|
{ |
|
if (!_saveCallback) |
|
return; |
|
|
|
Buffer out; |
|
|
|
for (Uint32 i = 0; i < _rep.size(); i++) |
|
{ |
|
SerializeNameSpace(out, _rep[i].first); |
|
SerializeInstance(out, _rep[i].second); |
|
} |
|
|
|
(*_saveCallback)(out, _saveData); |
|
} |
|
|
|
void MemoryResidentRepository::_processLoadHandler() |
|
{ |
|
if (!_loadCallback) |
|
return; |
|
|
|
Buffer in; |
|
(*_loadCallback)(in, _loadData); |
|
size_t pos = 0; |
|
|
|
while (pos != in.size()) |
|
{ |
|
CIMNamespaceName nameSpace; |
|
|
|
if (DeserializeNameSpace(in, pos, nameSpace) != 0) |
|
return; |
|
|
|
CIMInstance cimInstance; |
|
|
|
if (DeserializeInstance(in, pos, cimInstance) != 0) |
|
return; |
|
|
|
_rep.append(NamespaceInstancePair(nameSpace, cimInstance)); |
|
} |
|
} |
|
|
|
Boolean MemoryResidentRepository::addNameSpace(const SchemaNameSpace* nameSpace) |
|
{ |
|
if (!nameSpace) |
|
return false; |
|
|
|
if (_nameSpaceTableSize == _MAX_NAMESPACE_TABLE_SIZE) |
|
return false; |
|
|
|
if (_findNameSpace(nameSpace->name)) |
|
return false; |
|
|
|
_nameSpaceTable[_nameSpaceTableSize++] = nameSpace; |
|
|
|
return true; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |