Documentation ¶
Overview ¶
Package go-net-upnp provides UPnP control point and device frameworks to implement the control point and any devices.
go-net-upnp supports UPnP control functions. The control point can search UPnP devices in the local network, get the device and service descriptions. and post actions in the service:
cp := upnp.NewControlPoint() err := cp.Start() ... defer cp.Stop() ... err = cp.SearchRootDevice() ... for n, dev := range cp.GetRootDevices() { ... }
The control point can post actions in the service, and get the action response:
service, err := dev.GetServiceByType("xxxx") ... action, err := service.GetActionByName("xxxx") ... action.SetArgumentString("xxxx", "xxxx") err = action.Post() ... resArg = action.GetArgumentString("xxxx")
In addition to the control point functions, go-net-upnp supports UPnP device functions to implement any UPnP devices using Go.
To implement UPnP devices, prepare the UPnP device and service descriptions as the following:
type SampleDevice struct { *upnp.Device ... } func NewSampleDevice() (*SampleDevice, error) { dev, err := upnp.NewDeviceFromDescription(xxxxDeviceDescription) ... service, err := dev.GetServiceByType("urn:schemas-upnp-org:service:xxxx:x") ... err = service.LoadDescriptionBytes([]byte(xxxxServiceDescription)) ... sampleDev := &SampleDevice{ Device: dev, ... } return sampleDev, nil }
Next, implement the control actions in the service descriptions using upnp.ActionListener as the following:
sampleDev, err := NewSampleDevice() ... sampleDev.ActionListener = sampleDev ... func (self *SampleDevice) ActionRequestReceived(action *upnp.Action) upnp.Error { switch action.Name { case SetTarget: xxxx, err := action.GetArgumentString(xxxx) ... err := action.SetArgumentBool(...., ....) ... return nil case xxxx ... } return upnp.NewErrorFromCode(upnp.ErrorOptionalActionNotImplemented) }
Index ¶
- Constants
- func NewActionRequestFromAction(action *Action) (*control.ActionRequest, error)
- func NewActionResponseFromAction(action *Action) (*control.ActionResponse, error)
- func NewArgumentFromArgument(arg *Argument) *control.Argument
- func NewErrorResponseFromError(upnpError Error) *control.ErrorResponse
- type Action
- func (action *Action) GetArgumentBool(name string) (bool, error)
- func (action *Action) GetArgumentByName(name string) (*Argument, error)
- func (action *Action) GetArgumentFloat(name string) (float64, error)
- func (action *Action) GetArgumentInt(name string) (int, error)
- func (action *Action) GetArgumentString(name string) (string, error)
- func (action *Action) GetArguments() []*Argument
- func (action *Action) GetInputArguments() []*Argument
- func (action *Action) GetOutputArguments() []*Argument
- func (action *Action) Post() error
- func (action *Action) SetArgumentBool(name string, value bool) error
- func (action *Action) SetArgumentFloat(name string, value float64) error
- func (action *Action) SetArgumentInt(name string, value int) error
- func (action *Action) SetArgumentString(name string, value string) error
- func (action *Action) SetArgumentsByActionRequest(actionReq *control.ActionRequest) error
- func (action *Action) SetArgumentsByActionResponse(actionRes *control.ActionResponse) error
- type ActionList
- type AllowedValue
- type AllowedValueList
- type AllowedValueRange
- type Argument
- func (arg *Argument) GetBool() (bool, error)
- func (arg *Argument) GetDirection() int
- func (arg *Argument) GetFloat() (float64, error)
- func (arg *Argument) GetInt() (int, error)
- func (arg *Argument) GetString() (string, error)
- func (arg *Argument) IsInDirection() bool
- func (arg *Argument) IsOutDirection() bool
- func (arg *Argument) SetBool(value bool) error
- func (arg *Argument) SetDirection(dir int) bool
- func (arg *Argument) SetFloat(value float64) error
- func (arg *Argument) SetInt(value int) error
- func (arg *Argument) SetString(value string) error
- type ArgumentList
- type ControlPoint
- func (ctrl *ControlPoint) DeviceNotifyReceived(ssdpReq *ssdp.Request)
- func (ctrl *ControlPoint) DeviceResponseReceived(ssdpRes *ssdp.Response)
- func (ctrl *ControlPoint) DeviceSearchReceived(ssdpReq *ssdp.Request)
- func (ctrl *ControlPoint) FindDeviceByTypeAndUDN(deviceType string, udn string) (*Device, bool)
- func (ctrl *ControlPoint) GetRootDevices() []*Device
- func (ctrl *ControlPoint) GetRootDevicesByType(deviceType string) []*Device
- func (ctrl *ControlPoint) Search(st string) error
- func (ctrl *ControlPoint) SearchRootDevice() error
- func (ctrl *ControlPoint) Start() error
- func (ctrl *ControlPoint) StartWithPort(port int) error
- func (ctrl *ControlPoint) Stop() error
- type ControlPointListener
- type Device
- func (dev *Device) DescriptionString() (string, error)
- func (dev *Device) DeviceNotifyReceived(ssdpReq *ssdp.Request)
- func (dev *Device) DeviceSearchReceived(ssdpReq *ssdp.Request)
- func (dev *Device) GetAbsoluteURL(path string) (*url.URL, error)
- func (dev *Device) GetEmbeddedDeviceByType(deviceType string) (*Device, error)
- func (dev *Device) GetEmbeddedDevices() []*Device
- func (dev *Device) GetRootDevice() *Device
- func (dev *Device) GetServiceByControlURL(ctrlURL string) (*Service, error)
- func (dev *Device) GetServiceByEventSubURL(eventURL string) (*Service, error)
- func (dev *Device) GetServiceByID(serviceID string) (*Service, error)
- func (dev *Device) GetServiceByType(serviceType string) (*Service, error)
- func (dev *Device) GetServices() []*Service
- func (dev *Device) HTTPRequestReceived(httpReq *http.Request, httpRes http.ResponseWriter)
- func (dev *Device) HasDeviceType(deviceType string) bool
- func (dev *Device) HasServiceType(serviceType string) bool
- func (dev *Device) LoadDescriptionBytes(descBytes []byte) error
- func (dev *Device) LoadServiceDescriptions() error
- func (dev *Device) SetLocationURL(url string) error
- func (dev *Device) SetUDN(uuid string) error
- func (dev *Device) Start() error
- func (dev *Device) StartWithPort(port int) error
- func (dev *Device) Stop() error
- type DeviceActionListener
- type DeviceDescription
- type DeviceDescriptionRoot
- type DeviceHTTPListener
- type DeviceList
- type DeviceListener
- type DeviceMap
- func (devMap *DeviceMap) AddDevice(dev *Device) bool
- func (devMap *DeviceMap) FindDeviceByTypeAndUDN(deviceType string, udn string) (*Device, bool)
- func (devMap *DeviceMap) GetAllDevices() []*Device
- func (devMap *DeviceMap) GetDevicesByType(deviceType string) []*Device
- func (devMap *DeviceMap) HasDevice(dev *Device) bool
- func (devMap *DeviceMap) HasDeviceByTypeAndUDN(deviceType string, udn string) bool
- func (devMap *DeviceMap) Size() int
- type DeviceSSDPListener
- type Error
- type Icon
- type IconList
- type Service
- func (service *Service) DescriptionString() (string, error)
- func (service *Service) GetAbsoluteControlURL() (*url.URL, error)
- func (service *Service) GetAbsoluteEventSubURL() (*url.URL, error)
- func (service *Service) GetAbsoluteSCPDURL() (*url.URL, error)
- func (service *Service) GetActionByName(name string) (*Action, error)
- func (service *Service) GetActions() []*Action
- func (service *Service) LoadDescriptionBytes(descBytes []byte) error
- func (service *Service) LoadDescriptionFromSCPDURL() error
- type ServiceDescription
- type ServiceList
- type ServiceStateTable
- type SpecVersion
- type StateVariable
Constants ¶
const ( ProductName = "go-net-upnp" SupportVersion = "1.1" SupportVersionMajor = 1 SupportVersionMinor = 1 ControlPointDefaultPortBase = 5004 ControlPointDefaultPortRange = 1024 ControlPointDefaultPortMax = ControlPointDefaultPortBase + ControlPointDefaultPortRange ControlPointDefaultSearchMX = ssdp.DefaultMSearchMX DeviceDefaultPortBase = 6004 DeviceDefaultPortRange = 1024 DeviceDefaultPortMax = DeviceDefaultPortBase + DeviceDefaultPortRange DeviceUUIDPrefix = "uuid:" DeviceProtocol = "http" DeviceDefaultDescriptionURL = "/description.xml" In = "in" Out = "out" UnknownDirection = 0 InDirection = 1 OutDirection = 2 )
const ( ErrorInvalidAction = control.ErrorInvalidAction ErrorInvalidArgs = control.ErrorInvalidArgs ErrorActionFailed = control.ErrorActionFailed ErrorArgumentValueInvalid = control.ErrorArgumentValueInvalid ErrorArgumentValueOutOfRange = control.ErrorArgumentValueOutOfRange ErrorOptionalActionNotImplemented = control.ErrorOptionalActionNotImplemented ErrorOutOfMemory = control.ErrorOutOfMemory ErrorHumanInterventionRequired = control.ErrorHumanInterventionRequired ErrorStringArgumentTooLong = control.ErrorStringArgumentTooLong )
const (
ProductVersion = "0.8.3"
)
Variables ¶
This section is empty.
Functions ¶
func NewActionRequestFromAction ¶
func NewActionRequestFromAction(action *Action) (*control.ActionRequest, error)
NewActionRequestFromAction returns a new Request.
func NewActionResponseFromAction ¶
func NewActionResponseFromAction(action *Action) (*control.ActionResponse, error)
NewActionResponseFromAction returns a new Response.
func NewArgumentFromArgument ¶
NewArgument returns a new argument.
func NewErrorResponseFromError ¶
func NewErrorResponseFromError(upnpError Error) *control.ErrorResponse
NewErrorResponseFromError returns a new error response.
Types ¶
type Action ¶
type Action struct { XMLName xml.Name `xml:"action"` Name string `xml:"name"` ArgumentList ArgumentList `xml:"argumentList"` ParentService *Service `xml:"-"` }
A Action represents a UPnP action.
func (*Action) GetArgumentBool ¶
GetArgumentBool return a boolean value into the specified argument.
func (*Action) GetArgumentByName ¶
GetArgumentByName returns an argument by the specified name.
func (*Action) GetArgumentFloat ¶
GetArgumentFloat return a integer value into the specified argument.
func (*Action) GetArgumentInt ¶
GetArgumentInt return a integer value into the specified argument.
func (*Action) GetArgumentString ¶
GetArgumentString return a string value into the specified argument.
func (*Action) GetArguments ¶
GetArguments returns all arguments.
func (*Action) GetInputArguments ¶
GetInputArguments returns all input arguments.
func (*Action) GetOutputArguments ¶
GetOutputArguments returns all output arguments.
func (*Action) SetArgumentBool ¶
SetArgumentBool sets a boolean value into the specified argument.
func (*Action) SetArgumentFloat ¶
SetArgumentFloat sets a integer value into the specified argument.
func (*Action) SetArgumentInt ¶
SetArgumentInt sets a integer value into the specified argument.
func (*Action) SetArgumentString ¶
SetArgumentString sets a string value into the specified argument.
func (*Action) SetArgumentsByActionRequest ¶
func (action *Action) SetArgumentsByActionRequest(actionReq *control.ActionRequest) error
SetArgumentsByActionRequest sets request arguments into the specified argument.
func (*Action) SetArgumentsByActionResponse ¶
func (action *Action) SetArgumentsByActionResponse(actionRes *control.ActionResponse) error
SetArgumentsByActionResponse sets response arguments into the specified argument.
type ActionList ¶
A ActionList represents a UPnP action list.
type AllowedValue ¶
A AllowedValue represents a UPnP allowed value.
func NewAllowedValue ¶
func NewAllowedValue() *AllowedValue
NewAllowedValue returns a new AllowedValue.
type AllowedValueList ¶
type AllowedValueList struct { XMLName xml.Name `xml:"allowedValueList"` AllowedValues []AllowedValue `xml:"allowedValue"` }
A AllowedValueList represents a UPnP allowed value list.
type AllowedValueRange ¶
type AllowedValueRange struct { XMLName xml.Name `xml:"allowedValueRange"` Minimum string `xml:"minimum"` Maximum string `xml:"maximum"` Step string `xml:"step"` }
A AllowedValueRange represents a icon. NOTE : Minimum, Maximum and Step uses string type instead float64
because some devices sets a blank into the fields such as BUFFALO WZR-900DHP
func NewAllowedValueRange ¶
func NewAllowedValueRange() *AllowedValueRange
NewAllowedValueRange returns a new AllowedValueRange.
type Argument ¶
type Argument struct { XMLName xml.Name `xml:"argument"` Name string `xml:"name"` Direction string `xml:"direction"` RelatedStateVariable string `xml:"relatedStateVariable"` Value string `xml:"-"` ParentAction *Action `xml:"-"` }
A Argument represents a UPnP argument.
func (*Argument) GetDirection ¶
GetDirection returns a directional integer of the specified argument.
func (*Argument) IsInDirection ¶
IsInDirection returns true when the argument direction is in, otherwise false.
func (*Argument) IsOutDirection ¶
IsOutDirection returns true when the argument direction is out, otherwise false.
func (*Argument) SetDirection ¶
SetDirection sets a directional string of the specified diractional integer.
type ArgumentList ¶
type ArgumentList struct { XMLName xml.Name `xml:"argumentList"` Arguments []Argument `xml:"argument"` }
A ArgumentList represents a UPnP argument list.
type ControlPoint ¶
type ControlPoint struct { *sync.Mutex Port int SearchMX int Listener ControlPointListener // contains filtered or unexported fields }
A ControlPoint represents a ControlPoint.
func NewControlPoint ¶
func NewControlPoint() *ControlPoint
NewControlPoint returns a new ControlPoint.
func (*ControlPoint) DeviceNotifyReceived ¶
func (ctrl *ControlPoint) DeviceNotifyReceived(ssdpReq *ssdp.Request)
func (*ControlPoint) DeviceResponseReceived ¶
func (ctrl *ControlPoint) DeviceResponseReceived(ssdpRes *ssdp.Response)
func (*ControlPoint) DeviceSearchReceived ¶
func (ctrl *ControlPoint) DeviceSearchReceived(ssdpReq *ssdp.Request)
func (*ControlPoint) FindDeviceByTypeAndUDN ¶
func (ctrl *ControlPoint) FindDeviceByTypeAndUDN(deviceType string, udn string) (*Device, bool)
FindDeviceByTypeAndUDN returns a devices of the specified deviceType and UDN.
func (*ControlPoint) GetRootDevices ¶
func (ctrl *ControlPoint) GetRootDevices() []*Device
GetRootDevices returns found root devices.
func (*ControlPoint) GetRootDevicesByType ¶
func (ctrl *ControlPoint) GetRootDevicesByType(deviceType string) []*Device
GetRootDevicesByType returns found root devices of the specified device type.
func (*ControlPoint) Search ¶
func (ctrl *ControlPoint) Search(st string) error
Search sends a M-SEARCH request of the specified ST.
func (*ControlPoint) SearchRootDevice ¶
func (ctrl *ControlPoint) SearchRootDevice() error
SearchRootDevice sends a M-SEARCH request for root devices.
func (*ControlPoint) Start ¶
func (ctrl *ControlPoint) Start() error
Start starts this control point.
func (*ControlPoint) StartWithPort ¶
func (ctrl *ControlPoint) StartWithPort(port int) error
Start starts this control point.
type ControlPointListener ¶
type ControlPointListener interface { ssdp.MulticastListener ssdp.UnicastListener }
A ControlPointListener represents a listener for ControlPoint.
type Device ¶
type Device struct { *DeviceDescription SpecVersion SpecVersion `xml:"-"` URLBase string `xml:"-"` ParentDevice *Device `xml:"-"` Port int `xml:"-"` HTTPListener DeviceHTTPListener `xml:"-"` SSDPListener DeviceSSDPListener `xml:"-"` ActionListener DeviceActionListener `xml:"-"` LocationURL string `xml:"-"` DescriptionURL string `xml:"-"` // contains filtered or unexported fields }
A Device represents a UPnP device.
func NewDeviceFromDescription ¶
NewDeviceFromDescription returns a device from the specified string.
func NewDeviceFromDescriptionURL ¶
NewDeviceFromDescriptionURL returns a device from the specified URL.
func NewDeviceFromSSDPRequest ¶
NewDeviceFromSSDPRequest returns a device from the specified SSDP packet.
func NewDeviceFromSSDPResponse ¶
NewDeviceFromSSDPRequest returns a device from the specified SSDP packet.
func (*Device) DescriptionString ¶
DescriptionString returns a descrition string.
func (*Device) DeviceNotifyReceived ¶
func (*Device) DeviceSearchReceived ¶
func (*Device) GetAbsoluteURL ¶
GetAbsoluteURL return a absolute URL of the specified path using URLBase or LocationURL.
func (*Device) GetEmbeddedDeviceByType ¶
GetEmbeddedDeviceByType returns a embedded device by the specified deviceType.
func (*Device) GetEmbeddedDevices ¶
GetEmbeddedDevices returns all embedded devices.
func (*Device) GetRootDevice ¶
GetRootDevice returns the root device.
func (*Device) GetServiceByControlURL ¶
GetServiceByControlURL returns a service by the specified control URL.
func (*Device) GetServiceByEventSubURL ¶
GetServiceByEventSubURL returns a service by the specified event subscription URL.
func (*Device) GetServiceByID ¶ added in v0.8.3
GetServiceByID returns a service by the specified serviceId.
func (*Device) GetServiceByType ¶
GetServiceByType returns a service by the specified serviceType.
func (*Device) GetServices ¶
GetServices returns all services.
func (*Device) HTTPRequestReceived ¶
func (dev *Device) HTTPRequestReceived(httpReq *http.Request, httpRes http.ResponseWriter)
func (*Device) HasDeviceType ¶ added in v0.8.1
HasDeviceType returns true if the device or the embedded device type is the specified type, otherwise false.
func (*Device) HasServiceType ¶ added in v0.8.1
HasServiceType returns true if the device or the embedded device has the specified service type, otherwise false.
func (*Device) LoadDescriptionBytes ¶
LoadDescriptionBytes loads a device description string.
func (*Device) LoadServiceDescriptions ¶
LoadServiceDescriptions loads service descriptions.
func (*Device) SetLocationURL ¶
SetLocationURL set a location URL of SSDP packet.
func (*Device) StartWithPort ¶
Start starts this control point.
type DeviceActionListener ¶
A DeviceActionListener represents a listener for action request.
type DeviceDescription ¶
type DeviceDescription struct { XMLName xml.Name `xml:"device"` DeviceType string `xml:"deviceType"` FriendlyName string `xml:"friendlyName"` Manufacturer string `xml:"manufacturer"` ManufacturerURL string `xml:"manufacturerURL"` ModelDescription string `xml:"modelDescription"` ModelName string `xml:"modelName"` ModelNumber string `xml:"modelNumber"` ModelURL string `xml:"modelURL"` SerialNumber string `xml:"serialNumber"` UDN string `xml:"UDN"` UPC string `xml:"UPC"` PresentationURL string `xml:"presentationURL"` IconList IconList `xml:"iconList"` ServiceList ServiceList `xml:"serviceList"` DeviceList DeviceList `xml:"deviceList"` }
A DeviceDescription represents a UPnP device description.
type DeviceDescriptionRoot ¶
type DeviceDescriptionRoot struct { XMLName xml.Name `xml:"root"` SpecVersion SpecVersion `xml:"specVersion"` URLBase string `xml:"URLBase"` Device Device `xml:"device"` }
A DeviceDescriptionRoot represents a root UPnP device description.
func NewDeviceDescriptionRoot ¶
func NewDeviceDescriptionRoot() *DeviceDescriptionRoot
func NewDeviceDescriptionRootFromDevice ¶
func NewDeviceDescriptionRootFromDevice(dev *Device) (*DeviceDescriptionRoot, error)
func NewDeviceDescriptionRootFromString ¶
func NewDeviceDescriptionRootFromString(descStr string) (*DeviceDescriptionRoot, error)
type DeviceHTTPListener ¶
type DeviceHTTPListener interface { http.RequestListener }
A DeviceHTTPListener represents a listener for HTTP requests.
type DeviceList ¶
A DeviceList represents a ServiceList.
type DeviceListener ¶
type DeviceListener interface { DeviceHTTPListener DeviceSSDPListener DeviceActionListener }
A DeviceListener represents a listener for all requests.
type DeviceMap ¶
DeviceMap manages devices by UDN.
func (*DeviceMap) FindDeviceByTypeAndUDN ¶
FindDeviceByTypeAndUDN find a device of the specified device type and udn.
func (*DeviceMap) GetAllDevices ¶
GetAllDevices returns all devices.
func (*DeviceMap) GetDevicesByType ¶
GetDevicesByType returns only devices of the specified device type.
func (*DeviceMap) HasDeviceByTypeAndUDN ¶
HasDeviceByTypeAndUDN check whether a device of the specified device type and udn exits.
type DeviceSSDPListener ¶
type DeviceSSDPListener interface { ssdp.MulticastListener }
A DeviceSSDPListener represents a listener for SSDP requests.
type Error ¶
A Error represents a interface for UPnP error.
func NewErrorFromCode ¶
NewErrorFromCode returns a new Error from the specified code.
type Icon ¶
type Icon struct { XMLName xml.Name `xml:"icon"` Mimetype string `xml:"mimetype"` Width string `xml:"width"` Height string `xml:"height"` Depth string `xml:"depth"` URL string `xml:"url"` }
A Icon represents a UPnP icon.
type Service ¶
type Service struct { XMLName xml.Name `xml:"service"` ServiceType string `xml:"serviceType"` ServiceID string `xml:"serviceId"` SCPDURL string `xml:"SCPDURL"` ControlURL string `xml:"controlURL"` EventSubURL string `xml:"eventSubURL"` ServiceStateTable *ServiceStateTable `xml:"-"` ActionList *ActionList `xml:"-"` ParentDevice *Device `xml:"-"` // contains filtered or unexported fields }
A Service represents a UPnP service.
func NewServiceFromDescriptionBytes ¶
NewServiceFromDescription returns a service from the specified descrition string.
func (*Service) DescriptionString ¶
DescriptionString returns a descrition string.
func (*Service) GetAbsoluteControlURL ¶
func (*Service) GetAbsoluteEventSubURL ¶ added in v0.8.2
func (*Service) GetActionByName ¶
GetActionByName returns an action by the specified name.
func (*Service) GetActions ¶
GetActions returns all actions.
func (*Service) LoadDescriptionBytes ¶
LoadDescriptionBytes loads a device description string.
func (*Service) LoadDescriptionFromSCPDURL ¶
LoadDescriptinString loads a device description string.
type ServiceDescription ¶
type ServiceDescription struct { XMLName xml.Name `xml:"scpd"` ServiceStateTable ServiceStateTable `xml:"serviceStateTable"` ActionList ActionList `xml:"actionList"` }
A ServiceDescription represents a UPnP service description.
type ServiceList ¶
A ServiceList represents a UPnP serviceList.
type ServiceStateTable ¶
type ServiceStateTable struct { XMLName xml.Name `xml:"serviceStateTable"` StateVariables []StateVariable `xml:"stateVariable"` }
A StateVariable represents a UPnP state variable.
type SpecVersion ¶
type SpecVersion struct { XMLName xml.Name `xml:"specVersion"` Major int `xml:"major"` Minor int `xml:"minor"` }
A SpecVersion represents a UPnP spec version.
type StateVariable ¶
type StateVariable struct { XMLName xml.Name `xml:"stateVariable"` Name string `xml:"name"` DataType string `xml:"dataType"` DefaultValue string `xml:"defaultValue"` AllowedValueList AllowedValueList `xml:"allowedValueList"` AllowedValueRange AllowedValueRange `xml:"allowedValueRange"` SendEvents string `xml:"sendEvents,attr"` Multicast string `xml:"multicast,attr"` ParentService *Service `xml:"-"` }
A StateVariable represents a UPnP state variable.
func NewStateVariable ¶
func NewStateVariable() *StateVariable
NewStateVariable returns a new StateVariable.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package control implements control functions of UPnP for net-upnp-go.
|
Package control implements control functions of UPnP for net-upnp-go. |
Package http is a wrapper packages of net/http for net-upnp-go.
|
Package http is a wrapper packages of net/http for net-upnp-go. |
Package ssdp implements multicast and unicast functions of SSDP for net-upnp-go.
|
Package ssdp implements multicast and unicast functions of SSDP for net-upnp-go. |
Package util implements some misc functoins for net-upnp-go.
|
Package util implements some misc functoins for net-upnp-go. |