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

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

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

	FixSettingsAlways *dbusPropertyGrub2FixSettingsAlways
	EnableTheme       *dbusPropertyGrub2EnableTheme
	DefaultEntry      *dbusPropertyGrub2DefaultEntry
	Timeout           *dbusPropertyGrub2Timeout
	Resolution        *dbusPropertyGrub2Resolution
	Updating          *dbusPropertyGrub2Updating
}

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

	obj.FixSettingsAlways.Reset()
	obj.EnableTheme.Reset()
	obj.DefaultEntry.Reset()
	obj.Timeout.Reset()
	obj.Resolution.Reset()
	obj.Updating.Reset()
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyGrub2Timeout) SetValue(v interface{} /*int32*/) {
	if reflect.TypeOf(v) == reflect.TypeOf((*int32)(nil)).Elem() {
		this.core.Call("org.freedesktop.DBus.Properties.Set", 0, "com.deepin.daemon.Grub2", "Timeout", dbus.MakeVariant(v))
	} else {
		fmt.Println("The property Timeout of com.deepin.daemon.Grub2 is an int32 but Set with an ", reflect.TypeOf(v))
	}
}
func (this *dbusPropertyGrub2Timeout) Set(v int32) {
	this.SetValue(v)
}

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

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

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

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

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

func (this *dbusPropertyGrub2Updating) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.Grub2.Updating is not writable")
}

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

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

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

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

	obj.FixSettingsAlways = &dbusPropertyGrub2FixSettingsAlways{&property.BaseObserver{}, core}
	obj.EnableTheme = &dbusPropertyGrub2EnableTheme{&property.BaseObserver{}, core}
	obj.DefaultEntry = &dbusPropertyGrub2DefaultEntry{&property.BaseObserver{}, core}
	obj.Timeout = &dbusPropertyGrub2Timeout{&property.BaseObserver{}, core}
	obj.Resolution = &dbusPropertyGrub2Resolution{&property.BaseObserver{}, core}
	obj.Updating = &dbusPropertyGrub2Updating{&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.Grub2',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.Grub2" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "FixSettingsAlways" {
						obj.FixSettingsAlways.Notify()

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Grub2) { DestroyGrub2(_obj) })
	return obj, nil
}
