Cut down on useless argument/return docs.

This commit is contained in:
John Beisley 2015-06-07 10:42:22 +01:00
parent 4eb9134d2b
commit 99da32467b
4 changed files with 210 additions and 2915 deletions

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

View File

@ -275,7 +275,19 @@ type SCPDWithURN struct {
SCPD *scpd.SCPD SCPD *scpd.SCPD
} }
func (s *SCPDWithURN) WrapArgument(arg scpd.Argument) (*argumentWrapper, error) { func (s *SCPDWithURN) WrapArguments(args []*scpd.Argument) (argumentWrapperList, error) {
wrappedArgs := make(argumentWrapperList, len(args))
for i, arg := range args {
wa, err := s.wrapArgument(arg)
if err != nil {
return nil, err
}
wrappedArgs[i] = wa
}
return wrappedArgs, nil
}
func (s *SCPDWithURN) wrapArgument(arg *scpd.Argument) (*argumentWrapper, error) {
relVar := s.SCPD.GetStateVariable(arg.RelatedStateVariable) relVar := s.SCPD.GetStateVariable(arg.RelatedStateVariable)
if relVar == nil { if relVar == nil {
return nil, fmt.Errorf("no such state variable: %q, for argument %q", arg.RelatedStateVariable, arg.Name) return nil, fmt.Errorf("no such state variable: %q, for argument %q", arg.RelatedStateVariable, arg.Name)
@ -285,7 +297,7 @@ func (s *SCPDWithURN) WrapArgument(arg scpd.Argument) (*argumentWrapper, error)
return nil, fmt.Errorf("unknown data type: %q, for state variable %q, for argument %q", relVar.DataType.Type, arg.RelatedStateVariable, arg.Name) return nil, fmt.Errorf("unknown data type: %q, for state variable %q, for argument %q", relVar.DataType.Type, arg.RelatedStateVariable, arg.Name)
} }
return &argumentWrapper{ return &argumentWrapper{
Argument: arg, Argument: *arg,
relVar: relVar, relVar: relVar,
conv: cnv, conv: cnv,
}, nil }, nil
@ -301,6 +313,12 @@ func (arg *argumentWrapper) AsParameter() string {
return fmt.Sprintf("%s %s", arg.Name, arg.conv.ExtType) return fmt.Sprintf("%s %s", arg.Name, arg.conv.ExtType)
} }
func (arg *argumentWrapper) HasDoc() bool {
rng := arg.relVar.AllowedValueRange
return ((rng != nil && (rng.Minimum != "" || rng.Maximum != "" || rng.Step != "")) ||
len(arg.relVar.AllowedValues) > 0)
}
func (arg *argumentWrapper) Document() string { func (arg *argumentWrapper) Document() string {
relVar := arg.relVar relVar := arg.relVar
if rng := relVar.AllowedValueRange; rng != nil { if rng := relVar.AllowedValueRange; rng != nil {
@ -330,6 +348,17 @@ func (arg *argumentWrapper) Unmarshal(objVar string) string {
return fmt.Sprintf("soap.Unmarshal%s(%s.%s)", arg.conv.FuncSuffix, objVar, arg.Name) return fmt.Sprintf("soap.Unmarshal%s(%s.%s)", arg.conv.FuncSuffix, objVar, arg.Name)
} }
type argumentWrapperList []*argumentWrapper
func (args argumentWrapperList) HasDoc() bool {
for _, arg := range args {
if arg.HasDoc() {
return true
}
}
return false
}
type conv struct { type conv struct {
FuncSuffix string FuncSuffix string
ExtType string ExtType string
@ -524,29 +553,33 @@ func new{{$srvIdent}}ClientsFromGenericClients(genericClients []goupnp.ServiceCl
{{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}} {{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}}
{{$inargs := .InputArguments}}{{$outargs := .OutputArguments}} {{$winargs := $srv.WrapArguments .InputArguments}}
// {{if $inargs}}Arguments:{{range $inargs}}{{$argWrap := $srv.WrapArgument .}} {{$woutargs := $srv.WrapArguments .OutputArguments}}
{{if $winargs.HasDoc}}
// //
// * {{.Name}}: {{$argWrap.Document}}{{end}}{{end}} // Arguments:{{range $winargs}}{{if .HasDoc}}
// //
// {{if $outargs}}Return values:{{range $outargs}}{{$argWrap := $srv.WrapArgument .}} // * {{.Name}}: {{.Document}}{{end}}{{end}}{{end}}
{{if $woutargs.HasDoc}}
// //
// * {{.Name}}: {{$argWrap.Document}}{{end}}{{end}} // Return values:{{range $woutargs}}{{if .HasDoc}}
func (client *{{$srvIdent}}) {{.Name}}({{range $inargs}}{{/* //
*/}}{{$argWrap := $srv.WrapArgument .}}{{$argWrap.AsParameter}}, {{end}}{{/* // * {{.Name}}: {{.Document}}{{end}}{{end}}{{end}}
*/}}) ({{range $outargs}}{{/* func (client *{{$srvIdent}}) {{.Name}}({{range $winargs}}{{/*
*/}}{{$argWrap := $srv.WrapArgument .}}{{$argWrap.AsParameter}}, {{end}} err error) { */}}{{.AsParameter}}, {{end}}{{/*
*/}}) ({{range $woutargs}}{{/*
*/}}{{.AsParameter}}, {{end}} err error) {
// Request structure. // Request structure.
request := {{if $inargs}}&{{template "argstruct" $inargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}} request := {{if $winargs}}&{{template "argstruct" $winargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}}
// BEGIN Marshal arguments into request. // BEGIN Marshal arguments into request.
{{range $inargs}}{{$argWrap := $srv.WrapArgument .}} {{range $winargs}}
if request.{{.Name}}, err = {{$argWrap.Marshal}}; err != nil { if request.{{.Name}}, err = {{.Marshal}}; err != nil {
return return
}{{end}} }{{end}}
// END Marshal arguments into request. // END Marshal arguments into request.
// Response structure. // Response structure.
response := {{if $outargs}}&{{template "argstruct" $outargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}} response := {{if $woutargs}}&{{template "argstruct" $woutargs}}{{"{}"}}{{else}}{{"interface{}(nil)"}}{{end}}
// Perform the SOAP call. // Perform the SOAP call.
if err = client.SOAPClient.PerformAction({{$srv.URNParts.Const}}, "{{.Name}}", request, response); err != nil { if err = client.SOAPClient.PerformAction({{$srv.URNParts.Const}}, "{{.Name}}", request, response); err != nil {
@ -554,8 +587,8 @@ func (client *{{$srvIdent}}) {{.Name}}({{range $inargs}}{{/*
} }
// BEGIN Unmarshal arguments from response. // BEGIN Unmarshal arguments from response.
{{range $outargs}}{{$argWrap := $srv.WrapArgument .}} {{range $woutargs}}
if {{.Name}}, err = {{$argWrap.Unmarshal "response"}}; err != nil { if {{.Name}}, err = {{.Unmarshal "response"}}; err != nil {
return return
}{{end}} }{{end}}
// END Unmarshal arguments from response. // END Unmarshal arguments from response.