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

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

	Name           *dbusPropertyAudioSinkName
	Description    *dbusPropertyAudioSinkDescription
	BaseVolume     *dbusPropertyAudioSinkBaseVolume
	Mute           *dbusPropertyAudioSinkMute
	Volume         *dbusPropertyAudioSinkVolume
	Balance        *dbusPropertyAudioSinkBalance
	SupportBalance *dbusPropertyAudioSinkSupportBalance
	Fade           *dbusPropertyAudioSinkFade
	SupportFade    *dbusPropertyAudioSinkSupportFade
	Ports          *dbusPropertyAudioSinkPorts
	ActivePort     *dbusPropertyAudioSinkActivePort
}

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

	obj.Name.Reset()
	obj.Description.Reset()
	obj.BaseVolume.Reset()
	obj.Mute.Reset()
	obj.Volume.Reset()
	obj.Balance.Reset()
	obj.SupportBalance.Reset()
	obj.Fade.Reset()
	obj.SupportFade.Reset()
	obj.Ports.Reset()
	obj.ActivePort.Reset()
}

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyAudioSinkDescription) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.Sink.Description is not writable")
}

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

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

func (this *dbusPropertyAudioSinkBaseVolume) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.Sink.BaseVolume is not writable")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyAudioSinkPorts) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.Sink.Ports is not writable")
}

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

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

func (this *dbusPropertyAudioSinkActivePort) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Audio.Sink.ActivePort is not writable")
}

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

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

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

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

	obj.Name = &dbusPropertyAudioSinkName{&property.BaseObserver{}, core}
	obj.Description = &dbusPropertyAudioSinkDescription{&property.BaseObserver{}, core}
	obj.BaseVolume = &dbusPropertyAudioSinkBaseVolume{&property.BaseObserver{}, core}
	obj.Mute = &dbusPropertyAudioSinkMute{&property.BaseObserver{}, core}
	obj.Volume = &dbusPropertyAudioSinkVolume{&property.BaseObserver{}, core}
	obj.Balance = &dbusPropertyAudioSinkBalance{&property.BaseObserver{}, core}
	obj.SupportBalance = &dbusPropertyAudioSinkSupportBalance{&property.BaseObserver{}, core}
	obj.Fade = &dbusPropertyAudioSinkFade{&property.BaseObserver{}, core}
	obj.SupportFade = &dbusPropertyAudioSinkSupportFade{&property.BaseObserver{}, core}
	obj.Ports = &dbusPropertyAudioSinkPorts{&property.BaseObserver{}, core}
	obj.ActivePort = &dbusPropertyAudioSinkActivePort{&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.Sink',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.Sink" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Name" {
						obj.Name.Notify()

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

					} else if key == "BaseVolume" {
						obj.BaseVolume.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 key == "Ports" {
						obj.Ports.Notify()

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

					} else if key == "BaseVolume" {
						obj.BaseVolume.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 key == "Ports" {
						obj.Ports.Notify()

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

	runtime.SetFinalizer(obj, func(_obj *AudioSink) { DestroyAudioSink(_obj) })
	return obj, nil
}
