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;
27 message = (struct message *)MALLOC(sizeof(struct message));
29 FATAL("No memory for message.\n");
32 message->id_from = id_from;
33 message->id_to = id_to;
40 /* attaches a message to the end of the message chain */
41 void message_put(struct message *message)
43 if (message->id_to == 0)
45 PDEBUG(DEBUG_MSG, "message %s not written, because destination is 0.\n", messages_txt[message->type]);
46 message_free(message);
50 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
51 PDEBUG(DEBUG_MSG, "message %s written from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
53 *messagepointer_end = message;
54 messagepointer_end = &(message->next);
57 void message_forward(int id_from, int id_to, int flow, union parameter *param)
59 struct message *message;
61 /* get point to message */
62 message = (struct message *)((unsigned long)param - ((unsigned long)(&message->param) - (unsigned long)message));
64 /* protect, so forwarded messages are not freed after handling */
67 message->id_from = id_from;
68 message->id_to = id_to;
73 /* detaches the first messages from the message chain */
74 struct message *message_get(void)
76 struct message *message;
83 message = message_first;
84 message_first = message->next;
86 messagepointer_end = &message_first;
90 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
92 PDEBUG(DEBUG_MSG, "message %s reading from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
98 void message_free(struct message *message)
102 FREE(message, sizeof(struct message));