snu-quiqcl / qiwis

QuIqcl Widget Integration Software
MIT License
5 stars 2 forks source link

[FEATURE] Implement Bus using PyQt's queued connection mechanism #110

Closed kangz12345 closed 1 year ago

kangz12345 commented 1 year ago

Feature you want to implement

Swift currently uses Bus system for broadcasting the messages among the apps. However, it could be implemented with queued connection mechanism of Qt.

How the feature is implemented

Current system:

  1. An app emits broadcastRequested signal with a bus name and a message.
  2. Swift routes it to the designated Bus, and push the message into its message queue.
  3. When the control flow switches to the Bus's queue consumer thread, the message is popped, and the received signal of the Bus is emitted.
  4. Swift routes it to the subscriber apps' received signals.

Suggested system:

  1. Same.
  2. broadcastRequested signal is connected as QueuedConnection, so it is queued in the main thread's queue.
  3. When the connected slot is executed by the main thread's event loop, it emits the received signal of the subscriber apps.

Additional context

The reason why we should use the queued system is that an app may abuse the broadcasting. Imagine:

  1. An app broadcasts a message.
  2. The app itself subscribes it, and as a result, it broadcasts the same message again.
  3. Then it will induce an infinite loop, freezing the GUI.

If we use the queued system, the events between each broadcast can be handled, since the control flow always returns back to the event loop immediately after broadcasting.

See also: #6.