foobar2000 SDK  2015-01-14
Data Structures | Namespaces | Typedefs | Functions
service.h File Reference

Go to the source code of this file.

Data Structures

class  _service_by_guid_data_container< what >
 
class  comparator_service_guid
 
class  pfc::traits_service_ptr
 
class  pfc::traits_t< service_nnptr_t< T > >
 
class  pfc::traits_t< service_ptr_t< T > >
 
class  service_base
 
class  service_by_guid_data< what >
 
class  service_class_helper_t< T >
 
class  service_enum_t< t_interface >
 
class  service_factory_base
 
class  service_factory_base_t< B >
 
class  service_factory_single_ref_t< T >
 
class  service_factory_single_t< T >
 
class  service_factory_single_transparent_t< T >
 
class  service_factory_t< T >
 
class  service_factory_traits< B >
 
class  service_instance_array_t< T >
 
class  service_list_t< T, t_alloc >
 
class  service_nnptr_t< T >
 
class  service_nnptr_t< T >
 
class  service_obscure_refcounting< T >
 
class  service_ptr_base_t< T >
 
class  service_ptr_t< T >
 
class  static_api_ptr_t< t_interface >
 

Namespaces

 pfc
 

Typedefs

typedef const void * service_class_ref
 
typedef service_nnptr_t< service_baseservice_nnptr
 
typedef service_ptr_t< service_baseservice_ptr
 

Functions

template<typename T >
void __validate_service_class_helper ()
 
template<>
void __validate_service_class_helper< service_base > ()
 
template<typename T >
static service_class_ref _service_find_class ()
 
template<typename what >
static bool _service_instantiate_helper (service_ptr_t< what > &out, service_class_ref servClass, t_size index)
 
void _standard_api_create_internal (service_ptr &out, const GUID &classID)
 
template<typename T >
static void _validate_service_ptr (service_ptr_t< T > const &ptr)
 
 PFC_DECLARE_EXCEPTION (exception_service_not_found, pfc::exception,"Service not found")
 
 PFC_DECLARE_EXCEPTION (exception_service_extension_not_found, pfc::exception,"Service extension not found")
 
 PFC_DECLARE_EXCEPTION (exception_service_duplicated, pfc::exception,"Service duplicated")
 
template<typename T >
static void service_add_ref_safe (T *p_ptr) throw ()
 
template<typename what >
static bool service_by_guid (service_ptr_t< what > &out, const GUID &theID)
 
template<typename what >
static service_ptr_t< what > service_by_guid (const GUID &theID)
 
template<typename what >
static bool service_by_guid_fallback (service_ptr_t< what > &out, const GUID &id)
 
template<typename what >
static void service_by_guid_init ()
 
template<class T >
static bool service_enum_create_t (service_ptr_t< T > &p_out, t_size p_index)
 
template<typename T >
static service_obscure_refcounting< T > * service_obscure_refcounting_cast (T *p_source) throw ()
 
template<typename T >
static void service_release_safe (T *p_ptr) throw ()
 
template<typename T >
void standard_api_create_t (service_ptr_t< T > &p_out)
 
template<typename T >
void standard_api_create_t (T *&p_out)
 
template<typename T >
service_ptr_t< Tstandard_api_create_t ()
 
template<typename T >
bool static_api_test_t ()
 

Typedef Documentation

typedef const void* service_class_ref

Definition at line 4 of file service.h.

Definition at line 370 of file service.h.

Definition at line 369 of file service.h.

Function Documentation

template<typename T >
void __validate_service_class_helper ( )
inline

Definition at line 373 of file service.h.

373  {
374  __validate_service_class_helper<typename T::t_interface_parent>();
375 }
template<>
void __validate_service_class_helper< service_base > ( )
inline

Definition at line 378 of file service.h.

378 {}
template<typename T >
static service_class_ref _service_find_class ( )
static

Definition at line 445 of file service.h.

445  {
447  return service_factory_base::enum_find_class(T::class_guid);
448 }
static service_class_ref enum_find_class(const GUID &p_guid)
Definition: service.cpp:6
template<typename what >
static bool _service_instantiate_helper ( service_ptr_t< what > &  out,
service_class_ref  servClass,
t_size  index 
)
static

Definition at line 451 of file service.h.

451  {
452  /*if (out._as_base_ptr_check()) {
453  const bool state = service_factory_base::enum_create(out._as_base_ptr(), servClass, index);
454  if (state) { FB2K_ASSERT_VALID_SERVICE_PTR(out); }
455  return state;
456  } else */{
457  service_ptr temp;
458  const bool state = service_factory_base::enum_create(temp, servClass, index);
459  if (state) {
460  out.attach( static_cast<what*>( temp.detach() ) );
461  FB2K_ASSERT_VALID_SERVICE_PTR( out );
462  }
463  return state;
464  }
465 }
T * detach()
Definition: service.h:145
void attach(t_source *p_ptr)
Definition: service.h:150
static bool enum_create(service_ptr_t< service_base > &p_out, service_class_ref p_class, t_size p_index)
Definition: service.cpp:12
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
void _standard_api_create_internal ( service_ptr out,
const GUID classID 
)

Definition at line 48 of file service.cpp.

48  {
51  case 0:
52  throw exception_service_not_found();
53  case 1:
54  PFC_ASSERT_SUCCESS( service_factory_base::enum_create(out, c, 0) );
55  break;
56  default:
57  throw exception_service_duplicated();
58  }
59 }
const void * service_class_ref
Definition: service.h:4
static t_size enum_get_count(service_class_ref p_class)
Definition: service.cpp:18
static service_class_ref enum_find_class(const GUID &p_guid)
Definition: service.cpp:6
static bool enum_create(service_ptr_t< service_base > &p_out, service_class_ref p_class, t_size p_index)
Definition: service.cpp:12
template<typename T >
static void _validate_service_ptr ( service_ptr_t< T > const &  ptr)
static

Definition at line 421 of file service.h.

421  {
422  PFC_ASSERT( ptr.is_valid() );
424  PFC_ASSERT( ptr->service_query_t(test) );
425 }
bool is_valid() const
Definition: service.h:119
bool test(const char *str, const char *pattern, bool b_separate_by_semicolon=false)
Definition: wildcard.cpp:26
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
PFC_DECLARE_EXCEPTION ( exception_service_not_found  ,
pfc::exception  ,
"Service not found"   
)
PFC_DECLARE_EXCEPTION ( exception_service_extension_not_found  ,
pfc::exception  ,
"Service extension not found"   
)
PFC_DECLARE_EXCEPTION ( exception_service_duplicated  ,
pfc::exception  ,
"Service duplicated"   
)
template<typename T >
static void service_add_ref_safe ( T p_ptr)
throw (
)
static

Definition at line 36 of file service.h.

36  {
37  if (p_ptr != NULL) PFC_ASSERT_NO_EXCEPTION( p_ptr->service_add_ref() );
38 }
template<typename what >
static bool service_by_guid ( service_ptr_t< what > &  out,
const GUID theID 
)
static

Definition at line 738 of file service.h.

738  {
741  if (data.ready()) {
742  //fall-thru
743  } else if (core_api::is_main_thread()) {
744  data.initialize();
745  } else {
746 #ifdef _DEBUG
747  FB2K_DebugLog() << "Warning: service_by_guid() used in non-main thread without initialization, using fallback";
748 #endif
749  return service_by_guid_fallback(out,theID);
750  }
751  return data.create(out,theID);
752 }
bool is_main_thread()
Returns true if calling thread is main app thread, false otherwise.
static bool service_by_guid_fallback(service_ptr_t< what > &out, const GUID &id)
Definition: service.h:677
template<typename what >
static service_ptr_t<what> service_by_guid ( const GUID theID)
static

Definition at line 754 of file service.h.

754  {
755  service_ptr_t<what> temp;
756  if (!service_by_guid(temp,theID)) throw exception_service_not_found();
757  return temp;
758 }
static bool service_by_guid(service_ptr_t< what > &out, const GUID &theID)
Definition: service.h:738
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
template<typename what >
static bool service_by_guid_fallback ( service_ptr_t< what > &  out,
const GUID id 
)
static

Definition at line 677 of file service.h.

677  {
680  while(e.next(ptr)) {
681  if (ptr->get_guid() == id) {out = ptr; return true;}
682  }
683  return false;
684 }
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
template<typename what >
static void service_by_guid_init ( )
static
template<class T >
static bool service_enum_create_t ( service_ptr_t< T > &  p_out,
t_size  p_index 
)
static

Definition at line 433 of file service.h.

433  {
437  p_out = static_cast<T*>(ptr.get_ptr());
438  return true;
439  } else {
440  p_out.release();
441  return false;
442  }
443 }
void release()
Definition: service.h:109
static service_class_ref enum_find_class(const GUID &p_guid)
Definition: service.cpp:6
static bool enum_create(service_ptr_t< service_base > &p_out, service_class_ref p_class, t_size p_index)
Definition: service.cpp:12
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
template<typename T >
static service_obscure_refcounting<T>* service_obscure_refcounting_cast ( T p_source)
throw (
)
inlinestatic

Converts a service interface pointer to a pointer that obscures service counter functionality.

Definition at line 28 of file service.h.

28 {return static_cast<service_obscure_refcounting<T>*>(p_source);}
Special hack to ensure errors when someone tries to ->service_add_ref()/->service_release() on a serv...
Definition: service.h:21
template<typename T >
static void service_release_safe ( T p_ptr)
throw (
)
static

Definition at line 31 of file service.h.

31  {
32  if (p_ptr != NULL) PFC_ASSERT_NO_EXCEPTION( p_ptr->service_release() );
33 }
template<typename T >
void standard_api_create_t ( service_ptr_t< T > &  p_out)
inline

Definition at line 492 of file service.h.

492  {
494  _standard_api_create_internal(p_out._as_base_ptr(), T::class_guid);
495  FB2K_ASSERT_VALID_SERVICE_PTR(p_out);
496  } else {
498  standard_api_create_t(temp);
499  if (!temp->service_query_t(p_out)) throw exception_service_extension_not_found();
500  }
501 }
void standard_api_create_t(service_ptr_t< T > &p_out)
Definition: service.h:492
void _standard_api_create_internal(service_ptr &out, const GUID &classID)
Definition: service.cpp:48
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
service_ptr_t< service_base > & _as_base_ptr()
Definition: service.h:157
template<typename T >
void standard_api_create_t ( T *&  p_out)
inline

Definition at line 503 of file service.h.

503  {
504  p_out = NULL;
505  standard_api_create_t( *reinterpret_cast< service_ptr_t<T> * >( & p_out ) );
506 }
void standard_api_create_t(service_ptr_t< T > &p_out)
Definition: service.h:492
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
template<typename T >
service_ptr_t<T> standard_api_create_t ( )
inline

Definition at line 508 of file service.h.

508  {
509  service_ptr_t<T> temp;
510  standard_api_create_t(temp);
511  return temp;
512 }
void standard_api_create_t(service_ptr_t< T > &p_out)
Definition: service.h:492
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
template<typename T >
bool static_api_test_t ( )
inline

Definition at line 515 of file service.h.

515  {
516  typedef typename T::t_interface_entrypoint EP;
518  if (helper.get_count() != 1) return false;
521  if (!helper.create(0)->service_query_t(t)) return false;
522  }
523  return true;
524 }
t_size get_count() const
Definition: service.h:472
bool create(service_ptr_t< T > &p_out, t_size p_index) const
Definition: service.h:476
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55