mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:43:23 +00:00
core: add C struct device and struct device_table accessors
Up to now, "struct device" and "struct device_table" were C++ only, because they used C++ strings for convenience. Since we switched from QString to std::string, we can create accessors for these structs. For the C code, we simply declare them as opaque structs and give the full definition only for C++. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4a50badb57
commit
c4bfecce1b
2 changed files with 52 additions and 2 deletions
|
@ -358,3 +358,40 @@ const char *get_dc_nickname(const struct divecomputer *dc)
|
||||||
else
|
else
|
||||||
return dc->model;
|
return dc->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" int nr_devices(const struct device_table *table)
|
||||||
|
{
|
||||||
|
return (int)table->devices.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const struct device *get_device(const struct device_table *table, int i)
|
||||||
|
{
|
||||||
|
if (i < 0 || i > nr_devices(table))
|
||||||
|
return NULL;
|
||||||
|
return &table->devices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const char *device_get_model(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->model.c_str() : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const uint32_t device_get_id(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->deviceId : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const char *device_get_serial(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->serialNumber.c_str() : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const char *device_get_firmware(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->firmware.c_str() : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const char *device_get_nickname(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->nickName.c_str() : NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -9,15 +9,30 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct divecomputer;
|
struct divecomputer;
|
||||||
|
struct device;
|
||||||
|
struct device_table;
|
||||||
|
|
||||||
|
// global device table
|
||||||
|
extern struct device_table device_table;
|
||||||
|
|
||||||
extern void fake_dc(struct divecomputer *dc);
|
extern void fake_dc(struct divecomputer *dc);
|
||||||
extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid);
|
extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid);
|
||||||
extern void set_dc_nickname(struct dive *dive);
|
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 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,
|
extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t,
|
||||||
const char *, const char *, const char *), bool select_only);
|
const char *, const char *, const char *), bool select_only);
|
||||||
extern void clear_device_nodes();
|
extern void clear_device_nodes();
|
||||||
const char *get_dc_nickname(const struct divecomputer *dc);
|
const char *get_dc_nickname(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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,8 +59,6 @@ struct device_table {
|
||||||
std::vector<device> devices;
|
std::vector<device> devices;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct device_table device_table;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // DEVICE_H
|
#endif // DEVICE_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue