foobar2000 SDK  2015-08-03
metadb_handle.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 
5 {
6  return this->get_info_ref()->info().get_length();
7 }
8 
10 {
11  return get_filestats().m_timestamp;
12 }
13 
15 {
16  return get_filestats().m_size;
17 }
18 
20 {
22  if (static_api_ptr_t<titleformat_compiler>()->compile(script,p_spec)) {
23  return format_title(p_hook,p_out,script,p_filter);
24  } else {
25  p_out.reset();
26  return false;
27  }
28 }
29 
30 
31 
32 bool metadb_handle::g_should_reload(const t_filestats & p_old_stats,const t_filestats & p_new_stats,bool p_fresh)
33 {
34  if (p_new_stats.m_timestamp == filetimestamp_invalid) return p_fresh;
35  else if (p_fresh) return p_old_stats!= p_new_stats;
36  else return p_old_stats.m_timestamp < p_new_stats.m_timestamp;
37 }
38 
39 bool metadb_handle::should_reload(const t_filestats & p_new_stats, bool p_fresh) const
40 {
41  if (!is_info_loaded_async()) return true;
42  else return g_should_reload(get_filestats(),p_new_stats,p_fresh);
43 }
44 
45 
47  bool rv = true;
48  metadb_info_container::ptr info, browse;
49  this->get_browse_info_ref(info, browse);
50  if (info.is_valid() && browse.is_valid()) {
51  infoMerged = info->info();
52  infoMerged.merge_fallback( browse->info() );
53  } else if (info.is_valid()) {
54  infoMerged = info->info();
55  } else if (browse.is_valid()) {
56  infoMerged = browse->info();
57  } else {
58  infoMerged.reset();
59  rv = false;
60  }
61  return rv;
62 }
63 
64 namespace {
65  class metadb_info_container_impl : public metadb_info_container {
66  public:
67  metadb_info_container_impl() : m_stats( filestats_invalid ), m_partial() {}
68  file_info const & info() {
69  return m_info;
70  }
71  t_filestats const & stats() {
72  return m_stats;
73  }
74  bool isInfoPartial() {
75  return m_partial;
76  }
77 
78  file_info_impl m_info;
79  t_filestats m_stats;
80  bool m_partial;
81 
82  };
83 }
84 
85 metadb_info_container::ptr metadb_handle::get_full_info_ref( abort_callback & aborter ) const {
86  {
87  metadb_info_container::ptr info;
88  if (this->get_info_ref( info ) ) {
89  if (!info->isInfoPartial()) return info;
90  }
91  }
92 
93 
94  input_info_reader::ptr reader;
95  input_entry::g_open_for_info_read( reader, NULL, this->get_path(), aborter );
96 
98  obj->m_stats = reader->get_file_stats( aborter );
99  reader->get_info( this->get_subsong_index(), obj->m_info, aborter );
100  return obj;
101 }
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
virtual void get_browse_info_ref(metadb_info_container::ptr &outInfo, metadb_info_container::ptr &outBrowse) const =0
virtual t_filestats get_filestats() const =0
Returns last seen file stats, filestats_invalid if unknown.
bool get_browse_info_merged(file_info &infoMerged) const
metadb_info_container::ptr get_full_info_ref(abort_callback &aborter) const
void info(const char *p_message)
Definition: console.cpp:4
bool format_title_legacy(titleformat_hook *p_hook, pfc::string_base &out, const char *p_spec, titleformat_text_filter *p_filter)
Helper provided for backwards compatibility; takes formatting script as text string and calls relevan...
pfc::string_base & p_out
Definition: metadb_handle.h:66
const char * get_path() const
Retrieves path of item described by this metadb_handle instance. Returned string is valid until calli...
static const t_filestats filestats_invalid
Invalid/unknown file stats constant. See: t_filestats.
Definition: filesystem.h:80
void merge_fallback(const file_info &fallback)
static void g_open_for_info_read(service_ptr_t< input_info_reader > &p_instance, service_ptr_t< file > p_filehint, const char *p_path, abort_callback &p_abort, bool p_from_redirect=false)
Definition: input.cpp:175
t_filesize get_filesize()
const t_filetimestamp filetimestamp_invalid
Invalid/unknown file timestamp constant. Also see: t_filetimestamp.
Definition: filesystem.h:14
Main interface class for information about some playable object.
Definition: file_info.h:73
void reset()
Definition: file_info.cpp:287
This is free and unencumbered software released into the public domain Anyone is free to compile
Definition: pfc-license.txt:3
titleformat_hook * p_hook
Definition: metadb_handle.h:68
static bool g_should_reload(const t_filestats &p_old_stats, const t_filestats &p_new_stats, bool p_fresh)
t_uint64 t_filetimestamp
Type used for file timestamp related variables. 64-bit value representing the number of 100-nanosecon...
Definition: filesystem.h:12
t_filetimestamp get_filetimestamp()
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
double get_length()
virtual bool is_info_loaded_async() const =0
Queries whether cached info about item referenced by this metadb_handle object is already available...
pfc::string_base const service_ptr_t< titleformat_object > titleformat_text_filter * p_filter
Definition: metadb_handle.h:66
Implements file_info.
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
virtual metadb_info_container::ptr get_info_ref() const =0
Simplified method, always returns non-null, dummy info if nothing to return.
virtual bool format_title(titleformat_hook *p_hook, pfc::string_base &p_out, const service_ptr_t< titleformat_object > &p_script, titleformat_text_filter *p_filter)=0
Renders information about item referenced by this metadb_handle object.
t_uint32 get_subsong_index() const
Retrieves subsong index of item described by this metadb_handle instance (used for multiple playable ...
bool should_reload(const t_filestats &p_new_stats, bool p_fresh) const