summaryrefslogtreecommitdiff
path: root/database
diff options
context:
space:
mode:
Diffstat (limited to 'database')
-rw-r--r--database/database.cpp4
-rw-r--r--database/database.h1024
-rw-r--r--database/metadata.cpp159
-rw-r--r--database/metadata.h185
-rw-r--r--database/object.cpp40
-rw-r--r--database/object.h1728
-rw-r--r--database/resources.cpp57
-rw-r--r--database/resources.h162
8 files changed, 138 insertions, 3221 deletions
diff --git a/database/database.cpp b/database/database.cpp
index e47dcbf..c58294d 100644
--- a/database/database.cpp
+++ b/database/database.cpp
@@ -12,6 +12,7 @@
#include "../common.h"
#include "object.h"
#include "../upnp.h"
+#include "config.h"
cSQLiteDatabase* cSQLiteDatabase::mInstance = NULL;
@@ -160,7 +161,8 @@ bool cRow::fetchColumn(char** Column, char** Value){
int cSQLiteDatabase::initialize(){
int ret;
- cString File = cString::sprintf("%s/%s", cPluginUpnp::getConfigDirectory(), SQLITE_DB_FILE);
+ const char* dbdir = (cUPnPConfig::get()->mDatabaseFolder) ? cUPnPConfig::get()->mDatabaseFolder : cPluginUpnp::getConfigDirectory();
+ cString File = cString::sprintf("%s/%s", dbdir, SQLITE_DB_FILE);
if((ret = sqlite3_open(File, &this->mDatabase))){
ERROR("Unable to open database file %s (Error code: %d)!", *File, ret);
sqlite3_close(this->mDatabase);
diff --git a/database/database.h b/database/database.h
deleted file mode 100644
index 5bb595f..0000000
--- a/database/database.h
+++ /dev/null
@@ -1,1024 +0,0 @@
-/*
- * File: database.h
- * Author: savop
- *
- * Created on 3. September 2009, 22:20
- */
-
-#ifndef _DATABASE_H
-#define _DATABASE_H
-
-#include <sqlite3.h>
-#include <vdr/tools.h>
-#include "../common.h"
-
-#define SQLITE_CASCADE_DELETES
-
-#define PK_OBJECTS TOSTRING(1)
-#define PK_RESOURCES TOSTRING(2)
-#define PK_SEARCHCLASSES TOSTRING(3)
-
-#define SQLITE_FIRST_CUSTOMID TOSTRING(100)
-
-#define SQLITE_COLUMN_NAME_LENGTH 64
-
-#define SQLITE_TABLE_RESOURCES "Resources"
-#define SQLITE_TABLE_OBJECTS "Objects"
-#define SQLITE_TABLE_ITEMS "Items"
-#define SQLITE_TABLE_CONTAINERS "Containers"
-#define SQLITE_TABLE_VIDEOITEMS "VideoItems"
-#define SQLITE_TABLE_AUDIOITEMS "AudioItems"
-#define SQLITE_TABLE_IMAGEITEMS "ImageItems"
-#define SQLITE_TABLE_VIDEOBROADCASTS "VideoBroadcasts"
-#define SQLITE_TABLE_AUDIOBROADCASTS "AudioBroadcasts"
-#define SQLITE_TABLE_MOVIES "Movies"
-#define SQLITE_TABLE_PHOTOS "Photos"
-#define SQLITE_TABLE_ALBUMS "Albums"
-#define SQLITE_TABLE_PLAYLISTS "Playlists"
-#define SQLITE_TABLE_SEARCHCLASS "SearchClass"
-#define SQLITE_TABLE_PRIMARY_KEYS "PrimaryKeys"
-#define SQLITE_TABLE_SYSTEM "System"
-#define SQLITE_TABLE_ITEMFINDER "ItemFinder"
-
-#define SQLITE_TYPE_TEXT "TEXT"
-#define SQLITE_TYPE_INTEGER "INTEGER"
-#define SQLITE_TYPE_BOOL SQLITE_TYPE_INTEGER
-#define SQLITE_TYPE_DATE SQLITE_TYPE_TEXT
-#define SQLITE_TYPE_ULONG SQLITE_TYPE_INTEGER
-#define SQLITE_TYPE_LONG SQLITE_TYPE_INTEGER
-#define SQLITE_TYPE_UINTEGER SQLITE_TYPE_INTEGER
-
-#define SQLITE_TRANSACTION_BEGIN "BEGIN IMMEDIATE TRANSACTION "
-#define SQLITE_TRANSACTION_END "COMMIT TRANSACTION"
-#define SQLITE_TRANSACTION_TYPE "ROLLBACK"
-
-#define SQLITE_CONFLICT_CLAUSE "ON CONFLICT " SQLITE_TRANSACTION_TYPE
-#define SQLITE_PRIMARY_KEY SQLITE_TYPE_INTEGER " PRIMARY KEY"
-#define SQLITE_NOT_NULL "NOT NULL"
-#define SQLITE_UNIQUE "UNIQUE"
-
-#define SQLITE_COL_OBJECTID "ObjectID"
-#define SQLITE_COL_PARENTID "ParentID"
-#define SQLITE_COL_TITLE "Title"
-#define SQLITE_COL_CREATOR "Creator"
-#define SQLITE_COL_CLASS "Class"
-#define SQLITE_COL_RESTRICTED "Restricted"
-#define SQLITE_COL_WRITESTATUS "WriteStatus"
-#define SQLITE_COL_REFERENCEID "RefID"
-#define SQLITE_COL_CLASSDERIVED "IncludeDerived"
-#define SQLITE_COL_SEARCHABLE "Searchable"
-#define SQLITE_COL_CONTAINER_UID "UpdateID"
-#define SQLITE_COL_RESOURCEID "ResourceID"
-#define SQLITE_COL_PROTOCOLINFO "ProtocolInfo"
-#define SQLITE_COL_CONTENTTYPE "ContentType"
-#define SQLITE_COL_RESOURCETYPE "ResourceType"
-#define SQLITE_COL_RESOURCE "Resource"
-#define SQLITE_COL_SIZE "Size"
-#define SQLITE_COL_DURATION "Duration"
-#define SQLITE_COL_BITRATE "Bitrate"
-#define SQLITE_COL_SAMPLEFREQUENCE "SampleFreq"
-#define SQLITE_COL_BITSPERSAMPLE "BitsPerSample"
-#define SQLITE_COL_NOAUDIOCHANNELS "NoAudioChannels"
-#define SQLITE_COL_COLORDEPTH "ColorDepth"
-#define SQLITE_COL_RESOLUTION "Resolution"
-#define SQLITE_COL_GENRE "Genre"
-#define SQLITE_COL_LONGDESCRIPTION "LongDescription"
-#define SQLITE_COL_PRODUCER "Producer"
-#define SQLITE_COL_RATING "Rating"
-#define SQLITE_COL_ACTOR "Actor"
-#define SQLITE_COL_DIRECTOR "Director"
-#define SQLITE_COL_DESCRIPTION "Description"
-#define SQLITE_COL_PUBLISHER "Publisher"
-#define SQLITE_COL_LANGUAGE "Language"
-#define SQLITE_COL_RELATION "Relation"
-#define SQLITE_COL_STORAGEMEDIUM "StorageMedium"
-#define SQLITE_COL_DVDREGIONCODE "DVDRegionCode"
-#define SQLITE_COL_CHANNELNAME "Channelname"
-#define SQLITE_COL_SCHEDULEDSTARTTIME "ScheduledStartTime"
-#define SQLITE_COL_SCHEDULEDENDTIME "ScheduledEndTime"
-#define SQLITE_COL_ICON "Icon"
-#define SQLITE_COL_REGION "Region"
-#define SQLITE_COL_CHANNELNR "ChannelNr"
-#define SQLITE_COL_RIGHTS "Rights"
-#define SQLITE_COL_RADIOCALLSIGN "CallSign"
-#define SQLITE_COL_RADIOSTATIONID "StationID"
-#define SQLITE_COL_RADIOBAND "Band"
-#define SQLITE_COL_CONTRIBUTOR "Contributor"
-#define SQLITE_COL_DATE "Date"
-#define SQLITE_COL_ALBUM "Album"
-#define SQLITE_COL_ARTIST "Artist"
-#define SQLITE_COL_DLNA_CONTAINERTYPE "DLNAContainer"
-#define SQLITE_COL_CHILDCOUNT "ChildCount"
-#define SQLITE_COL_ITEMFINDER "ItemFastID"
-
-#define SQLITE_UPNP_OBJECTID SQLITE_COL_OBJECTID " " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL " " SQLITE_CONFLICT_CLAUSE " "\
- SQLITE_UNIQUE " " SQLITE_CONFLICT_CLAUSE
-
-#define SQLITE_INSERT_TRIGGER(TableA,TableB,Class) "CREATE TRIGGER IF NOT EXISTS "\
- TableA "_I_" TableB " "\
- "BEFORE INSERT ON "\
- TableB " "\
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "((SELECT " SQLITE_COL_OBJECTID " FROM " TableA " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID " "\
- ") IS NULL) "\
- "OR "\
- "((SELECT " SQLITE_COL_OBJECTID " FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID " "\
- "AND " SQLITE_COL_CLASS " LIKE '" Class "%%') IS NULL) "\
- ") THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ", "\
- "'INSERT on table " TableB " failed due constraint violation "\
- "on foreign key " SQLITE_COL_OBJECTID "'"\
- ") "\
- "END; END;"
-
-#define SQLITE_UPDATE_TRIGGER(TableA,TableB,Class) "CREATE TRIGGER IF NOT EXISTS "\
- TableA "_U_" TableB " "\
- "BEFORE UPDATE ON "\
- TableB " "\
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "((SELECT " SQLITE_COL_OBJECTID " FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID " "\
- "AND " SQLITE_COL_CLASS " LIKE '" Class "%%') IS NULL)"\
- ") THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ", "\
- "'UPDATE on table " TableB " failed due constraint violation "\
- "on foreign key " SQLITE_COL_OBJECTID "'"\
- ") "\
- "END; END;"
-
-#define SQLITE_INSERT_REFERENCE_TRIGGER(Table,Column) "CREATE TRIGGER IF NOT EXISTS "\
- Table "_I_" Table " "\
- "BEFORE INSERT ON " \
- Table " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ( "\
- "((SELECT " SQLITE_COL_OBJECTID " FROM " Table " "\
- "WHERE " SQLITE_COL_OBJECTID " = NEW." Column ") IS NULL) "\
- "AND "\
- "(NEW." Column "!=-1)"\
- ")THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ", 'INSERT on table " Table " "\
- "violates foreign key \"" Column "\"') "\
- "END; END;"
-
-#define SQLITE_UPDATE_REFERENCE_TRIGGER(Table,Column) "CREATE TRIGGER IF NOT EXISTS "\
- Table "_U_" Table " "\
- "BEFORE INSERT ON " \
- Table " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ( "\
- "((SELECT " SQLITE_COL_OBJECTID " FROM " Table " "\
- "WHERE " SQLITE_COL_OBJECTID " = NEW." Column ") IS NULL) "\
- "AND "\
- "(NEW." Column "!=-1)"\
- ")THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ", 'UPDATE on table " Table " "\
- "violates foreign key \"" Column "\"') "\
- "END; END;"
-
-#define SQLITE_DELETE_REFERENCE_TRIGGER(Table,Column) "CREATE TRIGGER IF NOT EXISTS "\
- Table "_D_" Table " " \
- "BEFORE DELETE ON " \
- Table " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "(SELECT " Column " FROM " Table " "\
- "WHERE " Column " = OLD." SQLITE_COL_OBJECTID ") IS NOT NULL"\
- ")THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ", 'DELETE on table " Table " "\
- "violates foreign key \"" Column "\"') "\
- "END; END;"
-
-#ifdef SQLITE_CASCADE_DELETES
-#define SQLITE_DELETE_TRIGGER(TableA,TableB) "CREATE TRIGGER IF NOT EXISTS "\
- TableA "_D_" TableB " "\
- "BEFORE DELETE ON "\
- TableA " "\
- "FOR EACH ROW BEGIN "\
- "DELETE FROM " TableB " "\
- "WHERE " SQLITE_COL_OBJECTID "=OLD." SQLITE_COL_OBJECTID "; "\
- "END;"
-
-#define SQLITE_DELETE_PARENT_TRIGGER "CREATE TRIGGER IF NOT EXISTS "\
- SQLITE_TABLE_OBJECTS "_D_" SQLITE_TABLE_OBJECTS " " \
- "BEFORE DELETE ON " \
- SQLITE_TABLE_OBJECTS " " \
- "FOR EACH ROW BEGIN "\
- "DELETE FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_PARENTID "=OLD." SQLITE_COL_OBJECTID "; "\
- "END;"
-#else
-#define SQLITE_DELETE_TRIGGER(TableA,TableB) "CREATE TRIGGER IF NOT EXISTS "\
- TableA "_D_" TableB " "\
- "BEFORE DELETE ON "\
- TableA " "\
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "(SELECT " SQLITE_COL_OBJECTID " FROM " TableB " "\
- "WHERE " SQLITE_COL_OBJECTID "=OLD." SQLITE_COL_OBJECTID ") IS NOT NULL"\
- ") THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ", "\
- "'DELETE on table " TableA " failed due constraint violation "\
- "on foreign key " SQLITE_COL_OBJECTID "'"\
- ") "\
- "END; END;"
-
-#define SQLITE_DELETE_PARENT_TRIGGER SQLITE_DELETE_REFERENCE_TRIGGER(SQLITE_TABLE_OBJECTS, SQLITE_COL_PARENTID)
-#endif
-
-/**********************************************\
-* *
-* Primary keys *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_PRIMARY_KEYS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_PRIMARY_KEYS \
- "("\
- "KeyID " SQLITE_PRIMARY_KEY " " SQLITE_NOT_NULL ","\
- "Key " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL\
- ");"\
- "INSERT OR IGNORE INTO "\
- SQLITE_TABLE_PRIMARY_KEYS \
- "(KeyID, Key) VALUES ("\
- PK_OBJECTS "," SQLITE_FIRST_CUSTOMID\
- ");"\
- "INSERT OR IGNORE INTO "\
- SQLITE_TABLE_PRIMARY_KEYS \
- "(KeyID, Key) VALUES ("\
- PK_RESOURCES ",0"\
- ");"\
- "INSERT OR IGNORE INTO "\
- SQLITE_TABLE_PRIMARY_KEYS \
- "(KeyID, Key) VALUES ("\
- PK_SEARCHCLASSES ",0"\
- ");"
-
-#define SQLITE_TRIGGER_UPDATE_OBJECTID "CREATE TRIGGER IF NOT EXISTS "\
- SQLITE_TABLE_OBJECTS "_PK_UPDATE "\
- "AFTER INSERT ON "\
- SQLITE_TABLE_OBJECTS " "\
- "BEGIN "\
- "UPDATE " SQLITE_TABLE_PRIMARY_KEYS " SET Key=Key+1 WHERE KeyID=" PK_OBJECTS "; "\
- "END;"
-
-/**********************************************\
-* *
-* System settings *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_SYSTEM "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_SYSTEM " "\
- "("\
- "Key " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL " " SQLITE_UNIQUE ","\
- "Value " SQLITE_TYPE_TEXT " "\
- ");"
-
-#define SQLITE_TRIGGER_UPDATE_SYSTEM "CREATE TRIGGER IF NOT EXISTS "\
- SQLITE_TABLE_SYSTEM "_VALUE_UPDATE "\
- "BEFORE UPDATE "\
- "ON " SQLITE_TABLE_SYSTEM " "\
- "WHEN ((SELECT Key FROM " SQLITE_TABLE_SYSTEM " WHERE Key=NEW.Key) IS NULL) "\
- "BEGIN INSERT INTO " SQLITE_TABLE_SYSTEM " (Key) VALUES (NEW.Key); END;"
-
-/**********************************************\
-* *
-* Fast item finder *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_ITEMFINDER "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_ITEMFINDER " "\
- "("\
- SQLITE_UPNP_OBJECTID ","\
- SQLITE_COL_ITEMFINDER " " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL " " SQLITE_UNIQUE \
- ");"
-
-#define SQLITE_TRIGGER_D_OBJECTS_ITEMFINDER SQLITE_DELETE_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_ITEMFINDER)
-
-/**********************************************\
-* *
-* Objects *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_OBJECTS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_OBJECTS \
- "(" \
- SQLITE_COL_OBJECTID " " SQLITE_PRIMARY_KEY " " SQLITE_NOT_NULL " " SQLITE_CONFLICT_CLAUSE "," \
- SQLITE_COL_PARENTID " " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL " " SQLITE_CONFLICT_CLAUSE "," \
- SQLITE_COL_TITLE " " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL "," \
- SQLITE_COL_CREATOR " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_CLASS " " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL "," \
- SQLITE_COL_RESTRICTED " " SQLITE_TYPE_BOOL " " SQLITE_NOT_NULL "," \
- SQLITE_COL_WRITESTATUS " " SQLITE_TYPE_INTEGER \
- ");"
-
-// Trigger for foreign key ParentID
-
-#define SQLITE_TRIGGER_D_OBJECTS_OBJECTS SQLITE_DELETE_PARENT_TRIGGER
-
-#define SQLITE_TRIGGER_I_OBJECTS_OBJECTS SQLITE_INSERT_REFERENCE_TRIGGER(SQLITE_TABLE_OBJECTS, SQLITE_COL_PARENTID)\
- "CREATE TRIGGER IF NOT EXISTS "\
- SQLITE_TABLE_OBJECTS "_PI_" SQLITE_TABLE_OBJECTS " "\
- "BEFORE INSERT ON "\
- SQLITE_TABLE_OBJECTS " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "((SELECT " SQLITE_COL_PARENTID " FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_PARENTID "=-1) IS NOT NULL) "\
- "AND "\
- "(NEW." SQLITE_COL_PARENTID "=-1)"\
- ") THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ","\
- "'INSERT on table " SQLITE_TABLE_OBJECTS " violates constraint. "\
- SQLITE_COL_PARENTID " must uniquely be -1') "\
- "END; END;"
-
-#define SQLITE_TRIGGER_U_OBJECTS_OBJECTS SQLITE_UPDATE_REFERENCE_TRIGGER(SQLITE_TABLE_OBJECTS, SQLITE_COL_PARENTID)\
- "CREATE TRIGGER IF NOT EXISTS "\
- SQLITE_TABLE_OBJECTS "_PU_" SQLITE_TABLE_OBJECTS " "\
- "BEFORE UPDATE ON "\
- SQLITE_TABLE_OBJECTS " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "((SELECT " SQLITE_COL_PARENTID " FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_PARENTID "=-1 "\
- "AND " SQLITE_COL_OBJECTID "!=NEW." SQLITE_COL_OBJECTID " ) IS NOT NULL) "\
- "AND "\
- "(NEW." SQLITE_COL_PARENTID "=-1) AND (OLD." SQLITE_COL_PARENTID "!=-1) "\
- ") THEN "\
- "RAISE(" SQLITE_TRANSACTION_TYPE ","\
- "'UPDATE on table " SQLITE_TABLE_OBJECTS " violates constraint. "\
- SQLITE_COL_PARENTID " must uniquely be -1') "\
- "END; END;"
-
-/**********************************************\
-* *
-* Items *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_ITEMS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_ITEMS \
- "(" \
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_REFERENCEID " " SQLITE_TYPE_INTEGER " DEFAULT -1" \
- ");"
-
-// Trigger for foreign key ObjectID
-
-#define SQLITE_TRIGGER_D_OBJECT_ITEMS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_ITEMS)
-
-#define SQLITE_TRIGGER_I_OBJECT_ITEMS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_ITEMS,\
- UPNP_CLASS_ITEM)
-
-#define SQLITE_TRIGGER_U_OBJECT_ITEMS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_ITEMS,\
- UPNP_CLASS_ITEM)
-
-// Trigger for Reference items
-
-#define SQLITE_TRIGGER_I_ITEMS_ITEMS SQLITE_INSERT_REFERENCE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_COL_REFERENCEID)
-
-#define SQLITE_TRIGGER_U_ITEMS_ITEMS SQLITE_UPDATE_REFERENCE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_COL_REFERENCEID)
-
-#define SQLITE_TRIGGER_D_ITEMS_ITEMS SQLITE_DELETE_REFERENCE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_COL_REFERENCEID)
-
-/**********************************************\
-* *
-* Containers *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_CONTAINER "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_CONTAINERS \
- "(" \
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_SEARCHABLE " " SQLITE_TYPE_INTEGER ","\
- SQLITE_COL_CONTAINER_UID " " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL ","\
- SQLITE_COL_DLNA_CONTAINERTYPE " " SQLITE_TYPE_TEXT \
- ");"
-
-#define SQLITE_TRIGGER_D_OBJECT_CONTAINERS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_CONTAINERS)
-
-#define SQLITE_TRIGGER_I_OBJECT_CONTAINERS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_CONTAINERS,\
- UPNP_CLASS_CONTAINER)
-
-#define SQLITE_TRIGGER_U_OBJECT_CONTAINERS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_OBJECTS,\
- SQLITE_TABLE_CONTAINERS,\
- UPNP_CLASS_CONTAINER)
-
-/**********************************************\
-* *
-* Video items *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_VIDEOITEMS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_VIDEOITEMS \
- "(" \
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_GENRE " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_LONGDESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_PRODUCER " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_RATING " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_ACTOR " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DIRECTOR " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_PUBLISHER " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_LANGUAGE " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_RELATION " " SQLITE_TYPE_TEXT \
- ");"
-
-#define SQLITE_TRIGGER_D_ITEMS_VIDEOITEMS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_TABLE_VIDEOITEMS)
-
-#define SQLITE_TRIGGER_U_ITEMS_VIDEOITEMS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_ITEMS, \
- SQLITE_TABLE_VIDEOITEMS, \
- UPNP_CLASS_VIDEO)
-
-#define SQLITE_TRIGGER_I_ITEMS_VIDEOITEMS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_ITEMS, \
- SQLITE_TABLE_VIDEOITEMS, \
- UPNP_CLASS_VIDEO)
-
-/**********************************************\
-* *
-* Audio items *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_AUDIOITEMS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_AUDIOITEMS \
- "(" \
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_GENRE " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_LONGDESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_PUBLISHER " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_RELATION " " SQLITE_TYPE_TEXT \
- ");"
-
-#define SQLITE_TRIGGER_D_ITEMS_AUDIOITEMS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_TABLE_AUDIOITEMS)
-
-#define SQLITE_TRIGGER_U_ITEMS_AUDIOITEMS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_ITEMS, \
- SQLITE_TABLE_AUDIOITEMS, \
- UPNP_CLASS_AUDIO)
-
-#define SQLITE_TRIGGER_I_ITEMS_AUDIOITEMS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_ITEMS, \
- SQLITE_TABLE_AUDIOITEMS, \
- UPNP_CLASS_AUDIO)
-
-/**********************************************\
-* *
-* Image items *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_IMAGEITEMS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_IMAGEITEMS \
- "("\
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_LONGDESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_PUBLISHER " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_STORAGEMEDIUM " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_RATING " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_DATE " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_RIGHTS " " SQLITE_TYPE_TEXT\
- ");"
-
-#define SQLITE_TRIGGER_D_ITEMS_IMAGEITEMS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_TABLE_IMAGEITEMS)
-
-#define SQLITE_TRIGGER_U_ITEMS_IMAGEITEMS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_ITEMS, \
- SQLITE_TABLE_IMAGEITEMS, \
- UPNP_CLASS_IMAGE)
-
-#define SQLITE_TRIGGER_I_ITEMS_IMAGEITEMS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_ITEMS, \
- SQLITE_TABLE_IMAGEITEMS, \
- UPNP_CLASS_IMAGE)
-
-/**********************************************\
-* *
-* Video broadcasts *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_VIDEOBROADCASTS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_VIDEOBROADCASTS \
- "("\
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_ICON " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_REGION " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_CHANNELNR " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_CHANNELNAME " " SQLITE_TYPE_TEXT " " SQLITE_UNIQUE \
- ");"
-
-#define SQLITE_TRIGGER_D_VIDEOITEMS_VIDEOBROADCASTS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_VIDEOITEMS, SQLITE_TABLE_VIDEOBROADCASTS)
-
-#define SQLITE_TRIGGER_U_VIDEOITEMS_VIDEOBROADCASTS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_VIDEOITEMS,\
- SQLITE_TABLE_VIDEOBROADCASTS,\
- UPNP_CLASS_VIDEOBC)
-
-#define SQLITE_TRIGGER_I_VIDEOITEMS_VIDEOBROADCASTS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_VIDEOITEMS,\
- SQLITE_TABLE_VIDEOBROADCASTS,\
- UPNP_CLASS_VIDEOBC)
-
-/**********************************************\
-* *
-* Audio broadcasts *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_AUDIOBROADCASTS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_AUDIOBROADCASTS \
- "("\
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_REGION " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_RADIOCALLSIGN " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_RADIOSTATIONID " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_RADIOBAND " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_CHANNELNR " " SQLITE_TYPE_INTEGER \
- ");"
-
-#define SQLITE_TRIGGER_D_AUDIOITEMS_AUDIOBROADCASTS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_AUDIOITEMS, SQLITE_TABLE_AUDIOBROADCASTS)
-
-#define SQLITE_TRIGGER_I_AUDIOITEMS_AUDIOBROADCASTS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_AUDIOITEMS,\
- SQLITE_TABLE_AUDIOBROADCASTS,\
- UPNP_CLASS_AUDIOBC)
-
-#define SQLITE_TRIGGER_U_AUDIOITEMS_AUDIOBROADCASTS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_AUDIOITEMS,\
- SQLITE_TABLE_AUDIOBROADCASTS,\
- UPNP_CLASS_AUDIOBC)
-
-/**********************************************\
-* *
-* Movies *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_MOVIES "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_MOVIES \
- "("\
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_STORAGEMEDIUM " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DVDREGIONCODE " " SQLITE_TYPE_INTEGER "," \
- SQLITE_COL_CHANNELNAME " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_SCHEDULEDSTARTTIME " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_SCHEDULEDENDTIME " " SQLITE_TYPE_TEXT\
- ");"
-
-#define SQLITE_TRIGGER_D_VIDEOITEMS_MOVIES SQLITE_DELETE_TRIGGER(SQLITE_TABLE_VIDEOITEMS, SQLITE_TABLE_MOVIES)
-
-
-#define SQLITE_TRIGGER_I_VIDEOITEMS_MOVIES SQLITE_INSERT_TRIGGER(SQLITE_TABLE_VIDEOITEMS,\
- SQLITE_TABLE_MOVIES,\
- UPNP_CLASS_MOVIE)
-
-#define SQLITE_TRIGGER_U_VIDEOITEMS_MOVIES SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_VIDEOITEMS,\
- SQLITE_TABLE_MOVIES,\
- UPNP_CLASS_MOVIE)
-
-/**********************************************\
-* *
-* Photos *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_PHOTOS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_PHOTOS \
- "("\
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_ALBUM " " SQLITE_TYPE_TEXT\
- ");"
-
-#define SQLITE_TRIGGER_D_IMAGEITEMS_PHOTOS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_IMAGEITEMS, SQLITE_TABLE_PHOTOS)
-
-#define SQLITE_TRIGGER_I_IMAGEITEMS_PHOTOS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_IMAGEITEMS,\
- SQLITE_TABLE_PHOTOS,\
- UPNP_CLASS_PHOTO)
-
-#define SQLITE_TRIGGER_U_IMAGEITEMS_PHOTOS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_IMAGEITEMS,\
- SQLITE_TABLE_PHOTOS,\
- UPNP_CLASS_PHOTO)
-
-/**********************************************\
-* *
-* Albums *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_ALBUMS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_ALBUMS \
- "("\
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_STORAGEMEDIUM " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_LONGDESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_PUBLISHER " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_CONTRIBUTOR " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_DATE " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_RELATION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_RIGHTS " " SQLITE_TYPE_TEXT \
- ");"
-
-#define SQLITE_TRIGGER_D_CONTAINERS_ALBUMS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_CONTAINERS, SQLITE_TABLE_ALBUMS)
-
-#define SQLITE_TRIGGER_U_CONTAINERS_ALBUMS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_CONTAINERS,\
- SQLITE_TABLE_ALBUMS,\
- UPNP_CLASS_ALBUM)
-
-#define SQLITE_TRIGGER_I_CONTAINERS_ALBUMS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_CONTAINERS,\
- SQLITE_TABLE_ALBUMS,\
- UPNP_CLASS_ALBUM)
-
-/**********************************************\
-* *
-* Playlists *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_PLAYLISTS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_PLAYLISTS \
- "(" \
- SQLITE_UPNP_OBJECTID "," \
- SQLITE_COL_ARTIST " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_GENRE " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_LONGDESCRIPTION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DESCRIPTION " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_PRODUCER " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_STORAGEMEDIUM " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_CONTRIBUTOR " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_DATE " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_LANGUAGE " " SQLITE_TYPE_TEXT ","\
- SQLITE_COL_RIGHTS " " SQLITE_TYPE_TEXT\
- ");"
-
-#define SQLITE_TRIGGER_D_CONTAINERS_PLAYLISTS SQLITE_DELETE_TRIGGER(SQLITE_TABLE_CONTAINERS, SQLITE_TABLE_PLAYLISTS)
-
-#define SQLITE_TRIGGER_I_CONTAINERS_PLAYLISTS SQLITE_INSERT_TRIGGER(SQLITE_TABLE_CONTAINERS,\
- SQLITE_TABLE_PLAYLISTS,\
- UPNP_CLASS_PLAYLISTCONT)
-
-#define SQLITE_TRIGGER_U_CONTAINERS_PLAYLISTS SQLITE_UPDATE_TRIGGER(SQLITE_TABLE_CONTAINERS,\
- SQLITE_TABLE_PLAYLISTS,\
- UPNP_CLASS_PLAYLISTCONT)
-
-/**********************************************\
-* *
-* Search classes *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_SEARCHCLASS "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_SEARCHCLASS \
- "(" \
- SQLITE_COL_OBJECTID " " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL "," \
- SQLITE_COL_CLASS " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_CLASSDERIVED " " SQLITE_TYPE_BOOL \
- ");"
-
-#define SQLITE_TRIGGER_D_CONTAINERS_SEARCHCLASSES "CREATE TRIGGER IF NOT EXISTS " \
- SQLITE_TABLE_CONTAINERS "_D_" SQLITE_TABLE_SEARCHCLASS " " \
- "BEFORE DELETE ON " \
- SQLITE_TABLE_CONTAINERS " " \
- "FOR EACH ROW BEGIN "\
- "DELETE FROM " SQLITE_TABLE_SEARCHCLASS " "\
- "WHERE " SQLITE_COL_OBJECTID "= OLD." SQLITE_COL_OBJECTID "; " \
- "END;"
-
-#define SQLITE_TRIGGER_U_CONTAINERS_SEARCHCLASSES "CREATE TRIGGER IF NOT EXISTS " \
- SQLITE_TABLE_CONTAINERS "_U_" SQLITE_TABLE_SEARCHCLASS " " \
- "BEFORE UPDATE ON " \
- SQLITE_TABLE_SEARCHCLASS " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "(SELECT " SQLITE_COL_OBJECTID " FROM " SQLITE_TABLE_CONTAINERS " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID ") IS NULL "\
- ") THEN "\
- "RAISE (" SQLITE_TRANSACTION_TYPE ", 'UPDATE on table " SQLITE_TABLE_SEARCHCLASS " "\
- "violates foreign key constraint \"" SQLITE_COL_OBJECTID "\"') " \
- "END; END;"
-
-#define SQLITE_TRIGGER_I_CONTAINERS_SEARCHCLASSES "CREATE TRIGGER IF NOT EXISTS " \
- SQLITE_TABLE_CONTAINERS "_I_" SQLITE_TABLE_SEARCHCLASS " " \
- "BEFORE INSERT ON " \
- SQLITE_TABLE_SEARCHCLASS " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "(SELECT " SQLITE_COL_OBJECTID " FROM " SQLITE_TABLE_CONTAINERS " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID ") IS NULL "\
- ") THEN "\
- "RAISE (" SQLITE_TRANSACTION_TYPE ", 'INSERT on table " SQLITE_TABLE_SEARCHCLASS " "\
- "violates foreign key constraint \"" SQLITE_COL_OBJECTID "\"') " \
- "END; END;"
-
-/**********************************************\
-* *
-* Resources *
-* *
-\**********************************************/
-
-#define SQLITE_CREATE_TABLE_RESOURCES "CREATE TABLE IF NOT EXISTS "\
- SQLITE_TABLE_RESOURCES \
- "(" \
- SQLITE_COL_RESOURCEID " " SQLITE_PRIMARY_KEY " " SQLITE_NOT_NULL "," \
- SQLITE_COL_OBJECTID " " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL "," \
- SQLITE_COL_PROTOCOLINFO " " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL "," \
- SQLITE_COL_CONTENTTYPE " " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL "," \
- SQLITE_COL_RESOURCETYPE " " SQLITE_TYPE_INTEGER " " SQLITE_NOT_NULL "," \
- SQLITE_COL_RESOURCE " " SQLITE_TYPE_TEXT " " SQLITE_NOT_NULL "," \
- SQLITE_COL_SIZE " " SQLITE_TYPE_ULONG "," \
- SQLITE_COL_DURATION " " SQLITE_TYPE_TEXT "," \
- SQLITE_COL_BITRATE " " SQLITE_TYPE_UINTEGER "," \
- SQLITE_COL_SAMPLEFREQUENCE " " SQLITE_TYPE_UINTEGER "," \
- SQLITE_COL_BITSPERSAMPLE " " SQLITE_TYPE_UINTEGER "," \
- SQLITE_COL_NOAUDIOCHANNELS " " SQLITE_TYPE_UINTEGER "," \
- SQLITE_COL_COLORDEPTH " " SQLITE_TYPE_UINTEGER "," \
- SQLITE_COL_RESOLUTION " " SQLITE_TYPE_TEXT \
- ");"
-
-#define SQLITE_TRIGGER_D_OBJECT_RESOURCES "CREATE TRIGGER IF NOT EXISTS " \
- SQLITE_TABLE_OBJECTS "_D_" SQLITE_TABLE_RESOURCES " " \
- "BEFORE DELETE ON " \
- SQLITE_TABLE_OBJECTS " " \
- "FOR EACH ROW BEGIN "\
- "DELETE FROM " SQLITE_TABLE_RESOURCES " "\
- "WHERE " SQLITE_COL_OBJECTID "= OLD." SQLITE_COL_OBJECTID "; " \
- "END;"
-
-#define SQLITE_TRIGGER_I_OBJECT_RESOURCES "CREATE TRIGGER IF NOT EXISTS " \
- SQLITE_TABLE_OBJECTS "_I_" SQLITE_TABLE_RESOURCES " " \
- "BEFORE INSERT ON " \
- SQLITE_TABLE_RESOURCES " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "(SELECT " SQLITE_COL_OBJECTID " FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID ") IS NULL"\
- ") THEN "\
- "RAISE (" SQLITE_TRANSACTION_TYPE ", 'INSERT on table " SQLITE_TABLE_RESOURCES " "\
- "violates foreign key constraint \"" SQLITE_COL_OBJECTID "\"') " \
- "END; END;"
-
-#define SQLITE_TRIGGER_U_OBJECT_RESOURCES "CREATE TRIGGER IF NOT EXISTS " \
- SQLITE_TABLE_OBJECTS "_U_" SQLITE_TABLE_RESOURCES " " \
- "BEFORE UPDATE ON " \
- SQLITE_TABLE_RESOURCES " " \
- "FOR EACH ROW BEGIN "\
- "SELECT CASE "\
- "WHEN ("\
- "(SELECT " SQLITE_COL_OBJECTID " FROM " SQLITE_TABLE_OBJECTS " "\
- "WHERE " SQLITE_COL_OBJECTID "=NEW." SQLITE_COL_OBJECTID ") IS NULL"\
- ") THEN "\
- "RAISE (" SQLITE_TRANSACTION_TYPE ", 'INSERT on table " SQLITE_TABLE_RESOURCES " "\
- "violates foreign key constraint \"" SQLITE_COL_OBJECTID "\"') " \
- "END; END;"
-
-class cSQLiteDatabase;
-
-/**
- * Result row of a SQL SELECT request
- *
- * This is a single row of a {\c SQL SELECT} request.
- *
- * @see cRows
- */
-class cRow : public cListObject {
- friend class cSQLiteDatabase;
-private:
- int currentCol;
- int ColCount;
- char** Columns;
- char** Values;
- cRow();
-public:
- virtual ~cRow();
- /**
- * Number of columns in this row
- *
- * @return the number of rows
- */
- int Count(){ return this->ColCount; }
- /**
- * Fetches a Column
- *
- * This will fetch a column of this row and stores the name of the column
- * in the first parameter and the value in the second parameter.
- *
- * @return returns
- * - \bc true, if more columns to come
- * - \bc false, if the column is its last in this row.
- */
- bool fetchColumn(
- cString* Column, /**< The name of the current column */
- cString* Value /**< The value of the current value */
- );
-
- /**
- * Fetches a Column
- *
- * This will fetch a column of this row and stores the name of the column
- * in the first parameter and the value in the second parameter.
- *
- * @return returns
- * - \bc true, if more columns to come
- * - \bc false, if the column is its last in this row.
- */
- bool fetchColumn(
- char** Column, /**< The name of the current column */
- char** Value /**< The value of the current column */
- );
-};
-
-/**
- * Result rows of a SQL SELECT request
- *
- * Contains the rows of a SQL SELECT request
- *
- * @see cRow
- */
-class cRows : public cList<cRow> {
- friend class cSQLiteDatabase;
-private:
- cRow* mLastRow;
- cRows();
-public:
- virtual ~cRows();
- /**
- * Fetches a row from the result
- *
- * This fetches the next row in the resultset by storing the contents of
- * that row in the first parameter.
- *
- * @return returns
- * - \bc true, if more rows to come
- * - \bc false, if the row is its last in this resultset.
- */
- bool fetchRow(
- cRow** Row /**< The Pointer of the row */
- );
-};
-
-/**
- * SQLite Database
- *
- * This is a wrapper class for a SQLite3 database connection
- * It supports simple execution functions.
- *
- * On requests with returns any results a instance of \c cRows* will be created.
- */
-class cSQLiteDatabase {
- friend class cStatement;
-private:
- bool mAutoCommit;
- bool mActiveTransaction;
- cRow* mLastRow;
- cRows* mRows;
- sqlite3* mDatabase;
- static cSQLiteDatabase* mInstance;
- cSQLiteDatabase();
- int initialize();
- int initializeTables();
- int initializeTriggers();
- static int getResultRow(void* DB, int NumCols, char** Values, char** ColNames);
- int exec(const char* Statement);
-public:
- /**
- * Prints a SQLite escaped text
- *
- * Returns a formated text with special characters to escape SQLite special
- * characters like "'". Additionally to the well known characters of \a printf
- * the following are allowed:
- *
- * - \bc q, like s, escapes single quotes in strings
- * - \bc Q, like q, surrounds the escaped string with additional
- * single quotes
- * - \bc z, frees the string after reading and coping it
- *
- * @see sprintf()
- * @return the formated string
- */
- static const char* sprintf(
- const char* Format, /**< The format string */
- ... /**< optional properties which will be passed to sprintf */
- );
- virtual ~cSQLiteDatabase();
- /**
- * Returns the instance of the database
- *
- * Returns the instance of the SQLite database. This will create a single
- * instance of none is existing on the very first call. A subsequent call
- * will return the same instance.
- *
- * @return the database instance
- */
- static cSQLiteDatabase* getInstance();
- /**
- * Row count of the last result
- *
- * Returns the row count of the last {\c SQL SELECT} request.
- *
- * @see cRows
- * @return the result row count
- */
- int getResultCount() const { return this->mRows->Count(); }
- /**
- * The last \c INSERT RowID
- *
- * Returns the primary key of the last inserted row.
- * This will only work if there are no successive calls to the database.
- *
- * @return the last insert RowID
- */
- long getLastInsertRowID() const;
- /**
- * Result set of the last request
- *
- * Returns the result rows of the SQL SELECT request.
- * This might be NULL, if the last statement was not a SELECT.
- *
- * @see cRows
- * @return the result rows of the last \c SELECT statement.
- */
- cRows* getResultRows() const { return this->mRows; }
- /**
- * Executes a SQL statement
- *
- * This will execute the statement in the first parameter. If it is followed
- * by any optional parameters it will be formated using the same function as
- * in \c cSQLiteDatabase::sprintf().
- *
- * \sa cSQLiteDatabase::sprintf().
- *
- * @return returns an integer representing
- * - \bc -1, in case of an error
- * - \bc 0, when the statement was executed successfuly
- */
- int execStatement(
- const char* Statement , /**< Statement to be executed */
- ... /**< optional parameters passed to the format string */
- );
- /**
- * Starts a transaction
- *
- * This starts a new transaction and commits or rolls back a previous.
- *
- * @see cSQLiteDatabase::setAutoCommit
- * @see cSQLiteDatabase::commitTransaction
- */
- void startTransaction();
- /**
- * Commits a transaction
- *
- * This function commits the transaction and writes all changes to the
- * database
- *
- * @see cSQLiteDatabase::startTransaction
- */
- void commitTransaction();
- /**
- * Performs a rollback on a transaction
- *
- * This function performs a rollback. No changes will be made to the
- * database
- *
- * @see cSQLiteDatabase::rollbackTransaction
- */
- void rollbackTransaction();
- /**
- * Set the commit behavior
- *
- * This function sets the auto commit behavior on new transactions with
- * \sa cSQLiteDatabase::startTransaction.
- *
- * - \bc true, commits the last transaction before starting a
- * new one
- * - \bc false, performs a rollback on the old transaction
- *
- */
- void setAutoCommit(
- bool Commit=true /**< Switches the behavior of auto commit */
- ){ this->mAutoCommit = Commit; }
-};
-
-#endif /* _DATABASE_H */ \ No newline at end of file
diff --git a/database/metadata.cpp b/database/metadata.cpp
index 91c512f..2bfa2d1 100644
--- a/database/metadata.cpp
+++ b/database/metadata.cpp
@@ -12,7 +12,7 @@
#include "resources.h"
#include "metadata.h"
#include "../common.h"
-#include "../misc/search.h"
+#include "search.h"
#include <vdr/channels.h>
#include <vdr/epg.h>
#include <upnp/upnp.h>
@@ -49,14 +49,18 @@ bool cMediaDatabase::init(){
ERROR("Initializing of database failed.");
return false;
}
+#ifndef WITHOUT_TV
if(this->loadChannels()){
ERROR("Loading channels failed");
return false;
}
+#endif
+#ifndef WITHOUT_RECORDS
if(this->loadRecordings()){
ERROR("Loading records failed");
return false;
}
+#endif
return true;
}
@@ -195,58 +199,65 @@ int cMediaDatabase::prepareDatabase(){
cUPnPClassContainer* Root = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _(PLUGIN_SHORT_NAME));
Root->setID(0);
if(this->mFactory->saveObject(Root)) return -1;
-
- cClass VideoClass = { UPNP_CLASS_VIDEO, true };
- cClass AudioClass = { UPNP_CLASS_AUDIO, true };
- cClass VideoBCClass = { UPNP_CLASS_VIDEOBC, true };
- cClass AudioBCClass = { UPNP_CLASS_AUDIOBC, true };
-
+
+#ifndef WITHOUT_VIDEO
cUPnPClassContainer* Video = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _("Video"));
Video->setID(1);
Root->addObject(Video);
+ cClass VideoClass = { UPNP_CLASS_VIDEO, true };
Video->addSearchClass(VideoClass);
Video->setSearchable(true);
if(this->mFactory->saveObject(Video)) return -1;
-
+#endif
+#ifndef WITHOUT_AUDIO
cUPnPClassContainer* Audio = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _("Audio"));
Audio->setID(2);
Root->addObject(Audio);
+ cClass AudioClass = { UPNP_CLASS_AUDIO, true };
Audio->addSearchClass(AudioClass);
Audio->setSearchable(true);
if(this->mFactory->saveObject(Audio)) return -1;
-
+#endif
+#ifndef WITHOUT_TV
cUPnPClassContainer* TV = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _("TV"));
TV->setID(3);
TV->setContainerType(DLNA_CONTAINER_TUNER);
TV->setSearchable(true);
+ cClass VideoBCClass = { UPNP_CLASS_VIDEOBC, true };
TV->addSearchClass(VideoBCClass);
Video->addObject(TV);
if(this->mFactory->saveObject(TV)) return -1;
-
+#endif
+#ifndef WITHOUT_RECORDS
cUPnPClassContainer* Records = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _("Records"));
Records->setID(4);
Video->addObject(Records);
Records->addSearchClass(VideoClass);
Records->setSearchable(true);
if(this->mFactory->saveObject(Records)) return -1;
-
+#endif
+#ifndef WITHOUT_RADIO
cUPnPClassContainer* Radio = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _("Radio"));
Radio->setID(5);
Audio->addObject(Radio);
+ cClass AudioBCClass = { UPNP_CLASS_AUDIOBC, true };
Radio->addSearchClass(AudioBCClass);
Radio->setSearchable(true);
if(this->mFactory->saveObject(Radio)) return -1;
-
+#endif
+#ifndef WITHOUT_CUSTOM_VIDEOS
cUPnPClassContainer* CustomVideos = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _("User videos"));
CustomVideos->setID(6);
Video->addObject(CustomVideos);
CustomVideos->addSearchClass(VideoClass);
CustomVideos->setSearchable(true);
if(this->mFactory->saveObject(CustomVideos)) return -1;
+#endif
}
return 0;
}
+#ifndef WITHOUT_TV
int cMediaDatabase::loadChannels(){
MESSAGE(VERBOSE_LIVE_TV ,"Loading channels");
cUPnPClassContainer* TV = (cUPnPClassContainer*)this->getObjectByID(3);
@@ -317,6 +328,70 @@ int cMediaDatabase::loadChannels(){
return 0;
}
+void cMediaDatabase::updateChannelEPG(){
+ cUPnPClassContainer* TV = (cUPnPClassContainer*)this->getObjectByID(3);
+ if(TV){
+ // Iterating channels
+ MESSAGE(VERBOSE_EPG_UPDATES, "Getting schedule...");
+ cSchedulesLock SchedulesLock;
+ const cSchedules *Schedules = cSchedules::Schedules(SchedulesLock);
+
+ cList<cUPnPClassObject>* List = TV->getObjectList();
+ MESSAGE(VERBOSE_EPG_UPDATES, "TV folder has %d items", List->Count());
+ for(cUPnPClassVideoBroadcast* ChannelItem = (cUPnPClassVideoBroadcast*)List->First();
+ ChannelItem;
+ ChannelItem = (cUPnPClassVideoBroadcast*)List->Next(ChannelItem)
+ ){
+ MESSAGE(VERBOSE_EPG_UPDATES, "Find channel by number %d", ChannelItem->getChannelNr());
+ cChannel* Channel = Channels.GetByNumber(ChannelItem->getChannelNr());
+
+ if(!Channel){
+ continue;
+ }
+ else {
+ MESSAGE(VERBOSE_EPG_UPDATES, "Found channel with ID %s", *Channel->GetChannelID().ToString());
+
+ const cSchedule* Schedule = Schedules->GetSchedule(Channel);
+ const cEvent* Event = Schedule?Schedule->GetPresentEvent():NULL;
+ if(Event){
+
+ time_t LastEPGChange = Event->StartTime();
+ time_t LastObjectChange = ChannelItem->modified();
+
+ MESSAGE(VERBOSE_EPG_UPDATES, "Last event start: %s", ctime(&LastEPGChange));
+ MESSAGE(VERBOSE_EPG_UPDATES, "Last object modification: %s", ctime(&LastObjectChange));
+ if(LastEPGChange >= LastObjectChange){
+ MESSAGE(VERBOSE_EPG_UPDATES, "Updating details");
+
+ if(Event){
+ ChannelItem->setTitle(Event->Title()?Event->Title():Channel->Name());
+ ChannelItem->setLongDescription(Event->Description());
+ ChannelItem->setDescription(Event->ShortText());
+ }
+ else {
+ ChannelItem->setTitle(Channel->Name());
+ ChannelItem->setLongDescription(NULL);
+ ChannelItem->setDescription(NULL);
+ }
+
+ this->mFactory->saveObject(ChannelItem);
+ }
+ else {
+ MESSAGE(VERBOSE_EPG_UPDATES, "Channel did not change");
+ }
+ }
+ else {
+ MESSAGE(VERBOSE_EPG_UPDATES, "No EPG data");
+ ChannelItem->setTitle(Channel->Name());
+ ChannelItem->setLongDescription(NULL);
+ ChannelItem->setDescription(NULL);
+ }
+ }
+ }
+ }
+}
+#endif
+#ifndef WITHOUT_RECORDS
int cMediaDatabase::loadRecordings(){
MESSAGE(VERBOSE_RECORDS, "Loading recordings");
cUPnPClassContainer* Records = (cUPnPClassContainer*)this->getObjectByID(4);
@@ -344,7 +419,7 @@ int cMediaDatabase::loadRecordings(){
MESSAGE(VERBOSE_RECORDS, "Adding movie '%s' File name:%s", RecInfo->Title(), Recording->FileName());
- MovieItem = (cUPnPClassMovie*)this->mFactory->createObject(UPNP_CLASS_MOVIE, RecInfo->Title());
+ MovieItem = (cUPnPClassMovie*)this->mFactory->createObject(UPNP_CLASS_MOVIE, RecInfo->Title()?RecInfo->Title():Recording->Name());
MovieItem->setDescription(RecInfo->ShortText());
MovieItem->setLongDescription(RecInfo->Description());
MovieItem->setStorageMedium(UPNP_STORAGE_HDD);
@@ -380,6 +455,7 @@ int cMediaDatabase::loadRecordings(){
}
return 0;
}
+#endif
void cMediaDatabase::Action(){
time_t LastEPGUpdate = 0;
@@ -395,63 +471,6 @@ void cMediaDatabase::Action(){
}
}
-void cMediaDatabase::updateChannelEPG(){
- cUPnPClassContainer* TV = (cUPnPClassContainer*)this->getObjectByID(3);
- if(TV){
- // Iterating channels
- MESSAGE(VERBOSE_EPG_UPDATES, "Getting schedule...");
- cSchedulesLock SchedulesLock;
- const cSchedules *Schedules = cSchedules::Schedules(SchedulesLock);
-
- cList<cUPnPClassObject>* List = TV->getObjectList();
- MESSAGE(VERBOSE_EPG_UPDATES, "TV folder has %d items", List->Count());
- for(cUPnPClassVideoBroadcast* ChannelItem = (cUPnPClassVideoBroadcast*)List->First();
- ChannelItem;
- ChannelItem = (cUPnPClassVideoBroadcast*)List->Next(ChannelItem)
- ){
- MESSAGE(VERBOSE_EPG_UPDATES, "Find channel by number %d", ChannelItem->getChannelNr());
- cChannel* Channel = Channels.GetByNumber(ChannelItem->getChannelNr());
- MESSAGE(VERBOSE_EPG_UPDATES, "Found channel with ID %s", *Channel->GetChannelID().ToString());
-
- const cSchedule* Schedule = Schedules->GetSchedule(Channel);
- const cEvent* Event = Schedule?Schedule->GetPresentEvent():NULL;
- if(Event){
-
- time_t LastEPGChange = Event->StartTime();
- time_t LastObjectChange = ChannelItem->modified();
-
- MESSAGE(VERBOSE_EPG_UPDATES, "Last event start: %s", ctime(&LastEPGChange));
- MESSAGE(VERBOSE_EPG_UPDATES, "Last object modification: %s", ctime(&LastObjectChange));
- if(LastEPGChange >= LastObjectChange){
- MESSAGE(VERBOSE_EPG_UPDATES, "Updating details");
-
- if(Event){
- ChannelItem->setTitle(Event->Title()?Event->Title():Channel->Name());
- ChannelItem->setLongDescription(Event->Description());
- ChannelItem->setDescription(Event->ShortText());
- }
- else {
- ChannelItem->setTitle(Channel->Name());
- ChannelItem->setLongDescription(NULL);
- ChannelItem->setDescription(NULL);
- }
-
- this->mFactory->saveObject(ChannelItem);
- }
- else {
- MESSAGE(VERBOSE_EPG_UPDATES, "Channel did not change");
- }
- }
- else {
- MESSAGE(VERBOSE_EPG_UPDATES, "No EPG data");
- ChannelItem->setTitle(Channel->Name());
- ChannelItem->setLongDescription(NULL);
- ChannelItem->setDescription(NULL);
- }
- }
- }
-}
-
int cMediaDatabase::browse(
OUT cUPnPResultSet** Results,
IN const char* ID,
diff --git a/database/metadata.h b/database/metadata.h
deleted file mode 100644
index 4868231..0000000
--- a/database/metadata.h
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * File: metadata.h
- * Author: savop
- *
- * Created on 28. Mai 2009, 21:14
- */
-
-#ifndef _METADATA_H
-#define _METADATA_H
-
-#include <vdr/tools.h>
-#include <vdr/channels.h>
-#include <vdr/recording.h>
-#include "../common.h"
-#include "database.h"
-#include "object.h"
-#include "resources.h"
-
-/**
- * The result set of a request
- *
- * This contains the results of a previous \e Browse or \e Search request.
- */
-struct cUPnPResultSet {
- int mNumberReturned; ///< The number of returned matches
- int mTotalMatches; ///< The total amount of matches
- const char* mResult; ///< The DIDL-Lite fragment
-};
-
-/**
- * The media database
- *
- * This class is the global object manager. It holds every object in a local cache.
- * Only this class is allowed to create new objects.
- *
- * @see cUPnPClassObject
- */
-class cMediaDatabase : public cThread {
- friend class cUPnPServer;
- friend class cUPnPObjectMediator;
-private:
- unsigned int mSystemUpdateID;
- cUPnPObjectFactory* mFactory;
- cHash<cUPnPClassObject>* mObjects;
- cSQLiteDatabase* mDatabase;
- cUPnPObjectID mLastInsertObjectID;
- cUPnPObjectID getNextObjectID();
- void cacheObject(cUPnPClassObject* Object);
- int prepareDatabase();
- int loadChannels();
- int loadRecordings();
- void updateChannelEPG();
- void updateRecordings();
- bool init();
- void updateSystemID();
- virtual void Action();
-public:
- /**
- * Returns the SystemUpdateID
- *
- * This returns the \e SystemUpdateID. This changes whenever anything changed
- * within the content directory. This value will be sent through the UPnP
- * network every 2 seconds.
- *
- * @return the SystemUpdateID
- */
- unsigned int getSystemUpdateID();
- /**
- * Returns a CSV list with ContainerUpdateIDs
- *
- * This list contains an unordered list of ordered pairs of ContainerID and
- * its ContainerUpdateID. It contains only recent changes which are not yet
- * beeing evented. This means that evented updates will be removed from list.
- *
- * @return CSV list of ContainerUpdateIDs
- */
- const char* getContainerUpdateIDs();
- /**
- * Constructor
- *
- * This creates an instance of the media database.
- */
- cMediaDatabase();
- virtual ~cMediaDatabase();
- /**
- * Add a Fastfind
- *
- * This creates a \e Fastfind entry. It is a string which can be used to
- * relocate a objectID. Usually this is a file name or another ID with which
- * the related object can be found.
- *
- * @return returns
- * - \bc -1, if the creation was successful
- * - \bc 0, otherwise
- */
- int addFastFind(
- cUPnPClassObject* Object, ///< the object, which should be registered
- const char* FastFind ///< the string with which the object shall be
- ///< relocated
- );
- /**
- * Finds a object by Fastfind
- *
- * This returns the object via the \e Fastfind string. The object must be
- * previosly registered via \c cMediaDatabase::addFastFind().
- *
- * It tries to find the object in the internal object cache. If this fails,
- * the object will be loaded from the database.
- *
- * @see cMediaDatabase::addFastFind
- * @return The object associated with FastFind
- */
- cUPnPClassObject* getObjectByFastFind(
- const char* FastFind ///< the string with which the object shall be
- ///< relocated
- );
- /**
- * Finds a object by its ObjectID
- *
- * This returns the object via its \e ObjectID.
- *
- * It tries to find the object in the internal object cache. If this fails,
- * the object will be loaded from the database.
- *
- * @return The object associated with FastFind
- */
- cUPnPClassObject* getObjectByID(
- cUPnPObjectID ID ///< The ObjectID of the requested object
- );
- /**
- * Performs a browse on the database
- *
- * This performs a browse request on the database and returns a structure
- * containing the matching count and DIDL-Lite fragement which is sent to
- * the control point.
- *
- * @return returns an integer representing one of the following:
- * - \bc UPNP_CDS_E_INVALID_SORT_CRITERIA, when the sort criteria is malformed
- * - \bc UPNP_CDS_E_CANT_PROCESS_REQUEST, when there is an internal error while
- * processing the request
- * - \bc UPNP_CDS_E_NO_SUCH_OBJECT, when the requested ObjectID does not exist
- * - \bc UPNP_SOAP_E_ACTION_FAILED, when the action failed due any reasons
- * - \bc UPNP_E_SUCCESS, if the request was successful
- */
- int browse(
- OUT cUPnPResultSet** Results, ///< the result of the request
- IN const char* ID, ///< the objectID of the request
- IN bool BrowseMetadata, ///< \b true to browse metadata, \b false otherwise
- IN const char* Filter = "*", ///< the filter applied to the returned metadata
- IN unsigned int Offset = 0, ///< the starting offset
- IN unsigned int Count = 0, ///< maximum count returned
- IN const char* SortCriteria = "" ///< sorts the results before returning them
- );
- /**
- * Performs a search on the database
- *
- * This performs a search request on the database and returns a structure
- * containing the matching count and DIDL-Lite fragement which is sent to
- * the control point.
- *
- * @note
- * The submitted ID must be a ContainerID. Searches are performed only
- * in this container.
- *
- * @return returns an integer representing one of the following:
- * - \bc UPNP_CDS_E_INVALID_SORT_CRITERIA, when the sort criteria is malformed
- * - \bc UPNP_CDS_E_CANT_PROCESS_REQUEST, when there is an internal error while
- * processing the request
- * - \bc UPNP_CDS_E_NO_SUCH_OBJECT, when the requested ObjectID does not exist
- * - \bc UPNP_SOAP_E_ACTION_FAILED, when the action failed due any reasons
- * - \bc UPNP_E_SUCCESS, if the request was successful
- */
- int search(
- OUT cUPnPResultSet** Results, ///< the result of the request
- IN const char* ID, ///< the ContainerID
- IN const char* Search, ///< the search string
- IN const char* Filter = "*", ///< the filter applied to the returned metadata
- IN unsigned int Offset = 0, ///< the starting offset
- IN unsigned int Count = 0, ///< maximum count returned
- IN const char* SortCriteria = "" ///< sorts the results before returning them
- );
-};
-
-#endif /* _METADATA_H */
-
diff --git a/database/object.cpp b/database/object.cpp
index 5ab355d..71dfe63 100644
--- a/database/object.cpp
+++ b/database/object.cpp
@@ -18,46 +18,6 @@
#include "../common.h"
#include "resources.h"
-cUPnPResource::cUPnPResource(){
- this->mBitrate = 0;
- this->mBitsPerSample = 0;
- this->mColorDepth = 0;
- this->mDuration = NULL;
- this->mImportURI = NULL;
- this->mNrAudioChannels = 0;
- this->mObjectID = 0;
- this->mProtocolInfo = NULL;
- this->mResolution = NULL;
- this->mResource = NULL;
- this->mResourceID = 0;
- this->mSampleFrequency = 0;
- this->mSize = 0;
- this->mContentType = NULL;
-}
-
-time_t cUPnPResource::getLastModification() const {
- time_t Time;
- const cRecording* Recording;
- const cEvent* Event;
- switch(this->mResourceType){
- case UPNP_RESOURCE_CHANNEL:
- case UPNP_RESOURCE_URL:
- Time = time(NULL);
- break;
- case UPNP_RESOURCE_RECORDING:
- Recording = Recordings.GetByName(this->mResource);
- Event = (Recording)?Recording->Info()->GetEvent():NULL;
- Time = (Event)?Event->EndTime():time(NULL);
- break;
- case UPNP_RESOURCE_FILE:
- //break;
- default:
- ERROR("Invalid resource type. This resource might be broken");
- Time = -1;
- }
- return Time;
-}
-
static int CompareUPnPObjects(const void *a, const void *b){
const cUPnPClassObject *la = *(const cUPnPClassObject **)a;
const cUPnPClassObject *lb = *(const cUPnPClassObject **)b;
diff --git a/database/object.h b/database/object.h
deleted file mode 100644
index 9c2c133..0000000
--- a/database/object.h
+++ /dev/null
@@ -1,1728 +0,0 @@
-/*
- * File: object.h
- * Author: savop
- *
- * Created on 11. September 2009, 20:39
- */
-
-#ifndef _OBJECT_H
-#define _OBJECT_H
-
-#include "database.h"
-#include "../common.h"
-#include "../misc/util.h"
-#include <string.h>
-#include <vdr/tools.h>
-#include <map>
-#include <vector>
-#include <upnp/ixml.h>
-
-/**
- * UPnP Object ID
- *
- * This is a UPnP Object ID representation.
- */
-struct cUPnPObjectID {
- int _ID; ///< The UPnP Object ID
- /**
- * Constructor
- *
- * Creates invalid ID
- */
- cUPnPObjectID():_ID(-1){}
- /**
- * Constructor
- *
- * Creates from long integer
- */
- cUPnPObjectID(
- long ID ///< new ID
- ){ _ID = (int)ID; }
- /**
- * Constructor
- *
- * Creates from integer
- */
- cUPnPObjectID(
- int ID ///< new ID
- ){ _ID = ID; }
- /** Set the object ID */
- cUPnPObjectID &operator=(
- long ID ///< new ID
- ){ _ID = ID; return *this; }
- /** @overload cUPnPObjectID &operator=(long ID) */
- cUPnPObjectID &operator=(
- int ID ///< new ID
- ){ _ID = ID; return *this; }
- /** @overload cUPnPObjectID &operator=(long ID) */
- cUPnPObjectID &operator=(
- const cUPnPObjectID& ID ///< new ID
- ){ if(this != &ID){ _ID = ID._ID; } return *this; }
- /** Pre increment the ID */
- cUPnPObjectID &operator++(){ _ID++; return *this; }
- /** Post increment the ID */
- cUPnPObjectID operator++(int){ cUPnPObjectID old = *this; _ID++; return old; }
- /** Post decrement the ID */
- cUPnPObjectID operator--(int){ cUPnPObjectID old = *this; _ID--; return old; }
- /** Pre decrement the ID */
- cUPnPObjectID &operator--(){ _ID--; return *this; }
- /** Not equal */
- bool operator!=(
- long ID ///< compare with this ID
- ){ return _ID != ID; }
- /** Equal */
- bool operator==(
- long ID ///< compare with this ID
- ){ return _ID == ID; }
- /** @overload bool operator!=(long ID) */
- bool operator!=(
- int ID ///< compare with this ID
- ){ return _ID != ID; }
- /** @overload bool operator==(long ID) */
- bool operator==(
- int ID ///< compare with this ID
- ){ return _ID == ID; }
- /** @overload bool operator!=(long ID) */
- bool operator!=(
- const cUPnPObjectID& ID ///< compare with this ID
- ){ return *this == ID; }
- /** @overload bool operator==(long ID) */
- bool operator==(
- const cUPnPObjectID& ID ///< compare with this ID
- ){ return *this == ID; }
- /** Casts to unsigned int */
- operator unsigned int(){ return (unsigned int)_ID; }
- /** Casts to int */
- operator int(){ return _ID; }
- /** Casts to long */
- operator long(){ return (long)_ID; }
- /** Casts to string */
- const char* operator*(){ char* buf; return asprintf(&buf,"%d",_ID)?buf:NULL; }
-};
-
-/**
- * Structure of a UPnP Class
- *
- * This represents a UPnP Class
- */
-struct cClass {
- cString ID; ///< The upnp class ID
- bool includeDerived; ///< flag, to indicate if derived classes are allowed
- /**
- * Compares two classes
- *
- * @param cmp the other class to compare with
- */
- bool operator==(const cClass &cmp){ return (!strcasecmp(cmp.ID,ID) && includeDerived==cmp.includeDerived); }
- /*! @copydoc operator==(const cClass &cmp) */
- bool operator!=(const cClass &cmp){ return !(*this==cmp); }
-};
-
-/**
- * UPnP Resource
- *
- * This contains all details about a resource
- */
-class cUPnPResource : public cListObject {
- friend class cUPnPResourceMediator;
- friend class cUPnPResources;
- friend class cAudioVideoDetector;
-private:
- unsigned int mResourceID;
- cUPnPObjectID mObjectID;
- int mResourceType;
- cString mResource;
- cString mDuration;
- cString mResolution;
- cString mProtocolInfo;
- cString mContentType;
- cString mImportURI;
- off64_t mSize;
- unsigned int mBitrate;
- unsigned int mSampleFrequency;
- unsigned int mBitsPerSample;
- unsigned int mNrAudioChannels;
- unsigned int mColorDepth;
- cUPnPResource();
-public:
- /**
- * Get resource ID
- *
- * Gets the resource ID
- *
- * @return the resource ID
- */
- unsigned int getID() const { return this->mResourceID; }
- /**
- * Get the resources
- *
- * Returns the resource. This is in most cases the file name or resource locator
- * where to find the resource
- *
- * @return the resource string
- */
- const char* getResource() const { return this->mResource; }
- /**
- * Get the duration
- *
- * Returns a date time string with the duration of the resource
- *
- * @return the duration of the resource
- */
- const char* getDuration() const { return this->mDuration; }
- /**
- * Get the resolution
- *
- * Returns the resolution string with the pattern width x height in pixels
- *
- * @return the resolution of the resource
- */
- const char* getResolution() const { return this->mResolution; }
- /**
- * Get the protocol info
- *
- * This returns the protocol info field of a resource
- *
- * @return the protocol info string
- */
- const char* getProtocolInfo() const { return this->mProtocolInfo; }
- /**
- * Get the content type
- *
- * Returns the mime type of the content of the resource
- *
- * @return the content type of the resource
- */
- const char* getContentType() const { return this->mContentType; }
- /**
- * Get the import URI
- *
- * This returns the import URI where the resource was located before importing
- * it
- *
- * @return the import URI
- */
- const char* getImportURI() const { return this->mImportURI; }
- /**
- * Get the resource type
- *
- * This returns the resource type of the resource.
- *
- * @return the resource type
- */
- int getResourceType() const { return this->mResourceType; }
- /**
- * Get the file size
- *
- * Returns the file size in bytes of the resource or 0 if its unknown or a
- * stream
- *
- * @return the file size
- */
- off64_t getFileSize() const { return this->mSize; };
- /**
- * Get the last modification
- *
- * This returns the timestamp of the last modification to the file. If it
- * is a stream, then its the current time.
- *
- * @return the timestamp with the last modification of the resource
- */
- time_t getLastModification() const;
- /**
- * Get the bitrate
- *
- * This returns the bitrate of the resource in bits per second.
- *
- * @return the bitrate of the resource
- */
- unsigned int getBitrate() const { return this->mBitrate; }
- /**
- * Get the sample frequency
- *
- * Returns the sample frequency in samples per second.
- *
- * @return the sample frequency of the resource
- */
- unsigned int getSampleFrequency() const { return this->mSampleFrequency; }
- /**
- * Get the bits per sample
- *
- * Returns the number of bits per sample.
- *
- * @return the bits per sample of the resource
- */
- unsigned int getBitsPerSample() const { return this->mBitsPerSample; }
- /**
- * Get number of audio channels
- *
- * Returns the number of audio channels of the audio stream in a video
- *
- * @return the number of audio channels
- */
- unsigned int getNrAudioChannels() const { return this->mNrAudioChannels; }
- /**
- * Get the color depth
- *
- * Returns the color depth of the resource in pits per pixel
- *
- * @return the color depth of the resource
- */
- unsigned int getColorDepth() const { return this->mColorDepth; }
-};
-
-class cUPnPClassObject;
-class cUPnPObjectMediator;
-class cUPnPContainerMediator;
-class cUPnPClassContainer;
-
-/**
- * List of UPnP Objects
- *
- * This is a cList of UPnP Objects
- * The list can be sorted by using a specific property
- */
-class cUPnPObjects : public cList<cUPnPClassObject> {
-public:
- cUPnPObjects();
- virtual ~cUPnPObjects();
- /**
- * Sorts the list
- *
- * This sorts the list by a specific property and a certain direction
- */
- void SortBy(
- const char* Property, ///< the property used for sorting
- bool Descending = false ///< the direction of the sort
- );
-};
-
-/**
- * The UPnP class Object
- *
- * This is a UPnP class Object representation with all its properties.
- */
-class cUPnPClassObject : public cListObject {
- friend class cMediaDatabase;
- friend class cUPnPObjectMediator;
- friend class cUPnPClassContainer;
-private:
- cUPnPObjectID mLastID;
- bool mDeleted; // is this Objected marked as deleted, NOT used yet.
-protected:
- time_t mLastModified; ///< The last modification of this property
- cUPnPObjectID mID; ///< The object ID
- cUPnPClassObject* mParent; ///< The parent object
- cString mClass; ///< Class (Who am I?)
- cString mTitle; ///< Object title
- cString mCreator; ///< Creator of this object
- bool mRestricted; ///< Ability of changing metadata?
- int mWriteStatus; ///< Ability of writing resources?
- cList<cUPnPResource>* mResources; ///< The resources of this object
- cHash<cUPnPResource>* mResourcesID; ///< The resources of this object as hashmap
- IXML_Document* mDIDLFragment; ///< The DIDL fragment of the object
- cString mSortCriteria; ///< The sort criteria to sort with
- bool mSortDescending; ///< The direction of the sort
- cUPnPClassObject();
- /**
- * Set the Object ID
- *
- * This is only allowed by mediators and the media database. Manually editing
- * the object ID may result in unpredictable behavior.
- *
- * @param ID the ObjectID of this object
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- */
- int setID(cUPnPObjectID ID);
- /**
- * Set the Parent Object
- *
- * This is only allowed by mediators and the media database. Manually editing
- * the parent may result in unpredictable behavior.
- *
- * @param Parent the parent of this object
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- */
- int setParent(cUPnPClassContainer* Parent);
- /**
- * Set the object class
- *
- * This is only allowed by mediators and the media database. Manually editing
- * the object class may result in unpredictable behavior.
- *
- * @param Class the class of this object
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- */
- int setClass(const char* Class);
- /**
- * Set the modification time
- *
- * This sets the last modification time to the current timestamp. This is
- * used to indicate when the object was updated the last time.
- */
- void setModified(void){ this->mLastModified = time(NULL); }
-public:
- /**
- * Last modified
- *
- * Returns when the object was modified the last time.
- *
- * @return last modification timestamp
- */
- time_t modified() const { return this->mLastModified; }
- virtual ~cUPnPClassObject();
- /**
- * Compares a object
- *
- * This compares a given object with this object
- * It uses the SortCriteria to compare them.
- *
- * @return returns
- * - \bc >0, if the object comes after this one
- * - \bc 0, if the objects have the same property
- * - \bc <0, if the object comes before this one
- * @param ListObject the object to compare with
- */
- virtual int Compare(const cListObject& ListObject) const;
- /**
- * Get the properties of the object
- *
- * This returns a property list with all the properties which can be obtained
- * or set with \c getProperty or \c setProperty.
- *
- * @return a stringlist with the properties
- */
- virtual cStringList* getPropertyList();
- /**
- * Gets a property
- *
- * Returns the value of a specified property. The value is converted into a
- * string.
- *
- * @return returns
- * - \bc true, if the property exists
- * - \bc false, otherwise
- * @param Property the property which should be returned
- * @param Value the value of that property
- */
- virtual bool getProperty(const char* Property, char** Value) const ;
- /**
- * Sets a property
- *
- * Sets the value of a specified property. The value is converted from string
- * into the propper data type
- *
- * @return returns
- * - \bc true, if the property exists
- * - \bc false, otherwise
- * @param Property the property which should be set
- * @param Value the value of that property
- */
- virtual bool setProperty(const char* Property, const char* Value);
- /**
- * Converts to container
- *
- * This will convert the object into a container if it is one. If not, it
- * returns \bc NULL.
- *
- * @return returns
- * - \bc NULL, if it is not a container
- * - a container representation of this object
- */
- virtual cUPnPClassContainer* getContainer(){ return NULL; }
- /**
- * Create the DIDL fragment
- *
- * This creates the DIDL-Lite fragment of the object. The DIDL is written to the
- * specified \em IXML document. The details of the output can be controlled via
- * the filter stringlist
- *
- * @return the DIDL fragment of the object
- * @param Document the IXML document where to write the contents
- * @param Filter the string list with the filter criteria
- */
- virtual IXML_Node* createDIDLFragment(IXML_Document* Document, cStringList* Filter) = 0;
- /**
- * Is this a container?
- *
- * Returns if this object is a container or not
- *
- * @return returns
- * - \bc true, if it is a container
- * - \bc false, otherwise
- */
- bool isContainer(){ return this->getContainer()==NULL?false:true; }
- /**
- * Set the sort criteria
- *
- * This sets a certain criteria which the object can be compared with.
- *
- * @param Property the property to sort after
- * @param Descending sort the objects in descending order
- */
- void setSortCriteria(const char* Property, bool Descending = false);
- /**
- * Clears the sort criteria
- *
- * Clears the property of the sort criteria and sets the descending flag to
- * false.
- */
- void clearSortCriteria();
- /******* Setter *******/
- /**
- * Set the title
- *
- * This sets the title of the object. It is a required metadata information.
- * It must not be \bc NULL or an empty string.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Title the title of the object
- */
- int setTitle(const char* Title);
- /**
- * Set the creator
- *
- * The creator of an object is primarily the creator or owner of the object
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Creator the creator of the object
- */
- int setCreator(const char* Creator);
- /**
- * Set the restriction
- *
- * This sets the restriction flag. If the object is restricted, no modifications
- * to its metadata by the user are allowed.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Restricted \bc true, to disallow modification, \bc false to allow it
- */
- int setRestricted(bool Restricted);
- /**
- * Set the write status
- *
- * This sets the write status of a resource. With this indicator, you can set
- * the modifiabilty of resources by a control point.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Status the write status
- */
- int setWriteStatus(int Status);
- /**
- * Set the resources
- *
- * This sets the list of resources of an object. The list usally contain a
- * single resource. However, multiple resources a also very common.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Resources the resource list of this object
- */
- int setResources(cList<cUPnPResource>* Resources);
- /**
- * Add resource to list
- *
- * This adds the specified resource to the resource list of the object
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Resource the resource to be added
- */
- int addResource(cUPnPResource* Resource);
- /**
- * Remove resource from list
- *
- * This removes the specified resource from the resource list of the object
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Resource the resource to be removed
- */
- int removeResource(cUPnPResource* Resource);
- /******* Getter *******/
- /**
- * Get the object ID
- *
- * This returns the object ID of the object.
- *
- * @return the object ID
- */
- cUPnPObjectID getID() const { return this->mID; }
- /**
- * Get the parent ID
- *
- * This returns the ID of the parent container object, associated with this object.
- * It is \bc -1, if the object is the root object.
- *
- * @return the parent ID
- */
- cUPnPObjectID getParentID() const { return this->mParent?this->mParent->getID():cUPnPObjectID(-1); }
- /**
- * Get the parent object
- *
- * This returns the parent container object, associated with this object. It is
- * \bc NULL, if the object is the root object.
- *
- * @return the parent object
- */
- cUPnPClassContainer* getParent() const { return (cUPnPClassContainer*)this->mParent; }
- /**
- * Get the title
- *
- * This returns the title of the object. This may be the title of an item or
- * the folder name in case of a container.
- *
- * @return the title of the object
- */
- const char* getTitle() const { return this->mTitle; }
- /**
- * Get the object class
- *
- * This returns the object class of the object. The classes are defined by
- * the UPnP Working Committee. However, custom classes which are derived from
- * a standardized class are also possible.
- *
- * @return the class of the object
- */
- const char* getClass() const { return this->mClass; }
- /**
- * Get the creator
- *
- * This returns the creator of the object. Usually, this is the primary
- * content creator or the owner of the object
- *
- * @return the creator of the object
- */
- const char* getCreator() const { return this->mCreator; }
- /**
- * Is the resource restricted?
- *
- * Returns \bc true, if the object is restricted or \bc false, otherwise.
- * When the object is restricted, then modifications to the metadata of the
- * object are disallowed.
- *
- * @return returns
- * - \bc true, if the object is restricted
- * - \bc false, otherwise
- */
- bool isRestricted() const { return this->mRestricted; }
- /**
- * Get write status
- *
- * This returns the write status of the object. It gives information, if the
- * resource is modifiable.
- *
- * @return the write status
- */
- int getWriteStatus() const { return this->mWriteStatus; }
- /**
- * Get a resource by its ID
- *
- * Returns the resource with the specified resource ID.
- *
- * @return the resource by ID
- * @param ResourceID the resource ID of the demanded resource
- */
- cUPnPResource* getResource(unsigned int ResourceID) const { return this->mResourcesID->Get(ResourceID); }
- /**
- * Get the resources
- *
- * This returns a list with resources associated with this object.
- *
- * @return the resources of this object
- */
- cList<cUPnPResource>* getResources() const { return this->mResources; }
-};
-
-/**
- * The UPnP class Item
- *
- * This is a UPnP class Item representation with all its properties.
- */
-class cUPnPClassItem : public cUPnPClassObject {
- friend class cMediaDatabase;
- friend class cUPnPObjectMediator;
- friend class cUPnPItemMediator;
-protected:
-// cUPnPObjectID mReferenceID;
- cUPnPClassItem* mReference; ///< The reference item
- /**
- * Constructor of an item
- *
- * This creates a new instance of an item
- */
- cUPnPClassItem();
-public:
- virtual ~cUPnPClassItem(){};
- virtual cStringList* getPropertyList();
- virtual IXML_Node* createDIDLFragment(IXML_Document* Document, cStringList* Filter);
- virtual bool setProperty(const char* Property, const char* Value);
- virtual bool getProperty(const char* Property, char** Value) const;
- /******** Setter ********/
- /**
- * Set a reference item
- *
- * This sets a reference item. Its comparable with symlinks in *nix systems
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Reference the reference item
- */
- int setReference(cUPnPClassItem* Reference);
- /******** Getter ********/
- /**
- * Get the referenced item
- *
- * This returns the referenced item of this item
- *
- * @return the referenced item
- */
- cUPnPClassItem* getReference() const { return this->mReference; }
- /**
- * Get the reference ID
- *
- * This returns the object ID of the referenced item or \b -1, if
- * no reference exists.
- *
- * @return the reference ID
- */
- cUPnPObjectID getReferenceID() const { return this->mReference?this->mReference->getID():cUPnPObjectID(-1); }
-};
-
-typedef std::vector<cClass> tClassVector;
-
-/**
- * The UPnP class Container
- *
- * This is a UPnP class Container representation with all its properties.
- */
-class cUPnPClassContainer : public cUPnPClassObject {
- friend class cMediaDatabase;
- friend class cUPnPObjectMediator;
- friend class cUPnPContainerMediator;
-protected:
- cString mContainerType; ///< DLNA container type
- tClassVector mSearchClasses; ///< Classes which are searchable
- tClassVector mCreateClasses; ///< Classes which are creatable
- bool mSearchable; ///< Is the Container searchable?
- unsigned int mUpdateID; ///< The containerUpdateID
- cUPnPObjects* mChildren; ///< List of children
- cHash<cUPnPClassObject>* mChildrenID; ///< List of children as hash map
- /**
- * Update the container
- *
- * This performs an update, which acutally increases the containerUpdateID.
- */
- void update();
- /**
- * Sets the containerUpdateID
- *
- * This method should only be used when the containerUpdateID is loaded from
- * the database.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param UID the containerUpdateID
- */
- int setUpdateID(unsigned int UID);
- /**
- * Constructor of a container
- *
- * This creates a new instance of a container
- */
- cUPnPClassContainer();
-public:
- virtual ~cUPnPClassContainer();
- virtual cStringList* getPropertyList();
- virtual IXML_Node* createDIDLFragment(IXML_Document* Document, cStringList* Filter);
- virtual bool setProperty(const char* Property, const char* Value);
- virtual bool getProperty(const char* Property, char** Value) const;
- virtual cUPnPClassContainer* getContainer(){ return this; }
- /**
- * Add a child
- *
- * This adds the specified child to this container. The parent container of the
- * child will be set to this container.
- *
- * @param Object the child to be added
- */
- void addObject(cUPnPClassObject* Object);
- /**
- * Remove a child
- *
- * This removes the specified child from the list of children. The child will
- * also loose its parent container, so that there is no link between left.
- *
- * @param Object the child to be removed
- */
- void removeObject(cUPnPClassObject* Object);
- /**
- * Get a child by ID
- *
- * Returns the child, which is specified by the \c ObjectID.
- *
- * @return the child with the specified ID
- * @param ID the \c ObjectID of the child
- */
- cUPnPClassObject* getObject(cUPnPObjectID ID) const;
- /**
- * Get the list of children
- *
- * This returns a list of the children of the container.
- *
- * @return the list of children
- */
- cUPnPObjects* getObjectList() const { return this->mChildren; }
- /**
- * Add a search class
- *
- * This adds a search class to the search classes vector
- *
- * @return returns
- * - \bc 0, if adding was successful
- * - \bc <0, otherwise
- * @param SearchClass the new class to be added
- */
- int addSearchClass(cClass SearchClass);
- /**
- * Remove a search class
- *
- * This removes a search class from the search classes vector
- *
- * @return returns
- * - \bc 0, if deleting was successful
- * - \bc <0, otherwise
- * @param SearchClass the class to be deleted
- */
- int delSearchClass(cClass SearchClass);
- /**
- * Add a create class
- *
- * This adds a create class to the create classes vector
- *
- * @return returns
- * - \bc 0, if adding was successful
- * - \bc <0, otherwise
- * @param CreateClass the new class to be added
- */
- int addCreateClass(cClass CreateClass);
- /**
- * Remove a create class
- *
- * This removes a create class from the create classes vector
- *
- * @return returns
- * - \bc 0, if deleting was successful
- * - \bc <0, otherwise
- * @param CreateClass the class to be deleted
- */
- int delCreateClass(cClass CreateClass);
- /******** Setter ********/
- /**
- * Set the DLNA container type
- *
- * This sets the DLNA container type. It must be a valid container type value.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Type the DLNA container type
- */
- int setContainerType(const char* Type);
- /**
- * Sets the search classes
- *
- * This sets the search classes, which allows the user to search only for
- * these classes in the current container and its children. If the vector
- * is empty the search can return any match. If the additional flag \bc
- * derived is set, then also any derived classes are matched.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param SearchClasses a vector container the allowed search classes
- */
- int setSearchClasses(std::vector<cClass> SearchClasses);
- /**
- * Sets the create classes
- *
- * This sets the create classes, which allows the user to create new objects
- * in this container, if \em restricted is \bc false.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param CreateClasses a vector containing the create classes
- */
- int setCreateClasses(std::vector<cClass> CreateClasses);
- /**
- * Sets the searchable flag
- *
- * This sets the searchable flag, which allows or disallows search on this
- * container.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Searchable \bc true, to enable or \bc false, to disable searching
- */
- int setSearchable(bool Searchable);
- /******** Getter ********/
- /**
- * Get the DLNA container type
- *
- * This returns the DLNA container type. Currently there are only these possible
- * values beside \bc NULL:
- * - \bc TUNER_1_0
- *
- * @return the DLNA container type
- */
- const char* getContainerType() const { return this->mContainerType; }
- /**
- * Get the search classes
- *
- * This returns a vector container all possible search classes. This are classes,
- * which can be used for searching in this container.
- *
- * @return a vector with all search classes
- */
- const std::vector<cClass>* getSearchClasses() const { return &(this->mSearchClasses); }
- /**
- * Get the create classes
- *
- * This returns a vector containing all possible create classes. This are classes,
- * which can be created in this container. For instance a TV container can only create
- * items of the class VideoBroadcast. The vector is empty when creation of new items
- * by the user is not allowed.
- *
- * @return a vector with create classes
- */
- const std::vector<cClass>* getCreateClasses() const { return &(this->mCreateClasses); }
- /**
- * Is this container searchable
- *
- * This returns \bc true, if the container can be search via \em Search or
- * \bc false, otherwise.
- *
- * @return returns
- * - \bc true, if the container is searchable
- * - \bc false, otherwise
- */
- bool isSearchable() const { return this->mSearchable; }
- /**
- * Get the number of children
- *
- * This returns the total number of children of this container
- *
- * @return the number of childen
- */
- unsigned int getChildCount() const { return this->mChildren->Count(); }
- /**
- * Get the containerUpdateID
- *
- * This returns the containerUpdateID
- *
- * @return the containerUpdateID of this container
- */
- unsigned int getUpdateID() const { return this->mUpdateID; }
- /**
- * Has the container been updated?
- *
- * This returns \bc true, if the container was recently updated or
- * \bc false, otherwise
- *
- * @return returns
- * - \bc true, if the container was updated
- * - \bc false, otherwise
- */
- bool isUpdated();
-};
-
-/**
- * The UPnP class VideoItem
- *
- * This is a UPnP class VideoItem representation with all its properties.
- */
-class cUPnPClassVideoItem : public cUPnPClassItem {
- friend class cMediaDatabase;
- friend class cUPnPObjectMediator;
- friend class cUPnPVideoItemMediator;
-protected:
- cString mGenre; ///< Genre of the video
- cString mDescription; ///< Description
- cString mLongDescription; ///< a longer description
- cString mPublishers; ///< CSV of Publishers
- cString mLanguage; ///< RFC 1766 Language code
- cString mRelations; ///< Relation to other contents
- cString mProducers; ///< CSV of Producers
- cString mRating; ///< Rating (for parential control)
- cString mActors; ///< CSV of Actors
- cString mDirectors; ///< CSV of Directors
- /**
- * Constructor of a video item
- *
- * This creates a new instance of a video item
- */
- cUPnPClassVideoItem();
-public:
- virtual ~cUPnPClassVideoItem();
- //virtual cString createDIDLFragment(cStringList* Filter);
- virtual cStringList* getPropertyList();
- virtual bool setProperty(const char* Property, const char* Value);
- virtual bool getProperty(const char* Property, char** Value) const;
- /******** Setter ********/
- /**
- * Set a long description
- *
- * A long description may hold information about the content or the story
- * of a video
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param LongDescription the content or story of a video
- */
- int setLongDescription(const char* LongDescription);
- /**
- * Set a description
- *
- * A description may hold short information about the content or the story
- * of a video. Unlike a long description, this contains just a very short
- * brief like a subtitle or the episode title.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Description the description of a video
- */
- int setDescription(const char* Description);
- /**
- * Set the publishers
- *
- * This is a CSV list of publishers, who distributes the video.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Publishers a CSV list of publishers
- */
- int setPublishers(const char* Publishers);
- /**
- * Set a genre
- *
- * This is a CSV list of genre of a video. This may be something like
- * "Western" or "SciFi". Actually, there is no standardized rule for
- * a genre name, which results in an ambiguous definition of certain
- * genre, like Thriller and Horror.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Genre a CSV list of genre
- */
- int setGenre(const char* Genre);
- /**
- * Set the language
- *
- * This sets the language of a video. It is defined by RFC 1766.
- * A valid language definition is \em "de-DE" or \em "en-US".
- *
- * @see http://www.ietf.org/rfc/rfc1766.txt
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Language the language (RFC 1766)
- */
- int setLanguage(const char* Language);
- /**
- * Sets a relation URL
- *
- * This sets a CSV list of relation URLs, where to find additional
- * information about the movie. The URLs may not contain commas and they
- * must be properly escaped as in RFC 2396
- *
- * @see http://www.ietf.org/rfc/rfc2396.txt
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Relations a CSV list with relations
- */
- int setRelations(const char* Relations);
- /**
- * Sets the directors
- *
- * This sets a CSV list of directors.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Directors a CSV list of directors
- */
- int setDirectors(const char* Directors);
- /**
- * Sets the actors
- *
- * This sets a CSV list of actors in a video. This usually contain the main actors.
- * However, also other actors appearing in the video can be mentioned here.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Actors a CSV list of actors
- */
- int setActors(const char* Actors);
- /**
- * Sets the producers
- *
- * This sets a CSV list of producers of a video. These are the people who are
- * involed in the production of a video
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Producers a CSV list of producers
- */
- int setProducers(const char* Producers);
- /**
- * Sets the rating
- *
- * This is a rating, which can be used for parential control issues.
- *
- * @see http://en.wikipedia.org/wiki/Motion_picture_rating_system
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Rating the rating of a video
- */
- int setRating(const char* Rating);
- /******** Getter ********/
- /**
- * Get the genres
- *
- * This returns a CSV list of genre
- *
- * @return the genre of a video
- */
- const char* getGenre() const { return this->mGenre; }
- /**
- * Get the long description
- *
- * This returns the long description of a video
- *
- * @return the long description of a video
- */
- const char* getLongDescription() const { return this->mLongDescription; }
- /**
- * Get the description
- *
- * This returns the description of a video
- *
- * @return the description of a video
- */
- const char* getDescription() const { return this->mDescription; }
- /**
- * Get the publishers
- *
- * This returns a CSV list of publishers of the video
- *
- * @return a CSV list of publishers
- */
- const char* getPublishers() const { return this->mPublishers; }
- /**
- * Get the language
- *
- * This returns the language of the video
- *
- * @return the language
- */
- const char* getLanguage() const { return this->mLanguage; }
- /**
- * Get the relations
- *
- * This returns a CSV list of relation URLs.
- *
- * @return a CSV list of relation URLs
- */
- const char* getRelations() const { return this->mRelations; }
- /**
- * Get the actors
- *
- * This returns a CSV list of actors in the video
- *
- * @return a CSV list of actors
- */
- const char* getActors() const { return this->mActors; }
- /**
- * Get the producers
- *
- * This returns a CSV list of producers of a video
- *
- * @return a CSV list of producers
- */
- const char* getProducers() const { return this->mProducers; }
- /**
- * Get the directors
- *
- * This returns a CSV list of directors
- *
- * @return a CSV list of directors
- */
- const char* getDirectors() const { return this->mDirectors; }
- /**
- * Get the rating
- *
- * This returns the rating used for parental control.
- *
- * @return the rating of a video
- */
- const char* getRating() const { return this->mRating; }
-};
-
-/**
- * The UPnP class Movie
- *
- * This is a UPnP class Movie representation with all its properties.
- */
-class cUPnPClassMovie : public cUPnPClassVideoItem {
- friend class cMediaDatabase;
- friend class cUPnPObjectMediator;
- friend class cUPnPMovieMediator;
-protected:
- int mDVDRegionCode; ///< The Region code of the movie (0 - 8)
- cString mStorageMedium; ///< The storage medium where the movie is stored
- /**
- * Constructor of a movie
- *
- * This creates a new instance of a movie
- */
- cUPnPClassMovie();
-public:
- virtual ~cUPnPClassMovie();
- //virtual cString createDIDLFragment(cStringList* Filter);
- virtual cStringList* getPropertyList();
- virtual bool setProperty(const char* Property, const char* Value);
- virtual bool getProperty(const char* Property, char** Value) const;
- /******** Setter ********/
- /**
- * Sets the DVD region code
- *
- * For more information on this, see http://en.wikipedia.org/wiki/DVD_region_code
- *
- * The integer representation for \em ALL is 9.
- *
- * @see http://en.wikipedia.org/wiki/DVD_region_code
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param RegionCode the region code of this movie
- */
- int setDVDRegionCode(int RegionCode);
- /**
- * Sets the storage medium
- *
- * This will set the storage medium, where the movie resides. Valid media
- * are defined in \link common.h \endlink
- *
- * @see common.h
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param StorageMedium the medium where the movie is located
- */
- int setStorageMedium(const char* StorageMedium);
- /******** Getter ********/
- /**
- * Get the DVD region code
- *
- * This returns the DVD region code. For more information,
- * see http://en.wikipedia.org/wiki/DVD_region_code
- *
- * The integer representation for \em ALL is 9.
- *
- * @see http://en.wikipedia.org/wiki/DVD_region_code
- * @return the DVD region code
- */
- int getDVDRegionCode() const { return this->mDVDRegionCode; }
- /**
- * Get the storage medium
- *
- * This returns the storage medium, where the movie resides.
- *
- * @return the storage medium
- */
- const char* getStorageMedium() const { return this->mStorageMedium; }
-};
-
-/**
- * The UPnP class VideoBroadcast
- *
- * This is a UPnP class VideoBroadcast representation with all its properties.
- */
-class cUPnPClassVideoBroadcast : public cUPnPClassVideoItem {
- friend class cMediaDatabase;
- friend class cUPnPObjectMediator;
- friend class cUPnPVideoBroadcastMediator;
-protected:
- cString mIcon; ///< The channel icon of the channel
- cString mRegion; ///< The region where the channel can be received
- int mChannelNr; ///< The channel number
- cString mChannelName; ///< The channel name or provider name
- /**
- * Constructor of a video broadcast
- *
- * This creates a new instance of a video broadcast
- */
- cUPnPClassVideoBroadcast();
-public:
- virtual ~cUPnPClassVideoBroadcast();
- //virtual cString createDIDLFragment(cStringList* Filter);
- virtual cStringList* getPropertyList();
- virtual bool setProperty(const char* Property, const char* Value);
- virtual bool getProperty(const char* Property, char** Value) const;
- /******** Setter ********/
- /**
- * Set the channel icon
- *
- * This sets the channel icon of this channel. The resource must be a valid
- * URI which can be obtained via the internal webserver
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param IconURI the URI to the icon file
- */
- int setIcon(const char* IconURI);
- /**
- * Set the channel region
- *
- * This sets the region of a channel, where it can be received
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param Region the location where the channel can be received
- */
- int setRegion(const char* Region);
- /**
- * Set channel number
- *
- * This sets the channel number, so that it can be used for directly navigation
- * or channel up and down navigation respectively.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param ChannelNr the channel number
- */
- int setChannelNr(int ChannelNr);
- /**
- * Set the channel name
- *
- * This sets the channel name or the provider of the channel.
- *
- * @return returns
- * - \bc 0, if setting was successful
- * - \bc <0, otherwise
- * @param ChannelName the channel name
- */
- int setChannelName(const char* ChannelName);
- /******** Getter ********/
- /**
- * Get the channel icon
- *
- * This returns the channel icon of the channel.
- *
- * @return the channel icon
- */
- const char* getIcon() const { return this->mIcon; }
- /**
- * Get the region
- *
- * This returns the region, where the channel can be received
- *
- * @return the channel region
- */
- const char* getRegion() const { return this->mRegion; }
- /**
- * Get the channel number
- *
- * This returns the channel number
- *
- * @return the channel number
- */
- int getChannelNr() const { return this->mChannelNr; }
- /**
- * Get the channel name
- *
- * This returns the channel name or provider name respectively
- *
- * @return the channel name
- */
- const char* getChannelName() const { return this->mChannelName; }
-};
-
-/**
- * Mediator interface
- *
- * This is an interface for mediators used to communicate with the database.
- * A mediator is applied to get, create, save or delete an UPnP object.
- */
-class cMediatorInterface {
-public:
- virtual ~cMediatorInterface(){};
- /**
- * Creates an object
- *
- * This creates a new UPnP object with the specific title and the restriction.
- *
- * @return the newly created object
- * @param Title the title of that object
- * @param Restricted the restriction of the object
- */
- virtual cUPnPClassObject* createObject(const char* Title, bool Restricted) = 0;
- /**
- * Get an object
- *
- * Retrieves a UPnP object from the database and stores its information in the
- * object. The object is obtained via its object ID.
- *
- * @return the object, found in the database
- * @param ID the object ID
- */
- virtual cUPnPClassObject* getObject(cUPnPObjectID ID) = 0;
- /**
- * Saves the object
- *
- * This saves the object in the database by updating the values in the database
- * with those in the object.
- *
- * @return returns
- * - \bc <0, in case of an error
- * - \bc 0, otherwise
- * @param Object the object to be saved
- */
- virtual int saveObject(cUPnPClassObject* Object) = 0;
- /**
- * Deletes the object
- *
- * This deletes the object in the database by removing all its children and then
- * deleting the contents from the database
- *
- * @return returns
- * - \bc <0, in case of an error
- * - \bc 0, otherwise
- * @param Object the object to be deleted
- */
- virtual int deleteObject(cUPnPClassObject* Object) = 0;
- /**
- * Clears the object
- *
- * This clears the object, i.e. all its children will be removed and deleted
- * from the database
- *
- * @return returns
- * - \bc <0, in case of an error
- * - \bc 0, otherwise
- * @param Object the object to be cleared
- */
- virtual int clearObject(cUPnPClassObject* Object) = 0;
-};
-
-typedef std::map<const char*, cMediatorInterface*, strCmp> tMediatorMap;
-
-/**
- * The object factory
- *
- * This factory can create, delete, clear or save UPnP objects. It uses mediators
- * to communicate with the persistance database to load or persist the objects.
- *
- * If a new type of object shall be stored in the database an according mediator
- * is needed, which knows the internal database structure. It must implement the
- * cMediatorInterface class to work with this factory.
- */
-class cUPnPObjectFactory {
-private:
- static cUPnPObjectFactory* mInstance;
- cSQLiteDatabase* mDatabase;
- tMediatorMap mMediators;
- cMediatorInterface* findMediatorByID(cUPnPObjectID ID);
- cMediatorInterface* findMediatorByClass(const char* Class);
- cUPnPObjectFactory();
-public:
- /**
- * Return the instance of the factory
- *
- * This returns the instance of the factory. When the media database is
- * initialized successfully, it usally has all known mediators already
- * registered.
- *
- * @return the instance of the factory
- */
- static cUPnPObjectFactory* getInstance();
- /**
- * Register a mediator
- *
- * This registers a new mediator by the associated class. The mediator
- * must implement the cMediatorInterface class to be used with this
- * factory.
- *
- * @param UPnPClass the class of which the mediator is associated to
- * @param Mediator the mediator itself
- */
- void registerMediator(const char* UPnPClass, cMediatorInterface* Mediator);
- /**
- * Unregisters a mediator
- *
- * This unregisters a mediator if it is not needed anylonger. If the optional
- * parameter \c freeMediator is set, the object instance will be free'd after
- * removing it from the list.
- *
- * @param UPnPClass the class of the associated mediator
- * @param freeMediator flag to indicate if the mediator shall be free'd after removing
- */
- void unregisterMediator(const char* UPnPClass, bool freeMediator=true);
- /**
- * @copydoc cMediatorInterface::createObject(const char* Title, bool Restricted)
- *
- * @param UPnPClass the class of the new object
- */
- cUPnPClassObject* createObject(const char* UPnPClass, const char* Title, bool Restricted=true);
- /*! @copydoc cMediatorInterface::getObject(cUPnPObjectID ID) */
- cUPnPClassObject* getObject(cUPnPObjectID ID);
- /*! @copydoc cMediatorInterface::saveObject(cUPnPClassObject* Object) */
- int saveObject(cUPnPClassObject* Object);
- /*! @copydoc cMediatorInterface::deleteObject(cUPnPClassObject* Object) */
- int deleteObject(cUPnPClassObject* Object);
- /*! @copydoc cMediatorInterface::clearObject(cUPnPClassObject* Object) */
- int clearObject(cUPnPClassObject* Object);
-};
-
-class cMediaDatabase;
-
-/**
- * Object Mediator
- *
- * This is the interface between the objects and the database. It is possible to
- * create new objects, stores objects in the database as well as removing them from
- * it.
- */
-class cUPnPObjectMediator : public cMediatorInterface {
-protected:
- cSQLiteDatabase* mDatabase; ///< the SQLite 3 database wrapper
- cMediaDatabase* mMediaDatabase; ///< the media database
- /**
- * Constructor of object mediator
- *
- * This constructs a new object mediator. This is actually not allowed because
- * it is prohibited to create instances of the UPnP class Object
- */
- cUPnPObjectMediator(
- cMediaDatabase* MediaDatabase ///< the media database
- );
- /**
- * Initializes an object
- *
- * This initializes an object, which means, that it will be created in the database with
- * the required details.
- *
- * @return returns
- * - \bc <0, in case of an error
- * - \bc 0, otherwise
- */
- virtual int initializeObject(
- cUPnPClassObject* Object, ///< the object to be initialized
- const char* Class, ///< the class of the object
- const char* Title, ///< the title of the object
- bool Restricted ///< restriction of the object
- );
- /**
- * Store the object in the database
- *
- * This stores the information of an object in the database
- *
- * @return returns
- * - \bc <0, in case of an error
- * - \bc 0, otherwise
- * @param Object the object to be saved
- */
- virtual int objectToDatabase(cUPnPClassObject* Object);
- /**
- * Loads an object from database
- *
- * This loads an object from the database
- *
- * @return returns
- * - \bc <0, in case of an error
- * - \bc 0, otherwise
- * @param Object the object to be loaded
- * @param ID the object ID of that object
- */
- virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
-public:
- virtual ~cUPnPObjectMediator();
- /*! @copydoc cMediatorInterface::createObject(const char* Title, bool Restricted) */
- virtual cUPnPClassObject* createObject(const char* Title, bool Restricted);
- /*! @copydoc cMediatorInterface::getObject(cUPnPObjectID ID) */
- virtual cUPnPClassObject* getObject(cUPnPObjectID ID);
- /*! @copydoc cMediatorInterface::saveObject(cUPnPClassObject* Object) */
- virtual int saveObject(cUPnPClassObject* Object);
- /*! @copydoc cMediatorInterface::deleteObject(cUPnPClassObject* Object) */
- virtual int deleteObject(cUPnPClassObject* Object);
- /*! @copydoc cMediatorInterface::clearObject(cUPnPClassObject* Object) */
- virtual int clearObject(cUPnPClassObject* Object);
-};
-
-/**
- * Item Mediator
- *
- * This is the interface between the objects and the database. It is possible to
- * create new objects, stores objects in the database as well as removing them from
- * it.
- */
-class cUPnPItemMediator : public cUPnPObjectMediator {
-protected:
- /*! @copydoc cUPnPObjectMediator::objectToDatabase(cUPnPClassObject* Object) */
- virtual int objectToDatabase(cUPnPClassObject* Object);
- /*! @copydoc cUPnPObjectMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID) */
- virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
-public:
- /**
- * Constructor of item mediator
- *
- * This creates a new item mediator with which it is possible to create new
- * instances of Item objects.
- *
- * @param MediaDatabase the media database
- */
- cUPnPItemMediator(cMediaDatabase* MediaDatabase);
- virtual ~cUPnPItemMediator(){};
- /*! @copydoc cUPnPObjectMediator::createObject(const char* Title, bool Restricted) */
- virtual cUPnPClassItem* createObject(const char* Title, bool Restricted);
- /*! @copydoc cUPnPObjectMediator::getObject(cUPnPObjectID ID) */
- virtual cUPnPClassItem* getObject(cUPnPObjectID ID);
-};
-
-/**
- * VideoItem Mediator
- *
- * This is the interface between the objects and the database. It is possible to
- * create new objects, stores objects in the database as well as removing them from
- * it.
- */
-class cUPnPVideoItemMediator : public cUPnPItemMediator {
-protected:
- virtual int objectToDatabase(cUPnPClassObject* Object);
- virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
-public:
- /**
- * Constructor of videoitem mediator
- *
- * This creates a new videoitem mediator with which it is possible to create new
- * instances of VideoItem objects.
- *
- * @param MediaDatabase the media database
- */
- cUPnPVideoItemMediator(cMediaDatabase* MediaDatabase);
- virtual ~cUPnPVideoItemMediator(){};
- virtual cUPnPClassVideoItem* createObject(const char* Title, bool Restricted);
- virtual cUPnPClassVideoItem* getObject(cUPnPObjectID ID);
-};
-
-/**
- * VideoBroadcast Mediator
- *
- * This is the interface between the objects and the database. It is possible to
- * create new objects, stores objects in the database as well as removing them from
- * it.
- */
-class cUPnPVideoBroadcastMediator : public cUPnPVideoItemMediator {
-protected:
- virtual int objectToDatabase(cUPnPClassObject* Object);
- virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
-public:
- /**
- * Constructor of video broadcast mediator
- *
- * This creates a new video broadcast mediator with which it is possible to create new
- * instances of VideoBroadcast objects.
- *
- * @param MediaDatabase the media database
- */
- cUPnPVideoBroadcastMediator(cMediaDatabase* MediaDatabase);
- virtual ~cUPnPVideoBroadcastMediator(){};
- virtual cUPnPClassVideoBroadcast* createObject(const char* Title, bool Restricted);
- virtual cUPnPClassVideoBroadcast* getObject(cUPnPObjectID ID);
-};
-
-/**
- * Movie Mediator
- *
- * This is the interface between the objects and the database. It is possible to
- * create new objects, stores objects in the database as well as removing them from
- * it.
- */
-class cUPnPMovieMediator : public cUPnPVideoItemMediator {
-protected:
- virtual int objectToDatabase(cUPnPClassObject* Object);
- virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
-public:
- /**
- * Constructor of movie mediator
- *
- * This creates a new movie mediator with which it is possible to create new
- * instances of Movie objects.
- *
- * @param MediaDatabase the media database
- */
- cUPnPMovieMediator(cMediaDatabase* MediaDatabase);
- virtual ~cUPnPMovieMediator(){};
- virtual cUPnPClassMovie* createObject(const char* Title, bool Restricted);
- virtual cUPnPClassMovie* getObject(cUPnPObjectID ID);
-};
-
-/**
- * Container Mediator
- *
- * This is the interface between the objects and the database. It is possible to
- * create new objects, stores objects in the database as well as removing them from
- * it.
- */
-class cUPnPContainerMediator : public cUPnPObjectMediator {
-protected:
- virtual int objectToDatabase(cUPnPClassObject* Object);
- virtual int databaseToObject(cUPnPClassObject* Object, cUPnPObjectID ID);
-public:
- /**
- * Constructor of container mediator
- *
- * This creates a new container mediator with which it is possible to create new
- * instances of Container objects.
- *
- * @param MediaDatabase the media database
- */
- cUPnPContainerMediator(cMediaDatabase* MediaDatabase);
- virtual ~cUPnPContainerMediator(){};
- virtual cUPnPClassContainer* createObject(const char* Title, bool Restricted);
- virtual cUPnPClassContainer* getObject(cUPnPObjectID ID);
-};
-
-#endif /* _OBJECT_H */
-
diff --git a/database/resources.cpp b/database/resources.cpp
index 646560a..d0ca481 100644
--- a/database/resources.cpp
+++ b/database/resources.cpp
@@ -7,10 +7,49 @@
#include <string.h>
#include <vdr/channels.h>
-#include "../upnpcomponents/dlna.h"
+#include "upnp/dlna.h"
#include <vdr/tools.h>
#include "resources.h"
-#include "../misc/avdetector.h"
+#include "avdetector.h"
+
+cUPnPResource::cUPnPResource(){
+ this->mBitrate = 0;
+ this->mBitsPerSample = 0;
+ this->mColorDepth = 0;
+ this->mDuration = NULL;
+ this->mImportURI = NULL;
+ this->mNrAudioChannels = 0;
+ this->mProtocolInfo = NULL;
+ this->mResolution = NULL;
+ this->mResource = NULL;
+ this->mResourceID = 0;
+ this->mSampleFrequency = 0;
+ this->mSize = 0;
+ this->mContentType = NULL;
+}
+
+time_t cUPnPResource::getLastModification() const {
+ time_t Time;
+ const cRecording* Recording;
+ const cEvent* Event;
+ switch(this->mResourceType){
+ case UPNP_RESOURCE_CHANNEL:
+ case UPNP_RESOURCE_URL:
+ Time = time(NULL);
+ break;
+ case UPNP_RESOURCE_RECORDING:
+ Recording = Recordings.GetByName(this->mResource);
+ Event = (Recording)?Recording->Info()->GetEvent():NULL;
+ Time = (Event)?Event->EndTime():time(NULL);
+ break;
+ case UPNP_RESOURCE_FILE:
+ //break;
+ default:
+ ERROR("Invalid resource type. This resource might be broken");
+ Time = -1;
+ }
+ return Time;
+}
cUPnPResources* cUPnPResources::mInstance = NULL;
@@ -125,7 +164,7 @@ int cUPnPResources::createFromRecording(cUPnPClassVideoItem* Object, cRecording*
Resource->mImportURI = NULL;
Resource->mColorDepth = 0;
Object->addResource(Resource);
- this->mMediator->saveResource(Resource);
+ this->mMediator->saveResource(Object, Resource);
this->mResources->Add(Resource, Resource->getID());
delete Detector;
@@ -178,7 +217,7 @@ int cUPnPResources::createFromChannel(cUPnPClassVideoBroadcast* Object, cChannel
Resource->mImportURI = NULL;
Resource->mColorDepth = 0;
Object->addResource(Resource);
- this->mMediator->saveResource(Resource);
+ this->mMediator->saveResource(Object, Resource);
this->mResources->Add(Resource, Resource->getID());
delete Detector;
@@ -208,10 +247,7 @@ cUPnPResource* cUPnPResourceMediator::getResource(unsigned int ResourceID){
}
cString Column = NULL, Value = NULL;
while(Row->fetchColumn(&Column, &Value)){
- if(!strcasecmp(SQLITE_COL_OBJECTID, Column)){
- Resource->mObjectID = *Value?atoi(Value):-1;
- }
- else if(!strcasecmp(SQLITE_COL_PROTOCOLINFO, Column)){
+ if(!strcasecmp(SQLITE_COL_PROTOCOLINFO, Column)){
Resource->mProtocolInfo = Value;
}
else if(!strcasecmp(SQLITE_COL_RESOURCE, Column)){
@@ -251,7 +287,7 @@ cUPnPResource* cUPnPResourceMediator::getResource(unsigned int ResourceID){
return Resource;
}
-int cUPnPResourceMediator::saveResource(cUPnPResource* Resource){
+int cUPnPResourceMediator::saveResource(cUPnPClassObject* Object, cUPnPResource* Resource){
cString Format = "UPDATE %s SET %s=%Q,"
"%s=%Q,"
@@ -270,7 +306,7 @@ int cUPnPResourceMediator::saveResource(cUPnPResource* Resource){
if(this->mDatabase->execStatement(Format,
SQLITE_TABLE_RESOURCES,
- SQLITE_COL_OBJECTID, *Resource->mObjectID,
+ SQLITE_COL_OBJECTID, *Object->getID(),
SQLITE_COL_PROTOCOLINFO, *Resource->mProtocolInfo,
SQLITE_COL_RESOURCE, *Resource->mResource,
SQLITE_COL_SIZE, Resource->mSize,
@@ -310,7 +346,6 @@ cUPnPResource* cUPnPResourceMediator::newResource(cUPnPClassObject* Object, int
return NULL;
}
Resource->mResourceID = (unsigned int)this->mDatabase->getLastInsertRowID();
- Resource->mObjectID = Object->getID();
Resource->mResource = ResourceFile;
Resource->mProtocolInfo = ProtocolInfo;
Resource->mContentType = ContentType;
diff --git a/database/resources.h b/database/resources.h
deleted file mode 100644
index 8f7fa86..0000000
--- a/database/resources.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * File: resources.h
- * Author: savop
- *
- * Created on 30. September 2009, 15:17
- */
-
-#ifndef _RESOURCES_H
-#define _RESOURCES_H
-
-#include "database.h"
-#include "object.h"
-#include <vdr/channels.h>
-#include <vdr/recording.h>
-
-class cUPnPResourceMediator;
-class cMediaDatabase;
-
-/**
- * The resource manager
- *
- * This manages the resources in an internal cache. It may create a new resource
- * from a channel, a recording or a custom file.
- */
-class cUPnPResources {
-private:
- cHash<cUPnPResource>* mResources;
- static cUPnPResources* mInstance;
- cUPnPResourceMediator* mMediator;
- cSQLiteDatabase* mDatabase;
- cUPnPResources();
-public:
- /**
- * Fill object with its resources
- *
- * This will load all the resources from the database, which are associated
- * to the given object
- *
- * @param Object the object, which shall be filled
- * @return returns
- * - \bc 0, if loading was successful
- * - \bc <0, otherwise
- */
- int getResourcesOfObject(cUPnPClassObject* Object);
- /**
- * Loads all resources from database
- *
- * This loads all resources from the database into the internal cache.
- *
- * @return returns
- * - \bc 0, if loading was successful
- * - \bc <0, otherwise
- */
- int loadResources();
- /*! @copydoc cUPnPResourceMediator::getResource */
- cUPnPResource* getResource(unsigned int ResourceID);
- virtual ~cUPnPResources();
- /**
- * Get the instance of the resource manager
- *
- * This returns the instance of the resource manager.
- *
- * @return the instance of the manager
- */
- static cUPnPResources* getInstance();
- /**
- * Create resource from channel
- *
- * This creates a new resource from the given channel. It determines what
- * kind of video stream it is and further details if available. It stores
- * the resource in the database after creating it.
- *
- * @param Object the videoBroadcast item which holds the resource
- * @param Channel the VDR TV channel
- * @return returns
- * - \bc 0, if loading was successful
- * - \bc <0, otherwise
- */
- int createFromChannel(cUPnPClassVideoBroadcast* Object, cChannel* Channel);
- /**
- * Create resource from recording
- *
- * This creates a new resource from the given recording. It determines what
- * kind of video stream it is and further details if available. It stores
- * the resource in the database after creating it.
- *
- * @param Object the videoItem item which holds the resource
- * @param Recording the VDR TV recording
- * @return returns
- * - \bc 0, if loading was successful
- * - \bc <0, otherwise
- */
- int createFromRecording(cUPnPClassVideoItem* Object, cRecording* Recording);
- /**
- * Create resource from file
- *
- * This creates a new resource from the given file. It determines all available
- * information about the resource by analizing the content. It stores
- * the resource in the database after creating it.
- *
- * @param Object the item which holds the resource
- * @param File the file name
- * @return returns
- * - \bc 0, if loading was successful
- * - \bc <0, otherwise
- */
- int createFromFile(cUPnPClassItem* Object, cString File);
-};
-
-/**
- * The resource mediator
- *
- * This is another mediator which communicates with the database. It manages the
- * resources in the database
- */
-class cUPnPResourceMediator {
- friend class cUPnPResources;
-private:
- cSQLiteDatabase* mDatabase;
- cUPnPResourceMediator();
- unsigned int getNextResourceID();
-public:
- virtual ~cUPnPResourceMediator();
- /**
- * Get a resource by ID
- *
- * This returns a resource by its resource ID
- *
- * @param ResourceID the resource ID of the demanded resource
- * @return the requested resource
- */
- cUPnPResource* getResource(unsigned int ResourceID);
- /**
- * Saves the resource
- *
- * This updates the information in the database with those in the resource
- * object
- *
- * @param Resource the resource which shall be saved
- * @return returns
- * - \bc 0, if saving was successful
- * - \bc <0, if an error occured
- */
- int saveResource(cUPnPResource* Resource);
- /**
- * Create new resource
- *
- * This creates a new resource and stores the skeleton in the database. The
- * newly created resource will only contain all required information.
- *
- * @param Object the Object which will hold the resource
- * @param ResourceType the type of the resource
- * @param ResourceFile the file or URL, where the resource can be located
- * @param ContentType the mime type of the content
- * @param ProtocolInfo the protocol information of the resource
- * @return the newly created resource
- */
- cUPnPResource* newResource(cUPnPClassObject* Object, int ResourceType, cString ResourceFile, cString ContentType, cString ProtocolInfo);
-};
-
-#endif /* _RESOURCES_H */
-