00001 #ifndef _METADB_H_
00002 #define _METADB_H_
00003
00008 class NOVTABLE metadb_io : public service_base
00009 {
00010 public:
00011 enum t_load_info_type {
00012 load_info_default,
00013 load_info_force,
00014 load_info_check_if_changed
00015 };
00016
00017 enum t_update_info_state {
00018 update_info_success,
00019 update_info_aborted,
00020 update_info_errors,
00021 };
00022
00023 enum t_load_info_state {
00024 load_info_success,
00025 load_info_aborted,
00026 load_info_errors,
00027 };
00028
00030 __declspec(deprecated) virtual bool is_busy() = 0;
00032 __declspec(deprecated) virtual bool is_updating_disabled() = 0;
00034 __declspec(deprecated) virtual bool is_file_updating_blocked() = 0;
00036 __declspec(deprecated) virtual void highlight_running_process() = 0;
00038 __declspec(deprecated) virtual t_load_info_state load_info_multi(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,t_load_info_type p_type,HWND p_parent_window,bool p_show_errors) = 0;
00040 __declspec(deprecated) virtual t_update_info_state update_info_multi(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const pfc::list_base_const_t<file_info*> & p_new_info,HWND p_parent_window,bool p_show_errors) = 0;
00042 __declspec(deprecated) virtual t_update_info_state rewrite_info_multi(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,HWND p_parent_window,bool p_show_errors) = 0;
00044 __declspec(deprecated) virtual t_update_info_state remove_info_multi(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,HWND p_parent_window,bool p_show_errors) = 0;
00045
00046 virtual void hint_multi(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const pfc::list_base_const_t<const file_info*> & p_infos,const pfc::list_base_const_t<t_filestats> & p_stats,const bit_array & p_fresh_mask) = 0;
00047
00048 virtual void hint_multi_async(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const pfc::list_base_const_t<const file_info*> & p_infos,const pfc::list_base_const_t<t_filestats> & p_stats,const bit_array & p_fresh_mask) = 0;
00049
00050 virtual void hint_reader(service_ptr_t<class input_info_reader> p_reader,const char * p_path,abort_callback & p_abort) = 0;
00051
00053 virtual void path_to_handles_simple(const char * p_path,pfc::list_base_t<metadb_handle_ptr> & p_out) = 0;
00054
00056 virtual void dispatch_refresh(const pfc::list_base_const_t<metadb_handle_ptr> & p_list) = 0;
00057
00058 void hint_async(metadb_handle_ptr p_item,const file_info & p_info,const t_filestats & p_stats,bool p_fresh);
00059
00060 __declspec(deprecated) t_load_info_state load_info(metadb_handle_ptr p_item,t_load_info_type p_type,HWND p_parent_window,bool p_show_errors);
00061 __declspec(deprecated) t_update_info_state update_info(metadb_handle_ptr p_item,file_info & p_info,HWND p_parent_window,bool p_show_errors);
00062
00063 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb_io);
00064 };
00065
00067 class NOVTABLE file_info_filter : public service_base {
00068 public:
00072 virtual bool apply_filter(metadb_handle_ptr p_location,t_filestats p_stats,file_info & p_info) = 0;
00073
00074 FB2K_MAKE_SERVICE_INTERFACE(file_info_filter,service_base);
00075 };
00076
00078 class NOVTABLE metadb_hint_list : public service_base {
00079 public:
00085 virtual void add_hint(metadb_handle_ptr const & p_location,const file_info & p_info,const t_filestats & p_stats,bool p_freshflag) = 0;
00087 virtual void add_hint_reader(const char * p_path,service_ptr_t<input_info_reader> const & p_reader,abort_callback & p_abort) = 0;
00089 virtual void on_done() = 0;
00090
00091 FB2K_MAKE_SERVICE_INTERFACE(metadb_hint_list,service_base);
00092 };
00093
00095 class NOVTABLE metadb_io_v2 : public metadb_io {
00096 public:
00097 enum {
00100 op_flag_no_errors = 1 << 0,
00102 op_flag_background = 1 << 1,
00104 op_flag_delay_ui = 1 << 2,
00105 };
00106
00110 virtual void load_info_async(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,t_load_info_type p_type,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0;
00115 virtual void update_info_async(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,service_ptr_t<file_info_filter> p_filter,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0;
00119 virtual void rewrite_info_async(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0;
00123 virtual void remove_info_async(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) = 0;
00124
00126 virtual service_ptr_t<metadb_hint_list> create_hint_list() = 0;
00127
00132 void update_info_async_simple(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const pfc::list_base_const_t<const file_info*> & p_new_info, HWND p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify);
00133
00134 FB2K_MAKE_SERVICE_INTERFACE(metadb_io_v2,metadb_io);
00135 };
00136
00138 class NOVTABLE metadb_io_callback : public service_base {
00139 public:
00143 virtual void on_changed_sorted(const pfc::list_base_const_t<metadb_handle_ptr> & p_items_sorted, bool p_fromhook) = 0;
00144
00145 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb_io_callback);
00146 };
00147
00151 class NOVTABLE metadb : public service_base
00152 {
00153 public:
00155 virtual void database_lock()=0;
00157 virtual void database_unlock()=0;
00158
00162 virtual void handle_create(metadb_handle_ptr & p_out,const playable_location & p_location)=0;
00163
00164 void handle_create_replace_path_canonical(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path);
00165 void handle_replace_path_canonical(metadb_handle_ptr & p_out,const char * p_new_path);
00166 void handle_create_replace_path(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path);
00167
00170 static bool g_get_random_handle(metadb_handle_ptr & p_out);
00171
00172 enum {case_sensitive = true};
00173 typedef pfc::comparator_strcmp path_comparator;
00174
00175 inline static int path_compare_ex(const char * p1,unsigned len1,const char * p2,unsigned len2) {return case_sensitive ? pfc::strcmp_ex(p1,len1,p2,len2) : stricmp_utf8_ex(p1,len1,p2,len2);}
00176 inline static int path_compare(const char * p1,const char * p2) {return case_sensitive ? strcmp(p1,p2) : stricmp_utf8(p1,p2);}
00177 inline static int path_compare_metadb_handle(const metadb_handle_ptr & p1,const metadb_handle_ptr & p2) {return path_compare(p1->get_path(),p2->get_path());}
00178
00179 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb);
00180 };
00181
00182
00183 class in_metadb_sync {
00184 public:
00185 in_metadb_sync() {
00186 m_api->database_lock();
00187 }
00188 ~in_metadb_sync() {
00189 m_api->database_unlock();
00190 }
00191 private:
00192 static_api_ptr_t<metadb> m_api;
00193 };
00194
00195 class in_metadb_sync_fromptr {
00196 public:
00197 in_metadb_sync_fromptr(const service_ptr_t<metadb> & p_api) : m_api(p_api) {m_api->database_lock();}
00198 ~in_metadb_sync_fromptr() {m_api->database_unlock();}
00199 private:
00200 service_ptr_t<metadb> m_api;
00201 };
00202
00203 class in_metadb_sync_fromhandle {
00204 public:
00205 in_metadb_sync_fromhandle(const service_ptr_t<metadb_handle> & p_api) : m_api(p_api) {m_api->metadb_lock();}
00206 ~in_metadb_sync_fromhandle() {m_api->metadb_unlock();}
00207 private:
00208 service_ptr_t<metadb_handle> m_api;
00209 };
00210
00211
00213 class __declspec(deprecated("Use metadb_io_v2::update_info_async instead whenever possible.")) file_info_update_helper
00214 {
00215 public:
00216 file_info_update_helper(const pfc::list_base_const_t<metadb_handle_ptr> & p_data);
00217 file_info_update_helper(metadb_handle_ptr p_item);
00218
00219 bool read_infos(HWND p_parent,bool p_show_errors);
00220
00221 enum t_write_result
00222 {
00223 write_ok,
00224 write_aborted,
00225 write_error
00226 };
00227 t_write_result write_infos(HWND p_parent,bool p_show_errors);
00228
00229 t_size get_item_count() const;
00230 bool is_item_valid(t_size p_index) const;
00231
00232 file_info & get_item(t_size p_index);
00233 metadb_handle_ptr get_item_handle(t_size p_index) const;
00234
00235 void invalidate_item(t_size p_index);
00236
00237 private:
00238 metadb_handle_list m_data;
00239 pfc::array_t<file_info_impl> m_infos;
00240 pfc::array_t<bool> m_mask;
00241 };
00242
00243 class titleformat_text_out;
00244 class titleformat_hook_function_params;
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 class metadb_display_hook : public service_base {
00257 public:
00258 virtual bool process_field(metadb_handle * p_handle,titleformat_text_out * p_out,const char * p_name,t_size p_name_length,bool & p_found_flag) = 0;
00259 virtual bool process_function(metadb_handle * p_handle,titleformat_text_out * p_out,const char * p_name,t_size p_name_length,titleformat_hook_function_params * p_params,bool & p_found_flag) = 0;
00260
00261 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(metadb_display_hook);
00262 };
00263
00264
00265
00266
00267
00268
00269
00271 class file_info_filter_impl : public file_info_filter {
00272 public:
00273 file_info_filter_impl(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const pfc::list_base_const_t<const file_info*> & p_new_info) {
00274 pfc::dynamic_assert(p_list.get_count() == p_new_info.get_count());
00275 pfc::array_t<t_size> order;
00276 order.set_size(p_list.get_count());
00277 order_helper::g_fill(order.get_ptr(),order.get_size());
00278 p_list.sort_get_permutation_t(pfc::compare_t<metadb_handle_ptr,metadb_handle_ptr>,order.get_ptr());
00279 m_handles.set_count(order.get_size());
00280 m_infos.set_size(order.get_size());
00281 for(t_size n = 0; n < order.get_size(); n++) {
00282 m_handles[n] = p_list[order[n]];
00283 m_infos[n] = *p_new_info[order[n]];
00284 }
00285 }
00286
00287 bool apply_filter(metadb_handle_ptr p_location,t_filestats p_stats,file_info & p_info) {
00288 t_size index;
00289 if (m_handles.bsearch_t(pfc::compare_t<metadb_handle_ptr,metadb_handle_ptr>,p_location,index)) {
00290 p_info = m_infos[index];
00291 return true;
00292 } else {
00293 return false;
00294 }
00295 }
00296 private:
00297 metadb_handle_list m_handles;
00298 pfc::array_t<file_info_impl> m_infos;
00299 };
00300
00301 #endif