From ea6577b0e52c28030631a573356007617e1d6206 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sun, 11 Jun 2017 17:47:23 +0200 Subject: [PATCH] device, discovereddevice, utils: use same method for generating 'unique' device strings --- src/mconnect/device.vala | 9 ++++++--- src/mconnect/discovereddevice.vala | 7 +++++++ src/mconnect/utils.vala | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/mconnect/device.vala b/src/mconnect/device.vala index e1f1375..2a339c4 100644 --- a/src/mconnect/device.vala +++ b/src/mconnect/device.vala @@ -141,12 +141,15 @@ class Device : Object { * Generates a unique string for this device */ public string to_unique_string() { - return this.to_string().replace(" ", "-"); + return make_unique_device_string(this.device_id, + this.device_name, + this.device_type, + this.protocol_version); } public string to_string() { - return "%s-%s-%s-%u".printf(this.device_id, this.device_name, - this.device_type, this.protocol_version); + return make_device_string(this.device_id, this.device_name, + this.device_type, this.protocol_version); } /** diff --git a/src/mconnect/discovereddevice.vala b/src/mconnect/discovereddevice.vala index 8bbba3c..587624f 100644 --- a/src/mconnect/discovereddevice.vala +++ b/src/mconnect/discovereddevice.vala @@ -72,4 +72,11 @@ class DiscoveredDevice : Object { this.protocol_version); } + public string to_unique_string() { + return make_unique_device_string(this.device_id, + this.device_name, + this.device_type, + this.protocol_version); + } + } \ No newline at end of file diff --git a/src/mconnect/utils.vala b/src/mconnect/utils.vala index 45011f5..ec67d48 100644 --- a/src/mconnect/utils.vala +++ b/src/mconnect/utils.vala @@ -55,3 +55,31 @@ void vdebug(string format, ...) { } } +/** + * make_unique_device_string: + * @id: device ID + * @name: device name + * @type: device type + * @pv: protocol version + * + * Generate device string that can be used as map index + */ +string make_unique_device_string(string id, string name, + string type, uint pv) { + return make_device_string(id, name, type, pv).replace(" ", "-"); +} + +/** + * make_device_string: + * @id: device ID + * @name: device name + * @type: device type + * @pv: protocol version + * + * Generate device string + */ +string make_device_string(string id, string name, + string type, uint pv) { + return "%s-%s-%s-%u".printf(id, name, type, pv); + +}