/[zanavi_public1]/navit/navit/messages.c
ZANavi

Diff of /navit/navit/messages.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2 Revision 27
55 struct message *msg,*last;; 55 struct message *msg,*last;;
56 56
57 msg = this_->messages; 57 msg = this_->messages;
58 last = NULL; 58 last = NULL;
59 59
60 while (msg) { 60 while (msg)
61 {
61 if (msg->id == mid) { 62 if (msg->id == mid)
63 {
62 break; 64 break;
63 } 65 }
64 66
65 last = msg; 67 last = msg;
66 msg = msg->next; 68 msg = msg->next;
67 } 69 }
68 70
69 if (msg) { 71 if (msg)
72 {
70 if (last) { 73 if (last)
74 {
71 last->next = msg->next; 75 last->next = msg->next;
76 }
72 } else { 77 else
78 {
73 this_->messages = msg->next; 79 this_->messages = msg->next;
74 } 80 }
75 81
76 g_free(msg->text); 82 g_free(msg->text);
77 g_free(msg); 83 g_free(msg);
78 84
79 return 1; 85 return 1;
80 } else { 86 }
87 else
88 {
81 return 0; 89 return 0;
82 } 90 }
83} 91}
84 92
85static void 93static void
92 msg = this_->messages; 100 msg = this_->messages;
93 101
94 now = time(NULL); 102 now = time(NULL);
95 103
96 i = 0; 104 i = 0;
97 while (msg && (i < this_->maxnum)) { 105 while (msg && (i < this_->maxnum))
106 {
98 if ((this_->maxage > 0) && (now - msg->time) > this_->maxage) { 107 if ((this_->maxage > 0) && (now - msg->time) > this_->maxage)
108 {
99 break; 109 break;
100 } 110 }
101 111
102 i++; 112 i++;
103 prev = msg; 113 prev = msg;
104 msg = msg->next; 114 msg = msg->next;
105 } 115 }
106 116
107 if (prev) { 117 if (prev)
118 {
108 prev->next = NULL; 119 prev->next = NULL;
109 } else { 120 }
121 else
122 {
110 this_->messages = NULL; 123 this_->messages = NULL;
111 } 124 }
112 125
113 while (msg) { 126 while (msg)
127 {
114 next = msg->next; 128 next = msg->next;
115 129
116 g_free(msg->text); 130 g_free(msg->text);
117 g_free(msg); 131 g_free(msg);
118 132
124*messagelist_new(struct attr **attrs) 138*messagelist_new(struct attr **attrs)
125{ 139{
126 struct messagelist *this = g_new0(struct messagelist, 1); 140 struct messagelist *this = g_new0(struct messagelist, 1);
127 struct attr num_attr,age_attr; 141 struct attr num_attr,age_attr;
128 142
129 if (attr_generic_get_attr(attrs, NULL, attr_message_maxage, &age_attr, NULL)) { 143 if (attr_generic_get_attr(attrs, NULL, attr_message_maxage, &age_attr, NULL))
144 {
130 this->maxage = age_attr.u.num; 145 this->maxage = age_attr.u.num;
131 } else { 146 }
147 else
148 {
132 this->maxage = 10; 149 this->maxage = 10;
133 } 150 }
134 151
135 if (attr_generic_get_attr(attrs, NULL, attr_message_maxnum, &num_attr, NULL)) { 152 if (attr_generic_get_attr(attrs, NULL, attr_message_maxnum, &num_attr, NULL))
153 {
136 this->maxnum = num_attr.u.num; 154 this->maxnum = num_attr.u.num;
137 } else { 155 }
156 else
157 {
138 this->maxnum = 3; 158 this->maxnum = 3;
139 } 159 }
140 160
141 return this; 161 return this;
142} 162}
143 163
144void 164void
145messagelist_init(struct messagelist *this_) 165messagelist_init(struct messagelist *this_)
146{ 166{
147 if (!event_system()) 167 if (!event_system())
168 {
148 return; 169 return;
170 }
149 this_->msg_cleanup_cb = callback_new_1(callback_cast(message_cleanup), this_); 171 this_->msg_cleanup_cb = callback_new_1(callback_cast(message_cleanup), this_);
172 // 10 secs. delay
150 this_->msg_cleanup_to = event_add_timeout(1000, 1, this_->msg_cleanup_cb); 173 this_->msg_cleanup_to = event_add_timeout(10000, 1, this_->msg_cleanup_cb);
151} 174}
152 175
153struct message 176struct message
154*message_get(struct messagelist *this_) 177*message_get(struct messagelist *this_)
155{ 178{
156 return this_->messages; 179 return this_->messages;
157} 180}
181

Legend:
Removed from v.2  
changed lines
  Added in v.27

   
Visit the ZANavi Wiki