Add New*Clients functions to the generated code to simplify their use.

This commit is contained in:
John Beisley 2013-12-31 20:01:17 +00:00
parent 03572e5988
commit 1f02d6bce3
6 changed files with 530 additions and 65 deletions

View File

@ -5,40 +5,32 @@ package main
import (
"fmt"
"github.com/huin/goupnp"
"github.com/huin/goupnp/dcps/internetgateway1"
)
func main() {
results, err := goupnp.DiscoverDevices(internetgateway1.URN_WANPPPConnection_1)
clients, errors, err := internetgateway1.NewWANPPPConnection1Clients()
if err != nil {
fmt.Println("Error discovering InternetGatewayDevice with UPnP: ", err)
fmt.Println("Error discovering service with UPnP: ", err)
return
}
fmt.Printf("Discovered %d InternetGatewayDevices:\n", len(results))
for _, maybeRootDevice := range results {
if maybeRootDevice.Err != nil {
fmt.Println(maybeRootDevice.Err)
continue
if len(errors) > 0 {
fmt.Printf("Error discovering %d services:\n", len(errors))
for _, err := range errors {
fmt.Println(" ", err)
}
}
device := &maybeRootDevice.Root.Device
fmt.Printf("Successfully discovered %d services:\n", len(clients))
for _, client := range clients {
device := &client.RootDevice.Device
fmt.Println("Device ", device.FriendlyName)
wanPPPSrvs := device.FindService(internetgateway1.URN_WANPPPConnection_1)
if len(wanPPPSrvs) < 1 {
fmt.Printf("Could not find expected service on device %s\n", device.FriendlyName)
continue
}
for _, srv := range wanPPPSrvs {
client := internetgateway1.WANPPPConnection1{srv.NewSOAPClient()}
if addr, err := client.GetExternalIPAddress(); err != nil {
fmt.Printf("Failed to get external IP address: %v\n", err)
} else {
fmt.Printf("External IP address: %v\n", addr)
}
fmt.Println(" Device:", device.FriendlyName)
if addr, err := client.GetExternalIPAddress(); err != nil {
fmt.Printf(" Failed to get external IP address: %v\n", err)
} else {
fmt.Printf(" External IP address: %v\n", addr)
}
}
}

View File

@ -9,6 +9,7 @@ var packageTmpl = template.Must(template.New("package").Parse(`package {{.Name}}
import (
"time"
"github.com/huin/goupnp"
"github.com/huin/goupnp/soap"
)
@ -29,9 +30,29 @@ const ({{range .ServiceTypes}}
{{$srv := .}}
{{$srvIdent := printf "%s%s" .Name .Version}}
// {{$srvIdent}} is a client for UPnP SOAP service with URN "{{.URN}}".
// {{$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 {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// New{{$srvIdent}}Clients discovers instances of the service on the network,
// 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.
func New{{$srvIdent}}Clients() (clients []*{{$srvIdent}}, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients({{$srv.Const}}); err != nil {
return
}
clients = make([]*{{$srvIdent}}, len(genericClients))
for i := range genericClients {
clients[i] = &{{$srvIdent}}{genericClients[i]}
}
return
}
{{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}}

View File

@ -176,6 +176,7 @@ func (dcp *DCP) writePackage(outDir string) error {
defer packageFile.Close()
gofmt := exec.Command("gofmt")
gofmt.Stdout = packageFile
gofmt.Stderr = os.Stderr
gofmtWriter, err := gofmt.StdinPipe()
if err != nil {
return err

View File

@ -3,6 +3,7 @@ package internetgateway1
import (
"time"
"github.com/huin/goupnp"
"github.com/huin/goupnp/soap"
)
@ -29,9 +30,29 @@ const (
URN_WANPPPConnection_1 = "urn:schemas-upnp-org:service:WANPPPConnection:1"
)
// LANHostConfigManagement1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:LANHostConfigManagement:1".
// LANHostConfigManagement1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:LANHostConfigManagement:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type LANHostConfigManagement1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewLANHostConfigManagement1Clients discovers instances of the service on the network,
// 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.
func NewLANHostConfigManagement1Clients() (clients []*LANHostConfigManagement1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_LANHostConfigManagement_1); err != nil {
return
}
clients = make([]*LANHostConfigManagement1, len(genericClients))
for i := range genericClients {
clients[i] = &LANHostConfigManagement1{genericClients[i]}
}
return
}
// Arguments:
@ -635,9 +656,29 @@ func (client *LANHostConfigManagement1) GetDNSServers() (NewDNSServers string, e
return
}
// Layer3Forwarding1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:Layer3Forwarding:1".
// Layer3Forwarding1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:Layer3Forwarding:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type Layer3Forwarding1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewLayer3Forwarding1Clients discovers instances of the service on the network,
// 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.
func NewLayer3Forwarding1Clients() (clients []*Layer3Forwarding1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_Layer3Forwarding_1); err != nil {
return
}
clients = make([]*Layer3Forwarding1, len(genericClients))
for i := range genericClients {
clients[i] = &Layer3Forwarding1{genericClients[i]}
}
return
}
// Arguments:
@ -702,9 +743,29 @@ func (client *Layer3Forwarding1) GetDefaultConnectionService() (NewDefaultConnec
return
}
// WANCableLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCableLinkConfig:1".
// WANCableLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCableLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANCableLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANCableLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANCableLinkConfig1Clients() (clients []*WANCableLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCableLinkConfig_1); err != nil {
return
}
clients = make([]*WANCableLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANCableLinkConfig1{genericClients[i]}
}
return
}
//
@ -1023,9 +1084,29 @@ func (client *WANCableLinkConfig1) GetTFTPServer() (NewTFTPServer string, err er
return
}
// WANCommonInterfaceConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1".
// WANCommonInterfaceConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANCommonInterfaceConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANCommonInterfaceConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANCommonInterfaceConfig1Clients() (clients []*WANCommonInterfaceConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCommonInterfaceConfig_1); err != nil {
return
}
clients = make([]*WANCommonInterfaceConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANCommonInterfaceConfig1{genericClients[i]}
}
return
}
// Arguments:
@ -1369,9 +1450,29 @@ func (client *WANCommonInterfaceConfig1) GetActiveConnection(NewActiveConnection
return
}
// WANDSLLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANDSLLinkConfig:1".
// WANDSLLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANDSLLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANDSLLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANDSLLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANDSLLinkConfig1Clients() (clients []*WANDSLLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANDSLLinkConfig_1); err != nil {
return
}
clients = make([]*WANDSLLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANDSLLinkConfig1{genericClients[i]}
}
return
}
// Arguments:
@ -1690,9 +1791,29 @@ func (client *WANDSLLinkConfig1) GetFCSPreserved() (NewFCSPreserved bool, err er
return
}
// WANEthernetLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANEthernetLinkConfig:1".
// WANEthernetLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANEthernetLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANEthernetLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANEthernetLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANEthernetLinkConfig1Clients() (clients []*WANEthernetLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANEthernetLinkConfig_1); err != nil {
return
}
clients = make([]*WANEthernetLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANEthernetLinkConfig1{genericClients[i]}
}
return
}
//
@ -1726,9 +1847,29 @@ func (client *WANEthernetLinkConfig1) GetEthernetLinkStatus() (NewEthernetLinkSt
return
}
// WANIPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPConnection:1".
// WANIPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPConnection:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANIPConnection1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANIPConnection1Clients discovers instances of the service on the network,
// 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.
func NewWANIPConnection1Clients() (clients []*WANIPConnection1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPConnection_1); err != nil {
return
}
clients = make([]*WANIPConnection1, len(genericClients))
for i := range genericClients {
clients[i] = &WANIPConnection1{genericClients[i]}
}
return
}
// Arguments:
@ -2438,9 +2579,29 @@ func (client *WANIPConnection1) GetExternalIPAddress() (NewExternalIPAddress str
return
}
// WANPOTSLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPOTSLinkConfig:1".
// WANPOTSLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPOTSLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANPOTSLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANPOTSLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANPOTSLinkConfig1Clients() (clients []*WANPOTSLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANPOTSLinkConfig_1); err != nil {
return
}
clients = make([]*WANPOTSLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANPOTSLinkConfig1{genericClients[i]}
}
return
}
// Arguments:
@ -2758,9 +2919,29 @@ func (client *WANPOTSLinkConfig1) GetPlusVTRCommandSupported() (NewPlusVTRComman
return
}
// WANPPPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPPPConnection:1".
// WANPPPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPPPConnection:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANPPPConnection1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANPPPConnection1Clients discovers instances of the service on the network,
// 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.
func NewWANPPPConnection1Clients() (clients []*WANPPPConnection1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANPPPConnection_1); err != nil {
return
}
clients = make([]*WANPPPConnection1, len(genericClients))
for i := range genericClients {
clients[i] = &WANPPPConnection1{genericClients[i]}
}
return
}
// Arguments:

View File

@ -3,6 +3,7 @@ package internetgateway2
import (
"time"
"github.com/huin/goupnp"
"github.com/huin/goupnp/soap"
)
@ -33,9 +34,29 @@ const (
URN_WANPPPConnection_1 = "urn:schemas-upnp-org:service:WANPPPConnection:1"
)
// LANHostConfigManagement1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:LANHostConfigManagement:1".
// LANHostConfigManagement1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:LANHostConfigManagement:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type LANHostConfigManagement1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewLANHostConfigManagement1Clients discovers instances of the service on the network,
// 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.
func NewLANHostConfigManagement1Clients() (clients []*LANHostConfigManagement1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_LANHostConfigManagement_1); err != nil {
return
}
clients = make([]*LANHostConfigManagement1, len(genericClients))
for i := range genericClients {
clients[i] = &LANHostConfigManagement1{genericClients[i]}
}
return
}
// Arguments:
@ -639,9 +660,29 @@ func (client *LANHostConfigManagement1) GetDNSServers() (NewDNSServers string, e
return
}
// Layer3Forwarding1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:Layer3Forwarding:1".
// Layer3Forwarding1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:Layer3Forwarding:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type Layer3Forwarding1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewLayer3Forwarding1Clients discovers instances of the service on the network,
// 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.
func NewLayer3Forwarding1Clients() (clients []*Layer3Forwarding1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_Layer3Forwarding_1); err != nil {
return
}
clients = make([]*Layer3Forwarding1, len(genericClients))
for i := range genericClients {
clients[i] = &Layer3Forwarding1{genericClients[i]}
}
return
}
// Arguments:
@ -706,9 +747,29 @@ func (client *Layer3Forwarding1) GetDefaultConnectionService() (NewDefaultConnec
return
}
// WANCableLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCableLinkConfig:1".
// WANCableLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCableLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANCableLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANCableLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANCableLinkConfig1Clients() (clients []*WANCableLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCableLinkConfig_1); err != nil {
return
}
clients = make([]*WANCableLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANCableLinkConfig1{genericClients[i]}
}
return
}
//
@ -1027,9 +1088,29 @@ func (client *WANCableLinkConfig1) GetTFTPServer() (NewTFTPServer string, err er
return
}
// WANCommonInterfaceConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1".
// WANCommonInterfaceConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANCommonInterfaceConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANCommonInterfaceConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANCommonInterfaceConfig1Clients() (clients []*WANCommonInterfaceConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCommonInterfaceConfig_1); err != nil {
return
}
clients = make([]*WANCommonInterfaceConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANCommonInterfaceConfig1{genericClients[i]}
}
return
}
// Arguments:
@ -1373,9 +1454,29 @@ func (client *WANCommonInterfaceConfig1) GetActiveConnection(NewActiveConnection
return
}
// WANDSLLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANDSLLinkConfig:1".
// WANDSLLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANDSLLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANDSLLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANDSLLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANDSLLinkConfig1Clients() (clients []*WANDSLLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANDSLLinkConfig_1); err != nil {
return
}
clients = make([]*WANDSLLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANDSLLinkConfig1{genericClients[i]}
}
return
}
// Arguments:
@ -1694,9 +1795,29 @@ func (client *WANDSLLinkConfig1) GetFCSPreserved() (NewFCSPreserved bool, err er
return
}
// WANEthernetLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANEthernetLinkConfig:1".
// WANEthernetLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANEthernetLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANEthernetLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANEthernetLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANEthernetLinkConfig1Clients() (clients []*WANEthernetLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANEthernetLinkConfig_1); err != nil {
return
}
clients = make([]*WANEthernetLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANEthernetLinkConfig1{genericClients[i]}
}
return
}
//
@ -1730,9 +1851,29 @@ func (client *WANEthernetLinkConfig1) GetEthernetLinkStatus() (NewEthernetLinkSt
return
}
// WANIPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPConnection:1".
// WANIPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPConnection:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANIPConnection1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANIPConnection1Clients discovers instances of the service on the network,
// 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.
func NewWANIPConnection1Clients() (clients []*WANIPConnection1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPConnection_1); err != nil {
return
}
clients = make([]*WANIPConnection1, len(genericClients))
for i := range genericClients {
clients[i] = &WANIPConnection1{genericClients[i]}
}
return
}
// Arguments:
@ -2442,9 +2583,29 @@ func (client *WANIPConnection1) GetExternalIPAddress() (NewExternalIPAddress str
return
}
// WANIPConnection2 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPConnection:2".
// WANIPConnection2 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPConnection:2". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANIPConnection2 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANIPConnection2Clients discovers instances of the service on the network,
// 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.
func NewWANIPConnection2Clients() (clients []*WANIPConnection2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPConnection_2); err != nil {
return
}
clients = make([]*WANIPConnection2, len(genericClients))
for i := range genericClients {
clients[i] = &WANIPConnection2{genericClients[i]}
}
return
}
// Arguments:
@ -3345,9 +3506,29 @@ func (client *WANIPConnection2) AddAnyPortMapping(NewRemoteHost string, NewExter
return
}
// WANIPv6FirewallControl1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1".
// WANIPv6FirewallControl1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANIPv6FirewallControl1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANIPv6FirewallControl1Clients discovers instances of the service on the network,
// 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.
func NewWANIPv6FirewallControl1Clients() (clients []*WANIPv6FirewallControl1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPv6FirewallControl_1); err != nil {
return
}
clients = make([]*WANIPv6FirewallControl1, len(genericClients))
for i := range genericClients {
clients[i] = &WANIPv6FirewallControl1{genericClients[i]}
}
return
}
//
@ -3661,9 +3842,29 @@ func (client *WANIPv6FirewallControl1) CheckPinholeWorking(UniqueID uint16) (IsW
return
}
// WANPOTSLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPOTSLinkConfig:1".
// WANPOTSLinkConfig1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPOTSLinkConfig:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANPOTSLinkConfig1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANPOTSLinkConfig1Clients discovers instances of the service on the network,
// 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.
func NewWANPOTSLinkConfig1Clients() (clients []*WANPOTSLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANPOTSLinkConfig_1); err != nil {
return
}
clients = make([]*WANPOTSLinkConfig1, len(genericClients))
for i := range genericClients {
clients[i] = &WANPOTSLinkConfig1{genericClients[i]}
}
return
}
// Arguments:
@ -3981,9 +4182,29 @@ func (client *WANPOTSLinkConfig1) GetPlusVTRCommandSupported() (NewPlusVTRComman
return
}
// WANPPPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPPPConnection:1".
// WANPPPConnection1 is a client for UPnP SOAP service with URN "urn:schemas-upnp-org:service:WANPPPConnection:1". See
// goupnp.ServiceClient, which contains RootDevice and Service attributes which
// are provided for informational value.
type WANPPPConnection1 struct {
SOAPClient *soap.SOAPClient
goupnp.ServiceClient
}
// NewWANPPPConnection1Clients discovers instances of the service on the network,
// 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.
func NewWANPPPConnection1Clients() (clients []*WANPPPConnection1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANPPPConnection_1); err != nil {
return
}
clients = make([]*WANPPPConnection1, len(genericClients))
for i := range genericClients {
clients[i] = &WANPPPConnection1{genericClients[i]}
}
return
}
// Arguments:

49
service_client.go Normal file
View File

@ -0,0 +1,49 @@
package goupnp
import (
"fmt"
"github.com/huin/goupnp/soap"
)
// ServiceClient is a SOAP client, root device and the service for the SOAP
// client rolled into one value. The root device and service are intended to be
// informational.
type ServiceClient struct {
SOAPClient *soap.SOAPClient
RootDevice *RootDevice
Service *Service
}
func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error) {
var maybeRootDevices []MaybeRootDevice
if maybeRootDevices, err = DiscoverDevices(searchTarget); err != nil {
return
}
clients = make([]ServiceClient, 0, len(maybeRootDevices))
for _, maybeRootDevice := range maybeRootDevices {
if maybeRootDevice.Err != nil {
errors = append(errors, maybeRootDevice.Err)
continue
}
device := &maybeRootDevice.Root.Device
srvs := device.FindService(searchTarget)
if len(srvs) == 0 {
errors = append(errors, fmt.Errorf("goupnp: service %q not found within device %q (UDN=%q)",
searchTarget, device.FriendlyName, device.UDN))
continue
}
for _, srv := range srvs {
clients = append(clients, ServiceClient{
SOAPClient: srv.NewSOAPClient(),
RootDevice: maybeRootDevice.Root,
Service: srv,
})
}
}
return
}