int ThreadBase::threadProcess()
{
   WTRACE("ThreadBase::threadProcess");
   while (1)
   {
      //default behavior: sleep until it's time to stop the thread
      switch (WaitForSingleObject( getStopEvent(), INFINITE ))
      {
         case WAIT_OBJECT_0:  return (1);
         case WAIT_TIMEOUT:   
         default:             return (0);
      }
   }
}
Beispiel #2
0
void CScrobbler::Process()
{
  CLog::Log(LOGDEBUG, "%s: Thread started.", m_strLogPrefix.c_str());
  if (!m_pHttp)
  {
    // Hack since CFileCurl isn't threadsafe
    if (!(m_pHttp = new XFILE::CFileCurl))
      return;
  }
  XbmcThreads::CEventGroup eventGroup(&m_hEvent, getStopEvent(), NULL);
  while (!m_bStop)
  {
    eventGroup.wait();
    if (m_bStop)
      break;
    
    if (m_strSessionID.IsEmpty())
    {
      time_t now = time(NULL);
      // We need to handshake.
      if (m_bBanned || m_bBadAuth ||
          ((now - m_lastFailedHandshake) < m_failedHandshakeDelay))
        continue;
      if (!DoHandshake(now))
        continue;
    }
    int action = 0;
    {
      CSingleLock lock(m_actionLock);
      action = m_action;
      m_action = 0;
    }
    if (action == SCROBBLER_ACTION_NOWPLAYING)
      DoNowPlayingNotification();
    else if (action == SCROBBLER_ACTION_SUBMIT)
    {
      m_bSubmitting = true;
      DoSubmission();
      m_bSubmitting = false;
    }
  }
  delete m_pHttp; // More of aforementioned hack 
  m_pHttp = NULL;
  CLog::Log(LOGDEBUG, "%s: Thread ended.", m_strLogPrefix.c_str());
}