/[pcsx2_0.9.7]/trunk/pcsx2/Plugins.h
ViewVC logotype

Annotation of /trunk/pcsx2/Plugins.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (hide annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File MIME type: text/plain
File size: 11293 byte(s)
re-commit (had local access denied errors when committing)
1 william 31 /* 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 william 62 class SaveStateLoadError : public BadStream
59 william 31 {
60 william 280 DEFINE_STREAM_EXCEPTION( SaveStateLoadError, BadStream )
61    
62     virtual wxString FormatDiagnosticMessage() const;
63     virtual wxString FormatDisplayMessage() const;
64 william 31 };
65    
66 william 62 class PluginError : public RuntimeError
67 william 31 {
68 william 280 DEFINE_RUNTIME_EXCEPTION( PluginError, RuntimeError, L"Generic plugin error!" )
69 william 62
70 william 31 public:
71     PluginsEnum_t PluginId;
72    
73     public:
74 william 62 explicit PluginError( PluginsEnum_t pid )
75 william 31 {
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 william 62 // creation of a SysCorePlugins object. The error may either be due to non-existence,
85 william 31 // corruption, or incompatible versioning.
86 william 62 class PluginLoadError : public PluginError
87 william 31 {
88 william 62 DEFINE_EXCEPTION_COPYTORS( PluginLoadError, PluginError )
89     DEFINE_EXCEPTION_MESSAGES( PluginLoadError )
90    
91 william 31 public:
92 william 62 wxString StreamName;
93 william 31
94 william 62 protected:
95     PluginLoadError() {}
96 william 31
97 william 62 public:
98     PluginLoadError( PluginsEnum_t pid );
99 william 31
100 william 62 virtual PluginLoadError& SetStreamName( const wxString& name ) { StreamName = name; return *this; } \
101     virtual PluginLoadError& SetStreamName( const char* name ) { StreamName = fromUTF8(name); return *this; }
102    
103 william 31 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 william 62 class PluginInitError : public PluginError
111 william 31 {
112 william 62 DEFINE_EXCEPTION_COPYTORS( PluginInitError, PluginError )
113     DEFINE_EXCEPTION_MESSAGES( PluginInitError )
114    
115     protected:
116     PluginInitError() {}
117    
118 william 31 public:
119 william 62 PluginInitError( PluginsEnum_t pid );
120 william 31 };
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 william 62 class PluginOpenError : public PluginError
125 william 31 {
126 william 62 DEFINE_EXCEPTION_COPYTORS( PluginOpenError, PluginError )
127     DEFINE_EXCEPTION_MESSAGES( PluginOpenError )
128    
129     protected:
130     PluginOpenError() {}
131    
132 william 31 public:
133 william 62 explicit PluginOpenError( PluginsEnum_t pid );
134 william 31 };
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 william 62 class FreezePluginFailure : public PluginError
141 william 31 {
142 william 62 DEFINE_EXCEPTION_COPYTORS( FreezePluginFailure, PluginError )
143     DEFINE_EXCEPTION_MESSAGES( FreezePluginFailure )
144    
145     protected:
146     FreezePluginFailure() {}
147    
148 william 31 public:
149 william 62 explicit FreezePluginFailure( PluginsEnum_t pid )
150 william 31 {
151     PluginId = pid;
152     }
153    
154     virtual wxString FormatDiagnosticMessage() const;
155     virtual wxString FormatDisplayMessage() const;
156     };
157    
158 william 62 class ThawPluginFailure : public SaveStateLoadError
159 william 31 {
160 william 62 DEFINE_EXCEPTION_COPYTORS( ThawPluginFailure, SaveStateLoadError )
161     DEFINE_EXCEPTION_MESSAGES( ThawPluginFailure )
162    
163 william 31 public:
164 william 62 PluginsEnum_t PluginId;
165 william 31
166 william 62 protected:
167     ThawPluginFailure() {}
168    
169     public:
170 william 31 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 william 62 typedef void CALLBACK FnType_SetDir( const char* dir );
185    
186 william 31 // --------------------------------------------------------------------------------------
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 william 62 FnType_SetDir* SetSettingsDir;
203     FnType_SetDir* SetLogDir;
204    
205 william 31 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 william 62 // make the current SysCorePlugins largely obsolete (with the exception of the general Load/Unload
224 william 31 // 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 william 62 friend class SysCorePlugins;
245 william 31 };
246    
247     extern SysPluginBindings SysPlugins;
248    
249     // --------------------------------------------------------------------------------------
250 william 62 // SysCorePlugins Class
251 william 31 // --------------------------------------------------------------------------------------
252     //
253 william 62 class SysCorePlugins
254 william 31 {
255 william 62 DeclareNoncopyableObject( SysCorePlugins );
256 william 31
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 william 62 SysCorePlugins();
302     virtual ~SysCorePlugins() throw();
303 william 31
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 william 62 bool AreOpen() const;
311 william 31 bool AreAnyLoaded() const;
312     bool AreAnyInitialized() const;
313    
314     Threading::Mutex& GetMutex() { return m_mtx_PluginStatus; }
315    
316 william 62 virtual bool Init();
317 william 31 virtual void Init( PluginsEnum_t pid );
318     virtual void Shutdown( PluginsEnum_t pid );
319 william 62 virtual bool Shutdown();
320 william 31 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 void Freeze( PluginsEnum_t pid, SaveStateBase& state );
330     virtual bool DoFreeze( PluginsEnum_t pid, int mode, freezeData* data );
331    
332     virtual bool KeyEvent( const keyEvent& evt );
333     virtual void Configure( PluginsEnum_t pid );
334     virtual void SetSettingsFolder( const wxString& folder );
335 william 62 virtual void SetLogFolder( const wxString& folder );
336 william 31 virtual void SendSettingsFolder();
337     virtual void SendLogFolder();
338    
339    
340     const wxString GetName( PluginsEnum_t pid ) const;
341     const wxString GetVersion( PluginsEnum_t pid ) const;
342    
343     protected:
344     virtual bool NeedsClose() const;
345     virtual bool NeedsOpen() const;
346    
347     virtual bool NeedsShutdown() const;
348     virtual bool NeedsInit() const;
349    
350     virtual bool NeedsLoad() const;
351     virtual bool NeedsUnload() const;
352    
353     virtual bool OpenPlugin_GS();
354     virtual bool OpenPlugin_CDVD();
355     virtual bool OpenPlugin_PAD();
356     virtual bool OpenPlugin_SPU2();
357     virtual bool OpenPlugin_DEV9();
358     virtual bool OpenPlugin_USB();
359     virtual bool OpenPlugin_FW();
360     virtual bool OpenPlugin_Mcd();
361    
362     void _generalclose( PluginsEnum_t pid );
363    
364     virtual void ClosePlugin_GS();
365     virtual void ClosePlugin_CDVD();
366     virtual void ClosePlugin_PAD();
367     virtual void ClosePlugin_SPU2();
368     virtual void ClosePlugin_DEV9();
369     virtual void ClosePlugin_USB();
370     virtual void ClosePlugin_FW();
371     virtual void ClosePlugin_Mcd();
372    
373     friend class SysMtgsThread;
374     };
375    
376     extern const PluginInfo tbl_PluginInfo[];
377    
378     // GetPluginManager() is a required external implementation. This function is *NOT*
379     // provided by the PCSX2 core library. It provides an interface for the linking User
380 william 62 // Interface apps or DLLs to reference their own instance of SysCorePlugins (also allowing
381 william 31 // them to extend the class and override virtual methods).
382    
383 william 62 extern SysCorePlugins& GetCorePlugins();
384 william 31
385     // Hack to expose internal MemoryCard plugin:
386    
387     extern "C" const PS2E_LibraryAPI* FileMcd_InitAPI( const PS2E_EmulatorInfo* emuinfo );
388    
389     // Per ChickenLiver, this is being used to pass the GS plugins window handle to the Pad plugins.
390     // So a rename to pDisplay is in the works, but it will not, in fact, be removed.
391     extern uptr pDsp;
392    

  ViewVC Help
Powered by ViewVC 1.1.22