private void OnDeviceDisconnected(object sender, DeviceDataEventArgs args) { var dev = args.Device; Debug.WriteLine($"Device disconnected {dev.Name}[{dev.Model}/{dev.Serial}]"); DeviceDisconnected?.Invoke(this, args); }
/// <summary> /// Invokes the <see cref="DeviceDisconnected"/> event. /// </summary> /// <param name="device"></param> protected void OnDeviceDisconnected(Device device) { if (DeviceDisconnected != null) { DeviceDisconnected.Invoke(device); } }
private void DeviceOnDisconnected(DeviceEventArgs args) { lock (_connectedDevices) { _connectedDevices.Remove(args.Device); } DeviceDisconnected?.Invoke(args.Device); }
public void DisconnectDevice(IDevice device) { connectedDevices.Remove(device); var args = new DeviceConnectionEventArgs(); args.Device = device; DeviceDisconnected?.Invoke(this, args); }
/// <summary> /// Callback method that MdsLib calls when a device disconnects from MdsLib /// </summary> /// <param name="MACaddress"></param> public void OnDisconnect(string MACaddress) { Debug.WriteLine($"SUCCESS MdsConnectionListener OnDisconnect callback called: MACaddress {MACaddress}"); var uuid = GetUuidFromMACAddress(MACaddress); var serial = string.Empty; this.UuidToSerialMapper.TryGetValue(uuid, out serial); DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uuid)); }
private void AxLEDeviceConnectionLost(object sender, IDevice device) { var serial = _devices.SingleOrDefault(d => d.Value.Id == device.Id).Key; if (!string.IsNullOrEmpty(serial)) { DeviceDisconnected?.Invoke(this, serial); } }
private void DisconnectArrived(object sender, EventArrivedEventArgs e) { if (IsConnected) { if (!InitialChek()) { IsConnected = false; DeviceDisconnected?.Invoke(); } } }
protected void InvokeDeviceDisconnected() { try { DeviceDisconnected?.Invoke(this); } catch (Exception e) { UPnPConfiguration.LOGGER.Warn("DeviceConnection: Error invoking DeviceDisconnected delegate", e); } }
private void BluetoothDevice_ConnectionStatusChanged(BluetoothDevice sender, object args) { if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected) { if (connectedDevices.ContainsKey(sender.DeviceId)) { var device = connectedDevices[sender.DeviceId]; connectedDevices.Remove(device.deviceInfo.Id); DeviceDisconnected?.Invoke(device); } } }
public async void OpenServer() { TokenSource = new CancellationTokenSource(); IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(Utils.GetLocalIp()), port); try { listener.Bind(localEndPoint); listener.Listen(10); await Task.Run(() => { try { newDebugMessage(this, $"Server started accepting connections at {Utils.GetLocalIp().ToString()}:{port}"); IsRunning = true; while (!TokenSource.Token.IsCancellationRequested) { var handler = listener.Accept(); var connectedItem = new TCPConnector(handler); connectedItem.disconnected += (sender, arg) => { var connector = sender as TCPConnector; lock (ConnectedClients) ConnectedClients.Remove(connector); DeviceDisconnected?.Invoke(this, connector); connector.Dispose(); }; connectedItem.newError += (sender2, err2) => { this.newError(this, err2); }; connectedItem.StartListening(); lock (ConnectedClients) ConnectedClients.Add(connectedItem); newDeviceConnected?.Invoke(this, connectedItem); } IsRunning = false; } catch (Exception e) { IsRunning = false; if (!((e as SocketException).NativeErrorCode == 10004)) //error code for "async task canceled" { newError?.Invoke(this, e); } } }); } catch (Exception e) { newError?.Invoke(this, e); } }
private void Disconnection(bool stopListen = true) { CheckDisposed(); DeviceDisconnecting?.Invoke(this); Disconnect(); client?.Close(); client?.Dispose(); if (stopListen) { StopListen(); } DeviceDisconnected?.Invoke(this); }
public BleAdapter(IAdapter adapter) { _adapter = adapter; _adapter.DeviceDiscovered += (sender, args) => DeviceDiscovered?.Invoke(sender, BleDevice.Wrap(args.Device)); _adapter.DeviceConnected += (sender, args) => DeviceConnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>()); _adapter.DeviceDisconnected += (sender, args) => DeviceDisconnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>()); _adapter.ScanTimeoutElapsed += (sender, args) => ScanTimeoutElapsed?.Invoke(sender, args); }
public void Disconnect() { if (ConnectedDevice == null) { return; } DeviceDisconnecting?.Invoke(this, EventArgs.Empty); ConnectedDevice.Dispose(); ConnectedDevice = null; DeviceDisconnected?.Invoke(this, EventArgs.Empty); }
private void OnDisconnected() { if (!Monitor.TryEnter(this)) { return; } try { DeviceDisconnected?.Invoke(this, EventArgs.Empty); } finally { Monitor.Exit(this); } }
private void Watcher_EventArrived(object sender, EventArrivedEventArgs e) { bool connected = IsDeviceConnected(); if (!Connected && connected) { Trace.WriteLine("Device Connected: " + DeviceName); Connected = true; DeviceConnected?.Invoke(this, null); } else if (Connected && !connected) { Trace.WriteLine("Device Disconnected: " + DeviceName); Connected = false; DeviceDisconnected?.Invoke(this, null); } }
private void Heartbeat(object state) { if (!_socket.Connected && IsConnected) { DeviceDisconnected?.Invoke(); IsConnected = false; } if (!IsConnected) { // Try reconnect try { ConnectSocket(); DeviceConnected?.Invoke(); } catch (Exception e) { IsConnected = false; } } try { var response = Ping(); Span<byte> statusSpan = Serialize<DacStatusDto>(response.DacStatus); var dacStatus = DacStatus.ParseDacStatus(statusSpan); var ack = DacResponse.ParseAckCode(response.Response); StatusUpdated?.Invoke(ack, dacStatus.BufferFullness); } catch (Exception e) { } }
/// <summary> /// Callback function that MdsLib calls when an exception is thrown during device connection /// </summary> /// <param name="e"></param> public void OnError(Com.Movesense.Mds.MdsException e) { // Unexpected device disconnections come in here if (e.Message.StartsWith("com.polidea.rxandroidble.exceptions.BleDisconnectedException")) { var msgParts = e.Message.Split(" "); string MACaddress = msgParts[msgParts.Length - 1]; var uuid = GetUuidFromMACAddress(MACaddress); Debug.WriteLine($"DISCONNECT MdsConnectionListener OnError callback called for unintended disconnection: MACaddress {MACaddress}"); var serial = string.Empty; this.UuidToSerialMapper.TryGetValue(uuid, out serial); DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uuid)); } else { // Other unexpected error Debug.WriteLine($"ERROR MdsConnectionListener OnError callback called for unexpected error: {e.ToString()}"); DeviceConnectionError?.Invoke(this, new MdsException("MdsConnectionListener unexpected error", e)); } }
/// <summary> /// Callback method that MdsLib calls when a device connects or disconnects /// </summary> /// <param name="mdsevent">details of device connection/disconnection</param> public void OnDeviceConnectionEvent(MDSEvent mdsevent) { var method = ((NSString)mdsevent.BodyDictionary.ValueForKey(new NSString("Method"))); if (method == new NSString("POST")) { // Device connected var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body")); var serial = ((NSString)bodyDict.ValueForKey(new NSString("Serial"))).ToString(); var connDict = (NSDictionary)bodyDict.ValueForKey(new NSString("Connection")); var uuid = ((NSString)connDict.ValueForKey(new NSString("UUID"))).ToString(); var uniqueIDGuid = new Guid(uuid); this.UuidToSerialMapper.TryAdd(uniqueIDGuid, serial); Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent CONNECTED: Serial {serial}"); DeviceConnected?.Invoke(this, new MdsConnectionListenerBLEConnectedEventArgs(uuid)); DeviceConnectionComplete?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uniqueIDGuid)); } else if (method == new NSString("DEL")) { // Device disconnected var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body")); var serial = ((NSString)bodyDict.ValueForKey(new NSString("Serial"))).ToString(); // Get the matching Uuid var uniqueIDGuid = this.UuidToSerialMapper.First(kv => kv.Value == serial).Key; Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent DISCONNECTED: Serial {serial}"); DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uniqueIDGuid)); } else { throw new MdsException($"OnDeviceConnectionEvent unexpected method: {method}"); } }
/// <summary>Raises the <see cref="E:RAPISink.DeviceDisconnected"/> event.</summary> public void OnDeviceDisconnected(IRAPIDevice pIDevice) { DeviceDisconnected?.Invoke(this, new DeviceConnectEventArgs(pIDevice)); }
private void OnDeviceDisconnectedEvent() { DeviceDisconnected?.Invoke(this, new EventArgs()); }
public async Task CheckForDevicesAsync(CancellationToken cancellationToken = default) { try { if (_IsDisposed) { return; } await _ListenSemaphoreSlim.WaitAsync(cancellationToken).ConfigureAwait(false); var connectedDeviceDefinitions = (await DeviceFactory.GetConnectedDeviceDefinitionsAsync(cancellationToken).ConfigureAwait(false)).ToList(); //Iterate through connected devices foreach (var connectedDeviceDefinition in connectedDeviceDefinitions) { //TODO: What to do if there are multiple? IDevice device = null; if (_CreatedDevicesByDefinition.ContainsKey(connectedDeviceDefinition.DeviceId)) { device = _CreatedDevicesByDefinition[connectedDeviceDefinition.DeviceId]; } if (device == null) { //Need to use the connected device def here instead of the filter version because the filter version won't have the id or any details device = await DeviceFactory.GetDeviceAsync(connectedDeviceDefinition, cancellationToken).ConfigureAwait(false); if (device == null) { _logger.LogWarning("A connected device with id {deviceId} was detected but the factory didn't create an instance of it. Bad stuff is going to happen now.", connectedDeviceDefinition.DeviceId); } else { _CreatedDevicesByDefinition.Add(connectedDeviceDefinition.DeviceId, device); } } else { if (device.IsInitialized) { continue; } } _logger.LogDebug("Attempting to initialize with DeviceId of {deviceId}", device.DeviceId); //The device is not initialized so initialize it await device.InitializeAsync(cancellationToken).ConfigureAwait(false); //Let listeners know a registered device was initialized DeviceInitialized?.Invoke(this, new DeviceEventArgs(device)); _logger.LogDebug(Messages.InformationMessageDeviceConnected, device.DeviceId); } var removeDeviceIds = new List <string>(); //Iterate through registered devices foreach (var deviceId in _CreatedDevicesByDefinition.Keys) { var device = _CreatedDevicesByDefinition[deviceId]; if (connectedDeviceDefinitions.Any(cdd => cdd.DeviceId == deviceId)) { continue; } if (!device.IsInitialized) { continue; } //Let listeners know a registered device was disconnected //NOTE: let the rest of the app know before disposal so that the app can stop doing whatever it's doing. DeviceDisconnected?.Invoke(this, new DeviceEventArgs(device)); //The device is no longer connected so close it device.Close(); removeDeviceIds.Add(deviceId); _logger.LogDebug(Messages.InformationMessageDeviceListenerDisconnected); } foreach (var deviceId in removeDeviceIds) { _ = _CreatedDevicesByDefinition.Remove(deviceId); } _logger.LogDebug(Messages.InformationMessageDeviceListenerPollingComplete); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { //Log and move on _logger.LogError(ex, Messages.ErrorMessagePollingError); //TODO: What else to do here? } finally { if (!_IsDisposed) { _ = _ListenSemaphoreSlim.Release(); } } }
public override void OnDeviceDisconnected() => DeviceDisconnected?.Invoke();
protected virtual void OnDeviceDisconnected(BleDeviceEventArgs args) { DeviceDisconnected?.Invoke(this, args); }
public void OnDeviceDisconnected() { DeviceDisconnected?.Invoke(null, null); }
protected virtual void OnDeviceDisconnected(IDeviceService device) { DeviceDisconnected?.Invoke(device); }
/// <summary>Raises the <see cref="E:RemoteDeviceManager.DeviceDisconnected"/> event.</summary> private void OnDeviceDisconnected(RemoteDevice dev) { DeviceDisconnected?.Invoke(null, new RemoteDeviceConnectEventArgs(dev)); }
void hidDevice_Removed() { Device.CloseDevice(); DeviceDisconnected?.Invoke(); }
public async Task CheckForDevicesAsync() { try { if (_IsDisposed) { return; } await _ListenSemaphoreSlim.WaitAsync(); var connectedDeviceDefinitions = new List <ConnectedDeviceDefinition>(); foreach (var deviceDefinition in FilterDeviceDefinitions) { connectedDeviceDefinitions.AddRange(await DeviceManager.Current.GetConnectedDeviceDefinitionsAsync(deviceDefinition)); } //Iterate through connected devices foreach (var connectedDeviceDefinition in connectedDeviceDefinitions) { var deviceDefinition = FilterDeviceDefinitions.FirstOrDefault(d => DeviceManager.IsDefinitionMatch(d, connectedDeviceDefinition)); if (deviceDefinition == null) { continue; } //TODO: What to do if there are multiple? IDevice device = null; if (_CreatedDevicesByDefinition.ContainsKey(deviceDefinition)) { device = _CreatedDevicesByDefinition[deviceDefinition]; } if (device == null) { //Need to use the connected device def here instead of the filter version because the filter version won't have the id or any details device = DeviceManager.Current.GetDevice(connectedDeviceDefinition); _CreatedDevicesByDefinition.Add(deviceDefinition, device); } if (device.IsInitialized) { continue; } Log($"Attempting to initialize with DeviceId of {device.DeviceId}", null); //The device is not initialized so initialize it await device.InitializeAsync(); //Let listeners know a registered device was initialized DeviceInitialized?.Invoke(this, new DeviceEventArgs(device)); Log(Messages.InformationMessageDeviceConnected, null); } var removeDefs = new List <FilterDeviceDefinition>(); //Iterate through registered devices foreach (var filteredDeviceDefinitionKey in _CreatedDevicesByDefinition.Keys) { var device = _CreatedDevicesByDefinition[filteredDeviceDefinitionKey]; if (connectedDeviceDefinitions.Any(cdd => DeviceManager.IsDefinitionMatch(filteredDeviceDefinitionKey, cdd))) { continue; } if (!device.IsInitialized) { continue; } //Let listeners know a registered device was disconnected //NOTE: let the rest of the app know before disposal so that the app can stop doing whatever it's doing. DeviceDisconnected?.Invoke(this, new DeviceEventArgs(device)); //The device is no longer connected so close it device.Close(); removeDefs.Add(filteredDeviceDefinitionKey); Log(Messages.InformationMessageDeviceListenerDisconnected, null); } foreach (var removeDef in removeDefs) { _CreatedDevicesByDefinition.Remove(removeDef); } Log(Messages.InformationMessageDeviceListenerPollingComplete, null); } catch (Exception ex) { Log(Messages.ErrorMessagePollingError, ex); //TODO: What else to do here? } finally { if (!_IsDisposed) { _ListenSemaphoreSlim.Release(); } } }
void OnUpdate() { if (m_MessageProvider == null) { return; } if (m_MessageProvider.HasExited) { Stop(); if (DeviceDisconnected != null) { DeviceDisconnected.Invoke(Device.Id); } return; } List <LogEntry> entries = new List <LogEntry>(); lock (m_CachedLogLines) { if (m_CachedLogLines.Count == 0) { return; } var needFilterByPid = !m_Device.SupportsFilteringByPid && PackagePid > 0; var needFilterByTags = Tags != null && Tags.Length > 0; var needFilterBySearch = !m_Device.SupportsFilteringByRegex && !string.IsNullOrEmpty(Filter); Regex regex = LogParseRegex; foreach (var logLine in m_CachedLogLines) { var m = regex.Match(logLine); if (!m.Success) { // The reason we need to check `needFilterByTags` is we don't really want to show the error logs that we can't parse if a tag is chosen. // For logs we can't parse, please refer to https://gitlab.cds.internal.unity3d.com/upm-packages/mobile/mobile-android-logcat/issues/44 // And we should remove this check once #44 is fixed completely. if (!needFilterByTags) { entries.Add(LogEntryParserErrorFor(logLine)); } continue; } if (needFilterByPid && Int32.Parse(m.Groups["pid"].Value) != PackagePid) { continue; } if (needFilterByTags && !MatchTagsFilter(m.Groups["tag"].Value)) { continue; } if (needFilterBySearch && !MatchSearchFilter(m.Groups["msg"].Value)) { continue; } entries.Add(ParseLogEntry(m)); } m_CachedLogLines.Clear(); } if (entries.Count == 0) { return; } ResolveStackTrace(entries); LogEntriesAdded(entries); }
private void OnDeviceDisconnected(IDevice device) { CurConnectDeves.Remove(device); DeviceDisconnected?.Invoke(device); }