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

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

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

	Version    *dbusPropertySystemInfoVersion
	Processor  *dbusPropertySystemInfoProcessor
	MemoryCap  *dbusPropertySystemInfoMemoryCap
	SystemType *dbusPropertySystemInfoSystemType
	DiskCap    *dbusPropertySystemInfoDiskCap
}

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

	obj.Version.Reset()
	obj.Processor.Reset()
	obj.MemoryCap.Reset()
	obj.SystemType.Reset()
	obj.DiskCap.Reset()
}

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

func (this *dbusPropertySystemInfoVersion) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.SystemInfo.Version is not writable")
}

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

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

func (this *dbusPropertySystemInfoProcessor) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.SystemInfo.Processor is not writable")
}

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

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

func (this *dbusPropertySystemInfoMemoryCap) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.SystemInfo.MemoryCap is not writable")
}

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

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

func (this *dbusPropertySystemInfoSystemType) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.SystemInfo.SystemType is not writable")
}

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

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

func (this *dbusPropertySystemInfoDiskCap) SetValue(notwritable interface{}) {
	fmt.Println("com.deepin.daemon.SystemInfo.DiskCap is not writable")
}

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

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

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

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

	obj.Version = &dbusPropertySystemInfoVersion{&property.BaseObserver{}, core}
	obj.Processor = &dbusPropertySystemInfoProcessor{&property.BaseObserver{}, core}
	obj.MemoryCap = &dbusPropertySystemInfoMemoryCap{&property.BaseObserver{}, core}
	obj.SystemType = &dbusPropertySystemInfoSystemType{&property.BaseObserver{}, core}
	obj.DiskCap = &dbusPropertySystemInfoDiskCap{&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.SystemInfo',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.SystemInfo" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Version" {
						obj.Version.Notify()

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *SystemInfo) { DestroySystemInfo(_obj) })
	return obj, nil
}
