📄 internalcimomhandlerep.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/Thread.h>#include <Pegasus/Common/CIMMessage.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/AutoPtr.h>#ifdef PEGASUS_OS_OS400#include <qycmutilu2.H>#include "OS400ConvertChar.h"#include "CIMOMHandleOS400UserState.h"#include "CIMOMHandleOS400SystemState.h"#endif#include "InternalCIMOMHandleRep.h"PEGASUS_NAMESPACE_BEGINInternalCIMOMHandleMessageQueue::InternalCIMOMHandleMessageQueue() : MessageQueue(PEGASUS_QUEUENAME_INTERNALCLIENT), _output_qid(0), _return_qid(0), _response(0){ // output queue is the binary message handler MessageQueue* out = MessageQueue::lookup(PEGASUS_QUEUENAME_BINARY_HANDLER); PEGASUS_ASSERT(out != 0); _output_qid = out->getQueueId(); // input queue is this _return_qid = getQueueId();}InternalCIMOMHandleMessageQueue::~InternalCIMOMHandleMessageQueue(){ try { // ATTN: release any unprocessed responses _response.clear(); } catch (...) { }}void InternalCIMOMHandleMessageQueue::handleEnqueue(){ PEG_METHOD_ENTER(TRC_CIMOM_HANDLE, "InternalCIMOMHandleMessageQueue::handleEnqueue"); Message* message = dequeue(); switch(message->getType()) { /* case CIM_GET_CLASS_REQUEST_MESSAGE: case CIM_ENUMERATE_CLASSES_REQUEST_MESSAGE: case CIM_ENUMERATE_CLASS_NAMES_REQUEST_MESSAGE: case CIM_CREATE_CLASS_REQUEST_MESSAGE: case CIM_MODIFY_CLASS_REQUEST_MESSAGE: case CIM_DELETE_CLASS_REQUEST_MESSAGE: case CIM_GET_INSTANCE_REQUEST_MESSAGE: case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE: case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE: case CIM_CREATE_INSTANCE_REQUEST_MESSAGE: case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE: case CIM_DELETE_INSTANCE_REQUEST_MESSAGE: case CIM_EXEC_QUERY_REQUEST_MESSAGE: case CIM_ASSOCIATORS_REQUEST_MESSAGE: case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE: case CIM_REFERENCES_REQUEST_MESSAGE: case CIM_REFERENCE_NAMES_REQUEST_MESSAGE: case CIM_GET_PROPERTY_REQUEST_MESSAGE: case CIM_SET_PROPERTY_REQUEST_MESSAGE: case CIM_INVOKE_METHOD_REQUEST_MESSAGE: sendRequest(message); break; */ case CIM_GET_CLASS_RESPONSE_MESSAGE: case CIM_ENUMERATE_CLASSES_RESPONSE_MESSAGE: case CIM_ENUMERATE_CLASS_NAMES_RESPONSE_MESSAGE: case CIM_CREATE_CLASS_RESPONSE_MESSAGE: case CIM_MODIFY_CLASS_RESPONSE_MESSAGE: case CIM_DELETE_CLASS_RESPONSE_MESSAGE: case CIM_GET_INSTANCE_RESPONSE_MESSAGE: case CIM_ENUMERATE_INSTANCES_RESPONSE_MESSAGE: case CIM_ENUMERATE_INSTANCE_NAMES_RESPONSE_MESSAGE: case CIM_CREATE_INSTANCE_RESPONSE_MESSAGE: case CIM_MODIFY_INSTANCE_RESPONSE_MESSAGE: case CIM_DELETE_INSTANCE_RESPONSE_MESSAGE: case CIM_EXEC_QUERY_RESPONSE_MESSAGE: case CIM_ASSOCIATORS_RESPONSE_MESSAGE: case CIM_ASSOCIATOR_NAMES_RESPONSE_MESSAGE: case CIM_REFERENCES_RESPONSE_MESSAGE: case CIM_REFERENCE_NAMES_RESPONSE_MESSAGE: case CIM_GET_PROPERTY_RESPONSE_MESSAGE: case CIM_SET_PROPERTY_RESPONSE_MESSAGE: case CIM_INVOKE_METHOD_RESPONSE_MESSAGE: _response.enqueue(message); break; default: PEG_TRACE_STRING( TRC_DISCARDED_DATA, Tracer::LEVEL2, "Error: unexpected message type"); delete message; break; } PEG_METHOD_EXIT();}CIMResponseMessage* InternalCIMOMHandleMessageQueue::sendRequest( CIMRequestMessage* request){ PEG_METHOD_ENTER(TRC_CIMOM_HANDLE, "InternalCIMOMHandleRep::sendRequest"); AutoMutex autoMutex(_mutex); // update message to include routing information request->dest = _output_qid; request->queueIds.push(_return_qid); request->queueIds.push(_output_qid); // locate destination MessageQueueService* service = dynamic_cast<MessageQueueService *>( MessageQueue::lookup(_output_qid)); PEGASUS_ASSERT(service != 0); // forward request if (service->SendForget(request) == false) { PEG_METHOD_EXIT(); throw Exception("Failed to send message"); } // wait for response CIMResponseMessage* response = dynamic_cast<CIMResponseMessage *>(_response.dequeue_wait()); PEG_METHOD_EXIT(); return response;}static void _deleteContentLanguage(void* data){ if (data != 0) { ContentLanguageList* cl = static_cast<ContentLanguageList*>(data); delete cl; }}static OperationContext _filterOperationContext(const OperationContext& context){ OperationContext temp;#ifdef PEGASUS_OS_OS400 // on OS/400, do not allow the provider set the user name for the request // get the user name from the current thread. char os400UserName[11]; if (ycmGetCurrentUser(os400UserName) == 0) { throw CIMException(CIM_ERR_FAILED, MessageLoaderParms( "Common.CIMOMHandleOS400UserState.UNKNOWN_ERROR", "An internal error occurred during the processing of the " "CIMOM handle")); } EtoA(os400UserName); temp.insert(IdentityContainer(String(os400UserName)));#else if (context.contains(IdentityContainer::NAME)) { // propagate the identity container if it exists (get() with throw // an exception if it does not) temp.insert(context.get(IdentityContainer::NAME)); } else { temp.insert(IdentityContainer(String::EMPTY)); }#endif if (context.contains(AcceptLanguageListContainer::NAME)) { // propagate the accept languages container if it exists // (get() with throw an exception if it does not exist) temp.insert(context.get(AcceptLanguageListContainer::NAME)); } else { // If the container is not found then try to use the // AcceptLanguageList from the current thread AcceptLanguageList* pal = Thread::getLanguages(); if (pal != 0) { temp.insert(AcceptLanguageListContainer(*pal)); } else { temp.insert(AcceptLanguageListContainer(AcceptLanguageList())); } } if (context.contains(ContentLanguageListContainer::NAME)) { // propagate the accept languages container if it exists // (get() with throw an exception if it does not) temp.insert(context.get(ContentLanguageListContainer::NAME)); } else { temp.insert(ContentLanguageListContainer(ContentLanguageList())); } return temp;}InternalCIMOMHandleRep::InternalCIMOMHandleRep(){}InternalCIMOMHandleRep::~InternalCIMOMHandleRep(){}#ifdef PEGASUS_OS_OS400InternalCIMOMHandleRep::InternalCIMOMHandleRep(Uint32 os400UserStateKey) : _chOS400(os400UserStateKey){}void InternalCIMOMHandleRep::setOS400ProfileHandle(const char* profileHandle){ memcpy(os400PH, profileHandle, 12);}#endifCIMResponseMessage* InternalCIMOMHandleRep::do_request( CIMRequestMessage* request){ PEG_METHOD_ENTER(TRC_CIMOM_HANDLE, "InternalCIMOMHandleRep::do_request");#ifdef PEGASUS_OS_OS400 // On OS/400, this code runs in a system state thread. Swap the // thread profile to be able to access server resources. if (CIMOMHandleOS400SystemState::setProfileHandle(os400PH) != CIM_ERR_SUCCESS) { PEG_METHOD_EXIT(); throw Exception("Could not set profile handle"); }#endif /* Uint32 timeout = 0; try { const TimeoutContainer* p = dynamic_cast<const TimeoutContainer*>( &(context.get(TimeoutContainer::NAME))); if (p) { timeout = p->getTimeOut(); } } catch (Exception &) { } try { if (timeout) { _msg_avail.time_wait(timeout); } else { _msg_avail.wait(); } } catch (TimeOut&) { PEG_TRACE_STRING(TRC_CIMOM_HANDLE, Tracer::LEVEL2, "timeout waiting for response"); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Provider.CIMOMHandle.EMPTY_CIM_RESPONSE", "Empty CIM Response")); } catch (...) { PEG_TRACE_STRING(TRC_CIMOM_HANDLE, Tracer::LEVEL2, "Unexpected Exception"); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Provider.CIMOMHandle.EMPTY_CIM_RESPONSE", "Empty CIM Response")); } */ Message* temp = _queue.sendRequest(request); CIMResponseMessage* response = dynamic_cast<CIMResponseMessage*>(temp); if (response == 0) { delete response; PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Provider.CIMOMHandle.EMPTY_CIM_RESPONSE", "Empty CIM Response")); } if (response->cimException.getCode() != CIM_ERR_SUCCESS) { CIMException e(response->cimException); delete response; PEG_METHOD_EXIT(); throw e; } if (response->operationContext.contains(ContentLanguageListContainer::NAME)) { // If the response has a Content-Language then save it into // thread-specific storage ContentLanguageListContainer container = response->operationContext.get(ContentLanguageListContainer::NAME); if (container.getLanguages().size() > 0) { Thread* currentThread = Thread::getCurrent(); if (currentThread != 0) { // deletes the old tsd and creates a new one currentThread->put_tsd( "cimomHandleContentLanguages", _deleteContentLanguage, sizeof(ContentLanguageList*), new ContentLanguageList(container.getLanguages())); } } } PEG_METHOD_EXIT(); return response;}//// CIM Operations//CIMClass InternalCIMOMHandleRep::getClass( const OperationContext & context, const CIMNamespaceName& nameSpace, const CIMName& className, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList){ PEG_METHOD_ENTER(TRC_CIMOM_HANDLE, "InternalCIMOMHandleRep::getClass");#ifdef PEGASUS_OS_OS400 // If this is running in user-state, then run the request // through the user-state layer if (_chOS400.hasKey()) { CIMClass cimClass = _chOS400.getClass( context, nameSpace, className, localOnly, includeQualifiers, includeClassOrigin, propertyList); PEG_METHOD_EXIT(); return cimClass; }#endif // encode request CIMGetClassRequestMessage* request = new CIMGetClassRequestMessage( XmlWriter::getNextMessageId(), nameSpace, className, localOnly, includeQualifiers, includeClassOrigin, propertyList, QueueIdStack()); // copy and adjust, as needed, the operation context request->operationContext = _filterOperationContext(context);// request->operationContext.get(AcceptLanguageListContainer::NAME); AutoPtr<CIMGetClassResponseMessage> response; try { response.reset(dynamic_cast<CIMGetClassResponseMessage*>( do_request(request))); if (response.get() == 0) { PEG_TRACE_STRING( TRC_CIMOM_HANDLE, Tracer::LEVEL2, "Incorrect response type in CIMOMHandle"); throw CIMException(CIM_ERR_FAILED); } } catch (CIMException &) { PEG_METHOD_EXIT(); throw; } catch (...) { PEG_TRACE_STRING( TRC_CIMOM_HANDLE, Tracer::LEVEL2, "Exception caught in CIMOMHandle"); PEG_METHOD_EXIT(); throw CIMException(CIM_ERR_FAILED, MessageLoaderParms( "Provider.CIMOMHandle.CAUGHT_EXCEPTION", "Exception caught in CIMOMHandle")); } CIMClass cimClass = response->cimClass; PEG_METHOD_EXIT(); return cimClass;}Array<CIMClass> InternalCIMOMHandleRep::enumerateClasses( const OperationContext & context, const CIMNamespaceName& nameSpace, const CIMName& className, Boolean deepInheritance, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin){ PEG_METHOD_ENTER(TRC_CIMOM_HANDLE, "InternalCIMOMHandleRep::enumerateClasses");#ifdef PEGASUS_OS_OS400 // If this is running in user-state, then run the request // through the user-state layer if (_chOS400.hasKey()) { Array<CIMClass> cimClasses = _chOS400.enumerateClasses( context, nameSpace, className, deepInheritance, localOnly, includeQualifiers, includeClassOrigin); PEG_METHOD_EXIT(); return cimClasses; }#endif CIMEnumerateClassesRequestMessage* request = new CIMEnumerateClassesRequestMessage( XmlWriter::getNextMessageId(), nameSpace, className, deepInheritance, localOnly, includeQualifiers, includeClassOrigin, QueueIdStack()); // copy and adjust, as needed, the operation context request->operationContext = _filterOperationContext(context);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -