summaryrefslogtreecommitdiff
path: root/database
diff options
context:
space:
mode:
authorDenis Loh <denis.loh@gmail.com>2009-11-19 12:21:55 +0100
committerDenis Loh <denis.loh@gmail.com>2009-11-19 12:21:55 +0100
commit2d245fcabb385347359759de8e6c40ce16e43cab (patch)
treeee6d718e2be089c50a1f0f6ca6fb89cc3c3161b0 /database
parent4510b4d123a4f62c49c55fa517f15df4fa90ebec (diff)
downloadvdr-plugin-upnp-2d245fcabb385347359759de8e6c40ce16e43cab.tar.gz
vdr-plugin-upnp-2d245fcabb385347359759de8e6c40ce16e43cab.tar.bz2
Added options for verbosity level and auto detect settings
Diffstat (limited to 'database')
-rw-r--r--database/database.cpp15
-rw-r--r--database/database.h347
-rw-r--r--database/metadata.cpp88
-rw-r--r--database/metadata.h149
-rw-r--r--database/object.cpp112
-rw-r--r--database/object.h1420
-rw-r--r--database/resources.cpp14
-rw-r--r--database/resources.h111
8 files changed, 1988 insertions, 268 deletions
diff --git a/database/database.cpp b/database/database.cpp
index b3d11b2..e47dcbf 100644
--- a/database/database.cpp
+++ b/database/database.cpp
@@ -46,9 +46,7 @@ int cSQLiteDatabase::exec(const char* Statement){
return -1;
}
this->mRows = new cRows;
-#ifdef SQLITE_PRINT_STATEMENTS
- MESSAGE("SQLite: %s", Statement);
-#endif
+ MESSAGE(VERBOSE_SQL_STATEMENTS,"SQLite: %s", Statement);
if(sqlite3_exec(this->mDatabase, Statement, cSQLiteDatabase::getResultRow, (cSQLiteDatabase*)this, &Error)!=SQLITE_OK){
ERROR("Database error: %s", Error);
ERROR("Statement was: %s", Statement);
@@ -143,13 +141,12 @@ bool cRow::fetchColumn(cString* Column, cString* Value){
return ret;
}
+
bool cRow::fetchColumn(char** Column, char** Value){
if(currentCol>=this->ColCount){
return false;
}
- #ifdef SQLITE_PRINT_FETCHES
- MESSAGE("Fetching column %s='%s' (%d/%d)", this->Columns[currentCol], this->Values[currentCol], currentCol+1, this->ColCount);
- #endif
+ MESSAGE(VERBOSE_SQL_FETCHES,"Fetching column %s='%s' (%d/%d)", this->Columns[currentCol], this->Values[currentCol], currentCol+1, this->ColCount);
*Column = strdup0(this->Columns[currentCol]);
if(this->Values[currentCol]){
*Value = strcasecmp(this->Values[currentCol],"NULL")?strdup(this->Values[currentCol]):NULL;
@@ -169,7 +166,7 @@ int cSQLiteDatabase::initialize(){
sqlite3_close(this->mDatabase);
return -1;
}
- MESSAGE("Database file %s opened.", *File);
+ MESSAGE(VERBOSE_SDK,"Database file %s opened.", *File);
if(this->initializeTables()){
ERROR("Error while creating tables");
return -1;
@@ -191,17 +188,19 @@ void cSQLiteDatabase::startTransaction(){
}
}
this->execStatement("BEGIN TRANSACTION");
- MESSAGE("Start new transaction");
+ MESSAGE(VERBOSE_SQL,"Start new transaction");
this->mActiveTransaction = true;
}
void cSQLiteDatabase::commitTransaction(){
this->execStatement("COMMIT TRANSACTION");
+ MESSAGE(VERBOSE_SQL,"Commited transaction");
this->mActiveTransaction = false;
}
void cSQLiteDatabase::rollbackTransaction(){
this->execStatement("ROLLBACK TRANSACTION");
+ MESSAGE(VERBOSE_SQL,"Rolled back transaction");
this->mActiveTransaction = false;
}
diff --git a/database/database.h b/database/database.h
index 041772e..5bb595f 100644
--- a/database/database.h
+++ b/database/database.h
@@ -12,8 +12,6 @@
#include <vdr/tools.h>
#include "../common.h"
-#define SQLITE_PRINT_STATEMENTS
-#define SQLITE_PRINT_FETCHES
#define SQLITE_CASCADE_DELETES
#define PK_OBJECTS TOSTRING(1)
@@ -144,7 +142,7 @@
"FOR EACH ROW BEGIN "\
"SELECT CASE "\
"WHEN ("\
- "((SELECT " SQLITE_COL_OBJECTID " FROM " TableA " "\
+ "((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 "\
@@ -238,11 +236,11 @@
#define SQLITE_DELETE_PARENT_TRIGGER SQLITE_DELETE_REFERENCE_TRIGGER(SQLITE_TABLE_OBJECTS, SQLITE_COL_PARENTID)
#endif
- /**********************************************\
- * *
- * Primary keys *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Primary keys *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_PRIMARY_KEYS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_PRIMARY_KEYS \
@@ -274,11 +272,11 @@
"UPDATE " SQLITE_TABLE_PRIMARY_KEYS " SET Key=Key+1 WHERE KeyID=" PK_OBJECTS "; "\
"END;"
- /**********************************************\
- * *
- * System settings *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* System settings *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_SYSTEM "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_SYSTEM " "\
@@ -294,11 +292,11 @@
"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 *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Fast item finder *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_ITEMFINDER "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_ITEMFINDER " "\
@@ -310,11 +308,11 @@
#define SQLITE_TRIGGER_D_OBJECTS_ITEMFINDER SQLITE_DELETE_TRIGGER(SQLITE_TABLE_OBJECTS,\
SQLITE_TABLE_ITEMFINDER)
- /**********************************************\
- * *
- * Objects *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Objects *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_OBJECTS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_OBJECTS \
@@ -369,11 +367,11 @@
SQLITE_COL_PARENTID " must uniquely be -1') "\
"END; END;"
- /**********************************************\
- * *
- * Items *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Items *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_ITEMS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_ITEMS \
@@ -403,11 +401,11 @@
#define SQLITE_TRIGGER_D_ITEMS_ITEMS SQLITE_DELETE_REFERENCE_TRIGGER(SQLITE_TABLE_ITEMS, SQLITE_COL_REFERENCEID)
- /**********************************************\
- * *
- * Containers *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Containers *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_CONTAINER "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_CONTAINERS \
@@ -429,11 +427,11 @@
SQLITE_TABLE_CONTAINERS,\
UPNP_CLASS_CONTAINER)
- /**********************************************\
- * *
- * Video items *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Video items *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_VIDEOITEMS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_VIDEOITEMS \
@@ -461,11 +459,11 @@
SQLITE_TABLE_VIDEOITEMS, \
UPNP_CLASS_VIDEO)
- /**********************************************\
- * *
- * Audio items *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Audio items *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_AUDIOITEMS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_AUDIOITEMS \
@@ -488,11 +486,11 @@
SQLITE_TABLE_AUDIOITEMS, \
UPNP_CLASS_AUDIO)
- /**********************************************\
- * *
- * Image items *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Image items *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_IMAGEITEMS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_IMAGEITEMS \
@@ -517,11 +515,11 @@
SQLITE_TABLE_IMAGEITEMS, \
UPNP_CLASS_IMAGE)
- /**********************************************\
- * *
- * Video broadcasts *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Video broadcasts *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_VIDEOBROADCASTS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_VIDEOBROADCASTS \
@@ -543,11 +541,11 @@
SQLITE_TABLE_VIDEOBROADCASTS,\
UPNP_CLASS_VIDEOBC)
- /**********************************************\
- * *
- * Audio broadcasts *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Audio broadcasts *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_AUDIOBROADCASTS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_AUDIOBROADCASTS \
@@ -570,11 +568,11 @@
SQLITE_TABLE_AUDIOBROADCASTS,\
UPNP_CLASS_AUDIOBC)
- /**********************************************\
- * *
- * Movies *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Movies *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_MOVIES "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_MOVIES \
@@ -598,11 +596,11 @@
SQLITE_TABLE_MOVIES,\
UPNP_CLASS_MOVIE)
- /**********************************************\
- * *
- * Photos *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Photos *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_PHOTOS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_PHOTOS \
@@ -621,11 +619,11 @@
SQLITE_TABLE_PHOTOS,\
UPNP_CLASS_PHOTO)
- /**********************************************\
- * *
- * Albums *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Albums *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_ALBUMS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_ALBUMS \
@@ -651,11 +649,11 @@
SQLITE_TABLE_ALBUMS,\
UPNP_CLASS_ALBUM)
- /**********************************************\
- * *
- * Playlists *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Playlists *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_PLAYLISTS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_PLAYLISTS \
@@ -683,11 +681,11 @@
SQLITE_TABLE_PLAYLISTS,\
UPNP_CLASS_PLAYLISTCONT)
- /**********************************************\
- * *
- * Search classes *
- * *
- \**********************************************/
+/**********************************************\
+* *
+* Search classes *
+* *
+\**********************************************/
#define SQLITE_CREATE_TABLE_SEARCHCLASS "CREATE TABLE IF NOT EXISTS "\
SQLITE_TABLE_SEARCHCLASS \
@@ -798,6 +796,13 @@
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:
@@ -808,11 +813,50 @@ private:
cRow();
public:
virtual ~cRow();
+ /**
+ * Number of columns in this row
+ *
+ * @return the number of rows
+ */
int Count(){ return this->ColCount; }
- bool fetchColumn(cString* Column, cString* Value);
- bool fetchColumn(char** Column, char** 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(
+ 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:
@@ -820,9 +864,29 @@ private:
cRows();
public:
virtual ~cRows();
- bool fetchRow(cRow** Row);
+ /**
+ * 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:
@@ -839,17 +903,122 @@ private:
static int getResultRow(void* DB, int NumCols, char** Values, char** ColNames);
int exec(const char* Statement);
public:
- static const char* sprintf(const char* Format, ...);
+ /**
+ * 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; }
- int execStatement(const char* Statement, ...);
+ /**
+ * 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();
- void setAutoCommit(bool Commit=true){ this->mAutoCommit = Commit; }
+ /**
+ * 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 3316522..91c512f 100644
--- a/database/metadata.cpp
+++ b/database/metadata.cpp
@@ -44,7 +44,7 @@ cMediaDatabase::~cMediaDatabase(){
}
bool cMediaDatabase::init(){
- MESSAGE("Initializing...");
+ MESSAGE(VERBOSE_SDK,"Initializing...");
if(this->prepareDatabase()){
ERROR("Initializing of database failed.");
return false;
@@ -122,7 +122,7 @@ cUPnPObjectID cMediaDatabase::getNextObjectID(){
int cMediaDatabase::addFastFind(cUPnPClassObject* Object, const char* FastFind){
if(!Object || !FastFind){
- MESSAGE("Invalid fast find parameters");
+ MESSAGE(VERBOSE_OBJECTS,"Invalid fast find parameters");
return -1;
}
@@ -140,7 +140,7 @@ int cMediaDatabase::addFastFind(cUPnPClassObject* Object, const char* FastFind){
cUPnPClassObject* cMediaDatabase::getObjectByFastFind(const char* FastFind){
if(!FastFind) return NULL;
- MESSAGE("Try to find Object with identifier %s", FastFind);
+ MESSAGE(VERBOSE_OBJECTS,"Try to find Object with identifier %s", FastFind);
cString Column, Value;
if(this->mDatabase->execStatement("SELECT %s FROM %s WHERE %s=%Q",
SQLITE_COL_OBJECTID,
@@ -166,14 +166,14 @@ cUPnPClassObject* cMediaDatabase::getObjectByFastFind(const char* FastFind){
}
cUPnPClassObject* cMediaDatabase::getObjectByID(cUPnPObjectID ID){
- MESSAGE("Try to find Object with ID '%s'", *ID);
+ MESSAGE(VERBOSE_OBJECTS, "Try to find Object with ID '%s'", *ID);
cUPnPClassObject* Object;
if((Object = this->mObjects->Get((unsigned int)ID))){
- MESSAGE("Found cached object with ID '%s'", *ID);
+ MESSAGE(VERBOSE_OBJECTS, "Found cached object with ID '%s'", *ID);
}
else if((Object = this->mFactory->getObject(ID))){
//this->cacheObject(Object);
- MESSAGE("Found object with ID '%s' in database", *ID);
+ MESSAGE(VERBOSE_OBJECTS, "Found object with ID '%s' in database", *ID);
}
else {
ERROR("No object with such ID '%s'", *ID);
@@ -184,14 +184,14 @@ cUPnPClassObject* cMediaDatabase::getObjectByID(cUPnPObjectID ID){
void cMediaDatabase::cacheObject(cUPnPClassObject* Object){
if(this->mObjects->Get((unsigned int)Object->getID())==NULL){
- MESSAGE("Added %s to cache.", *Object->getID());
+ MESSAGE(VERBOSE_OBJECTS ,"Added %s to cache.", *Object->getID());
this->mObjects->Add(Object, (unsigned int)Object->getID());
}
}
int cMediaDatabase::prepareDatabase(){
if(this->getObjectByID(0)==NULL){
- MESSAGE("Creating database structure");
+ MESSAGE(VERBOSE_SDK, "Creating database structure");
cUPnPClassContainer* Root = (cUPnPClassContainer*)this->mFactory->createObject(UPNP_CLASS_CONTAINER, _(PLUGIN_SHORT_NAME));
Root->setID(0);
if(this->mFactory->saveObject(Root)) return -1;
@@ -248,7 +248,7 @@ int cMediaDatabase::prepareDatabase(){
}
int cMediaDatabase::loadChannels(){
- MESSAGE("Loading channels");
+ MESSAGE(VERBOSE_LIVE_TV ,"Loading channels");
cUPnPClassContainer* TV = (cUPnPClassContainer*)this->getObjectByID(3);
if(TV){
bool noResource = false;
@@ -262,7 +262,7 @@ int cMediaDatabase::loadChannels(){
bool inList = false;
tChannelID ChannelID = Channel->GetChannelID();
- MESSAGE("Determine if the channel %s is already listed", *ChannelID.ToString());
+ MESSAGE(VERBOSE_LIVE_TV, "Determine if the channel %s is already listed", *ChannelID.ToString());
cUPnPClassVideoBroadcast* ChannelItem = NULL;
ChannelItem = (cUPnPClassVideoBroadcast*)this->getObjectByFastFind(ChannelID.ToString());
@@ -271,18 +271,18 @@ int cMediaDatabase::loadChannels(){
if(!inList){
if(Channel->GroupSep()){
- MESSAGE("Skipping group '%s'", Channel->Name());
+ MESSAGE(VERBOSE_LIVE_TV, "Skipping group '%s'", Channel->Name());
// Skip channel groups
// Channel groups may be supported theoretically. However, DLNA states that a tuner needs
// a consecutive list of channels. A simple work-around may be a virtual tuner for each group.
}
else if(Channel->Vpid()==0){
// TODO: add radio support
- MESSAGE("Skipping radio '%s'", Channel->Name());
+ MESSAGE(VERBOSE_LIVE_TV, "Skipping radio '%s'", Channel->Name());
}
else {
noResource = false;
- MESSAGE("Adding channel '%s' ID:%s", Channel->Name(), *ChannelID.ToString());
+ MESSAGE(VERBOSE_LIVE_TV, "Adding channel '%s' ID:%s", Channel->Name(), *ChannelID.ToString());
ChannelItem = (cUPnPClassVideoBroadcast*)this->mFactory->createObject(UPNP_CLASS_VIDEOBC, Channel->Name());
ChannelItem->setChannelName(Channel->Name());
ChannelItem->setChannelNr(Channel->Number());
@@ -301,7 +301,7 @@ int cMediaDatabase::loadChannels(){
this->mFactory->deleteObject(ChannelItem);
return -1;
}
- MESSAGE("Successfuly added channel");
+ MESSAGE(VERBOSE_LIVE_TV, "Successfuly added channel");
}
else {
// Delete temporarily created object with no resource
@@ -310,7 +310,7 @@ int cMediaDatabase::loadChannels(){
}
}
else {
- MESSAGE("Skipping %s, already in database", Channel->Name());
+ MESSAGE(VERBOSE_LIVE_TV, "Skipping %s, already in database", Channel->Name());
}
}
}
@@ -318,7 +318,7 @@ int cMediaDatabase::loadChannels(){
}
int cMediaDatabase::loadRecordings(){
- MESSAGE("Loading recordings");
+ MESSAGE(VERBOSE_RECORDS, "Loading recordings");
cUPnPClassContainer* Records = (cUPnPClassContainer*)this->getObjectByID(4);
if(Records){
bool noResource = false;
@@ -330,7 +330,7 @@ int cMediaDatabase::loadRecordings(){
// Iterating the records
bool inList = false;
- MESSAGE("Determine if the channel %s is already listed", Recording->FileName());
+ MESSAGE(VERBOSE_RECORDS, "Determine if the channel %s is already listed", Recording->FileName());
cUPnPClassMovie *MovieItem = NULL;
@@ -342,7 +342,7 @@ int cMediaDatabase::loadRecordings(){
noResource = false;
const cRecordingInfo* RecInfo = Recording->Info();
- MESSAGE("Adding movie '%s' File name:%s", RecInfo->Title(), Recording->FileName());
+ MESSAGE(VERBOSE_RECORDS, "Adding movie '%s' File name:%s", RecInfo->Title(), Recording->FileName());
MovieItem = (cUPnPClassMovie*)this->mFactory->createObject(UPNP_CLASS_MOVIE, RecInfo->Title());
MovieItem->setDescription(RecInfo->ShortText());
@@ -366,7 +366,7 @@ int cMediaDatabase::loadRecordings(){
this->mFactory->deleteObject(MovieItem);
return -1;
}
- MESSAGE("Successfuly added movie");
+ MESSAGE(VERBOSE_RECORDS, "Successfuly added movie");
}
else {
// Delete temporarily created object with no resource
@@ -374,7 +374,7 @@ int cMediaDatabase::loadRecordings(){
}
}
else {
- MESSAGE("Skipping %s, already in Database", Recording->FileName());
+ MESSAGE(VERBOSE_RECORDS, "Skipping %s, already in Database", Recording->FileName());
}
}
}
@@ -386,7 +386,7 @@ void cMediaDatabase::Action(){
while(this->Running()){
if(cSchedules::Modified() >= LastEPGUpdate){
- MESSAGE("Schedule changed. Updating...");
+ MESSAGE(VERBOSE_EPG_UPDATES, "Schedule changed. Updating...");
updateChannelEPG();
LastEPGUpdate = cSchedules::Modified();
}
@@ -399,19 +399,19 @@ void cMediaDatabase::updateChannelEPG(){
cUPnPClassContainer* TV = (cUPnPClassContainer*)this->getObjectByID(3);
if(TV){
// Iterating channels
- MESSAGE("Getting schedule...");
+ MESSAGE(VERBOSE_EPG_UPDATES, "Getting schedule...");
cSchedulesLock SchedulesLock;
const cSchedules *Schedules = cSchedules::Schedules(SchedulesLock);
cList<cUPnPClassObject>* List = TV->getObjectList();
- MESSAGE("TV folder has %d items", List->Count());
+ MESSAGE(VERBOSE_EPG_UPDATES, "TV folder has %d items", List->Count());
for(cUPnPClassVideoBroadcast* ChannelItem = (cUPnPClassVideoBroadcast*)List->First();
ChannelItem;
ChannelItem = (cUPnPClassVideoBroadcast*)List->Next(ChannelItem)
){
- MESSAGE("Find channel by number %d", ChannelItem->getChannelNr());
+ MESSAGE(VERBOSE_EPG_UPDATES, "Find channel by number %d", ChannelItem->getChannelNr());
cChannel* Channel = Channels.GetByNumber(ChannelItem->getChannelNr());
- MESSAGE("Found channel with ID %s", *Channel->GetChannelID().ToString());
+ 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;
@@ -420,10 +420,10 @@ void cMediaDatabase::updateChannelEPG(){
time_t LastEPGChange = Event->StartTime();
time_t LastObjectChange = ChannelItem->modified();
- MESSAGE("Last event start: %s", ctime(&LastEPGChange));
- MESSAGE("Last object modification: %s", ctime(&LastObjectChange));
+ MESSAGE(VERBOSE_EPG_UPDATES, "Last event start: %s", ctime(&LastEPGChange));
+ MESSAGE(VERBOSE_EPG_UPDATES, "Last object modification: %s", ctime(&LastObjectChange));
if(LastEPGChange >= LastObjectChange){
- MESSAGE("Updating details");
+ MESSAGE(VERBOSE_EPG_UPDATES, "Updating details");
if(Event){
ChannelItem->setTitle(Event->Title()?Event->Title():Channel->Name());
@@ -439,11 +439,11 @@ void cMediaDatabase::updateChannelEPG(){
this->mFactory->saveObject(ChannelItem);
}
else {
- MESSAGE("Channel did not change");
+ MESSAGE(VERBOSE_EPG_UPDATES, "Channel did not change");
}
}
else {
- MESSAGE("No EPG data");
+ MESSAGE(VERBOSE_EPG_UPDATES, "No EPG data");
ChannelItem->setTitle(Channel->Name());
ChannelItem->setLongDescription(NULL);
ChannelItem->setDescription(NULL);
@@ -452,19 +452,27 @@ void cMediaDatabase::updateChannelEPG(){
}
}
-int cMediaDatabase::browse(cUPnPResultSet** Results, const char* ID, bool BrowseMetadata, const char* Filter, unsigned int Offset, unsigned int Count, const char* SortCriteria){
+int cMediaDatabase::browse(
+ OUT cUPnPResultSet** Results,
+ IN const char* ID,
+ IN bool BrowseMetadata,
+ IN const char* Filter,
+ IN unsigned int Offset,
+ IN unsigned int Count,
+ IN const char* SortCriteria
+){
*Results = new cUPnPResultSet;
(*Results)->mNumberReturned = 0;
(*Results)->mTotalMatches = 0;
(*Results)->mResult = NULL;
- MESSAGE("===== Browsing =====");
- MESSAGE("ID: %s", ID);
- MESSAGE("Browse %s", BrowseMetadata?"metadata":"children");
- MESSAGE("Filter: %s", Filter);
- MESSAGE("Offset: %d", Offset);
- MESSAGE("Count: %d", Count);
- MESSAGE("Sort: %s", SortCriteria);
+ MESSAGE(VERBOSE_DIDL, "===== Browsing =====");
+ MESSAGE(VERBOSE_DIDL, "ID: %s", ID);
+ MESSAGE(VERBOSE_DIDL, "Browse %s", BrowseMetadata?"metadata":"children");
+ MESSAGE(VERBOSE_DIDL, "Filter: %s", Filter);
+ MESSAGE(VERBOSE_DIDL, "Offset: %d", Offset);
+ MESSAGE(VERBOSE_DIDL, "Count: %d", Count);
+ MESSAGE(VERBOSE_DIDL, "Sort: %s", SortCriteria);
cUPnPObjectID ObjectID = atoi(ID);
@@ -498,7 +506,7 @@ int cMediaDatabase::browse(cUPnPResultSet** Results, const char* ID, bool Browse
if(SortCriterias){
for(cSortCrit* SortBy = SortCriterias->First(); SortBy ; SortBy = SortCriterias->Next(SortBy)){
- MESSAGE("Sorting by %s %s", SortBy->Property, SortBy->SortDescending?"ascending":"descending");
+ MESSAGE(VERBOSE_DIDL, "Sorting by %s %s", SortBy->Property, SortBy->SortDescending?"ascending":"descending");
Children->SortBy(SortBy->Property, SortBy->SortDescending);
}
}
@@ -507,7 +515,7 @@ int cMediaDatabase::browse(cUPnPResultSet** Results, const char* ID, bool Browse
if(Count==0) Count = Container->getChildCount();
while(Offset-- && (Child = Children->Next(Child))){}
for(; Count && Child ; Child = Children->Next(Child), Count--){
- MESSAGE("Appending %s to didl", Child->getTitle());
+ MESSAGE(VERBOSE_DIDL, "Appending %s to didl", Child->getTitle());
ixmlNode_appendChild(Root, Child->createDIDLFragment(DIDLDoc, FilterList));
(*Results)->mNumberReturned++;
}
diff --git a/database/metadata.h b/database/metadata.h
index 6e3732c..4868231 100644
--- a/database/metadata.h
+++ b/database/metadata.h
@@ -16,17 +16,25 @@
#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;
- int mTotalMatches;
- const char* mResult;
-};
-
-struct cSearchCriteria {
- const char* Property;
- bool Descending;
+ 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;
@@ -47,15 +55,130 @@ private:
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();
- int addFastFind(cUPnPClassObject* Object, const char* FastFind);
- cUPnPClassObject* getObjectByFastFind(const char* FastFind);
- cUPnPClassObject* getObjectByID(cUPnPObjectID ID);
- int browse(OUT cUPnPResultSet** Results, IN const char* ID, IN bool BrowseMetadata, IN const char* Filter = "*", IN unsigned int Offset = 0, IN unsigned int Count = 0, IN const char* SortCriteria = "");
- int search(OUT cUPnPResultSet** Results, IN const char* ID, IN const char* Search, IN const char* Filter = "*", IN unsigned int Offset = 0, IN unsigned int Count = 0, IN const char* SortCriteria = "");
+ /**
+ * 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 94d9415..f6875f9 100644
--- a/database/object.cpp
+++ b/database/object.cpp
@@ -150,7 +150,7 @@ void cUPnPClassObject::clearSortCriteria(){
}
int cUPnPClassObject::setID(cUPnPObjectID ID){
- MESSAGE("Set ID from %s to %s", *this->getID(),*ID);
+ MESSAGE(VERBOSE_MODIFICATIONS, "Set ID from %s to %s", *this->getID(),*ID);
if((int)ID < 0){
ERROR("Invalid object ID '%s'",*ID);
return -1;
@@ -162,7 +162,7 @@ int cUPnPClassObject::setID(cUPnPObjectID ID){
int cUPnPClassObject::setParent(cUPnPClassContainer* Parent){
if(Parent==NULL){
- MESSAGE("Object '%s' elected as root object", *this->getID());
+ MESSAGE(VERBOSE_MODIFICATIONS, "Object '%s' elected as root object", *this->getID());
}
// unregister from old parent
if(this->mParent && Parent != this->mParent){
@@ -316,7 +316,7 @@ bool cUPnPClassObject::setProperty(const char* Property, const char* Value){
}
int cUPnPClassObject::addResource(cUPnPResource* Resource){
- MESSAGE("Adding resource #%d", Resource->getID());
+ MESSAGE(VERBOSE_MODIFICATIONS, "Adding resource #%d", Resource->getID());
if(!Resource){
ERROR("No resource");
return -1;
@@ -374,10 +374,10 @@ bool cUPnPClassItem::setProperty(const char* Property, const char* Value){
IXML_Node* cUPnPClassItem::createDIDLFragment(IXML_Document* Document, cStringList* Filter){
this->mDIDLFragment = Document;
- MESSAGE("==(%s)= %s =====", *this->getID(), this->getTitle());
- MESSAGE("ParentID: %s", *this->getParentID());
- MESSAGE("Restricted: %s", this->isRestricted()?"1":"0");
- MESSAGE("Class: %s", this->getClass());
+ MESSAGE(VERBOSE_DIDL, "==(%s)= %s =====", *this->getID(), this->getTitle());
+ MESSAGE(VERBOSE_DIDL, "ParentID: %s", *this->getParentID());
+ MESSAGE(VERBOSE_DIDL, "Restricted: %s", this->isRestricted()?"1":"0");
+ MESSAGE(VERBOSE_DIDL, "Class: %s", this->getClass());
IXML_Node* Didl = ixmlNode_getFirstChild((IXML_Node*) this->mDIDLFragment);
@@ -404,13 +404,13 @@ IXML_Node* cUPnPClassItem::createDIDLFragment(IXML_Document* Document, cStringLi
// if(Filter==NULL || Filter->Find(UPNP_PROP_REFERENCEID)) ixmlAddProperty(this->mDIDLFragment, eItem, UPNP_PROP_REFERENCEID, *this->getReferenceID());
for(cUPnPResource* Resource = this->getResources()->First(); Resource; Resource = this->getResources()->Next(Resource)){
- MESSAGE("Resource: %s", Resource->getResource());
- MESSAGE("Protocolinfo: %s", Resource->getProtocolInfo());
+ MESSAGE(VERBOSE_DIDL, "Resource: %s", Resource->getResource());
+ MESSAGE(VERBOSE_DIDL, "Protocolinfo: %s", Resource->getProtocolInfo());
cString URLBase = cString::sprintf("http://%s:%d", UpnpGetServerIpAddress(), UpnpGetServerPort());
cString ResourceURL = cString::sprintf("%s%s/get?resId=%d", *URLBase, UPNP_DIR_SHARES, Resource->getID());
- MESSAGE("Resource-URI: %s", *ResourceURL);
+ MESSAGE(VERBOSE_DIDL, "Resource-URI: %s", *ResourceURL);
IXML_Element* eRes = ixmlDocument_createElement(this->mDIDLFragment, UPNP_PROP_RESOURCE);
IXML_Node* Res = ixmlDocument_createTextNode(this->mDIDLFragment, *ResourceURL);
@@ -451,10 +451,10 @@ cUPnPClassContainer::~cUPnPClassContainer(){
IXML_Node* cUPnPClassContainer::createDIDLFragment(IXML_Document* Document, cStringList* Filter){
this->mDIDLFragment = Document;
- MESSAGE("===(%s)= %s =====", *this->getID(), this->getTitle());
- MESSAGE("ParentID: %s", *this->getParentID());
- MESSAGE("Restricted: %s", this->isRestricted()?"1":"0");
- MESSAGE("Class: %s", this->getClass());
+ MESSAGE(VERBOSE_DIDL, "===(%s)= %s =====", *this->getID(), this->getTitle());
+ MESSAGE(VERBOSE_DIDL, "ParentID: %s", *this->getParentID());
+ MESSAGE(VERBOSE_DIDL, "Restricted: %s", this->isRestricted()?"1":"0");
+ MESSAGE(VERBOSE_DIDL, "Class: %s", this->getClass());
IXML_Node* Didl = ixmlNode_getFirstChild((IXML_Node*) this->mDIDLFragment);
IXML_Element* eItem = ixmlDocument_createElement(this->mDIDLFragment, "container");
@@ -521,7 +521,7 @@ bool cUPnPClassContainer::getProperty(const char* Property, char** Value) const
}
void cUPnPClassContainer::addObject(cUPnPClassObject* Object){
- MESSAGE("Adding object (ID:%s) to container (ID:%s)", *Object->getID(), *this->getID());
+ MESSAGE(VERBOSE_MODIFICATIONS, "Adding object (ID:%s) to container (ID:%s)", *Object->getID(), *this->getID());
Object->setParent(this);
this->mChildren->Add(Object);
this->mChildrenID->Add(Object, (unsigned int)Object->getID());
@@ -531,11 +531,11 @@ void cUPnPClassContainer::removeObject(cUPnPClassObject* Object){
this->mChildrenID->Del(Object, (unsigned int)Object->getID());
this->mChildren->Del(Object, false);
Object->mParent = NULL;
- MESSAGE("Removed object (ID:%s) from container (ID:%s)", *Object->getID(), *this->getID());
+ MESSAGE(VERBOSE_MODIFICATIONS, "Removed object (ID:%s) from container (ID:%s)", *Object->getID(), *this->getID());
}
cUPnPClassObject* cUPnPClassContainer::getObject(cUPnPObjectID ID) const {
- MESSAGE("Getting object (ID:%s)", *ID);
+ MESSAGE(VERBOSE_METADATA, "Getting object (ID:%s)", *ID);
if((int)ID < 0){
ERROR("Invalid object ID");
return NULL;
@@ -1011,9 +1011,9 @@ void cUPnPObjectFactory::registerMediator(const char* UPnPClass, cMediatorInterf
ERROR("Mediator is undefined");
return;
}
- MESSAGE("Registering mediator for class '%s'", UPnPClass);
+ MESSAGE(VERBOSE_SDK, "Registering mediator for class '%s'", UPnPClass);
this->mMediators[UPnPClass] = Mediator;
- MESSAGE("Now %d mediators registered", this->mMediators.size());
+ MESSAGE(VERBOSE_SDK, "Now %d mediators registered", this->mMediators.size());
return;
}
@@ -1027,10 +1027,10 @@ void cUPnPObjectFactory::unregisterMediator(const char* UPnPClass, bool freeMedi
ERROR("No such mediator found for class '%s'", UPnPClass);
return;
}
- MESSAGE("Unregistering mediator for class '%s'", UPnPClass);
+ MESSAGE(VERBOSE_SDK, "Unregistering mediator for class '%s'", UPnPClass);
this->mMediators.erase(MediatorIterator);
if(freeMediator) delete MediatorIterator->second;
- MESSAGE("Now %d mediators registered", this->mMediators.size());
+ MESSAGE(VERBOSE_SDK, "Now %d mediators registered", this->mMediators.size());
return;
}
@@ -1057,7 +1057,7 @@ cMediatorInterface* cUPnPObjectFactory::findMediatorByID(cUPnPObjectID ID){
cMediatorInterface* cUPnPObjectFactory::findMediatorByClass(const char* Class){
if(!Class){ ERROR("No class specified"); return NULL; }
- MESSAGE("Searching for mediator '%s' in %d mediators", Class, this->mMediators.size());
+ MESSAGE(VERBOSE_SQL, "Searching for mediator '%s' in %d mediators", Class, this->mMediators.size());
tMediatorMap::iterator MediatorIterator = this->mMediators.find(Class);
if(MediatorIterator==this->mMediators.end()){
ERROR("No matching mediator for class '%s'",Class);
@@ -1212,7 +1212,7 @@ cUPnPClassObject* cUPnPObjectMediator::getObject(cUPnPObjectID){ WARNING("Gettin
cUPnPClassObject* cUPnPObjectMediator::createObject(const char*, bool){ WARNING("Getting instance of class 'Object' forbidden"); return NULL; }
int cUPnPObjectMediator::objectToDatabase(cUPnPClassObject* Object){
- MESSAGE("Updating object #%s", *Object->getID());
+ MESSAGE(VERBOSE_MODIFICATIONS, "Updating object #%s", *Object->getID());
cString Format = "UPDATE %s SET %s WHERE %s='%s'";
//cString Format = "INSERT OR REPLACE INTO %s (%s) VALUES (%s);";
cString Set=NULL;
@@ -1261,41 +1261,47 @@ int cUPnPObjectMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObjectI
}
while(Row->fetchColumn(&Column, &Value)){
if(!strcasecmp(Column, SQLITE_COL_OBJECTID)){
- if(Object->setID(atoi(Value))){
+ if(!*Value || Object->setID(atoi(Value))){
ERROR("Error while setting object ID");
return -1;
}
this->mMediaDatabase->cacheObject(Object);
}
else if(!strcasecmp(Column, SQLITE_COL_PARENTID)){
- cUPnPObjectID RefID = atoi(Value);
- cUPnPClassContainer* ParentObject;
- if(RefID == -1){
- ParentObject = NULL;
+ if(*Value){
+ cUPnPObjectID RefID = atoi(Value);
+ cUPnPClassContainer* ParentObject;
+ if(RefID == -1){
+ ParentObject = NULL;
+ }
+ else {
+ ParentObject = (cUPnPClassContainer*)this->mMediaDatabase->getObjectByID(RefID);
+ if(!ParentObject){
+ ERROR("No such parent with ID '%s' found.",*RefID);
+ return -1;
+ }
+ }
+ Object->setParent(ParentObject);
}
else {
- ParentObject = (cUPnPClassContainer*)this->mMediaDatabase->getObjectByID(RefID);
- if(!ParentObject){
- ERROR("No such parent with ID '%s' found.",*RefID);
- return -1;
- }
+ ERROR("Invalid parent ID");
+ return -1;
}
- Object->setParent(ParentObject);
}
else if(!strcasecmp(Column, SQLITE_COL_CLASS)){
- if(Object->setClass(Value)){
+ if(!*Value || Object->setClass(Value)){
ERROR("Error while setting class");
return -1;
}
}
else if(!strcasecmp(Column, SQLITE_COL_TITLE)){
- if(Object->setTitle(Value)){
+ if(!*Value || Object->setTitle(Value)){
ERROR("Error while setting title");
return -1;
}
}
else if(!strcasecmp(Column, SQLITE_COL_RESTRICTED)){
- if(Object->setRestricted(atoi(Value)==1?true:false)){
+ if(!*Value || Object->setRestricted(atoi(Value)==1?true:false)){
ERROR("Error while setting restriction");
return -1;
}
@@ -1307,7 +1313,7 @@ int cUPnPObjectMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObjectI
}
}
else if(!strcasecmp(Column, SQLITE_COL_WRITESTATUS)){
- if(Object->setWriteStatus(atoi(Value))){
+ if(*Value && Object->setWriteStatus(atoi(Value))){
ERROR("Error while setting write status");
return -1;
}
@@ -1369,7 +1375,7 @@ int cUPnPItemMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObjectID
}
Rows = this->mDatabase->getResultRows();
if(!Rows->fetchRow(&Row)){
- MESSAGE("No item properties found");
+ MESSAGE(VERBOSE_SQL, "No item properties found");
return 0;
}
while(Row->fetchColumn(&Column, &Value)){
@@ -1393,14 +1399,14 @@ int cUPnPItemMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObjectID
}
cUPnPClassItem* cUPnPItemMediator::getObject(cUPnPObjectID ID){
- MESSAGE("Getting Item with ID '%s'",*ID);
+ MESSAGE(VERBOSE_METADATA, "Getting Item with ID '%s'",*ID);
cUPnPClassItem* Object = new cUPnPClassItem;
if(this->databaseToObject(Object, ID)) return NULL;
return Object;
}
cUPnPClassItem* cUPnPItemMediator::createObject(const char* Title, bool Restricted){
- MESSAGE("Creating Item '%s'",Title);
+ MESSAGE(VERBOSE_MODIFICATIONS, "Creating Item '%s'",Title);
cUPnPClassItem* Object = new cUPnPClassItem;
if(this->initializeObject(Object, UPNP_CLASS_ITEM, Title, Restricted)) return NULL;
return Object;
@@ -1468,7 +1474,7 @@ int cUPnPContainerMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObje
}
Rows = this->mDatabase->getResultRows();
if(!Rows->fetchRow(&Row)){
- MESSAGE("No item properties found");
+ MESSAGE(VERBOSE_SQL, "No item properties found");
return 0;
}
while(Row->fetchColumn(&Column, &Value)){
@@ -1532,14 +1538,14 @@ int cUPnPContainerMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObje
}
cUPnPClassContainer* cUPnPContainerMediator::createObject(const char* Title, bool Restricted){
- MESSAGE("Creating Container '%s'",Title);
+ MESSAGE(VERBOSE_MODIFICATIONS, "Creating Container '%s'",Title);
cUPnPClassContainer* Object = new cUPnPClassContainer;
if(this->initializeObject(Object, UPNP_CLASS_CONTAINER, Title, Restricted)) return NULL;
return Object;
}
cUPnPClassContainer* cUPnPContainerMediator::getObject(cUPnPObjectID ID){
- MESSAGE("Getting Container with ID '%s'",*ID);
+ MESSAGE(VERBOSE_METADATA, "Getting Container with ID '%s'",*ID);
cUPnPClassContainer* Object = new cUPnPClassContainer;
if(this->databaseToObject(Object, ID)) return NULL;
return Object;
@@ -1555,14 +1561,14 @@ cUPnPVideoItemMediator::cUPnPVideoItemMediator(cMediaDatabase* MediaDatabase) :
cUPnPItemMediator(MediaDatabase){}
cUPnPClassVideoItem* cUPnPVideoItemMediator::createObject(const char* Title, bool Restricted){
- MESSAGE("Creating Video item '%s'",Title);
+ MESSAGE(VERBOSE_MODIFICATIONS, "Creating Video item '%s'",Title);
cUPnPClassVideoItem* Object = new cUPnPClassVideoItem;
if(this->initializeObject(Object, UPNP_CLASS_VIDEO, Title, Restricted)) return NULL;
return Object;
}
cUPnPClassVideoItem* cUPnPVideoItemMediator::getObject(cUPnPObjectID ID){
- MESSAGE("Getting Video item with ID '%s'",*ID);
+ MESSAGE(VERBOSE_METADATA, "Getting Video item with ID '%s'",*ID);
cUPnPClassVideoItem* Object = new cUPnPClassVideoItem;
if(this->databaseToObject(Object, ID)) return NULL;
return Object;
@@ -1618,7 +1624,7 @@ int cUPnPVideoItemMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObje
}
Rows = this->mDatabase->getResultRows();
if(!Rows->fetchRow(&Row)){
- MESSAGE("No item properties found");
+ MESSAGE(VERBOSE_SQL, "No item properties found");
return 0;
}
while(Row->fetchColumn(&Column, &Value)){
@@ -1696,14 +1702,14 @@ cUPnPVideoBroadcastMediator::cUPnPVideoBroadcastMediator(cMediaDatabase* MediaDa
cUPnPVideoItemMediator(MediaDatabase){}
cUPnPClassVideoBroadcast* cUPnPVideoBroadcastMediator::createObject(const char* Title, bool Restricted){
- MESSAGE("Creating Video broadcast '%s'",Title);
+ MESSAGE(VERBOSE_MODIFICATIONS, "Creating Video broadcast '%s'",Title);
cUPnPClassVideoBroadcast* Object = new cUPnPClassVideoBroadcast;
if(this->initializeObject(Object, UPNP_CLASS_VIDEOBC, Title, Restricted)) return NULL;
return Object;
}
cUPnPClassVideoBroadcast* cUPnPVideoBroadcastMediator::getObject(cUPnPObjectID ID){
- MESSAGE("Getting Video broadcast with ID '%s'",*ID);
+ MESSAGE(VERBOSE_METADATA, "Getting Video broadcast with ID '%s'",*ID);
cUPnPClassVideoBroadcast* Object = new cUPnPClassVideoBroadcast;
if(this->databaseToObject(Object, ID)) return NULL;
return Object;
@@ -1753,7 +1759,7 @@ int cUPnPVideoBroadcastMediator::databaseToObject(cUPnPClassObject* Object, cUPn
}
Rows = this->mDatabase->getResultRows();
if(!Rows->fetchRow(&Row)){
- MESSAGE("No item properties found");
+ MESSAGE(VERBOSE_SQL, "No item properties found");
return 0;
}
while(Row->fetchColumn(&Column, &Value)){
@@ -1795,14 +1801,14 @@ cUPnPMovieMediator::cUPnPMovieMediator(cMediaDatabase* MediaDatabase) :
cUPnPVideoItemMediator(MediaDatabase){}
cUPnPClassMovie* cUPnPMovieMediator::createObject(const char* Title, bool Restricted){
- MESSAGE("Creating movie '%s'",Title);
+ MESSAGE(VERBOSE_MODIFICATIONS, "Creating movie '%s'",Title);
cUPnPClassMovie* Object = new cUPnPClassMovie;
if(this->initializeObject(Object, UPNP_CLASS_MOVIE, Title, Restricted)) return NULL;
return Object;
}
cUPnPClassMovie* cUPnPMovieMediator::getObject(cUPnPObjectID ID){
- MESSAGE("Getting movie with ID '%s'",*ID);
+ MESSAGE(VERBOSE_METADATA, "Getting movie with ID '%s'",*ID);
cUPnPClassMovie* Object = new cUPnPClassMovie;
if(this->databaseToObject(Object, ID)) return NULL;
return Object;
@@ -1850,7 +1856,7 @@ int cUPnPMovieMediator::databaseToObject(cUPnPClassObject* Object, cUPnPObjectID
}
Rows = this->mDatabase->getResultRows();
if(!Rows->fetchRow(&Row)){
- MESSAGE("No item properties found");
+ MESSAGE(VERBOSE_SQL, "No item properties found");
return 0;
}
while(Row->fetchColumn(&Column, &Value)){
diff --git a/database/object.h b/database/object.h
index a38098d..245a617 100644
--- a/database/object.h
+++ b/database/object.h
@@ -17,37 +17,112 @@
#include <vector>
#include <upnp/ixml.h>
+/**
+ * UPnP Object ID
+ *
+ * This is a UPnP Object ID representation.
+ */
struct cUPnPObjectID {
- int _ID;
+ int _ID; ///< The UPnP Object ID
+ /**
+ * Constructor
+ *
+ * Creates invalid ID
+ */
cUPnPObjectID():_ID(-1){}
- cUPnPObjectID(long ID){ _ID = (int)ID; }
- cUPnPObjectID(int ID){ _ID = ID; }
- cUPnPObjectID &operator=(long ID){ _ID = ID; return *this; }
- cUPnPObjectID &operator=(int ID){ _ID = ID; return *this; }
- cUPnPObjectID &operator=(const cUPnPObjectID& ID){ if(this != &ID){ _ID = ID._ID; } return *this; }
+ /**
+ * 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; }
- bool operator!=(long ID){ return _ID != ID; }
- bool operator==(long ID){ return _ID == ID; }
- bool operator!=(int ID){ return _ID != ID; }
- bool operator==(int ID){ return _ID == ID; }
- bool operator!=(const cUPnPObjectID& ID){ return *this == ID; }
- bool operator==(const cUPnPObjectID& ID){ return *this == ID; }
+ /** 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;
- bool includeDerived;
+ 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;
@@ -70,21 +145,137 @@ private:
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 size
+ *
+ * Returns the resource size or -1 if its unknown
+ *
+ * @return the resource size or -1 if unknown
+ */
unsigned long getSize() const { return this->mSize; }
+ /**
+ * 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;
+ /**
+ * 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; }
};
@@ -93,79 +284,398 @@ 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();
- void SortBy(const char* Property, bool Descending = false);
+ /**
+ * 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
+ bool mDeleted; // is this Objected marked as deleted, NOT used yet.
protected:
- time_t mLastModified;
- cUPnPObjectID mID; // The object ID
- cUPnPClassObject* mParent;
- 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;
- IXML_Document* mDIDLFragment;
- cString mSortCriteria;
- bool mSortDescending;
+ 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;
+ cUPnPClassItem* mReference; ///< The reference item
+ /**
+ * Constructor of an item
+ *
+ * This creates a new instance of an item
+ */
cUPnPClassItem();
public:
virtual ~cUPnPClassItem(){};
@@ -174,28 +684,78 @@ public:
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;
- tClassVector mSearchClasses;
- tClassVector mCreateClasses;
- bool mSearchable;
- unsigned int mUpdateID;
- cUPnPObjects* mChildren;
- cHash<cUPnPClassObject>* mChildrenID;
+ 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();
@@ -204,44 +764,231 @@ public:
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
- 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
+ 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();
@@ -250,36 +997,230 @@ public:
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;
- cString mStorageMedium;
+ 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();
@@ -288,22 +1229,75 @@ public:
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;
- cString mRegion;
- int mChannelNr;
- cString mChannelName;
+ 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();
@@ -312,29 +1306,166 @@ public:
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;
@@ -344,84 +1475,257 @@ private:
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;
- cMediaDatabase* mMediaDatabase;
- cUPnPObjectMediator(cMediaDatabase* MediaDatabase);
- virtual int initializeObject(cUPnPClassObject* Object, const char* Class, const char* Title, bool Restricted);
+ 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);
- virtual cUPnPClassObject* getObject(cUPnPObjectID);
+ /*! @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);
diff --git a/database/resources.cpp b/database/resources.cpp
index 7d01ceb..8f0dec4 100644
--- a/database/resources.cpp
+++ b/database/resources.cpp
@@ -75,11 +75,11 @@ int cUPnPResources::getResourcesOfObject(cUPnPClassObject* Object){
cUPnPResource* cUPnPResources::getResource(unsigned int ResourceID){
cUPnPResource* Resource;
if((Resource = this->mResources->Get(ResourceID))){
- MESSAGE("Found cached resource");
+ MESSAGE(VERBOSE_METADATA, "Found cached resource");
return Resource;
}
else if((Resource = this->mMediator->getResource(ResourceID))){
- MESSAGE("Found resource in database");
+ MESSAGE(VERBOSE_METADATA, "Found resource in database");
this->mResources->Add(Resource, ResourceID);
return Resource;
}
@@ -107,12 +107,12 @@ int cUPnPResources::createFromRecording(cUPnPClassVideoItem* Object, cRecording*
}
delete Detector;
- MESSAGE("To be continued, may it work with DLNA?! Guess, not!");
+ MESSAGE(VERBOSE_SDK, "To be continued, may it work with DLNA?! Guess, not!");
return 0;
}
int cUPnPResources::createFromFile(cUPnPClassItem* , cString ){
- MESSAGE("To be done");
+ MESSAGE(VERBOSE_SDK, "To be done");
return -1;
}
@@ -131,12 +131,12 @@ int cUPnPResources::createFromChannel(cUPnPClassVideoBroadcast* Object, cChannel
const char* ProtocolInfo = cDlna::getInstance()->getProtocolInfo(Profile);
- MESSAGE("Protocol info: %s", ProtocolInfo);
+ MESSAGE(VERBOSE_METADATA, "Protocol info: %s", ProtocolInfo);
// Adapted from streamdev
int index = 0;
for(int i=0; Channel->Apid(i)!=0; i++, index++){
- MESSAGE("Analog channel %d", i);
+ MESSAGE(VERBOSE_METADATA, "Analog channel %d", i);
cString ResourceFile = cString::sprintf("%s:%d", *Channel->GetChannelID().ToString(), index);
cUPnPResource* Resource = this->mMediator->newResource(Object, UPNP_RESOURCE_CHANNEL,ResourceFile, Profile->mime, ProtocolInfo);
Resource->mBitrate = 0;
@@ -153,7 +153,7 @@ int cUPnPResources::createFromChannel(cUPnPClassVideoBroadcast* Object, cChannel
this->mResources->Add(Resource, Resource->getID());
}
for(int i=0; Channel->Dpid(i)!=0; i++, index++){
- MESSAGE("Digital channel %d", i);
+ MESSAGE(VERBOSE_METADATA, "Digital channel %d", i);
cString ResourceFile = cString::sprintf("%s:%d", *Channel->GetChannelID().ToString(), index);
cUPnPResource* Resource = this->mMediator->newResource(Object, UPNP_RESOURCE_CHANNEL,ResourceFile, Profile->mime, ProtocolInfo);
Resource->mBitrate = 0;
diff --git a/database/resources.h b/database/resources.h
index 46ec0d5..8f7fa86 100644
--- a/database/resources.h
+++ b/database/resources.h
@@ -16,6 +16,12 @@
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;
@@ -24,16 +30,89 @@ private:
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:
@@ -42,8 +121,40 @@ private:
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);
};