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

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

	Address       *dbusPropertyDevice1Address
	Name          *dbusPropertyDevice1Name
	Alias         *dbusPropertyDevice1Alias
	Class         *dbusPropertyDevice1Class
	Appearance    *dbusPropertyDevice1Appearance
	Icon          *dbusPropertyDevice1Icon
	Paired        *dbusPropertyDevice1Paired
	Trusted       *dbusPropertyDevice1Trusted
	Blocked       *dbusPropertyDevice1Blocked
	LegacyPairing *dbusPropertyDevice1LegacyPairing
	RSSI          *dbusPropertyDevice1RSSI
	Connected     *dbusPropertyDevice1Connected
	UUIDs         *dbusPropertyDevice1UUIDs
	Modalias      *dbusPropertyDevice1Modalias
	Adapter       *dbusPropertyDevice1Adapter
}

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

	obj.Address.Reset()
	obj.Name.Reset()
	obj.Alias.Reset()
	obj.Class.Reset()
	obj.Appearance.Reset()
	obj.Icon.Reset()
	obj.Paired.Reset()
	obj.Trusted.Reset()
	obj.Blocked.Reset()
	obj.LegacyPairing.Reset()
	obj.RSSI.Reset()
	obj.Connected.Reset()
	obj.UUIDs.Reset()
	obj.Modalias.Reset()
	obj.Adapter.Reset()
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyDevice1Appearance) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.Appearance is not writable")
}

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

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

func (this *dbusPropertyDevice1Icon) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.Icon is not writable")
}

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

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

func (this *dbusPropertyDevice1Paired) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.Paired is not writable")
}

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

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

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

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

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

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

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

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

func (this *dbusPropertyDevice1LegacyPairing) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.LegacyPairing is not writable")
}

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

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

func (this *dbusPropertyDevice1RSSI) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.RSSI is not writable")
}

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

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

func (this *dbusPropertyDevice1Connected) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.Connected is not writable")
}

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

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

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

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

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

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

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

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

func (this *dbusPropertyDevice1Adapter) SetValue(notwritable interface{}) {
	fmt.Println("org.bluez.Device1.Adapter is not writable")
}

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

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

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

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

	obj.Address = &dbusPropertyDevice1Address{&property.BaseObserver{}, core}
	obj.Name = &dbusPropertyDevice1Name{&property.BaseObserver{}, core}
	obj.Alias = &dbusPropertyDevice1Alias{&property.BaseObserver{}, core}
	obj.Class = &dbusPropertyDevice1Class{&property.BaseObserver{}, core}
	obj.Appearance = &dbusPropertyDevice1Appearance{&property.BaseObserver{}, core}
	obj.Icon = &dbusPropertyDevice1Icon{&property.BaseObserver{}, core}
	obj.Paired = &dbusPropertyDevice1Paired{&property.BaseObserver{}, core}
	obj.Trusted = &dbusPropertyDevice1Trusted{&property.BaseObserver{}, core}
	obj.Blocked = &dbusPropertyDevice1Blocked{&property.BaseObserver{}, core}
	obj.LegacyPairing = &dbusPropertyDevice1LegacyPairing{&property.BaseObserver{}, core}
	obj.RSSI = &dbusPropertyDevice1RSSI{&property.BaseObserver{}, core}
	obj.Connected = &dbusPropertyDevice1Connected{&property.BaseObserver{}, core}
	obj.UUIDs = &dbusPropertyDevice1UUIDs{&property.BaseObserver{}, core}
	obj.Modalias = &dbusPropertyDevice1Modalias{&property.BaseObserver{}, core}
	obj.Adapter = &dbusPropertyDevice1Adapter{&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.Device1',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.Device1" {
				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 == "Appearance" {
						obj.Appearance.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Device1) { DestroyDevice1(_obj) })
	return obj, nil
}
