/*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 DeviceGre struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

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

	Parent           *dbusPropertyDeviceGreParent
	InputFlags       *dbusPropertyDeviceGreInputFlags
	OutputFlags      *dbusPropertyDeviceGreOutputFlags
	InputKey         *dbusPropertyDeviceGreInputKey
	OutputKey        *dbusPropertyDeviceGreOutputKey
	Local            *dbusPropertyDeviceGreLocal
	Remote           *dbusPropertyDeviceGreRemote
	Ttl              *dbusPropertyDeviceGreTtl
	Tos              *dbusPropertyDeviceGreTos
	PathMtuDiscovery *dbusPropertyDeviceGrePathMtuDiscovery
}

func (obj *DeviceGre) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *DeviceGre) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyDeviceGre(obj *DeviceGre) {
	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.Gre',sender='" + obj.DestName + "',member='PropertiesChanged'")

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

	obj.Parent.Reset()
	obj.InputFlags.Reset()
	obj.OutputFlags.Reset()
	obj.InputKey.Reset()
	obj.OutputKey.Reset()
	obj.Local.Reset()
	obj.Remote.Reset()
	obj.Ttl.Reset()
	obj.Tos.Reset()
	obj.PathMtuDiscovery.Reset()
}

func (obj *DeviceGre) 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.Gre.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 dbusPropertyDeviceGreParent struct {
	*property.BaseObserver
	core *dbus.Object
}

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

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

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

func (this *dbusPropertyDeviceGreInputFlags) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.Gre.InputFlags is not writable")
}

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

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

func (this *dbusPropertyDeviceGreOutputFlags) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.Gre.OutputFlags is not writable")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	obj.Parent = &dbusPropertyDeviceGreParent{&property.BaseObserver{}, core}
	obj.InputFlags = &dbusPropertyDeviceGreInputFlags{&property.BaseObserver{}, core}
	obj.OutputFlags = &dbusPropertyDeviceGreOutputFlags{&property.BaseObserver{}, core}
	obj.InputKey = &dbusPropertyDeviceGreInputKey{&property.BaseObserver{}, core}
	obj.OutputKey = &dbusPropertyDeviceGreOutputKey{&property.BaseObserver{}, core}
	obj.Local = &dbusPropertyDeviceGreLocal{&property.BaseObserver{}, core}
	obj.Remote = &dbusPropertyDeviceGreRemote{&property.BaseObserver{}, core}
	obj.Ttl = &dbusPropertyDeviceGreTtl{&property.BaseObserver{}, core}
	obj.Tos = &dbusPropertyDeviceGreTos{&property.BaseObserver{}, core}
	obj.PathMtuDiscovery = &dbusPropertyDeviceGrePathMtuDiscovery{&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.Gre',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.Gre" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Parent" {
						obj.Parent.Notify()

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

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

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

					} else if key == "OutputKey" {
						obj.OutputKey.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 v.Name == "org.freedesktop.NetworkManager.Device.Gre.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 == "Parent" {
						obj.Parent.Notify()

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

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

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

					} else if key == "OutputKey" {
						obj.OutputKey.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()
					}
				}
			}
		}
	}()

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

	runtime.SetFinalizer(obj, func(_obj *DeviceGre) { DestroyDeviceGre(_obj) })
	return obj, nil
}
