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); + +}