foobar2000 SDK  2015-08-03
component_client.cpp
Go to the documentation of this file.
1 #include "../SDK/foobar2000.h"
2 #include "../SDK/component.h"
3 
4 static HINSTANCE g_hIns;
5 
7 
8 static bool g_services_available = false, g_initialized = false;
9 
10 
11 
12 namespace core_api
13 {
14 
15  HINSTANCE get_my_instance()
16  {
17  return g_hIns;
18  }
19 
21  {
22  PFC_ASSERT( g_foobar2000_api != NULL );
23  return g_foobar2000_api->get_main_window();
24  }
25  const char* get_my_file_name()
26  {
27  return g_name;
28  }
29 
30  const char* get_my_full_path()
31  {
32  return g_full_path;
33  }
34 
36  {
37  return g_services_available;
38  }
40  {
41  return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->assert_main_thread() : true;
42  }
43 
45  if (!is_main_thread()) uBugCheck();
46  }
47 
49  {
50  return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->is_main_thread() : true;
51  }
52  const char* get_profile_path()
53  {
54  PFC_ASSERT( g_foobar2000_api != NULL );
55  return g_foobar2000_api->get_profile_path();
56  }
57 
59  {
60  return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->is_shutting_down() : g_initialized;
61  }
63  {
64  return (g_services_available && g_foobar2000_api) ? g_foobar2000_api->is_initializing() : !g_initialized;
65  }
67  PFC_ASSERT( g_foobar2000_api != NULL );
68  return g_foobar2000_api->is_portable_mode_enabled();
69  }
70 
72  PFC_ASSERT( g_foobar2000_api != NULL );
73  return g_foobar2000_api->is_quiet_mode_enabled();
74  }
75 }
76 
77 namespace {
78  class foobar2000_client_impl : public foobar2000_client, private foobar2000_component_globals
79  {
80  public:
81  t_uint32 get_version() {return FOOBAR2000_CLIENT_VERSION;}
82  pservice_factory_base get_service_list() {return service_factory_base::__internal__list;}
83 
84  void get_config(stream_writer * p_stream,abort_callback & p_abort) {
85  cfg_var::config_write_file(p_stream,p_abort);
86  }
87 
88  void set_config(stream_reader * p_stream,abort_callback & p_abort) {
89  cfg_var::config_read_file(p_stream,p_abort);
90  }
91 
92  void set_library_path(const char * path,const char * name) {
93  g_full_path = path;
94  g_name = name;
95  }
96 
97  void services_init(bool val) {
98  if (val) g_initialized = true;
100  }
101 
102  bool is_debug() {
103 #ifdef _DEBUG
104  return true;
105 #else
106  return false;
107 #endif
108  }
109  };
110 }
111 
112 static foobar2000_client_impl g_client;
113 
114 extern "C"
115 {
116  __declspec(dllexport) foobar2000_client * _cdecl foobar2000_get_interface(foobar2000_api * p_api,HINSTANCE hIns)
117  {
118  g_hIns = hIns;
120 
121  return &g_client;
122  }
123 }
void ensure_main_thread()
Triggers a bug check if the calling thread is not the main app thread.
bool is_shutting_down()
Returns whether the app is currently shutting down.
static void config_write_file(stream_writer *p_stream, abort_callback &p_abort)
For internal use only, do not call.
Definition: cfg_var.cpp:34
static bool g_services_available
static HINSTANCE g_hIns
const char * get_my_full_path()
Retrieves full path of calling dll, e.g. file://c:.dll.
static void config_read_file(stream_reader *p_stream, abort_callback &p_abort)
For internal use only, do not call.
Definition: cfg_var.cpp:6
__declspec(dllexport) foobar2000_client *_cdecl foobar2000_get_interface(foobar2000_api *p_api
static service_factory_base * __internal__list
FOR INTERNAL USE ONLY.
Definition: service.h:400
bool is_initializing()
Returns whether the app is currently initializing.
static pfc::string_simple g_full_path
const char * get_profile_path()
Returns filesystem path to directory with user settings, e.g. file://c:.
string_simple_t< char > string_simple
Definition: string_base.h:826
const char * get_my_file_name()
Retrieves filename of calling dll, excluding extension, e.g. "foo_asdf".
g_foobar2000_api
bool is_quiet_mode_enabled()
Returns whether foobar2000 is currently running in quiet mode. Quiet mode bypasses all GUI features...
bool assert_main_thread()
Tests whether calling thread is main app thread, and shows diagnostic message in debugger output if i...
HINSTANCE hIns
HWND get_main_window()
Retrieves main app window. WARNING: this is provided for parent of dialog windows and such only; usin...
bool is_portable_mode_enabled()
Returns whether foobar2000 has been installed in "portable" mode.
bool is_main_thread()
Returns true if calling thread is main app thread, false otherwise.
HINSTANCE get_my_instance()
Retrieves HINSTANCE of calling DLL.
PFC_NORETURN void SHARED_EXPORT uBugCheck()
static bool g_initialized
static foobar2000_client_impl g_client
static pfc::string_simple g_name
bool are_services_available()
Tests whether services are available at this time. They are not available only during DLL startup or ...
uint32_t t_uint32
Definition: int_types.h:5