Added a couple new SDK interfaces -- IMetadataValue and

IMetadataValueList. Implement these interface in CategoryListQuery.

Also added TrackListQueryBase::WrappedTrackList so we can return track
query results to plugins efficiently.
This commit is contained in:
casey langen 2017-02-03 23:18:29 -08:00
parent 27bfa8fd3c
commit e4c1acca84
9 changed files with 190 additions and 1 deletions

View File

@ -165,6 +165,8 @@
<ClInclude Include="sdk\IDataStream.h" />
<ClInclude Include="sdk\IDataStreamFactory.h" />
<ClInclude Include="sdk\IMetadataReader.h" />
<ClInclude Include="sdk\IMetadataValue.h" />
<ClInclude Include="sdk\IMetadataValueList.h" />
<ClInclude Include="sdk\IOutput.h" />
<ClInclude Include="sdk\IBufferProvider.h" />
<ClInclude Include="sdk\IPcmVisualizer.h" />

View File

@ -333,5 +333,11 @@
<ClInclude Include="sdk\IPreferences.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\IMetadataValue.h">
<Filter>src\sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\IMetadataValueList.h">
<Filter>src\sdk</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -53,6 +53,7 @@ namespace musik { namespace core {
virtual ~TrackList();
/* ITrackList */
virtual void Release() { /* no delete this! not used directly by SDK. */ }
virtual size_t Count();
virtual musik::core::sdk::IRetainedTrack* GetRetainedTrack(size_t index);
virtual unsigned long long GetId(size_t index);

View File

@ -0,0 +1,49 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 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 <stddef.h>
namespace musik { namespace core { namespace sdk {
class IMetadataValue {
public:
virtual unsigned long long GetId() = 0;
virtual const char* GetValue() = 0;
virtual int GetValue(char* dst, size_t size) = 0;
};
} } }

View File

@ -0,0 +1,50 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 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 <stddef.h>
#include "IMetadataValue.h"
namespace musik { namespace core { namespace sdk {
class IMetadataValueList {
public:
virtual void Release() = 0;
virtual size_t Count() = 0;
virtual IMetadataValue* GetAt(size_t index) = 0;
};
} } }

View File

@ -43,6 +43,7 @@ namespace musik {
class ITrackList {
public:
virtual void Release() = 0;
virtual size_t Count() = 0;
virtual IRetainedTrack* GetRetainedTrack(size_t index) = 0;
virtual unsigned long long GetId(size_t index) = 0;

View File

@ -127,6 +127,29 @@ static void initFieldToQueryMap() {
FILTERED_FIELD_TO_QUERY_MAP[Playlists::TABLE_NAME] = REGULAR_PLAYLISTS_QUERY;
}
/* data structure that we can return to plugins who need metadata info */
class MetadataList : public musik::core::sdk::IMetadataValueList {
public:
MetadataList(CategoryListQuery::ResultList results) {
this->results = results;
}
virtual void Release() {
delete this;
}
virtual size_t Count() {
return this->results->size();
}
virtual musik::core::sdk::IMetadataValue* GetAt(size_t index) {
return this->results->at(index).get();
}
private:
CategoryListQuery::ResultList results;
};
CategoryListQuery::CategoryListQuery(
const std::string& trackField, const std::string& filter)
: trackField(trackField)
@ -154,6 +177,10 @@ CategoryListQuery::ResultList CategoryListQuery::GetResult() {
return this->result;
}
musik::core::sdk::IMetadataValueList* CategoryListQuery::GetSdkResult() {
return new MetadataList(this->result);
}
int CategoryListQuery::GetIndexOf(DBID id) {
auto result = this->GetResult();
for (size_t i = 0; i < result->size(); i++) {

View File

@ -36,13 +36,29 @@
#include <core/library/query/QueryBase.h>
#include <core/db/Connection.h>
#include <core/sdk/IMetadataValueList.h>
#include <core/support/Common.h>
#include <memory>
namespace musik {
namespace glue {
class CategoryListQuery : public musik::core::query::QueryBase {
public:
struct Result {
/* note we implement the SDK's IMetadataValue interface so
we can return data to plugins! */
struct Result : public musik::core::sdk::IMetadataValue {
virtual unsigned long long GetId() {
return this->id;
}
virtual const char* GetValue() {
return this->displayValue.c_str();
}
virtual int GetValue(char* dst, size_t size) {
return musik::core::CopyString(this->displayValue, dst, size);
}
std::string displayValue;
DBID id;
};
@ -61,6 +77,8 @@ namespace musik {
virtual ResultList GetResult();
virtual int GetIndexOf(DBID id);
musik::core::sdk::IMetadataValueList* GetSdkResult();
protected:
virtual bool OnRun(musik::core::db::Connection &db);

View File

@ -51,6 +51,41 @@ namespace musik {
virtual Result GetResult() = 0;
virtual Headers GetHeaders() = 0;
virtual size_t GetQueryHash() = 0;
virtual musik::core::sdk::ITrackList* GetSdkResult() {
return new WrappedTrackList(GetResult());
}
private:
class WrappedTrackList : public musik::core::sdk::ITrackList {
public:
WrappedTrackList(Result wrapped) {
this->wrapped = wrapped;
}
virtual void Release() {
delete this;
}
virtual size_t Count() {
return this->wrapped->Count();
}
virtual musik::core::sdk::IRetainedTrack* GetRetainedTrack(size_t index) {
return this->wrapped->GetRetainedTrack(index);
}
virtual unsigned long long GetId(size_t index) {
return this->wrapped->GetId(index);
}
virtual int IndexOf(unsigned long long id) {
return this->wrapped->IndexOf(id);
}
private:
Result wrapped;
};
};
}
}