2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
28 struct message *messages; /**< All the messages that can currently be shown */
29 int last_mid; /**< Last Message ID */
30 int maxage; /**< Maximum age of messages */
31 int maxnum; /**< Maximum number of messages */
32 struct callback *msg_cleanup_cb; /**< Callback to clean up the messages */
33 struct event_timeout *msg_cleanup_to; /**< Idle event to clean up the messages */
37 message_new(struct messagelist *this_, char *message)
41 msg = g_new0(struct message, 1);
42 msg->text = g_strdup(message);
43 msg->id = ++(this_->last_mid);
44 msg->time = time(NULL);
46 msg->next = this_->messages;
47 this_->messages = msg;
53 message_delete(struct messagelist *this_, int mid)
55 struct message *msg,*last;;
57 msg = this_->messages;
71 last->next = msg->next;
73 this_->messages = msg->next;
86 message_cleanup(struct messagelist *this_)
88 struct message *msg,*next,*prev=NULL;
92 msg = this_->messages;
97 while (msg && (i < this_->maxnum)) {
98 if ((this_->maxage > 0) && (now - msg->time) > this_->maxage) {
110 this_->messages = NULL;
124 *messagelist_new(struct attr **attrs)
126 struct messagelist *this = g_new0(struct messagelist, 1);
127 struct attr num_attr,age_attr;
129 if (attr_generic_get_attr(attrs, NULL, attr_message_maxage, &age_attr, NULL)) {
130 this->maxage = age_attr.u.num;
135 if (attr_generic_get_attr(attrs, NULL, attr_message_maxnum, &num_attr, NULL)) {
136 this->maxnum = num_attr.u.num;
145 messagelist_init(struct messagelist *this_)
147 this_->msg_cleanup_cb = callback_new_1(callback_cast(message_cleanup), this_);
148 this_->msg_cleanup_to = event_add_timeout(1000, 1, this_->msg_cleanup_cb);
152 *message_get(struct messagelist *this_)
154 return this_->messages;