/[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 62 - (hide annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (10 years, 4 months ago) by william
File MIME type: text/plain
File size: 11249 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
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 62 DEFINE_STREAM_EXCEPTION( SaveStateLoadError, BadStream, wxLt("The savestate appears to be corrupt or incomplete.") )
61 william 31 };
62    
63 william 62 class PluginError : public RuntimeError
64 william 31 {
65 william 62 DEFINE_RUNTIME_EXCEPTION( PluginError, RuntimeError, L"Generic plugin error")
66    
67 william 31 public:
68     PluginsEnum_t PluginId;
69    
70     public:
71 william 62 explicit PluginError( PluginsEnum_t pid )
72 william 31 {
73     PluginId = pid;
74     }
75    
76     virtual wxString FormatDiagnosticMessage() const;
77     virtual wxString FormatDisplayMessage() const;
78     };
79    
80     // Plugin load errors occur when initially trying to load plugins during the
81 william 62 // creation of a SysCorePlugins object. The error may either be due to non-existence,
82 william 31 // corruption, or incompatible versioning.
83 william 62 class PluginLoadError : public PluginError
84 william 31 {
85 william 62 DEFINE_EXCEPTION_COPYTORS( PluginLoadError, PluginError )
86     DEFINE_EXCEPTION_MESSAGES( PluginLoadError )
87    
88 william 31 public:
89 william 62 wxString StreamName;
90 william 31
91 william 62 protected:
92     PluginLoadError() {}
93 william 31
94 william 62 public:
95     PluginLoadError( PluginsEnum_t pid );
96 william 31
97 william 62 virtual PluginLoadError& SetStreamName( const wxString& name ) { StreamName = name; return *this; } \
98     virtual PluginLoadError& SetStreamName( const char* name ) { StreamName = fromUTF8(name); return *this; }
99    
100 william 31 virtual wxString FormatDiagnosticMessage() const;
101     virtual wxString FormatDisplayMessage() const;
102     };
103    
104     // Thrown when a plugin fails it's init() callback. The meaning of this error is entirely
105     // dependent on the plugin and, in most cases probably never happens (most plugins do little
106     // more than a couple basic memory reservations during init)
107 william 62 class PluginInitError : public PluginError
108 william 31 {
109 william 62 DEFINE_EXCEPTION_COPYTORS( PluginInitError, PluginError )
110     DEFINE_EXCEPTION_MESSAGES( PluginInitError )
111    
112     protected:
113     PluginInitError() {}
114    
115 william 31 public:
116 william 62 PluginInitError( PluginsEnum_t pid );
117 william 31 };
118    
119     // Plugin failed to open. Typically this is a non-critical error that means the plugin has
120     // not been configured properly by the user, but may also be indicative of a system
121 william 62 class PluginOpenError : public PluginError
122 william 31 {
123 william 62 DEFINE_EXCEPTION_COPYTORS( PluginOpenError, PluginError )
124     DEFINE_EXCEPTION_MESSAGES( PluginOpenError )
125    
126     protected:
127     PluginOpenError() {}
128    
129 william 31 public:
130 william 62 explicit PluginOpenError( PluginsEnum_t pid );
131 william 31 };
132    
133     // This exception is thrown when a plugin returns an error while trying to save itself.
134     // Typically this should be a very rare occurance since a plugin typically shoudn't
135     // be doing memory allocations or file access during state saving.
136     //
137 william 62 class FreezePluginFailure : public PluginError
138 william 31 {
139 william 62 DEFINE_EXCEPTION_COPYTORS( FreezePluginFailure, PluginError )
140     DEFINE_EXCEPTION_MESSAGES( FreezePluginFailure )
141    
142     protected:
143     FreezePluginFailure() {}
144    
145 william 31 public:
146 william 62 explicit FreezePluginFailure( PluginsEnum_t pid )
147 william 31 {
148     PluginId = pid;
149     }
150    
151     virtual wxString FormatDiagnosticMessage() const;
152     virtual wxString FormatDisplayMessage() const;
153     };
154    
155 william 62 class ThawPluginFailure : public SaveStateLoadError
156 william 31 {
157 william 62 DEFINE_EXCEPTION_COPYTORS( ThawPluginFailure, SaveStateLoadError )
158     DEFINE_EXCEPTION_MESSAGES( ThawPluginFailure )
159    
160 william 31 public:
161 william 62 PluginsEnum_t PluginId;
162 william 31
163 william 62 protected:
164     ThawPluginFailure() {}
165    
166     public:
167 william 31 explicit ThawPluginFailure( PluginsEnum_t pid )
168     {
169     PluginId = pid;
170     }
171    
172     virtual wxString FormatDiagnosticMessage() const;
173     virtual wxString FormatDisplayMessage() const;
174     };
175     };
176    
177     #ifdef _MSC_VER
178     # pragma warning(pop)
179     #endif
180    
181 william 62 typedef void CALLBACK FnType_SetDir( const char* dir );
182    
183 william 31 // --------------------------------------------------------------------------------------
184     // LegacyPluginAPI_Common
185     // --------------------------------------------------------------------------------------
186     // Important: Contents of this structure must match the order of the contents of the
187     // s_MethMessCommon[] array defined in Plugins.cpp.
188     //
189     // Note: Open is excluded from this list because the GS and CDVD have custom signatures >_<
190     //
191     struct LegacyPluginAPI_Common
192     {
193     s32 (CALLBACK* Init)();
194     void (CALLBACK* Close)();
195     void (CALLBACK* Shutdown)();
196    
197     void (CALLBACK* KeyEvent)( keyEvent* evt );
198    
199 william 62 FnType_SetDir* SetSettingsDir;
200     FnType_SetDir* SetLogDir;
201    
202 william 31 s32 (CALLBACK* Freeze)(int mode, freezeData *data);
203     s32 (CALLBACK* Test)();
204     void (CALLBACK* Configure)();
205     void (CALLBACK* About)();
206    
207     LegacyPluginAPI_Common()
208     {
209     memzero( *this );
210     }
211     };
212    
213     class SaveStateBase;
214     class SysMtgsThread;
215    
216     // --------------------------------------------------------------------------------------
217     // PluginBindings
218     // --------------------------------------------------------------------------------------
219     // This structure is intended to be the "future" of PCSX2's plugin interface, and will hopefully
220 william 62 // make the current SysCorePlugins largely obsolete (with the exception of the general Load/Unload
221 william 31 // management facilities)
222     //
223     class SysPluginBindings
224     {
225     protected:
226     PS2E_ComponentAPI_Mcd* Mcd;
227    
228     public:
229     SysPluginBindings()
230     {
231     Mcd = NULL;
232     }
233    
234     bool McdIsPresent( uint port, uint slot );
235     void McdGetSizeInfo( uint port, uint slot, PS2E_McdSizeInfo& outways );
236     void McdRead( uint port, uint slot, u8 *dest, u32 adr, int size );
237     void McdSave( uint port, uint slot, const u8 *src, u32 adr, int size );
238     void McdEraseBlock( uint port, uint slot, u32 adr );
239     u64 McdGetCRC( uint port, uint slot );
240    
241 william 62 friend class SysCorePlugins;
242 william 31 };
243    
244     extern SysPluginBindings SysPlugins;
245    
246     // --------------------------------------------------------------------------------------
247 william 62 // SysCorePlugins Class
248 william 31 // --------------------------------------------------------------------------------------
249     //
250 william 62 class SysCorePlugins
251 william 31 {
252 william 62 DeclareNoncopyableObject( SysCorePlugins );
253 william 31
254     protected:
255     class PluginStatus_t
256     {
257     public:
258     PluginsEnum_t pid;
259    
260     bool IsInitialized;
261     bool IsOpened;
262    
263     wxString Filename;
264     wxString Name;
265     wxString Version;
266    
267     LegacyPluginAPI_Common CommonBindings;
268     wxDynamicLibrary Lib;
269    
270     public:
271     PluginStatus_t()
272     {
273     IsInitialized = false;
274     IsOpened = false;
275     }
276    
277     PluginStatus_t( PluginsEnum_t _pid, const wxString& srcfile );
278     virtual ~PluginStatus_t() throw() { }
279    
280     protected:
281     void BindCommon( PluginsEnum_t pid );
282     void BindRequired( PluginsEnum_t pid );
283     void BindOptional( PluginsEnum_t pid );
284     };
285    
286     const PS2E_LibraryAPI* m_mcdPlugin;
287     wxString m_SettingsFolder;
288     wxString m_LogFolder;
289     Threading::MutexRecursive m_mtx_PluginStatus;
290    
291     // Lovely hack until the new PS2E API is completed.
292     volatile u32 m_mcdOpen;
293    
294     public: // hack until we unsuck plugins...
295     ScopedPtr<PluginStatus_t> m_info[PluginId_Count];
296    
297     public:
298 william 62 SysCorePlugins();
299     virtual ~SysCorePlugins() throw();
300 william 31
301     virtual void Load( PluginsEnum_t pid, const wxString& srcfile );
302     virtual void Load( const wxString (&folders)[PluginId_Count] );
303     virtual void Unload();
304     virtual void Unload( PluginsEnum_t pid );
305    
306     bool AreLoaded() const;
307 william 62 bool AreOpen() const;
308 william 31 bool AreAnyLoaded() const;
309     bool AreAnyInitialized() const;
310    
311     Threading::Mutex& GetMutex() { return m_mtx_PluginStatus; }
312    
313 william 62 virtual bool Init();
314 william 31 virtual void Init( PluginsEnum_t pid );
315     virtual void Shutdown( PluginsEnum_t pid );
316 william 62 virtual bool Shutdown();
317 william 31 virtual void Open();
318     virtual void Open( PluginsEnum_t pid );
319     virtual void Close( PluginsEnum_t pid );
320     virtual void Close();
321    
322     virtual bool IsOpen( PluginsEnum_t pid ) const;
323     virtual bool IsInitialized( PluginsEnum_t pid ) const;
324     virtual bool IsLoaded( PluginsEnum_t pid ) const;
325    
326     virtual void Freeze( PluginsEnum_t pid, SaveStateBase& state );
327     virtual bool DoFreeze( PluginsEnum_t pid, int mode, freezeData* data );
328    
329     virtual bool KeyEvent( const keyEvent& evt );
330     virtual void Configure( PluginsEnum_t pid );
331     virtual void SetSettingsFolder( const wxString& folder );
332 william 62 virtual void SetLogFolder( const wxString& folder );
333 william 31 virtual void SendSettingsFolder();
334     virtual void SendLogFolder();
335    
336    
337     const wxString GetName( PluginsEnum_t pid ) const;
338     const wxString GetVersion( PluginsEnum_t pid ) const;
339    
340     protected:
341     virtual bool NeedsClose() const;
342     virtual bool NeedsOpen() const;
343    
344     virtual bool NeedsShutdown() const;
345     virtual bool NeedsInit() const;
346    
347     virtual bool NeedsLoad() const;
348     virtual bool NeedsUnload() const;
349    
350     virtual bool OpenPlugin_GS();
351     virtual bool OpenPlugin_CDVD();
352     virtual bool OpenPlugin_PAD();
353     virtual bool OpenPlugin_SPU2();
354     virtual bool OpenPlugin_DEV9();
355     virtual bool OpenPlugin_USB();
356     virtual bool OpenPlugin_FW();
357     virtual bool OpenPlugin_Mcd();
358    
359     void _generalclose( PluginsEnum_t pid );
360    
361     virtual void ClosePlugin_GS();
362     virtual void ClosePlugin_CDVD();
363     virtual void ClosePlugin_PAD();
364     virtual void ClosePlugin_SPU2();
365     virtual void ClosePlugin_DEV9();
366     virtual void ClosePlugin_USB();
367     virtual void ClosePlugin_FW();
368     virtual void ClosePlugin_Mcd();
369    
370     friend class SysMtgsThread;
371     };
372    
373     extern const PluginInfo tbl_PluginInfo[];
374    
375     // GetPluginManager() is a required external implementation. This function is *NOT*
376     // provided by the PCSX2 core library. It provides an interface for the linking User
377 william 62 // Interface apps or DLLs to reference their own instance of SysCorePlugins (also allowing
378 william 31 // them to extend the class and override virtual methods).
379    
380 william 62 extern SysCorePlugins& GetCorePlugins();
381 william 31
382     // Hack to expose internal MemoryCard plugin:
383    
384     extern "C" const PS2E_LibraryAPI* FileMcd_InitAPI( const PS2E_EmulatorInfo* emuinfo );
385    
386     // Per ChickenLiver, this is being used to pass the GS plugins window handle to the Pad plugins.
387     // So a rename to pDisplay is in the works, but it will not, in fact, be removed.
388     extern uptr pDsp;
389    

  ViewVC Help
Powered by ViewVC 1.1.22