(file) Return to ProviderManagerService.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2

  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 chip  1.4 
131                   PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
132                       "ProviderManagerService::ProviderManagerService() loaded DEFAULT provider manager.");
133 chip  1.1     }
134               catch(...)
135               {
136 chip  1.4         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
137                       "ProviderManagerService::ProviderManagerService() failed to load DEFAULT provider manager.");
138 chip  1.1     }
139 chip  1.3     #endif
140 chip  1.2 
141 chip  1.3     #if defined(ENABLE_CMPI_PROVIDER_MANAGER)
142 chip  1.2     try
143               {
144                   ProviderManagerModule module("CMPIProviderManager");
145           
146                   // ATTN: ensure module loaded
147                   module.load();
148           
149                   // ATTN: ensure entry point returned valid response
150                   ProviderManager * manager = module.getProviderManager("CMPI");
151           
152                   // ATTN: only set the hacked/cached provider registration manager pointer after the module
153                   // has loaded.
154                   // manager->setProviderRegistrationManager(providerRegistrationManager);
155           
156                   _providerManagers.append(Pair<ProviderManager *, ProviderManagerModule>(manager, module));
157 chip  1.4 
158                   PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
159                       "ProviderManagerService::ProviderManagerService() loaded CMPI provider manager.");
160 chip  1.2     }
161               catch(...)
162               {
163 chip  1.4         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
164                       "ProviderManagerService::ProviderManagerService() failed to load CMPI provider manager.");
165 chip  1.2     }
166 chip  1.3     #endif
167 chip  1.1 }
168           
169           ProviderManagerService::~ProviderManagerService(void)
170           {
171           }
172           
173           Boolean ProviderManagerService::messageOK(const Message * message)
174           {
175               PEGASUS_ASSERT(message != 0);
176           
177 chip  1.3     if(_isSupportedRequestType(message))
178 chip  1.1     {
179 chip  1.3         return(MessageQueueService::messageOK(message));
180 chip  1.1     }
181           
182 chip  1.3     return(false);
183 chip  1.1 }
184           
185           void ProviderManagerService::handleEnqueue(void)
186           {
187               Message * message = dequeue();
188           
189               handleEnqueue(message);
190           }
191           
192           void ProviderManagerService::handleEnqueue(Message * message)
193           {
194               PEGASUS_ASSERT(message != 0);
195           
196               AsyncLegacyOperationStart * asyncRequest;
197           
198               if(message->_async != NULL)
199               {
200                   asyncRequest = static_cast<AsyncLegacyOperationStart *>(message->_async);
201               }
202               else
203               {
204 chip  1.1         asyncRequest = new AsyncLegacyOperationStart(
205                       get_next_xid(),
206                       0,
207                       this->getQueueId(),
208                       message,
209                       this->getQueueId());
210               }
211           
212               _handle_async_request(asyncRequest);
213           }
214           
215           void ProviderManagerService::_handle_async_request(AsyncRequest * request)
216           {
217               PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
218                   "ProviderManagerService::_handle_async_request");
219           
220               PEGASUS_ASSERT((request != 0) && (request->op != 0));
221           
222               if(request->getType() == async_messages::ASYNC_LEGACY_OP_START)
223               {
224                   request->op->processing();
225 chip  1.1 
226                   _incomingQueue.enqueue(request->op);
227           
228                   _thread_pool->allocate_and_awaken((void *)this, ProviderManagerService::handleCimOperation);
229               }
230               else
231               {
232                   // pass all other operations to the default handler
233                   MessageQueueService::_handle_async_request(request);
234               }
235           
236               PEG_METHOD_EXIT();
237           
238               return;
239           }
240           
241           /*
242           PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ProviderManagerService::handleServiceOperation(void * arg) throw()
243           {
244               // get the service from argument
245               ProviderManagerService * service = reinterpret_cast<ProviderManagerService *>(arg);
246 chip  1.1 
247               PEGASUS_ASSERT(service != 0);
248           
249               // get message from service queue
250               Message * message = service->_incomingQueue.dequeue();
251           
252               PEGASUS_ASSERT(message != 0);
253           
254               if(service->_incomingQueue.size() == 0)
255               {
256                   PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
257                       "ProviderManagerService::handleCimOperation() called with no op node in queue" );
258           
259                   PEG_METHOD_EXIT();
260           
261                   // thread started with no message in queue.
262                   return(PEGASUS_THREAD_RETURN(1));
263               }
264           
265               AsyncOpNode * op = service->_incomingQueue.dequeue();
266           
267 chip  1.1     PEGASUS_ASSERT(op != 0 );
268           
269               if(op->_request.count() == 0)
270               {
271                   MessageQueue * queue = MessageQueue::lookup(op->_source_queue);
272           
273                   PEGASUS_ASSERT(queue != 0);
274           
275                   PEG_METHOD_EXIT();
276           
277                   // no request in op node
278                   return(PEGASUS_THREAD_RETURN(1));
279               }
280           
281               return(0);
282           }
283           */
284           
285           PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ProviderManagerService::handleCimOperation(void * arg) throw()
286           {
287               PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderManagerService::handleCimOperation");
288 chip  1.1 
289               // get the service from argument
290               ProviderManagerService * service = reinterpret_cast<ProviderManagerService *>(arg);
291           
292               PEGASUS_ASSERT(service != 0);
293           
294               if(service->_incomingQueue.size() == 0)
295               {
296                   PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
297                       "ProviderManagerService::handleCimOperation() called with no op node in queue" );
298           
299                   PEG_METHOD_EXIT();
300           
301                   // thread started with no message in queue.
302                   return(PEGASUS_THREAD_RETURN(1));
303               }
304           
305               AsyncOpNode * op = service->_incomingQueue.dequeue();
306           
307               PEGASUS_ASSERT(op != 0 );
308           
309 chip  1.1     if(op->_request.count() == 0)
310               {
311                   MessageQueue * queue = MessageQueue::lookup(op->_source_queue);
312           
313                   PEGASUS_ASSERT(queue != 0);
314           
315                   PEG_METHOD_EXIT();
316           
317                   // no request in op node
318                   return(PEGASUS_THREAD_RETURN(1));
319               }
320           
321               AsyncRequest * request = static_cast<AsyncRequest *>(op->_request.next(0));
322           
323               PEGASUS_ASSERT(request != 0);
324           
325               if(request->getType() != async_messages::ASYNC_LEGACY_OP_START)
326               {
327                   // reply with NAK
328           
329                   PEG_METHOD_EXIT();
330 chip  1.1 
331                   return(PEGASUS_THREAD_RETURN(0));
332               }
333           
334               Message * legacy = static_cast<AsyncLegacyOperationStart *>(request)->get_action();
335           
336 chip  1.3     if(_isSupportedRequestType(legacy))
337 chip  1.1     {
338                   Destroyer<Message> xmessage(legacy);
339           
340                   // Set the client's requested language into this service thread.
341                   // This will allow functions in this service to return messages
342                   // in the correct language.
343                   CIMMessage * msg = dynamic_cast<CIMMessage *>(legacy);
344           
345                   if(msg != 0)
346                   {
347                       AcceptLanguages * langs = new AcceptLanguages(msg->acceptLanguages);
348           
349                       Thread::setLanguages(langs);
350                   }
351                   else
352                   {
353                       Thread::clearLanguages();
354                   }
355           
356 chip  1.3         try
357 chip  1.1         {
358                       service->handleCimRequest(op, legacy);
359 chip  1.3         }
360                   catch(...)
361                   {
362                       // ATTN: log error
363 chip  1.1         }
364               }
365           
366               PEG_METHOD_EXIT();
367           
368               return(PEGASUS_THREAD_RETURN(0));
369           }
370           
371           void ProviderManagerService::handleCimRequest(AsyncOpNode * op, const Message * message) throw()
372           {
373               PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderManagerService::handleCimRequest");
374           
375               // ATTN: ensure message is a request???
376               CIMMessage * request = dynamic_cast<CIMMessage *>(const_cast<Message *>(message));
377           
378               // get request from op node
379               AsyncRequest * async = static_cast<AsyncRequest *>(op->_request.next(0));
380           
381               PEGASUS_ASSERT((request != 0) && (async != 0));
382           
383               Message * response = 0;
384 chip  1.1 
385               // find provider manager
386               // ATTN: implement efficient lookup
387               ProviderManager * manager = _providerManagers[0].first;
388           
389               try
390               {
391 chip  1.4         PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,
392                       "ProviderManagerService::handleCimRequest() passing control to provider manager.");
393           
394 chip  1.1         // forward request
395                   response = manager->processMessage(request);
396               }
397               catch(...)
398               {
399                   // ATTN: create response with error message
400               }
401           
402               // preserve message key
403               response->setKey(request->getKey());
404           
405               // set HTTP method in response from request
406               response->setHttpMethod(request->getHttpMethod());
407           
408               AsyncLegacyOperationResult * async_result =
409                   new AsyncLegacyOperationResult(
410                       async->getKey(),
411                       async->getRouting(),
412                       op,
413                       response);
414           
415 chip  1.1     _complete_op_node(op, ASYNC_OPSTATE_COMPLETE, 0, 0);
416           
417               PEG_METHOD_EXIT();
418           }
419           
420           void ProviderManagerService::unload_idle_providers(void)
421           {
422           }
423           
424           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2