version 1.1.2.1, 2007/10/05 01:43:41
|
version 1.1.2.5, 2007/11/03 22:42:34
|
|
|
#include "RepositoryDeclContext.h" | #include "RepositoryDeclContext.h" |
#include "MetaRepository.h" | #include "MetaRepository.h" |
#include "Filtering.h" | #include "Filtering.h" |
|
#include "Serialization.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
#define PEGASUS_ARRAY_T NamespaceInstancePair |
|
# include <Pegasus/Common/ArrayImpl.h> |
|
#undef PEGASUS_ARRAY_T |
|
|
//============================================================================== | //============================================================================== |
// | // |
// Local routines: | // Local routines: |
// | // |
//============================================================================== | //============================================================================== |
| |
PEGASUS_FORMAT(2, 3) |
class ThrowContext |
static void _throw(CIMStatusCode code, const char* format, ...) |
|
{ | { |
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 |
{ | { |
|
|
| |
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 & META_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: |
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
|
static void (*_saveCallback)(const Buffer& buffer, void* data); |
|
static void* _saveData; |
|
static void (*_loadCallback)(Buffer& buffer, void* data); |
|
static void* _loadData; |
|
|
MemoryResidentRepository::MemoryResidentRepository( | MemoryResidentRepository::MemoryResidentRepository( |
const String& repositoryRoot, | const String& repositoryRoot, |
Uint32 repositoryMode) | Uint32 repositoryMode) |
: | : |
Repository(repositoryRoot, repositoryMode) | Repository(repositoryRoot, repositoryMode) |
{ | { |
|
// Load users data if any: |
|
_processLoadHandler(); |
} | } |
| |
MemoryResidentRepository::~MemoryResidentRepository() | MemoryResidentRepository::~MemoryResidentRepository() |
|
|
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(); |
| |
|
|
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( |
|
|
// 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; |
} | } |
|
|
| |
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( |
|
|
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>(); |
} | } |
| |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "associators()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "associators()")); |
return Array<CIMObject>(); | return Array<CIMObject>(); |
} | } |
} | } |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "associatorNames()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "associatorNames()")); |
return Array<CIMObjectPath>(); | return Array<CIMObjectPath>(); |
} | } |
} | } |
|
|
} | } |
else | else |
{ | { |
_throw(CIM_ERR_NOT_SUPPORTED, "references()"); |
Throw((CIM_ERR_NOT_SUPPORTED, "references()")); |
return Array<CIMObject>(); | return Array<CIMObject>(); |
} | } |
} | } |
|
|
} | } |
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( |
|
|
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( |
|
|
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)); |
|
} |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |