comparison g23m-aci/aci/aci_lst.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS (6147)
4 | Modul : aci_lst
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : Process lists in ACI
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ACI_LST_C
22 #define ACI_LST_C
23 #endif
24
25 #include "config.h"
26 #include "fixedconf.h"
27 #include "condat-features.h"
28 #include "aci_conf.h"
29
30 #include "aci_all.h"
31
32 /*==== INCLUDES ===================================================*/
33
34 #include "aci_lst.h"
35 #include "aci_mem.h"
36
37 /*==== CONSTANTS ==================================================*/
38
39 /*==== EXPORT =====================================================*/
40
41 /*==== VARIABLES ==================================================*/
42
43 /*==== FUNCTIONS ==================================================*/
44
45 /*==== TYPES ======================================================*/
46
47
48 /*
49 +--------------------------------------------------------------------+
50 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
51 | STATE : code ROUTINE : new_list |
52 +--------------------------------------------------------------------+
53
54 PURPOSE : create a new list.
55 */
56
57 GLOBAL T_ACI_LIST *new_list (void)
58 {
59 T_ACI_LIST *new_elem = NULL;
60
61 ACI_MALLOC(new_elem, sizeof(T_ACI_LIST));
62 new_elem->msg = NULL;
63 new_elem->next = NULL;
64
65 return (new_elem);
66 }
67
68 GLOBAL USHORT get_list_count (T_ACI_LIST *list)
69 {
70 T_ACI_LIST *curr;
71 USHORT count = 0;
72
73 curr = list;
74 while (curr NEQ NULL)
75 {
76 if (curr->msg NEQ NULL)
77 count++;
78
79 curr = curr->next;
80 }
81
82 return (count);
83 }
84
85 /*
86 +--------------------------------------------------------------------+
87 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
88 | STATE : code ROUTINE : insert_list |
89 +--------------------------------------------------------------------+
90
91 PURPOSE : insert a new element in an existing list.
92 - list: pointer to the list where the element is to be added
93 - buffer: pointer to the buffer containing the datas that are to
94 be written in the new element.
95 - buffer_len: length of the datas to be stored.
96
97 */
98
99 GLOBAL BOOL insert_list (T_ACI_LIST *list, void *buffer)
100 {
101 T_ACI_LIST *current;
102 T_ACI_LIST *new_elem;
103
104 if (list EQ NULL)
105 return (FALSE);
106
107 if (list->msg EQ NULL)
108 {
109 list->msg = buffer;
110 return (TRUE);
111 }
112
113 ACI_MALLOC(new_elem, sizeof(T_ACI_LIST));
114
115 new_elem->msg = buffer;
116 new_elem->next = NULL;
117
118 current = list;
119 while (current->next NEQ NULL)
120 {
121 current = (T_ACI_LIST *)current->next;
122 }
123 current->next = new_elem;
124
125 return TRUE;
126 }
127
128 /*
129 +--------------------------------------------------------------------+
130 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
131 | STATE : code ROUTINE : find_element |
132 +--------------------------------------------------------------------+
133
134 PURPOSE : find an element in a list:
135 - search_list: list to be scanned.
136 - criterium: search criterium. (source Id for instance)
137 - test_criterium: function(criterium, element) that returns TRUE if
138 the criterium is found in the element.
139
140 */
141
142 GLOBAL void *find_element (T_ACI_LIST *search_list,
143 UBYTE criterium,
144 T_LIST_FIND_FCT test_criterium)
145 {
146 T_ACI_LIST *current;
147
148 if ((search_list EQ NULL) OR (search_list->msg EQ NULL))
149 return NULL;
150
151 current = search_list;
152
153 do
154 {
155 if (current->msg NEQ NULL)
156 {
157 if (test_criterium(criterium, current->msg))
158 return (current->msg);
159 else
160 current = current->next;
161 }
162 }
163 while( current NEQ NULL );
164
165 return NULL;
166 }
167
168 /*
169 +--------------------------------------------------------------------+
170 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
171 | STATE : code ROUTINE : psi_find_element |
172 +--------------------------------------------------------------------+
173
174 PURPOSE : find an element in a list:
175 - search_list: list to be scanned.
176 - criterium: search criterium. (source Id for instance)
177 - test_criterium: function(criterium, element) that returns TRUE if
178 the criterium is found in the element.
179
180 */
181 #ifdef FF_PSI
182 GLOBAL void *psi_find_element (T_ACI_LIST *search_list,
183 U32 criterium,
184 T_LIST_FIND_FCT_PSI test_criterium)
185 {
186 T_ACI_LIST *current;
187
188 if ((search_list EQ NULL) OR (search_list->msg EQ NULL))
189 return NULL;
190
191 current = search_list;
192
193 do
194 {
195 if (current->msg NEQ NULL)
196 {
197 if (test_criterium(criterium, current->msg))
198 return (current->msg);
199 else
200 current = current->next;
201 }
202 }
203 while( current NEQ NULL );
204
205 return NULL;
206 }
207 #endif /*FF_PSI*/
208
209 /*
210 +--------------------------------------------------------------------+
211 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
212 | STATE : code ROUTINE : find_next_element |
213 +--------------------------------------------------------------------+
214
215 PURPOSE : find the next element in a list:
216 - search_list: list to be scanned.
217 - previous element
218 - criterium: search criterium. (source Id for instance)
219 - test_criterium: function(criterium, element) that returns TRUE if
220 the criterium is found in the element.
221
222 */
223 GLOBAL void *find_next_element (T_ACI_LIST *search_list,
224 void *prev_elem,
225 UBYTE criterium,
226 T_LIST_FIND_FCT test_criterium)
227 {
228 T_ACI_LIST *current;
229
230 if ((search_list EQ NULL) OR (search_list->msg EQ NULL))
231 return NULL;
232
233 current = search_list;
234
235 if (prev_elem NEQ NULL)
236 {
237 while (current NEQ NULL)
238 {
239 if (current->msg EQ prev_elem)
240 break;
241
242 current = current->next;
243 }
244 if ((current EQ NULL) OR (current->next EQ NULL))
245 return (NULL);
246
247 current = current->next;
248 }
249
250 do
251 {
252 if( test_criterium(criterium, current->msg) )
253 return (current->msg);
254 else
255 current = current->next;
256 }
257 while( current NEQ NULL );
258
259 return NULL;
260 }
261
262
263 /*
264 +--------------------------------------------------------------------+
265 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
266 | STATE : code ROUTINE : find_next_element |
267 +--------------------------------------------------------------------+
268
269 PURPOSE : find the next element in a list:
270 - search_list: list to be scanned.
271 - previous element
272 - criterium: search criterium. (source Id for instance)
273 - test_criterium: function(criterium, element) that returns TRUE if
274 the criterium is found in the element.
275
276 */
277 #ifdef FF_PSI
278 GLOBAL void *psi_find_next_element (T_ACI_LIST *search_list,
279 void *prev_elem,
280 U32 criterium,
281 T_LIST_FIND_FCT_PSI test_criterium)
282 {
283 T_ACI_LIST *current;
284
285 if ((search_list EQ NULL) OR (search_list->msg EQ NULL))
286 return NULL;
287
288 current = search_list;
289
290 if (prev_elem NEQ NULL)
291 {
292 while (current NEQ NULL)
293 {
294 if (current->msg EQ prev_elem)
295 break;
296
297 current = current->next;
298 }
299 if ((current EQ NULL) OR (current->next EQ NULL))
300 return (NULL);
301
302 current = current->next;
303 }
304
305 do
306 {
307 if( test_criterium(criterium, current->msg) )
308 return (current->msg);
309 else
310 current = current->next;
311 }
312 while( current NEQ NULL );
313
314 return NULL;
315 }
316 #endif /*FF_PSI*/
317
318 /*
319 +--------------------------------------------------------------------+
320 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
321 | STATE : code ROUTINE : remove_element |
322 +--------------------------------------------------------------------+
323
324 PURPOSE : remove a element from the list.
325
326 */
327 GLOBAL void *remove_element (T_ACI_LIST *search_list,
328 UBYTE criterium,
329 T_LIST_FIND_FCT test_criterium)
330 {
331 T_ACI_LIST *previous = NULL,
332 *current = search_list,
333 *next = NULL;
334 void *msg = NULL;
335
336 current = search_list;
337 while (current NEQ NULL)
338 {
339 if (test_criterium (criterium, current->msg))
340 {
341 msg = current->msg;
342 break;
343 }
344 previous = current;
345 current = current->next;
346 }
347
348 if (current EQ NULL)
349 return (NULL);
350
351 if (msg EQ NULL)
352 return (NULL);
353
354 /* the first element is to delete */
355 if (previous EQ NULL)
356 {
357 /* the header contains the element */
358 if (current->next EQ NULL)
359 {
360 /* one element in list */
361 current->msg = NULL;
362 }
363 else
364 {
365 /* actually deletes the second element and redirects the pointers */
366 next = current->next;
367 current->msg = next->msg;
368 current->next = next->next;
369
370 ACI_MFREE (next); }
371 }
372 else
373 {
374 previous->next = current->next;
375
376 ACI_MFREE (current);
377 }
378
379 return (msg);
380 }
381
382 #ifdef FF_PSI
383 GLOBAL void *psi_remove_element (T_ACI_LIST *search_list,
384 U32 criterium,
385 T_LIST_FIND_FCT_PSI test_criterium)
386 {
387 T_ACI_LIST *previous = NULL,
388 *current = search_list,
389 *next = NULL;
390 void *msg = NULL;
391
392 current = search_list;
393 while (current NEQ NULL)
394 {
395 if (test_criterium (criterium, current->msg))
396 {
397 msg = current->msg;
398 break;
399 }
400 previous = current;
401 current = current->next;
402 }
403
404 if (current EQ NULL)
405 return (NULL);
406
407 if (msg EQ NULL)
408 return (NULL);
409
410 /* the first element is to delete */
411 if (previous EQ NULL)
412 {
413 /* the header contains the element */
414 if (current->next EQ NULL)
415 {
416 /* one element in list */
417 current->msg = NULL;
418 }
419 else
420 {
421 /* actually deletes the second element and redirects the pointers */
422 next = current->next;
423 current->msg = next->msg;
424 current->next = next->next;
425
426 ACI_MFREE (next); }
427 }
428 else
429 {
430 previous->next = current->next;
431
432 ACI_MFREE (current);
433 }
434
435 return (msg);
436 }
437
438 #endif /*FF_PSI*/
439
440
441 /*
442 +--------------------------------------------------------------------+
443 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
444 | STATE : code ROUTINE : remove_first_element |
445 +--------------------------------------------------------------------+
446
447 PURPOSE : get and remove the first element from the list
448
449 */
450 GLOBAL void *remove_first_element (T_ACI_LIST *search_list)
451 {
452 T_ACI_LIST *next = NULL;
453 void *msg = NULL;
454
455 if ((search_list EQ NULL) OR (search_list->msg EQ NULL))
456 return (NULL);
457
458 msg = search_list->msg;
459 search_list->msg = NULL;
460
461 if (search_list->next EQ NULL)
462 return (msg);
463
464 next = search_list->next;
465 search_list->next = next->next;
466 search_list->msg = next->msg;
467
468 ACI_MFREE (next);
469
470 return (msg);
471 }
472
473 /*
474 +--------------------------------------------------------------------+
475 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
476 | STATE : code ROUTINE : get_first_element |
477 +--------------------------------------------------------------------+
478
479 PURPOSE : get the next element from the list
480 - search_list: list to be scanned.
481 - previous element
482 */
483
484 GLOBAL void *get_next_element (T_ACI_LIST *search_list,
485 void *prev_elem)
486 {
487 T_ACI_LIST *current;
488
489 if ((search_list EQ NULL) OR (search_list->msg EQ NULL))
490 return NULL;
491
492 if (prev_elem EQ NULL)
493 {
494 /* return first element */
495 return (search_list->msg);
496 }
497
498 current = search_list;
499
500 /* search the previous element */
501 while (current NEQ NULL)
502 {
503 if (current->msg EQ prev_elem)
504 {
505 break;
506 }
507 current = current->next;
508 }
509
510 /* last entry found or previous entry not found */
511 if ((current EQ NULL) OR (current->next EQ NULL))
512 {
513 return (NULL);
514 }
515
516 return (current->next->msg);
517 }
518
519 /*
520 +---------------------------------------------------------------------+
521 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST |
522 | STATE : code ROUTINE : insert_shift_list |
523 +---------------------------------------------------------------------+
524
525 PURPOSE :
526 */
527 GLOBAL BOOL insert_shift_list (T_ACI_LIST *list, void *buffer)
528 {
529 T_ACI_LIST *current;
530 T_ACI_LIST *new_elem;
531 void *old_buf;
532
533 if (list EQ NULL)
534 return (FALSE);
535
536 if (list->msg EQ NULL)
537 {
538 list->msg = buffer;
539 return (TRUE);
540 }
541 else if (list->next EQ NULL)
542 return (FALSE);
543
544 current = list;
545
546 old_buf = list->msg;
547 list->msg = list->next->msg;
548
549 new_elem = list->next;
550 list->next = list->next->next;
551
552
553 new_elem->msg = buffer;
554 new_elem->next = NULL;
555
556 while (current->next NEQ NULL)
557 {
558 current = (T_ACI_LIST *)current->next;
559 }
560 current->next = new_elem;
561
562 ACI_MFREE (old_buf);
563
564 return TRUE;
565 }
566 /**********************************************************************/