Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
WSPCallContext Class Reference

#include <wspprivate.h>

Inheritance diagram for WSPCallContext:
Inheritance graph
[legend]
Collaboration diagram for WSPCallContext:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 WSPCallContext (WSPProxy *aProxy, nsISOAPCall *aSOAPCall, const nsAString &aMethodName, nsIWSDLOperation *aOperation)
virtual ~WSPCallContext ()
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBSERVICECALLCONTEXT
NS_DECL_NSIWEBSERVICESOAPCALLCONTEXT
NS_DECL_NSISOAPRESPONSELISTENER
nsresult 
CallAsync (PRUint32 aListenerMethodIndex, nsISupports *aListener)
nsresult CallSync (PRUint32 aMethodIndex, nsXPTCMiniVariant *params)
void abort (in nsIException error)
 Called to abort a pending call.
boolean handleResponse (in nsISOAPResponse aResponse, in nsISOAPCall aCall, in unsigned long status, in boolean aLast)
 This method is invoked when we receive an asynchronous response to a SOAP message.

Public Attributes

readonly attribute nsISOAPResponse soapResponse
 For users who want access to the lower-level constructs that are used for the method invocation, this attributes provides the SOAP response once the call has completed.
const PRUint32 PENDING = 0
 Possible values of the status attribute.
const PRUint32 SUCCEEDED = 1
const PRUint32 FAILED = 2
const PRUint32 ABORTED = 3
readonly attribute
nsIWebServiceProxy 
proxy
 The proxy object on which the call was made.
readonly attribute AString methodName
 The name of the method that was invoked.
readonly attribute PRUint32 status
 The status of the call, whether pending, completed successfully or completed with a fault.
readonly attribute nsIException pendingException
 The exception generated by the call if the status is FAILURE.
readonly attribute nsIWSDLOperation operation
 The WSDL operation that correpsonds to the method being invoked.

Protected Member Functions

nsresult CallCompletionListener ()

Protected Attributes

WSPProxymProxy
nsCOMPtr< nsISOAPCallmCall
nsString mMethodName
nsCOMPtr< nsIWSDLOperationmOperation
nsCOMPtr< nsISOAPCallCompletionmCompletion
nsCOMPtr< nsISOAPResponsemResponse
nsresult mStatus
nsCOMPtr< nsIExceptionmException
nsCOMPtr< nsISupports > mAsyncListener
PRUint32 mListenerMethodIndex

Detailed Description

Definition at line 178 of file wspprivate.h.


Constructor & Destructor Documentation

WSPCallContext::WSPCallContext ( WSPProxy aProxy,
nsISOAPCall aSOAPCall,
const nsAString &  aMethodName,
nsIWSDLOperation aOperation 
)

Definition at line 48 of file wspcallcontext.cpp.

  : mProxy(aProxy), mCall(aSOAPCall), mMethodName(aMethodName),
    mOperation(aOperation), mStatus(NS_ERROR_NOT_AVAILABLE)
{
  NS_IF_ADDREF(mProxy);
}

Definition at line 57 of file wspcallcontext.cpp.


Member Function Documentation

Called to abort a pending call.

If the call is still pending, its callback instance's onError will be invoked, passing in the specified exception.

Parameters:
errorThe exception passed to the callback instance's onError method.
nsresult WSPCallContext::CallAsync ( PRUint32  aListenerMethodIndex,
nsISupports *  aListener 
)

Definition at line 162 of file wspcallcontext.cpp.

{
  mAsyncListener = aListener;
  mListenerMethodIndex = aListenerMethodIndex;
  return mCall->AsyncInvoke(this, getter_AddRefs(mCompletion));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 177 of file wspcallcontext.cpp.

{
  nsresult rv;
#define PARAM_BUFFER_COUNT     8  /* Never set less than 2 */

  if (!mProxy) {
    NS_ERROR("Huh, no proxy?");

    return NS_OK;
  }
  nsXPTCVariant paramBuffer[PARAM_BUFFER_COUNT];
  nsXPTCVariant* dispatchParams = nsnull;

  nsCOMPtr<nsISOAPFault> fault;
  mCompletion->GetResponse(getter_AddRefs(mResponse));
  if (mResponse) {
    rv = mResponse->GetFault(getter_AddRefs(fault));
    if (NS_FAILED(rv)) {
      return rv;
    }
  }
  if (!mResponse || fault) {
    WSPException* exception = new WSPException(fault, mStatus);
    if (!exception) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    mException = exception;
  }

  nsCOMPtr<nsIInterfaceInfo> listenerInterfaceInfo;
  mProxy->GetListenerInterfaceInfo(getter_AddRefs(listenerInterfaceInfo));
  NS_ASSERTION(listenerInterfaceInfo,
               "WSPCallContext:Missing listener interface info");

  const nsXPTMethodInfo* methodInfo;
  rv = listenerInterfaceInfo->GetMethodInfo(mListenerMethodIndex,
                                            &methodInfo);
  if (NS_FAILED(rv)) {
    return rv;
  }

  PRUint32 paramCount = methodInfo->GetParamCount();
  if(paramCount > PARAM_BUFFER_COUNT) {
    if(!(dispatchParams = new nsXPTCVariant[paramCount])) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
  }
  else {
    dispatchParams = paramBuffer;
  }

  // iterate through the params to clear flags
  PRUint32 i;
  for(i = 0; i < paramCount; i++) {
    nsXPTCVariant* dp = &dispatchParams[i];
    dp->ClearFlags();
    dp->val.p = nsnull;
  }

  PRUint32 headerCount = 0, bodyCount = 0;
  nsISOAPHeaderBlock** headerBlocks;
  nsISOAPParameter** bodyBlocks;

#define STRING_ARRAY_BUF_SIZE 2
  nsAutoString string_array_buf[STRING_ARRAY_BUF_SIZE];
  nsAutoString *string_array = &string_array_buf[0];
  PRUint32 string_array_index = 0;


  // If we have an exception, report it now
  if (mException) {
    nsCOMPtr<nsISupports> canonical_this = 
      do_QueryInterface(NS_STATIC_CAST(nsIWebServiceCallContext*, this));
    dispatchParams[0].val.p = mException.get();
    dispatchParams[0].SetValIsInterface();
    dispatchParams[0].type.flags = XPT_TDP_POINTER | TD_INTERFACE_TYPE;

    dispatchParams[1].val.p = canonical_this;
    dispatchParams[1].SetValIsInterface();
    dispatchParams[1].type.flags = XPT_TDP_POINTER | TD_INTERFACE_TYPE;

    rv = XPTC_InvokeByIndex(mAsyncListener, 3, 2, dispatchParams);
  }
  else if (mResponse) {
    nsCOMPtr<nsIWSDLBinding> binding;
    rv = mOperation->GetBinding(getter_AddRefs(binding));
    if (NS_FAILED(rv)) {
      goto call_completion_end;
    }

    nsCOMPtr<nsISOAPOperationBinding> operationBinding =
      do_QueryInterface(binding, &rv);
    if (NS_FAILED(rv)) {
      goto call_completion_end;
    }

    PRUint16 style;
    operationBinding->GetStyle(&style);

    rv = mResponse->GetHeaderBlocks(&headerCount, &headerBlocks);
    if (NS_FAILED(rv)) {
      goto call_completion_end;
    }
    rv = mResponse->GetParameters(style == nsISOAPPortBinding::STYLE_DOCUMENT,
                                  &bodyCount, &bodyBlocks);
    if (NS_FAILED(rv)) {
      goto call_completion_end;
    }

    nsCOMPtr<nsIWSDLMessage> output;
    rv = mOperation->GetOutput(getter_AddRefs(output));
    if (NS_FAILED(rv)) {
      goto call_completion_end;
    }
    PRUint32 partCount;
    output->GetPartCount(&partCount);

    PRUint32 maxParamIndex = methodInfo->GetParamCount()-1;

    PRUint32 bodyEntry = 0, headerEntry = 0, paramIndex = 0;
    for (i = 0; i < partCount; paramIndex++, i++) {
      nsCOMPtr<nsIWSDLPart> part;
      rv = output->GetPart(i, getter_AddRefs(part));
      if (NS_FAILED(rv)) {
        goto call_completion_end;
      }
      rv = part->GetBinding(getter_AddRefs(binding));
      if (NS_FAILED(rv)) {
        goto call_completion_end;
      }

      nsCOMPtr<nsISOAPPartBinding> partBinding =
        do_QueryInterface(binding, &rv);
      if (NS_FAILED(rv)) {
        goto call_completion_end;
      }

      PRUint16 location;
      partBinding->GetLocation(&location);

      nsCOMPtr<nsISOAPBlock> block;
      if (location == nsISOAPPartBinding::LOCATION_HEADER && 
          headerEntry < headerCount) {
        block = do_QueryInterface(headerBlocks[headerEntry++]);
      }
      else if (location == nsISOAPPartBinding::LOCATION_BODY &&
               bodyEntry < bodyCount) {
        block = do_QueryInterface(bodyBlocks[bodyEntry++]);
      }

      if (!block) {
        rv = NS_ERROR_UNEXPECTED;
        goto call_completion_end;
      }

      nsCOMPtr<nsISchemaComponent> schemaComponent;
      rv = part->GetSchemaComponent(getter_AddRefs(schemaComponent));
      if (NS_FAILED(rv)) {
        goto call_completion_end;
      }

      nsCOMPtr<nsISchemaType> type;
      nsCOMPtr<nsISchemaElement> element = do_QueryInterface(schemaComponent);
      if (element) {
        rv = element->GetType(getter_AddRefs(type));
        if (NS_FAILED(rv)) {
          goto call_completion_end;
        }
      }
      else {
        type = do_QueryInterface(schemaComponent);
      }

      rv = block->SetSchemaType(type);
      if (NS_FAILED(rv)) {
        goto call_completion_end;
      }

      nsCOMPtr<nsIVariant> value;
      rv = block->GetValue(getter_AddRefs(value));
      if (NS_FAILED(rv) || !value) {
        goto call_completion_end;
      }

      nsXPTCVariant* vars = dispatchParams + paramIndex;

      if (paramIndex < maxParamIndex &&
          methodInfo->GetParam((PRUint8)(paramIndex+1)).GetType().IsArray()) {
        paramIndex++;
      }

      NS_ASSERTION(paramIndex <= maxParamIndex,
                   "WSDL/IInfo param count mismatch");

      const nsXPTParamInfo& paramInfo = methodInfo->GetParam(paramIndex);
      
      if (XPT_TDP_TAG(paramInfo.type.prefix) == TD_DOMSTRING) {
        // If there's no more room in the string buffer on the stack
        // for this parameter, allocate an array on the heap.
        if (string_array == &string_array_buf[0] &&
            string_array_index >= STRING_ARRAY_BUF_SIZE) {
          string_array = new nsAutoString[partCount - i];

          if (!string_array) {
            rv = NS_ERROR_OUT_OF_MEMORY;

            goto call_completion_end;
          }

          // Reset string_array_index now that we switched arrays.
          string_array_index = 0;
        }

        // Give the variant value a nsAString object to hold the data
        // in.
        vars->val.p =
          NS_STATIC_CAST(nsAString *, &string_array[string_array_index++]);
      }

      rv = WSPProxy::VariantToInParameter(listenerInterfaceInfo,
                                          mListenerMethodIndex, &paramInfo,
                                          value, vars);
      if (NS_FAILED(rv)) {
        goto call_completion_end;
      }
    }

    NS_ASSERTION(paramIndex == maxParamIndex,
                 "WSDL/IInfo param count mismatch");

    dispatchParams[paramIndex].val.p =
        NS_STATIC_CAST(nsIWebServiceCallContext*, this);
    dispatchParams[paramIndex].SetValIsInterface();
    dispatchParams[paramIndex].type.flags = 
      XPT_TDP_POINTER | TD_INTERFACE_TYPE;

    rv = XPTC_InvokeByIndex(mAsyncListener, mListenerMethodIndex,
                            paramCount, dispatchParams);
  }
  else {
    rv = NS_ERROR_FAILURE;
  }

call_completion_end:
  if (headerCount) {
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(headerCount, headerBlocks);
  }
  if (bodyCount) {
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(bodyCount, bodyBlocks);
  }
  if(dispatchParams != paramBuffer) {
    delete [] dispatchParams;
  }
  if (string_array != &string_array_buf[0]) {
    delete [] string_array;
  }

  nsCOMPtr<nsIWebServiceCallContext> kungFuDeathGrip(this);
  mProxy->CallCompleted(this);
  NS_RELEASE(mProxy);

  return rv;
}

Here is the call graph for this function:

nsresult WSPCallContext::CallSync ( PRUint32  aMethodIndex,
nsXPTCMiniVariant params 
)

Definition at line 171 of file wspcallcontext.cpp.

{
  return mCall->Invoke(getter_AddRefs(mResponse));
}

Here is the call graph for this function:

Here is the caller graph for this function:

boolean nsISOAPResponseListener::handleResponse ( in nsISOAPResponse  aResponse,
in nsISOAPCall  aCall,
in unsigned long  status,
in boolean  aLast 
) [inherited]

This method is invoked when we receive an asynchronous response to a SOAP message.

The listener is registered as part of the original asynchronous call invocation.

Parameters:
aResponseThe decoded version of the response. If an error occurred transmitting the response, the status field of the response will contain an error code. The last call to the listener may contain a null response, which should only be interpreted as an error if your call expected more results than it got. If the service or the transport do not know whether to expect more results, then setting the last parameter true may only be possible after the last response has already been delivered.
aLastTrue if this is the last call to the listener.
Returns:
True to make this the last call to the listener, even if last was not true. Calls which expect a single response should return true upon receiving that response to avoid possibly recieving another callback with a null response indicating that the last response was already sent.

Member Data Documentation

Definition at line 229 of file nsIWebServiceProxy.idl.

Definition at line 228 of file nsIWebServiceProxy.idl.

nsCOMPtr<nsISupports> WSPCallContext::mAsyncListener [protected]

Definition at line 210 of file wspprivate.h.

Definition at line 203 of file wspprivate.h.

Definition at line 206 of file wspprivate.h.

readonly attribute AString nsIWebServiceCallContext::methodName [inherited]

The name of the method that was invoked.

Definition at line 241 of file nsIWebServiceProxy.idl.

Definition at line 209 of file wspprivate.h.

Definition at line 211 of file wspprivate.h.

Definition at line 204 of file wspprivate.h.

Definition at line 205 of file wspprivate.h.

Definition at line 202 of file wspprivate.h.

Definition at line 207 of file wspprivate.h.

Definition at line 208 of file wspprivate.h.

The WSDL operation that correpsonds to the method being invoked.

See also:
nsIWSDLOperation

Definition at line 263 of file nsIWebServiceProxy.idl.

Possible values of the status attribute.

A pending call has a status of PENDING. A completed call has a status of SUCCEEDED or FAILED depending on the result of the call.

Definition at line 226 of file nsIWebServiceProxy.idl.

The exception generated by the call if the status is FAILURE.

The exception object can be introspected for more information. The data member can be QIed to a nsISOAPFault instance for calls that use a SOAP binding.

Definition at line 256 of file nsIWebServiceProxy.idl.

The proxy object on which the call was made.

See also:
nsIWebServiceProxy

Definition at line 236 of file nsIWebServiceProxy.idl.

For users who want access to the lower-level constructs that are used for the method invocation, this attributes provides the SOAP response once the call has completed.

See also:
nsISOAPResponse

Definition at line 285 of file nsIWebServiceProxy.idl.

The status of the call, whether pending, completed successfully or completed with a fault.

Definition at line 247 of file nsIWebServiceProxy.idl.

Definition at line 227 of file nsIWebServiceProxy.idl.


The documentation for this class was generated from the following files: