small optimization and error handling comment

pull/279/head
Joseph Poirier 2016-02-24 08:18:40 -06:00
rodzic 0d5807cb23
commit 5e2209e906
1 zmienionych plików z 10 dodań i 13 usunięć

Wyświetl plik

@ -372,22 +372,24 @@ func createESDev(id int, serial string, idSet bool) error {
func configDevices(count int, es_enabled, uat_enabled bool) { func configDevices(count int, es_enabled, uat_enabled bool) {
// entry to this function is only valid when both UATDev and ESDev are nil // entry to this function is only valid when both UATDev and ESDev are nil
// TODO: refactor and optimize
// once the tagged dongles have been assigned, explicitly range over // once the tagged dongles have been assigned, explicitly range over
// the remaining IDs and assign them to any anonymous dongles // the remaining IDs and assign them to any anonymous dongles
unusedIDs := make([]int, 0, count) unusedIDs := make([int]string)
// loop 1: assign tagged dongles // loop 1: assign tagged dongles
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
_, _, s, err := rtl.GetDeviceUsbStrings(i) _, _, s, err := rtl.GetDeviceUsbStrings(i)
if err == nil { if err == nil {
// no need to check if createXDev returned an error; if it
// failed to config the error is logged and we can ignore
// it here so it doesn't get queued up again
if uat_enabled && UATDev == nil && rUAT.hasID(s) { if uat_enabled && UATDev == nil && rUAT.hasID(s) {
createUATDev(i, s, true) createUATDev(i, s, true)
} else if es_enabled && ESDev == nil && rES.hasID(s) { } else if es_enabled && ESDev == nil && rES.hasID(s) {
createESDev(i, s, true) createESDev(i, s, true)
} else { } else {
unusedIDs = append(unusedIDs, i) unusedIDs[i] = s
} }
} else { } else {
log.Printf("rtl.GetDeviceUsbStrings id %d: %s\n", i, err) log.Printf("rtl.GetDeviceUsbStrings id %d: %s\n", i, err)
@ -398,16 +400,11 @@ func configDevices(count int, es_enabled, uat_enabled bool) {
// so we don't cross config for dual assigned dongles. E.g. when two // so we don't cross config for dual assigned dongles. E.g. when two
// dongles are set to the same stratux id and the unconsumed, non-anonymous, // dongles are set to the same stratux id and the unconsumed, non-anonymous,
// dongle makes it to this loop. // dongle makes it to this loop.
for _, v := range unusedIDs { for i, s := range unusedIDs {
_, _, s, err := rtl.GetDeviceUsbStrings(v) if uat_enabled && UATDev == nil && !rES.hasID(s) {
if err == nil { createUATDev(i, s, false)
if uat_enabled && UATDev == nil && !rES.hasID(s) { } else if es_enabled && ESDev == nil && !rUAT.hasID(s) {
createUATDev(v, s, false) createESDev(i, s, false)
} else if es_enabled && ESDev == nil && !rUAT.hasID(s) {
createESDev(v, s, false)
}
} else {
log.Printf("rtl.GetDeviceUsbStrings id %d: %s\n", v, err)
} }
} }
} }