2021-02-18 13:45:29 +01:00
|
|
|
#ifndef CONTACT_STORAGE_H
|
|
|
|
#define CONTACT_STORAGE_H
|
2021-01-26 16:14:58 +01:00
|
|
|
|
2021-02-18 13:45:29 +01:00
|
|
|
#include "contacts.h" // Requires contact_t in contacts.h!
|
|
|
|
|
|
|
|
// TODO: This should be masked to k=24 bits
|
|
|
|
typedef uint32_t record_sequence_number_t;
|
|
|
|
|
|
|
|
typedef uint16_t storage_id_t;
|
|
|
|
|
|
|
|
typedef struct stored_contacts_information {
|
|
|
|
record_sequence_number_t oldest_contact;
|
2021-03-11 00:32:36 +01:00
|
|
|
record_sequence_number_t count;
|
2021-02-18 13:45:29 +01:00
|
|
|
} stored_contacts_information_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the contact storage component
|
|
|
|
* @return 0 for success
|
|
|
|
*/
|
|
|
|
int init_contact_storage();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the contact with number sn into the destination struct
|
|
|
|
* @param dest
|
|
|
|
* @param sn
|
|
|
|
* @return 0 in case of success
|
|
|
|
*/
|
|
|
|
int load_contact(contact_t* dest, record_sequence_number_t sn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the contact from src with number sn, increases latest sequence number
|
|
|
|
* @param sn
|
|
|
|
* @param src
|
|
|
|
* @return 0 in case of success
|
|
|
|
*/
|
|
|
|
int add_contact(contact_t* src);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the contact from storage with number sn
|
|
|
|
* @param sn the sequence number to delete
|
|
|
|
* @return 0 in case of success
|
|
|
|
*/
|
|
|
|
int delete_contact(record_sequence_number_t sn);
|
2021-02-01 23:17:48 +01:00
|
|
|
|
2021-01-26 16:14:58 +01:00
|
|
|
/**
|
2021-02-18 13:45:29 +01:00
|
|
|
* TODO: How to handle if none is available?
|
|
|
|
* @return The latest available sequence number (Caution: can actually be lower than the oldes in case of a
|
|
|
|
* wrap-around!)
|
2021-01-26 16:14:58 +01:00
|
|
|
*/
|
2021-02-18 13:45:29 +01:00
|
|
|
record_sequence_number_t get_latest_sequence_number();
|
2021-01-26 16:14:58 +01:00
|
|
|
|
2021-02-01 23:17:48 +01:00
|
|
|
/**
|
2021-02-18 13:45:29 +01:00
|
|
|
* TODO: How to handle if none is available?
|
|
|
|
* @return The oldest available sequence number
|
2021-02-01 23:17:48 +01:00
|
|
|
*/
|
2021-02-18 13:45:29 +01:00
|
|
|
record_sequence_number_t get_oldest_sequence_number();
|
2021-02-03 19:39:01 +01:00
|
|
|
|
|
|
|
/**
|
2021-02-18 13:45:29 +01:00
|
|
|
* TODO: How to handle if none is available?
|
|
|
|
* @return The amount of contacts, usually get_latest_sequence_number() - get_oldest_sequence_number()
|
2021-02-03 19:39:01 +01:00
|
|
|
*/
|
2021-02-18 13:45:29 +01:00
|
|
|
uint32_t get_num_contacts();
|
2021-02-01 23:17:48 +01:00
|
|
|
|
2021-03-11 00:32:36 +01:00
|
|
|
#endif
|