Added separate_thread_set_enabled(bool) function to MessageSimObject class (#1523)

* Added separate_thread_set_enabled(bool) function to MessageSimObject class for user to use the feature of letting trick to write the messages out on a separate thread in a more intuitive way (hopefully ;-).

* Updated Status-Message-System.md for the newly added separate_thread_set_enabled(bool on_off) function in MessageSimObject class of default_trick_sys.sm

* Fixed the bullets

* Put missing update in due to merge.
This commit is contained in:
Hong Chen 2023-06-29 13:31:03 -05:00 committed by GitHub
parent d3cc021cca
commit bbe9768a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -26,13 +26,22 @@ The user may also add their own subscriber by creating a derived class from `Tri
The `MessageThreadedCout` class is included with the simulation but not activated by default. When activated messages will be written to the standard output stream like `MessageCout`, but internally we use a separate thread to do the writing. This helps real-time performance.
To activate the `MessageThreadedCout` class, add these 2 lines to the input file.
To activate the `MessageThreadedCout` class, there are two ways:
- Add these 2 lines to the input file:
```python
trick_message.mtcout.init()
trick.message_subscribe(trick_message.mtcout)
```
- Or add this line to the input file:
```python
trick_message.separate_thread_set_enabled(True)
```
`trick_message.separate_thread_set_enabled(True)` - turns on outputting messages to the standard output stream on a separate thread while turning off outputting messages to the standard output stream on the same thread and Sim Control Panel
`trick_message.separate_thread_set_enabled(False)` - turns off outputting messages to the standard output stream on a separate thread while turning on outputing messages to the standard output stream on the same thread and Sim Control Panel
## Publish a message
To publish a message:

View File

@ -288,6 +288,20 @@ class MessageSimObject : public Trick::SimObject {
{TRK} ("shutdown") mdevice.shutdown() ;
}
// Toggle log messages on separate thread on/off
void separate_thread_set_enabled(bool on_off) {
if (on_off) {
mpublisher.unsubscribe(&mcout);
mpublisher.unsubscribe(&mdevice);
mtcout.init();
mpublisher.subscribe(&mtcout);
} else {
mpublisher.unsubscribe(&mtcout);
mpublisher.subscribe(&mcout);
mpublisher.subscribe(&mdevice);
}
}
private:
// This object is not copyable
void operator =(const MessageSimObject &) {};