Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/foobar2000_component_client/component_client.cpp @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #include <SDK/foobar2000.h> | |
| 2 #include <SDK/component.h> | |
| 3 #include <SDK/cfg_var_legacy.h> | |
| 4 | |
| 5 #ifdef _WIN32 | |
| 6 static HINSTANCE g_hIns; | |
| 7 #endif | |
| 8 static pfc::string_simple g_name,g_full_path; | |
| 9 | |
| 10 static bool g_services_available = false, g_initialized = false; | |
| 11 | |
| 12 | |
| 13 | |
| 14 namespace core_api | |
| 15 { | |
| 16 | |
| 17 #ifdef _WIN32 | |
| 18 HINSTANCE get_my_instance() | |
| 19 { | |
| 20 return g_hIns; | |
| 21 } | |
| 22 #endif | |
| 23 fb2k::hwnd_t get_main_window() | |
| 24 { | |
| 25 PFC_ASSERT( g_foobar2000_api != NULL ); | |
| 26 return g_foobar2000_api->get_main_window(); | |
| 27 } | |
| 28 const char* get_my_file_name() | |
| 29 { | |
| 30 return g_name; | |
| 31 } | |
| 32 | |
| 33 const char* get_my_full_path() | |
| 34 { | |
| 35 return g_full_path; | |
| 36 } | |
| 37 | |
| 38 bool are_services_available() | |
| 39 { | |
| 40 return g_services_available; | |
| 41 } | |
| 42 bool assert_main_thread() | |
| 43 { | |
| 44 return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->assert_main_thread() : true; | |
| 45 } | |
| 46 | |
| 47 void ensure_main_thread() { | |
| 48 if (!is_main_thread()) FB2K_BugCheck(); | |
| 49 } | |
| 50 | |
| 51 bool is_main_thread() | |
| 52 { | |
| 53 return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->is_main_thread() : true; | |
| 54 } | |
| 55 const char* get_profile_path() | |
| 56 { | |
| 57 PFC_ASSERT( g_foobar2000_api != NULL ); | |
| 58 return g_foobar2000_api->get_profile_path(); | |
| 59 } | |
| 60 | |
| 61 bool is_shutting_down() | |
| 62 { | |
| 63 return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->is_shutting_down() : g_initialized; | |
| 64 } | |
| 65 bool is_initializing() | |
| 66 { | |
| 67 return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->is_initializing() : !g_initialized; | |
| 68 } | |
| 69 bool is_portable_mode_enabled() { | |
| 70 PFC_ASSERT( g_foobar2000_api != NULL ); | |
| 71 return g_foobar2000_api->is_portable_mode_enabled(); | |
| 72 } | |
| 73 | |
| 74 bool is_quiet_mode_enabled() { | |
| 75 PFC_ASSERT( g_foobar2000_api != NULL ); | |
| 76 return g_foobar2000_api->is_quiet_mode_enabled(); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 namespace { | |
| 81 class foobar2000_client_impl : public foobar2000_client, private foobar2000_component_globals | |
| 82 { | |
| 83 public: | |
| 84 t_uint32 get_version() override {return FOOBAR2000_CLIENT_VERSION;} | |
| 85 pservice_factory_base get_service_list() override {return service_factory_base::__internal__list;} | |
| 86 | |
| 87 void get_config(stream_writer * p_stream,abort_callback & p_abort) override { | |
| 88 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 89 cfg_var_legacy::cfg_var::config_write_file(p_stream,p_abort); | |
| 90 #endif | |
| 91 } | |
| 92 | |
| 93 void set_config(stream_reader * p_stream,abort_callback & p_abort) override { | |
| 94 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 95 cfg_var_legacy::cfg_var::config_read_file(p_stream,p_abort); | |
| 96 #endif | |
| 97 } | |
| 98 | |
| 99 void set_library_path(const char * path,const char * name) override { | |
| 100 g_full_path = path; | |
| 101 g_name = name; | |
| 102 } | |
| 103 | |
| 104 void services_init(bool val) override { | |
| 105 if (val) g_initialized = true; | |
| 106 g_services_available = val; | |
| 107 } | |
| 108 | |
| 109 bool is_debug() override { | |
| 110 return PFC_DEBUG != 0; | |
| 111 } | |
| 112 }; | |
| 113 } | |
| 114 | |
| 115 static foobar2000_client_impl g_client; | |
| 116 | |
| 117 #ifdef _WIN32 | |
| 118 extern "C" | |
| 119 { | |
| 120 __declspec(dllexport) foobar2000_client * _cdecl foobar2000_get_interface(foobar2000_api * p_api,HINSTANCE hIns) | |
| 121 { | |
| 122 g_hIns = hIns; | |
| 123 g_foobar2000_api = p_api; | |
| 124 | |
| 125 return &g_client; | |
| 126 } | |
| 127 } | |
| 128 #endif | |
| 129 | |
| 130 #ifdef __APPLE__ | |
| 131 extern "C" { | |
| 132 __attribute__ ((visibility ("default"))) foobar2000_client * foobar2000_get_interface(foobar2000_api * p_api, void * /*reserved*/) { | |
| 133 g_foobar2000_api = p_api; | |
| 134 return &g_client; | |
| 135 } | |
| 136 } | |
| 137 #endif |
