mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 05:37:55 +00:00
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:
parent
d3cc021cca
commit
bbe9768a30
@ -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.
|
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
|
```python
|
||||||
trick_message.mtcout.init()
|
trick_message.mtcout.init()
|
||||||
trick.message_subscribe(trick_message.mtcout)
|
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
|
## Publish a message
|
||||||
|
|
||||||
To publish a message:
|
To publish a message:
|
||||||
|
@ -288,6 +288,20 @@ class MessageSimObject : public Trick::SimObject {
|
|||||||
{TRK} ("shutdown") mdevice.shutdown() ;
|
{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:
|
private:
|
||||||
// This object is not copyable
|
// This object is not copyable
|
||||||
void operator =(const MessageSimObject &) {};
|
void operator =(const MessageSimObject &) {};
|
||||||
|
Loading…
Reference in New Issue
Block a user