Skip to content

Instantly share code, notes, and snippets.

@SplittyDev
Created January 2, 2014 19:35
Show Gist options
  • Save SplittyDev/8225175 to your computer and use it in GitHub Desktop.
Save SplittyDev/8225175 to your computer and use it in GitHub Desktop.
DriverPool class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SplitsysOS_Source.Drivers
{
public static class DriverPool
{
public delegate void PassDriverFunction ();
public static List<RegisteredDriver> drivers = new List<RegisteredDriver> ();
static DriverPool ()
{
}
public static void Call (string driver, string function)
{
for (int i = 0; i < drivers.Count; i++)
{
if (drivers[i].DriverName == driver)
{
for (int j = 0; j < drivers[i].driverFunctions.Count; i++)
{
if (drivers[i].driverFunctions[j].name == function)
drivers[i].driverFunctions[j].func ();
}
}
}
}
public static RegisteredDriver Register (IDriver driver)
{
return new RegisteredDriver (driver);
}
public static void Register (RegisteredDriver drv)
{
drivers.Add (drv);
}
public class RegisteredDriver
{
public List<DriverFunction> driverFunctions = new List<DriverFunction> ();
public string DriverName;
public RegisteredDriver (IDriver driver)
{
DriverName = driver.Name;
}
public void RegisterFunction (string name, PassDriverFunction func)
{
driverFunctions.Add (new DriverFunction (name, func));
}
public class DriverFunction
{
public PassDriverFunction func;
public string name;
public DriverFunction (string name, PassDriverFunction func)
{
this.func = func;
this.name = name;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment