bool ProvisioningAgentXmlRpcAction::execute(const HttpRequestContext&      rContext,
                                            UtlSList&                      rParameters,
                                            void*                          pProvisioningAgentInstance,
                                            XmlRpcResponse&                rResponse,
                                            XmlRpcMethod::ExecutionStatus& rStatus)
{
   rStatus = XmlRpcMethod::OK;

   // Extract the request argument structure from the head of the SList.
   UtlContainable *pRequestArgs = rParameters.at(0);

   // Verify that a parameter list was given
   if (pRequestArgs != NULL) {
      // Verify that the parameter list is a structure ("UtlHashMap").
      if (UtlString(pRequestArgs->getContainableType()) == "UtlHashMap") {
         // Now call the Provisioning Agent.
         ProvisioningAttrList requestAttributes(dynamic_cast<UtlHashMap*>(pRequestArgs));
         ProvisioningAttrList* pResponseAttributes;
         pResponseAttributes = ((ProvisioningAgent*)pProvisioningAgentInstance)->Action(requestAttributes);

         if (pResponseAttributes == NULL) {
            // Method failure.  Report error back to client
            rResponse.setFault(METHOD_DISPATCH_FAULT_CODE, METHOD_DISPATCH_FAULT_STRING);
         }
         else {
            // Encode the response
            rResponse.setResponse(dynamic_cast<UtlContainable*>(pResponseAttributes->getData()));

            // and clean up the responsettributes list.
            delete pResponseAttributes;
         }
      }
      else {
         // Missing parameter list.  Report error back to client
         rResponse.setFault(EXPECTED_STRUCT_FAULT_CODE, EXPECTED_STRUCT_FAULT_STRING);
      }
   }
   else {
      // Bad parameter list.  Report error back to client
      rResponse.setFault(EXPECTED_STRUCT_FAULT_CODE, EXPECTED_STRUCT_FAULT_STRING);
   }

   return true;
}
示例#2
0
ProvisioningAttrList* ACDAudioManager::Get(ProvisioningAttrList& rRequestAttributes)
{
   ProvisioningAttrList* pResponse;
   ProvisioningAttrList* pAudioInstance;
   UtlString             name;
   UtlSList*             pAudioList;


   osPrintf("{method} = get\n{object-class} = acd-audio\n");
   rRequestAttributes.dumpAttributes();
   osPrintf("\n");

   mLock.acquire();

   // Extract the instance index from the request attributes.
   if (rRequestAttributes.getAttribute(AUDIO_NAME_TAG, name)) {
      // A specific instance has been specified, verify that it exists
      ACDAudio* pAudioRef = getAcdAudioReference(name);
      if (pAudioRef == NULL) {
         // There is no instance.
         mLock.release();
         pResponse = new ProvisioningAttrList;
         pResponse->setAttribute("method-name", "get");
         pResponse->setAttribute("result-code", ProvisioningAgent::UNKNOWN_OBJECT);
         pResponse->setAttribute("result-text", "Unknown instance");
         return pResponse;
      }

      // Call the instance to get the requested attributes
      pResponse = new ProvisioningAttrList;
      try {
         pAudioRef->getAttributes(rRequestAttributes, pResponse);
      }
      catch (UtlString error) {
         // The request for attributes failed, send back the response
         mLock.release();
         pResponse->setAttribute("method-name", "get");
         pResponse->setAttribute("result-code", ProvisioningAgent::FAILURE);
         pResponse->setAttribute("result-text", error);
         return pResponse;
      }

      // Send back the response
      mLock.release();
      pResponse->setAttribute("method-name", "get");
      pResponse->setAttribute("result-code", ProvisioningAgent::SUCCESS);
      pResponse->setAttribute("result-text", "SUCCESS");
      pResponse->setAttribute("object-class", ACD_AUDIO_TAG);
      pResponse->setAttribute(AUDIO_NAME_TAG, name);
      return pResponse;
   }
   else {
      // No specific instance was requested, send back a list of the available instances
      // Find the first instance.
      TiXmlNode* pInstanceNode = findPSInstance(ACD_AUDIO_TAG);
      pAudioList = new UtlSList;

      // Build up a list of instances
      while (pInstanceNode != NULL) {
         // Read the index parameter
         getPSAttribute(pInstanceNode, AUDIO_NAME_TAG, name);

         // Create the list entry
         pAudioInstance = new ProvisioningAttrList;
         pAudioInstance->setAttribute("object-class", ACD_AUDIO_TAG);
         pAudioInstance->setAttribute(AUDIO_NAME_TAG, name);
         pAudioList->append(pAudioInstance->getData());

         // Get the next instance.
         pInstanceNode = pInstanceNode->NextSibling();
      }

      // Send back the response
      mLock.release();
      pResponse = new ProvisioningAttrList;
      pResponse->setAttribute("method-name", "get");
      pResponse->setAttribute("result-code", ProvisioningAgent::SUCCESS);
      pResponse->setAttribute("result-text", "SUCCESS");
      pResponse->setAttribute("object-class-list", pAudioList);
      return pResponse;
   }
}