1 |
/* PCSX2 - PS2 Emulator for PCs |
2 |
* Copyright (C) 2002-2010 PCSX2 Dev Team |
3 |
* |
4 |
* PCSX2 is free software: you can redistribute it and/or modify it under the terms |
5 |
* of the GNU Lesser General Public License as published by the Free Software Found- |
6 |
* ation, either version 3 of the License, or (at your option) any later version. |
7 |
* |
8 |
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
9 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
10 |
* PURPOSE. See the GNU General Public License for more details. |
11 |
* |
12 |
* You should have received a copy of the GNU General Public License along with PCSX2. |
13 |
* If not, see <http://www.gnu.org/licenses/>. |
14 |
*/ |
15 |
|
16 |
#pragma once |
17 |
|
18 |
#define PLUGINtypedefs |
19 |
#define PLUGINfuncs |
20 |
|
21 |
#include "PS2Edefs.h" |
22 |
#include "PluginCallbacks.h" |
23 |
|
24 |
#include "Utilities/Threading.h" |
25 |
|
26 |
#include <wx/dynlib.h> |
27 |
|
28 |
#ifdef _MSC_VER |
29 |
|
30 |
// Disabling C4673: throwing 'Exception::Blah' the following types will not be considered at the catch site |
31 |
// The warning is bugged, and happens even though we're properly inheriting classes with |
32 |
// 'virtual' qualifiers. But since the warning is potentially useful elsewhere, I disable |
33 |
// it only for the scope of these exceptions. |
34 |
|
35 |
# pragma warning(push) |
36 |
# pragma warning(disable:4673) |
37 |
#endif |
38 |
|
39 |
struct PluginInfo |
40 |
{ |
41 |
const char* shortname; |
42 |
PluginsEnum_t id; |
43 |
int typemask; |
44 |
int version; // minimum version required / supported |
45 |
|
46 |
wxString GetShortname() const |
47 |
{ |
48 |
return fromUTF8( shortname ); |
49 |
} |
50 |
}; |
51 |
|
52 |
// -------------------------------------------------------------------------------------- |
53 |
// Plugin-related Exceptions |
54 |
// -------------------------------------------------------------------------------------- |
55 |
namespace Exception |
56 |
{ |
57 |
// Exception thrown when a corrupted or truncated savestate is encountered. |
58 |
class SaveStateLoadError : public BadStream |
59 |
{ |
60 |
DEFINE_STREAM_EXCEPTION( SaveStateLoadError, BadStream ) |
61 |
|
62 |
virtual wxString FormatDiagnosticMessage() const; |
63 |
virtual wxString FormatDisplayMessage() const; |
64 |
}; |
65 |
|
66 |
class PluginError : public RuntimeError |
67 |
{ |
68 |
DEFINE_RUNTIME_EXCEPTION( PluginError, RuntimeError, L"Generic plugin error!" ) |
69 |
|
70 |
public: |
71 |
PluginsEnum_t PluginId; |
72 |
|
73 |
public: |
74 |
explicit PluginError( PluginsEnum_t pid ) |
75 |
{ |
76 |
PluginId = pid; |
77 |
} |
78 |
|
79 |
virtual wxString FormatDiagnosticMessage() const; |
80 |
virtual wxString FormatDisplayMessage() const; |
81 |
}; |
82 |
|
83 |
// Plugin load errors occur when initially trying to load plugins during the |
84 |
// creation of a SysCorePlugins object. The error may either be due to non-existence, |
85 |
// corruption, or incompatible versioning. |
86 |
class PluginLoadError : public PluginError |
87 |
{ |
88 |
DEFINE_EXCEPTION_COPYTORS( PluginLoadError, PluginError ) |
89 |
DEFINE_EXCEPTION_MESSAGES( PluginLoadError ) |
90 |
|
91 |
public: |
92 |
wxString StreamName; |
93 |
|
94 |
protected: |
95 |
PluginLoadError() {} |
96 |
|
97 |
public: |
98 |
PluginLoadError( PluginsEnum_t pid ); |
99 |
|
100 |
virtual PluginLoadError& SetStreamName( const wxString& name ) { StreamName = name; return *this; } \ |
101 |
virtual PluginLoadError& SetStreamName( const char* name ) { StreamName = fromUTF8(name); return *this; } |
102 |
|
103 |
virtual wxString FormatDiagnosticMessage() const; |
104 |
virtual wxString FormatDisplayMessage() const; |
105 |
}; |
106 |
|
107 |
// Thrown when a plugin fails it's init() callback. The meaning of this error is entirely |
108 |
// dependent on the plugin and, in most cases probably never happens (most plugins do little |
109 |
// more than a couple basic memory reservations during init) |
110 |
class PluginInitError : public PluginError |
111 |
{ |
112 |
DEFINE_EXCEPTION_COPYTORS( PluginInitError, PluginError ) |
113 |
DEFINE_EXCEPTION_MESSAGES( PluginInitError ) |
114 |
|
115 |
protected: |
116 |
PluginInitError() {} |
117 |
|
118 |
public: |
119 |
PluginInitError( PluginsEnum_t pid ); |
120 |
}; |
121 |
|
122 |
// Plugin failed to open. Typically this is a non-critical error that means the plugin has |
123 |
// not been configured properly by the user, but may also be indicative of a system |
124 |
class PluginOpenError : public PluginError |
125 |
{ |
126 |
DEFINE_EXCEPTION_COPYTORS( PluginOpenError, PluginError ) |
127 |
DEFINE_EXCEPTION_MESSAGES( PluginOpenError ) |
128 |
|
129 |
protected: |
130 |
PluginOpenError() {} |
131 |
|
132 |
public: |
133 |
explicit PluginOpenError( PluginsEnum_t pid ); |
134 |
}; |
135 |
|
136 |
// This exception is thrown when a plugin returns an error while trying to save itself. |
137 |
// Typically this should be a very rare occurance since a plugin typically shoudn't |
138 |
// be doing memory allocations or file access during state saving. |
139 |
// |
140 |
class FreezePluginFailure : public PluginError |
141 |
{ |
142 |
DEFINE_EXCEPTION_COPYTORS( FreezePluginFailure, PluginError ) |
143 |
DEFINE_EXCEPTION_MESSAGES( FreezePluginFailure ) |
144 |
|
145 |
protected: |
146 |
FreezePluginFailure() {} |
147 |
|
148 |
public: |
149 |
explicit FreezePluginFailure( PluginsEnum_t pid ) |
150 |
{ |
151 |
PluginId = pid; |
152 |
} |
153 |
|
154 |
virtual wxString FormatDiagnosticMessage() const; |
155 |
virtual wxString FormatDisplayMessage() const; |
156 |
}; |
157 |
|
158 |
class ThawPluginFailure : public SaveStateLoadError |
159 |
{ |
160 |
DEFINE_EXCEPTION_COPYTORS( ThawPluginFailure, SaveStateLoadError ) |
161 |
DEFINE_EXCEPTION_MESSAGES( ThawPluginFailure ) |
162 |
|
163 |
public: |
164 |
PluginsEnum_t PluginId; |
165 |
|
166 |
protected: |
167 |
ThawPluginFailure() {} |
168 |
|
169 |
public: |
170 |
explicit ThawPluginFailure( PluginsEnum_t pid ) |
171 |
{ |
172 |
PluginId = pid; |
173 |
} |
174 |
|
175 |
virtual wxString FormatDiagnosticMessage() const; |
176 |
virtual wxString FormatDisplayMessage() const; |
177 |
}; |
178 |
}; |
179 |
|
180 |
#ifdef _MSC_VER |
181 |
# pragma warning(pop) |
182 |
#endif |
183 |
|
184 |
typedef void CALLBACK FnType_SetDir( const char* dir ); |
185 |
|
186 |
// -------------------------------------------------------------------------------------- |
187 |
// LegacyPluginAPI_Common |
188 |
// -------------------------------------------------------------------------------------- |
189 |
// Important: Contents of this structure must match the order of the contents of the |
190 |
// s_MethMessCommon[] array defined in Plugins.cpp. |
191 |
// |
192 |
// Note: Open is excluded from this list because the GS and CDVD have custom signatures >_< |
193 |
// |
194 |
struct LegacyPluginAPI_Common |
195 |
{ |
196 |
s32 (CALLBACK* Init)(); |
197 |
void (CALLBACK* Close)(); |
198 |
void (CALLBACK* Shutdown)(); |
199 |
|
200 |
void (CALLBACK* KeyEvent)( keyEvent* evt ); |
201 |
|
202 |
FnType_SetDir* SetSettingsDir; |
203 |
FnType_SetDir* SetLogDir; |
204 |
|
205 |
s32 (CALLBACK* Freeze)(int mode, freezeData *data); |
206 |
s32 (CALLBACK* Test)(); |
207 |
void (CALLBACK* Configure)(); |
208 |
void (CALLBACK* About)(); |
209 |
|
210 |
LegacyPluginAPI_Common() |
211 |
{ |
212 |
memzero( *this ); |
213 |
} |
214 |
}; |
215 |
|
216 |
class SaveStateBase; |
217 |
class SysMtgsThread; |
218 |
|
219 |
// -------------------------------------------------------------------------------------- |
220 |
// PluginBindings |
221 |
// -------------------------------------------------------------------------------------- |
222 |
// This structure is intended to be the "future" of PCSX2's plugin interface, and will hopefully |
223 |
// make the current SysCorePlugins largely obsolete (with the exception of the general Load/Unload |
224 |
// management facilities) |
225 |
// |
226 |
class SysPluginBindings |
227 |
{ |
228 |
protected: |
229 |
PS2E_ComponentAPI_Mcd* Mcd; |
230 |
|
231 |
public: |
232 |
SysPluginBindings() |
233 |
{ |
234 |
Mcd = NULL; |
235 |
} |
236 |
|
237 |
bool McdIsPresent( uint port, uint slot ); |
238 |
void McdGetSizeInfo( uint port, uint slot, PS2E_McdSizeInfo& outways ); |
239 |
void McdRead( uint port, uint slot, u8 *dest, u32 adr, int size ); |
240 |
void McdSave( uint port, uint slot, const u8 *src, u32 adr, int size ); |
241 |
void McdEraseBlock( uint port, uint slot, u32 adr ); |
242 |
u64 McdGetCRC( uint port, uint slot ); |
243 |
|
244 |
friend class SysCorePlugins; |
245 |
}; |
246 |
|
247 |
extern SysPluginBindings SysPlugins; |
248 |
|
249 |
// -------------------------------------------------------------------------------------- |
250 |
// SysCorePlugins Class |
251 |
// -------------------------------------------------------------------------------------- |
252 |
// |
253 |
class SysCorePlugins |
254 |
{ |
255 |
DeclareNoncopyableObject( SysCorePlugins ); |
256 |
|
257 |
protected: |
258 |
class PluginStatus_t |
259 |
{ |
260 |
public: |
261 |
PluginsEnum_t pid; |
262 |
|
263 |
bool IsInitialized; |
264 |
bool IsOpened; |
265 |
|
266 |
wxString Filename; |
267 |
wxString Name; |
268 |
wxString Version; |
269 |
|
270 |
LegacyPluginAPI_Common CommonBindings; |
271 |
wxDynamicLibrary Lib; |
272 |
|
273 |
public: |
274 |
PluginStatus_t() |
275 |
{ |
276 |
IsInitialized = false; |
277 |
IsOpened = false; |
278 |
} |
279 |
|
280 |
PluginStatus_t( PluginsEnum_t _pid, const wxString& srcfile ); |
281 |
virtual ~PluginStatus_t() throw() { } |
282 |
|
283 |
protected: |
284 |
void BindCommon( PluginsEnum_t pid ); |
285 |
void BindRequired( PluginsEnum_t pid ); |
286 |
void BindOptional( PluginsEnum_t pid ); |
287 |
}; |
288 |
|
289 |
const PS2E_LibraryAPI* m_mcdPlugin; |
290 |
wxString m_SettingsFolder; |
291 |
wxString m_LogFolder; |
292 |
Threading::MutexRecursive m_mtx_PluginStatus; |
293 |
|
294 |
// Lovely hack until the new PS2E API is completed. |
295 |
volatile u32 m_mcdOpen; |
296 |
|
297 |
public: // hack until we unsuck plugins... |
298 |
ScopedPtr<PluginStatus_t> m_info[PluginId_Count]; |
299 |
|
300 |
public: |
301 |
SysCorePlugins(); |
302 |
virtual ~SysCorePlugins() throw(); |
303 |
|
304 |
virtual void Load( PluginsEnum_t pid, const wxString& srcfile ); |
305 |
virtual void Load( const wxString (&folders)[PluginId_Count] ); |
306 |
virtual void Unload(); |
307 |
virtual void Unload( PluginsEnum_t pid ); |
308 |
|
309 |
bool AreLoaded() const; |
310 |
bool AreOpen() const; |
311 |
bool AreAnyLoaded() const; |
312 |
bool AreAnyInitialized() const; |
313 |
|
314 |
Threading::Mutex& GetMutex() { return m_mtx_PluginStatus; } |
315 |
|
316 |
virtual bool Init(); |
317 |
virtual void Init( PluginsEnum_t pid ); |
318 |
virtual void Shutdown( PluginsEnum_t pid ); |
319 |
virtual bool Shutdown(); |
320 |
virtual void Open(); |
321 |
virtual void Open( PluginsEnum_t pid ); |
322 |
virtual void Close( PluginsEnum_t pid ); |
323 |
virtual void Close(); |
324 |
|
325 |
virtual bool IsOpen( PluginsEnum_t pid ) const; |
326 |
virtual bool IsInitialized( PluginsEnum_t pid ) const; |
327 |
virtual bool IsLoaded( PluginsEnum_t pid ) const; |
328 |
|
329 |
virtual size_t GetFreezeSize( PluginsEnum_t pid ); |
330 |
virtual void FreezeOut( PluginsEnum_t pid, void* dest ); |
331 |
virtual void FreezeOut( PluginsEnum_t pid, pxOutputStream& outfp ); |
332 |
virtual void FreezeIn( PluginsEnum_t pid, pxInputStream& infp ); |
333 |
virtual void Freeze( PluginsEnum_t pid, SaveStateBase& state ); |
334 |
virtual bool DoFreeze( PluginsEnum_t pid, int mode, freezeData* data ); |
335 |
|
336 |
virtual bool KeyEvent( const keyEvent& evt ); |
337 |
virtual void Configure( PluginsEnum_t pid ); |
338 |
virtual void SetSettingsFolder( const wxString& folder ); |
339 |
virtual void SetLogFolder( const wxString& folder ); |
340 |
virtual void SendSettingsFolder(); |
341 |
virtual void SendLogFolder(); |
342 |
|
343 |
|
344 |
const wxString GetName( PluginsEnum_t pid ) const; |
345 |
const wxString GetVersion( PluginsEnum_t pid ) const; |
346 |
|
347 |
protected: |
348 |
virtual bool NeedsClose() const; |
349 |
virtual bool NeedsOpen() const; |
350 |
|
351 |
virtual bool NeedsShutdown() const; |
352 |
virtual bool NeedsInit() const; |
353 |
|
354 |
virtual bool NeedsLoad() const; |
355 |
virtual bool NeedsUnload() const; |
356 |
|
357 |
virtual bool OpenPlugin_GS(); |
358 |
virtual bool OpenPlugin_CDVD(); |
359 |
virtual bool OpenPlugin_PAD(); |
360 |
virtual bool OpenPlugin_SPU2(); |
361 |
virtual bool OpenPlugin_DEV9(); |
362 |
virtual bool OpenPlugin_USB(); |
363 |
virtual bool OpenPlugin_FW(); |
364 |
virtual bool OpenPlugin_Mcd(); |
365 |
|
366 |
void _generalclose( PluginsEnum_t pid ); |
367 |
|
368 |
virtual void ClosePlugin_GS(); |
369 |
virtual void ClosePlugin_CDVD(); |
370 |
virtual void ClosePlugin_PAD(); |
371 |
virtual void ClosePlugin_SPU2(); |
372 |
virtual void ClosePlugin_DEV9(); |
373 |
virtual void ClosePlugin_USB(); |
374 |
virtual void ClosePlugin_FW(); |
375 |
virtual void ClosePlugin_Mcd(); |
376 |
|
377 |
friend class SysMtgsThread; |
378 |
}; |
379 |
|
380 |
extern const PluginInfo tbl_PluginInfo[]; |
381 |
|
382 |
// GetPluginManager() is a required external implementation. This function is *NOT* |
383 |
// provided by the PCSX2 core library. It provides an interface for the linking User |
384 |
// Interface apps or DLLs to reference their own instance of SysCorePlugins (also allowing |
385 |
// them to extend the class and override virtual methods). |
386 |
|
387 |
extern SysCorePlugins& GetCorePlugins(); |
388 |
|
389 |
// Hack to expose internal MemoryCard plugin: |
390 |
|
391 |
extern "C" const PS2E_LibraryAPI* FileMcd_InitAPI( const PS2E_EmulatorInfo* emuinfo ); |
392 |
|
393 |
// Per ChickenLiver, this is being used to pass the GS plugins window handle to the Pad plugins. |
394 |
// So a rename to pDisplay is in the works, but it will not, in fact, be removed. |
395 |
extern uptr pDsp; |
396 |
|