mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	core: use C accessors in core/libdivecomputer.c instead of callback
Searching the proper device for the divecomputer was done via a callback. Very hard to follow code. Since we can now access "struct device" from C, obtain it directly via get_device_for_dc(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									74b8d13672
								
							
						
					
					
						commit
						7415824a8c
					
				
					 1 changed files with 5 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -551,25 +551,6 @@ static uint32_t calculate_string_hash(const char *str)
 | 
			
		|||
	return calculate_diveid((const unsigned char *)str, strlen(str));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Find an existing device ID for this device model and serial number
 | 
			
		||||
 */
 | 
			
		||||
static void dc_match_serial(void *_dc, const char *model, uint32_t deviceid, const char *nickname, const char *serial, const char *firmware)
 | 
			
		||||
{
 | 
			
		||||
	UNUSED(nickname);
 | 
			
		||||
	UNUSED(firmware);
 | 
			
		||||
 | 
			
		||||
	struct divecomputer *dc = _dc;
 | 
			
		||||
 | 
			
		||||
	if (!deviceid)
 | 
			
		||||
		return;
 | 
			
		||||
	if (!dc->model || !model || strcasecmp(dc->model, model))
 | 
			
		||||
		return;
 | 
			
		||||
	if (!dc->serial || !serial || strcasecmp(dc->serial, serial))
 | 
			
		||||
		return;
 | 
			
		||||
	dc->deviceid = deviceid;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Set the serial number.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -581,8 +562,12 @@ static void dc_match_serial(void *_dc, const char *model, uint32_t deviceid, con
 | 
			
		|||
 */
 | 
			
		||||
static void set_dc_serial(struct divecomputer *dc, const char *serial)
 | 
			
		||||
{
 | 
			
		||||
	const struct device *device;
 | 
			
		||||
 | 
			
		||||
	dc->serial = serial;
 | 
			
		||||
	call_for_each_dc(dc, dc_match_serial, false);
 | 
			
		||||
	if ((device = get_device_for_dc(&device_table, dc)) != NULL)
 | 
			
		||||
		dc->deviceid = device_get_id(device);
 | 
			
		||||
 | 
			
		||||
	if (!dc->deviceid)
 | 
			
		||||
		dc->deviceid = calculate_string_hash(serial);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue