1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
19 struct message *message_first = NULL;
20 struct message **messagepointer_end = &message_first;
23 //PMutex mutex_message;
26 /* creates a new message with the given attributes. the message must be filled then. after filling, the message_put must be called */
27 struct message *message_create(int id_from, int id_to, int flow, int type)
29 struct message *message;
34 message = (struct message *)calloc(1, sizeof(struct message));
39 PERROR("no mem for message, retrying...\n");
45 PERROR("***Fatal error: no mem for message!!! exitting.\n");
50 memset(message, 0, sizeof(struct message));
52 message->id_from = id_from;
53 message->id_to = id_to;
60 /* attaches a message to the end of the message chain */
61 void message_put(struct message *message)
63 /* the mutex prevents from creating two messages at a time (h323 thread and main thread). */
65 // mutex_message.Wait();
68 if (message->id_to == 0)
70 PDEBUG(DEBUG_MSG, "message %s not written, because destination is 0.\n", messages_txt[message->type]);
71 message_free(message);
75 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
76 PDEBUG(DEBUG_MSG, "message %s written from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
78 *messagepointer_end = message;
79 messagepointer_end = &(message->next);
82 // mutex_message.Signal();
87 /* detaches the first messages from the message chain */
88 struct message *message_get(void)
90 struct message *message;
92 /* the mutex prevents from getting a message while creating a messages at a time (h323 thread and main thread). */
94 // mutex_message.Wait();
100 // mutex_message.Signal();
105 message = message_first;
106 message_first = message->next;
108 messagepointer_end = &message_first;
111 // mutex_message.Signal();
114 if ((options.deb&DEBUG_MSG) && message->type != MESSAGE_DATA)
115 PDEBUG(DEBUG_MSG, "message %s reading from %ld to %ld (memory %x)\n", messages_txt[message->type], message->id_from, message->id_to, message);
121 void message_free(struct message *message)
123 memset(message, 0, sizeof(struct message));