1 kumpf 1.17 //%/////////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 kumpf 1.17 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 kumpf 1.1 //
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 kumpf 1.17 //
|
13 kumpf 1.1 // 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: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
|
30 kumpf 1.11 #include <Pegasus/Common/Constants.h>
|
31 mday 1.14 #include <Pegasus/Common/Tracer.h>
|
32 kumpf 1.1 #include <Pegasus/Common/CIMMessage.h>
33 #include <Pegasus/Common/XmlWriter.h>
|
34 kumpf 1.13 #include <Pegasus/Common/PegasusVersion.h>
|
35 kumpf 1.1
36 #include "IndicationHandlerService.h"
37
38 PEGASUS_USING_STD;
39 PEGASUS_USING_PEGASUS;
40
41 PEGASUS_NAMESPACE_BEGIN
42
|
43 kumpf 1.2 IndicationHandlerService::IndicationHandlerService(void)
|
44 kumpf 1.11 : Base(PEGASUS_QUEUENAME_INDHANDLERMANAGER)
|
45 kumpf 1.1 {
|
46 kumpf 1.2
|
47 kumpf 1.1 }
48
|
49 kumpf 1.2 IndicationHandlerService::IndicationHandlerService(CIMRepository* repository)
50 : Base("IndicationHandlerService", MessageQueue::getNextQueueId()),
51 _repository(repository)
|
52 kumpf 1.1 {
53 }
54
55 void IndicationHandlerService::_handle_async_request(AsyncRequest *req)
56 {
|
57 mday 1.6 if ( req->getType() == async_messages::CIMSERVICE_STOP )
58 {
59 req->op->processing();
60 handle_CimServiceStop(static_cast<CimServiceStop *>(req));
61 }
62 else if ( req->getType() == async_messages::ASYNC_LEGACY_OP_START )
63 {
64 req->op->processing();
65 Message *legacy = (static_cast<AsyncLegacyOperationStart *>(req)->get_action());
66 handleEnqueue(legacy);
67 return;
68 }
69 else
70 Base::_handle_async_request(req);
|
71 kumpf 1.1 }
72
|
73 mday 1.4 void IndicationHandlerService::handleEnqueue(Message* message)
|
74 kumpf 1.1 {
|
75 mday 1.6 if( ! message )
76 return;
77
78 switch (message->getType())
79 {
80 case CIM_HANDLE_INDICATION_REQUEST_MESSAGE:
81 _handleIndication(message);
82 break;
|
83 kumpf 1.2
|
84 mday 1.6 default:
85 break;
86 }
87 delete message;
|
88 kumpf 1.1 }
89
|
90 kumpf 1.3 void IndicationHandlerService::handleEnqueue()
91 {
|
92 mday 1.6 Message * message = dequeue();
|
93 kumpf 1.3
|
94 mday 1.6 PEGASUS_ASSERT(message != 0);
95 if( message )
96 handleEnqueue(message);
|
97 kumpf 1.3 }
98
|
99 mday 1.9
100 void IndicationHandlerService::_handleIndicationCallBack(AsyncOpNode *op,
101 MessageQueue *q,
102 void *parm)
103 {
104 IndicationHandlerService *service =
105 static_cast<IndicationHandlerService *>(q);
106
107 AsyncRequest *asyncRequest = static_cast<AsyncRequest *>(op->get_request());
108 AsyncReply *asyncReply = static_cast<AsyncReply *>(op->get_response());
109 CIMRequestMessage *request = reinterpret_cast<CIMRequestMessage *>
110 ((static_cast<AsyncLegacyOperationStart *>(asyncRequest))->get_action());
111 CIMResponseMessage *response = reinterpret_cast<CIMResponseMessage *>
112 ((static_cast<AsyncLegacyOperationResult *>(asyncReply))->get_result());
113 PEGASUS_ASSERT(response != 0);
114 // ensure that the destination queue is in response->dest
|
115 kumpf 1.10 #ifdef PEGASUS_ARCHITECTURE_IA64
116 response->dest = (Uint64)parm;
117 #else
|
118 mday 1.9 response->dest = (Uint32)parm;
|
119 kumpf 1.10 #endif
|
120 mday 1.9 service->SendForget(response);
121 delete asyncRequest;
122 delete asyncReply;
123 // op->release();
124 // service->return_op(op);
125 }
126
127
|
128 kumpf 1.2 void IndicationHandlerService::_handleIndication(const Message* message)
|
129 kumpf 1.1 {
|
130 mday 1.6 CIMHandleIndicationRequestMessage* request =
131 (CIMHandleIndicationRequestMessage*) message;
|
132 kumpf 1.1
|
133 kumpf 1.16 CIMException cimException = PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY);
134
|
135 mday 1.6 String className = request->handlerInstance.getClassName();
|
136 kumpf 1.1
|
137 mday 1.6 String nameSpace = request->nameSpace;
|
138 kumpf 1.1
|
139 mday 1.6 CIMInstance indication = request->indicationInstance;
140 CIMInstance handler = request->handlerInstance;
|
141 kumpf 1.1
|
142 kumpf 1.7 Uint32 pos = PEG_NOT_FOUND;
143
|
144 kumpf 1.12 if (className == String("PG_IndicationHandlerCIMXML"))
|
145 kumpf 1.7 pos = handler.findProperty("destination");
146 else if (className == String("PG_IndicationHandlerSNMPMapper"))
147 pos = handler.findProperty("TrapDestination");
148
|
149 mday 1.6 if (pos == PEG_NOT_FOUND)
150 {
|
151 kumpf 1.16 cimException =
152 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, String("Handler without destination"));
|
153 mday 1.6 }
|
154 kumpf 1.16 else
155 {
156 CIMProperty prop = handler.getProperty(pos);
157 String destination = prop.getValue().toString();
|
158 kumpf 1.1
|
159 kumpf 1.16 if (destination.size() == 0)
160 {
161 cimException =
162 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, String("invalid destination"));
163 }
164 else if ((className == "PG_IndicationHandlerCIMXML") &&
165 (destination.subString(0, 9) == String("localhost")))
166 {
167 Array<Uint32> exportServer;
|
168 kumpf 1.12
|
169 kumpf 1.16 find_services(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER, 0, 0, &exportServer);
|
170 kumpf 1.5
|
171 kumpf 1.16 // Listener is build with Cimom, so send message to ExportServer
|
172 kumpf 1.1
|
173 kumpf 1.16 CIMExportIndicationRequestMessage* exportmessage =
174 new CIMExportIndicationRequestMessage(
175 "1234",
176 destination.subString(15), //taking localhost:5988 portion out from reg
177 indication,
178 QueueIdStack(exportServer[0], getQueueId()));
|
179 kumpf 1.1
|
180 kumpf 1.16 AsyncOpNode* op = this->get_op();
|
181 kumpf 1.3
|
182 kumpf 1.16 AsyncLegacyOperationStart *req =
183 new AsyncLegacyOperationStart(
184 get_next_xid(),
185 op,
186 exportServer[0],
187 exportmessage,
188 _queueId);
|
189 mday 1.6
|
190 kumpf 1.16 PEG_TRACE_STRING(TRC_IND_HANDLE, Tracer::LEVEL4,
|
191 mday 1.14 "Indication handler forwarding message to " +
192 ((MessageQueue::lookup(exportServer[0])) ?
193 String( ((MessageQueue::lookup(exportServer[0]))->getQueueName()) ) :
194 String("BAD queue name")));
195
|
196 kumpf 1.16 SendAsync(op,
|
197 mday 1.9 exportServer[0],
198 IndicationHandlerService::_handleIndicationCallBack,
199 this,
200 (void *)request->queueIds.top());
201
|
202 kumpf 1.16 }
203 else
204 {
205 // generic handler. So load it and let it to do.
206 CIMHandler* handlerLib = _lookupHandlerForClass(className);
207
208 if (handlerLib)
209 {
210 handlerLib->handleIndication(
211 handler,
212 indication,
213 nameSpace);
214 }
215 else
216 cimException =
217 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, String("Failed to load Handler"));
218 }
|
219 mday 1.6 }
220
|
221 kumpf 1.16 CIMExportIndicationResponseMessage* response =
222 new CIMExportIndicationResponseMessage(
223 request->messageId,
224 cimException,
225 request->queueIds.copyAndPop());
|
226 kumpf 1.1
|
227 kumpf 1.16 _enqueueResponse(request, response);
|
228 kumpf 1.1 }
229
230 CIMHandler* IndicationHandlerService::_lookupHandlerForClass(
|
231 mday 1.6 const String& className)
|
232 kumpf 1.1 {
|
233 mday 1.6 String handlerId;
|
234 kumpf 1.1
|
235 kumpf 1.8 if (className == String("PG_IndicationHandlerCIMXML"))
236 handlerId = String("CIMxmlIndicationHandler");
|
237 kumpf 1.12 else if (className == String("PG_IndicationHandlerSNMPMapper"))
|
238 kumpf 1.8 handlerId = String("snmpIndicationHandler");
239 else
240 return 0;
|
241 kumpf 1.1
|
242 mday 1.6 CIMHandler* handler = _handlerTable.lookupHandler(handlerId);
|
243 kumpf 1.1
|
244 mday 1.6 if (!handler)
245 {
246 handler = _handlerTable.loadHandler(handlerId);
|
247 kumpf 1.1
|
248 mday 1.6 if (!handler)
249 throw CIMException(CIM_ERR_FAILED);
|
250 kumpf 1.1
|
251 mday 1.6 handler->initialize(_repository);
252 }
|
253 kumpf 1.1
|
254 mday 1.6 return handler;
|
255 kumpf 1.1 }
256
257 PEGASUS_NAMESPACE_END
|