Exemple #1
0
        /// <summary>
        /// Registers the client with a Selector.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: void register(java.nio.channels.Selector sel) throws java.io.IOException
        internal virtual void register(Selector sel)
        {
            if (mChan != null)
            {
                mChan.register(sel, SelectionKey.OP_READ, this);
            }
        }
Exemple #2
0
        /// <summary>
        /// Starts a monitoring service for a device. </summary>
        /// <param name="device"> the device to monitor. </param>
        /// <returns> true if success. </returns>
        private bool startMonitoringDevice(Device device)
        {
            SocketChannel socketChannel = openAdbConnection();

            if (socketChannel != null)
            {
                try
                {
                    bool result = sendDeviceMonitoringRequest(socketChannel, device);
                    if (result)
                    {
                        if (mSelector == null)
                        {
                            startDeviceMonitorThread();
                        }

                        device.clientMonitoringSocket = socketChannel;

                        lock (mDevices)
                        {
                            // always wakeup before doing the register. The synchronized block
                            // ensure that the selector won't select() before the end of this block.
                            // @see deviceClientMonitorLoop
                            mSelector.wakeup();

                            socketChannel.configureBlocking(false);
                            socketChannel.register(mSelector, SelectionKey.OP_READ, device);
                        }

                        return(true);
                    }
                }
                catch (TimeoutException)
                {
                    try
                    {
                        // attempt to close the socket if needed.
                        socketChannel.close();
                    }
                    catch (IOException)
                    {
                        // we can ignore that one. It may already have been closed.
                    }
                    Log.d("DeviceMonitor", "Connection Failure when starting to monitor device '" + device + "' : timeout");
                }
                catch (AdbCommandRejectedException e)
                {
                    try
                    {
                        // attempt to close the socket if needed.
                        socketChannel.close();
                    }
                    catch (IOException)
                    {
                        // we can ignore that one. It may already have been closed.
                    }
                    Log.d("DeviceMonitor", "Adb refused to start monitoring device '" + device + "' : " + e.Message);
                }
                catch (IOException e)
                {
                    try
                    {
                        // attempt to close the socket if needed.
                        socketChannel.close();
                    }
                    catch (IOException)
                    {
                        // we can ignore that one. It may already have been closed.
                    }
                    Log.d("DeviceMonitor", "Connection Failure when starting to monitor device '" + device + "' : " + e.Message);
                }
            }

            return(false);
        }