/[pcsx2_0.9.7]/trunk/pcsx2/gui/AppEventListeners.h
ViewVC logotype

Contents of /trunk/pcsx2/gui/AppEventListeners.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File MIME type: text/plain
File size: 8813 byte(s)
re-commit (had local access denied errors when committing)
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 #include "Utilities/EventSource.h"
19 #include "Utilities/pxEvents.h"
20
21 enum CoreThreadStatus
22 {
23 CoreThread_Indeterminate,
24 CoreThread_Started,
25 CoreThread_Resumed,
26 CoreThread_Suspended,
27 CoreThread_Reset,
28 CoreThread_Stopped,
29 };
30
31 enum AppEventType
32 {
33 AppStatus_SettingsLoaded,
34 AppStatus_SettingsSaved,
35 AppStatus_SettingsApplied,
36 AppStatus_Exiting
37 };
38
39 enum PluginEventType
40 {
41 CorePlugins_Loaded,
42 CorePlugins_Init,
43 CorePlugins_Opening, // dispatched prior to plugins being opened
44 CorePlugins_Opened, // dispatched after plugins are opened
45 CorePlugins_Closing, // dispatched prior to plugins being closed
46 CorePlugins_Closed, // dispatched after plugins are closed
47 CorePlugins_Shutdown,
48 CorePlugins_Unloaded,
49 };
50
51 struct AppEventInfo
52 {
53 AppEventType evt_type;
54
55 AppEventInfo( AppEventType type )
56 {
57 evt_type = type;
58 }
59 };
60
61 struct AppSettingsEventInfo : AppEventInfo
62 {
63 IniInterface& m_ini;
64
65 AppSettingsEventInfo( IniInterface& ini );
66
67 IniInterface& GetIni() const
68 {
69 return const_cast<IniInterface&>(m_ini);
70 }
71 };
72
73 // --------------------------------------------------------------------------------------
74 // IEventListener_CoreThread
75 // --------------------------------------------------------------------------------------
76 class IEventListener_CoreThread : public IEventDispatcher<CoreThreadStatus>
77 {
78 public:
79 typedef CoreThreadStatus EvtParams;
80
81 public:
82 virtual ~IEventListener_CoreThread() throw() {}
83
84 virtual void DispatchEvent( const CoreThreadStatus& status );
85
86 protected:
87 virtual void CoreThread_OnStarted() {}
88 virtual void CoreThread_OnResumed() {}
89 virtual void CoreThread_OnSuspended() {}
90 virtual void CoreThread_OnReset() {}
91 virtual void CoreThread_OnStopped() {}
92 };
93
94 class EventListener_CoreThread : public IEventListener_CoreThread
95 {
96 public:
97 EventListener_CoreThread();
98 virtual ~EventListener_CoreThread() throw();
99 };
100
101 // --------------------------------------------------------------------------------------
102 // IEventListener_Plugins
103 // --------------------------------------------------------------------------------------
104 class IEventListener_Plugins : public IEventDispatcher<PluginEventType>
105 {
106 public:
107 typedef PluginEventType EvtParams;
108
109 public:
110 virtual ~IEventListener_Plugins() throw() {}
111
112 virtual void DispatchEvent( const PluginEventType& pevt );
113
114 protected:
115 virtual void CorePlugins_OnLoaded() {}
116 virtual void CorePlugins_OnInit() {}
117 virtual void CorePlugins_OnOpening() {} // dispatched prior to plugins being opened
118 virtual void CorePlugins_OnOpened() {} // dispatched after plugins are opened
119 virtual void CorePlugins_OnClosing() {} // dispatched prior to plugins being closed
120 virtual void CorePlugins_OnClosed() {} // dispatched after plugins are closed
121 virtual void CorePlugins_OnShutdown() {}
122 virtual void CorePlugins_OnUnloaded() {}
123 };
124
125 class EventListener_Plugins : public IEventListener_Plugins
126 {
127 public:
128 EventListener_Plugins();
129 virtual ~EventListener_Plugins() throw();
130 };
131
132 // --------------------------------------------------------------------------------------
133 // IEventListener_AppStatus
134 // --------------------------------------------------------------------------------------
135 class IEventListener_AppStatus : public IEventDispatcher<AppEventInfo>
136 {
137 public:
138 typedef AppEventInfo EvtParams;
139
140 public:
141 virtual ~IEventListener_AppStatus() throw() {}
142
143 virtual void DispatchEvent( const AppEventInfo& evtinfo );
144
145 protected:
146 virtual void AppStatusEvent_OnSettingsLoadSave( const AppSettingsEventInfo& evtinfo ) {}
147 virtual void AppStatusEvent_OnSettingsApplied() {}
148 virtual void AppStatusEvent_OnExit() {}
149 };
150
151 class EventListener_AppStatus : public IEventListener_AppStatus
152 {
153 public:
154 EventListener_AppStatus();
155 virtual ~EventListener_AppStatus() throw();
156 };
157
158 // --------------------------------------------------------------------------------------
159 // EventListenerHelpers (CoreThread / Plugins / AppStatus)
160 // --------------------------------------------------------------------------------------
161 // Welcome to the awkward world of C++ multi-inheritence. wxWidgets' Connect() system is
162 // incompatible because of limitations in C++ class member function pointers, so we need
163 // this second layer class to act as a bridge between the event system and the class's
164 // handler implementations.
165 //
166 // Explained in detail: The class that wants to listen to shit will implement its expected
167 // virtual overrides from the listener classes (OnCoreThread_Started, for example), and then
168 // it adds an instance of the EventListenerHelper_CoreThread class to itself, instead of
169 // *inheriting* from it. Thusly, the Helper gets initialized when the class is created,
170 // and when events are dispatched to the listener, it forwards the event to the main class.
171 // --air
172
173 template< typename TypeToDispatchTo >
174 class EventListenerHelper_CoreThread : public EventListener_CoreThread
175 {
176 public:
177 TypeToDispatchTo& Owner;
178
179 public:
180 EventListenerHelper_CoreThread( TypeToDispatchTo& dispatchTo )
181 : Owner( dispatchTo ) { }
182
183 EventListenerHelper_CoreThread( TypeToDispatchTo* dispatchTo )
184 : Owner( *dispatchTo )
185 {
186 pxAssume(dispatchTo != NULL);
187 }
188
189 virtual ~EventListenerHelper_CoreThread() throw() {}
190
191 protected:
192 void OnCoreThread_Indeterminate() { Owner.OnCoreThread_Indeterminate(); }
193 void CoreThread_OnStarted() { Owner.OnCoreThread_Started(); }
194 void CoreThread_OnResumed() { Owner.OnCoreThread_Resumed(); }
195 void CoreThread_OnSuspended() { Owner.OnCoreThread_Suspended(); }
196 void CoreThread_OnReset() { Owner.OnCoreThread_Reset(); }
197 void CoreThread_OnStopped() { Owner.OnCoreThread_Stopped(); }
198 };
199
200 template< typename TypeToDispatchTo >
201 class EventListenerHelper_Plugins : public EventListener_Plugins
202 {
203 public:
204 TypeToDispatchTo& Owner;
205
206 public:
207 EventListenerHelper_Plugins( TypeToDispatchTo& dispatchTo )
208 : Owner( dispatchTo ) { }
209
210 EventListenerHelper_Plugins( TypeToDispatchTo* dispatchTo )
211 : Owner( *dispatchTo )
212 {
213 pxAssume(dispatchTo != NULL);
214 }
215
216 virtual ~EventListenerHelper_Plugins() throw() {}
217
218 protected:
219 void CorePlugins_OnLoaded() { Owner.OnCorePlugins_Loaded(); }
220 void CorePlugins_OnInit() { Owner.OnCorePlugins_Init(); }
221 void CorePlugins_OnOpening() { Owner.OnCorePlugins_Opening(); }
222 void CorePlugins_OnOpened() { Owner.OnCorePlugins_Opened(); }
223 void CorePlugins_OnClosing() { Owner.OnCorePlugins_Closing(); }
224 void CorePlugins_OnClosed() { Owner.OnCorePlugins_Closed(); }
225 void CorePlugins_OnShutdown() { Owner.OnCorePlugins_Shutdown(); }
226 void CorePlugins_OnUnloaded() { Owner.OnCorePlugins_Unloaded(); }
227 };
228
229 template< typename TypeToDispatchTo >
230 class EventListenerHelper_AppStatus : public EventListener_AppStatus
231 {
232 public:
233 TypeToDispatchTo& Owner;
234
235 public:
236 EventListenerHelper_AppStatus( TypeToDispatchTo& dispatchTo )
237 : Owner( dispatchTo ) { }
238
239 EventListenerHelper_AppStatus( TypeToDispatchTo* dispatchTo )
240 : Owner( *dispatchTo )
241 {
242 pxAssume(dispatchTo != NULL);
243 }
244
245 virtual ~EventListenerHelper_AppStatus() throw() {}
246
247 protected:
248 virtual void AppStatusEvent_OnSettingsLoadSave( const AppSettingsEventInfo& evtinfo ) { Owner.AppStatusEvent_OnSettingsLoadSave( evtinfo ); }
249 virtual void AppStatusEvent_OnSettingsApplied() { Owner.AppStatusEvent_OnSettingsApplied(); }
250 virtual void AppStatusEvent_OnExit() { Owner.AppStatusEvent_OnExit(); }
251 };
252
253
254 // --------------------------------------------------------------------------------------
255 // CoreThreadStatusEvent
256 // --------------------------------------------------------------------------------------
257 class CoreThreadStatusEvent : public pxActionEvent
258 {
259 typedef pxActionEvent _parent;
260
261 protected:
262 CoreThreadStatus m_evt;
263
264 public:
265 virtual ~CoreThreadStatusEvent() throw() {}
266 CoreThreadStatusEvent* Clone() const { return new CoreThreadStatusEvent( *this ); }
267
268 explicit CoreThreadStatusEvent( CoreThreadStatus evt, SynchronousActionState* sema=NULL );
269 explicit CoreThreadStatusEvent( CoreThreadStatus evt, SynchronousActionState& sema );
270
271 void SetEventType( CoreThreadStatus evt ) { m_evt = evt; }
272 CoreThreadStatus GetEventType() { return m_evt; }
273
274 protected:
275 void InvokeEvent();
276 };

  ViewVC Help
Powered by ViewVC 1.1.22