|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2 #include "component.h"
|
|
|
3
|
|
|
4 foobar2000_api * g_foobar2000_api = NULL;
|
|
|
5
|
|
|
6 service_class_ref service_factory_base::enum_find_class(const GUID & p_guid)
|
|
|
7 {
|
|
|
8 PFC_ASSERT(core_api::are_services_available() && g_foobar2000_api);
|
|
|
9 return g_foobar2000_api->service_enum_find_class(p_guid);
|
|
|
10 }
|
|
|
11
|
|
|
12 bool service_factory_base::enum_create(service_ptr_t<service_base> & p_out,service_class_ref p_class,t_size p_index)
|
|
|
13 {
|
|
|
14 PFC_ASSERT(core_api::are_services_available() && g_foobar2000_api);
|
|
|
15 return g_foobar2000_api->service_enum_create(p_out,p_class,p_index);
|
|
|
16 }
|
|
|
17
|
|
|
18 t_size service_factory_base::enum_get_count(service_class_ref p_class)
|
|
|
19 {
|
|
|
20 PFC_ASSERT(core_api::are_services_available() && g_foobar2000_api);
|
|
|
21 return g_foobar2000_api->service_enum_get_count(p_class);
|
|
|
22 }
|
|
|
23
|
|
|
24 service_factory_base * service_factory_base::__internal__list = NULL;
|
|
|
25
|
|
|
26
|
|
|
27 namespace service_impl_helper {
|
|
|
28 void release_object_delayed(service_base * ptr) {
|
|
|
29 ptr->service_add_ref();
|
|
|
30 fb2k::inMainThread( [ptr] {
|
|
|
31 try { ptr->service_release(); } catch(...) {}
|
|
|
32 } );
|
|
|
33 }
|
|
|
34 };
|
|
|
35
|
|
|
36
|
|
|
37 void _standard_api_create_internal(service_ptr & out, const GUID & classID) {
|
|
|
38 service_class_ref c = service_factory_base::enum_find_class(classID);
|
|
|
39 switch(service_factory_base::enum_get_count(c)) {
|
|
|
40 case 0:
|
|
|
41 #if PFC_DEBUG
|
|
|
42 if ( core_api::are_services_available() ) {
|
|
|
43 FB2K_DebugLog() << "Service not found of type: " << pfc::print_guid(classID);
|
|
|
44 }
|
|
|
45 #endif
|
|
|
46 throw exception_service_not_found();
|
|
|
47 case 1:
|
|
|
48 PFC_ASSERT_SUCCESS( service_factory_base::enum_create(out, c, 0) );
|
|
|
49 break;
|
|
|
50 default:
|
|
|
51 throw exception_service_duplicated();
|
|
|
52 }
|
|
|
53 }
|
|
|
54
|
|
|
55 bool _standard_api_try_get_internal(service_ptr & out, const GUID & classID) {
|
|
|
56 service_class_ref c = service_factory_base::enum_find_class(classID);
|
|
|
57 switch (service_factory_base::enum_get_count(c)) {
|
|
|
58 case 1:
|
|
|
59 PFC_ASSERT_SUCCESS(service_factory_base::enum_create(out, c, 0));
|
|
|
60 return true;
|
|
|
61 default:
|
|
|
62 return false;
|
|
|
63 }
|
|
|
64 }
|
|
|
65
|
|
|
66 void _standard_api_get_internal(service_ptr & out, const GUID & classID) {
|
|
|
67 if (!_standard_api_try_get_internal(out, classID) ) uBugCheck();
|
|
|
68 } |