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

📄 cimclientrep.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//%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 "CIMClientRep.h"#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/LanguageParser.h>#include <iostream>#include <fstream>#include <Pegasus/Common/Network.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN/////////////////////////////////////////////////////////////////////////////////// CIMClientRep/////////////////////////////////////////////////////////////////////////////////CIMClientRep::CIMClientRep(Uint32 timeoutMilliseconds)    :    MessageQueue(PEGASUS_QUEUENAME_CLIENT),    _timeoutMilliseconds(timeoutMilliseconds),    _connected(false){    //    // Create Monitor and HTTPConnector    //    _monitor.reset(new Monitor());    _httpConnector.reset(new HTTPConnector(_monitor.get()));    requestAcceptLanguages.clear();    requestContentLanguages.clear();}CIMClientRep::~CIMClientRep(){   disconnect();}void CIMClientRep::handleEnqueue(){}Uint32 _getShowType(String& s){    String log = "log";    String con = "con";    String both = "both";    if (s == log)        return 2;    if (s == con)        return 1;    if (s == both)        return 3;    return 0;}void CIMClientRep::_connect(){    //    // Test for Display optons of the form    // Use Env variable PEGASUS_CLIENT_TRACE= <intrace> : <outtrace    // intrace = "con" | "log" | "both"    // outtrace = intrace    // ex set PEGASUS_CLIENT_TRACE=BOTH:BOTH traces input and output    // to console and log    // Keywords are case insensitive.    // PEP 90    //    Uint32 showOutput = 0;    Uint32 showInput = 0;#ifdef PEGASUS_CLIENT_TRACE_ENABLE    String input;    if (char * envVar = getenv("PEGASUS_CLIENT_TRACE"))    {        input = envVar;        input.toLower();        String io = String::EMPTY;        Uint32 pos = input.find(':');        if (pos == PEG_NOT_FOUND)            pos = 0;        else            io = input.subString(0,pos);        // some compilers do not allow temporaries to be passed to a        // reference argument - so break into 2 lines        String out = input.subString(pos + 1);        showOutput = _getShowType(out);        showInput = _getShowType(io);    }#endif    //    // Create response decoder:    //    AutoPtr<CIMOperationResponseDecoder> responseDecoder(        new CIMOperationResponseDecoder(            this, _requestEncoder.get(), &_authenticator, showInput));    //    // Attempt to establish a connection:    //    AutoPtr<HTTPConnection> httpConnection(_httpConnector->connect(        _connectHost,        _connectPortNumber,        _connectSSLContext.get(),        responseDecoder.get()));    //    // Create request encoder:    //    String connectHost = _connectHost;    if (connectHost.size())    {        char portStr[32];        sprintf(portStr, ":%u", _connectPortNumber);        connectHost.append(portStr);    }    AutoPtr<CIMOperationRequestEncoder> requestEncoder(        new CIMOperationRequestEncoder(            httpConnection.get(), connectHost, &_authenticator, showOutput));    _responseDecoder.reset(responseDecoder.release());    _httpConnection = httpConnection.release();    _requestEncoder.reset(requestEncoder.release());    _responseDecoder->setEncoderQueue(_requestEncoder.get());    //pass encoder and decoder a pointer to CIMClientRep::perfDataStore    _requestEncoder->setDataStorePointer(&perfDataStore);    _responseDecoder->setDataStorePointer(&perfDataStore);    _connected = true;    _httpConnection->setSocketWriteTimeout(_timeoutMilliseconds/1000+1);}void CIMClientRep::_disconnect(){    if (_connected)    {        //        // destroy response decoder        //        _responseDecoder.reset();        //        // Close the connection        //        if (_httpConnector.get())        {            _httpConnector->disconnect(_httpConnection);            _httpConnection = 0;        }        //        // destroy request encoder        //        _requestEncoder.reset();        _connected = false;    }}void CIMClientRep::_reconnect(){    _disconnect();    _authenticator.clearReconnect();    _connect();}void CIMClientRep::connect(    const String& host,    const Uint32 portNumber,    const String& userName,    const String& password){    //    // If already connected, bail out!    //    if (_connected)        throw AlreadyConnectedException();    //    // If the host is empty, set hostName to "localhost"    //    String hostName = host;    if (host == String::EMPTY)    {        hostName = "localhost";    }    //    // Set authentication information    //    _authenticator.clear();    if (userName.size())    {        _authenticator.setUserName(userName);    }    if (password.size())    {        _authenticator.setPassword(password);    }    _connectSSLContext.reset();    _connectHost = hostName;    _connectPortNumber = portNumber;    _connect();}void CIMClientRep::connect(    const String& host,    const Uint32 portNumber,    const SSLContext& sslContext,    const String& userName,    const String& password){    //    // If already connected, bail out!    //    if (_connected)        throw AlreadyConnectedException();    //    // If the host is empty, set hostName to "localhost"    //    String hostName = host;    if (host == String::EMPTY)    {        hostName = "localhost";    }    //    // Set authentication information    //    _authenticator.clear();    if (userName.size())    {        _authenticator.setUserName(userName);    }    if (password.size())    {        _authenticator.setPassword(password);    }    _connectHost = hostName;    _connectPortNumber = portNumber;    _connectSSLContext.reset(new SSLContext(sslContext));    _connect();}void CIMClientRep::connectLocal(){    //    // If already connected, bail out!    //    if (_connected)        throw AlreadyConnectedException();    //    // Set authentication type    //    _authenticator.clear();    _authenticator.setAuthType(ClientAuthenticator::LOCAL);#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET    _connectSSLContext.reset();    _connectHost = String::EMPTY;    _connectPortNumber = 0;    _connect();#else    try    {        //        // Look up the WBEM HTTP port number for the local system        //        _connectPortNumber = System::lookupPort (WBEM_HTTP_SERVICE_NAME,            WBEM_DEFAULT_HTTP_PORT);        //        //  Assign host        //        _connectHost.assign(_getLocalHostName());        _connectSSLContext.reset();        _connect();    }    catch (const CannotConnectException &)    {        //        // Look up the WBEM HTTPS port number for the local system        //        _connectPortNumber = System::lookupPort (WBEM_HTTPS_SERVICE_NAME,            WBEM_DEFAULT_HTTPS_PORT);        //        //  Assign host        //        _connectHost.assign(_getLocalHostName());        //        // Create SSLContext        //#ifdef PEGASUS_OS_OS400#pragma convert(37)        const char* env = getenv("PEGASUS_HOME");#pragma convert(0)        char pegasusHome[256] = {0};        if (env != NULL && strlen(env) < 256)        {            strcpy(pegasusHome, env);            EtoA(pegasusHome);        }#else        const char* pegasusHome = getenv("PEGASUS_HOME");#endif        String randFile = String::EMPTY;#ifdef PEGASUS_SSL_RANDOMFILE        randFile = FileSystem::getAbsolutePath(            pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);#endif        try        {            _connectSSLContext.reset(                new SSLContext(String::EMPTY, NULL, randFile));        }        catch (const SSLException &)        {            throw;        }        _connect();    }#endif}void CIMClientRep::disconnect(){    _disconnect();    _authenticator.clear();    _connectSSLContext.reset();}Boolean CIMClientRep::isConnected() const throw(){    return _connected;}AcceptLanguageList CIMClientRep::getRequestAcceptLanguages() const{    return requestAcceptLanguages;}ContentLanguageList CIMClientRep::getRequestContentLanguages() const{    return requestContentLanguages;}ContentLanguageList CIMClientRep::getResponseContentLanguages() const{    return responseContentLanguages;}void CIMClientRep::setRequestAcceptLanguages(const AcceptLanguageList& langs){    requestAcceptLanguages = langs;}void CIMClientRep::setRequestContentLanguages(const ContentLanguageList& langs){    requestContentLanguages = langs;}void CIMClientRep::setRequestDefaultLanguages(){

⌨️ 快捷键说明

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