Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* Copyright (C) 2010-2020 The RetroArch team |
2 | * | |
3 | * --------------------------------------------------------------------------------------- | |
4 | * The following license statement only applies to this file (message_queue.h). | |
5 | * --------------------------------------------------------------------------------------- | |
6 | * | |
7 | * Permission is hereby granted, free of charge, | |
8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), | |
9 | * to deal in the Software without restriction, including without limitation the rights to | |
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | |
11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef __LIBRETRO_SDK_MSG_QUEUE_H | |
24 | #define __LIBRETRO_SDK_MSG_QUEUE_H | |
25 | ||
26 | #include <stddef.h> | |
27 | ||
28 | #include <retro_common_api.h> | |
29 | #include <boolean.h> | |
30 | ||
31 | RETRO_BEGIN_DECLS | |
32 | ||
33 | enum message_queue_icon | |
34 | { | |
35 | MESSAGE_QUEUE_ICON_DEFAULT = 0 /* default icon is tied to category */ | |
36 | }; | |
37 | ||
38 | enum message_queue_category | |
39 | { | |
40 | MESSAGE_QUEUE_CATEGORY_INFO = 0, | |
41 | MESSAGE_QUEUE_CATEGORY_ERROR, | |
42 | MESSAGE_QUEUE_CATEGORY_WARNING, | |
43 | MESSAGE_QUEUE_CATEGORY_SUCCESS | |
44 | }; | |
45 | ||
46 | typedef struct queue_elem | |
47 | { | |
48 | char *msg; | |
49 | char *title; | |
50 | unsigned duration; | |
51 | unsigned prio; | |
52 | enum message_queue_icon icon; | |
53 | enum message_queue_category category; | |
54 | } queue_elem_t; | |
55 | ||
56 | typedef struct msg_queue | |
57 | { | |
58 | char *tmp_msg; | |
59 | queue_elem_t **elems; | |
60 | size_t ptr; | |
61 | size_t size; | |
62 | } msg_queue_t; | |
63 | ||
64 | typedef struct | |
65 | { | |
66 | unsigned duration; | |
67 | unsigned prio; | |
68 | enum message_queue_icon icon; | |
69 | enum message_queue_category category; | |
70 | char msg[1024]; | |
71 | char title[1024]; | |
72 | } msg_queue_entry_t; | |
73 | ||
74 | /** | |
75 | * msg_queue_new: | |
76 | * @size : maximum size of message | |
77 | * | |
78 | * Creates a message queue with maximum size different messages. | |
79 | * | |
80 | * Returns: NULL if allocation error, pointer to a message queue | |
81 | * if successful. Has to be freed manually. | |
82 | **/ | |
83 | msg_queue_t *msg_queue_new(size_t size); | |
84 | ||
85 | bool msg_queue_initialize(msg_queue_t *queue, size_t size); | |
86 | ||
87 | /** | |
88 | * msg_queue_push: | |
89 | * @queue : pointer to queue object | |
90 | * @msg : message to add to the queue | |
91 | * @prio : priority level of the message | |
92 | * @duration : how many times the message can be pulled | |
93 | * before it vanishes (E.g. show a message for | |
94 | * 3 seconds @ 60fps = 180 duration). | |
95 | * | |
96 | * Push a new message onto the queue. | |
97 | **/ | |
98 | void msg_queue_push(msg_queue_t *queue, const char *msg, | |
99 | unsigned prio, unsigned duration, | |
100 | char *title, | |
101 | enum message_queue_icon icon, enum message_queue_category category); | |
102 | ||
103 | /** | |
104 | * msg_queue_pull: | |
105 | * @queue : pointer to queue object | |
106 | * | |
107 | * Pulls highest priority message in queue. | |
108 | * | |
109 | * Returns: NULL if no message in queue, otherwise a string | |
110 | * containing the message. | |
111 | **/ | |
112 | const char *msg_queue_pull(msg_queue_t *queue); | |
113 | ||
114 | /** | |
115 | * msg_queue_extract: | |
116 | * @queue : pointer to queue object | |
117 | * @queue_entry : pointer to external queue entry struct | |
118 | * | |
119 | * Removes highest priority message from queue, copying | |
120 | * contents into queue_entry struct. | |
121 | * | |
122 | * Returns: false if no messages in queue, otherwise true | |
123 | **/ | |
124 | bool msg_queue_extract(msg_queue_t *queue, msg_queue_entry_t *queue_entry); | |
125 | ||
126 | /** | |
127 | * msg_queue_size: | |
128 | * @queue : pointer to queue object | |
129 | * | |
130 | * Fetches number of messages in queue. | |
131 | * | |
132 | * Returns: Number of messages in queue. | |
133 | **/ | |
134 | size_t msg_queue_size(msg_queue_t *queue); | |
135 | ||
136 | /** | |
137 | * msg_queue_clear: | |
138 | * @queue : pointer to queue object | |
139 | * | |
140 | * Clears out everything in the queue. | |
141 | **/ | |
142 | void msg_queue_clear(msg_queue_t *queue); | |
143 | ||
144 | /** | |
145 | * msg_queue_free: | |
146 | * @queue : pointer to queue object | |
147 | * | |
148 | * Frees message queue.. | |
149 | **/ | |
150 | void msg_queue_free(msg_queue_t *queue); | |
151 | ||
152 | bool msg_queue_deinitialize(msg_queue_t *queue); | |
153 | ||
154 | RETRO_END_DECLS | |
155 | ||
156 | #endif |