summaryrefslogtreecommitdiff
path: root/media
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2012-09-18 22:17:55 +0200
committermethodus <methodus@web.de>2012-09-18 22:17:55 +0200
commitf2502b0723f10c87d515866b2135251583e588ad (patch)
tree0c82860dc742f25434a0e40cb47e0eac0421ebf6 /media
parentedebadad86f1d03867fdfc28f6be1a9c7c5d33d6 (diff)
downloadvdr-plugin-upnp-f2502b0723f10c87d515866b2135251583e588ad.tar.gz
vdr-plugin-upnp-f2502b0723f10c87d515866b2135251583e588ad.tar.bz2
Changed database columns to property names for faster access
Diffstat (limited to 'media')
-rw-r--r--media/mediaManager.cpp152
-rw-r--r--media/pluginManager.cpp52
2 files changed, 117 insertions, 87 deletions
diff --git a/media/mediaManager.cpp b/media/mediaManager.cpp
index e1b3665..388bcee 100644
--- a/media/mediaManager.cpp
+++ b/media/mediaManager.cpp
@@ -52,14 +52,14 @@ void cMediaManager::OnContainerUpdate(string uri, long updateID){
StringList cMediaManager::GetSearchCapabilities() const {
StringList list;
- list.push_back("dc:title");
- list.push_back("dc:creator");
- list.push_back("dc:description");
- list.push_back("upnp:longDescription");
- list.push_back("res@protocolInfo");
- list.push_back("upnp:class");
- list.push_back("dc:date");
- list.push_back("dc:language");
+ list.push_back(property::object::KEY_TITLE);
+ list.push_back(property::object::KEY_CREATOR);
+ list.push_back(property::object::KEY_DESCRIPTION);
+ list.push_back(property::object::KEY_LONG_DESCRIPTION);
+ list.push_back(property::object::KEY_CLASS);
+ list.push_back(property::object::KEY_DATE);
+ list.push_back(property::object::KEY_LANGUAGE);
+ list.push_back(property::resource::KEY_PROTOCOL_INFO);
return list;
}
@@ -67,14 +67,14 @@ StringList cMediaManager::GetSearchCapabilities() const {
StringList cMediaManager::GetSortCapabilities() const {
StringList list;
- list.push_back("dc:title");
- list.push_back("dc:creator");
- list.push_back("dc:description");
- list.push_back("upnp:longDescription");
- list.push_back("res@protocolInfo");
- list.push_back("upnp:class");
- list.push_back("dc:date");
- list.push_back("dc:language");
+ list.push_back(property::object::KEY_TITLE);
+ list.push_back(property::object::KEY_CREATOR);
+ list.push_back(property::object::KEY_DESCRIPTION);
+ list.push_back(property::object::KEY_LONG_DESCRIPTION);
+ list.push_back(property::object::KEY_CLASS);
+ list.push_back(property::object::KEY_DATE);
+ list.push_back(property::object::KEY_LANGUAGE);
+ list.push_back(property::resource::KEY_PROTOCOL_INFO);
return list;
}
@@ -82,14 +82,17 @@ StringList cMediaManager::GetSortCapabilities() const {
StringList cMediaManager::GetSupportedProtocolInfos() const {
tntdb::Connection conn = mConnection;
tntdb::Statement stmt = conn.prepare(
- "SELECT DISTINCT protocolInfo FROM resources;"
+ "SELECT DISTINCT :protocolInfo FROM :resourceTable;"
);
+ stmt.setString("protocolInfo", property::resource::KEY_PROTOCOL_INFO)
+ .setString("resourceTable", "resources");
+
StringList list;
for(tntdb::Statement::const_iterator it = stmt.begin(); it != stmt.end(); ++it){
tntdb::Row row = (*it);
- list.push_back(row.getString("protocolInfo"));
+ list.push_back(row.getString(property::resource::KEY_PROTOCOL_INFO));
}
return list;
@@ -167,61 +170,82 @@ bool cMediaManager::Initialise(){
mConnection.beginTransaction();
- tntdb::Statement objectTable = mConnection.prepare(
- "CREATE TABLE metadata"
- "("
- " objectID TEXT PRIMARY KEY,"
- " parentID TEXT NOT NULL,"
- " title TEXT NOT NULL,"
- " class TEXT NOT NULL,"
- " restricted INTEGER NOT NULL,"
- " creator TEXT,"
- " description TEXT,"
- " longDescription TEXT,"
- " date TEXT,"
- " language TEXT,"
- " channelNr INTEGER,"
- " channelName TEXT,"
- " scheduledStart TEXT,"
- " scheduledEnd TEXT"
- ")");
+ ss.str(string());
+
+ ss << "CREATE TABLE metadata"
+ << "("
+ << "`" << property::object::KEY_OBJECTID << "` TEXT PRIMARY KEY,"
+ << "`" << property::object::KEY_PARENTID << "` TEXT NOT NULL,"
+ << "`" << property::object::KEY_TITLE << "` TEXT NOT NULL,"
+ << "`" << property::object::KEY_CLASS << "` TEXT NOT NULL,"
+ << "`" << property::object::KEY_RESTRICTED << "` INTEGER NOT NULL,"
+ << "`" << property::object::KEY_CREATOR << "` TEXT,"
+ << "`" << property::object::KEY_DESCRIPTION << "` TEXT,"
+ << "`" << property::object::KEY_LONG_DESCRIPTION << "` TEXT,"
+ << "`" << property::object::KEY_DATE << "` TEXT,"
+ << "`" << property::object::KEY_LANGUAGE << "` TEXT,"
+ << "`" << property::object::KEY_CHANNEL_NR << "` INTEGER,"
+ << "`" << property::object::KEY_CHANNEL_NAME << "` TEXT,"
+ << "`" << property::object::KEY_SCHEDULED_START << "` TEXT,"
+ << "`" << property::object::KEY_SCHEDULED_END << "` TEXT"
+ << ")";
+
+ tntdb::Statement objectTable = mConnection.prepare(ss.str());
objectTable.execute();
- tntdb::Statement detailsTable = mConnection.prepare(
- "CREATE TABLE details"
- "("
- " propertyID INTEGER PRIMARY KEY,"
- " objectID TEXT REFERENCES metadata (objectID) ON DELETE CASCADE ON UPDATE CASCADE,"
- " property TEXT,"
- " value TEXT"
- ")");
+ ss.str(string());
+
+ ss << "CREATE TABLE details"
+ << "("
+ << " `propertyID` INTEGER PRIMARY KEY,"
+ << " `" << property::object::KEY_OBJECTID << "` TEXT "
+ << " REFERENCES metadata (`"<< property::object::KEY_OBJECTID <<"`) ON DELETE CASCADE ON UPDATE CASCADE,"
+ << " `property` TEXT,"
+ << " `value` TEXT"
+ << ")";
+
+ tntdb::Statement detailsTable = mConnection.prepare(ss.str());
detailsTable.execute();
- tntdb::Statement resourcesTable = mConnection.prepare(
- "CREATE TABLE resources"
- "("
- " resourceID INTEGER PRIMARY KEY,"
- " objectID TEXT REFERENCES metadata (objectID) ON DELETE CASCADE ON UPDATE CASCADE,"
- " resourceUri TEXT NOT NULL,"
- " protocolInfo TEXT NOT NULL,"
- " size INTEGER,"
- " duration TEXT,"
- " resolution TEXT,"
- " bitrate INTEGER,"
- " sampleFreq INTEGER,"
- " bitsPerSample INTEGER,"
- " nrAudioChannels INTEGER,"
- " colorDepth INTEGER"
- ")");
+ ss.str(string());
+
+ ss << "CREATE TABLE resources"
+ << "("
+ << " resourceID INTEGER PRIMARY KEY,"
+ << " `" << property::object::KEY_OBJECTID << "` TEXT "
+ << " REFERENCES metadata (`"<< property::object::KEY_OBJECTID <<"`) ON DELETE CASCADE ON UPDATE CASCADE,"
+ << "`" << property::resource::KEY_RESOURCE << "` TEXT NOT NULL,"
+ << "`" << property::resource::KEY_PROTOCOL_INFO << "` TEXT NOT NULL,"
+ << "`" << property::resource::KEY_SIZE << "` INTEGER,"
+ << "`" << property::resource::KEY_DURATION << "` TEXT,"
+ << "`" << property::resource::KEY_RESOLUTION << "` TEXT,"
+ << "`" << property::resource::KEY_BITRATE << "` INTEGER,"
+ << "`" << property::resource::KEY_SAMPLE_FREQUENCY << "` INTEGER,"
+ << "`" << property::resource::KEY_BITS_PER_SAMPLE << "` INTEGER,"
+ << "`" << property::resource::KEY_NR_AUDIO_CHANNELS << "` INTEGER,"
+ << "`" << property::resource::KEY_COLOR_DEPTH << "` INTEGER"
+ << ")";
+
+ tntdb::Statement resourcesTable = mConnection.prepare(ss.str());
resourcesTable.execute();
- tntdb::Statement rootContainer = mConnection.prepare(
- "INSERT INTO metadata (objectID, parentID, title, creator, class, restricted, description, longDescription)"
- " VALUES (:objectID, :parentID, :title, :creator, :class, :restricted, :description, :longDescription)"
- );
+ ss.str(string());
+
+ ss << "INSERT INTO metadata ("
+ << "`" << property::object::KEY_OBJECTID << "`, "
+ << "`" << property::object::KEY_PARENTID << "`, "
+ << "`" << property::object::KEY_TITLE << "`, "
+ << "`" << property::object::KEY_CLASS << "`, "
+ << "`" << property::object::KEY_RESTRICTED << "`, "
+ << "`" << property::object::KEY_CREATOR << "`, "
+ << "`" << property::object::KEY_DESCRIPTION << "`, "
+ << "`" << property::object::KEY_LONG_DESCRIPTION << "`) "
+ << " VALUES (:objectID, :parentID, :title, :class, :restricted, :creator, :description, :longDescription)";
+
+ tntdb::Statement rootContainer = mConnection.prepare(ss.str());
const cMediaServer::Description desc = cMediaServer::GetInstance()->GetServerDescription();
diff --git a/media/pluginManager.cpp b/media/pluginManager.cpp
index ec23ea4..5b397b7 100644
--- a/media/pluginManager.cpp
+++ b/media/pluginManager.cpp
@@ -13,36 +13,24 @@ using namespace std;
namespace upnp {
+cMetadata::ValidatorMap cMetadata::validators;
+
class PropertyValidator {
- PropertyValidator(){
+private:
+ string key;
+public:
+ PropertyValidator(string key) : key(key) {
cMetadata::RegisterPropertyValidator(this);
}
virtual ~PropertyValidator(){}
- virtual string GetPropertyKey() = 0;
+ virtual string GetPropertyKey() const { return key; };
virtual bool Validate(cMetadata::Property property) = 0;
};
-class ClassValidator : PropertyValidator {
- virtual string GetPropertyKey(){
- return property::object::KEY_CLASS;
- }
- virtual bool Validate(cMetadata::Property property){
- string value = property.GetString();
-
- if(value.find("object.container", 0) == 0 ||
- value.find("object.item", 0) == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-} ClassValidatorInst;
-
void cMetadata::RegisterPropertyValidator(PropertyValidator* validator){
- validators[validator->GetPropertyKey()] = validator;
+ string key = validator->GetPropertyKey();
+
+ validators[key] = validator;
}
bool cMetadata::SetObjectIDByUri(string uri){
@@ -94,7 +82,7 @@ bool cMetadata::AddProperty(Property property){
key.compare(property::object::KEY_SCHEDULED_START) == 0 ||
key.compare(property::object::KEY_TITLE) == 0)
{
- esyslog("UPnP\tProperty '%s' already exist!", key);
+ esyslog("UPnP\tProperty '%s' already exist!", key.c_str());
return false;
}
}
@@ -225,6 +213,24 @@ bool cMetadata::Resource::SetColorDepth(uint32_t colorDepth){
return true;
}
+class ClassValidator : public PropertyValidator {
+public:
+ ClassValidator() : PropertyValidator(property::object::KEY_CLASS) {}
+ virtual bool Validate(cMetadata::Property property){
+ string value = property.GetString();
+
+ if(value.find("object.container", 0) == 0 ||
+ value.find("object.item", 0) == 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+} ClassValidatorInst;
+
cMetadata* cUPnPResourceProvider::GetMetadata(string uri){
cMetadata* metadata = new cMetadata;