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

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

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

	Name           *dbusPropertyAudioSinkInputName
	Icon           *dbusPropertyAudioSinkInputIcon
	Mute           *dbusPropertyAudioSinkInputMute
	Volume         *dbusPropertyAudioSinkInputVolume
	Balance        *dbusPropertyAudioSinkInputBalance
	SupportBalance *dbusPropertyAudioSinkInputSupportBalance
	Fade           *dbusPropertyAudioSinkInputFade
	SupportFade    *dbusPropertyAudioSinkInputSupportFade
}

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

	obj.Name.Reset()
	obj.Icon.Reset()
	obj.Mute.Reset()
	obj.Volume.Reset()
	obj.Balance.Reset()
	obj.SupportBalance.Reset()
	obj.Fade.Reset()
	obj.SupportFade.Reset()
}

func (obj *AudioSinkInput) SetBalance(arg0 float64, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Audio.SinkInput.SetBalance", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *AudioSinkInput) SetFade(arg0 float64) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Audio.SinkInput.SetFade", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *AudioSinkInput) SetMute(arg0 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Audio.SinkInput.SetMute", 0, arg0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *AudioSinkInput) SetVolume(arg0 float64, arg1 bool) (_err error) {
	_err = obj.core.Call("com.deepin.daemon.Audio.SinkInput.SetVolume", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyAudioSinkInputName) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.Name is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputIcon) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.Icon is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputMute) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.Mute is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputVolume) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.Volume is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputBalance) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.Balance is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputSupportBalance) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.SupportBalance is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputFade) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.Fade is not writable")
}

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

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

func (this *dbusPropertyAudioSinkInputSupportFade) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.SinkInput.SupportFade is not writable")
}

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

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

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

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

	obj.Name = &dbusPropertyAudioSinkInputName{&property.BaseObserver{}, core}
	obj.Icon = &dbusPropertyAudioSinkInputIcon{&property.BaseObserver{}, core}
	obj.Mute = &dbusPropertyAudioSinkInputMute{&property.BaseObserver{}, core}
	obj.Volume = &dbusPropertyAudioSinkInputVolume{&property.BaseObserver{}, core}
	obj.Balance = &dbusPropertyAudioSinkInputBalance{&property.BaseObserver{}, core}
	obj.SupportBalance = &dbusPropertyAudioSinkInputSupportBalance{&property.BaseObserver{}, core}
	obj.Fade = &dbusPropertyAudioSinkInputFade{&property.BaseObserver{}, core}
	obj.SupportFade = &dbusPropertyAudioSinkInputSupportFade{&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.Audio.SinkInput',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.Audio.SinkInput" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Name" {
						obj.Name.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *AudioSinkInput) { DestroyAudioSinkInput(_obj) })
	return obj, nil
}
