Fixed Library referring itself through the nowPlaying tracklist. There is a memory leak in the current trunk.

This commit is contained in:
Daniel Önnerby 2008-08-12 21:08:57 +00:00
parent 89e29f62f3
commit a440be19aa
13 changed files with 46 additions and 33 deletions

View File

@ -52,12 +52,21 @@ Library::Base::Base(utfstring identifier)
,queueCallbackStarted(false)
,bCurrentQueryCanceled(false)
,exit(false)
,nowPlaying(new musik::core::tracklist::Standard())
{
}
musik::core::tracklist::Ptr Library::Base::NowPlaying(){
return this->nowPlaying;
if(tracklist::Ptr tracklist = this->nowPlaying.lock()){
return tracklist;
}
tracklist::Ptr tracklist(new musik::core::tracklist::Standard());
this->nowPlaying = tracklist;
if(LibraryPtr thisPtr = this->self.lock()){
tracklist->SetLibrary(thisPtr);
}
return tracklist;
}
Library::Base::~Base(void){

View File

@ -37,6 +37,7 @@
#pragma once
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
//////////////////////////////////////////////////////////////////////////////
// Forward declare
namespace musik{ namespace core{
@ -50,6 +51,7 @@ namespace musik{ namespace core{
class Base;
}
typedef boost::shared_ptr<Library::Base> LibraryPtr;
typedef boost::weak_ptr<Library::Base> LibraryWeakPtr;
} }
//////////////////////////////////////////////////////////////////////////////
@ -86,8 +88,9 @@ namespace musik{ namespace core{ namespace Library{
///musik::core::Library::LocalDB
//////////////////////////////////////////
class Base : boost::noncopyable{
public:
protected:
Base(utfstring identifier);
public:
virtual ~Base(void);
//////////////////////////////////////////
@ -259,10 +262,11 @@ class Base : boost::noncopyable{
bool exit;
boost::condition waitCondition;
musik::core::tracklist::Ptr nowPlaying;
musik::core::tracklist::WeakPtr nowPlaying;
public:
boost::mutex libraryMutex;
LibraryWeakPtr self;
};
@ -273,4 +277,5 @@ class Base : boost::noncopyable{
namespace musik{ namespace core{
typedef boost::shared_ptr<musik::core::Library::Base> LibraryPtr;
typedef boost::weak_ptr<Library::Base> LibraryWeakPtr;
} }

View File

@ -58,6 +58,12 @@ Library::LocalDB::LocalDB(utfstring identifier)
{
}
LibraryPtr Library::LocalDB::Create(utfstring identifier){
LibraryPtr lib(new Library::LocalDB(identifier));
lib->self = lib;
return lib;
}
Library::LocalDB::~LocalDB(void){
this->Exit();
this->threads.join_all();

View File

@ -69,9 +69,11 @@ namespace musik{ namespace core{ namespace Library{
///Indexer
//////////////////////////////////////////
class LocalDB : public Library::Base{
private:
LocalDB(utfstring identifier);
public:
// Methods:
LocalDB(utfstring identifier);
static LibraryPtr Create(utfstring identifier);
~LocalDB(void);
bool Startup();
@ -96,6 +98,7 @@ class LocalDB : public Library::Base{
//////////////////////////////////////////
musik::core::Indexer indexer;
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -63,6 +63,12 @@ Library::Remote::Remote(utfstring identifier)
{
}
LibraryPtr Library::Remote::Create(utfstring identifier){
LibraryPtr lib(new Library::Remote(identifier));
lib->self = lib;
return lib;
}
Library::Remote::~Remote(void){
this->Exit();
this->threads.join_all();

View File

@ -58,9 +58,11 @@ namespace musik{ namespace core{ namespace Library{
///Library used for your remote music.
//////////////////////////////////////////
class Remote : public Library::Base{
private:
Remote(utfstring identifier);
public:
// Methods:
Remote(utfstring identifier);
static LibraryPtr Create(utfstring identifier);
~Remote(void);
bool Startup();

View File

@ -79,10 +79,10 @@ void LibraryFactory::AddLibrary(utfstring name,int type){
LibraryPtr lib;
switch(type){
case Types::Remote:
lib.reset(new Library::Remote(name));
lib = Library::Remote::Create(name);
break;
default:
lib.reset(new Library::LocalDB(name));
lib = Library::LocalDB::Create(name);
}
if(lib){

View File

@ -65,6 +65,7 @@ PlaybackQueue::PlaybackQueue(void)
PlaybackQueue::~PlaybackQueue(void)
{
this->transport.Stop();
this->nowPlaying.reset();
}
//////////////////////////////////////////

View File

@ -39,6 +39,8 @@
#pragma warning (disable : 4996 4018 4482)
#include <vld/vld.h>
#include <core/config.h>
#include <sigslot/sigslot.h>
@ -73,5 +75,4 @@
#include <boost/noncopyable.hpp>
*/
#include <vld/vld.h>

View File

@ -53,6 +53,7 @@ namespace musik{ namespace core{
#include <core/Library/Base.h>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <sigslot/sigslot.h>
namespace musik{ namespace core{
@ -96,6 +97,7 @@ namespace musik{ namespace core{
};
typedef boost::shared_ptr<IRandomAccess> Ptr;
typedef boost::weak_ptr<IRandomAccess> WeakPtr;
}
} }

View File

@ -87,12 +87,6 @@ void LibraryWindowController::OnViewCreated(Window* window)
}
// create sources view/controller
/*
*/
}
void LibraryWindowController::OnResize(Window* window, Size size)
@ -100,17 +94,3 @@ void LibraryWindowController::OnResize(Window* window, Size size)
RedrawLock redrawLock(&this->view);
// this->clientView->Resize(this->mainWindow.ClientSize());
}
/*
void LibraryWindowController::QueryQueueStart(){
this->LibraryCallbackTimer.ConnectToWindow(&this->mainWindow);
this->LibraryCallbackTimer.Start();
}
void LibraryWindowController::QueryQueueEnd(){
this->LibraryCallbackTimer.Stop();
}
void LibraryWindowController::QueryQueueLoop(){
musik::core::LibraryFactory::GetCurrentLibrary()->RunCallbacks();
}
*/

View File

@ -45,7 +45,6 @@
#include <cube/TracklistView.hpp>
#include <cube/TracklistController.hpp>
#include <core/PlaybackQueue.h>
#include <win32cpp/Label.hpp>
using namespace musik::cube;

View File

@ -48,6 +48,8 @@
//////////////////////////////////////////////////////////////////////////////
#pragma warning (disable : 4996 4018 4482)
#include "vld/vld.h"
#include <core/config.h>
#include <core/LibraryFactory.h>
#include <core/ITrack.h>
@ -76,8 +78,5 @@
#include <win32cpp/Application.hpp>
#include <win32cpp/TopLevelWindow.hpp>
//////////////////////////////////////////////////////////////////////////////
#include "vld/vld.h"
//////////////////////////////////////////////////////////////////////////////