Debian Codegraph @

src/common/err_queue.h

raw symbols SCIP
1 /*
2 * Copyright 2013 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #pragma once
22 #ifndef _OSCAP_ERR_QUEUE_H
23 #define _OSCAP_ERR_QUEUE_H
24
25 #include "util.h"
26 #include "_error.h"
27 #include <stdbool.h>
28
29
30 /**
31 * OpenSCAP Internal Error Queue.
32 * This structure is the traditional FIFO object which allows to lookup
33 * the last item.
34 */
35 struct err_queue;
36
37 /**
38 * Initialize new error_queue.
39 * @memberof err_queue
40 * @returns newly initialized error queue
41 */
42 struct err_queue *err_queue_new(void);
43
44 /**
45 * Push the new error at the end of the error queue.
46 * @memberof err_queue
47 * @param q Internal Error Queue
48 * @param error new error to save in the queuei
49 * @returns true on success
50 */
51 bool err_queue_push(struct err_queue *q, struct oscap_err_t *error);
52
53 /**
54 * Query if the queue is empty
55 * @meberof err_queue
56 * @param q Internal Error Queue
57 * @returns false if there is some error in the queue
58 */
59 bool err_queue_is_empty(struct err_queue *q);
60
61 /**
62 * Pop the first object from the FIFO queue. This new object is no longer
63 * tracked by err_queue and shall be disposed by caller.
64 * @memberof err_queue
65 * @param q Internal Error Queue
66 * @returns The first item in the queue or NULL.
67 */
68 struct oscap_err_t *err_queue_pop_first(struct err_queue *q);
69
70 /**
71 * Return the last object from the FIFO queuqe. This object continues to
72 * be a property of err_queue and shall not be modified nor disposed.
73 * @memberof err_queue
74 * @param q Internal Error Queue
75 * @returns the last item in the queue or NULL
76 */
77 const struct oscap_err_t *err_queue_get_last(struct err_queue *q);
78
79 /**
80 * Dispose given err_queue. Dispose also stored messages if destructor is
81 * supplied.
82 * @memberof err_queue
83 * @param q Internal Error Queue
84 * @param destructor a function to dipose messages in the queue
85 */
86 void err_queue_free(struct err_queue *q, oscap_destruct_func destructor);
87
88 /**
89 * Get all the errors in the queue as a single string.
90 * @memberof err_queue
91 * @param q Internal Error Queue
92 * @param result pointer, where to store the resulting string. Newly
93 * allocated mmory will be assigned with this. And shall be disposed
94 * by caller.
95 * @returns zero on success
96 */
97 int err_queue_to_string(struct err_queue *q, char **result);
98
99
100 #endif