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

  ViewVC Help
Powered by ViewVC 1.1.22