GNUnet 0.21.1
messenger_api_queue_messages.h File Reference
#include "gnunet_util_lib.h"
Include dependency graph for messenger_api_queue_messages.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_QueueMessage
 
struct  GNUNET_MESSENGER_QueueMessages
 

Functions

void init_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages)
 Initializes queue of messages as empty queue. More...
 
void clear_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages)
 Clears the queue of messages. More...
 
void enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages *messages, const struct GNUNET_CRYPTO_PrivateKey *sender, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript, enum GNUNET_GenericReturnValue priority)
 Adds a specific message to the end or the beginning of the queue depending on its priority. More...
 
struct GNUNET_MESSENGER_Messagedequeue_from_messages (struct GNUNET_MESSENGER_QueueMessages *messages, struct GNUNET_CRYPTO_PrivateKey *sender, struct GNUNET_MESSENGER_Message **transcript)
 Remove the message from the front of the queue and returns it. More...
 

Function Documentation

◆ init_queue_messages()

void init_queue_messages ( struct GNUNET_MESSENGER_QueueMessages messages)

Initializes queue of messages as empty queue.

Parameters
[out]messagesQueue of messages

Definition at line 32 of file messenger_api_queue_messages.c.

33{
34 GNUNET_assert (messages);
35
36 messages->head = NULL;
37 messages->tail = NULL;
38}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_QueueMessage * tail
struct GNUNET_MESSENGER_QueueMessage * head

References GNUNET_assert, GNUNET_MESSENGER_QueueMessages::head, and GNUNET_MESSENGER_QueueMessages::tail.

Referenced by create_room().

Here is the caller graph for this function:

◆ clear_queue_messages()

void clear_queue_messages ( struct GNUNET_MESSENGER_QueueMessages messages)

Clears the queue of messages.

Parameters
[in,out]messagesQueue of messages

Definition at line 42 of file messenger_api_queue_messages.c.

43{
44 GNUNET_assert (messages);
45
46 while (messages->head)
47 {
48 struct GNUNET_MESSENGER_QueueMessage *element = messages->head;
49
50 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
51
52 if (element->message)
53 destroy_message (element->message);
54
55 if (element->transcript)
56 destroy_message (element->transcript);
57
58 GNUNET_free (element);
59 }
60
61 messages->head = NULL;
62 messages->tail = NULL;
63}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Message * transcript

References destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MESSENGER_QueueMessages::head, GNUNET_MESSENGER_QueueMessage::message, GNUNET_MESSENGER_QueueMessages::tail, and GNUNET_MESSENGER_QueueMessage::transcript.

Referenced by destroy_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueue_to_messages()

void enqueue_to_messages ( struct GNUNET_MESSENGER_QueueMessages messages,
const struct GNUNET_CRYPTO_PrivateKey sender,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_MESSENGER_Message transcript,
enum GNUNET_GenericReturnValue  priority 
)

Adds a specific message to the end or the beginning of the queue depending on its priority.

Parameters
[in,out]messagesQueue of messages
[in]senderPrivate sender key
[in]messageMessage
[in]transcriptMessage transcript
[in]priorityWhether the message has priority

Definition at line 67 of file messenger_api_queue_messages.c.

72{
73 GNUNET_assert ((messages) && (sender) && (message));
74
75 struct GNUNET_MESSENGER_QueueMessage *element = GNUNET_new (struct
77
78 if (! element)
79 return;
80
81 element->message = message;
82 element->transcript = transcript;
83
84 GNUNET_memcpy (&(element->sender), sender, sizeof (element->sender));
85
86 if (! element->message)
87 {
88 if (element->transcript)
89 destroy_message (element->transcript);
90
91 GNUNET_free (element);
92 return;
93 }
94
95 if (GNUNET_YES == priority)
96 GNUNET_CONTAINER_DLL_insert (messages->head, messages->tail, element);
97 else
98 GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element);
99}
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CRYPTO_PrivateKey sender

References destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_YES, GNUNET_MESSENGER_QueueMessages::head, GNUNET_MESSENGER_QueueMessage::message, GNUNET_MESSENGER_QueueMessage::sender, GNUNET_MESSENGER_QueueMessages::tail, and GNUNET_MESSENGER_QueueMessage::transcript.

Referenced by enqueue_message_to_room().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dequeue_from_messages()

struct GNUNET_MESSENGER_Message * dequeue_from_messages ( struct GNUNET_MESSENGER_QueueMessages messages,
struct GNUNET_CRYPTO_PrivateKey sender,
struct GNUNET_MESSENGER_Message **  transcript 
)

Remove the message from the front of the queue and returns it.

Parameters
[in,out]messagesQueue of messages
[out]senderPrivate sender key
[out]transcriptMessage transcript
Returns
Message from front or NULL

Definition at line 103 of file messenger_api_queue_messages.c.

106{
107 GNUNET_assert (messages);
108
109 struct GNUNET_MESSENGER_QueueMessage *element = messages->head;
110
111 if (! element)
112 {
113 if (transcript)
114 *transcript = NULL;
115
116 return NULL;
117 }
118
119 struct GNUNET_MESSENGER_Message *message = element->message;
120
121 if (transcript)
122 *transcript = element->transcript;
123 else if (element->transcript)
124 destroy_message (element->transcript);
125
126 GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
127
128 if (sender)
129 GNUNET_memcpy (sender, &(element->sender), sizeof (*sender));
130
131 GNUNET_free (element);
132 return message;
133}

References destroy_message(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_memcpy, GNUNET_MESSENGER_QueueMessages::head, GNUNET_MESSENGER_QueueMessage::message, GNUNET_MESSENGER_QueueMessage::sender, GNUNET_MESSENGER_QueueMessages::tail, and GNUNET_MESSENGER_QueueMessage::transcript.

Referenced by dequeue_messages_from_room().

Here is the call graph for this function:
Here is the caller graph for this function: