1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (message_queue.h).
5 * ---------------------------------------------------------------------------------------
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:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
23 #ifndef __LIBRETRO_SDK_MSG_QUEUE_H
24 #define __LIBRETRO_SDK_MSG_QUEUE_H
28 #include <retro_common_api.h>
33 enum message_queue_icon
35 MESSAGE_QUEUE_ICON_DEFAULT = 0 /* default icon is tied to category */
38 enum message_queue_category
40 MESSAGE_QUEUE_CATEGORY_INFO = 0,
41 MESSAGE_QUEUE_CATEGORY_ERROR,
42 MESSAGE_QUEUE_CATEGORY_WARNING,
43 MESSAGE_QUEUE_CATEGORY_SUCCESS
46 typedef struct queue_elem
52 enum message_queue_icon icon;
53 enum message_queue_category category;
56 typedef struct msg_queue
68 enum message_queue_icon icon;
69 enum message_queue_category category;
76 * @size : maximum size of message
78 * Creates a message queue with maximum size different messages.
80 * Returns: NULL if allocation error, pointer to a message queue
81 * if successful. Has to be freed manually.
83 msg_queue_t *msg_queue_new(size_t size);
85 bool msg_queue_initialize(msg_queue_t *queue, size_t size);
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).
96 * Push a new message onto the queue.
98 void msg_queue_push(msg_queue_t *queue, const char *msg,
99 unsigned prio, unsigned duration,
101 enum message_queue_icon icon, enum message_queue_category category);
105 * @queue : pointer to queue object
107 * Pulls highest priority message in queue.
109 * Returns: NULL if no message in queue, otherwise a string
110 * containing the message.
112 const char *msg_queue_pull(msg_queue_t *queue);
116 * @queue : pointer to queue object
117 * @queue_entry : pointer to external queue entry struct
119 * Removes highest priority message from queue, copying
120 * contents into queue_entry struct.
122 * Returns: false if no messages in queue, otherwise true
124 bool msg_queue_extract(msg_queue_t *queue, msg_queue_entry_t *queue_entry);
128 * @queue : pointer to queue object
130 * Fetches number of messages in queue.
132 * Returns: Number of messages in queue.
134 size_t msg_queue_size(msg_queue_t *queue);
138 * @queue : pointer to queue object
140 * Clears out everything in the queue.
142 void msg_queue_clear(msg_queue_t *queue);
146 * @queue : pointer to queue object
148 * Frees message queue..
150 void msg_queue_free(msg_queue_t *queue);
152 bool msg_queue_deinitialize(msg_queue_t *queue);