Browse Source

device, discovereddevice, utils: use same method for generating 'unique' device strings

bboozzoo/wip
Maciek Borzecki 8 years ago
parent
commit
ea6577b0e5
3 changed files with 41 additions and 3 deletions
  1. +6
    -3
      src/mconnect/device.vala
  2. +7
    -0
      src/mconnect/discovereddevice.vala
  3. +28
    -0
      src/mconnect/utils.vala

+ 6
- 3
src/mconnect/device.vala View File

@ -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);
}
/**


+ 7
- 0
src/mconnect/discovereddevice.vala View File

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

+ 28
- 0
src/mconnect/utils.vala View File

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

Loading…
Cancel
Save