public void SorterCallback(UIntPtr buf, int buf_length) { unsafe { Span <byte> byteArray = new Span <byte>(buf.ToPointer(), buf_length); ByteBuffer byteBuf = new ByteBuffer(byteArray.ToArray()); var server_message = ServerMessage.GetRootAsServerMessage(byteBuf); if (server_message.Id > 0) { _messageSorter.CheckMessage(server_message); } else { if (server_message.MessageType == ServerMessageType.DeviceAdded) { var device_added_message = server_message.Message <DeviceAdded>(); var device_handle = ButtplugFFI.SendCreateDevice(_clientHandle, device_added_message.Value.Index); var attribute_dict = new Dictionary <MessageAttributeType, ButtplugMessageAttributes>(); for (var i = 0; i < device_added_message.Value.AttributesLength; ++i) { var attributes = device_added_message.Value.Attributes(i).Value; var device_message_attributes = new ButtplugMessageAttributes(attributes.FeatureCount, attributes.GetStepCountArray(), attributes.GetEndpointsArray(), attributes.GetMaxDurationArray(), null, null); attribute_dict.Add(attributes.MessageType, device_message_attributes); } var device = new ButtplugClientDevice(_messageSorter, device_handle, device_added_message.Value.Index, device_added_message.Value.Name, attribute_dict); DeviceAdded.Invoke(this, new DeviceAddedEventArgs(device)); } } } }
/* * public MessageAttributes GetMessageAttributes(Type aMsgType) * { * ButtplugUtils.ArgumentNotNull(aMsgType, nameof(aMsgType)); * if (!aMsgType.IsSubclassOf(typeof(ButtplugDeviceMessage))) * { * throw new ArgumentException("Argument must be subclass of ButtplugDeviceMessage"); * } * * if (!AllowedMessages.ContainsKey(aMsgType)) * { * throw new ButtplugDeviceException($"Message type {aMsgType.Name} not allowed for device {Name}."); * } * * return AllowedMessages[aMsgType]; * } * * public MessageAttributes GetMessageAttributes<T>() * where T : ButtplugDeviceMessage * { * return GetMessageAttributes(typeof(T)); * } */ public bool Equals(ButtplugClientDevice aDevice) { return(Index == aDevice.Index); }