File: Simple_Message.txt

package info (click to toggle)
yoshimi 2.3.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,976 kB
  • sloc: cpp: 62,482; sh: 94; xml: 93; python: 45; makefile: 14
file content (42 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
This is not intended to be used within the realtime threads as both push and pop use
a common semaphore. However, they are very fast so you'd probably get away with it :)

There are three calls:

void TextMsgBuffer::clear()

int TextMsgBuffer::push( string )

string TextMsgBuffer::fetch( int )

These calls are accessible to all parts of Yoshimi and provide a simple asynchronous
means of passing text between threads and functions via just the integer ID.

TextMsgBuffer::clear() is only intended to be used internally on major resets and
just adds a bit of insurance that there are no orphaned messages.

Pushing a message will return the first available ID and Popping a message makes its
ID available again.

There is a maximum of 254 possible entries at any one time, but it's unlikely that
limit will ever be reached.

The ID 255 (which has the global ID of NO_MSG) is a 'do nothing' reserved for calls
that might want to send a message... but then again might not :)

If you push an empty string you'll get back NO_MSG, and fetching NO_MSG will of
course return an empty string.



Remark by Ichthyo, 8/2019:
In order to make MiscFuncs stateless, I have extracted these functions into a
singleton TextMsgBuffer.
Moreover, I renamed the "miscMsgPop" function into "fetch", since this obviously is
not a stack, so the name "pop" might be misleading.

Update by Will, ?/2023
There is an extra parameter to decide whether or not to clear a message when it is
fetched. This defaults to 'true' however there are times (especially in development)
when you might want to look at a message without removing it, so setting this to
false will show the message, but leave it in place.