mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: use getDCExact() instead of callback in set_dc_deviceid()
core/device.c used to be a C file, which couldn't access the C++ divecomputer list directly. Therefore, instead of a simple loop, searching for a matching DC was implemented via a callback with void * user data parameter. Wild. Since the file is now C++, let's just use direct access to the C++ data structures to make this readable by mere humans. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ce7e74f62f
commit
90ca635316
1 changed files with 26 additions and 28 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "ssrf.h"
|
||||
#include "dive.h"
|
||||
#include "subsurface-string.h"
|
||||
#include "qthelper.h" // for copy_qstring
|
||||
#include "device.h"
|
||||
#include "errorhelper.h" // for verbose flag
|
||||
#include "selection.h"
|
||||
|
@ -191,34 +192,6 @@ extern "C" void fake_dc(struct divecomputer *dc)
|
|||
/* Even that didn't work? Give up, there's something wrong */
|
||||
}
|
||||
|
||||
static void match_id(void *_dc, const char *model, uint32_t deviceid,
|
||||
const char *, const char *serial, const char *firmware)
|
||||
{
|
||||
struct divecomputer *dc = (divecomputer *)_dc;
|
||||
|
||||
if (dc->deviceid != deviceid)
|
||||
return;
|
||||
if (!model || !dc->model || strcmp(dc->model, model))
|
||||
return;
|
||||
|
||||
if (serial && !dc->serial)
|
||||
dc->serial = strdup(serial);
|
||||
if (firmware && !dc->fw_version)
|
||||
dc->fw_version = strdup(firmware);
|
||||
}
|
||||
|
||||
/*
|
||||
* When setting the device ID, we also fill in the
|
||||
* serial number and firmware version data
|
||||
*/
|
||||
extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid)
|
||||
{
|
||||
if (deviceid) {
|
||||
dc->deviceid = deviceid;
|
||||
call_for_each_dc(dc, match_id, false);
|
||||
}
|
||||
}
|
||||
|
||||
DiveComputerList dcList;
|
||||
|
||||
bool DiveComputerNode::operator==(const DiveComputerNode &a) const
|
||||
|
@ -252,6 +225,31 @@ static const DiveComputerNode *getDC(const QVector<DiveComputerNode> &dcs, const
|
|||
return it != dcs.end() && it->model == dc->model ? &*it : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* When setting the device ID, we also fill in the
|
||||
* serial number and firmware version data
|
||||
*/
|
||||
extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid)
|
||||
{
|
||||
if (!deviceid)
|
||||
return;
|
||||
|
||||
dc->deviceid = deviceid;
|
||||
|
||||
// Serial and firmware can only be deduced if we know the model
|
||||
if (!dc->model)
|
||||
return;
|
||||
|
||||
const DiveComputerNode *node = getDCExact(dcList.dcs, dc);
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
if (!node->serialNumber.isEmpty() && empty_string(dc->serial))
|
||||
dc->serial = copy_qstring(node->serialNumber);
|
||||
if (!node->firmware.isEmpty() && empty_string(dc->fw_version))
|
||||
dc->fw_version = copy_qstring(node->firmware);
|
||||
}
|
||||
|
||||
void DiveComputerNode::showchanges(const QString &n, const QString &s, const QString &f) const
|
||||
{
|
||||
if (nickName != n && !n.isEmpty())
|
||||
|
|
Loading…
Add table
Reference in a new issue