core: remove device C access code

This was used from C, so there was lots of access code, which is
not necessary.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-31 07:08:54 +02:00 committed by bstoeger
parent 9e3e0a5a05
commit 73f2605ab1
13 changed files with 84 additions and 177 deletions

View file

@ -7,36 +7,32 @@
#include <vector>
struct divecomputer;
struct device;
struct device_table;
struct dive_table;
struct device {
bool operator<(const device &a) const;
void showchanges(const std::string &n) const;
std::string model;
std::string serialNumber;
std::string nickName;
uint32_t deviceId; // Always the string hash of the serialNumber
};
using device_table = std::vector<device>;
// global device table
extern struct fingerprint_table fingerprint_table;
extern int create_device_node(struct device_table *table, const std::string &model, const std::string &serial, const std::string &nickname);
extern int nr_devices(const struct device_table *table);
extern const struct device *get_device(const struct device_table *table, int i);
extern struct device *get_device_mutable(struct device_table *table, int i);
extern void clear_device_table(struct device_table *table);
extern int create_device_node(device_table &table, const std::string &model, const std::string &serial, const std::string &nickname);
std::string get_dc_nickname(const struct divecomputer *dc);
extern bool device_used_by_selected_dive(const struct device *dev);
extern bool device_used_by_selected_dive(const struct device &dev);
extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc);
extern int get_or_add_device_for_dc(struct device_table *table, const struct divecomputer *dc);
extern bool device_exists(const struct device_table *table, const struct device *dev);
extern int add_to_device_table(struct device_table *table, const struct device *dev); // returns index
extern int remove_device(struct device_table *table, const struct device *dev); // returns index or -1 if not found
extern void remove_from_device_table(struct device_table *table, int idx);
// struct device accessors for C-code. The returned strings are not stable!
std::string device_get_model(const struct device *dev);
std::string device_get_serial(const struct device *dev);
std::string device_get_nickname(const struct device *dev);
// for C code that needs to alloc/free a device table. (Let's try to get rid of those)
extern struct device_table *alloc_device_table();
extern void free_device_table(struct device_table *devices);
extern const struct device *get_device_for_dc(const device_table &table, const struct divecomputer *dc);
extern int get_or_add_device_for_dc(device_table &table, const struct divecomputer *dc);
extern bool device_exists(const device_table &table, const struct device &dev);
extern int add_to_device_table(device_table &table, const struct device &dev); // returns index
extern int remove_device(device_table &table, const struct device &dev); // returns index or -1 if not found
extern void remove_from_device_table(device_table &table, int idx);
// create fingerprint entry - raw data remains owned by caller
extern void create_fingerprint_node(struct fingerprint_table *table, uint32_t model, uint32_t serial,
@ -59,16 +55,6 @@ typedef void (*device_callback_t)(const char *name, void *userdata);
extern int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport);
// Functions and global variables that are only available to C++ code
struct device {
bool operator<(const device &a) const;
void showchanges(const std::string &n) const;
std::string model;
std::string serialNumber;
std::string nickName;
uint32_t deviceId; // Always the string hash of the serialNumber
};
struct fingerprint_record {
bool operator<(const fingerprint_record &a) const;
uint32_t model; // model and libdivecomputer serial number to
@ -79,11 +65,6 @@ struct fingerprint_record {
unsigned int fdiveid; // corresponding diveid
};
struct device_table {
// Keep the dive computers in a vector sorted by (model, serial)
std::vector<device> devices;
};
struct fingerprint_table {
// Keep the fingerprint records in a vector sorted by (model, serial) - these are uint32_t here
std::vector<fingerprint_record> fingerprints;