mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-20 06:45:27 +00:00
d93b261e89
We have a callback for all devices with a twist: it can loop over those devices that are used by a selected dive. This is used for exporting a subset of the dive log. Factor out the "is device used by selected dive" part of the function and make it available to C. The goal is to make the whole callback thing unnecessary and let C code loop directly over the device list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef DEVICE_H
|
|
#define DEVICE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct divecomputer;
|
|
struct device;
|
|
struct device_table;
|
|
struct dive_table;
|
|
|
|
// global device table
|
|
extern struct device_table device_table;
|
|
|
|
extern void fake_dc(struct divecomputer *dc);
|
|
extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid);
|
|
extern void set_dc_nickname(struct dive *dive);
|
|
extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
|
|
extern int nr_devices(const struct device_table *table);
|
|
extern const struct device *get_device(const struct device_table *table, int i);
|
|
extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t,
|
|
const char *, const char *, const char *), bool select_only);
|
|
extern void clear_device_nodes();
|
|
const char *get_dc_nickname(const struct divecomputer *dc);
|
|
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);
|
|
|
|
// 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);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
// Functions and global variables that are only available to C++ code
|
|
#ifdef __cplusplus
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
struct device {
|
|
bool operator==(const device &a) const; // TODO: remove, once devices are integrated in the undo system
|
|
bool operator<(const device &a) const;
|
|
void showchanges(const std::string &n, const std::string &s, const std::string &f) const;
|
|
std::string model;
|
|
uint32_t deviceId;
|
|
std::string serialNumber;
|
|
std::string firmware;
|
|
std::string nickName;
|
|
};
|
|
|
|
struct device_table {
|
|
// Keep the dive computers in a vector sorted by (model, deviceId)
|
|
std::vector<device> devices;
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif // DEVICE_H
|