automotive-dlt
dlt-kpi-process-list.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
27 #include "dlt-kpi-process-list.h"
28 
30 {
31  DltKpiProcessList *new_list = malloc(sizeof(DltKpiProcessList));
32  if(new_list == NULL)
33  {
34  fprintf(stderr, "%s: Cannot create process list, out of memory\n", __func__);
35  return NULL;
36  }
37 
38  memset(new_list, 0, sizeof(DltKpiProcessList));
39  new_list->start = new_list->cursor = NULL;
40 
41  return new_list;
42 }
43 
45 {
46  if(list == NULL)
47  {
48  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
50  }
51 
52  free(list);
53 
54  return DLT_RETURN_OK;
55 }
56 
58 {
59  if(list == NULL)
60  {
61  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
63  }
64 
65  DltKpiProcess *tmp;
66 
67  list->cursor = list->start;
68  while(list->cursor != NULL)
69  {
70  tmp = list->cursor->next;
72  list->cursor = tmp;
73  }
74 
75  return dlt_kpi_free_process_list_soft(list);
76 }
77 
79 {
80  if(list == NULL)
81  {
82  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
83  return NULL;
84  }
85 
86  return list->cursor;
87 }
88 
90 {
91  if(list == NULL)
92  {
93  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
95  }
96 
97  list->cursor = list->start;
98  return DLT_RETURN_OK;
99 }
100 
102 {
103  if(list == NULL)
104  {
105  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
107  }
108 
109  list->cursor = list->start;
110  if(list->cursor == NULL)
111  return DLT_RETURN_OK;
112 
113  while(list->cursor->next != NULL)
115 
116  return DLT_RETURN_OK;
117 }
118 
120 {
121  if(list == NULL)
122  {
123  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
125  }
126 
127  if(list->cursor == NULL)
128  return DLT_RETURN_ERROR;
129 
130  list->cursor = list->cursor->next;
131 
132  return DLT_RETURN_OK;
133 }
134 
136 {
137  if(list == NULL)
138  {
139  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
141  }
142 
143  if(list->cursor == NULL)
144  return DLT_RETURN_ERROR;
145 
146  list->cursor = list->cursor->prev;
147 
148  return DLT_RETURN_OK;
149 }
150 
152 {
153  if(list == NULL || process == NULL)
154  {
155  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
157  }
158 
159  if(list->start != NULL)
160  list->start->prev = process;
161 
162  process->next = list->start;
163  list->start = process;
164 
165  return DLT_RETURN_OK;
166 }
167 
169 {
170  if(list == NULL || process == NULL)
171  {
172  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
174  }
175 
176  if(list->start == NULL) // Empty list?
177  {
178  DltReturnValue ret = dlt_kpi_add_process_at_start(list, process);
179  list->cursor = NULL;
180  return ret;
181  }
182  else if(list->cursor == NULL)
183  {
186  list->cursor = NULL;
187  return ret;
188  }
189 
190  if(list->cursor->prev != NULL)
191  list->cursor->prev->next = process;
192  else
193  list->start = process;
194 
195  process->next = list->cursor;
196  process->prev = list->cursor->prev;
197  list->cursor->prev = process;
198 
199  return DLT_RETURN_OK;
200 }
201 
203 {
204  if(list == NULL || process == NULL)
205  {
206  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
207  return DLT_RETURN_ERROR;
208  }
209 
210  if(list->cursor == NULL)
211  return dlt_kpi_add_process_at_start(list, process);
212 
213  if(list->cursor->next != NULL)
214  list->cursor->next->prev = process;
215 
216  process->next = list->cursor->next;
217  process->prev = list->cursor;
218  list->cursor->next = process;
219 
220  return DLT_RETURN_OK;
221 }
222 
224 {
225  if(list == NULL)
226  {
227  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
229  }
230 
231  if(list->cursor == NULL)
232  {
233  fprintf(stderr, "%s: Cursor is Invalid (NULL)\n", __func__);
234  return DLT_RETURN_ERROR;
235  }
236 
237  DltKpiProcess *tmp = list->cursor;
238 
239  if(tmp->prev != NULL)
240  {
241  if(tmp->next != NULL)
242  {
243  tmp->prev->next = tmp->next;
244  tmp->next->prev = tmp->prev;
245  }
246  else
247  tmp->prev->next = NULL;
248  }
249  else
250  {
251  if(tmp->next != NULL)
252  {
253  tmp->next->prev = NULL;
254  list->start = tmp->next;
255  }
256  else
257  list->start = NULL;
258  }
259 
260  list->cursor = tmp->next; // becomes NULL if list is at end
261 
262  return DLT_RETURN_OK;
263 }
264 
266 {
267  if(list == NULL)
268  {
269  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
271  }
272 
273  if(list->cursor == NULL)
274  {
275  fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
276  return DLT_RETURN_ERROR;
277  }
278 
279  DltKpiProcess *tmp = list->cursor;
281  if(ret < DLT_RETURN_OK)
282  return ret;
283 
285 
286  return DLT_RETURN_OK;
287 }
288 
DltReturnValue dlt_kpi_remove_process_at_cursor(DltKpiProcessList *list)
struct DltKpiProcess * cursor
DltReturnValue
Definition: dlt_types.h:86
DltReturnValue dlt_kpi_remove_process_at_cursor_soft(DltKpiProcessList *list)
static DltKpiProcessList * list
Definition: dlt-kpi.c:40
DltReturnValue dlt_kpi_add_process_at_start(DltKpiProcessList *list, DltKpiProcess *process)
DltReturnValue dlt_kpi_decrement_cursor(DltKpiProcessList *list)
DltReturnValue dlt_kpi_set_cursor_at_end(DltKpiProcessList *list)
DltKpiProcessList * dlt_kpi_create_process_list()
DltKpiProcess * dlt_kpi_get_process_at_cursor(DltKpiProcessList *list)
struct DltKpiProcess * next
DltReturnValue dlt_kpi_add_process_before_cursor(DltKpiProcessList *list, DltKpiProcess *process)
DltReturnValue dlt_kpi_free_process_list(DltKpiProcessList *list)
DltReturnValue dlt_kpi_increment_cursor(DltKpiProcessList *list)
DltReturnValue dlt_kpi_add_process_after_cursor(DltKpiProcessList *list, DltKpiProcess *process)
DltReturnValue dlt_kpi_free_process_list_soft(DltKpiProcessList *list)
DltReturnValue dlt_kpi_free_process(DltKpiProcess *process)
struct DltKpiProcess * start
struct DltKpiProcess * prev
DltReturnValue dlt_kpi_reset_cursor(DltKpiProcessList *list)
#define NULL
Definition: dlt_common.h:232