/// <summary> /// Loads a native with the specified name. /// </summary> /// <param name="name">The name.</param> /// <param name="sizes">The references to the parameter which contains the size of array parameters.</param> /// <param name="parameterTypes">The parameter types.</param> /// <returns> /// The loaded native. /// </returns> public INative Load(string name, int[] sizes, Type[] parameterTypes) { try { if (parameterTypes == null || parameterTypes.Length == 0) { var handle = Interop.LoadNative(name, string.Empty, null); var native = new DefaultNative(name, handle, parameterTypes); _handles[handle] = native; return(native); } else { // Compute the parameter format string. string format; var lengthIndices = ComputeFormatString(parameterTypes, out format); var handle = Interop.LoadNative(name, format, (sizes?.Length ?? 0) == 0 ? lengthIndices : sizes); var native = new DefaultNative(name, handle, parameterTypes); _handles[handle] = native; return(native); } } catch (Exception e) { FrameworkLog.WriteLine(FrameworkMessageLevel.Debug, "Native load failure ({0})", name); return(null); } }
/// <summary> /// Registers the specified command. /// </summary> /// <param name="command">The command.</param> public virtual void Register(ICommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } FrameworkLog.WriteLine(FrameworkMessageLevel.Debug, $"Registering command {command}"); _commands.Add(command); }
/// <summary> /// Invokes the native with the specified arguments. /// </summary> /// <param name="arguments">The arguments.</param> /// <returns>The return value of the native.</returns> public int Invoke(params object[] arguments) { if (Sync.IsRequired) { FrameworkLog.WriteLine(FrameworkMessageLevel.Debug, $"Call to native handle {this} is being synchronized."); return(Sync.RunSync(() => CastArgsAndInvoke(arguments))); } return(CastArgsAndInvoke(arguments)); }
/// <summary> /// Adds a <see cref="IController" /> to this collection and remove controllers it overrides. /// </summary> /// <param name="controller">The <see cref="IController" /> to add to this collection.</param> public void Override(IController controller) { var overrides = this.Where(c => c.GetType().IsInstanceOfType(controller)).ToArray(); if (overrides.Any()) { FrameworkLog.WriteLine(FrameworkMessageLevel.Debug, $"{controller} overrides {string.Join(", ", (object[]) overrides)}"); } foreach (var c in overrides) { Remove(c); } _controllers.Add(controller); }