/*This file is automatically generated by pkg.deepin.io/dbus-generator. Don't edit it*/
package networkmanager

import "pkg.deepin.io/lib/dbus"
import "pkg.deepin.io/lib/dbus/property"
import "reflect"
import "sync"
import "runtime"
import "fmt"
import "errors"

/*prevent compile error*/
var _ = fmt.Println
var _ = runtime.SetFinalizer
var _ = sync.NewCond
var _ = reflect.TypeOf
var _ = property.BaseObserver{}

type DeviceIPTunnel struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

	signals       map[<-chan *dbus.Signal]struct{}
	signalsLocker sync.Mutex

	Mode               *dbusPropertyDeviceIPTunnelMode
	Parent             *dbusPropertyDeviceIPTunnelParent
	Local              *dbusPropertyDeviceIPTunnelLocal
	Remote             *dbusPropertyDeviceIPTunnelRemote
	Ttl                *dbusPropertyDeviceIPTunnelTtl
	Tos                *dbusPropertyDeviceIPTunnelTos
	PathMtuDiscovery   *dbusPropertyDeviceIPTunnelPathMtuDiscovery
	InputKey           *dbusPropertyDeviceIPTunnelInputKey
	OutputKey          *dbusPropertyDeviceIPTunnelOutputKey
	EncapsulationLimit *dbusPropertyDeviceIPTunnelEncapsulationLimit
	FlowLabel          *dbusPropertyDeviceIPTunnelFlowLabel
}

func (obj *DeviceIPTunnel) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *DeviceIPTunnel) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyDeviceIPTunnel(obj *DeviceIPTunnel) {
	obj.signalsLocker.Lock()
	defer obj.signalsLocker.Unlock()
	if obj.signals == nil {
		return
	}
	for ch, _ := range obj.signals {
		getBus().DetachSignal(ch)
	}
	obj.signals = nil

	runtime.SetFinalizer(obj, nil)

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.DBus.Properties',sender='" + obj.DestName + "',member='PropertiesChanged'")
	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.NetworkManager.Device.IPTunnel',sender='" + obj.DestName + "',member='PropertiesChanged'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.NetworkManager.Device.IPTunnel',sender='" + obj.DestName + "',member='PropertiesChanged'")

	obj.Mode.Reset()
	obj.Parent.Reset()
	obj.Local.Reset()
	obj.Remote.Reset()
	obj.Ttl.Reset()
	obj.Tos.Reset()
	obj.PathMtuDiscovery.Reset()
	obj.InputKey.Reset()
	obj.OutputKey.Reset()
	obj.EncapsulationLimit.Reset()
	obj.FlowLabel.Reset()
}

func (obj *DeviceIPTunnel) ConnectPropertiesChanged(callback func(properties map[string]dbus.Variant)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.NetworkManager.Device.IPTunnel.PropertiesChanged" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*map[string]dbus.Variant)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(map[string]dbus.Variant))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

type dbusPropertyDeviceIPTunnelMode struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelMode) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.Mode is not writable")
}

func (this *dbusPropertyDeviceIPTunnelMode) Get() uint32 {
	v, _ := this.GetValue()
	return v.(uint32)
}
func (this *dbusPropertyDeviceIPTunnelMode) GetValue() (interface{} /*uint32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "Mode").Store(&r)
	if err == nil && r.Signature().String() == "u" {
		return r.Value().(uint32), nil
	}
	return *new(uint32), err
}
func (this *dbusPropertyDeviceIPTunnelMode) GetType() reflect.Type {
	return reflect.TypeOf((*uint32)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelParent struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelParent) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.Parent is not writable")
}

func (this *dbusPropertyDeviceIPTunnelParent) Get() dbus.ObjectPath {
	v, _ := this.GetValue()
	return v.(dbus.ObjectPath)
}
func (this *dbusPropertyDeviceIPTunnelParent) GetValue() (interface{} /*dbus.ObjectPath*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "Parent").Store(&r)
	if err == nil && r.Signature().String() == "o" {
		return r.Value().(dbus.ObjectPath), nil
	}
	return *new(dbus.ObjectPath), err
}
func (this *dbusPropertyDeviceIPTunnelParent) GetType() reflect.Type {
	return reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelLocal struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelLocal) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.Local is not writable")
}

func (this *dbusPropertyDeviceIPTunnelLocal) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyDeviceIPTunnelLocal) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "Local").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyDeviceIPTunnelLocal) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelRemote struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelRemote) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.Remote is not writable")
}

func (this *dbusPropertyDeviceIPTunnelRemote) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyDeviceIPTunnelRemote) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "Remote").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyDeviceIPTunnelRemote) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelTtl struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelTtl) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.Ttl is not writable")
}

func (this *dbusPropertyDeviceIPTunnelTtl) Get() uint8 {
	v, _ := this.GetValue()
	return v.(uint8)
}
func (this *dbusPropertyDeviceIPTunnelTtl) GetValue() (interface{} /*uint8*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "Ttl").Store(&r)
	if err == nil && r.Signature().String() == "y" {
		return r.Value().(uint8), nil
	}
	return *new(uint8), err
}
func (this *dbusPropertyDeviceIPTunnelTtl) GetType() reflect.Type {
	return reflect.TypeOf((*uint8)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelTos struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelTos) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.Tos is not writable")
}

func (this *dbusPropertyDeviceIPTunnelTos) Get() uint8 {
	v, _ := this.GetValue()
	return v.(uint8)
}
func (this *dbusPropertyDeviceIPTunnelTos) GetValue() (interface{} /*uint8*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "Tos").Store(&r)
	if err == nil && r.Signature().String() == "y" {
		return r.Value().(uint8), nil
	}
	return *new(uint8), err
}
func (this *dbusPropertyDeviceIPTunnelTos) GetType() reflect.Type {
	return reflect.TypeOf((*uint8)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelPathMtuDiscovery struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelPathMtuDiscovery) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.PathMtuDiscovery is not writable")
}

func (this *dbusPropertyDeviceIPTunnelPathMtuDiscovery) Get() bool {
	v, _ := this.GetValue()
	return v.(bool)
}
func (this *dbusPropertyDeviceIPTunnelPathMtuDiscovery) GetValue() (interface{} /*bool*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "PathMtuDiscovery").Store(&r)
	if err == nil && r.Signature().String() == "b" {
		return r.Value().(bool), nil
	}
	return *new(bool), err
}
func (this *dbusPropertyDeviceIPTunnelPathMtuDiscovery) GetType() reflect.Type {
	return reflect.TypeOf((*bool)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelInputKey struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelInputKey) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.InputKey is not writable")
}

func (this *dbusPropertyDeviceIPTunnelInputKey) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyDeviceIPTunnelInputKey) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "InputKey").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyDeviceIPTunnelInputKey) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelOutputKey struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelOutputKey) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.OutputKey is not writable")
}

func (this *dbusPropertyDeviceIPTunnelOutputKey) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyDeviceIPTunnelOutputKey) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "OutputKey").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyDeviceIPTunnelOutputKey) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelEncapsulationLimit struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelEncapsulationLimit) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.EncapsulationLimit is not writable")
}

func (this *dbusPropertyDeviceIPTunnelEncapsulationLimit) Get() uint8 {
	v, _ := this.GetValue()
	return v.(uint8)
}
func (this *dbusPropertyDeviceIPTunnelEncapsulationLimit) GetValue() (interface{} /*uint8*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "EncapsulationLimit").Store(&r)
	if err == nil && r.Signature().String() == "y" {
		return r.Value().(uint8), nil
	}
	return *new(uint8), err
}
func (this *dbusPropertyDeviceIPTunnelEncapsulationLimit) GetType() reflect.Type {
	return reflect.TypeOf((*uint8)(nil)).Elem()
}

type dbusPropertyDeviceIPTunnelFlowLabel struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyDeviceIPTunnelFlowLabel) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.IPTunnel.FlowLabel is not writable")
}

func (this *dbusPropertyDeviceIPTunnelFlowLabel) Get() uint32 {
	v, _ := this.GetValue()
	return v.(uint32)
}
func (this *dbusPropertyDeviceIPTunnelFlowLabel) GetValue() (interface{} /*uint32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager.Device.IPTunnel", "FlowLabel").Store(&r)
	if err == nil && r.Signature().String() == "u" {
		return r.Value().(uint32), nil
	}
	return *new(uint32), err
}
func (this *dbusPropertyDeviceIPTunnelFlowLabel) GetType() reflect.Type {
	return reflect.TypeOf((*uint32)(nil)).Elem()
}

func NewDeviceIPTunnel(destName string, path dbus.ObjectPath) (*DeviceIPTunnel, error) {
	if !path.IsValid() {
		return nil, errors.New("The path of '" + string(path) + "' is invalid.")
	}

	core := getBus().Object(destName, path)

	obj := &DeviceIPTunnel{Path: path, DestName: destName, core: core, signals: make(map[<-chan *dbus.Signal]struct{})}

	obj.Mode = &dbusPropertyDeviceIPTunnelMode{&property.BaseObserver{}, core}
	obj.Parent = &dbusPropertyDeviceIPTunnelParent{&property.BaseObserver{}, core}
	obj.Local = &dbusPropertyDeviceIPTunnelLocal{&property.BaseObserver{}, core}
	obj.Remote = &dbusPropertyDeviceIPTunnelRemote{&property.BaseObserver{}, core}
	obj.Ttl = &dbusPropertyDeviceIPTunnelTtl{&property.BaseObserver{}, core}
	obj.Tos = &dbusPropertyDeviceIPTunnelTos{&property.BaseObserver{}, core}
	obj.PathMtuDiscovery = &dbusPropertyDeviceIPTunnelPathMtuDiscovery{&property.BaseObserver{}, core}
	obj.InputKey = &dbusPropertyDeviceIPTunnelInputKey{&property.BaseObserver{}, core}
	obj.OutputKey = &dbusPropertyDeviceIPTunnelOutputKey{&property.BaseObserver{}, core}
	obj.EncapsulationLimit = &dbusPropertyDeviceIPTunnelEncapsulationLimit{&property.BaseObserver{}, core}
	obj.FlowLabel = &dbusPropertyDeviceIPTunnelFlowLabel{&property.BaseObserver{}, core}

	dbusAddMatch("type='signal',path='" + string(path) + "',interface='org.freedesktop.DBus.Properties',sender='" + destName + "',member='PropertiesChanged'")
	dbusAddMatch("type='signal',path='" + string(path) + "',interface='org.freedesktop.NetworkManager.Device.IPTunnel',sender='" + destName + "',member='PropertiesChanged'")
	sigChan := obj._createSignalChan()
	go func() {
		typeString := reflect.TypeOf("")
		typeKeyValues := reflect.TypeOf(map[string]dbus.Variant{})
		typeArrayValues := reflect.TypeOf([]string{})
		for v := range sigChan {
			if v.Name == "org.freedesktop.DBus.Properties.PropertiesChanged" &&
				len(v.Body) == 3 &&
				reflect.TypeOf(v.Body[0]) == typeString &&
				reflect.TypeOf(v.Body[1]) == typeKeyValues &&
				reflect.TypeOf(v.Body[2]) == typeArrayValues &&
				v.Body[0].(string) == "org.freedesktop.NetworkManager.Device.IPTunnel" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Mode" {
						obj.Mode.Notify()

					} else if key == "Parent" {
						obj.Parent.Notify()

					} else if key == "Local" {
						obj.Local.Notify()

					} else if key == "Remote" {
						obj.Remote.Notify()

					} else if key == "Ttl" {
						obj.Ttl.Notify()

					} else if key == "Tos" {
						obj.Tos.Notify()

					} else if key == "PathMtuDiscovery" {
						obj.PathMtuDiscovery.Notify()

					} else if key == "InputKey" {
						obj.InputKey.Notify()

					} else if key == "OutputKey" {
						obj.OutputKey.Notify()

					} else if key == "EncapsulationLimit" {
						obj.EncapsulationLimit.Notify()

					} else if key == "FlowLabel" {
						obj.FlowLabel.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.NetworkManager.Device.IPTunnel.PropertiesChanged" && len(v.Body) == 1 && reflect.TypeOf(v.Body[0]) == typeKeyValues {
				for key, _ := range v.Body[0].(map[string]dbus.Variant) {
					if false {
					} else if key == "Mode" {
						obj.Mode.Notify()

					} else if key == "Parent" {
						obj.Parent.Notify()

					} else if key == "Local" {
						obj.Local.Notify()

					} else if key == "Remote" {
						obj.Remote.Notify()

					} else if key == "Ttl" {
						obj.Ttl.Notify()

					} else if key == "Tos" {
						obj.Tos.Notify()

					} else if key == "PathMtuDiscovery" {
						obj.PathMtuDiscovery.Notify()

					} else if key == "InputKey" {
						obj.InputKey.Notify()

					} else if key == "OutputKey" {
						obj.OutputKey.Notify()

					} else if key == "EncapsulationLimit" {
						obj.EncapsulationLimit.Notify()

					} else if key == "FlowLabel" {
						obj.FlowLabel.Notify()
					}
				}
			}
		}
	}()

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.NetworkManager.Device.IPTunnel',sender='" + obj.DestName + "',member='PropertiesChanged'")

	runtime.SetFinalizer(obj, func(_obj *DeviceIPTunnel) { DestroyDeviceIPTunnel(_obj) })
	return obj, nil
}
