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

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

	Nsps            *dbusPropertyDeviceWiMaxNsps
	HwAddress       *dbusPropertyDeviceWiMaxHwAddress
	CenterFrequency *dbusPropertyDeviceWiMaxCenterFrequency
	Rssi            *dbusPropertyDeviceWiMaxRssi
	Cinr            *dbusPropertyDeviceWiMaxCinr
	TxPower         *dbusPropertyDeviceWiMaxTxPower
	Bsid            *dbusPropertyDeviceWiMaxBsid
	ActiveNsp       *dbusPropertyDeviceWiMaxActiveNsp
}

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

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

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

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

	obj.Nsps.Reset()
	obj.HwAddress.Reset()
	obj.CenterFrequency.Reset()
	obj.Rssi.Reset()
	obj.Cinr.Reset()
	obj.TxPower.Reset()
	obj.Bsid.Reset()
	obj.ActiveNsp.Reset()
}

func (obj *DeviceWiMax) GetNspList() (nsps []dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.NetworkManager.Device.WiMax.GetNspList", 0).Store(&nsps)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *DeviceWiMax) 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.WiMax.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)
	}
}

func (obj *DeviceWiMax) ConnectNspAdded(callback func(nsp dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.NetworkManager.Device.WiMax.NspAdded" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

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

func (obj *DeviceWiMax) ConnectNspRemoved(callback func(nsp dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.NetworkManager.Device.WiMax.NspRemoved" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

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

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

func (this *dbusPropertyDeviceWiMaxNsps) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.Nsps is not writable")
}

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

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

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

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

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

func (this *dbusPropertyDeviceWiMaxCenterFrequency) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.CenterFrequency is not writable")
}

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

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

func (this *dbusPropertyDeviceWiMaxRssi) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.Rssi is not writable")
}

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

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

func (this *dbusPropertyDeviceWiMaxCinr) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.Cinr is not writable")
}

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

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

func (this *dbusPropertyDeviceWiMaxTxPower) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.TxPower is not writable")
}

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

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

func (this *dbusPropertyDeviceWiMaxBsid) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.Bsid is not writable")
}

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

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

func (this *dbusPropertyDeviceWiMaxActiveNsp) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.NetworkManager.Device.WiMax.ActiveNsp is not writable")
}

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

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

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

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

	obj.Nsps = &dbusPropertyDeviceWiMaxNsps{&property.BaseObserver{}, core}
	obj.HwAddress = &dbusPropertyDeviceWiMaxHwAddress{&property.BaseObserver{}, core}
	obj.CenterFrequency = &dbusPropertyDeviceWiMaxCenterFrequency{&property.BaseObserver{}, core}
	obj.Rssi = &dbusPropertyDeviceWiMaxRssi{&property.BaseObserver{}, core}
	obj.Cinr = &dbusPropertyDeviceWiMaxCinr{&property.BaseObserver{}, core}
	obj.TxPower = &dbusPropertyDeviceWiMaxTxPower{&property.BaseObserver{}, core}
	obj.Bsid = &dbusPropertyDeviceWiMaxBsid{&property.BaseObserver{}, core}
	obj.ActiveNsp = &dbusPropertyDeviceWiMaxActiveNsp{&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.WiMax',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.WiMax" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Nsps" {
						obj.Nsps.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *DeviceWiMax) { DestroyDeviceWiMax(_obj) })
	return obj, nil
}
