protected override bool ReleaseHandle()
 {
     if (!this.IsInvalid)
     {
         ButtplugFFICalls.buttplug_free_device(handle);
     }
     return(true);
 }
        internal static ButtplugFFIClientHandle SendCreateClient(string aClientName, ButtplugCallback aCallback)
        {
            var builder           = new FlatBufferBuilder(1024);
            var client_name       = builder.CreateString(aClientName);
            var create_client_msg = CreateClient.CreateCreateClient(builder, client_name);

            builder.Finish(create_client_msg.Value);
            var buf = builder.SizedByteArray();

            return(ButtplugFFICalls.buttplug_create_client(aCallback, buf, buf.Length));
        }
        internal static ButtplugFFIDeviceHandle SendCreateDevice(ButtplugFFIClientHandle aHandle, uint aDeviceIndex)
        {
            var builder = new FlatBufferBuilder(128);

            CreateDevice.StartCreateDevice(builder);
            CreateDevice.AddIndex(builder, aDeviceIndex);
            var get_device_msg = CreateDevice.EndCreateDevice(builder);

            builder.Finish(get_device_msg.Value);
            var buf = builder.SizedByteArray();

            return(ButtplugFFICalls.buttplug_create_device(aHandle, buf, buf.Length));
        }
        internal static Task <ServerMessage> SendClientMessage(ButtplugFFIMessageSorter aSorter, ButtplugFFIClientHandle aHandle, FlatBufferBuilder aBuilder, ClientMessageType aType, int aOffset)
        {
            ClientMessage.StartClientMessage(aBuilder);
            ClientMessage.AddMessageType(aBuilder, aType);
            ClientMessage.AddMessage(aBuilder, aOffset);
            var task = aSorter.PrepareClientMessage(aBuilder);
            var create_client_msg = CreateClient.EndCreateClient(aBuilder);

            aBuilder.Finish(create_client_msg.Value);
            var buf = aBuilder.SizedByteArray();

            ButtplugFFICalls.buttplug_parse_client_message(aHandle, buf, buf.Length);
            return(task);
        }
        internal static Task <ServerMessage> SendDeviceMessage(ButtplugFFIMessageSorter aSorter, ButtplugFFIDeviceHandle aHandle, uint aDeviceIndex, FlatBufferBuilder aBuilder, DeviceMessageType aType, int aOffset)
        {
            DeviceMessage.StartDeviceMessage(aBuilder);
            DeviceMessage.AddMessageType(aBuilder, aType);
            DeviceMessage.AddMessage(aBuilder, aOffset);
            DeviceMessage.AddDeviceIndex(aBuilder, aDeviceIndex);
            var task       = aSorter.PrepareClientMessage(aBuilder);
            var device_msg = DeviceMessage.EndDeviceMessage(aBuilder);

            aBuilder.Finish(device_msg.Value);
            var buf = aBuilder.SizedByteArray();

            ButtplugFFICalls.buttplug_parse_device_message(aHandle, buf, buf.Length);
            return(task);
        }