Message Processing
The Wireless Communication Library uses an internal messaging subsystem to safely deliver hardware events
from system callbacks to your application. Choose synchronous processing (mpSync) for UI frameworks like VCL,
WinForms, or MFC, and asynchronous processing (mpAsync) for console and service applications.
Bluetooth Framework classes automatically inherit the message processing method from the
Bluetooth manager.
The Wireless Communication Library works with different hardware devices: Bluetooth, Serial, and Wi-Fi. These devices send notifications (when the device is found, connected, disconnected, etc.) to an application through callbacks in different system-defined threads. However, UI frameworks (VCL, LCL, MFC, WinForms, WPF) require that UI updates always be performed in the main UI thread. To be able to work with the UI frameworks, the Wireless Communication Library needs to synchronize those callbacks with an application's main thread. To achieve this, the Library uses an internal inter-threading communication mechanism called Messaging.
The Messaging Subsystem
The Wireless Communication Library messaging subsystem provides a universal and cross-platform easy way for inter-threading notifications. This subsystem allows sending notifications from one application's thread to another. The Library uses this subsystem to deliver system notifications from system callbacks to the Wireless Communication Library objects. The messaging subsystem notifications are called messages. Sending messages is called synchronization. Currently, the Library messaging works on Windows and macOS.
The Wireless Communication Library provides two synchronization methods called
message processing methods: synchronous and asynchronous. Each class of the Library can use its own independent synchronization
method. You can specify the message processing method by setting the MessageProcessing property. By default, synchronous
message processing is used.
The message processing methods are described by the wclMessageProcessingMethod enumeration. The enumeration defines two
values: the mpAsync is defined for asynchronous message processing, and the
mpSync is defined for synchronous message processing.
ASYNCHRONOUS MESSAGE PROCESSING
The asynchronous message processing uses a separate thread for notifications delivery. It means that all the
Wireless Communication Library classes events will be called in a separate independent thread. This message
processing method is useful for console or service applications. It can also be used in UI applications when you need to run some Library functions
in a separate thread. To switch the Wireless Communication Library component to the asynchronous message
processing set the MessageProcessing property to mpAsync.
SYNCHRONOUS MESSAGE PROCESSING
The synchronous message processing (the default one) uses Windows messages (on Windows platforms) or RunLoop and GDC (on macOS) for delivering notifications. It means that all the Wireless Communication Library classes events will be called in the same UI thread. To be able to receive the synchronous notifications (events), an application must have a UI and run a messages loop. It is possible to use synchronous message processing in non-UI threads, but such threads must have a message loop. This is the default Library messages processing method.
MESSAGE PROCESSING IN BLUETOOTH FRAMEWORK
The Bluetooth Framework manages message processing methods in a little bit different way. You can
change the message processing method of the wclBluetoothManager and the wclBleSniffer classes
only. All other Bluetooth Framework classes select a message processing method automatically. If
a class is created and used in the same thread that was used to open the wclBluetoothManager then the class will use the
Bluetooth manager's message processing method. If a class is created and used in a separate thread (other than a thread used to open the Bluetooth
manager), then it will use the asynchronous message processing method.
NOTE: Even if the audio classes are shipped with the Bluetooth Framework, formally those classes are part of the Audio Framework and use common synchronization settings as described above.
Frequently Asked Questions
- What is the Wireless Communication Library messaging subsystem?
- It is an internal inter-thread communication mechanism that synchronizes hardware event callbacks with an application's main UI thread, ensuring thread-safe UI updates.
- What is the difference between synchronous and asynchronous message processing?
- Asynchronous processing delivers events on a separate thread, ideal for console and service apps. Synchronous processing uses the main UI thread's message loop, suitable for VCL, WinForms, and MFC.
- How do I switch between processing methods?
- Set the
MessageProcessingproperty tompAsyncfor asynchronous, ormpSync(default) for synchronous delivery. In Bluetooth Framework, onlywclBluetoothManagerandwclBleSniffercan be explicitly configured; other classes follow automatically.