1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
19 struct message *message_first = NULL;
20 struct message **messagepointer_end = &message_first;
22 /* creates a new message with the given attributes. the message must be filled then. after filling, the message_put must be called */
23 struct message *message_create(int id_from, int id_to, int flow, int type)
25 struct message *message;
30 message = (struct message *)calloc(1, sizeof(struct message));
35 PERROR("no mem for message, retrying...\n");
41 PERROR("***Fatal error: no mem for message!!! exitting.\n");
46 memset(message, 0, sizeof(struct message));
48 message->id_from = id_from;
49 message->id_to = id_to;
56 /* attaches a message to the end of the message chain */
57 void message_put(struct message *message)
59 if (message->id_to == 0)
61 PDEBUG(DEBUG_MSG, "message %s not written, because destination is 0.\n", messages_txt[message->type]);
62 message_free(message);
66 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
67 PDEBUG(DEBUG_MSG, "message %s written from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
69 *messagepointer_end = message;
70 messagepointer_end = &(message->next);
74 /* detaches the first messages from the message chain */
75 struct message *message_get(void)
77 struct message *message;
84 message = message_first;
85 message_first = message->next;
87 messagepointer_end = &message_first;
89 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
90 PDEBUG(DEBUG_MSG, "message %s reading from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
96 void message_free(struct message *message)
98 memset(message, 0, sizeof(struct message));