Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
TestIncrementalDownload.cpp File Reference
#include <stdlib.h>
#include "nsNetUtil.h"
#include "nsIIncrementalDownload.h"
#include "nsIRequestObserver.h"
#include "nsIProgressEventSink.h"
#include "nsIEventQueueService.h"
#include "nsIEventQueue.h"
#include "nsAutoPtr.h"
#include "prprf.h"
#include "prenv.h"

Go to the source code of this file.

Classes

class  FetchObserver

Functions

static nsresult SetupEventQ ()
static nsresult PumpEvents ()
static void QuitPumpingEvents ()
 NS_IMPL_ISUPPORTS2 (FetchObserver, nsIRequestObserver, nsIProgressEventSink) NS_IMETHODIMP FetchObserver
static nsresult DoIncrementalFetch (const char *uriSpec, const char *resultPath, PRInt32 chunkSize, PRInt32 interval)
int main (int argc, char **argv)
 The Xalan testcases app.

Function Documentation

static nsresult DoIncrementalFetch ( const char *  uriSpec,
const char *  resultPath,
PRInt32  chunkSize,
PRInt32  interval 
) [static]

Definition at line 136 of file TestIncrementalDownload.cpp.

{
  nsCOMPtr<nsILocalFile> resultFile;
  nsresult rv = NS_NewNativeLocalFile(nsDependentCString(resultPath),
                                      PR_FALSE, getter_AddRefs(resultFile));
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIURI> uri;
  rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIRequestObserver> observer = new FetchObserver();
  if (!observer)
    return NS_ERROR_OUT_OF_MEMORY;
  
  nsCOMPtr<nsIIncrementalDownload> download =
      do_CreateInstance(NS_INCREMENTALDOWNLOAD_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    return rv;

  rv = download->Init(uri, resultFile, chunkSize, interval);
  if (NS_FAILED(rv))
    return rv;

  rv = SetupEventQ();
  if (NS_FAILED(rv))
    return rv;

  rv = download->Start(observer, nsnull);
  if (NS_FAILED(rv))
    return rv;

  return PumpEvents();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 175 of file TestIncrementalDownload.cpp.

{
  if (PR_GetEnv("MOZ_BREAK_ON_MAIN"))
    NS_BREAK();

  if (argc < 5) {
    fprintf(stderr, "USAGE: TestIncrementalDownload <url> <file> <chunksize> <interval-in-seconds>\n");
    return -1;
  }

  nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
  if (NS_FAILED(rv))
    return -1;

  PRInt32 chunkSize = atoi(argv[3]);
  PRInt32 interval = atoi(argv[4]);

  rv = DoIncrementalFetch(argv[1], argv[2], chunkSize, interval);
  if (NS_FAILED(rv))
    fprintf(stderr, "ERROR: DoIncrementalFetch failed [%x]\n", rv);

  NS_ShutdownXPCOM(nsnull);
  return 0;
}

Here is the call graph for this function:

Definition at line 97 of file TestIncrementalDownload.cpp.

{
  printf("FetchObserver::OnStartRequest\n");
  return NS_OK;
}
static nsresult PumpEvents ( ) [static]

Definition at line 64 of file TestIncrementalDownload.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIEventQueueService> eqs =
      do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIEventQueue> eq;
  rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eq));
  if (NS_FAILED(rv))
    return rv;

  return eq->EventLoop();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void QuitPumpingEvents ( ) [static]

Definition at line 81 of file TestIncrementalDownload.cpp.

Here is the call graph for this function:

static nsresult SetupEventQ ( ) [static]

Definition at line 52 of file TestIncrementalDownload.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIEventQueueService> eqs =
      do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    return rv;

  return eqs->CreateMonitoredThreadEventQueue();
}

Here is the call graph for this function:

Here is the caller graph for this function: