Exemplo n.º 1
0
        void CommandQueueListenerThread(HandshakeThreadStarter starter)
        {
            starter.DoHandshake();

            while (!starter.StopRequested)
            {
                List <TaggedBlob> blobs = this.bugBotCommandQueue.Read();
                foreach (TaggedBlob blob in blobs)
                {
                    switch (blob.Tag)
                    {
                    case TaggedBlob.TagForgetLastConnection:
                        this.tracer.Trace($"TagForgetLastConnection command received");
                        ForgetLastTCPIPDevice();
                        break;

                    case TaggedBlob.TagSwerveToolsTrayStarted:
                        UpdateTrayStatus();
                        break;

                    case TaggedBlob.TagDisarmService:
                        this.armed = false;
                        NotifyDisarmed();
                        UpdateTrayStatus();
                        break;

                    case TaggedBlob.TagArmService:
                        this.armed = true;
                        NotifyArmed();
                        UpdateTrayStatus();
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        void DeviceTrackingThread(HandshakeThreadStarter starter)
        // RULE: Once a stop is requested, we NEVER create a new socket.
        // NOTE: With that rule in place, we probably could now get by w/o doing a handshake.
        //       The issue was that our (old) code here was racing with StopDeviceTrackign(), the
        //       former creating a socket and the latter closing it to wake us up. If that happened
        //       in the wrong order, we would never wake up.
        {
            Log.d(loggingTag, "::: DeviceTrackingThread started :::");

            // Right here we know that Start() hasn't yet returned. Do the interlock and let it return.
            starter.DoHandshake();

            // Loop until asked to stop. Do that even in the face of failures and exceptions
            while (!starter.StopRequested)
            {
                try
                {
                    if (OpenSocketIfNecessary(starter))
                    {
                        // Opened a new socket. Ask the ADB server to give us device notifications
                        this.IsTrackingDevices = RequestDeviceNotifications();
                    }

                    if (this.IsTrackingDevices)
                    {
                        // read the length of the incoming message
                        int length = ReadLength(this.socketTrackDevices, new byte[4]);
                        if (length >= 0)
                        {
                            // read the incoming message
                            ProcessTrackingDevicesNotification(length);

                            // flag the fact that we have build the list at least once.
                            this.HasDeviceList = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.w(loggingTag, $"exception in DeviceTrackingThread: {e.Message}");
                    this.IsTrackingDevices = false;
                    CloseSocket(ref this.socketTrackDevices);
                }
            }

            Log.d(loggingTag, "::: DeviceTrackingThread stopped :::");
        }
Exemplo n.º 3
0
        void NotificationThreadLoop(HandshakeThreadStarter starter)
        {
            Trace(Program.LoggingTag, "===== NotificationThreadLoop start ... ");
            try {
                // Interlock with StartNotificationThread
                starter.DoHandshake();

                // Spin, waiting for kernel to make the section for us
                for (bool thrown = true; !starter.StopRequested && thrown;)
                {
                    try {
                        thrown = false;
                        this.bugBotMessageQueue.InitializeIfNecessary();
                    }
                    catch (FileNotFoundException)
                    {
                        Trace(Program.LoggingTag, "service hasn't created shared mem");
                        thrown = true;
                        Thread.Sleep(2000);
                    }
                    catch (Exception e)
                    {
                        Trace(Program.LoggingTag, $"exception thrown: {e}");
                    }
                }

                Trace(Program.LoggingTag, "===== NotificationThreadLoop listening");

                while (!starter.StopRequested)
                {
                    try {
                        // Get messages from writer. This will block until there's
                        // (probably) messages for us to read
                        Trace(Program.LoggingTag, "waiting for message...");
                        List <TaggedBlob> messages = this.bugBotMessageQueue.Read();
                        Trace(Program.LoggingTag, "...messages received");
                        if (messages.Count > 0)
                        {
                            // Separate the messages with newlines.
                            StringBuilder balloonText = new StringBuilder();
                            foreach (TaggedBlob blob in messages)
                            {
                                switch (blob.Tag)
                                {
                                case TaggedBlob.TagBugBotMessage:
                                    if (balloonText.Length > 0)
                                    {
                                        balloonText.Append("\n");
                                    }
                                    balloonText.Append(blob.Message);
                                    break;

                                case TaggedBlob.TagBugBotStatus:
                                    // Update the status text
                                    this.statusText = blob.Message;
                                    UpdateIconText();
                                    break;
                                }
                            }

                            // Display them to the user
                            if (balloonText.Length > 0)
                            {
                                ShowBalloon(balloonText.ToString());
                            }
                        }
                    }
                    catch (ThreadInterruptedException)
                    {
                        return;
                    }
                }
            }
            finally
            {
                Trace(Program.LoggingTag, "===== ... NotificationThreadLoop stop");
            }
        }