OpenCPN Partial API docs
|
This is a basic notify-listen framework on top of wxWidgets. It requires C++11 and wxWidgets 3.0+.
Library is thread-safe in the sense that Notify() can be invoked from asynchronous worker threads. However, actual work performed by Listen() must be done in the main thread.
The listening mechanism makes it possible for a listener to receive an event on certain condtions. The event is based on wxCommandEvent and can thus optionally carry a string, a number and/or a pointer to the listening side. It has been extended to also be able to carry a shared_ptr<void>
which basically makes it possible to transfer any shared_ptr from the notifying side to the listeners.
There are three out of the box use cases:
The framework is developed in the opencpn project [1].
The basic event handling in wxWidgets has some limitations which this framework addresses:
std::shared_ptr
. Framework supports this by using a new event type which can carry also a std::shared_ptr
.The framework can be extended to handle other types. The basic condition is that anything which should use Listen() and Notify() should implement the KeyProvider interface. This is just the ability to return a unique, stable key.
Stated otherwise, the key used when invoking Listen() should be the same as when doing Notify(). Examples includes:
In the OpenCPN project the framework is extended to handle messages. Each message implements the KeyProvider interface which generates a key based on the message "type". This makes it possible to listen for specific message types as well as notifying when such a message is received.
This work is copyright (c) Alec Leamas 2021-2022. It is distributed under the GPL licence, version 2 or later. See the source files for details.