⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimclientrep.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
CIMValue CIMClientRep::getProperty(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName,    const CIMName& propertyName){    AutoPtr<CIMRequestMessage> request(new CIMGetPropertyRequestMessage(        String::EMPTY,        nameSpace,        instanceName,        propertyName,        QueueIdStack()));    Message* message = _doRequest(request, CIM_GET_PROPERTY_RESPONSE_MESSAGE);    CIMGetPropertyResponseMessage* response =        (CIMGetPropertyResponseMessage*)message;    AutoPtr<CIMGetPropertyResponseMessage> destroyer(response);    return response->value;}void CIMClientRep::setProperty(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName,    const CIMName& propertyName,    const CIMValue& newValue){    AutoPtr<CIMRequestMessage> request(new CIMSetPropertyRequestMessage(        String::EMPTY,        nameSpace,        instanceName,        propertyName,        newValue,        QueueIdStack()));    Message* message = _doRequest(request, CIM_SET_PROPERTY_RESPONSE_MESSAGE);    CIMSetPropertyResponseMessage* response =        (CIMSetPropertyResponseMessage*)message;    AutoPtr<CIMSetPropertyResponseMessage> destroyer(response);}CIMQualifierDecl CIMClientRep::getQualifier(    const CIMNamespaceName& nameSpace,    const CIMName& qualifierName){    AutoPtr<CIMRequestMessage> request(new CIMGetQualifierRequestMessage(        String::EMPTY,        nameSpace,        qualifierName,        QueueIdStack()));    Message* message = _doRequest(request, CIM_GET_QUALIFIER_RESPONSE_MESSAGE);    CIMGetQualifierResponseMessage* response =        (CIMGetQualifierResponseMessage*)message;    AutoPtr<CIMGetQualifierResponseMessage> destroyer(response);    return response->cimQualifierDecl;}void CIMClientRep::setQualifier(    const CIMNamespaceName& nameSpace,    const CIMQualifierDecl& qualifierDeclaration){    AutoPtr<CIMRequestMessage> request(new CIMSetQualifierRequestMessage(        String::EMPTY,        nameSpace,        qualifierDeclaration,        QueueIdStack()));    Message* message = _doRequest(request, CIM_SET_QUALIFIER_RESPONSE_MESSAGE);    CIMSetQualifierResponseMessage* response =        (CIMSetQualifierResponseMessage*)message;    AutoPtr<CIMSetQualifierResponseMessage> destroyer(response);}void CIMClientRep::deleteQualifier(    const CIMNamespaceName& nameSpace,    const CIMName& qualifierName){    AutoPtr<CIMRequestMessage> request(new CIMDeleteQualifierRequestMessage(        String::EMPTY,        nameSpace,        qualifierName,        QueueIdStack()));    Message* message =        _doRequest(request, CIM_DELETE_QUALIFIER_RESPONSE_MESSAGE);    CIMDeleteQualifierResponseMessage* response =        (CIMDeleteQualifierResponseMessage*)message;    AutoPtr<CIMDeleteQualifierResponseMessage> destroyer(response);}Array<CIMQualifierDecl> CIMClientRep::enumerateQualifiers(    const CIMNamespaceName& nameSpace){    AutoPtr<CIMRequestMessage> request(new CIMEnumerateQualifiersRequestMessage(        String::EMPTY,        nameSpace,        QueueIdStack()));    Message* message =        _doRequest(request, CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE);    CIMEnumerateQualifiersResponseMessage* response =        (CIMEnumerateQualifiersResponseMessage*)message;    AutoPtr<CIMEnumerateQualifiersResponseMessage> destroyer(response);    return response->qualifierDeclarations;}CIMValue CIMClientRep::invokeMethod(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName,    const CIMName& methodName,    const Array<CIMParamValue>& inParameters,    Array<CIMParamValue>& outParameters){    // ATTN-RK-P2-20020301: Does it make sense to have a nameSpace parameter    // when the namespace should already be included in the instanceName?    // ATTN-RK-P3-20020301: Do we need to make sure the caller didn't specify    // a host name in the instanceName?    // solved with PEP#139 Stage1 as other CIMOMs contained in the object path    // will cause a TypeMisMatchException    AutoPtr<CIMRequestMessage> request(new CIMInvokeMethodRequestMessage(        String::EMPTY,        nameSpace,        instanceName,        methodName,        inParameters,        QueueIdStack()));    Message* message = _doRequest(request, CIM_INVOKE_METHOD_RESPONSE_MESSAGE);    CIMInvokeMethodResponseMessage* response =        (CIMInvokeMethodResponseMessage*)message;    AutoPtr<CIMInvokeMethodResponseMessage> destroyer(response);    outParameters = response->outParameters;    return response->retValue;}Message* CIMClientRep::_doRequest(    AutoPtr<CIMRequestMessage>& request,    const Uint32 expectedResponseMessageType){    if (!_connected)    {        request.reset();        throw NotConnectedException();    }    String messageId = XmlWriter::getNextMessageId();    const_cast<String &>(request->messageId) = messageId;    _authenticator.setRequestMessage(0);    // ATTN-RK-P2-20020416: We should probably clear out the queue first.    PEGASUS_ASSERT(getCount() == 0);  // Shouldn't be any messages in our queue    //    //  Set HTTP method in request to POST    //    //Bug 478/418 - Change this to do post call, not mpost    request->setHttpMethod (HTTP_METHOD__POST);    // Set the Accept-Languages and Content-Languages into    // the request message    request->operationContext.set(        AcceptLanguageListContainer(requestAcceptLanguages));    request->operationContext.set(        ContentLanguageListContainer(requestContentLanguages));    //gathering statistical information about client operation    perfDataStore.reset();    perfDataStore.setOperationType(request->getType());    perfDataStore.setMessageID(request->messageId);    // Sending a new request, so clear out the response Content-Languages    responseContentLanguages.clear();    _requestEncoder->enqueue(request.get());    request.release();    Uint64 startMilliseconds = TimeValue::getCurrentTime().toMilliseconds();    Uint64 nowMilliseconds = startMilliseconds;    Uint64 stopMilliseconds = nowMilliseconds + _timeoutMilliseconds;    while (nowMilliseconds < stopMilliseconds)    {        //        // Wait until the timeout expires or an event occurs:        //        _monitor->run(Uint32(stopMilliseconds - nowMilliseconds));        //        // Check to see if incoming queue has a message        //        Message* response = dequeue();        if (response)        {            // Shouldn't be any more messages in our queue            PEGASUS_ASSERT(getCount() == 0);            //            // Reconnect to reset the connection            // if Server response contained a Connection: Close Header            //            if (response->getCloseConnect() == true)            {                _reconnect();                response->setCloseConnect(false);            }            //            //  Future:  If M-POST is used and HTTP response is 501 Not            //  Implemented or 510 Not Extended, retry with POST method            //            if (response->getType() == CLIENT_EXCEPTION_MESSAGE)            {                Exception* clientException =                    ((ClientExceptionMessage*)response)->clientException;                delete response;                AutoPtr<Exception> d(clientException);                // Make the ContentLanguage of the exception available through                // the CIMClient API (its also available in the exception).                responseContentLanguages =                    clientException->getContentLanguages();                //                // Determine and throw the specific class of client exception                //                CIMClientMalformedHTTPException* malformedHTTPException =                    dynamic_cast<CIMClientMalformedHTTPException*>(                        clientException);                if (malformedHTTPException)                {                    throw *malformedHTTPException;                }                CIMClientHTTPErrorException* httpErrorException =                    dynamic_cast<CIMClientHTTPErrorException*>(                        clientException);                if (httpErrorException)                {                    throw *httpErrorException;                }                CIMClientXmlException* xmlException =                    dynamic_cast<CIMClientXmlException*>(clientException);                if (xmlException)                {                    throw *xmlException;                }                CIMClientResponseException* responseException =                    dynamic_cast<CIMClientResponseException*>(clientException);                if (responseException)                {                    throw *responseException;                }                CIMException* cimException =                    dynamic_cast<CIMException*>(clientException);                if (cimException)                {                    throw *cimException;                }                throw *clientException;            }            else if (response->getType() == expectedResponseMessageType)            {                CIMResponseMessage* cimResponse = (CIMResponseMessage*)response;                if (cimResponse->messageId != messageId)                {                    MessageLoaderParms mlParms(                        "Client.CIMClient.MISMATCHED_RESPONSE",                        "Mismatched response message ID:  Got \"$0\", "                            "expected \"$1\".",                        cimResponse->messageId, messageId);                    String mlString(MessageLoader::getMessage(mlParms));                    CIMClientResponseException responseException(mlString);                    delete response;                    throw responseException;                }                // Get the Content-Languages from the response's                // operationContext and make available through the                // CIMClient API                responseContentLanguages = ((ContentLanguageListContainer)                    cimResponse->operationContext.get(                        ContentLanguageListContainer::NAME)).getLanguages();                if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS)                {                    CIMException cimException(cimResponse->cimException);                    cimException.setContentLanguages(responseContentLanguages);                    delete response;                    throw cimException;                }                // if execution gets here everytihng is working correctly                // and a proper response was generated and received.                // Check that client side statistics are valid before                // handing them to the client application via a call back                Boolean re_check = perfDataStore.checkMessageIDandType(                    cimResponse->messageId,                    cimResponse->getType());                if (re_check &&                    !perfDataStore.getStatError() &&                    perfDataStore.isClassRegistered())                {                   // If callback method throws an exception it will be seen                   // by the client no try/catch block is used here                   // intentionaly - because exceptions come from the client                   // application so client app. should handle them                   ClientOpPerformanceData item =                       perfDataStore.createPerfDataStruct();                   perfDataStore.handler_prt->handleClientOpPerformanceData(                       item);                }//end of if statmet that call the callback method                return response;            }            else if (dynamic_cast<CIMRequestMessage*>(response) != 0)            {                // Respond to an authentication challenge                _requestEncoder->enqueue(response);                nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();                stopMilliseconds = nowMilliseconds + _timeoutMilliseconds;                continue;            }            else            {                MessageLoaderParms mlParms(                    "Client.CIMOperationResponseDecoder."                        "MISMATCHED_RESPONSE_TYPE",                    "Mismatched response message type.");                String mlString(MessageLoader::getMessage(mlParms));                CIMClientResponseException responseException(mlString);                delete response;                throw responseException;            }        }        nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();        Threads::yield();    }    //    // Reconnect to reset the connection (disregard late response)    //    try    {        _reconnect();    }    catch (...)    {    }    //    // Throw timed out exception:    //    throw ConnectionTimeoutException();}String CIMClientRep::_getLocalHostName(){    static String hostname;    if (!hostname.size())    {        hostname.assign(System::getHostName());    }    return hostname;}void CIMClientRep::registerClientOpPerformanceDataHandler(    ClientOpPerformanceDataHandler& handler){    perfDataStore.handler_prt = &handler;    perfDataStore.setClassRegistered(true);}void CIMClientRep::deregisterClientOpPerformanceDataHandler(){    perfDataStore.handler_prt = NULL;    perfDataStore.setClassRegistered(false);}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -