1 //%/////////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //==============================================================================
24 // Author: Mike Brasher (mbrasher@bmc.com)
26 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
28 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
30 //%/////////////////////////////////////////////////////////////////////////////
32 #include <Pegasus/Common/Config.h>
33 #include <Pegasus/Common/HTTPConnection.h>
34 #include <Pegasus/Common/Destroyer.h>
35 #include <Pegasus/Common/XmlWriter.h>
36 #include <Pegasus/Common/TimeValue.h>
37 #include <Pegasus/Common/Exception.h>
38 #include "CIMExportRequestEncoder.h"
39 #include "CIMExportResponseDecoder.h"
40 #include "CIMExportClient.h"
46 PEGASUS_NAMESPACE_BEGIN
48 CIMExportClient::CIMExportClient(
50 HTTPConnector* httpConnector,
51 Uint32 timeOutMilliseconds)
53 Base("CIMExportClient", MessageQueue::getNextQueueId()),
55 _httpConnector(httpConnector),
56 _timeOutMilliseconds(timeOutMilliseconds),
62 // Create client authenticator
64 _authenticator = new ClientAuthenticator();
67 CIMExportClient::~CIMExportClient()
69 delete _authenticator;
72 void CIMExportClient::handleEnqueue(Message *message)
80 void CIMExportClient::handleEnqueue()
85 const char* CIMExportClient::getQueueName() const
87 return "CIMExportClient";
90 void CIMExportClient::connect(const String& address)
92 // If already connected, bail out!
95 throw AlreadyConnected();
97 // Create response decoder:
99 _responseDecoder = new CIMExportResponseDecoder(
100 this, _requestEncoder, _authenticator);
102 // Attempt to establish a connection:
104 HTTPConnection* httpConnection;
108 httpConnection = _httpConnector->connect(address, _responseDecoder);
112 delete _responseDecoder;
116 // Create request encoder:
118 _requestEncoder = new CIMExportRequestEncoder(
119 httpConnection, _authenticator);
121 _responseDecoder->setEncoderQueue(_requestEncoder);
126 void CIMExportClient::connectLocal(const String& address, const String& userName)
130 _authenticator->setUserName(userName);
132 _authenticator->setAuthType(ClientAuthenticator::LOCAL);
137 void CIMExportClient::exportIndication(
139 const CIMInstance& instanceName)
141 String messageId = XmlWriter::getNextMessageId();
144 Message* request = new CIMExportIndicationRequestMessage(
150 _authenticator->clearRequest();
152 _requestEncoder->enqueue(request);
154 Message* message = _waitForResponse(
155 CIM_EXPORT_INDICATION_RESPONSE_MESSAGE, messageId);
157 CIMExportIndicationResponseMessage* response =
158 (CIMExportIndicationResponseMessage*)message;
160 Destroyer<CIMExportIndicationResponseMessage> destroyer(response);
162 _checkError(response);
164 //return(response->cimClass);
167 Message* CIMExportClient::_waitForResponse(
168 const Uint32 messageType,
169 const String& messageId,
170 const Uint32 timeOutMilliseconds)
173 throw NotConnected();
175 long rem = long(timeOutMilliseconds);
180 // Wait until the timeout expires or an event occurs:
183 TimeValue start = TimeValue::getCurrentTime();
185 TimeValue stop = TimeValue::getCurrentTime();
188 // Check to see if incoming queue has a message of the appropriate
189 // type with the given message id:
192 Message* message = findByType(messageType);
196 CIMResponseMessage* responseMessage = (CIMResponseMessage*)message;
198 if (responseMessage->messageId == messageId)
200 remove(responseMessage);
201 return responseMessage;
206 // Terminate loop if timed out:
209 long diff = stop.toMilliseconds() - start.toMilliseconds();
218 // Throw timed out exception:
224 void CIMExportClient::_checkError(const CIMResponseMessage* responseMessage)
226 if (responseMessage &&
227 (responseMessage->cimException.getCode() != CIM_ERR_SUCCESS) )
229 throw responseMessage->cimException;
233 PEGASUS_NAMESPACE_END