Beispiel #1
0
        public Command CallFunction(DeviceAddress deviceAddress, UInt16 instanceId, string name, Value[] values)
        {
            IntPtr nativeValues = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>() * values.Length);

            IntPtr currentElement = nativeValues;

            for (int i = 0; i < values.Length; i++)
            {
                Marshal.WriteIntPtr(currentElement, values[i].NativeInstance);
                currentElement += Marshal.SizeOf <IntPtr>();
            }

            IntPtr commandHandle = ControllerNative.CallFunction(m_nativeInstance, deviceAddress.NativeInstance, instanceId, name, nativeValues, values.Length);

            Marshal.FreeHGlobal(nativeValues);
            if (commandHandle == null)
            {
                return(null);
            }

            Command command = new Command(this, commandHandle, true);

            m_commands.Add(command);
            return(command);
        }
Beispiel #2
0
        internal Controller(IntPtr nativeInstance)
        {
            m_nativeInstance = nativeInstance;
            m_commands       = new List <Command>();

            m_managedCallback = HandleCallback;
            m_nativeCallback  = Marshal.GetFunctionPointerForDelegate <ControllerNative.CommandChangedDelegate>(m_managedCallback);
            ControllerNative.RegisterCommandCallback(m_nativeInstance, m_nativeCallback);
        }
Beispiel #3
0
        public Command SetProperty(DeviceAddress deviceAddress, UInt16 instanceId, string name, Value value)
        {
            IntPtr commandHandle = ControllerNative.SetProperty(m_nativeInstance, deviceAddress.NativeInstance, instanceId, name, value.NativeInstance);

            if (commandHandle == null)
            {
                return(null);
            }

            Command command = new Command(this, commandHandle, false);

            m_commands.Add(command);
            return(command);
        }
Beispiel #4
0
        public void Dispose()
        {
            while (m_commands.Count > 0)
            {
                m_commands[0].Dispose();
            }

            if (m_nativeCallback != IntPtr.Zero)
            {
                ControllerNative.UnregisterCommandCallback(m_nativeInstance, m_nativeCallback);
                m_nativeCallback  = IntPtr.Zero;
                m_managedCallback = null;
            }

            m_nativeInstance = IntPtr.Zero;
            m_commands       = null;
        }
Beispiel #5
0
 internal void ReleaseCommand(Command command)
 {
     m_commands.Remove(command);
     ControllerNative.ReleaseCommand(m_nativeInstance, command.NativeInstance);
 }