Ubuntu TV Media Scanner
A centralized index for removable media content.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Friends | List of all members
mediascanner::WritableMediaIndex Class Reference

A writable instance of the media index. More...

#include <mediascanner/writablemediaindex.h>

+ Inheritance diagram for mediascanner::WritableMediaIndex:

Public Member Functions

 WritableMediaIndex (MediaRootManagerPtr root_manager)
 
 ~WritableMediaIndex ()
 
void set_commit_policy (CommitPolicyPtr policy)
 Changes the commit_policy() of this media index. More...
 
CommitPolicyPtr commit_policy () const
 The commit policy of this media index. More...
 
void set_write_lock_timeout (int64_t timeout)
 Changes the time to wait for a write lock in milliseconds. More...
 
int64_t write_lock_timeout () const
 The time to wait for a write lock in milliseconds. More...
 
bool Open (const FileSystemPath &path)
 Opens the media index at path. More...
 
void Close ()
 Closes the media index. More...
 
bool Insert (const std::wstring &url, const MediaInfo &metadata)
 Inserts new properties for the media referenced by url. More...
 
bool Delete (const std::wstring &url)
 Removes a media information from the index. More...
 
void CommitPendingChanges ()
 Commits all pending changes so that other readers will see the changes, and so that the updates will survive a system crash or power loss. More...
 
- Public Member Functions inherited from mediascanner::MediaIndex
 MediaIndex (MediaRootManagerPtr root_manager)
 
virtual ~MediaIndex ()
 
std::string error_message ()
 The error message of the last failed operation. More...
 
FileSystemPath path () const
 The file system path of the index, or an empty string to use. More...
 
bool is_open () const
 Predicate indicating weither the index was opened successfully. More...
 
bool is_current () const
 Indicator if the index still reads current data, or if Refresh() should be called. More...
 
void set_refresh_policy (RefreshPolicyPtr policy)
 Changes the current RefreshPolicy of the media index. More...
 
RefreshPolicyPtr refresh_policy () const
 The current RefreshPolicy of the media index. More...
 
MediaRootManagerPtr root_manager () const
 The MediaRootManager of the media index. More...
 
virtual bool Reopen ()
 Refreshs the media index if it doesn't reflect recent changes anymore. More...
 
void AddMediaRoot (const MediaRoot &root)
 
void RemoveMediaRoot (const MediaRoot &root)
 
bool Exists (const std::wstring &url)
 Checks if the media index contains information about the media referenced by url. More...
 
MediaInfo Lookup (const std::wstring &url)
 Retrieves all information stored about the referenced media. More...
 
MediaInfo Lookup (const std::wstring &url, const Property::Set &fields)
 Retrieves the information stored in the index for the media referenced by url, as requested in field_names. More...
 
template<typename PropertyType , typename ValueType >
ValueType Lookup (const std::wstring &url, const GenericProperty< PropertyType, ValueType > &key)
 Looks up a single detail about the referenced media. More...
 
void VisitAll (const ItemVistor &visit_item, int32_t limit=kUnlimited, int32_t offset=0)
 Visits all items stored in the media index. More...
 
bool Query (const ItemVistor &visit_item, const Filter &filter, int32_t limit=kUnlimited, int32_t offset=0)
 Visits all items matching the filter. More...
 
template<typename P , typename V >
Lookup (const std::wstring &url, const GenericProperty< P, V > &key)
 

Protected Member Functions

bool ReadParams ()
 
bool FlushParams (Wrapper< GKeyFile > params)
 
Lucene::IndexReaderPtr OpenIndex ()
 
Lucene::IndexReaderPtr OpenChildIndex (const MediaRoot &root)
 
Lucene::IndexWriterPtr find_index_writer (const std::wstring &url)
 
- Protected Member Functions inherited from mediascanner::MediaIndex
Lucene::AnalyzerPtr analyzer () const
 
void report_error (const boost::locale::format &error_message)
 
Lucene::DocumentPtr FindDocument (const std::wstring &url) const
 
MediaInfo ExtractProperties (Lucene::DocumentPtr document)
 
MediaInfo ExtractProperties (Lucene::DocumentPtr document, const Property::Set &fields)
 
bool Lookup (const std::wstring &url, const Property &key, Property::Value *value)
 
bool FlushParams ()
 
std::string get_param (const std::string &group, const ParamId &key) const
 
void set_param (const std::string &group, const ParamId &key, const std::string &value)
 
FileSystemPath params_path () const
 

Friends

class CommitPolicy
 

Additional Inherited Members

- Public Types inherited from mediascanner::MediaIndex
typedef std::function< void(const
MediaInfo &metadata, int32_t
remaining_items)> 
ItemVistor
 Signature of the visitor function passed to methods like Query(), or VisitAll(). More...
 
- Static Public Member Functions inherited from mediascanner::MediaIndex
static FileSystemPath default_path ()
 The default that is used when path() is empty. More...
 
- Static Public Attributes inherited from mediascanner::MediaIndex
static const int32_t kUnlimited
 Pass this constant as limit argument to methods such as Query(), or VisitAll() to request all available results for those methods. More...
 
static const char kMediaIndexFormat []
 
static const char kMetaIndexFormat []
 
- Static Protected Member Functions inherited from mediascanner::MediaIndex
static Lucene::TermPtr MakeLookupTerm (const std::wstring &url)
 
static Property::Set GetFields (Lucene::DocumentPtr document)
 
- Static Protected Attributes inherited from mediascanner::MediaIndex
static const ParamId kParamFormat
 
static const ParamId kParamSegments
 
static const ParamId kParamVolumeUUID
 
static const ParamId kParamRelativePath
 

Detailed Description

A writable instance of the media index.

Use set_commit_policy() to control when changes are written back to the disk.

See Also
MediaIndex for a read-only instance.

Constructor & Destructor Documentation

mediascanner::WritableMediaIndex::WritableMediaIndex ( MediaRootManagerPtr  root_manager)
explicit
mediascanner::WritableMediaIndex::~WritableMediaIndex ( )

Member Function Documentation

void mediascanner::WritableMediaIndex::Close ( )
virtual

Closes the media index.

After calling this method no other queries are permitted.

See Also
Open()

Reimplemented from mediascanner::MediaIndex.

CommitPolicyPtr mediascanner::WritableMediaIndex::commit_policy ( ) const

The commit policy of this media index.

void mediascanner::WritableMediaIndex::CommitPendingChanges ( )

Commits all pending changes so that other readers will see the changes, and so that the updates will survive a system crash or power loss.

This call can be very expensive, therefore we should only call it if when really necessary. It's usually more efficient to just rely on the configured commit_policy().

bool mediascanner::WritableMediaIndex::Delete ( const std::wstring &  url)

Removes a media information from the index.

Parameters
urlThe URL of the media to remove.
Lucene::IndexWriterPtr mediascanner::WritableMediaIndex::find_index_writer ( const std::wstring &  url)
protected
bool mediascanner::WritableMediaIndex::FlushParams ( Wrapper< GKeyFile params)
protectedvirtual

Reimplemented from mediascanner::MediaIndex.

bool mediascanner::WritableMediaIndex::Insert ( const std::wstring &  url,
const MediaInfo metadata 
)

Inserts new properties for the media referenced by url.

Parameters
urlThe URL of the media to modify.
metadataThe new property values to attach.
bool mediascanner::WritableMediaIndex::Open ( const FileSystemPath path)
virtual

Opens the media index at path.

This method must be called before performing any read operations.

Parameters
pathThe file system path of the index, or an empty string to use the default_path().
Returns
true on success.
See Also
Close(), is_open), path(), default_path()

Reimplemented from mediascanner::MediaIndex.

Lucene::IndexReaderPtr mediascanner::WritableMediaIndex::OpenChildIndex ( const MediaRoot root)
protectedvirtual

Reimplemented from mediascanner::MediaIndex.

Lucene::IndexReaderPtr mediascanner::WritableMediaIndex::OpenIndex ( )
protectedvirtual

Reimplemented from mediascanner::MediaIndex.

bool mediascanner::WritableMediaIndex::ReadParams ( )
protectedvirtual

Reimplemented from mediascanner::MediaIndex.

void mediascanner::WritableMediaIndex::set_commit_policy ( CommitPolicyPtr  policy)

Changes the commit_policy() of this media index.

void mediascanner::WritableMediaIndex::set_write_lock_timeout ( int64_t  timeout)

Changes the time to wait for a write lock in milliseconds.

int64_t mediascanner::WritableMediaIndex::write_lock_timeout ( ) const

The time to wait for a write lock in milliseconds.

Friends And Related Function Documentation

friend class CommitPolicy
friend