8cedebd9a6bbc5a4541bc88701151f7c0cb8061b
[tpot/pegasus/.git] / src / Pegasus / ExportServer / CIMExportResponseEncoder.cpp
1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
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:
12 // 
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.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #include <Pegasus/Common/Config.h>
31 #include <cctype>
32 #include <cstdio>
33 #include <Pegasus/Common/XmlParser.h>
34 #include <Pegasus/Common/XmlReader.h>
35 #include <Pegasus/Common/Destroyer.h>
36 #include <Pegasus/Common/XmlWriter.h>
37 #include <Pegasus/Common/HTTPMessage.h>
38 #include <Pegasus/Common/Logger.h>
39 #include "CIMExportResponseEncoder.h"
40
41 PEGASUS_USING_STD;
42
43 PEGASUS_NAMESPACE_BEGIN
44
45 CIMExportResponseEncoder::CIMExportResponseEncoder()
46    : Base("CIMExportResponseEncoder", MessageQueue::getNextQueueId())
47 {
48
49 }
50
51 CIMExportResponseEncoder::~CIMExportResponseEncoder()
52 {
53
54 }
55
56 void CIMExportResponseEncoder::sendResponse(
57    Uint32 queueId, 
58    Array<Sint8>& message)
59 {
60    MessageQueue* queue = MessageQueue::lookup(queueId);
61
62    if (queue)
63    {
64       HTTPMessage* httpMessage = new HTTPMessage(message);
65       queue->enqueue(httpMessage);
66    }
67 }
68
69 void CIMExportResponseEncoder::sendEMethodError(
70    Uint32 queueId, 
71    const String& messageId,
72    const String& eMethodName,
73    const CIMException& cimException) 
74 {
75     Array<Sint8> message;
76     message = XmlWriter::formatSimpleEMethodErrorRspMessage(
77         eMethodName,
78         messageId,
79         cimException);
80
81     sendResponse(queueId, message);
82 }
83
84 void CIMExportResponseEncoder::sendEMethodError(
85    CIMResponseMessage* response,
86    const String& cimMethodName)
87 {
88    Uint32 queueId = response->queueIds.top();
89    response->queueIds.pop();
90
91    sendEMethodError(
92       queueId,
93       response->messageId, 
94       cimMethodName, 
95       response->cimException);
96 }
97
98 void CIMExportResponseEncoder::handleEnqueue(Message *message)
99 {
100    if (!message)
101       return;
102
103    switch (message->getType())
104    {
105       case CIM_EXPORT_INDICATION_RESPONSE_MESSAGE:
106          encodeExportIndicationResponse(
107             (CIMExportIndicationResponseMessage*)message);
108          break;
109    }
110    
111    delete message;
112 }
113
114
115 void CIMExportResponseEncoder::handleEnqueue()
116 {
117    Message* message = dequeue();
118    if(message)
119       handleEnqueue(message);
120 }
121
122 const char* CIMExportResponseEncoder::getQueueName() const
123 {
124    return "CIMExportResponseEncoder";
125 }
126
127 void CIMExportResponseEncoder::encodeExportIndicationResponse(
128    CIMExportIndicationResponseMessage* response)
129 {
130    if (response->cimException.getCode() != CIM_ERR_SUCCESS)
131    {
132       sendEMethodError(response, "ExportIndication");
133       return;
134    }
135
136    Array<Sint8> body;
137     
138    Array<Sint8> message = XmlWriter::formatSimpleEMethodRspMessage(
139       "ExportIndication", response->messageId, body);
140
141    sendResponse(response->queueIds.top(), message);
142 }
143
144 PEGASUS_NAMESPACE_END