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

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

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

	InterfaceIndex *dbusPropertyLinkInterfaceIndex
	MACAddress     *dbusPropertyLinkMACAddress
	InterfaceName  *dbusPropertyLinkInterfaceName
	FriendlyName   *dbusPropertyLinkFriendlyName
	Managed        *dbusPropertyLinkManaged
	P2PState       *dbusPropertyLinkP2PState
	P2PScanning    *dbusPropertyLinkP2PScanning
	WfdSubelements *dbusPropertyLinkWfdSubelements
}

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

	obj.InterfaceIndex.Reset()
	obj.MACAddress.Reset()
	obj.InterfaceName.Reset()
	obj.FriendlyName.Reset()
	obj.Managed.Reset()
	obj.P2PState.Reset()
	obj.P2PScanning.Reset()
	obj.WfdSubelements.Reset()
}

func (obj *Link) Manage() (_err error) {
	_err = obj.core.Call("org.freedesktop.miracle.wifi.Link.Manage", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Link) Unmanage() (_err error) {
	_err = obj.core.Call("org.freedesktop.miracle.wifi.Link.Unmanage", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyLinkInterfaceIndex) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Link.InterfaceIndex is not writable")
}

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

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

func (this *dbusPropertyLinkMACAddress) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Link.MACAddress is not writable")
}

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

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

func (this *dbusPropertyLinkInterfaceName) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Link.InterfaceName is not writable")
}

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

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

func (this *dbusPropertyLinkFriendlyName) SetValue(v interface{} /*string*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*string)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "org.freedesktop.miracle.wifi.Link", "FriendlyName", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property FriendlyName of org.freedesktop.miracle.wifi.Link is an string but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyLinkFriendlyName) Set(v string) {
	this.SetValue(v)
}

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

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

func (this *dbusPropertyLinkManaged) SetValue(v interface{} /*bool*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*bool)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "org.freedesktop.miracle.wifi.Link", "Managed", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property Managed of org.freedesktop.miracle.wifi.Link is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyLinkManaged) Set(v bool) {
	this.SetValue(v)
}

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

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

func (this *dbusPropertyLinkP2PState) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Link.P2PState is not writable")
}

func (this *dbusPropertyLinkP2PState) Get() int32 {
	v, _ := this.GetValue()
	return v.(int32)
}
func (this *dbusPropertyLinkP2PState) GetValue() (interface{} /*int32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.miracle.wifi.Link", "P2PState").Store(&r)
	if err == nil && r.Signature().String() == "i" {
		return r.Value().(int32), nil
	}
	return *new(int32), err
}
func (this *dbusPropertyLinkP2PState) GetType() reflect.Type {
	return reflect.TypeOf((*int32)(nil)).Elem()
}

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

func (this *dbusPropertyLinkP2PScanning) SetValue(v interface{} /*bool*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*bool)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "org.freedesktop.miracle.wifi.Link", "P2PScanning", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property P2PScanning of org.freedesktop.miracle.wifi.Link is an bool but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyLinkP2PScanning) Set(v bool) {
	this.SetValue(v)
}

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

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

func (this *dbusPropertyLinkWfdSubelements) SetValue(v interface{} /*string*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*string)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "org.freedesktop.miracle.wifi.Link", "WfdSubelements", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property WfdSubelements of org.freedesktop.miracle.wifi.Link is an string but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyLinkWfdSubelements) Set(v string) {
	this.SetValue(v)
}

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

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

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

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

	obj.InterfaceIndex = &dbusPropertyLinkInterfaceIndex{&property.BaseObserver{}, core}
	obj.MACAddress = &dbusPropertyLinkMACAddress{&property.BaseObserver{}, core}
	obj.InterfaceName = &dbusPropertyLinkInterfaceName{&property.BaseObserver{}, core}
	obj.FriendlyName = &dbusPropertyLinkFriendlyName{&property.BaseObserver{}, core}
	obj.Managed = &dbusPropertyLinkManaged{&property.BaseObserver{}, core}
	obj.P2PState = &dbusPropertyLinkP2PState{&property.BaseObserver{}, core}
	obj.P2PScanning = &dbusPropertyLinkP2PScanning{&property.BaseObserver{}, core}
	obj.WfdSubelements = &dbusPropertyLinkWfdSubelements{&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.miracle.wifi.Link',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.miracle.wifi.Link" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "InterfaceIndex" {
						obj.InterfaceIndex.Notify()

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

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

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

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

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

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

					} else if key == "WfdSubelements" {
						obj.WfdSubelements.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.miracle.wifi.Link.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 == "InterfaceIndex" {
						obj.InterfaceIndex.Notify()

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Link) { DestroyLink(_obj) })
	return obj, nil
}
