diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs b/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs index f98d334e03..3fdee56cfa 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs @@ -1,6 +1,6 @@ using System; +using System.Collections.Generic; using System.Windows.Forms; - using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.NES; @@ -11,6 +11,8 @@ namespace BizHawk.Client.EmuHawk private NES.NESSettings _oldSettings; private NES.NESSettings _settings; + public IDictionary EmulatorServices { private get; set; } + public bool AskSaveChanges() { return true; } public bool UpdateBefore { get { return false; } } public void UpdateValues() diff --git a/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs b/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs index c88bdf2d60..9a71f9bf31 100644 --- a/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs @@ -25,6 +25,8 @@ namespace BizHawk.Client.EmuHawk // Video Frame advance // Add to toolbox + public IDictionary EmulatorServices { private get; set; } + private Atari2600 _core = Global.Emulator as Atari2600; private readonly List _instructions = new List(); diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 77b0bd9067..94a8d3c987 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -19,6 +19,8 @@ namespace BizHawk.Client.EmuHawk { public partial class Cheats : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + public const string NAME = "NamesColumn"; public const string ADDRESS = "AddressColumn"; public const string VALUE = "ValueColumn"; diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index 48d04c8b26..01d35cdfc7 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -21,6 +21,8 @@ namespace BizHawk.Client.EmuHawk private IDebuggable Core; private IDisassemblable Disassembler; + public IDictionary EmulatorServices { private get; set; } + public GenericDebugger() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs b/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs index fe092ba047..0a0808b039 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs @@ -7,11 +7,14 @@ using BizHawk.Common.NumberExtensions; using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Client.EmuHawk.WinFormExtensions; +using System.Collections.Generic; namespace BizHawk.Client.EmuHawk { public partial class GBGPUView : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + // TODO: freeze semantics are a bit weird: details for a mouseover or freeze are taken from the current // state, not the state at the last callback (and so can be quite different when update is set to manual). // I'm not quite sure what's the best thing to do... diff --git a/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs b/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs index 2f4b27d5c5..4550532d1b 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs @@ -15,6 +15,8 @@ namespace BizHawk.Client.EmuHawk private readonly Dictionary _gameGenieTable = new Dictionary(); private bool _processing; + public IDictionary EmulatorServices { private get; set; } + #region Public public bool AskSaveChanges() { return true; } diff --git a/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs b/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs index 61a9f0f575..89c9e9348a 100644 --- a/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs +++ b/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs @@ -6,6 +6,7 @@ using BizHawk.Common.NumberExtensions; using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.GBA; +using System.Collections.Generic; namespace BizHawk.Client.EmuHawk { @@ -13,6 +14,8 @@ namespace BizHawk.Client.EmuHawk { IGBAGPUViewable gba; + public IDictionary EmulatorServices { private get; set; } + // emulator memory areas private IntPtr vram; private IntPtr oam; diff --git a/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs b/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs index 01ba0533aa..b8245bbbba 100644 --- a/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs @@ -50,6 +50,8 @@ namespace BizHawk.Client.EmuHawk { '9', 31 } }; + public IDictionary EmulatorServices { private get; set; } + private bool _processing; private void GenGameGenie_Load(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs index 765885316a..64725ecb99 100644 --- a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs @@ -18,6 +18,8 @@ namespace BizHawk.Client.EmuHawk private GPGX Emu; int palindex = 0; + public IDictionary EmulatorServices { private get; set; } + public GenVDPViewer() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 73dac5e938..b7462ddc60 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -22,6 +22,8 @@ namespace BizHawk.Client.EmuHawk { public partial class HexEditor : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + private bool fontSizeSet = false; private int fontWidth; private int fontHeight; diff --git a/BizHawk.Client.EmuHawk/tools/IToolForm.cs b/BizHawk.Client.EmuHawk/tools/IToolForm.cs index b67fc77c8a..3323098227 100644 --- a/BizHawk.Client.EmuHawk/tools/IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/IToolForm.cs @@ -1,7 +1,18 @@ -namespace BizHawk.Client.EmuHawk +using System; +using System.Linq; +using System.Collections.Generic; + +namespace BizHawk.Client.EmuHawk { public interface IToolForm { + /// + /// This should be used to approach any services required of the emulator + /// core. It will be populated by ToolManager with the services specified + /// in the tool's RequiredServices attribute. + /// + IDictionary EmulatorServices { set; } + /// /// Will be called by the client anytime an Update needs to occur, such as after an emulated frame, a loadstate, or a related dialog has made a relevant change /// @@ -28,7 +39,6 @@ /// bool AskSaveChanges(); - /// /// Indicates whether the tool should be updated before a frame loop or after. /// In general, tools that draw graphics from the core should update before the loop, @@ -42,4 +52,19 @@ void Close(); bool IsDisposed { get; } } + + /// + /// Attribute used for IToolForms to indicate which IEmulatorServices they + /// need. + /// + [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] + sealed class RequiredServices : Attribute + { + public readonly Type[] Dependencies; + + public RequiredServices(params Type[] requiredServices) + { + this.Dependencies = requiredServices; + } + } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 51f429e632..63878d9d77 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -19,6 +19,8 @@ namespace BizHawk.Client.EmuHawk { public partial class LuaConsole : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + private readonly LuaFileList _luaList; private int _defaultWidth; private int _defaultHeight; diff --git a/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs b/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs index 53279de39b..68eefedace 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs @@ -16,6 +16,8 @@ namespace BizHawk.Client.EmuHawk { private DatachBarcode reader; + public IDictionary EmulatorServices { private get; set; } + public BarcodeEntry() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs b/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs index fe5385b68c..54f97b4824 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs @@ -10,6 +10,8 @@ namespace BizHawk.Client.EmuHawk { public partial class NESDebugger : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + private const int ADDR_MAX = 0xFFFF; private const int DISASM_LINE_COUNT = 100; private int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs b/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs index e663dd2445..2cedefe667 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs @@ -11,6 +11,8 @@ namespace BizHawk.Client.EmuHawk { public partial class NESGameGenie : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + private readonly Dictionary _gameGenieTable = new Dictionary { { 'A', 0 }, // 0000 diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs index d97b2d35d2..b2199512dc 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs @@ -1,8 +1,8 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; - using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.NES; @@ -15,6 +15,8 @@ namespace BizHawk.Client.EmuHawk private readonly NES.PPU.DebugCallback _callback = new NES.PPU.DebugCallback(); private NES _nes; + public IDictionary EmulatorServices { private get; set; } + public NESNameTableViewer() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs index 71e7087254..c5d2737e73 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Common; +using System.Collections.Generic; namespace BizHawk.Client.EmuHawk { @@ -26,6 +27,8 @@ namespace BizHawk.Client.EmuHawk private NES _nes; private bool _forceChange; + public IDictionary EmulatorServices { private get; set; } + public NesPPU() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs index a5016a9394..03a3130722 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs @@ -1,8 +1,8 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; - using BizHawk.Client.Common; using BizHawk.Emulation.Cores.PCEngine; @@ -13,6 +13,8 @@ namespace BizHawk.Client.EmuHawk private PCEngine _pce; private int _vdcType; + public IDictionary EmulatorServices { private get; set; } + public PceBgViewer() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs index 5a48d25d3e..296f346673 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs @@ -24,6 +24,8 @@ namespace BizHawk.Client.EmuHawk private int _defaultWidth; private int _defaultHeight; + public IDictionary EmulatorServices { private get; set; } + public PCECDL() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs index fbde34e884..e4bb4139d6 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs @@ -20,6 +20,8 @@ namespace BizHawk.Client.EmuHawk { public partial class PCESoundDebugger : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + public PCESoundDebugger() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs index 0899245bdb..44ab12867d 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs @@ -22,6 +22,8 @@ namespace BizHawk.Client.EmuHawk private int bgpalnum; private int sppalnum; + public IDictionary EmulatorServices { private get; set; } + public PCETileViewer() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs b/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs index 9105897061..a381eba550 100644 --- a/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs @@ -18,6 +18,8 @@ namespace BizHawk.Client.EmuHawk private VDP vdp; int palindex = 0; + public IDictionary EmulatorServices { private get; set; } + public SmsVDPViewer() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs index c2351d705b..ce3bb1c58d 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs @@ -38,6 +38,8 @@ namespace BizHawk.Client.EmuHawk private bool _processing; + public IDictionary EmulatorServices { private get; set; } + public SNESGameGenie() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index 72de8eb797..7d1ede62b7 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -46,6 +46,8 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore { get { return false; } } public bool AskSaveChanges() { return true; } + public IDictionary EmulatorServices { private get; set; } + public void Restart() { if (Global.Emulator is LibsnesCore) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs index 9c526e8868..fbda8266a1 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs @@ -1,7 +1,11 @@ -namespace BizHawk.Client.EmuHawk +using System; +using System.Collections.Generic; +namespace BizHawk.Client.EmuHawk { public partial class TAStudio : IControlMainform { + public IDictionary EmulatorServices { private get; set; } + private bool _suppressAskSave = false; public bool WantsToControlReadOnly { get { return false; } } diff --git a/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs b/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs index c2649c6f1f..a2b80a9c54 100644 --- a/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs +++ b/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs @@ -1,6 +1,6 @@ using System; +using System.Collections.Generic; using System.Windows.Forms; - using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Calculators; @@ -8,6 +8,8 @@ namespace BizHawk.Client.EmuHawk { public partial class TI83KeyPad : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + public TI83KeyPad() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/ToolBox.cs b/BizHawk.Client.EmuHawk/tools/ToolBox.cs index 7524c6bbc9..b789cec6fd 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolBox.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolBox.cs @@ -19,6 +19,8 @@ namespace BizHawk.Client.EmuHawk { public partial class ToolBox : Form, IToolForm { + public IDictionary EmulatorServices { private get; set; } + public ToolBox() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 8fa55a57c8..3f1ad98745 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -40,6 +40,35 @@ namespace BizHawk.Client.EmuHawk return result; } + /// + /// Gets all the IEmulatorServices the tool needs, as defined in its + /// RequiredServices attribute. If no attribute is defined, returns an + /// empty array. + /// + public Type[] GetDependencies() + where T : IToolForm + { + var attribute = (RequiredServices)typeof(T) + .GetCustomAttributes(typeof(RequiredServices), false) + .FirstOrDefault(); + + if (attribute == null) + return new Type[0]; + else + return attribute.Dependencies; + } + + /// + /// Determines whether a tool is available, considering its dependencies + /// and the services provided by the emulator core. + /// + public bool IsAvailable() + where T : IToolForm + { + return GetDependencies() + .All(t => Global.Emulator.ServiceProvider.HasService(typeof(T))); + } + /// /// Determines whether a given IToolForm is already loaded /// diff --git a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index b0b13b2871..13edea5af7 100644 --- a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -26,6 +26,8 @@ namespace BizHawk.Client.EmuHawk private int _defaultWidth; private int _defaultHeight; + public IDictionary EmulatorServices { private get; set; } + public TraceLogger() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index 888205ab7b..736befbea6 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -25,6 +25,7 @@ namespace BizHawk.Client.EmuHawk } } + public IDictionary EmulatorServices { private get; set; } public bool Readonly { diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 093676ad9c..cc6086634c 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -55,6 +55,8 @@ namespace BizHawk.Client.EmuHawk public const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user public const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size ram search will support (as it will crash beyond this) + public IDictionary EmulatorServices { private get; set; } + public bool AskSaveChanges() { return true; diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 34794f1f9b..1621023541 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -39,6 +39,8 @@ namespace BizHawk.Client.EmuHawk private bool _sortReverse; private bool _paused = false; + public IDictionary EmulatorServices { private get; set; } + public RamWatch() { _core = (IMemoryDomains)Global.Emulator; // Cast is intentional, better to get a cast exception than a null reference exception later diff --git a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs index b0d653cd7c..9b09d8cb9b 100644 --- a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs +++ b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs @@ -70,17 +70,40 @@ namespace BizHawk.Emulation.Common } } + public IEmulatorService GetService(Type t) + { + if (typeof(IEmulatorService).IsAssignableFrom(t)) + { + IEmulatorService service; + + if (Services.TryGetValue(t, out service)) + return service; + else + return null; + } + else + { + throw new Exception(String.Format("Type {0} does not implement IEmulatorService.", t.Name)); + } + } + public bool HasService() where T : IEmulatorService { IEmulatorService service; - if (Services.TryGetValue(typeof(T), out service)) + return Services.TryGetValue(typeof(T), out service); + } + + public bool HasService(Type t) + { + if (typeof(IEmulatorService).IsAssignableFrom(t)) { - return true; + IEmulatorService service; + return Services.TryGetValue(t, out service); } else { - return false; + throw new Exception(String.Format("Type {0} does not implement IEmulatorService.", t.Name)); } } } diff --git a/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs b/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs index 92631749cf..e3bddd3a68 100644 --- a/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs @@ -1,4 +1,5 @@ -namespace BizHawk.Emulation.Common +using System; +namespace BizHawk.Emulation.Common { public interface IEmulatorServiceProvider { @@ -6,11 +7,22 @@ /// Returns whether or not T is available /// bool HasService() where T : IEmulatorService; + + /// + /// Returns whether or not t is available + /// + bool HasService(Type t); /// /// Returns an instance of T if T is available /// Else returns null /// IEmulatorService GetService() where T : IEmulatorService; + + /// + /// Returns an instance of t if t is available + /// Else returns null + /// + IEmulatorService GetService(Type t); } }