ContentManager Class Reference

#include <content_manager.h>

Inheritance diagram for ContentManager:
TimerSubscriberSingleton< ContentManager > TimerSubscriber Singleton< ContentManager > zmm::Object

Data Structures

class  TimerParameter
 This is the parameter class for timerNotify. More...

Public Member Functions

 ContentManager ()
virtual void init ()
virtual ~ContentManager ()
void shutdown ()
virtual void timerNotify (zmm::Ref< zmm::Object > parameter)
bool isBusy ()
zmm::Ref< CMAccountinggetAccounting ()
zmm::Ref< GenericTaskgetCurrentTask ()
 Returns the task that is currently being executed.
zmm::Ref< zmm::Array
< GenericTask > > 
getTasklist ()
 Returns the list of all enqueued tasks, including the current or nil if no tasks are present.
void invalidateTask (unsigned int taskID, task_owner_t taskOwner=ContentManagerTask)
 Find a task identified by the task ID and invalidate it.
void loadAccounting (bool async=true)
int addFile (zmm::String path, bool recursive=true, bool async=true, bool hidden=false, bool lowPriority=false, bool cancellable=true)
 Adds a file or directory to the database.
int ensurePathExistence (zmm::String path)
void removeObject (int objectID, bool async=true, bool all=false)
void rescanDirectory (int objectID, int scanID, scan_mode_t scanMode, zmm::String descPath=nil, bool cancellable=true)
void updateObject (int objectID, zmm::Ref< Dictionary > parameters)
 Updates an object in the database using the given parameters.
zmm::Ref< CdsObjectcreateObjectFromFile (zmm::String path, bool magic=true, bool allow_fifo=false)
void addVirtualItem (zmm::Ref< CdsObject > obj, bool allow_fifo=false)
 Adds a virtual item.
void addObject (zmm::Ref< CdsObject > obj)
 Adds an object to the database.
int addContainerChain (zmm::String chain, zmm::String lastClass=nil, int lastRefID=INVALID_OBJECT_ID)
 Adds a virtual container chain specified by path.
void addContainer (int parentID, zmm::String title, zmm::String upnpClass)
 Adds a virtual container specified by parentID and title.
void updateObject (zmm::Ref< CdsObject > obj, bool send_updates=true)
 Updates an object in the database.
zmm::Ref< CdsObjectconvertObject (zmm::Ref< CdsObject > obj, int objectType)
 Updates an object in the database using the given parameters.
zmm::Ref< AutoscanDirectorygetAutoscanDirectory (int scanID, scan_mode_t scanMode)
 Gets an AutocsanDirectrory from the watch list.
zmm::Ref< AutoscanDirectorygetAutoscanDirectory (zmm::String location)
 Get an AutoscanDirectory given by location on disk from the watch list.
void removeAutoscanDirectory (int scanID, scan_mode_t scanMode)
 Removes an AutoscanDirectrory (found by scanID) from the watch list.
void removeAutoscanDirectory (zmm::String location)
 Removes an AutoscanDirectrory (found by location) from the watch list.
void removeAutoscanDirectory (int objectID)
 Removes an AutoscanDirectory (by objectID) from the watch list.
void setAutoscanDirectory (zmm::Ref< AutoscanDirectory > dir)
 Update autoscan parameters for an existing autoscan directory or add a new autoscan directory.
void handlePeristentAutoscanRemove (int scanID, scan_mode_t scanMode)
 handles the removal of a persistent autoscan directory
void handlePersistentAutoscanRecreate (int scanID, scan_mode_t scanMode)
 handles the recreation of a persistent autoscan directory
zmm::Ref< zmm::Array
< AutoscanDirectory > > 
getAutoscanDirectories (scan_mode_t scanMode)
 returns an array of autoscan directories for the given scan mode
zmm::Ref< zmm::Array
< AutoscanDirectory > > 
getAutoscanDirectories ()
 returns an array of all autoscan directories
void reloadLayout ()
 instructs ContentManager to reload scripting environment
void retain ()
void release ()
int getRefCount ()

Static Public Member Functions

static zmm::Ref< ContentManagergetInstance ()
static void * operator new (size_t size)
static void operator delete (void *ptr)

Protected Member Functions

void initLayout ()
void destroyLayout ()
void _loadAccounting ()
int addFileInternal (zmm::String path, zmm::String rootpath, bool recursive=true, bool async=true, bool hidden=false, bool lowPriority=false, unsigned int parentTaskID=0, bool cancellable=true)
int _addFile (zmm::String path, zmm::String rootpath, bool recursive=false, bool hidden=false, zmm::Ref< GenericTask > task=nil)
void _removeObject (int objectID, bool all)
void _rescanDirectory (int containerID, int scanID, scan_mode_t scanMode, scan_level_t scanLevel, zmm::Ref< GenericTask > task=nil)
void addRecursive (zmm::String path, bool hidden, zmm::Ref< GenericTask > task)
zmm::String extension2mimetype (zmm::String extension)
zmm::String mimetype2upnpclass (zmm::String mimeType)
void invalidateAddTask (zmm::Ref< GenericTask > t, zmm::String path)
void setLastModifiedTime (time_t lm)
void signal ()
void threadProc ()
void addTask (zmm::Ref< GenericTask > task, bool lowPriority=false)
virtual void registerSingleton ()

Static Protected Member Functions

static void * staticThreadProc (void *arg)

Protected Attributes

zmm::Ref< RExpreMimetype
bool ignore_unknown_extensions
bool extension_map_case_sensitive
zmm::Ref< Dictionaryextension_mimetype_map
zmm::Ref< Dictionarymimetype_upnpclass_map
zmm::Ref< Dictionarymimetype_contenttype_map
zmm::Ref< AutoscanListautoscan_timed
zmm::Ref< Layoutlayout
bool layout_enabled
zmm::Ref< CMAccountingacct
pthread_t taskThread
zmm::Ref< Condcond
bool working
bool shutdownFlag
zmm::Ref< zmm::ObjectQueue
< GenericTask > > 
taskQueue1
zmm::Ref< zmm::ObjectQueue
< GenericTask > > 
taskQueue2
zmm::Ref< GenericTaskcurrentTask
unsigned int taskID
mt_atomic_t _ref_count

Static Protected Attributes

static zmm::Ref< Mutexmutex
static zmm::Ref< ContentManagerinstance
static bool singletonActive

Friends

void CMAddFileTask::run ()
void CMRemoveObjectTask::run ()
void CMRescanDirectoryTask::run ()
void CMLoadAccountingTask::run ()

Detailed Description

Definition at line 175 of file content_manager.h.


Constructor & Destructor Documentation

ContentManager::ContentManager (  ) 
ContentManager::~ContentManager (  )  [virtual]

Definition at line 367 of file content_manager.cc.

References log_debug.


Member Function Documentation

int ContentManager::_addFile ( zmm::String  path,
zmm::String  rootpath,
bool  recursive = false,
bool  hidden = false,
zmm::Ref< GenericTask task = nil 
) [protected]
void ContentManager::_loadAccounting (  )  [protected]

Definition at line 602 of file content_manager.cc.

References acct, and Singleton< ContentManager >::getInstance().

Referenced by loadAccounting().

void ContentManager::_removeObject ( int  objectID,
bool  all 
) [protected]
void ContentManager::_rescanDirectory ( int  containerID,
int  scanID,
scan_mode_t  scanMode,
scan_level_t  scanLevel,
zmm::Ref< GenericTask task = nil 
) [protected]
void ContentManager::addContainer ( int  parentID,
zmm::String  title,
zmm::String  upnpClass 
)

Adds a virtual container specified by parentID and title.

Parameters:
parentID the id of the parent.
title the title of the container.
upnpClass the upnp class of the container.

Definition at line 1287 of file content_manager.cc.

References addContainerChain(), escape(), Singleton< ContentManager >::getInstance(), VIRTUAL_CONTAINER_ESCAPE, and VIRTUAL_CONTAINER_SEPARATOR.

int ContentManager::addContainerChain ( zmm::String  chain,
zmm::String  lastClass = nil,
int  lastRefID = INVALID_OBJECT_ID 
)

Adds a virtual container chain specified by path.

Parameters:
container path separated by '/'. Slashes in container titles must be escaped.
lastClass upnp:class of the last container in the chain, if nil then the default class will be taken
lastRefID reference id of the last container in the chain, INVALID_OBJECT_ID indicates that the id will not be set.
Returns:
ID of the last container in the chain.

Definition at line 1294 of file content_manager.cc.

References _, _Exception, zmm::String::c_str(), Singleton< ContentManager >::getInstance(), INVALID_OBJECT_ID, log_debug, and string_ok().

Referenced by addContainer().

int ContentManager::addFile ( zmm::String  path,
bool  recursive = true,
bool  async = true,
bool  hidden = false,
bool  lowPriority = false,
bool  cancellable = true 
)

Adds a file or directory to the database.

Parameters:
path absolute path to the file
recursive recursive add (process subdirecotories)
async queue task or perform a blocking call
hidden true allows to import hidden files, false ignores them
queue for immediate processing or in normal order
Returns:
object ID of the added file - only in blockign mode, when used in async mode this function will return INVALID_OBJECT_ID

Definition at line 1619 of file content_manager.cc.

References addFileInternal(), and check_path().

int ContentManager::addFileInternal ( zmm::String  path,
zmm::String  rootpath,
bool  recursive = true,
bool  async = true,
bool  hidden = false,
bool  lowPriority = false,
unsigned int  parentTaskID = 0,
bool  cancellable = true 
) [protected]

Definition at line 1628 of file content_manager.cc.

References _, _addFile(), addTask(), and INVALID_OBJECT_ID.

Referenced by _rescanDirectory(), and addFile().

void ContentManager::addObject ( zmm::Ref< CdsObject obj  ) 

Adds an object to the database.

Parameters:
obj object to add

parentID of the object must be set before this method. The ID of the object provided is ignored and generated by this method

Definition at line 1250 of file content_manager.cc.

References DIR_SEPARATOR, Singleton< ContentManager >::getInstance(), INVALID_OBJECT_ID, IS_CDS_CONTAINER, IS_CDS_ITEM, IS_CDS_ITEM_EXTERNAL_URL, and log_debug.

Referenced by _addFile(), addRecursive(), and addVirtualItem().

void ContentManager::addRecursive ( zmm::String  path,
bool  hidden,
zmm::Ref< GenericTask task 
) [protected]
void ContentManager::addTask ( zmm::Ref< GenericTask task,
bool  lowPriority = false 
) [protected]
void ContentManager::addVirtualItem ( zmm::Ref< CdsObject obj,
bool  allow_fifo = false 
)

Adds a virtual item.

Parameters:
obj item to add
allow_fifo flag to indicate that it is ok to add a fifo, otherwise only regular files or directories are allowed.

This function makes sure that the file is first added to PC-Directory, however without the scripting execution. It then adds the user defined virtual item to the database.

Definition at line 608 of file content_manager.cc.

References _, _Exception, addObject(), check_path_ex(), createObjectFromFile(), Singleton< ContentManager >::getInstance(), IS_CDS_ITEM, and nil.

Ref< CdsObject > ContentManager::convertObject ( zmm::Ref< CdsObject obj,
int  objectType 
)

Updates an object in the database using the given parameters.

Parameters:
objectID ID of the object to update

Note: no actions should be performed on the object given as the parameter. Only the returned object should be processed. This method does not save the returned object in the database. To do so updateObject must be called

Definition at line 1336 of file content_manager.cc.

References _, _Exception, CdsObject::createObject(), and IS_CDS_ITEM.

Ref< CdsObject > ContentManager::createObjectFromFile ( zmm::String  path,
bool  magic = true,
bool  allow_fifo = false 
)
void ContentManager::destroyLayout (  )  [protected]

Definition at line 1527 of file content_manager.cc.

References layout, and nil.

Referenced by reloadLayout().

int ContentManager::ensurePathExistence ( zmm::String  path  ) 
String ContentManager::extension2mimetype ( zmm::String  extension  )  [protected]
Ref< CMAccounting > ContentManager::getAccounting (  ) 

Definition at line 545 of file content_manager.cc.

References acct.

Ref< Array< AutoscanDirectory > > ContentManager::getAutoscanDirectories (  ) 

returns an array of all autoscan directories

Definition at line 1979 of file content_manager.cc.

References autoscan_timed, and nil.

Ref< Array< AutoscanDirectory > > ContentManager::getAutoscanDirectories ( scan_mode_t  scanMode  ) 

returns an array of autoscan directories for the given scan mode

Definition at line 1963 of file content_manager.cc.

References autoscan_timed, InotifyScanMode, nil, and TimedScanMode.

Ref< AutoscanDirectory > ContentManager::getAutoscanDirectory ( zmm::String  location  ) 

Get an AutoscanDirectory given by location on disk from the watch list.

Definition at line 1992 of file content_manager.cc.

References autoscan_timed, and nil.

Ref< AutoscanDirectory > ContentManager::getAutoscanDirectory ( int  scanID,
scan_mode_t  scanMode 
)

Gets an AutocsanDirectrory from the watch list.

Definition at line 1947 of file content_manager.cc.

References autoscan_timed, InotifyScanMode, nil, and TimedScanMode.

Referenced by _rescanDirectory(), handlePeristentAutoscanRemove(), handlePersistentAutoscanRecreate(), and rescanDirectory().

Ref< GenericTask > ContentManager::getCurrentTask (  ) 

Returns the task that is currently being executed.

Definition at line 549 of file content_manager.cc.

References AUTOLOCK, currentTask, and Singleton< ContentManager >::mutex.

Referenced by getTasklist(), invalidateTask(), and removeObject().

static zmm::Ref<ContentManager > Singleton< ContentManager >::getInstance (  )  [inline, static, inherited]
int Object::getRefCount (  )  [inherited]

Definition at line 78 of file object.cc.

References zmm::Object::_ref_count, and atomic_get().

Ref< Array< GenericTask > > ContentManager::getTasklist (  ) 

Returns the list of all enqueued tasks, including the current or nil if no tasks are present.

Definition at line 557 of file content_manager.cc.

References AUTOLOCK, getCurrentTask(), Singleton< ContentManager >::getInstance(), Singleton< ContentManager >::mutex, nil, taskQueue1, and taskQueue2.

void ContentManager::handlePeristentAutoscanRemove ( int  scanID,
scan_mode_t  scanMode 
)

handles the removal of a persistent autoscan directory

Definition at line 2084 of file content_manager.cc.

References getAutoscanDirectory(), Singleton< ContentManager >::getInstance(), INVALID_OBJECT_ID, and removeAutoscanDirectory().

void ContentManager::handlePersistentAutoscanRecreate ( int  scanID,
scan_mode_t  scanMode 
)

handles the recreation of a persistent autoscan directory

Definition at line 2100 of file content_manager.cc.

References ensurePathExistence(), getAutoscanDirectory(), and Singleton< ContentManager >::getInstance().

void ContentManager::init (  )  [virtual]
void ContentManager::initLayout (  )  [protected]
void ContentManager::invalidateAddTask ( zmm::Ref< GenericTask t,
zmm::String  path 
) [protected]

Definition at line 1779 of file content_manager.cc.

References AddFile, zmm::String::c_str(), log_debug, and RefCast.

Referenced by removeObject().

void ContentManager::invalidateTask ( unsigned int  taskID,
task_owner_t  taskOwner = ContentManagerTask 
)

Find a task identified by the task ID and invalidate it.

Definition at line 1792 of file content_manager.cc.

References AUTOLOCK, ContentManagerTask, getCurrentTask(), Singleton< ContentManager >::getInstance(), Singleton< ContentManager >::mutex, nil, TaskProcessorTask, taskQueue1, and taskQueue2.

bool ContentManager::isBusy (  )  [inline]

Definition at line 217 of file content_manager.h.

References working.

void ContentManager::loadAccounting ( bool  async = true  ) 

Definition at line 1605 of file content_manager.cc.

References _, _loadAccounting(), and addTask().

String ContentManager::mimetype2upnpclass ( zmm::String  mimeType  )  [protected]

Definition at line 1457 of file content_manager.cc.

References mimetype_upnpclass_map, nil, and split_string().

Referenced by createObjectFromFile().

void Object::operator delete ( void *  ptr  )  [static, inherited]

Definition at line 87 of file object.cc.

References FREE.

void * Object::operator new ( size_t  size  )  [static, inherited]

Definition at line 83 of file object.cc.

References MALLOC.

virtual void Singleton< ContentManager >::registerSingleton (  )  [inline, protected, virtual, inherited]

Definition at line 94 of file singleton.h.

void Object::release (  )  [inherited]
void ContentManager::reloadLayout (  ) 

instructs ContentManager to reload scripting environment

Definition at line 1532 of file content_manager.cc.

References destroyLayout(), and initLayout().

void ContentManager::removeAutoscanDirectory ( int  objectID  ) 
void ContentManager::removeAutoscanDirectory ( zmm::String  location  ) 

Removes an AutoscanDirectrory (found by location) from the watch list.

Todo:
change this when more scanmodes become avaiable

Definition at line 2067 of file content_manager.cc.

References _, _Exception, autoscan_timed, Singleton< ConfigManager >::getInstance(), nil, and removeAutoscanDirectory().

void ContentManager::removeAutoscanDirectory ( int  scanID,
scan_mode_t  scanMode 
)
void ContentManager::removeObject ( int  objectID,
bool  async = true,
bool  all = false 
)
void ContentManager::rescanDirectory ( int  objectID,
int  scanID,
scan_mode_t  scanMode,
zmm::String  descPath = nil,
bool  cancellable = true 
)

Definition at line 1924 of file content_manager.cc.

References _, addTask(), BasicScanLevel, getAutoscanDirectory(), nil, and string_ok().

Referenced by _rescanDirectory(), and timerNotify().

void Object::retain (  )  [inherited]
void ContentManager::setAutoscanDirectory ( zmm::Ref< AutoscanDirectory dir  ) 
void ContentManager::setLastModifiedTime ( time_t  lm  )  [protected]
void ContentManager::shutdown (  )  [virtual]
void ContentManager::signal (  )  [inline, protected]

Definition at line 465 of file content_manager.h.

References cond.

Referenced by addTask(), and shutdown().

void * ContentManager::staticThreadProc ( void *  arg  )  [static, protected]

Definition at line 1583 of file content_manager.cc.

References NULL, and threadProc().

Referenced by init().

void ContentManager::threadProc (  )  [protected]
void ContentManager::timerNotify ( zmm::Ref< zmm::Object parameter  )  [virtual]
void ContentManager::updateObject ( zmm::Ref< CdsObject obj,
bool  send_updates = true 
)

Updates an object in the database.

Parameters:
obj the object to update

Definition at line 1314 of file content_manager.cc.

References Singleton< ContentManager >::getInstance(), INVALID_OBJECT_ID, and IS_CDS_CONTAINER.

void ContentManager::updateObject ( int  objectID,
zmm::Ref< Dictionary parameters 
)

Updates an object in the database using the given parameters.

Parameters:
objectID ID of the object to update
parameters key value pairs of fields to be updated

Todo:
if we have an active item, does it mean we first go through IS_ITEM and then thorugh IS_ACTIVE item? ask Gena

Definition at line 1114 of file content_manager.cc.

References _, CdsObject::createObject(), Singleton< ContentManager >::getInstance(), MetadataHandler::getMetaFieldName(), INVALID_OBJECT_ID, IS_CDS_ACTIVE_ITEM, IS_CDS_CONTAINER, IS_CDS_ITEM, log_debug, M_DESCRIPTION, nil, RefCast, renderProtocolInfo(), split_string(), and string_ok().


Friends And Related Function Documentation

void CMAddFileTask::run (  )  [friend]
void CMLoadAccountingTask::run (  )  [friend]
void CMRemoveObjectTask::run (  )  [friend]
void CMRescanDirectoryTask::run (  )  [friend]

Field Documentation

mt_atomic_t zmm::Object::_ref_count [protected, inherited]

Definition at line 471 of file content_manager.h.

Referenced by _loadAccounting(), ContentManager(), and getAccounting().

Definition at line 474 of file content_manager.h.

Referenced by ContentManager(), signal(), and threadProc().

Definition at line 482 of file content_manager.h.

Referenced by getCurrentTask(), and threadProc().

Definition at line 391 of file content_manager.h.

Referenced by ContentManager(), and extension2mimetype().

Definition at line 393 of file content_manager.h.

Referenced by ContentManager(), and extension2mimetype().

Definition at line 390 of file content_manager.h.

Referenced by ContentManager(), and createObjectFromFile().

zmm::Ref<ContentManager > Singleton< ContentManager >::instance [static, protected, inherited]

Definition at line 91 of file singleton.h.

Definition at line 430 of file content_manager.h.

Referenced by _addFile(), addRecursive(), destroyLayout(), and initLayout().

Definition at line 461 of file content_manager.h.

Referenced by _addFile(), and ContentManager().

Definition at line 395 of file content_manager.h.

Referenced by _addFile(), ContentManager(), and createObjectFromFile().

Definition at line 394 of file content_manager.h.

Referenced by ContentManager(), and mimetype2upnpclass().

zmm::Ref<Mutex> Singleton< ContentManager >::mutex [static, protected, inherited]

Definition at line 388 of file content_manager.h.

Referenced by createObjectFromFile(), and init().

bool ContentManager::shutdownFlag [protected]
bool Singleton< ContentManager >::singletonActive [static, protected, inherited]

Definition at line 92 of file singleton.h.

unsigned int ContentManager::taskID [protected]

Definition at line 484 of file content_manager.h.

Referenced by addTask(), and ContentManager().

pthread_t ContentManager::taskThread [protected]

Definition at line 473 of file content_manager.h.

Referenced by init(), and shutdown().

bool ContentManager::working [protected]

Definition at line 476 of file content_manager.h.

Referenced by ContentManager(), isBusy(), and threadProc().


The documentation for this class was generated from the following files:

Generated on Fri Mar 26 20:16:56 2010 for MediaTomb by  doxygen 1.6.1