Example #1
0
CDownloadQueue* CDownloadQueueManager::GetNextDownloadQueue()
{
  CDownloadQueue* pQueueAvailable = NULL;

  // if we haven't added any queues to the pool, add one.
  if (m_queues.size() < 1)
  {
    m_queues.push_back( new CDownloadQueue() );
  }

  // return the queue with the least number of items pending
  for (QUEUEPOOL::iterator it = m_queues.begin(); it != m_queues.end(); ++it)
  {
    // always choose the first queue if we haven't selected one yet
    if (!pQueueAvailable)
    {
      pQueueAvailable = *it;
    }
    else
    {
      // pick this queue if it has less items pending than our previous selection
      if ( pQueueAvailable->Size() > (*it)->Size() )
      {
        pQueueAvailable = *it;
      }
    }
  }

  // if we picked a queue with pending items and we haven't reached out max pool limit
  if (pQueueAvailable->Size() > 0 && m_queues.size() < MAX_DOWNLOAD_QUEUES)
  {
    // spawn a new queue
    pQueueAvailable = new CDownloadQueue();
    m_queues.push_back(pQueueAvailable);
  }

  assert(pQueueAvailable != NULL);

  return pQueueAvailable;
}
Example #2
0
TEST_F(TestDownloadQueue, RequestFile)
{
  IDownloadQueueObserver observer;
  CDownloadQueue queue;
  CTestDownloadQueueThread thread;
  unsigned int count;

  std::vector<CStdString> urls =
    CXBMCTestUtils::Instance().getTestDownloadQueueUrls();

  std::vector<CStdString>::iterator it;
  count = 0;
  for (it = urls.begin(); it < urls.end(); it++)
  {
    std::cout << "Testing URL: " << *it << "\n";
    TICKET t = queue.RequestFile(*it, &observer);
    EXPECT_EQ(count, t.dwItemId);
    count++;
  }

  thread.Sleep(1000);
  queue.Flush();
  EXPECT_EQ(0, queue.Size());
}