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

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

	Name           *dbusPropertyAudioSourceName
	Description    *dbusPropertyAudioSourceDescription
	BaseVolume     *dbusPropertyAudioSourceBaseVolume
	Mute           *dbusPropertyAudioSourceMute
	Volume         *dbusPropertyAudioSourceVolume
	Balance        *dbusPropertyAudioSourceBalance
	SupportBalance *dbusPropertyAudioSourceSupportBalance
	Fade           *dbusPropertyAudioSourceFade
	SupportFade    *dbusPropertyAudioSourceSupportFade
	Ports          *dbusPropertyAudioSourcePorts
	ActivePort     *dbusPropertyAudioSourceActivePort
}

func (obj *AudioSource) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *AudioSource) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyAudioSource(obj *AudioSource) {
	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.Source',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 *AudioSource) GetMeter() (arg0 dbus.ObjectPath, _err error) {
	_err = obj.core.Call("com.deepin.daemon.Audio.Source.GetMeter", 0).Store(&arg0)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	obj.Name = &dbusPropertyAudioSourceName{&property.BaseObserver{}, core}
	obj.Description = &dbusPropertyAudioSourceDescription{&property.BaseObserver{}, core}
	obj.BaseVolume = &dbusPropertyAudioSourceBaseVolume{&property.BaseObserver{}, core}
	obj.Mute = &dbusPropertyAudioSourceMute{&property.BaseObserver{}, core}
	obj.Volume = &dbusPropertyAudioSourceVolume{&property.BaseObserver{}, core}
	obj.Balance = &dbusPropertyAudioSourceBalance{&property.BaseObserver{}, core}
	obj.SupportBalance = &dbusPropertyAudioSourceSupportBalance{&property.BaseObserver{}, core}
	obj.Fade = &dbusPropertyAudioSourceFade{&property.BaseObserver{}, core}
	obj.SupportFade = &dbusPropertyAudioSourceSupportFade{&property.BaseObserver{}, core}
	obj.Ports = &dbusPropertyAudioSourcePorts{&property.BaseObserver{}, core}
	obj.ActivePort = &dbusPropertyAudioSourceActivePort{&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.Source',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.Source" {
				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.Source.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 *AudioSource) { DestroyAudioSource(_obj) })
	return obj, nil
}
