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

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

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

	GetAdapters_ *dbusPropertyBluetoothGetAdapters_
	GetDevices_  *dbusPropertyBluetoothGetDevices_
	State        *dbusPropertyBluetoothState
}

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AdapterAdded'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AdapterRemoved'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AdapterPropertiesChanged'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='DeviceAdded'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='DeviceRemoved'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='DevicePropertiesChanged'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='RequestPinCode'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AuthorizeService'")

	obj.GetAdapters_.Reset()
	obj.GetDevices_.Reset()
	obj.State.Reset()
}

func (obj *Bluetooth) ConnectDevice(arg0 dbus.ObjectPath) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.ConnectDevice", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) DebugInfo() (arg0 string, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.DebugInfo", 0).Store(&arg0)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) DisconnectDevice(arg0 dbus.ObjectPath) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.DisconnectDevice", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) FeedAuthorizeService(arg0 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.FeedAuthorizeService", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) FeedPinCode(arg0 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.FeedPinCode", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) GetAdapters() (arg0 string, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.GetAdapters", 0).Store(&arg0)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) GetDevices(arg0 dbus.ObjectPath) (arg1 string, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.GetDevices", 0, arg0).Store(&arg1)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) RemoveDevice(arg0 dbus.ObjectPath, arg1 dbus.ObjectPath) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.RemoveDevice", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) RequestDiscovery(arg0 dbus.ObjectPath) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.RequestDiscovery", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) SetAdapterAlias(arg0 dbus.ObjectPath, arg1 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.SetAdapterAlias", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) SetAdapterDiscoverable(arg0 dbus.ObjectPath, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.SetAdapterDiscoverable", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) SetAdapterDiscoverableTimeout(arg0 dbus.ObjectPath, arg1 uint32) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.SetAdapterDiscoverableTimeout", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) SetAdapterPowered(arg0 dbus.ObjectPath, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.SetAdapterPowered", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) SetDeviceAlias(arg0 dbus.ObjectPath, arg1 string) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.SetDeviceAlias", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) SetDeviceTrusted(arg0 dbus.ObjectPath, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Bluetooth.SetDeviceTrusted", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Bluetooth) ConnectAdapterAdded(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.AdapterAdded" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectAdapterRemoved(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.AdapterRemoved" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectAdapterPropertiesChanged(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.AdapterPropertiesChanged" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectDeviceAdded(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.DeviceAdded" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectDeviceRemoved(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.DeviceRemoved" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectDevicePropertiesChanged(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.DevicePropertiesChanged" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectRequestPinCode(callback func(arg0 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.RequestPinCode" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

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

func (obj *Bluetooth) ConnectAuthorizeService(callback func(arg0 string, arg1 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "com.deepin.daemon.Bluetooth.AuthorizeService" || 2 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string), v.Body[1].(string))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

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

func (this *dbusPropertyBluetoothGetAdapters_) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Bluetooth.GetAdapters_ is not writable")
}

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

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

func (this *dbusPropertyBluetoothGetDevices_) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Bluetooth.GetDevices_ is not writable")
}

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

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

func (this *dbusPropertyBluetoothState) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Bluetooth.State is not writable")
}

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

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

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

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

	obj.GetAdapters_ = &dbusPropertyBluetoothGetAdapters_{&property.BaseObserver{}, core}
	obj.GetDevices_ = &dbusPropertyBluetoothGetDevices_{&property.BaseObserver{}, core}
	obj.State = &dbusPropertyBluetoothState{&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='com.deepin.daemon.Bluetooth',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) == "com.deepin.daemon.Bluetooth" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "GetAdapters_" {
						obj.GetAdapters_.Notify()

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

					} else if key == "State" {
						obj.State.Notify()
					}
				}
			} else if v.Name == "com.deepin.daemon.Bluetooth.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 == "GetAdapters_" {
						obj.GetAdapters_.Notify()

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AdapterAdded'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AdapterRemoved'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AdapterPropertiesChanged'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='DeviceAdded'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='DeviceRemoved'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='DevicePropertiesChanged'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='RequestPinCode'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='com.deepin.daemon.Bluetooth',sender='" + obj.DestName + "',member='AuthorizeService'")

	runtime.SetFinalizer(obj, func(_obj *Bluetooth) { DestroyBluetooth(_obj) })
	return obj, nil
}
