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

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

	Flags      *dbusPropertyAccessPointFlags
	WpaFlags   *dbusPropertyAccessPointWpaFlags
	RsnFlags   *dbusPropertyAccessPointRsnFlags
	Ssid       *dbusPropertyAccessPointSsid
	Frequency  *dbusPropertyAccessPointFrequency
	HwAddress  *dbusPropertyAccessPointHwAddress
	Mode       *dbusPropertyAccessPointMode
	MaxBitrate *dbusPropertyAccessPointMaxBitrate
	Strength   *dbusPropertyAccessPointStrength
	LastSeen   *dbusPropertyAccessPointLastSeen
}

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

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

	obj.Flags.Reset()
	obj.WpaFlags.Reset()
	obj.RsnFlags.Reset()
	obj.Ssid.Reset()
	obj.Frequency.Reset()
	obj.HwAddress.Reset()
	obj.Mode.Reset()
	obj.MaxBitrate.Reset()
	obj.Strength.Reset()
	obj.LastSeen.Reset()
}

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

func (this *dbusPropertyAccessPointFlags) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.Flags is not writable")
}

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

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

func (this *dbusPropertyAccessPointWpaFlags) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.WpaFlags is not writable")
}

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

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

func (this *dbusPropertyAccessPointRsnFlags) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.RsnFlags is not writable")
}

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

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

func (this *dbusPropertyAccessPointSsid) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.Ssid is not writable")
}

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

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

func (this *dbusPropertyAccessPointFrequency) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.Frequency is not writable")
}

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

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

func (this *dbusPropertyAccessPointHwAddress) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.HwAddress is not writable")
}

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

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

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

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

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

func (this *dbusPropertyAccessPointMaxBitrate) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.MaxBitrate is not writable")
}

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

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

func (this *dbusPropertyAccessPointStrength) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.Strength is not writable")
}

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

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

func (this *dbusPropertyAccessPointLastSeen) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.AccessPoint.LastSeen is not writable")
}

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

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

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

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

	obj.Flags = &dbusPropertyAccessPointFlags{&property.BaseObserver{}, core}
	obj.WpaFlags = &dbusPropertyAccessPointWpaFlags{&property.BaseObserver{}, core}
	obj.RsnFlags = &dbusPropertyAccessPointRsnFlags{&property.BaseObserver{}, core}
	obj.Ssid = &dbusPropertyAccessPointSsid{&property.BaseObserver{}, core}
	obj.Frequency = &dbusPropertyAccessPointFrequency{&property.BaseObserver{}, core}
	obj.HwAddress = &dbusPropertyAccessPointHwAddress{&property.BaseObserver{}, core}
	obj.Mode = &dbusPropertyAccessPointMode{&property.BaseObserver{}, core}
	obj.MaxBitrate = &dbusPropertyAccessPointMaxBitrate{&property.BaseObserver{}, core}
	obj.Strength = &dbusPropertyAccessPointStrength{&property.BaseObserver{}, core}
	obj.LastSeen = &dbusPropertyAccessPointLastSeen{&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.AccessPoint',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.AccessPoint" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Flags" {
						obj.Flags.Notify()

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

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

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

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

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

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

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

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

					} else if key == "LastSeen" {
						obj.LastSeen.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.NetworkManager.AccessPoint.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 == "Flags" {
						obj.Flags.Notify()

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *AccessPoint) { DestroyAccessPoint(_obj) })
	return obj, nil
}
