static extern int UWK_Update(ref Command cmd);
static extern uint UWK_PostCommand(ref Command command);
/// <summary> /// Ticks the plugin /// </summary> public static void Update() { Command cmd = new Command (); while (true) { int ret = UWK_Update (ref cmd); if (ret != 0) ProcessCommand (ref cmd); else break; } }
/// <summary> /// Processes either a return or inbound command /// </summary> public static void ProcessCommand(ref Command cmd) { if (cmd.src == Source.PLUGIN) { if (ProcessReturn != null) ProcessReturn (null, new CommandProcessEventArgs (cmd)); } else { CommandProcessEventArgs args = new CommandProcessEventArgs (cmd); if (ProcessInbound != null) { ProcessInbound (null, args); } // post return, ensuring that retcode is valid if (args.Cmd.retCode == 0) args.Cmd.retCode = 1; PostCommand (ref args.Cmd); } }
/// <summary> /// Posts a command to the command queue and retrieves an id number /// </summary> public static void PostCommand(ref Command cmd) { cmd.id = UWK_PostCommand (ref cmd); if (cmd.id == 0) throw new Exception ("Unable to Post Command"); }
public CommandProcessEventArgs(Command cmd) { this.Cmd = cmd; }
public CommandHandler(ref Command cmd) { this.cmd = cmd; Plugin.ProcessReturn += OnProcessReturn; }
/// <summary> /// Allocate a new command with the given fourcc and variable number of int/string parameters /// </summary> public static Command NewCommand(string fourcc, params object[] parms) { Command cmd = new Command (); cmd.Init (); cmd.fourcc = fourcc; foreach (object o in parms) { if (o.GetType () == typeof(int)) { cmd.iParams[cmd.numIParams++] = (int)o; } else if (o.GetType () == typeof(float)) { cmd.iParams[cmd.numIParams++] = (int) ((float) o ); } else if (o.GetType () == typeof(string)) { cmd.SetSParam (cmd.numSParams++, (string)o); } else { throw new Exception ("Unknown command parameter type: " + o.GetType ()); } } return cmd; }