Some cleaning of the Indexer.

Continued on the Query::PlaylistSave and started on the Query::Playlists.
This commit is contained in:
Daniel Önnerby 2008-05-01 22:19:26 +00:00
parent c405f1d7f6
commit 32a43c11a1
8 changed files with 230 additions and 30 deletions

View File

@ -58,24 +58,20 @@ Indexer::~Indexer(void){
this->oThread = NULL;
}
}
int Indexer::GetStatusCode(){
boost::mutex::scoped_lock oLock(this->oProgressMutex);
return this->iStatus;
}
utfstring Indexer::GetStatus(){
boost::mutex::scoped_lock oLock(this->oProgressMutex);
utfstring sStatus;
switch(this->iStatus){
case 1:
sStatus = boost::str( boost::wformat(UTF("Counting files: %1%"))%this->iNOFFiles );
// sStatus.Format(UTF("Counting files: %d"),this->iNOFFiles);
sStatus = boost::str( boost::utfformat(UTF("Counting files: %1%"))%this->iNOFFiles );
break;
case 2:
sStatus = boost::str( boost::wformat(UTF("Indexing: %1%"))%(this->iProgress*100));
sStatus = boost::str( boost::utfformat(UTF("Indexing: %1%"))%(this->iProgress*100));
break;
case 3:
sStatus = boost::str( boost::wformat(UTF("Cleaning up: %1%"))%(this->iProgress*100));
sStatus = boost::str( boost::utfformat(UTF("Cleaning up: %1%"))%(this->iProgress*100));
break;
}
return sStatus;
@ -406,14 +402,16 @@ void Indexer::ThreadLoop(){
while(!this->Exit()){
this->SynchronizeStart();
// Database should only be open when synchronizing
this->dbConnection.Open(this->database.c_str(),0,4096);
this->RestartSync(false);
this->Synchronize();
this->dbConnection.Close();
this->SynchronizeEnd();
boost::xtime oWaitTime;
boost::xtime_get(&oWaitTime, boost::TIME_UTC);
@ -614,7 +612,11 @@ void Indexer::SyncCleanup(){
std::vector<utfstring> Indexer::GetPaths(){
std::vector<utfstring> aPaths;
db::Statement stmt("SELECT path FROM paths ORDER BY id",this->dbConnection);
db::Connection tempDB;
tempDB.Open(this->database.c_str());
db::Statement stmt("SELECT path FROM paths ORDER BY id",tempDB);
while(stmt.Step()==db::ReturnCode::Row){
aPaths.push_back(stmt.ColumnTextUTF(0));
@ -759,17 +761,8 @@ void Indexer::SyncAddRemovePaths(){
// Small cleanup
this->dbConnection.Execute("DELETE FROM folders WHERE path_id NOT IN (SELECT id FROM paths)");
}
this->PathsUpdated();
int Indexer::LongRunningQueryInterrupt(void *indexer){
Indexer *thisIndexer = (Indexer*)indexer;
if(thisIndexer->Exit()){
return 1;
}else{
return 0;
}
}

View File

@ -42,6 +42,8 @@
#include <core/Plugin/IMetaDataReader.h>
#include <core/db/Connection.h>
#include <sigslot/sigslot.h>
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/mutex.hpp>
@ -63,14 +65,16 @@ namespace musik{ namespace core{
int iTimeout;
// double getProgress();
utfstring GetStatus();
int GetStatusCode();
void RestartSync(bool bNewRestart=true);
bool Restarted();
utfstring database;
sigslot::signal0<> SynchronizeStart;
sigslot::signal0<> SynchronizeEnd;
sigslot::signal0<> PathsUpdated;
private:
db::Connection dbConnection;
@ -95,8 +99,6 @@ namespace musik{ namespace core{
void SyncAddRemovePaths();
void SyncOptimize();
static int LongRunningQueryInterrupt(void *indexer);
class _AddRemovePath{
public:
bool add;

View File

@ -55,8 +55,10 @@ Query::PlaylistSave::PlaylistSave(void){
Query::PlaylistSave::~PlaylistSave(void){
}
void Query::PlaylistSave::SavePlaylist(int playlistId,musik::core::tracklist::IRandomAccess &tracklist){
void Query::PlaylistSave::SavePlaylist(int playlistId,utfstring playlistName,musik::core::tracklist::IRandomAccess &tracklist){
this->playlistId = playlistId;
this->playlistName = playlistName;
for(int i(0);i<tracklist.Size();++i){
musik::core::TrackPtr track=tracklist.Track(i);
if(track){
@ -69,6 +71,19 @@ bool Query::PlaylistSave::ParseQuery(Library::Base *oLibrary,db::Connection &db)
db::ScopedTransaction transaction(db);
{
db::Statement updatePlaylist("INSERT OR REPLACE INT playlists (id,name) VALUES (?,?)",db);
if(this->playlistId==0){
updatePlaylist.BindInt(0,this->playlistId);
}
updatePlaylist.BindTextUTF(1,this->playlistName);
if( updatePlaylist.Step()==db::Done ){
if(this->playlistId==0){
this->playlistId = db.LastInsertedId();
}
}
}
{
db::Statement deleteTracks("DELETE FROM playlist_tracks WHERE playlist_id=?",db);
deleteTracks.BindInt(0,this->playlistId);
@ -98,3 +113,12 @@ Query::Ptr Query::PlaylistSave::copy() const{
return Query::Ptr(new Query::PlaylistSave(*this));
}
bool Query::PlaylistSave::RunCallbacks(Library::Base *oLibrary){
boost::mutex::scoped_lock lock(oLibrary->oResultMutex);
if( (this->status & Status::Ended)!=0){
this->PlaylistSaved(this->playlistId);
return true;
}
return false;
}

View File

@ -38,10 +38,9 @@
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sigslot/sigslot.h>
#include <core/config.h>
#include <core/Query/Base.h>
@ -65,11 +64,17 @@ namespace musik{ namespace core{
PlaylistSave(void);
~PlaylistSave(void);
void SavePlaylist(int playlistId,musik::core::tracklist::IRandomAccess &tracklist);
void SavePlaylist(int playlistId,utfstring playlistName,musik::core::tracklist::IRandomAccess &tracklist);
sigslot::signal1<int> PlaylistSaved;
protected:
bool RunCallbacks(Library::Base *oLibrary);
int playlistId;
utfstring playlistName;
std::vector<int> tracks;
friend class Library::Base;

View File

@ -0,0 +1,78 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Daniel Önnerby
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include <core/Query/Playlists.h>
#include <core/Library/Base.h>
using namespace musik::core;
//////////////////////////////////////////
///\brief
///Constructor
//////////////////////////////////////////
Query::Playlists::Playlists(void){
}
//////////////////////////////////////////
///\brief
///Destructor
//////////////////////////////////////////
Query::Playlists::~Playlists(void){
}
bool Query::Playlists::ParseQuery(Library::Base *oLibrary,db::Connection &db){
return true;
}
//////////////////////////////////////////
///\brief
///Copy a query
///
///\returns
///A shared_ptr to the Query::Base
//////////////////////////////////////////
Query::Ptr Query::Playlists::copy() const{
return Query::Ptr(new Query::Playlists(*this));
}
bool Query::Playlists::RunCallbacks(Library::Base *oLibrary){
return true;
}

View File

@ -0,0 +1,85 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Daniel Önnerby
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <vector>
#include <sigslot/sigslot.h>
#include <core/config.h>
#include <core/Query/Base.h>
#include <core/tracklist/IRandomAccess.h>
//////////////////////////////////////////////////////////////
// Forward declarations
//////////////////////////////////////////////////////////////
namespace musik{ namespace core{
namespace Library{
class Base;
}
} }
namespace musik{ namespace core{
namespace Query{
class Playlists : public Query::Base{
public:
Playlists(void);
~Playlists(void);
protected:
bool RunCallbacks(Library::Base *oLibrary);
friend class Library::Base;
friend class Library::LocalDB;
virtual bool ParseQuery(Library::Base *oLibrary,db::Connection &db);
Ptr copy() const;
private:
};
}
} }

View File

@ -66,6 +66,7 @@ typedef unsigned int DBTIME;
#include <string>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#if defined(WIN32)
@ -98,6 +99,8 @@ typedef unsigned int DBTIME;
typedef wpath utfpath;
typedef wdirectory_iterator utfdirectory_iterator;
}
typedef wformat utfformat;
}
//////////////////////////////////////////
@ -136,6 +139,8 @@ typedef unsigned int DBTIME;
typedef path utfpath;
typedef directory_iterator utfdirectory_iterator;
}
typedef format utfformat;
}

View File

@ -306,6 +306,14 @@
RelativePath=".\Query\PlaylistLoad.h"
>
</File>
<File
RelativePath=".\Query\Playlists.cpp"
>
</File>
<File
RelativePath=".\Query\Playlists.h"
>
</File>
<File
RelativePath=".\Query\PlaylistSave.cpp"
>