2021-08-14 09:17:22 +00:00
|
|
|
{{$name := .Metadata.Name -}}
|
2018-10-13 14:04:17 +00:00
|
|
|
// Client for UPnP Device Control Protocol {{.Metadata.OfficialName}}.
|
2022-03-21 13:46:32 +00:00
|
|
|
// {{if .DocURLs}}
|
|
|
|
// This DCP is documented in detail at: {{range .DocURLs}}
|
|
|
|
// - {{.}}{{end}}{{end}}
|
2018-10-13 14:04:17 +00:00
|
|
|
//
|
|
|
|
// Typically, use one of the New* functions to create clients for services.
|
2022-03-21 13:46:32 +00:00
|
|
|
package {{$name | base}}
|
2018-10-13 14:04:17 +00:00
|
|
|
|
|
|
|
// ***********************************************************
|
|
|
|
// GENERATED FILE - DO NOT EDIT BY HAND. See README.md
|
|
|
|
// ***********************************************************
|
|
|
|
|
|
|
|
import (
|
2021-07-11 13:53:32 +00:00
|
|
|
"context"
|
2018-10-13 14:04:17 +00:00
|
|
|
"net/url"
|
|
|
|
"time"
|
|
|
|
|
2022-11-01 19:02:13 +00:00
|
|
|
"git.cyrilix.bzh/cyrilix/goupnp"
|
|
|
|
"git.cyrilix.bzh/cyrilix/goupnp/soap"
|
2018-10-13 14:04:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hack to avoid Go complaining if time isn't used.
|
|
|
|
var _ time.Time
|
|
|
|
|
|
|
|
// Device URNs:
|
2022-03-13 09:02:29 +00:00
|
|
|
const ({{range .OrderedDeviceTypes}}
|
2018-10-13 14:04:17 +00:00
|
|
|
{{.Const}} = "{{.URN}}"{{end}}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Service URNs:
|
2022-03-13 09:02:29 +00:00
|
|
|
const ({{range .OrderedServiceTypes}}
|
2018-10-13 14:04:17 +00:00
|
|
|
{{.Const}} = "{{.URN}}"{{end}}
|
|
|
|
)
|
|
|
|
|
2022-03-13 09:02:29 +00:00
|
|
|
{{range .OrderedServices}}
|
2018-10-13 14:04:17 +00:00
|
|
|
{{$srv := .}}
|
|
|
|
{{$srvIdent := printf "%s%s" .Name .Version}}
|
|
|
|
|
|
|
|
// {{$srvIdent}} is a client for UPnP SOAP service with URN "{{.URN}}". See
|
|
|
|
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
|
|
|
|
// are provided for informational value.
|
|
|
|
type {{$srvIdent}} struct {
|
|
|
|
goupnp.ServiceClient
|
|
|
|
}
|
|
|
|
|
2022-10-01 11:49:02 +00:00
|
|
|
// New{{$srvIdent}}ClientsCtx discovers instances of the service on the network,
|
2018-10-13 14:04:17 +00:00
|
|
|
// and returns clients to any that are found. errors will contain an error for
|
|
|
|
// any devices that replied but which could not be queried, and err will be set
|
|
|
|
// if the discovery process failed outright.
|
|
|
|
//
|
|
|
|
// This is a typical entry calling point into this package.
|
2022-10-01 11:49:02 +00:00
|
|
|
func New{{$srvIdent}}ClientsCtx(ctx context.Context) (clients []*{{$srvIdent}}, errors []error, err error) {
|
2018-10-13 14:04:17 +00:00
|
|
|
var genericClients []goupnp.ServiceClient
|
2022-10-01 11:49:02 +00:00
|
|
|
if genericClients, errors, err = goupnp.NewServiceClientsCtx(ctx, {{$srv.Const}}); err != nil {
|
2018-10-13 14:04:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
clients = new{{$srvIdent}}ClientsFromGenericClients(genericClients)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-01 11:49:02 +00:00
|
|
|
// New{{$srvIdent}}Clients is the legacy version of New{{$srvIdent}}ClientsCtx, but uses
|
|
|
|
// context.Background() as the context.
|
|
|
|
func New{{$srvIdent}}Clients() (clients []*{{$srvIdent}}, errors []error, err error) {
|
|
|
|
return New{{$srvIdent}}ClientsCtx(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
// New{{$srvIdent}}ClientsByURLCtx discovers instances of the service at the given
|
2018-10-13 14:04:17 +00:00
|
|
|
// URL, and returns clients to any that are found. An error is returned if
|
|
|
|
// there was an error probing the service.
|
|
|
|
//
|
|
|
|
// This is a typical entry calling point into this package when reusing an
|
|
|
|
// previously discovered service URL.
|
2022-10-01 11:49:02 +00:00
|
|
|
func New{{$srvIdent}}ClientsByURLCtx(ctx context.Context, loc *url.URL) ([]*{{$srvIdent}}, error) {
|
|
|
|
genericClients, err := goupnp.NewServiceClientsByURLCtx(ctx, loc, {{$srv.Const}})
|
2018-10-13 14:04:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return new{{$srvIdent}}ClientsFromGenericClients(genericClients), nil
|
|
|
|
}
|
|
|
|
|
2022-10-01 11:49:02 +00:00
|
|
|
// New{{$srvIdent}}ClientsByURL is the legacy version of New{{$srvIdent}}ClientsByURLCtx, but uses
|
|
|
|
// context.Background() as the context.
|
|
|
|
func New{{$srvIdent}}ClientsByURL(loc *url.URL) ([]*{{$srvIdent}}, error) {
|
|
|
|
return New{{$srvIdent}}ClientsByURLCtx(context.Background(), loc)
|
|
|
|
}
|
|
|
|
|
2018-10-13 14:04:17 +00:00
|
|
|
// New{{$srvIdent}}ClientsFromRootDevice discovers instances of the service in
|
|
|
|
// a given root device, and returns clients to any that are found. An error is
|
|
|
|
// returned if there was not at least one instance of the service within the
|
|
|
|
// device. The location parameter is simply assigned to the Location attribute
|
|
|
|
// of the wrapped ServiceClient(s).
|
|
|
|
//
|
|
|
|
// This is a typical entry calling point into this package when reusing an
|
|
|
|
// previously discovered root device.
|
|
|
|
func New{{$srvIdent}}ClientsFromRootDevice(rootDevice *goupnp.RootDevice, loc *url.URL) ([]*{{$srvIdent}}, error) {
|
|
|
|
genericClients, err := goupnp.NewServiceClientsFromRootDevice(rootDevice, loc, {{$srv.Const}})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return new{{$srvIdent}}ClientsFromGenericClients(genericClients), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func new{{$srvIdent}}ClientsFromGenericClients(genericClients []goupnp.ServiceClient) []*{{$srvIdent}} {
|
|
|
|
clients := make([]*{{$srvIdent}}, len(genericClients))
|
|
|
|
for i := range genericClients {
|
|
|
|
clients[i] = &{{$srvIdent}}{genericClients[i]}
|
|
|
|
}
|
|
|
|
return clients
|
|
|
|
}
|
|
|
|
|
2022-03-13 09:02:29 +00:00
|
|
|
{{range .SCPD.OrderedActions}}{{/* loops over *SCPDWithURN values */}}
|
2018-10-13 14:04:17 +00:00
|
|
|
|
|
|
|
{{$winargs := $srv.WrapArguments .InputArguments}}
|
|
|
|
{{$woutargs := $srv.WrapArguments .OutputArguments}}
|
|
|
|
{{if $winargs.HasDoc}}
|
|
|
|
//
|
|
|
|
// Arguments:{{range $winargs}}{{if .HasDoc}}
|
|
|
|
//
|
|
|
|
// * {{.Name}}: {{.Document}}{{end}}{{end}}{{end}}
|
|
|
|
{{if $woutargs.HasDoc}}
|
|
|
|
//
|
|
|
|
// Return values:{{range $woutargs}}{{if .HasDoc}}
|
|
|
|
//
|
|
|
|
// * {{.Name}}: {{.Document}}{{end}}{{end}}{{end}}
|
2021-07-11 13:53:32 +00:00
|
|
|
func (client *{{$srvIdent}}) {{.Name}}Ctx(
|
|
|
|
ctx context.Context,
|
|
|
|
{{range $winargs }} {{.AsParameter}},
|
|
|
|
{{end -}}
|
2018-10-13 14:04:17 +00:00
|
|
|
) ({{range $woutargs -}}
|
|
|
|
{{.AsParameter}}, {{end}} err error) {
|
|
|
|
// Request structure.
|
|
|
|
request := {{if $winargs}}&{{template "argstruct" $winargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}}
|
|
|
|
// BEGIN Marshal arguments into request.
|
|
|
|
{{range $winargs}}
|
2021-08-18 16:03:52 +00:00
|
|
|
if request.{{.Name}}, err = {{.MarshalV1}}; err != nil {
|
2018-10-13 14:04:17 +00:00
|
|
|
return
|
|
|
|
}{{end}}
|
|
|
|
// END Marshal arguments into request.
|
|
|
|
|
|
|
|
// Response structure.
|
|
|
|
response := {{if $woutargs}}&{{template "argstruct" $woutargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}}
|
|
|
|
|
|
|
|
// Perform the SOAP call.
|
2021-07-11 13:53:32 +00:00
|
|
|
if err = client.SOAPClient.PerformActionCtx(ctx, {{$srv.URNParts.Const}}, "{{.Name}}", request, response); err != nil {
|
2018-10-13 14:04:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// BEGIN Unmarshal arguments from response.
|
|
|
|
{{range $woutargs}}
|
2021-08-18 16:03:52 +00:00
|
|
|
if {{.Name}}, err = {{.UnmarshalV1 "response"}}; err != nil {
|
2018-10-13 14:04:17 +00:00
|
|
|
return
|
|
|
|
}{{end}}
|
|
|
|
// END Unmarshal arguments from response.
|
|
|
|
return
|
|
|
|
}
|
2021-07-11 13:53:32 +00:00
|
|
|
|
|
|
|
// {{.Name}} is the legacy version of {{.Name}}Ctx, but uses
|
|
|
|
// context.Background() as the context.
|
|
|
|
func (client *{{$srvIdent}}) {{.Name}}({{range $winargs -}}
|
|
|
|
{{.AsParameter}}, {{end -}}
|
|
|
|
) ({{range $woutargs -}}
|
|
|
|
{{.AsParameter}}, {{end}} err error) {
|
|
|
|
return client.{{.Name}}Ctx(context.Background(),
|
|
|
|
{{range $winargs }}{{.Name}},
|
|
|
|
{{end}}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-10-13 14:04:17 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "argstruct"}}struct {{"{"}}
|
|
|
|
{{range .}}{{.Name}} string
|
|
|
|
{{end}}{{"}"}}{{end}}
|