mirror of
https://github.com/kerberos-io/onvif.git
synced 2026-08-23 15:08:33 +00:00
exports device params, fixes error in comments, adds gitignore file
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.idea
|
||||
*.iml
|
||||
35
Device.go
35
Device.go
@@ -17,7 +17,7 @@ import (
|
||||
wsdiscovery "github.com/use-go/onvif/ws-discovery"
|
||||
)
|
||||
|
||||
//Xlmns XML Scheam
|
||||
// Xlmns XML Scheam
|
||||
var Xlmns = map[string]string{
|
||||
"onvif": "http://www.onvif.org/ver10/schema",
|
||||
"tds": "http://www.onvif.org/ver10/device/wsdl",
|
||||
@@ -36,7 +36,7 @@ var Xlmns = map[string]string{
|
||||
"wsaw": "http://www.w3.org/2006/05/addressing/wsdl",
|
||||
}
|
||||
|
||||
//DeviceType alias for int
|
||||
// DeviceType alias for int
|
||||
type DeviceType int
|
||||
|
||||
// Onvif Device Tyoe
|
||||
@@ -63,7 +63,7 @@ func (devType DeviceType) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
//DeviceInfo struct contains general information about ONVIF device
|
||||
// DeviceInfo struct contains general information about ONVIF device
|
||||
type DeviceInfo struct {
|
||||
Manufacturer string
|
||||
Model string
|
||||
@@ -72,9 +72,9 @@ type DeviceInfo struct {
|
||||
HardwareId string
|
||||
}
|
||||
|
||||
//Device for a new device of onvif and DeviceInfo
|
||||
//struct represents an abstract ONVIF device.
|
||||
//It contains methods, which helps to communicate with ONVIF device
|
||||
// Device for a new device of onvif and DeviceInfo
|
||||
// struct represents an abstract ONVIF device.
|
||||
// It contains methods, which helps to communicate with ONVIF device
|
||||
type Device struct {
|
||||
params DeviceParams
|
||||
endpoints map[string]string
|
||||
@@ -88,16 +88,21 @@ type DeviceParams struct {
|
||||
HttpClient *http.Client
|
||||
}
|
||||
|
||||
//GetServices return available endpoints
|
||||
// GetServices return available endpoints
|
||||
func (dev *Device) GetServices() map[string]string {
|
||||
return dev.endpoints
|
||||
}
|
||||
|
||||
//GetServices return available endpoints
|
||||
// GetDeviceInfo return available endpoints
|
||||
func (dev *Device) GetDeviceInfo() DeviceInfo {
|
||||
return dev.info
|
||||
}
|
||||
|
||||
// GetDeviceParams return available endpoints
|
||||
func (dev *Device) GetDeviceParams() DeviceParams {
|
||||
return dev.params
|
||||
}
|
||||
|
||||
func readResponse(resp *http.Response) string {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
@@ -106,7 +111,7 @@ func readResponse(resp *http.Response) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
//GetAvailableDevicesAtSpecificEthernetInterface ...
|
||||
// GetAvailableDevicesAtSpecificEthernetInterface ...
|
||||
func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) ([]Device, error) {
|
||||
// Call a ws-discovery Probe Message to Discover NVT type Devices
|
||||
devices, err := wsdiscovery.SendProbe(interfaceName, nil, []string{"dn:" + NVT.String()}, map[string]string{"dn": "http://www.onvif.org/ver10/network/wsdl"})
|
||||
@@ -168,7 +173,7 @@ func (dev *Device) getSupportedServices(resp *http.Response) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//NewDevice function construct a ONVIF Device entity
|
||||
// NewDevice function construct a ONVIF Device entity
|
||||
func NewDevice(params DeviceParams) (*Device, error) {
|
||||
dev := new(Device)
|
||||
dev.params = params
|
||||
@@ -209,7 +214,7 @@ func (dev *Device) addEndpoint(Key, Value string) {
|
||||
dev.endpoints[lowCaseKey] = Value
|
||||
}
|
||||
|
||||
//GetEndpoint returns specific ONVIF service endpoint address
|
||||
// GetEndpoint returns specific ONVIF service endpoint address
|
||||
func (dev *Device) GetEndpoint(name string) string {
|
||||
return dev.endpoints[name]
|
||||
}
|
||||
@@ -229,7 +234,7 @@ func (dev Device) buildMethodSOAP(msg string) (gosoap.SoapMessage, error) {
|
||||
return soap, nil
|
||||
}
|
||||
|
||||
//getEndpoint functions get the target service endpoint in a better way
|
||||
// getEndpoint functions get the target service endpoint in a better way
|
||||
func (dev Device) getEndpoint(endpoint string) (string, error) {
|
||||
|
||||
// common condition, endpointMark in map we use this.
|
||||
@@ -250,8 +255,8 @@ func (dev Device) getEndpoint(endpoint string) (string, error) {
|
||||
return endpointURL, errors.New("target endpoint service not found")
|
||||
}
|
||||
|
||||
//CallMethod functions call an method, defined <method> struct.
|
||||
//You should use Authenticate method to call authorized requests.
|
||||
// CallMethod functions call an method, defined <method> struct.
|
||||
// You should use Authenticate method to call authorized requests.
|
||||
func (dev Device) CallMethod(method interface{}) (*http.Response, error) {
|
||||
pkgPath := strings.Split(reflect.TypeOf(method).PkgPath(), "/")
|
||||
pkg := strings.ToLower(pkgPath[len(pkgPath)-1])
|
||||
@@ -263,7 +268,7 @@ func (dev Device) CallMethod(method interface{}) (*http.Response, error) {
|
||||
return dev.callMethodDo(endpoint, method)
|
||||
}
|
||||
|
||||
//CallMethod functions call an method, defined <method> struct with authentication data
|
||||
// CallMethod functions call an method, defined <method> struct with authentication data
|
||||
func (dev Device) callMethodDo(endpoint string, method interface{}) (*http.Response, error) {
|
||||
output, err := xml.MarshalIndent(method, " ", " ")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user