version 1.5, 2002/01/08 18:49:50
|
version 1.6, 2002/02/05 19:13:35
|
|
|
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/HTTPMessage.h> | #include <Pegasus/Common/HTTPMessage.h> |
#include <Pegasus/Provider/CIMOMHandle.h> | #include <Pegasus/Provider/CIMOMHandle.h> |
#include <Pegasus/Repository/CIMRepository.h> |
|
| |
#include "CIMExportRequestDispatcher.h" | #include "CIMExportRequestDispatcher.h" |
| |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
CIMExportRequestDispatcher::CIMExportRequestDispatcher( | CIMExportRequestDispatcher::CIMExportRequestDispatcher( |
CIMRepository* repository) |
Boolean dynamicReg, Boolean staticConsumers, Boolean persistence) |
: Base("CIMExportDispatcher", true), _repository(repository) |
: Base("CIMExportDispatcher", true), |
|
_dynamicReg(dynamicReg), |
|
_staticConsumers(staticConsumers), |
|
_persistence(persistence) |
{ | { |
|
_consumerTable.set(_dynamicReg, _staticConsumers, _persistence); |
|
} |
| |
|
CIMExportRequestDispatcher::CIMExportRequestDispatcher() |
|
{ |
} | } |
| |
CIMExportRequestDispatcher::~CIMExportRequestDispatcher() | CIMExportRequestDispatcher::~CIMExportRequestDispatcher() |
|
|
void CIMExportRequestDispatcher::_handleExportIndicationRequest( | void CIMExportRequestDispatcher::_handleExportIndicationRequest( |
CIMExportIndicationRequestMessage* request) | CIMExportIndicationRequestMessage* request) |
{ | { |
// ATTN: This is just demo code |
|
|
|
OperationContext context; | OperationContext context; |
| |
CIMStatusCode errorCode = CIM_ERR_SUCCESS; | CIMStatusCode errorCode = CIM_ERR_SUCCESS; |
String errorDescription; | String errorDescription; |
| |
// REVIEW: CIMIndicationConsumer implementation is tied to provider |
if (request->indicationInstance.getClassName() == |
// interface which makes it unsuable by stand-alone listeners |
"PG_IndicationConsumerRegistration") |
// which aren't CIMOMs and don't have provider interfaces. |
{ |
|
CIMInstance instance = request->indicationInstance; |
|
if (instance.existsProperty("ConsumerId") && |
|
instance.existsProperty("Location") && |
|
instance.existsProperty("ActionType")) |
|
{ |
|
errorCode = _consumerTable.registerConsumer( |
|
instance.getProperty(instance.findProperty("ConsumerId")) |
|
.getValue().toString(), |
|
instance.getProperty(instance.findProperty("Location")) |
|
.getValue().toString(), |
|
instance.getProperty(instance.findProperty("ActionType")) |
|
.getValue().toString(), |
|
errorDescription); |
|
} |
|
else |
|
{ |
|
errorCode = CIM_ERR_FAILED; |
|
errorDescription = "Invalid Consumer registration data"; |
|
} |
|
} |
|
else |
|
{ |
CIMIndicationConsumer* consumer = _lookupConsumer(request->url); | CIMIndicationConsumer* consumer = _lookupConsumer(request->url); |
| |
if (consumer) | if (consumer) |
|
|
{ | { |
throw CIMException(CIM_ERR_FAILED); | throw CIMException(CIM_ERR_FAILED); |
} | } |
|
} |
| |
CIMExportIndicationResponseMessage* response = | CIMExportIndicationResponseMessage* response = |
new CIMExportIndicationResponseMessage( | new CIMExportIndicationResponseMessage( |
|
|
_enqueueResponse(request, response); | _enqueueResponse(request, response); |
} | } |
| |
// REVIEW: this implementation ties the CIMExportRequestDispatcher |
|
// to the CIMOM so that it cannot be used in a standalone listener. |
|
// This belongs in the indication processor. |
|
|
|
void CIMExportRequestDispatcher::handleIndication( |
|
CIMInstance& indicationHandlerInstance, |
|
CIMInstance& indicationInstance, |
|
String nameSpace) |
|
{ |
|
String className = indicationHandlerInstance.getClassName(); |
|
CIMHandler* handler = _lookupHandlerForClass(nameSpace, className); |
|
|
|
if (handler) |
|
{ |
|
handler->handleIndication( |
|
indicationHandlerInstance, |
|
indicationInstance, |
|
nameSpace); |
|
} |
|
else |
|
throw CIMException(CIM_ERR_FAILED); |
|
} |
|
|
|
CIMHandler* CIMExportRequestDispatcher::_lookupHandlerForClass( |
|
const String& nameSpace, |
|
const String& className) |
|
{ |
|
//---------------------------------------------------------------------- |
|
// Look up the class: |
|
//---------------------------------------------------------------------- |
|
|
|
CIMClass cimClass = _repository->getClass(nameSpace, className); |
|
|
|
if (!cimClass) |
|
throw CIMException(CIM_ERR_INVALID_CLASS); |
|
|
|
//---------------------------------------------------------------------- |
|
// Get the handler qualifier: |
|
//---------------------------------------------------------------------- |
|
|
|
Uint32 pos = cimClass.findQualifier("Handler"); |
|
|
|
if (pos == PEG_NOT_FOUND) |
|
return 0; |
|
|
|
CIMQualifier q = cimClass.getQualifier(pos); |
|
String handlerId; |
|
|
|
q.getValue().get(handlerId); |
|
|
|
CIMHandler* handler = _handlerTable.lookupHandler(handlerId); |
|
|
|
if (!handler) |
|
{ |
|
handler = _handlerTable.loadHandler(handlerId); |
|
|
|
if (!handler) |
|
throw CIMException(CIM_ERR_FAILED); |
|
|
|
handler->initialize(_repository); |
|
} |
|
|
|
return handler; |
|
} |
|
|
|
// REVIEW: Why must consumer be dynamically loaded? It makes sense in | // REVIEW: Why must consumer be dynamically loaded? It makes sense in |
// the case in which they are provider (then let the provider manager do it). | // the case in which they are provider (then let the provider manager do it). |
| |
CIMIndicationConsumer* CIMExportRequestDispatcher::_lookupConsumer( | CIMIndicationConsumer* CIMExportRequestDispatcher::_lookupConsumer( |
const String& url) | const String& url) |
{ | { |
//ATTN: How to get NAMESPACE? Defining just to proceed further. |
|
String NAMESPACE = "root/cimv2"; |
|
|
|
Array<CIMNamedInstance> cNamedInst; |
|
cNamedInst = _repository->enumerateInstances(NAMESPACE, |
|
"PG_ConsumerRegistration"); |
|
|
|
String consumerName; |
|
|
|
for (Uint32 i=0; (i < cNamedInst.size()) && (consumerName.size() == 0); i++) |
|
{ |
|
Uint32 urlPropertyPos; |
|
Uint32 consumerPropertyPos; |
|
String consumerUrl; |
|
CIMInstance& cInst = cNamedInst[i].getInstance(); |
|
|
|
urlPropertyPos = cInst.findProperty("url"); |
|
|
|
// Ignore malformed consumer registration |
|
if (urlPropertyPos != PEG_NOT_FOUND) |
|
{ |
|
try |
|
{ |
|
cInst.getProperty(urlPropertyPos).getValue() |
|
.get(consumerUrl); |
|
if (consumerUrl == url) |
|
{ |
|
consumerPropertyPos = cInst.findProperty("consumerName"); |
|
|
|
// Ignore malformed consumer registration |
|
if (consumerPropertyPos != PEG_NOT_FOUND) |
|
{ |
|
// TypeMismatch exception is caught in outer block |
|
cInst.getProperty(consumerPropertyPos).getValue() |
|
.get(consumerName); |
|
} |
|
} |
|
} |
|
catch (TypeMismatch& e) |
|
{ |
|
// Ignore malformed consumer registration |
|
} |
|
} |
|
} |
|
|
|
if (consumerName.size() == 0) |
|
{ |
|
// ATTN: What to do if no consumers are registered for this URL? |
|
throw CIMException(CIM_ERR_FAILED); |
|
} |
|
|
|
CIMIndicationConsumer* consumer = | CIMIndicationConsumer* consumer = |
_consumerTable.lookupConsumer(consumerName); |
_consumerTable.lookupConsumer(url); |
| |
if (!consumer) | if (!consumer) |
{ | { |
consumer = _consumerTable.loadConsumer(consumerName); |
consumer = _consumerTable.loadConsumer(url); |
| |
if (!consumer) | if (!consumer) |
throw CIMException(CIM_ERR_FAILED); | throw CIMException(CIM_ERR_FAILED); |