1 chip 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000 - 2003 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 chip 1.1 //==============================================================================
23 //
24 // Author: Chip Vincent (cvincent@us.ibm.com)
25 //
26 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
27 // (carolann_graves@hp.com)
28 // Mike Day, IBM (mdday@us.ibm.com)
29 // Karl Schopmeyer(k.schopmeyer@opengroup.org) - Fix associators.
|
30 chip 1.3 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
31 chip 1.1 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include "ProviderManagerService.h"
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Constants.h>
38 #include <Pegasus/Common/CIMMessage.h>
39 #include <Pegasus/Common/Tracer.h>
40 #include <Pegasus/Common/Logger.h>
41
42 #include <Pegasus/Common/Destroyer.h>
43
44 PEGASUS_NAMESPACE_BEGIN
45
|
46 chip 1.3 inline Boolean _isSupportedRequestType(const Message * message)
47 {
48 Boolean rc = false;
49
50 if(message == 0)
51 {
52 return(rc);
53 }
54
55 /*
56 // ATTN : need to determine valid request message types
57 // before enabling.
58
59 switch(message->getType())
60 {
61 case CIM_GET_INSTANCE_REQUEST_MESSAGE:
62 case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE:
63 case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE:
64 case CIM_CREATE_INSTANCE_REQUEST_MESSAGE:
65 case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE:
66 case CIM_DELETE_INSTANCE_REQUEST_MESSAGE:
67 chip 1.3 case CIM_EXEC_QUERY_REQUEST_MESSAGE:
68 case CIM_ASSOCIATORS_REQUEST_MESSAGE:
69 case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE:
70 case CIM_REFERENCES_REQUEST_MESSAGE:
71 case CIM_REFERENCE_NAMES_REQUEST_MESSAGE:
72 case CIM_GET_PROPERTY_REQUEST_MESSAGE:
73 case CIM_SET_PROPERTY_REQUEST_MESSAGE:
74 case CIM_INVOKE_METHOD_REQUEST_MESSAGE:
75 case CIM_CREATE_SUBSCRIPTION_REQUEST_MESSAGE:
76 case CIM_MODIFY_SUBSCRIPTION_REQUEST_MESSAGE:
77 case CIM_DELETE_SUBSCRIPTION_REQUEST_MESSAGE:
78 case CIM_ENABLE_INDICATIONS_REQUEST_MESSAGE:
79 case CIM_DISABLE_INDICATIONS_REQUEST_MESSAGE:
80 case CIM_DISABLE_MODULE_REQUEST_MESSAGE:
81 case CIM_ENABLE_MODULE_REQUEST_MESSAGE:
82 case CIM_STOP_ALL_PROVIDERS_REQUEST_MESSAGE:
83 case CIM_CONSUME_INDICATION_REQUEST_MESSAGE:
84 rc = true;
85
86 break;
87 default:
88 chip 1.3 rc = false;
89
90 break;
91 }
92 */
93
94 rc = true;
95
96 return(rc);
97 }
98
99 inline Boolean _isSupportedResponseType(const Message * message)
100 {
101 Boolean rc = false;
102
103 return(rc);
104 }
105
|
106 chip 1.1 ProviderManagerService::ProviderManagerService(void)
107 : MessageQueueService(PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP)
108 {
109 }
110
111 ProviderManagerService::ProviderManagerService(ProviderRegistrationManager * providerRegistrationManager)
112 : MessageQueueService(PEGASUS_QUEUENAME_PROVIDERMANAGER_CPP)
113 {
|
114 chip 1.3 #if defined(ENABLE_DEFAULT_PROVIDER_MANAGER)
|
115 chip 1.1 try
116 {
117 ProviderManagerModule module("DefaultProviderManager");
118
119 // ATTN: ensure module loaded
120 module.load();
121
122 // ATTN: ensure entry point returned valid response
123 ProviderManager * manager = module.getProviderManager("Default");
124
125 // ATTN: only set the hacked/cached provider registration manager pointer after the module
126 // has loaded.
127 manager->setProviderRegistrationManager(providerRegistrationManager);
128
129 _providerManagers.append(Pair<ProviderManager *, ProviderManagerModule>(manager, module));
130 }
131 catch(...)
132 {
133 }
|
134 chip 1.3 #endif
|
135 chip 1.2
|
136 chip 1.3 #if defined(ENABLE_CMPI_PROVIDER_MANAGER)
|
137 chip 1.2 try
138 {
139 ProviderManagerModule module("CMPIProviderManager");
140
141 // ATTN: ensure module loaded
142 module.load();
143
144 // ATTN: ensure entry point returned valid response
145 ProviderManager * manager = module.getProviderManager("CMPI");
146
147 // ATTN: only set the hacked/cached provider registration manager pointer after the module
148 // has loaded.
149 // manager->setProviderRegistrationManager(providerRegistrationManager);
150
151 _providerManagers.append(Pair<ProviderManager *, ProviderManagerModule>(manager, module));
152 }
153 catch(...)
154 {
155 }
|
156 chip 1.3 #endif
|
157 chip 1.1 }
158
159 ProviderManagerService::~ProviderManagerService(void)
160 {
161 }
162
163 Boolean ProviderManagerService::messageOK(const Message * message)
164 {
165 PEGASUS_ASSERT(message != 0);
166
|
167 chip 1.3 if(_isSupportedRequestType(message))
|
168 chip 1.1 {
|
169 chip 1.3 return(MessageQueueService::messageOK(message));
|
170 chip 1.1 }
171
|
172 chip 1.3 return(false);
|
173 chip 1.1 }
174
175 void ProviderManagerService::handleEnqueue(void)
176 {
177 Message * message = dequeue();
178
179 handleEnqueue(message);
180 }
181
182 void ProviderManagerService::handleEnqueue(Message * message)
183 {
184 PEGASUS_ASSERT(message != 0);
185
186 AsyncLegacyOperationStart * asyncRequest;
187
188 if(message->_async != NULL)
189 {
190 asyncRequest = static_cast<AsyncLegacyOperationStart *>(message->_async);
191 }
192 else
193 {
194 chip 1.1 asyncRequest = new AsyncLegacyOperationStart(
195 get_next_xid(),
196 0,
197 this->getQueueId(),
198 message,
199 this->getQueueId());
200 }
201
202 _handle_async_request(asyncRequest);
203 }
204
205 void ProviderManagerService::_handle_async_request(AsyncRequest * request)
206 {
207 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
208 "ProviderManagerService::_handle_async_request");
209
210 PEGASUS_ASSERT((request != 0) && (request->op != 0));
211
212 if(request->getType() == async_messages::ASYNC_LEGACY_OP_START)
213 {
214 request->op->processing();
215 chip 1.1
216 _incomingQueue.enqueue(request->op);
217
218 _thread_pool->allocate_and_awaken((void *)this, ProviderManagerService::handleCimOperation);
219 }
220 else
221 {
222 // pass all other operations to the default handler
223 MessageQueueService::_handle_async_request(request);
224 }
225
226 PEG_METHOD_EXIT();
227
228 return;
229 }
230
231 /*
232 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ProviderManagerService::handleServiceOperation(void * arg) throw()
233 {
234 // get the service from argument
235 ProviderManagerService * service = reinterpret_cast<ProviderManagerService *>(arg);
236 chip 1.1
237 PEGASUS_ASSERT(service != 0);
238
239 // get message from service queue
240 Message * message = service->_incomingQueue.dequeue();
241
242 PEGASUS_ASSERT(message != 0);
243
244 if(service->_incomingQueue.size() == 0)
245 {
246 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
247 "ProviderManagerService::handleCimOperation() called with no op node in queue" );
248
249 PEG_METHOD_EXIT();
250
251 // thread started with no message in queue.
252 return(PEGASUS_THREAD_RETURN(1));
253 }
254
255 AsyncOpNode * op = service->_incomingQueue.dequeue();
256
257 chip 1.1 PEGASUS_ASSERT(op != 0 );
258
259 if(op->_request.count() == 0)
260 {
261 MessageQueue * queue = MessageQueue::lookup(op->_source_queue);
262
263 PEGASUS_ASSERT(queue != 0);
264
265 PEG_METHOD_EXIT();
266
267 // no request in op node
268 return(PEGASUS_THREAD_RETURN(1));
269 }
270
271 return(0);
272 }
273 */
274
275 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ProviderManagerService::handleCimOperation(void * arg) throw()
276 {
277 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderManagerService::handleCimOperation");
278 chip 1.1
279 // get the service from argument
280 ProviderManagerService * service = reinterpret_cast<ProviderManagerService *>(arg);
281
282 PEGASUS_ASSERT(service != 0);
283
284 if(service->_incomingQueue.size() == 0)
285 {
286 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
287 "ProviderManagerService::handleCimOperation() called with no op node in queue" );
288
289 PEG_METHOD_EXIT();
290
291 // thread started with no message in queue.
292 return(PEGASUS_THREAD_RETURN(1));
293 }
294
295 AsyncOpNode * op = service->_incomingQueue.dequeue();
296
297 PEGASUS_ASSERT(op != 0 );
298
299 chip 1.1 if(op->_request.count() == 0)
300 {
301 MessageQueue * queue = MessageQueue::lookup(op->_source_queue);
302
303 PEGASUS_ASSERT(queue != 0);
304
305 PEG_METHOD_EXIT();
306
307 // no request in op node
308 return(PEGASUS_THREAD_RETURN(1));
309 }
310
311 AsyncRequest * request = static_cast<AsyncRequest *>(op->_request.next(0));
312
313 PEGASUS_ASSERT(request != 0);
314
315 if(request->getType() != async_messages::ASYNC_LEGACY_OP_START)
316 {
317 // reply with NAK
318
319 PEG_METHOD_EXIT();
320 chip 1.1
321 return(PEGASUS_THREAD_RETURN(0));
322 }
323
324 Message * legacy = static_cast<AsyncLegacyOperationStart *>(request)->get_action();
325
|
326 chip 1.3 if(_isSupportedRequestType(legacy))
|
327 chip 1.1 {
328 Destroyer<Message> xmessage(legacy);
329
330 // Set the client's requested language into this service thread.
331 // This will allow functions in this service to return messages
332 // in the correct language.
333 CIMMessage * msg = dynamic_cast<CIMMessage *>(legacy);
334
335 if(msg != 0)
336 {
337 AcceptLanguages * langs = new AcceptLanguages(msg->acceptLanguages);
338
339 Thread::setLanguages(langs);
340 }
341 else
342 {
343 Thread::clearLanguages();
344 }
345
|
346 chip 1.3 try
|
347 chip 1.1 {
348 service->handleCimRequest(op, legacy);
|
349 chip 1.3 }
350 catch(...)
351 {
352 // ATTN: log error
|
353 chip 1.1 }
354 }
355
356 PEG_METHOD_EXIT();
357
358 return(PEGASUS_THREAD_RETURN(0));
359 }
360
361 void ProviderManagerService::handleCimRequest(AsyncOpNode * op, const Message * message) throw()
362 {
363 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderManagerService::handleCimRequest");
364
365 // ATTN: ensure message is a request???
366 CIMMessage * request = dynamic_cast<CIMMessage *>(const_cast<Message *>(message));
367
368 // get request from op node
369 AsyncRequest * async = static_cast<AsyncRequest *>(op->_request.next(0));
370
371 PEGASUS_ASSERT((request != 0) && (async != 0));
372
373 Message * response = 0;
374 chip 1.1
375 // find provider manager
376 // ATTN: implement efficient lookup
377 ProviderManager * manager = _providerManagers[0].first;
378
379 try
380 {
381 // forward request
382 response = manager->processMessage(request);
383 }
384 catch(...)
385 {
386 // ATTN: create response with error message
387 }
388
389 // preserve message key
390 response->setKey(request->getKey());
391
392 // set HTTP method in response from request
393 response->setHttpMethod(request->getHttpMethod());
394
395 chip 1.1 AsyncLegacyOperationResult * async_result =
396 new AsyncLegacyOperationResult(
397 async->getKey(),
398 async->getRouting(),
399 op,
400 response);
401
402 _complete_op_node(op, ASYNC_OPSTATE_COMPLETE, 0, 0);
403
404 PEG_METHOD_EXIT();
405 }
406
407 void ProviderManagerService::unload_idle_providers(void)
408 {
409 }
410
411 PEGASUS_NAMESPACE_END
|