Reorder items in generated source files.
Ideally they would always have been sorted as such, but this seems more critical in migrating from one service definition to another where the ordering might change.
This commit is contained in:
parent
730ab6506b
commit
ca81a64b42
@ -29,16 +29,16 @@ import (
|
|||||||
var _ time.Time
|
var _ time.Time
|
||||||
|
|
||||||
// Device URNs:
|
// Device URNs:
|
||||||
const ({{range .DeviceTypes}}
|
const ({{range .OrderedDeviceTypes}}
|
||||||
{{.Const}} = "{{.URN}}"{{end}}
|
{{.Const}} = "{{.URN}}"{{end}}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service URNs:
|
// Service URNs:
|
||||||
const ({{range .ServiceTypes}}
|
const ({{range .OrderedServiceTypes}}
|
||||||
{{.Const}} = "{{.URN}}"{{end}}
|
{{.Const}} = "{{.URN}}"{{end}}
|
||||||
)
|
)
|
||||||
|
|
||||||
{{range .Services}}
|
{{range .OrderedServices}}
|
||||||
{{$srv := .}}
|
{{$srv := .}}
|
||||||
{{$srvIdent := printf "%s%s" .Name .Version}}
|
{{$srvIdent := printf "%s%s" .Name .Version}}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ func new{{$srvIdent}}ClientsFromGenericClients(genericClients []goupnp.ServiceCl
|
|||||||
return clients
|
return clients
|
||||||
}
|
}
|
||||||
|
|
||||||
{{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}}
|
{{range .SCPD.OrderedActions}}{{/* loops over *SCPDWithURN values */}}
|
||||||
|
|
||||||
{{$winargs := $srv.WrapArguments .InputArguments}}
|
{{$winargs := $srv.WrapArguments .InputArguments}}
|
||||||
{{$woutargs := $srv.WrapArguments .OutputArguments}}
|
{{$woutargs := $srv.WrapArguments .OutputArguments}}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/huin/goupnp"
|
"github.com/huin/goupnp"
|
||||||
@ -85,6 +86,7 @@ func (dcp *DCP) writeCode(outFile string, useGofmt bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = packageTmpl.Execute(output, dcp); err != nil {
|
if err = packageTmpl.Execute(output, dcp); err != nil {
|
||||||
output.Close()
|
output.Close()
|
||||||
return err
|
return err
|
||||||
@ -92,6 +94,33 @@ func (dcp *DCP) writeCode(outFile string, useGofmt bool) error {
|
|||||||
return output.Close()
|
return output.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dcp *DCP) OrderedServices() []SCPDWithURN {
|
||||||
|
services := append([]SCPDWithURN{}, dcp.Services...)
|
||||||
|
sort.SliceStable(services, func(i, j int) bool {
|
||||||
|
return services[i].URNParts.URN < services[j].URNParts.URN
|
||||||
|
})
|
||||||
|
return services
|
||||||
|
}
|
||||||
|
|
||||||
|
func orderedURNParts(urnMap map[string]*URNParts) []*URNParts {
|
||||||
|
urns := make([]*URNParts, 0, len(urnMap))
|
||||||
|
for _, urn := range urnMap {
|
||||||
|
urns = append(urns, urn)
|
||||||
|
}
|
||||||
|
sort.SliceStable(urns, func(i, j int) bool {
|
||||||
|
return urns[i].URN < urns[j].URN
|
||||||
|
})
|
||||||
|
return urns
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dcp *DCP) OrderedDeviceTypes() []*URNParts {
|
||||||
|
return orderedURNParts(dcp.DeviceTypes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dcp *DCP) OrderedServiceTypes() []*URNParts {
|
||||||
|
return orderedURNParts(dcp.ServiceTypes)
|
||||||
|
}
|
||||||
|
|
||||||
func (dcp *DCP) processSCPDFile(file *zip.File) error {
|
func (dcp *DCP) processSCPDFile(file *zip.File) error {
|
||||||
scpd := new(scpd.SCPD)
|
scpd := new(scpd.SCPD)
|
||||||
if err := unmarshalXmlFile(file, scpd); err != nil {
|
if err := unmarshalXmlFile(file, scpd); err != nil {
|
||||||
|
11532
dcps/av1/av1.go
11532
dcps/av1/av1.go
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2
go.mod
2
go.mod
@ -4,5 +4,5 @@ go 1.14
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150
|
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150
|
||||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -2,3 +2,5 @@ github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150 h1:vlNjIqmUZ9CMAWsbURY
|
|||||||
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
|
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
|
||||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
|
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
|
||||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
@ -2,6 +2,7 @@ package scpd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,6 +38,14 @@ func (scpd *SCPD) Clean() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scpd *SCPD) OrderedActions() []Action {
|
||||||
|
actions := append([]Action{}, scpd.Actions...)
|
||||||
|
sort.SliceStable(actions, func(i, j int) bool {
|
||||||
|
return actions[i].Name < actions[j].Name
|
||||||
|
})
|
||||||
|
return actions
|
||||||
|
}
|
||||||
|
|
||||||
func (scpd *SCPD) GetStateVariable(variable string) *StateVariable {
|
func (scpd *SCPD) GetStateVariable(variable string) *StateVariable {
|
||||||
for i := range scpd.StateVariables {
|
for i := range scpd.StateVariables {
|
||||||
v := &scpd.StateVariables[i]
|
v := &scpd.StateVariables[i]
|
||||||
|
Loading…
Reference in New Issue
Block a user