1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
16 struct lcr_msg *message_first = NULL;
17 struct lcr_msg **messagepointer_end = &message_first;
19 /* creates a new message with the given attributes. the message must be filled then. after filling, the message_put must be called */
20 struct lcr_msg *message_create(int id_from, int id_to, int flow, int type)
22 struct lcr_msg *message;
24 message = (struct lcr_msg *)MALLOC(sizeof(struct lcr_msg));
26 FATAL("No memory for message.\n");
29 message->id_from = id_from;
30 message->id_to = id_to;
37 /* attaches a message to the end of the message chain */
38 void message_put(struct lcr_msg *message)
40 if (message->id_to == 0) {
41 PDEBUG(DEBUG_MSG, "message %s not written, because destination is 0.\n", messages_txt[message->type]);
42 message_free(message);
46 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
47 PDEBUG(DEBUG_MSG, "message %s written from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
49 *messagepointer_end = message;
50 messagepointer_end = &(message->next);
51 /* Nullify next pointer if recycled messages */
52 *messagepointer_end=NULL;
55 struct lcr_msg *message_forward(int id_from, int id_to, int flow, union parameter *param)
57 struct lcr_msg *message;
59 /* get point to message */
60 message = (struct lcr_msg *)((unsigned long)param - ((unsigned long)(&message->param) - (unsigned long)message));
62 /* protect, so forwarded messages are not freed after handling */
65 message->id_from = id_from;
66 message->id_to = id_to;
73 /* detaches the first messages from the message chain */
74 struct lcr_msg *message_get(void)
76 struct lcr_msg *message;
81 message = message_first;
82 message_first = message->next;
84 messagepointer_end = &message_first;
88 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 lcr_msg *message)
100 FREE(message, sizeof(struct lcr_msg));