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

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

	Link           *dbusPropertyPeerLink
	P2PMac         *dbusPropertyPeerP2PMac
	FriendlyName   *dbusPropertyPeerFriendlyName
	Connected      *dbusPropertyPeerConnected
	Interface      *dbusPropertyPeerInterface
	LocalAddress   *dbusPropertyPeerLocalAddress
	RemoteAddress  *dbusPropertyPeerRemoteAddress
	WfdSubelements *dbusPropertyPeerWfdSubelements
}

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.miracle.wifi.Peer',sender='" + obj.DestName + "',member='ProvisionDiscovery'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.miracle.wifi.Peer',sender='" + obj.DestName + "',member='GoNegRequest'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.miracle.wifi.Peer',sender='" + obj.DestName + "',member='FormationFailure'")

	obj.Link.Reset()
	obj.P2PMac.Reset()
	obj.FriendlyName.Reset()
	obj.Connected.Reset()
	obj.Interface.Reset()
	obj.LocalAddress.Reset()
	obj.RemoteAddress.Reset()
	obj.WfdSubelements.Reset()
}

func (obj *Peer) Connect(arg0 string, arg1 string) (_err error) {
	_err = obj.core.Call("org.freedesktop.miracle.wifi.Peer.Connect", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (obj *Peer) ConnectProvisionDiscovery(callback func(arg0 string, arg1 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.miracle.wifi.Peer.ProvisionDiscovery" || 2 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string), v.Body[1].(string))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Peer) ConnectGoNegRequest(callback func(arg0 string, arg1 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.miracle.wifi.Peer.GoNegRequest" || 2 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string), v.Body[1].(string))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Peer) ConnectFormationFailure(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.miracle.wifi.Peer.FormationFailure" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

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

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

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

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

func (this *dbusPropertyPeerP2PMac) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.P2PMac is not writable")
}

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

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

func (this *dbusPropertyPeerFriendlyName) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.FriendlyName is not writable")
}

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

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

func (this *dbusPropertyPeerConnected) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.Connected is not writable")
}

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

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

func (this *dbusPropertyPeerInterface) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.Interface is not writable")
}

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

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

func (this *dbusPropertyPeerLocalAddress) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.LocalAddress is not writable")
}

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

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

func (this *dbusPropertyPeerRemoteAddress) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.RemoteAddress is not writable")
}

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

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

func (this *dbusPropertyPeerWfdSubelements) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.miracle.wifi.Peer.WfdSubelements is not writable")
}

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

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

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

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

	obj.Link = &dbusPropertyPeerLink{&property.BaseObserver{}, core}
	obj.P2PMac = &dbusPropertyPeerP2PMac{&property.BaseObserver{}, core}
	obj.FriendlyName = &dbusPropertyPeerFriendlyName{&property.BaseObserver{}, core}
	obj.Connected = &dbusPropertyPeerConnected{&property.BaseObserver{}, core}
	obj.Interface = &dbusPropertyPeerInterface{&property.BaseObserver{}, core}
	obj.LocalAddress = &dbusPropertyPeerLocalAddress{&property.BaseObserver{}, core}
	obj.RemoteAddress = &dbusPropertyPeerRemoteAddress{&property.BaseObserver{}, core}
	obj.WfdSubelements = &dbusPropertyPeerWfdSubelements{&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.Peer',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.Peer" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Link" {
						obj.Link.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.miracle.wifi.Peer',sender='" + obj.DestName + "',member='ProvisionDiscovery'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.miracle.wifi.Peer',sender='" + obj.DestName + "',member='GoNegRequest'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.miracle.wifi.Peer',sender='" + obj.DestName + "',member='FormationFailure'")

	runtime.SetFinalizer(obj, func(_obj *Peer) { DestroyPeer(_obj) })
	return obj, nil
}
