Skip to content
This repository has been archived by the owner on Sep 30, 2018. It is now read-only.

Commit

Permalink
factor out OnCachingComplete from OnJobComplete - we shouldn't really…
Browse files Browse the repository at this point in the history
… be calling OnJobComplete on a job not in the queue
  • Loading branch information
Jonathan Marshall committed May 26, 2012
1 parent b1d686d commit abded5e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
46 changes: 24 additions & 22 deletions xbmc/TextureCache.cpp
Expand Up @@ -172,7 +172,7 @@ CStdString CTextureCache::CacheImage(const CStdString &image, CBaseTexture **tex
// cache the texture directly
CTextureCacheJob job(url);
bool success = job.CacheTexture(texture);
OnJobComplete(0, success, &job);
OnCachingComplete(success, &job);
return success ? GetCachedPath(job.m_details.file) : "";
}
lock.Leave();
Expand Down Expand Up @@ -258,32 +258,34 @@ CStdString CTextureCache::GetCachedPath(const CStdString &file)
return URIUtils::AddFileToFolder(g_settings.GetThumbnailsFolder(), file);
}

void CTextureCache::OnJobComplete(unsigned int jobID, bool success, CJob *job)
void CTextureCache::OnCachingComplete(bool success, CTextureCacheJob *job)
{
if (strcmp(job->GetType(), "cacheimage") == 0)
if (success)
{
CTextureCacheJob *cacheJob = (CTextureCacheJob *)job;
if (success)
{
if (cacheJob->m_oldHash == cacheJob->m_details.hash)
SetCachedTextureValid(cacheJob->m_url, cacheJob->m_details.updateable);
else
AddCachedTexture(cacheJob->m_url, cacheJob->m_details);
}
if (job->m_oldHash == job->m_details.hash)
SetCachedTextureValid(job->m_url, job->m_details.updateable);
else
AddCachedTexture(job->m_url, job->m_details);
}

{ // remove from our processing list
CSingleLock lock(m_processingSection);
std::set<CStdString>::iterator i = m_processing.find(cacheJob->m_url);
if (i != m_processing.end())
m_processing.erase(i);
}
{ // remove from our processing list
CSingleLock lock(m_processingSection);
std::set<CStdString>::iterator i = m_processing.find(job->m_url);
if (i != m_processing.end())
m_processing.erase(i);
}

m_completeEvent.Set();
m_completeEvent.Set();

// TODO: call back to the UI indicating that it can update it's image...
if (success && g_advancedSettings.m_useDDSFanart && !cacheJob->m_details.file.empty())
AddJob(new CTextureDDSJob(GetCachedPath(cacheJob->m_details.file)));
}
// TODO: call back to the UI indicating that it can update it's image...
if (success && g_advancedSettings.m_useDDSFanart && !job->m_details.file.empty())
AddJob(new CTextureDDSJob(GetCachedPath(job->m_details.file)));
}

void CTextureCache::OnJobComplete(unsigned int jobID, bool success, CJob *job)
{
if (strcmp(job->GetType(), "cacheimage") == 0)
OnCachingComplete(success, (CTextureCacheJob *)job);
return CJobQueue::OnJobComplete(jobID, success, job);
}

Expand Down
8 changes: 8 additions & 0 deletions xbmc/TextureCache.h
Expand Up @@ -203,6 +203,14 @@ class CTextureCache : public CJobQueue
virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
virtual void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job);

/*! \brief Called when a caching job has completed.
Removes the job from our processing list, updates the database
and fires a DDS job if appropriate.
\param success whether the job was successful.
\param job the caching job.
*/
void OnCachingComplete(bool success, CTextureCacheJob *job);

CCriticalSection m_databaseSection;
CTextureDatabase m_database;
std::set<CStdString> m_processing; ///< currently processing list to avoid 2 jobs being processed at once
Expand Down

0 comments on commit abded5e

Please sign in to comment.