public static unsafe void Process(InputRemoting receiver, Message msg) { var manager = receiver.m_LocalManager; fixed(byte *dataPtr = msg.data) { var dataEndPtr = new IntPtr(dataPtr + msg.data.Length); var eventCount = 0; var eventPtr = new InputEventPtr((InputEvent *)dataPtr); var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); while ((Int64)eventPtr.data < dataEndPtr.ToInt64()) { // Patch up device ID to refer to local device and send event. var remoteDeviceId = eventPtr.deviceId; var localDeviceId = receiver.FindLocalDeviceId(remoteDeviceId, senderIndex); eventPtr.deviceId = localDeviceId; if (localDeviceId != InputDevice.InvalidDeviceId) { ////TODO: add API to send events in bulk rather than one by one manager.QueueEvent(eventPtr); } ++eventCount; eventPtr = eventPtr.Next(); } } }
public static void Process(InputRemoting receiver, Message msg) { ////REVIEW: we probably don't want to do this blindly var layoutName = Encoding.UTF8.GetString(msg.data); receiver.m_LocalManager.RemoveControlLayout(layoutName); }
public static unsafe Message Create(InputRemoting sender, InputEvent *events, int eventCount) { // Find total size of event buffer we need. var totalSize = 0u; var eventPtr = new InputEventPtr(events); for (var i = 0; i < eventCount; ++i, eventPtr = eventPtr.Next()) { totalSize += eventPtr.sizeInBytes; } // Copy event data to buffer. Would be nice if we didn't have to do that // but unfortunately we need a byte[] and can't just pass the 'events' IntPtr // directly. var data = new byte[totalSize]; fixed(byte *dataPtr = data) { UnsafeUtility.MemCpy(dataPtr, events, totalSize); } // Done. return(new Message { type = MessageType.NewEvents, data = data }); }
public static Message?Create(InputRemoting sender, string layoutName) { // Try to load the layout. Ignore the layout if it couldn't // be loaded. InputControlLayout layout; try { layout = sender.m_LocalManager.TryLoadControlLayout(new InternedString(layoutName)); if (layout == null) { Debug.Log(string.Format( "Could not find layout '{0}' meant to be sent through remote connection; this should not happen", layoutName)); return(null); } } catch (Exception exception) { Debug.Log(string.Format( "Could not load layout '{0}'; not sending to remote listeners (exception: {1})", layoutName, exception)); return(null); } var json = layout.ToJson(); var bytes = Encoding.UTF8.GetBytes(json); return(new Message { type = MessageType.NewLayout, data = bytes }); }
public static void Process(InputRemoting receiver, Message msg) { Debug.Log("DisconnectMsg.Process"); receiver.RemoveRemoteDevices(msg.participantId); receiver.StopSending(); }
public static Message Create(InputRemoting sender, InputDevice device) { return(new Message { type = MessageType.RemoveDevice, data = BitConverter.GetBytes(device.id) }); }
public static void Process(InputRemoting receiver, Message msg) { var json = Encoding.UTF8.GetString(msg.data); var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); receiver.m_LocalManager.RegisterControlLayout(json); ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].layouts, json); }
public static Message Create(InputRemoting sender, string layoutName) { var bytes = Encoding.UTF8.GetBytes(layoutName); return(new Message { type = MessageType.RemoveLayout, data = bytes }); }
public static void Process(InputRemoting receiver, Message msg) { if (receiver.sending) { receiver.SendAllDevices(); } else if ((receiver.m_Flags & Flags.StartSendingOnConnect) == Flags.StartSendingOnConnect) { receiver.StartSending(); } }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); var remoteDeviceId = BitConverter.ToInt32(msg.data, 0); var device = receiver.TryGetDeviceByRemoteId(remoteDeviceId, senderIndex); if (device != null) { receiver.m_LocalManager.RemoveDevice(device); } }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); var data = DeserializeData <Data>(msg.data); // Make sure we haven't already seen the device. var devices = receiver.m_Senders[senderIndex].devices; if (devices != null) { foreach (var entry in devices) { if (entry.remoteId == data.deviceId) { Debug.LogError(string.Format( "Already received device with id {0} (layout '{1}', description '{3}) from remote {2}", data.deviceId, data.layout, msg.participantId, data.description)); return; } } } // Create device. InputDevice device; try { ////REVIEW: this gives remote devices names the same way that local devices receive them; should we make remote status visible in the name? device = receiver.m_LocalManager.AddDevice(data.layout); device.m_ParticipantId = msg.participantId; } catch (Exception exception) { Debug.LogError( $"Could not create remote device '{data.description}' with layout '{data.layout}' locally (exception: {exception})"); return; } device.m_Description = data.description; device.m_DeviceFlags |= InputDevice.DeviceFlags.Remote; // Remember it. var record = new RemoteInputDevice { remoteId = data.deviceId, localId = device.id, description = data.description, layoutName = data.layout }; ArrayHelpers.Append(ref receiver.m_Senders[senderIndex].devices, record); }
public static Message Create(InputRemoting sender, InputDevice device) { var data = new Data { deviceId = device.id, usages = device.usages.Select(x => x.ToString()).ToArray() }; return(new Message { type = MessageType.ChangeUsages, data = SerializeData(data) }); }
public static void Process(InputRemoting receiver, Message msg) { var senderIndex = receiver.FindOrCreateSenderRecord(msg.participantId); var data = DeserializeData <Data>(msg.data); var device = receiver.TryGetDeviceByRemoteId(data.deviceId, senderIndex); if (device != null) { ////TODO: clearing usages and setting multiple usages if (data.usages.Length == 1) { receiver.m_LocalManager.SetUsage(device, new InternedString(data.usages[0])); } } }
public static Message Create(InputRemoting sender, InputDevice device) { Debug.Assert(!device.remote, "Device being sent to remotes should be a local device, not a remote one"); var data = new Data { name = device.name, layout = device.layout, deviceId = device.id, description = device.description }; var json = JsonUtility.ToJson(data); var bytes = Encoding.UTF8.GetBytes(json); return(new Message { type = MessageType.NewDevice, data = bytes }); }
public static void Process(InputRemoting receiver, Message msg) { receiver.StopSending(); }
public static void Process(InputRemoting receiver) { receiver.StartSending(); }