diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 7870339bf..6b8ffdd99 100755 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -165,6 +165,8 @@ + + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index e7501a713..af0b11766 100755 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -333,5 +333,11 @@ src\sdk + + src\sdk + + + src\sdk + \ No newline at end of file diff --git a/src/core/library/track/TrackList.h b/src/core/library/track/TrackList.h index 6fc01761a..f3733f698 100755 --- a/src/core/library/track/TrackList.h +++ b/src/core/library/track/TrackList.h @@ -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); diff --git a/src/core/sdk/IMetadataValue.h b/src/core/sdk/IMetadataValue.h new file mode 100644 index 000000000..d7171ae88 --- /dev/null +++ b/src/core/sdk/IMetadataValue.h @@ -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 + +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; + }; + +} } } + diff --git a/src/core/sdk/IMetadataValueList.h b/src/core/sdk/IMetadataValueList.h new file mode 100644 index 000000000..e56c279af --- /dev/null +++ b/src/core/sdk/IMetadataValueList.h @@ -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 +#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; + }; + +} } } + diff --git a/src/core/sdk/ITrackList.h b/src/core/sdk/ITrackList.h index d995035e5..09c5dd375 100644 --- a/src/core/sdk/ITrackList.h +++ b/src/core/sdk/ITrackList.h @@ -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; diff --git a/src/glue/query/CategoryListQuery.cpp b/src/glue/query/CategoryListQuery.cpp index 78d99172e..adac59f3a 100755 --- a/src/glue/query/CategoryListQuery.cpp +++ b/src/glue/query/CategoryListQuery.cpp @@ -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++) { diff --git a/src/glue/query/CategoryListQuery.h b/src/glue/query/CategoryListQuery.h index 2549c3dc0..4aa30449f 100755 --- a/src/glue/query/CategoryListQuery.h +++ b/src/glue/query/CategoryListQuery.h @@ -36,13 +36,29 @@ #include #include +#include +#include #include 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); diff --git a/src/glue/query/TrackListQueryBase.h b/src/glue/query/TrackListQueryBase.h index 174b9a1ab..b289896cf 100755 --- a/src/glue/query/TrackListQueryBase.h +++ b/src/glue/query/TrackListQueryBase.h @@ -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; + }; }; } }