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

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

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

	Address             *dbusPropertyAdapter1Address
	Name                *dbusPropertyAdapter1Name
	Alias               *dbusPropertyAdapter1Alias
	Class               *dbusPropertyAdapter1Class
	Powered             *dbusPropertyAdapter1Powered
	Discoverable        *dbusPropertyAdapter1Discoverable
	DiscoverableTimeout *dbusPropertyAdapter1DiscoverableTimeout
	Pairable            *dbusPropertyAdapter1Pairable
	PairableTimeout     *dbusPropertyAdapter1PairableTimeout
	Discovering         *dbusPropertyAdapter1Discovering
	UUIDs               *dbusPropertyAdapter1UUIDs
	Modalias            *dbusPropertyAdapter1Modalias
}

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

	obj.Address.Reset()
	obj.Name.Reset()
	obj.Alias.Reset()
	obj.Class.Reset()
	obj.Powered.Reset()
	obj.Discoverable.Reset()
	obj.DiscoverableTimeout.Reset()
	obj.Pairable.Reset()
	obj.PairableTimeout.Reset()
	obj.Discovering.Reset()
	obj.UUIDs.Reset()
	obj.Modalias.Reset()
}

func (obj *Adapter1) StartDiscovery() (_err error) {
	_err = obj.core.Call("org.bluez.Adapter1.StartDiscovery", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Adapter1) StopDiscovery() (_err error) {
	_err = obj.core.Call("org.bluez.Adapter1.StopDiscovery", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Adapter1) RemoveDevice(device dbus.ObjectPath) (_err error) {
	_err = obj.core.Call("org.bluez.Adapter1.RemoveDevice", 0, device).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyAdapter1Address) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Adapter1.Address is not writable")
}

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

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

func (this *dbusPropertyAdapter1Name) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Adapter1.Name is not writable")
}

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

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

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

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

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

func (this *dbusPropertyAdapter1Class) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Adapter1.Class is not writable")
}

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

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

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

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

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

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

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

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

func (this *dbusPropertyAdapter1DiscoverableTimeout) SetValue(v interface{} /*uint32*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*uint32)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "org.bluez.Adapter1", "DiscoverableTimeout", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property DiscoverableTimeout of org.bluez.Adapter1 is an uint32 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyAdapter1DiscoverableTimeout) Set(v uint32) {
	this.SetValue(v)
}

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

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

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

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

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

func (this *dbusPropertyAdapter1PairableTimeout) SetValue(v interface{} /*uint32*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*uint32)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "org.bluez.Adapter1", "PairableTimeout", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property PairableTimeout of org.bluez.Adapter1 is an uint32 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyAdapter1PairableTimeout) Set(v uint32) {
	this.SetValue(v)
}

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

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

func (this *dbusPropertyAdapter1Discovering) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Adapter1.Discovering is not writable")
}

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

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

func (this *dbusPropertyAdapter1UUIDs) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Adapter1.UUIDs is not writable")
}

func (this *dbusPropertyAdapter1UUIDs) Get() []string {
	v, _ := this.GetValue()
	return v.([]string)
}
func (this *dbusPropertyAdapter1UUIDs) GetValue() (interface{} /*[]string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.bluez.Adapter1", "UUIDs").Store(&r)
	if err == nil && r.Signature().String() == "as" {
		return r.Value().([]string), nil
	}
	return *new([]string), err
}
func (this *dbusPropertyAdapter1UUIDs) GetType() reflect.Type {
	return reflect.TypeOf((*[]string)(nil)).Elem()
}

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

func (this *dbusPropertyAdapter1Modalias) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Adapter1.Modalias is not writable")
}

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

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

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

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

	obj.Address = &dbusPropertyAdapter1Address{&property.BaseObserver{}, core}
	obj.Name = &dbusPropertyAdapter1Name{&property.BaseObserver{}, core}
	obj.Alias = &dbusPropertyAdapter1Alias{&property.BaseObserver{}, core}
	obj.Class = &dbusPropertyAdapter1Class{&property.BaseObserver{}, core}
	obj.Powered = &dbusPropertyAdapter1Powered{&property.BaseObserver{}, core}
	obj.Discoverable = &dbusPropertyAdapter1Discoverable{&property.BaseObserver{}, core}
	obj.DiscoverableTimeout = &dbusPropertyAdapter1DiscoverableTimeout{&property.BaseObserver{}, core}
	obj.Pairable = &dbusPropertyAdapter1Pairable{&property.BaseObserver{}, core}
	obj.PairableTimeout = &dbusPropertyAdapter1PairableTimeout{&property.BaseObserver{}, core}
	obj.Discovering = &dbusPropertyAdapter1Discovering{&property.BaseObserver{}, core}
	obj.UUIDs = &dbusPropertyAdapter1UUIDs{&property.BaseObserver{}, core}
	obj.Modalias = &dbusPropertyAdapter1Modalias{&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.bluez.Adapter1',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.bluez.Adapter1" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Address" {
						obj.Address.Notify()

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

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

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

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

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

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

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

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

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

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

					} else if key == "Modalias" {
						obj.Modalias.Notify()
					}
				}
			} else if v.Name == "org.bluez.Adapter1.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 == "Address" {
						obj.Address.Notify()

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Adapter1) { DestroyAdapter1(_obj) })
	return obj, nil
}
