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

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

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

	Capabilities    *dbusPropertyModemLocationCapabilities
	Enabled         *dbusPropertyModemLocationEnabled
	SignalsLocation *dbusPropertyModemLocationSignalsLocation
	GetLocation_    *dbusPropertyModemLocationGetLocation_
}

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

	obj.Capabilities.Reset()
	obj.Enabled.Reset()
	obj.SignalsLocation.Reset()
	obj.GetLocation_.Reset()
}

func (obj *ModemLocation) Setup(sources uint32, signal_location bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.ModemManager1.Modem.Location.Setup", 0, sources, signal_location).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *ModemLocation) GetLocation() (Location map[uint32]dbus.Variant, _err error) {
	_err = obj.core.Call("org.freedesktop.ModemManager1.Modem.Location.GetLocation", 0).Store(&Location)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyModemLocationCapabilities) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Location.Capabilities is not writable")
}

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

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

func (this *dbusPropertyModemLocationEnabled) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Location.Enabled is not writable")
}

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

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

func (this *dbusPropertyModemLocationSignalsLocation) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Location.SignalsLocation is not writable")
}

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

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

func (this *dbusPropertyModemLocationGetLocation_) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.ModemManager1.Modem.Location.GetLocation_ is not writable")
}

func (this *dbusPropertyModemLocationGetLocation_) Get() map[uint32]dbus.Variant {
	v, _ := this.GetValue()
	return v.(map[uint32]dbus.Variant)
}
func (this *dbusPropertyModemLocationGetLocation_) GetValue() (interface{} /*map[uint32]dbus.Variant*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.ModemManager1.Modem.Location", "GetLocation_").Store(&r)
	if err == nil && r.Signature().String() == "a{uv}" {
		return r.Value().(map[uint32]dbus.Variant), nil
	}
	return *new(map[uint32]dbus.Variant), err
}
func (this *dbusPropertyModemLocationGetLocation_) GetType() reflect.Type {
	return reflect.TypeOf((*map[uint32]dbus.Variant)(nil)).Elem()
}

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

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

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

	obj.Capabilities = &dbusPropertyModemLocationCapabilities{&property.BaseObserver{}, core}
	obj.Enabled = &dbusPropertyModemLocationEnabled{&property.BaseObserver{}, core}
	obj.SignalsLocation = &dbusPropertyModemLocationSignalsLocation{&property.BaseObserver{}, core}
	obj.GetLocation_ = &dbusPropertyModemLocationGetLocation_{&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.ModemManager1.Modem.Location',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.ModemManager1.Modem.Location" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Capabilities" {
						obj.Capabilities.Notify()

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

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

					} else if key == "GetLocation_" {
						obj.GetLocation_.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.ModemManager1.Modem.Location.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 == "Capabilities" {
						obj.Capabilities.Notify()

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

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

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

	runtime.SetFinalizer(obj, func(_obj *ModemLocation) { DestroyModemLocation(_obj) })
	return obj, nil
}
