// Queue a job, but not before checking if the moodbar is enabled // in the config, if the moodbar analyzer appears to be working, // and if a job for that URL isn't already queued. Returns true // if the job is already running, false otherwise. bool MoodServer::queueJob( MetaBundle *bundle ) { if( m_moodbarBroken || !AmarokConfig::showMoodbar() ) return false; m_mutex.lock(); // Check if the currently running job is for that URL if( m_currentProcess != 0 && m_currentData.m_url == bundle->url() ) { debug() << "MoodServer::queueJob: Not re-queueing already-running job " << bundle->url().path() << endl; m_mutex.unlock(); return true; } // Check if there's already a job in the queue for that URL QValueList<ProcData>::iterator it; for( it = m_jobQueue.begin(); it != m_jobQueue.end(); ++it ) { if( (*it).m_url == bundle->url() ) { (*it).m_refcount++; debug() << "MoodServer::queueJob: Job for " << bundle->url().path() << " already in queue, increasing refcount to " << (*it).m_refcount << endl; m_mutex.unlock(); return false; } } m_jobQueue.append( ProcData( bundle->url(), bundle->url().path(), bundle->moodbar().moodFilename( bundle->url() ) ) ); debug() << "MoodServer::queueJob: Queued job for " << bundle->url().path() << ", " << m_jobQueue.size() << " jobs in queue." << endl; m_mutex.unlock(); // New jobs *must* be started from the GUI thread! QTimer::singleShot( 1000, this, SLOT( slotNewJob( void ) ) ); return false; }
/** *\fn Load(const char *filename) *\brief 加载文件。 *\param[in] filename 文件名。 *\return 是否成功 */ bool CGIF::Load(const char *filename) { if (NULL == filename) return false; Unload(); FILE *file = fopen(filename, "rb"); if (NULL == file) return false; fseek(file, 0, SEEK_END); int fileSize = ftell(file); fseek(file, 0, SEEK_SET); unsigned char *data = new unsigned char[fileSize]; fread(data, fileSize, 1, file); fclose(file); return ProcData(data); }