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

  1 martin 1.13 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.14 //
  3 martin 1.13 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.14 //
 10 martin 1.13 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.14 //
 17 martin 1.13 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.14 //
 20 martin 1.13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.14 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.13 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.14 //
 28 martin 1.13 //////////////////////////////////////////////////////////////////////////
 29 h.sterling 1.1  //
 30                 //%/////////////////////////////////////////////////////////////////////////////
 31                 
 32                 #include "DynamicListenerIndicationDispatcher.h"
 33                 #include "DynamicConsumer.h"
 34                 #include "ConsumerManager.h"
 35                 
 36                 #include <Pegasus/Common/Config.h>
 37                 #include <Pegasus/Common/Constants.h>
 38                 #include <Pegasus/Common/OperationContext.h>
 39                 #include <Pegasus/Common/Tracer.h>
 40                 
 41                 #include <Pegasus/Listener/List.h>
 42                 #include <Pegasus/Consumer/CIMIndicationConsumer.h>
 43                 
 44                 PEGASUS_NAMESPACE_BEGIN
 45                 PEGASUS_USING_STD;
 46                 
 47                 #define PEGASUS_QUEUE_NAME "DynamicListenerIndicationDispatcher"
 48                 
 49                 
 50 marek      1.8  DynamicListenerIndicationDispatcher::DynamicListenerIndicationDispatcher(
 51                     ConsumerManager* consumerManager) :
 52                         Base(PEGASUS_QUEUE_NAME),
 53                         _consumerManager(consumerManager)
 54 h.sterling 1.1  {
 55 marek      1.8      PEG_METHOD_ENTER(
 56                         TRC_LISTENER,
 57                         "DynamicListenerIndicationDispatcher::"
 58                             "DynamicListenerIndicationDispatcher");
 59 h.sterling 1.1  
 60                     PEG_METHOD_EXIT();
 61                 }
 62                 
 63                 
 64                 DynamicListenerIndicationDispatcher::~DynamicListenerIndicationDispatcher()
 65                 {
 66 marek      1.8      PEG_METHOD_ENTER(
 67                         TRC_LISTENER,
 68                         "DynamicListenerIndicationDispatcher::"
 69                             "~DynamicListenerIndicationDispatcher");
 70 h.sterling 1.1  
 71                     PEG_METHOD_EXIT();
 72                 }
 73                 
 74                 void DynamicListenerIndicationDispatcher::handleEnqueue()
 75                 {
 76 marek      1.8      PEG_METHOD_ENTER(
 77                         TRC_LISTENER,
 78                         "DynamicListenerIndicationDispatcher::handleEnqueue");
 79 h.sterling 1.1  
 80                     Message *message = dequeue();
 81                     if (message)
 82                         handleEnqueue(message);
 83                 
 84                     PEG_METHOD_EXIT();
 85                 }
 86                 
 87                 void DynamicListenerIndicationDispatcher::handleEnqueue(Message* message)
 88                 {
 89 marek      1.8      PEG_METHOD_ENTER(
 90                         TRC_LISTENER,
 91                         "DynamicListenerIndicationDispatcher::handleEnqueue");
 92 h.sterling 1.1  
 93                     if (message!=NULL)
 94                     {
 95                         switch (message->getType())
 96                         {
 97                         case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
 98                             {
 99 kumpf      1.15                 CIMExportIndicationRequestMessage* request =
100 marek      1.8                      (CIMExportIndicationRequestMessage*)message;
101 h.sterling 1.1                  CIMException cimException;
102                 
103                                 try
104                                 {
105                                     _handleIndicationRequest(request);
106                 
107                                 } catch (Exception& ex)
108                                 {
109 marek      1.8                      cimException = CIMException(
110                                                        CIM_ERR_FAILED,
111                                                        ex.getMessage());
112 h.sterling 1.1  
113                                     Logger::put(
114                                                Logger::ERROR_LOG,
115 yi.zhou    1.6                                 System::CIMLISTENER,
116 h.sterling 1.1                                 Logger::SEVERE,
117 kumpf      1.15                                "Exception getting consumer: $0",
118 h.sterling 1.1                                 ex.getMessage());
119                 
120                                 } catch (...)
121                                 {
122 marek      1.8                      cimException = CIMException(
123                                                        CIM_ERR_FAILED,
124                                                        "Unknown exception");
125 h.sterling 1.1  
126                                     Logger::put(
127                                                Logger::ERROR_LOG,
128 yi.zhou    1.6                                 System::CIMLISTENER,
129 h.sterling 1.1                                 Logger::SEVERE,
130                                                "Unknown Exception getting consumer");
131                                 }
132                 
133 kumpf      1.15                 /** At this point (barring one of the above exceptions),
134                                  * we can be reasonably sure that the indication will get
135 marek      1.8                   * delivered and processed. The request was well-formatted and
136                                  * we were able to locate and load the consumer.
137 kumpf      1.15                  * Send an acknowledgement to the client that we received
138                                  * the indication.
139                                  * We should not wait until the consumer reports ultimate
140                                  * success since that could take a long time and would require
141                                  * us to store a bunch of status information.
142                                  * Additionally, the wait could cause a timeout exception
143 marek      1.8                   * on the client end.
144                 
145                                  */
146 kumpf      1.15                 // ATTN: Why isn't the CIM exception getting appended
147 marek      1.8                  // to the response?  Go look in Message.h
148 kumpf      1.9                  CIMResponseMessage* response = request->buildResponse();
149                                 response->cimException = cimException;
150 h.sterling 1.1                  response->dest = request->queueIds.top();
151                                 _enqueueResponse(request, response);
152                             }
153                             break;
154                         default:
155                             {
156 marek      1.8                  // unsupported message type
157 kumpf      1.15                 // it should not get here;
158 marek      1.8                  // this error is caught in the request decoder
159 kumpf      1.15                 PEG_TRACE((TRC_LISTENER,Tracer::LEVEL2,
160 thilo.boehm 1.12                     "Unsupported msg type: %s",
161                                      MessageTypeToString(message->getType())));
162 h.sterling  1.1  
163 kumpf       1.15                 CIMRequestMessage* cimRequest =
164 marek       1.8                      dynamic_cast<CIMRequestMessage*>(message);
165 h.sterling  1.1  
166                                  CIMResponseMessage* response = cimRequest->buildResponse();
167 kumpf       1.15                 response->cimException =
168 marek       1.8                      PEGASUS_CIM_EXCEPTION_L(
169                                          CIM_ERR_FAILED,
170                                          MessageLoaderParms(
171                                              "DynListener.DynamicListenerIndicationDispatcher"
172                                                  ".INVALID_MSG_TYPE",
173                                              "Invalid message type"));
174 h.sterling  1.1  
175                                  _enqueueResponse (cimRequest, response);
176                              }
177                              break;
178 kumpf       1.15         }
179 h.sterling  1.1          delete message;
180                      }
181                  
182                      PEG_METHOD_EXIT();
183                  }
184                  
185 marek       1.8  void DynamicListenerIndicationDispatcher::_handleIndicationRequest(
186                      CIMExportIndicationRequestMessage* request)
187 h.sterling  1.1  {
188 marek       1.8      PEG_METHOD_ENTER(
189                          TRC_LISTENER,
190                          "DynamicListenerIndicationDispatcher::handleIndicationRequest");
191 h.sterling  1.1  
192                      OperationContext context = request->operationContext;
193                      String url = request->destinationPath;
194                      CIMInstance instance = request->indicationInstance;
195                  
196 thilo.boehm 1.12     PEG_TRACE((TRC_LISTENER, Tracer::LEVEL4, "URL is %s",
197                          (const char*)url.getCString()));
198 h.sterling  1.1  
199                      Uint32 slash = url.find("/");
200                      if (slash == PEG_NOT_FOUND)
201                      {
202                          Logger::put(
203                                     Logger::ERROR_LOG,
204 yi.zhou     1.6                     System::CIMLISTENER,
205 h.sterling  1.1                     Logger::SEVERE,
206 kumpf       1.15                    "Invalid URL $0",
207 h.sterling  1.1                     url);
208                  
209                          MessageLoaderParms msgLoaderParms(
210 marek       1.8              "DynListener.DynamicListenerIndicationDispatcher.BAD_URL",
211                              "Invalid CIMXMLIndicationHandler destination: $0.",
212                              url);
213 h.sterling  1.1  
214                          throw CIMException(CIM_ERR_FAILED, msgLoaderParms);
215                      }
216                  
217                      String consumerName = url.subString(slash+1);
218                  
219 kumpf       1.15     // check for a trailing slash,
220                      // in the case that additional information is in the URL,
221 marek       1.8      // i.e. /CIMListener/MyConsumer/9.44.169.132
222 h.sterling  1.3      Uint32 trailingSlash = consumerName.find('/');
223                      if (trailingSlash != PEG_NOT_FOUND)
224                      {
225                          consumerName = consumerName.subString(0, trailingSlash);
226 thilo.boehm 1.12         PEG_TRACE((TRC_LISTENER,Tracer::LEVEL4,
227                              "The consumer name with slash removed is '%s'!",
228                              (const char*)consumerName.getCString()));
229 h.sterling  1.3      }
230 kumpf       1.15 
231 h.sterling  1.1      //get consumer
232                      //this will throw an exception if it fails
233                      //gets deleted by the ConsumerManager
234                      DynamicConsumer* consumer = _consumerManager->getConsumer(consumerName);
235                  
236                      //deliver indication to consumer
237                      //gets deleted by the DynamicConsumer
238 marek       1.8      IndicationDispatchEvent* event = new IndicationDispatchEvent(
239                                                               request->operationContext,
240                                                               request->destinationPath,
241                                                               request->indicationInstance);
242 h.sterling  1.1  
243                      //enqueue event
244                      consumer->enqueueEvent(event);
245                  
246                      PEG_METHOD_EXIT();
247                  }
248                  
249                  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2