1 /** \ingroup KeyGeneration
3 * @author David Llewellyn-Jones <david@flypig.co.uk>
8 * Copyright David Llewellyn-Jones, 2020
9 * Released under the GPLv2.
11 * @brief Provides a list of RPIs
12 * @section DESCRIPTION
14 * This class allows the simplified management of lists of Rpi objects. This is
15 * useful when checking DTKs received from a Diagnosis Server with RPIs
16 * captured over Bluetooth. Combined with the \ref DtkList class the two can
17 * be easily stored and passed into the \ref match_list_find_matches() function.
21 /** \addtogroup Containers
32 #include "contrac/contrac.h"
33 #include "contrac/utils.h"
34 #include "contrac/log.h"
35 #include "contrac/dtk_list.h"
37 #include "contrac/rpi_list.h"
44 * @brief An RPI list element
46 * This is an opaque structure that represents a single item in the list and
47 * contains an Rpi instance.
49 * The structure typedef is in rpi_list.h
57 * @brief The head of an RPI list
59 * This is an opaque structure that represents the head of a list of Rpi
62 * This is the object usually passed as the first parameter of every non-static
65 * The structure typedef is in dtk_list.h
72 // Function prototypes
74 // Function definitions
77 * Creates a new instance of the class.
79 * @return The newly created object.
81 RpiList
* rpi_list_new() {
84 data
= calloc(sizeof(RpiList
), 1);
90 * Deletes an instance of the class, freeing up the memory allocated to it.
92 * This will also delete all items contained in the list.
94 * @param data The instance to free.
96 void rpi_list_delete(RpiList
* data
) {
104 rpi_delete(item
->rpi
);
114 * Adds an item to the list.
116 * This adds an Rpi item to the list. It's primarily for internal use and when
117 * adding RPIs to the list it's usually more appropriate to use the
118 * \ref rpi_list_add_beacon() function.
120 * @param data The list to append to.
121 * @param rpi The RPI to append.
123 void rpi_list_append(RpiList
* data
, Rpi
* rpi
) {
126 item
= calloc(sizeof(RpiListItem
), 1);
129 if (data
->last
== NULL
) {
134 data
->last
->next
= item
;
140 * Returns the first item in the list.
142 * Useful for iterating through the items in the list.
144 * @param data The list to operate on.
145 * @return The first item of the list.
147 RpiListItem
const * rpi_list_first(RpiList
const * data
) {
152 * Returns the next item in the list.
154 * Useful for iterating through the items in the list.
156 * @param data The current item in the list.
157 * @return The next item in the list following the current item.
159 RpiListItem
const * rpi_list_next(RpiListItem
const * data
) {
164 * Returns the Rpi item contained in this list item.
166 * @param data The current item in the list.
167 * @return The Rpi instance stored in the list element.
169 Rpi
const * rpi_list_get_rpi(RpiListItem
const * data
) {
174 * Adds Rpi data to the list.
176 * The rpi_bytes buffer passed in must contain exactly RPI_SIZE (16) bytes of
177 * data. It doen't have to be null terminated.
179 * @param data The current list to operate on.
180 * @param rpi_bytes The RPI value to add, in binary format.
181 * @param time_interval_number The time interval number to associate with the
184 void rpi_list_add_beacon(RpiList
* data
, unsigned char const * rpi_bytes
, uint8_t time_interval_number
) {
185 Rpi
* rpi
= rpi_new();
186 rpi_assign(rpi
, rpi_bytes
, time_interval_number
);
187 rpi_list_append(data
, rpi
);
190 /** @} addtogroup Containers*/