📄 cimexportclient.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.////==============================================================================//// Author: Mike Brasher (mbrasher@bmc.com)//// Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)// Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)// Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)// Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)// Dan Gorey (djgorey@us.ibm.com)// Seema Gupta (gseema@in.ibm.com) for PEP135// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for PEP#101// John Alex, IBM (johnalex@us.ibm.com) - Bug#2290////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/HTTPConnection.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/TimeValue.h>#include <Pegasus/Common/Exception.h>#include <Pegasus/Common/PegasusVersion.h>#include "CIMExportRequestEncoder.h"#include "CIMExportResponseDecoder.h"#include "CIMExportClient.h"// l10n#include <Pegasus/Common/MessageLoader.h>#include <iostream>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINCIMExportClient::CIMExportClient( Monitor* monitor, HTTPConnector* httpConnector, Uint32 timeoutMilliseconds) : MessageQueue(PEGASUS_QUEUENAME_EXPORTCLIENT), _monitor(monitor), _httpConnector(httpConnector), _httpConnection(0), _timeoutMilliseconds(timeoutMilliseconds), _connected(false), _responseDecoder(0), _requestEncoder(0){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::CIMExportClient()"); PEG_METHOD_EXIT();}CIMExportClient::~CIMExportClient(){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::~CIMExportClient()"); disconnect(); PEG_METHOD_EXIT();}void CIMExportClient::_connect(){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::_connect()"); // Create response decoder: _responseDecoder = new CIMExportResponseDecoder( this, _requestEncoder, &_authenticator); // Attempt to establish a connection: try { _httpConnection = _httpConnector->connect(_connectHost, _connectPortNumber, _connectSSLContext.get(), _responseDecoder); } catch (...) { // Some possible exceptions are CannotCreateSocketException, // CannotConnectException, and InvalidLocatorException delete _responseDecoder; PEG_METHOD_EXIT(); throw; } // Create request encoder: String connectHost = _connectHost; if (connectHost.size()) { char portStr[32]; sprintf(portStr, ":%u", _connectPortNumber); connectHost.append(portStr); } _requestEncoder = new CIMExportRequestEncoder( _httpConnection, connectHost, &_authenticator); _responseDecoder->setEncoderQueue(_requestEncoder); _connected = true; _httpConnection->setSocketWriteTimeout(_timeoutMilliseconds/1000+1); PEG_METHOD_EXIT();}void CIMExportClient::_disconnect(){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::_disconnect()"); if (_connected) { // // destroy response decoder // delete _responseDecoder; _responseDecoder = 0; // // Close the connection // if (_httpConnector) { _httpConnector->disconnect(_httpConnection); _httpConnection = 0; } // // destroy request encoder // delete _requestEncoder; _requestEncoder = 0; _connected = false; } PEG_METHOD_EXIT();}void CIMExportClient::_reconnect(){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::_reconnect()"); _disconnect(); _authenticator.setRequestMessage(0); _connect(); PEG_METHOD_EXIT();}void CIMExportClient::connect( const String& host, const Uint32 portNumber){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::connect()"); // If already connected, bail out! if (_connected) { PEG_METHOD_EXIT(); 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(); _connectSSLContext.reset(0); _connectHost = hostName; _connectPortNumber = portNumber; _connect(); PEG_METHOD_EXIT();}void CIMExportClient::connect( const String& host, const Uint32 portNumber, const SSLContext& sslContext){ PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::connect()"); // If already connected, bail out! if (_connected) { PEG_METHOD_EXIT(); 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(); _connectSSLContext.reset(new SSLContext(sslContext)); _connectHost = hostName; _connectPortNumber = portNumber; try { _connect(); } catch (...) { _connectSSLContext.reset(); PEG_METHOD_EXIT(); throw; } PEG_METHOD_EXIT();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -