2013-10-06 21:06:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var packageTmpl = template.Must(template.New("package").Parse(`package {{.Name}}
|
|
|
|
|
2013-12-31 16:56:20 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/huin/goupnp/soap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hack to avoid Go complaining if time isn't used.
|
|
|
|
var _ time.Time
|
2013-10-06 21:06:47 +00:00
|
|
|
|
2013-12-31 18:04:59 +00:00
|
|
|
// Device URNs:
|
2013-10-06 21:06:47 +00:00
|
|
|
const ({{range .DeviceTypes}}
|
2013-12-31 18:04:59 +00:00
|
|
|
{{.Const}} = "{{.URN}}"{{end}}
|
|
|
|
)
|
2013-10-06 21:06:47 +00:00
|
|
|
|
2013-12-31 18:04:59 +00:00
|
|
|
// Service URNs:
|
2013-10-06 21:06:47 +00:00
|
|
|
const ({{range .ServiceTypes}}
|
2013-12-31 18:04:59 +00:00
|
|
|
{{.Const}} = "{{.URN}}"{{end}}
|
|
|
|
)
|
2013-10-06 21:06:47 +00:00
|
|
|
|
|
|
|
{{range .Services}}
|
|
|
|
{{$srv := .}}
|
|
|
|
{{$srvIdent := printf "%s%s" .Name .Version}}
|
|
|
|
|
|
|
|
// {{$srvIdent}} is a client for UPnP SOAP service with URN "{{.URN}}".
|
|
|
|
type {{$srvIdent}} struct {
|
|
|
|
SOAPClient soap.SOAPClient
|
|
|
|
}
|
|
|
|
|
|
|
|
{{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}}
|
|
|
|
|
2013-12-31 17:52:43 +00:00
|
|
|
{{$inargs := .InputArguments}}{{$outargs := .OutputArguments}}
|
2013-10-06 22:16:25 +00:00
|
|
|
// {{.Name}} action.
|
|
|
|
//
|
2013-12-31 17:52:43 +00:00
|
|
|
// {{if $inargs}}Arguments:{{range $inargs}}{{$argWrap := $srv.WrapArgument .}}
|
2013-12-31 18:04:59 +00:00
|
|
|
//
|
|
|
|
// * {{.Name}}: {{$argWrap.Document}}{{end}}{{end}}
|
|
|
|
//
|
2013-12-31 17:52:43 +00:00
|
|
|
// {{if $outargs}}Return values:{{range $outargs}}{{$argWrap := $srv.WrapArgument .}}
|
2013-12-31 18:04:59 +00:00
|
|
|
//
|
|
|
|
// * {{.Name}}: {{$argWrap.Document}}{{end}}{{end}}
|
2013-12-31 17:52:43 +00:00
|
|
|
func (client *{{$srvIdent}}) {{.Name}}({{range $inargs}}{{/*
|
|
|
|
*/}}{{$argWrap := $srv.WrapArgument .}}{{$argWrap.AsParameter}}, {{end}}{{/*
|
|
|
|
*/}}) ({{range $outargs}}{{/*
|
|
|
|
*/}}{{$argWrap := $srv.WrapArgument .}}{{$argWrap.AsParameter}}, {{end}} err error) {
|
2013-12-31 17:06:15 +00:00
|
|
|
// Request structure.
|
|
|
|
var request struct {{"{"}}{{range .Arguments}}{{if .IsInput}}{{.Name}} string
|
|
|
|
{{end}}{{end}}}
|
2013-12-31 16:56:20 +00:00
|
|
|
// BEGIN Marshal arguments into request.
|
2013-12-31 17:52:43 +00:00
|
|
|
{{range $inargs}}{{$argWrap := $srv.WrapArgument .}}
|
2013-12-31 16:56:20 +00:00
|
|
|
if request.{{.Name}}, err = {{$argWrap.Marshal}}; err != nil {
|
|
|
|
return
|
2013-12-31 17:52:43 +00:00
|
|
|
}{{end}}
|
2013-12-31 16:56:20 +00:00
|
|
|
// END Marshal arguments into request.
|
|
|
|
|
2013-12-31 17:06:15 +00:00
|
|
|
// Response structure.
|
2013-12-31 17:52:43 +00:00
|
|
|
var response struct {{"{"}}{{range $outargs}}{{.Name}} string
|
|
|
|
{{end}}}
|
2013-12-31 17:06:15 +00:00
|
|
|
|
2013-12-31 16:56:20 +00:00
|
|
|
// Perform the SOAP call.
|
|
|
|
if err = client.SOAPClient.PerformAction({{$srv.URNParts.Const}}, "{{.Name}}", &request, &response); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// BEGIN Unmarshal arguments from response.
|
2013-12-31 17:52:43 +00:00
|
|
|
{{range $outargs}}{{$argWrap := $srv.WrapArgument .}}
|
2013-12-31 16:56:20 +00:00
|
|
|
if {{.Name}}, err = {{$argWrap.Unmarshal "response"}}; err != nil {
|
2013-10-06 21:06:47 +00:00
|
|
|
return
|
2013-12-31 17:52:43 +00:00
|
|
|
}{{end}}
|
2013-12-31 16:56:20 +00:00
|
|
|
// END Unmarshal arguments from response.
|
2013-10-06 21:06:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
{{end}}{{/* range .SCPD.Actions */}}
|
|
|
|
{{end}}{{/* range .Services */}}
|
|
|
|
`))
|