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

A read-only instance of the media index. More...

#include <mediascanner/mediaindex.h>

+ Inheritance diagram for mediascanner::MediaIndex:

Public Types

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...
 

Public Member Functions

 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 Open (const FileSystemPath &path)
 Opens the media index at path. More...
 
virtual void Close ()
 Closes 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)
 

Static Public Member Functions

static FileSystemPath default_path ()
 The default that is used when path() is empty. More...
 

Static Public Attributes

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 []
 

Protected Member Functions

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)
 
virtual bool ReadParams ()
 
virtual bool FlushParams (Wrapper< GKeyFile > params)
 
bool FlushParams ()
 
virtual Lucene::IndexReaderPtr OpenIndex ()
 
virtual Lucene::IndexReaderPtr OpenChildIndex (const MediaRoot &root)
 
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
 

Static Protected Member Functions

static Lucene::TermPtr MakeLookupTerm (const std::wstring &url)
 
static Property::Set GetFields (Lucene::DocumentPtr document)
 

Static Protected Attributes

static const ParamId kParamFormat
 
static const ParamId kParamSegments
 
static const ParamId kParamVolumeUUID
 
static const ParamId kParamRelativePath
 

Detailed Description

A read-only instance of the media index.

Use set_refresh_policy() to control when changes are read from the disk.

See Also
WritableMediaIndex for a writable instance.

Member Typedef Documentation

typedef std::function<void(const MediaInfo &metadata, int32_t remaining_items)> mediascanner::MediaIndex::ItemVistor

Signature of the visitor function passed to methods like Query(), or VisitAll().

Parameters
metadataThe metadata of the current item.
remaining_itemsThe number of remaining items.

Constructor & Destructor Documentation

mediascanner::MediaIndex::MediaIndex ( MediaRootManagerPtr  root_manager)
explicit
virtual mediascanner::MediaIndex::~MediaIndex ( )
virtual

Member Function Documentation

void mediascanner::MediaIndex::AddMediaRoot ( const MediaRoot root)
Lucene::AnalyzerPtr mediascanner::MediaIndex::analyzer ( ) const
protected
virtual void mediascanner::MediaIndex::Close ( )
virtual

Closes the media index.

After calling this method no other queries are permitted.

See Also
Open()

Reimplemented in mediascanner::WritableMediaIndex.

static FileSystemPath mediascanner::MediaIndex::default_path ( )
static

The default that is used when path() is empty.

See Also
Open()
std::string mediascanner::MediaIndex::error_message ( )

The error message of the last failed operation.

bool mediascanner::MediaIndex::Exists ( const std::wstring &  url)

Checks if the media index contains information about the media referenced by url.

Parameters
urlThe URL of the media to check
Returns
true if the index contains information about url
MediaInfo mediascanner::MediaIndex::ExtractProperties ( Lucene::DocumentPtr  document)
protected
MediaInfo mediascanner::MediaIndex::ExtractProperties ( Lucene::DocumentPtr  document,
const Property::Set fields 
)
protected
Lucene::DocumentPtr mediascanner::MediaIndex::FindDocument ( const std::wstring &  url) const
protected
virtual bool mediascanner::MediaIndex::FlushParams ( Wrapper< GKeyFile params)
protectedvirtual
bool mediascanner::MediaIndex::FlushParams ( )
protected
std::string mediascanner::MediaIndex::get_param ( const std::string &  group,
const ParamId &  key 
) const
protected
static Property::Set mediascanner::MediaIndex::GetFields ( Lucene::DocumentPtr  document)
staticprotected
bool mediascanner::MediaIndex::is_current ( ) const

Indicator if the index still reads current data, or if Refresh() should be called.

bool mediascanner::MediaIndex::is_open ( ) const

Predicate indicating weither the index was opened successfully.

See Also
Open()
MediaInfo mediascanner::MediaIndex::Lookup ( const std::wstring &  url)

Retrieves all information stored about the referenced media.

Parameters
urlThe URL of the media to lookup.
Returns
A key-value map of the stored information.
MediaInfo mediascanner::MediaIndex::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.

Parameters
urlThe URL of the media to lookup.
field_namesThe fields to lookup.
Returns
A key-value map of the stored information.
template<typename PropertyType , typename ValueType >
ValueType mediascanner::MediaIndex::Lookup ( const std::wstring &  url,
const GenericProperty< PropertyType, ValueType > &  key 
)

Looks up a single detail about the referenced media.

Parameters
urlThe URL of the media to lookup.
keyThe field to lookup.
Returns
The stored information, or a default constructed value.
bool mediascanner::MediaIndex::Lookup ( const std::wstring &  url,
const Property key,
Property::Value value 
)
protected
template<typename P , typename V >
V mediascanner::MediaIndex::Lookup ( const std::wstring &  url,
const GenericProperty< P, V > &  key 
)
inline
static Lucene::TermPtr mediascanner::MediaIndex::MakeLookupTerm ( const std::wstring &  url)
staticprotected
virtual bool mediascanner::MediaIndex::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 in mediascanner::WritableMediaIndex.

virtual Lucene::IndexReaderPtr mediascanner::MediaIndex::OpenChildIndex ( const MediaRoot root)
protectedvirtual
virtual Lucene::IndexReaderPtr mediascanner::MediaIndex::OpenIndex ( )
protectedvirtual
FileSystemPath mediascanner::MediaIndex::params_path ( ) const
protected
FileSystemPath mediascanner::MediaIndex::path ( ) const

The file system path of the index, or an empty string to use.

the default_path().

See Also
Open()
bool mediascanner::MediaIndex::Query ( const ItemVistor visit_item,
const Filter filter,
int32_t  limit = kUnlimited,
int32_t  offset = 0 
)

Visits all items matching the filter.

Parameters
visit_itemThe function to call for each item.
filterThe filter to apply to all items.
limitThe maximum number of items to return, or kUnlimited
offsetNumber of items to skip.
@ptrue on success, check error_message() on error.
See Also
VisitAll, error_message()
virtual bool mediascanner::MediaIndex::ReadParams ( )
protectedvirtual
RefreshPolicyPtr mediascanner::MediaIndex::refresh_policy ( ) const

The current RefreshPolicy of the media index.

See Also
set_refresh_policy()
void mediascanner::MediaIndex::RemoveMediaRoot ( const MediaRoot root)
virtual bool mediascanner::MediaIndex::Reopen ( )
virtual

Refreshs the media index if it doesn't reflect recent changes anymore.

Such a method is needed because, to optimize performance, Lucene++ doesn't automatically reload its index readers upon changes.

See Also
RefreshPolicy, is_current()
void mediascanner::MediaIndex::report_error ( const boost::locale::format error_message)
protected
MediaRootManagerPtr mediascanner::MediaIndex::root_manager ( ) const

The MediaRootManager of the media index.

void mediascanner::MediaIndex::set_param ( const std::string &  group,
const ParamId &  key,
const std::string &  value 
)
protected
void mediascanner::MediaIndex::set_refresh_policy ( RefreshPolicyPtr  policy)

Changes the current RefreshPolicy of the media index.

See Also
refresh_policy()
void mediascanner::MediaIndex::VisitAll ( const ItemVistor visit_item,
int32_t  limit = kUnlimited,
int32_t  offset = 0 
)

Visits all items stored in the media index.

Parameters
visit_itemThe function to call for each item.
limitThe maximum number of items to return, or kUnlimited
offsetNumber of items to skip.
See Also
Query

Member Data Documentation

const char mediascanner::MediaIndex::kMediaIndexFormat[]
static
const char mediascanner::MediaIndex::kMetaIndexFormat[]
static
const ParamId mediascanner::MediaIndex::kParamFormat
staticprotected
const ParamId mediascanner::MediaIndex::kParamRelativePath
staticprotected
const ParamId mediascanner::MediaIndex::kParamSegments
staticprotected
const ParamId mediascanner::MediaIndex::kParamVolumeUUID
staticprotected
const int32_t mediascanner::MediaIndex::kUnlimited
static

Pass this constant as limit argument to methods such as Query(), or VisitAll() to request all available results for those methods.