summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2012-09-16 17:43:16 +0200
committermethodus <methodus@web.de>2012-09-16 17:43:16 +0200
commitedebadad86f1d03867fdfc28f6be1a9c7c5d33d6 (patch)
treeb4ff46a27c9f050bc1b0517c2f3bc62f471b7451
parent6291e30d852061c2c2dea42196232ec7746975a9 (diff)
downloadvdr-plugin-upnp-edebadad86f1d03867fdfc28f6be1a9c7c5d33d6.tar.gz
vdr-plugin-upnp-edebadad86f1d03867fdfc28f6be1a9c7c5d33d6.tar.bz2
Removed Getter/Setter for constant properties in plugin.h
-rw-r--r--include/plugin.h48
-rw-r--r--media/pluginManager.cpp147
2 files changed, 81 insertions, 114 deletions
diff --git a/include/plugin.h b/include/plugin.h
index e957505..d24f7e5 100644
--- a/include/plugin.h
+++ b/include/plugin.h
@@ -55,6 +55,8 @@ namespace resource {
}
+class PropertyValidator;
+
/**
* Metadata class
*
@@ -166,6 +168,7 @@ public:
typedef multimap<string, Property> PropertyMap;
typedef pair<PropertyMap::iterator,PropertyMap::iterator> PropertyRange;
typedef list<Resource> ResourceList;
+ typedef map<string, PropertyValidator*> ValidatorMap;
bool AddProperty(Property property);
bool SetProperty(Property property, int index = 0);
@@ -176,54 +179,19 @@ public:
bool SetObjectID(string objectID);
bool SetObjectIDByUri(string uri);
- string GetObjectID() const { return objectID; }
+ string GetObjectID();
bool SetParentID(string parentID);
bool SetParentIDByUri(string uri);
- string GetParentID() const { return parentID; }
- bool SetTitle(string title);
- string GetTitle() const { return title; }
- bool SetCreator(string creator);
- string GetCreator() const { return creator; }
- bool SetUpnpClass(string upnpClass);
- string GetUpnpClass() const { return upnpClass; }
- bool SetRestricted(bool restricted);
- bool GetRestricted() const { return restricted; }
- bool SetDescription(string description);
- string GetDescription() const { return description; }
- bool SetLongDescription(string longDescription);
- string GetLongDescription() const { return longDescription; }
- bool SetDate(string date);
- string GetDate() const { return date; }
- bool SetLanguage(string language);
- string GetLanguage() const { return language; }
- bool SetChannelNr(int channelNr);
- int GetChannelNr() const { return channelNr; }
- bool SetChannelName(string channelName);
- string GetChannelName() const { return channelName; }
- bool SetScheduledStart(string scheduledStart);
- string GetScheduledStart() const { return scheduledStart; }
- bool SetScheduledEnd(string scheduledEnd);
- string GetScheduledEnd() const { return scheduledEnd; }
+ string GetParentID();
+
+ static void RegisterPropertyValidator(PropertyValidator* validator);
private:
PropertyMap properties;
ResourceList resources;
- string objectID;
- string parentID;
- string title;
- string creator;
- string upnpClass;
- bool restricted;
- string description;
- string longDescription;
- string date;
- string language;
- int channelNr;
- string channelName;
- string scheduledStart;
- string scheduledEnd;
+ static ValidatorMap validators;
};
diff --git a/media/pluginManager.cpp b/media/pluginManager.cpp
index e677d6a..ec23ea4 100644
--- a/media/pluginManager.cpp
+++ b/media/pluginManager.cpp
@@ -13,6 +13,38 @@ using namespace std;
namespace upnp {
+class PropertyValidator {
+ PropertyValidator(){
+ cMetadata::RegisterPropertyValidator(this);
+ }
+ virtual ~PropertyValidator(){}
+ virtual string GetPropertyKey() = 0;
+ 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;
+}
+
bool cMetadata::SetObjectIDByUri(string uri){
return SetObjectID(tools::GenerateUUIDFromURL(uri));
}
@@ -24,93 +56,60 @@ bool cMetadata::SetParentIDByUri(string uri){
bool cMetadata::SetObjectID(string objectID){
if(objectID.empty() || objectID.compare("0") == 0) return false;
- this->objectID = objectID;
+ SetProperty(Property(property::object::KEY_OBJECTID, objectID));
return true;
};
bool cMetadata::SetParentID(string parentID){
- if(objectID.compare("-1") == 0) return false;
-
- this->parentID = parentID;
-
- return true;
-};
+ if(parentID.compare("-1") == 0) return false;
-bool cMetadata::SetTitle(string title){
- this->title = title;
+ SetProperty(Property(property::object::KEY_PARENTID, parentID));
return true;
};
-bool cMetadata::SetUpnpClass(string upnpClass){
- //TODO: Validiere upnpClass.
- this->upnpClass = upnpClass;
-
- return true;
-};
-
-bool cMetadata::SetRestricted(bool restricted){
- this->restricted = restricted;
-
- return true;
-};
-
-bool cMetadata::SetDescription(string description){
- this->description = description;
-
- return true;
-};
-
-bool cMetadata::SetLongDescription(string longDescription){
- this->longDescription = longDescription;
-
- return true;
-};
-
-bool cMetadata::SetDate(string date){
- this->date = date;
-
- return true;
-};
-
-bool cMetadata::SetLanguage(string language){
- this->language = language;
-
- return true;
-};
-
-bool cMetadata::SetChannelNr(int channelNr){
- this->channelNr = channelNr;
-
- return true;
-};
-
-bool cMetadata::SetChannelName(string channelName){
- this->channelName = channelName;
-
- return true;
-};
-
-bool cMetadata::SetScheduledStart(string scheduledStart){
- this->scheduledStart = scheduledStart;
-
- return true;
-};
-
-bool cMetadata::SetScheduledEnd(string scheduledEnd){
- this->scheduledEnd = scheduledEnd;
-
- return true;
-};
-
-
bool cMetadata::AddProperty(Property property){
+ string key = property.GetKey();
+
+ // Try to find a validator
+ PropertyValidator* validator = validators[key];
+ // If there is one and it fails to validate the property, return false.
+ // Otherwise ignore it.
+ if(validator && !validator->Validate(property)) return false;
+
+ if(properties.find(key) != properties.end()){
+ if(key.compare(property::object::KEY_CHANNEL_NAME) == 0 ||
+ key.compare(property::object::KEY_CHANNEL_NR) == 0 ||
+ key.compare(property::object::KEY_CLASS) == 0 ||
+ key.compare(property::object::KEY_CREATOR) == 0 ||
+ key.compare(property::object::KEY_DATE) == 0 ||
+ key.compare(property::object::KEY_DESCRIPTION) == 0 ||
+ key.compare(property::object::KEY_LANGUAGE) == 0 ||
+ key.compare(property::object::KEY_LONG_DESCRIPTION) == 0 ||
+ key.compare(property::object::KEY_OBJECTID) == 0 ||
+ key.compare(property::object::KEY_PARENTID) == 0 ||
+ key.compare(property::object::KEY_RESTRICTED) == 0 ||
+ key.compare(property::object::KEY_SCHEDULED_END) == 0 ||
+ key.compare(property::object::KEY_SCHEDULED_START) == 0 ||
+ key.compare(property::object::KEY_TITLE) == 0)
+ {
+ esyslog("UPnP\tProperty '%s' already exist!", key);
+ return false;
+ }
+ }
+
properties.insert(pair<string, Property>(property.GetKey(), property));
return true;
}
bool cMetadata::SetProperty(Property property, int index){
+ // Try to find a validator
+ PropertyValidator* validator = validators[property.GetKey()];
+ // If there is one and it fails to validate the property, return false.
+ // Otherwise ignore it.
+ if(validator && !validator->Validate(property)) return false;
+
PropertyRange ret = properties.equal_range(property.GetKey());
// No property with the given name found. Let's add it to the map.
@@ -230,11 +229,11 @@ cMetadata* cUPnPResourceProvider::GetMetadata(string uri){
cMetadata* metadata = new cMetadata;
- metadata->SetTitle(uri.substr(uri.find_last_of("/")+1));
- metadata->SetUpnpClass("object.container");
metadata->SetObjectIDByUri(uri);
metadata->SetParentIDByUri(uri.substr(0,uri.find_last_of("/")));
- metadata->SetRestricted(true);
+ metadata->SetProperty(cMetadata::Property(property::object::KEY_TITLE, uri.substr(uri.find_last_of("/")+1)));
+ metadata->SetProperty(cMetadata::Property(property::object::KEY_CLASS, "object.container"));
+ metadata->SetProperty(cMetadata::Property(property::object::KEY_RESTRICTED, true));
return metadata;