2017-04-27 20:18:03 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-02-11 19:14:46 +01:00
|
|
|
#ifndef DEVICE_H
|
|
|
|
#define DEVICE_H
|
2013-01-09 12:07:09 -08:00
|
|
|
|
2019-08-05 19:41:15 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-04-01 13:51:49 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-08-05 19:41:15 +02:00
|
|
|
struct divecomputer;
|
2020-10-05 20:55:57 +02:00
|
|
|
struct device;
|
|
|
|
struct device_table;
|
2020-10-06 21:36:51 +02:00
|
|
|
struct dive_table;
|
2020-10-05 20:55:57 +02:00
|
|
|
|
|
|
|
// global device table
|
|
|
|
extern struct device_table device_table;
|
|
|
|
|
2020-10-10 21:41:36 +02:00
|
|
|
extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid, const struct device_table *table);
|
|
|
|
|
2020-10-18 21:45:50 +02:00
|
|
|
extern void add_devices_of_dive(const struct dive *dive, struct device_table *table);
|
2020-10-10 21:41:36 +02:00
|
|
|
extern void create_device_node(struct device_table *table, const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
|
2020-10-05 20:55:57 +02:00
|
|
|
extern int nr_devices(const struct device_table *table);
|
|
|
|
extern const struct device *get_device(const struct device_table *table, int i);
|
2020-10-25 07:53:40 +01:00
|
|
|
extern struct device *get_device_mutable(struct device_table *table, int i);
|
2020-10-17 13:28:05 +02:00
|
|
|
extern void clear_device_table(struct device_table *table);
|
2020-10-05 09:56:21 +02:00
|
|
|
const char *get_dc_nickname(const struct divecomputer *dc);
|
2020-10-06 21:36:51 +02:00
|
|
|
extern bool device_used_by_selected_dive(const struct device *dev);
|
2020-10-05 21:12:49 +02:00
|
|
|
|
|
|
|
extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc);
|
2020-10-17 14:01:52 +02:00
|
|
|
extern bool device_exists(const struct device_table *table, const struct device *dev);
|
2020-10-21 15:25:18 +02:00
|
|
|
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
|
2020-10-24 22:46:36 +02:00
|
|
|
extern void remove_from_device_table(struct device_table *table, int idx);
|
2013-01-09 12:07:09 -08:00
|
|
|
|
2020-10-05 20:55:57 +02:00
|
|
|
// struct device accessors for C-code. The returned strings are not stable!
|
|
|
|
const char *device_get_model(const struct device *dev);
|
|
|
|
const uint32_t device_get_id(const struct device *dev);
|
|
|
|
const char *device_get_serial(const struct device *dev);
|
|
|
|
const char *device_get_firmware(const struct device *dev);
|
|
|
|
const char *device_get_nickname(const struct device *dev);
|
|
|
|
|
2020-10-17 16:07:39 +02:00
|
|
|
// 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);
|
|
|
|
|
2013-04-01 13:51:49 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-09-13 19:08:41 +02:00
|
|
|
// Functions and global variables that are only available to C++ code
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2020-10-05 09:56:21 +02:00
|
|
|
#include <string>
|
2020-10-05 10:12:12 +02:00
|
|
|
#include <vector>
|
2020-10-03 11:18:42 +02:00
|
|
|
struct device {
|
2020-10-05 21:28:26 +02:00
|
|
|
bool operator==(const device &a) const; // TODO: remove, once devices are integrated in the undo system
|
2020-10-03 11:18:42 +02:00
|
|
|
bool operator<(const device &a) const;
|
2020-10-05 09:56:21 +02:00
|
|
|
void showchanges(const std::string &n, const std::string &s, const std::string &f) const;
|
|
|
|
std::string model;
|
2020-09-13 19:08:41 +02:00
|
|
|
uint32_t deviceId;
|
2020-10-05 09:56:21 +02:00
|
|
|
std::string serialNumber;
|
|
|
|
std::string firmware;
|
|
|
|
std::string nickName;
|
2020-09-13 19:08:41 +02:00
|
|
|
};
|
|
|
|
|
2020-10-03 11:18:42 +02:00
|
|
|
struct device_table {
|
2020-09-13 19:08:41 +02:00
|
|
|
// Keep the dive computers in a vector sorted by (model, deviceId)
|
2020-10-05 10:12:12 +02:00
|
|
|
std::vector<device> devices;
|
2020-09-13 19:08:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-02-11 19:14:46 +01:00
|
|
|
#endif // DEVICE_H
|