mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-29 19:20:28 +00:00
Got rid of IRetainedTagStore -- only ITagStore is necessary now.
Next up: IRetainedTrack... hopefully.
This commit is contained in:
parent
a864efb1bc
commit
6f2af2cb16
@ -220,7 +220,6 @@
|
||||
<ClInclude Include="audio\Stream.h" />
|
||||
<ClInclude Include="sdk\IPreferences.h" />
|
||||
<ClInclude Include="sdk\IRetainedTrack.h" />
|
||||
<ClInclude Include="sdk\IRetainedTagStore.h" />
|
||||
<ClInclude Include="sdk\ISimpleDataProvider.h" />
|
||||
<ClInclude Include="sdk\ISpectrumVisualizer.h" />
|
||||
<ClInclude Include="sdk\ITrack.h" />
|
||||
|
@ -474,8 +474,5 @@
|
||||
<ClInclude Include="sdk\ITagStore.h">
|
||||
<Filter>src\sdk\library</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sdk\IRetainedTagStore.h">
|
||||
<Filter>src\sdk\library</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -358,13 +358,14 @@ void Indexer::ReadMetadataFromFile(
|
||||
const std::string& pathId)
|
||||
{
|
||||
musik::core::IndexerTrack track(0);
|
||||
TagStore* store = nullptr;
|
||||
|
||||
/* get cached filesize, parts, size, etc */
|
||||
if (track.NeedsToBeIndexed(file, this->dbConnection)) {
|
||||
bool saveToDb = false;
|
||||
|
||||
/* read the tag from the plugin */
|
||||
TagStore store(track);
|
||||
store = new TagStore(track);
|
||||
typedef TagReaderList::iterator Iterator;
|
||||
Iterator it = this->tagReaders.begin();
|
||||
while (it != this->tagReaders.end()) {
|
||||
@ -374,7 +375,7 @@ void Indexer::ReadMetadataFromFile(
|
||||
fprintf(logFile, " - %s\n", file.string().c_str());
|
||||
}
|
||||
|
||||
if ((*it)->Read(file.string().c_str(), &store)) {
|
||||
if ((*it)->Read(file.string().c_str(), store)) {
|
||||
saveToDb = true;
|
||||
break;
|
||||
}
|
||||
@ -434,6 +435,10 @@ void Indexer::ReadMetadataFromFile(
|
||||
}
|
||||
}
|
||||
|
||||
if (store) {
|
||||
store->Release();
|
||||
}
|
||||
|
||||
this->IncrementTracksScanned();
|
||||
|
||||
#ifdef MULTI_THREADED_INDEXER
|
||||
@ -535,7 +540,9 @@ ScanResult Indexer::SyncSource(IIndexerSource* source) {
|
||||
fprintf(logFile, " - %s\n", track->GetString(constants::Track::FILENAME).c_str());
|
||||
}
|
||||
|
||||
source->ScanTrack(this, new RetainedTagStore(track), tracks.ColumnText(2));
|
||||
TagStore* store = new TagStore(track);
|
||||
source->ScanTrack(this, store, tracks.ColumnText(2));
|
||||
store->Release();
|
||||
this->IncrementTracksScanned();
|
||||
}
|
||||
}
|
||||
@ -796,10 +803,10 @@ void Indexer::RunAnalyzers() {
|
||||
if (LibraryTrack::Load(&track, this->dbConnection)) {
|
||||
PluginVector runningAnalyzers;
|
||||
|
||||
TagStore store(track);
|
||||
TagStore* store = new TagStore(track);
|
||||
PluginVector::iterator plugin = analyzers.begin();
|
||||
for ( ; plugin != analyzers.end(); ++plugin) {
|
||||
if ((*plugin)->Start(&store)) {
|
||||
if ((*plugin)->Start(store)) {
|
||||
runningAnalyzers.push_back(*plugin);
|
||||
}
|
||||
}
|
||||
@ -817,7 +824,7 @@ void Indexer::RunAnalyzers() {
|
||||
while ((buffer = stream->GetNextProcessedOutputBuffer()) && !runningAnalyzers.empty()) {
|
||||
PluginVector::iterator plugin = runningAnalyzers.begin();
|
||||
while(plugin != runningAnalyzers.end()) {
|
||||
if ((*plugin)->Analyze(&store, buffer)) {
|
||||
if ((*plugin)->Analyze(store, buffer)) {
|
||||
++plugin;
|
||||
}
|
||||
else {
|
||||
@ -832,7 +839,7 @@ void Indexer::RunAnalyzers() {
|
||||
PluginVector::iterator plugin = analyzers.begin();
|
||||
|
||||
for ( ; plugin != analyzers.end(); ++plugin) {
|
||||
if ((*plugin)->End(&store)) {
|
||||
if ((*plugin)->End(store)) {
|
||||
successPlugins++;
|
||||
}
|
||||
}
|
||||
@ -846,6 +853,10 @@ void Indexer::RunAnalyzers() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (store) {
|
||||
store->Release();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->Exited()) {
|
||||
@ -861,12 +872,12 @@ bool Indexer::Exited() {
|
||||
return this->exit;
|
||||
}
|
||||
|
||||
IRetainedTagStore* Indexer::CreateWriter() {
|
||||
ITagStore* Indexer::CreateWriter() {
|
||||
std::shared_ptr<Track> track(new IndexerTrack(0));
|
||||
return new RetainedTagStore(track);
|
||||
return new TagStore(track);
|
||||
}
|
||||
|
||||
bool Indexer::Save(IIndexerSource* source, IRetainedTagStore* track, const char* externalId) {
|
||||
bool Indexer::Save(IIndexerSource* source, ITagStore* store, const char* externalId) {
|
||||
if (source->SourceId() == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -877,9 +888,9 @@ bool Indexer::Save(IIndexerSource* source, IRetainedTagStore* track, const char*
|
||||
|
||||
/* two levels of unpacking with dynamic_casts. don't tell anyone,
|
||||
it'll be our little secret. */
|
||||
RetainedTagStore* rtw = dynamic_cast<RetainedTagStore*>(track);
|
||||
if (rtw) {
|
||||
IndexerTrack* it = rtw->As<IndexerTrack*>();
|
||||
TagStore* ts = dynamic_cast<TagStore*>(store);
|
||||
if (ts) {
|
||||
IndexerTrack* it = ts->As<IndexerTrack*>();
|
||||
if (it) {
|
||||
it->SetValue(constants::Track::EXTERNAL_ID, externalId);
|
||||
it->SetValue(constants::Track::SOURCE_ID, std::to_string(source->SourceId()).c_str());
|
||||
|
@ -78,14 +78,14 @@ namespace musik { namespace core {
|
||||
virtual State GetState() { return this->state; }
|
||||
|
||||
/* IIndexerWriter */
|
||||
virtual musik::core::sdk::IRetainedTagStore* CreateWriter();
|
||||
virtual musik::core::sdk::ITagStore* CreateWriter();
|
||||
virtual bool RemoveByUri(musik::core::sdk::IIndexerSource* source, const char* uri);
|
||||
virtual bool RemoveByExternalId(musik::core::sdk::IIndexerSource* source, const char* id);
|
||||
virtual int RemoveAll(musik::core::sdk::IIndexerSource* source);
|
||||
|
||||
virtual bool Save(
|
||||
musik::core::sdk::IIndexerSource* source,
|
||||
musik::core::sdk::IRetainedTagStore* track,
|
||||
musik::core::sdk::ITagStore* store,
|
||||
const char* externalId = "");
|
||||
|
||||
/* IIndexerNotifier */
|
||||
|
@ -82,39 +82,4 @@ double RetainedTrack::GetDouble(const char* key, double defaultValue) {
|
||||
|
||||
int64_t RetainedTrack::GetId() {
|
||||
return track->GetId();
|
||||
}
|
||||
|
||||
/* * * * RetainedTagStore * * * */
|
||||
|
||||
RetainedTagStore::RetainedTagStore(TrackPtr track) {
|
||||
this->count = 1;
|
||||
this->track = track;
|
||||
}
|
||||
|
||||
RetainedTagStore::~RetainedTagStore() {
|
||||
}
|
||||
|
||||
void RetainedTagStore::Release() {
|
||||
int c = this->count.fetch_sub(1);
|
||||
if (c == 1) { /* fetched before sub */
|
||||
this->count = 0;
|
||||
this->track.reset();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void RetainedTagStore::Retain() {
|
||||
++this->count;
|
||||
}
|
||||
|
||||
void RetainedTagStore::SetValue(const char* metakey, const char* value) {
|
||||
this->track->SetValue(metakey, value);
|
||||
}
|
||||
|
||||
void RetainedTagStore::ClearValue(const char* metakey) {
|
||||
this->track->ClearValue(metakey);
|
||||
}
|
||||
|
||||
void RetainedTagStore::SetThumbnail(const char *data, long size) {
|
||||
this->track->SetThumbnail(data, size);
|
||||
}
|
@ -33,7 +33,6 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <core/sdk/IRetainedTrack.h>
|
||||
#include <core/sdk/IRetainedTagStore.h>
|
||||
#include "Track.h"
|
||||
#include <atomic>
|
||||
|
||||
@ -61,28 +60,5 @@ namespace musik { namespace core {
|
||||
TrackPtr track;
|
||||
};
|
||||
|
||||
class RetainedTagStore : public musik::core::sdk::IRetainedTagStore {
|
||||
public:
|
||||
RetainedTagStore(TrackPtr track);
|
||||
virtual ~RetainedTagStore();
|
||||
|
||||
template <typename T> T As() {
|
||||
return dynamic_cast<T>(track.get());
|
||||
}
|
||||
|
||||
/* IRetainedTagStore */
|
||||
virtual void Release();
|
||||
virtual void Retain();
|
||||
|
||||
/* ITagStore */
|
||||
virtual void SetValue(const char* metakey, const char* value);
|
||||
virtual void ClearValue(const char* metakey);
|
||||
virtual void SetThumbnail(const char *data, long size);
|
||||
|
||||
private:
|
||||
std::atomic<int> count;
|
||||
TrackPtr track;
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
|
@ -66,10 +66,12 @@ struct NoDeleter {
|
||||
};
|
||||
|
||||
TagStore::TagStore(TrackPtr track) {
|
||||
this->count = 1;
|
||||
this->track = track;
|
||||
}
|
||||
|
||||
TagStore::TagStore(Track& track) {
|
||||
this->count = 1;
|
||||
this->track = TrackPtr(&track, NoDeleter<Track>());
|
||||
}
|
||||
|
||||
@ -83,4 +85,17 @@ void TagStore::ClearValue(const char* key) {
|
||||
|
||||
void TagStore::SetThumbnail(const char *data, long size) {
|
||||
this->track->SetThumbnail(data, size);
|
||||
}
|
||||
|
||||
void TagStore::Release() {
|
||||
int c = this->count.fetch_sub(1);
|
||||
if (c == 1) { /* fetched before sub */
|
||||
this->count = 0;
|
||||
this->track.reset();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void TagStore::Retain() {
|
||||
++this->count;
|
||||
}
|
@ -38,6 +38,7 @@
|
||||
#include <core/library/ILibrary.h>
|
||||
#include <core/sdk/ITrack.h>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
@ -87,12 +88,19 @@ namespace musik { namespace core {
|
||||
TagStore(TrackPtr track);
|
||||
TagStore(Track& track);
|
||||
|
||||
template <typename T> T As() {
|
||||
return dynamic_cast<T>(track.get());
|
||||
}
|
||||
|
||||
virtual void Retain() override;
|
||||
virtual void Release() override;
|
||||
virtual void SetValue(const char* key, const char* value) override;
|
||||
virtual void ClearValue(const char* key) override;
|
||||
virtual void SetThumbnail(const char *data, long size) override;
|
||||
|
||||
private:
|
||||
TrackPtr track;
|
||||
std::atomic<int> count;
|
||||
};
|
||||
|
||||
} }
|
||||
|
@ -52,7 +52,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
|
||||
virtual void ScanTrack(
|
||||
IIndexerWriter* indexer,
|
||||
IRetainedTagStore* track,
|
||||
ITagStore* store,
|
||||
const char* externalId) = 0;
|
||||
|
||||
virtual void Interrupt() = 0;
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IRetainedTagStore.h"
|
||||
#include "ITagStore.h"
|
||||
|
||||
namespace musik { namespace core { namespace sdk {
|
||||
|
||||
@ -42,11 +42,11 @@ namespace musik { namespace core { namespace sdk {
|
||||
|
||||
class IIndexerWriter {
|
||||
public:
|
||||
virtual IRetainedTagStore* CreateWriter() = 0;
|
||||
virtual ITagStore* CreateWriter() = 0;
|
||||
|
||||
virtual bool Save(
|
||||
IIndexerSource* source,
|
||||
IRetainedTagStore* track,
|
||||
ITagStore* track,
|
||||
const char* externalId = "") = 0;
|
||||
|
||||
virtual bool RemoveByUri(IIndexerSource* source, const char* uri) = 0;
|
||||
|
@ -1,48 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2007-2017 musikcube team
|
||||
//
|
||||
// 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 "ITagStore.h"
|
||||
|
||||
namespace musik { namespace core { namespace sdk {
|
||||
|
||||
class IRetainedTagStore : public ITagStore {
|
||||
public:
|
||||
virtual void Release() = 0;
|
||||
virtual void Retain() = 0;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
@ -38,9 +38,11 @@ namespace musik { namespace core { namespace sdk {
|
||||
|
||||
class ITagStore {
|
||||
public:
|
||||
virtual void Retain() = 0;
|
||||
virtual void Release() = 0;
|
||||
virtual void SetValue(const char* key, const char* value) = 0;
|
||||
virtual void ClearValue(const char* value) = 0;
|
||||
virtual void SetThumbnail(const char *data, long size) = 0; /* should be SetBlob with a key */
|
||||
virtual void SetThumbnail(const char *data, long size) = 0;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
@ -373,7 +373,7 @@ void CddaIndexerSource::Interrupt() {
|
||||
|
||||
void CddaIndexerSource::ScanTrack(
|
||||
IIndexerWriter* indexer,
|
||||
IRetainedTagStore* track,
|
||||
ITagStore* tagStore,
|
||||
const char* externalId)
|
||||
{
|
||||
if (!exists(this->discIds, this->model, externalId)) {
|
||||
|
@ -56,7 +56,7 @@ class CddaIndexerSource :
|
||||
|
||||
virtual void ScanTrack(
|
||||
musik::core::sdk::IIndexerWriter* indexer,
|
||||
musik::core::sdk::IRetainedTagStore* track,
|
||||
musik::core::sdk::ITagStore* tagStore,
|
||||
const char* externalId);
|
||||
|
||||
virtual void Interrupt();
|
||||
|
Loading…
x
Reference in New Issue
Block a user