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

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

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

	UUID              *dbusPropertyMDRaidUUID
	Name              *dbusPropertyMDRaidName
	Level             *dbusPropertyMDRaidLevel
	NumDevices        *dbusPropertyMDRaidNumDevices
	Size              *dbusPropertyMDRaidSize
	SyncAction        *dbusPropertyMDRaidSyncAction
	SyncCompleted     *dbusPropertyMDRaidSyncCompleted
	SyncRate          *dbusPropertyMDRaidSyncRate
	SyncRemainingTime *dbusPropertyMDRaidSyncRemainingTime
	Degraded          *dbusPropertyMDRaidDegraded
	BitmapLocation    *dbusPropertyMDRaidBitmapLocation
	ChunkSize         *dbusPropertyMDRaidChunkSize
	ActiveDevices     *dbusPropertyMDRaidActiveDevices
}

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

	obj.UUID.Reset()
	obj.Name.Reset()
	obj.Level.Reset()
	obj.NumDevices.Reset()
	obj.Size.Reset()
	obj.SyncAction.Reset()
	obj.SyncCompleted.Reset()
	obj.SyncRate.Reset()
	obj.SyncRemainingTime.Reset()
	obj.Degraded.Reset()
	obj.BitmapLocation.Reset()
	obj.ChunkSize.Reset()
	obj.ActiveDevices.Reset()
}

func (obj *MDRaid) Start(options map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.UDisks2.MDRaid.Start", 0, options).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *MDRaid) Stop(options map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.UDisks2.MDRaid.Stop", 0, options).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *MDRaid) RemoveDevice(device dbus.ObjectPath, options map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.UDisks2.MDRaid.RemoveDevice", 0, device, options).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *MDRaid) AddDevice(device dbus.ObjectPath, options map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.UDisks2.MDRaid.AddDevice", 0, device, options).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *MDRaid) SetBitmapLocation(value []uint8, options map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.UDisks2.MDRaid.SetBitmapLocation", 0, value, options).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *MDRaid) RequestSyncAction(sync_action string, options map[string]dbus.Variant) (_err error) {
	_err = obj.core.Call("org.freedesktop.UDisks2.MDRaid.RequestSyncAction", 0, sync_action, options).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyMDRaidUUID) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.UUID is not writable")
}

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

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

func (this *dbusPropertyMDRaidName) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.Name is not writable")
}

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

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

func (this *dbusPropertyMDRaidLevel) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.Level is not writable")
}

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

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

func (this *dbusPropertyMDRaidNumDevices) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.NumDevices is not writable")
}

func (this *dbusPropertyMDRaidNumDevices) Get() uint32 {
	v, _ := this.GetValue()
	return v.(uint32)
}
func (this *dbusPropertyMDRaidNumDevices) GetValue() (interface{} /*uint32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.UDisks2.MDRaid", "NumDevices").Store(&r)
	if err == nil && r.Signature().String() == "u" {
		return r.Value().(uint32), nil
	}
	return *new(uint32), err
}
func (this *dbusPropertyMDRaidNumDevices) GetType() reflect.Type {
	return reflect.TypeOf((*uint32)(nil)).Elem()
}

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

func (this *dbusPropertyMDRaidSize) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.Size is not writable")
}

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

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

func (this *dbusPropertyMDRaidSyncAction) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.SyncAction is not writable")
}

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

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

func (this *dbusPropertyMDRaidSyncCompleted) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.SyncCompleted is not writable")
}

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

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

func (this *dbusPropertyMDRaidSyncRate) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.SyncRate is not writable")
}

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

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

func (this *dbusPropertyMDRaidSyncRemainingTime) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.SyncRemainingTime is not writable")
}

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

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

func (this *dbusPropertyMDRaidDegraded) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.Degraded is not writable")
}

func (this *dbusPropertyMDRaidDegraded) Get() uint32 {
	v, _ := this.GetValue()
	return v.(uint32)
}
func (this *dbusPropertyMDRaidDegraded) GetValue() (interface{} /*uint32*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.UDisks2.MDRaid", "Degraded").Store(&r)
	if err == nil && r.Signature().String() == "u" {
		return r.Value().(uint32), nil
	}
	return *new(uint32), err
}
func (this *dbusPropertyMDRaidDegraded) GetType() reflect.Type {
	return reflect.TypeOf((*uint32)(nil)).Elem()
}

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

func (this *dbusPropertyMDRaidBitmapLocation) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.BitmapLocation is not writable")
}

func (this *dbusPropertyMDRaidBitmapLocation) Get() []uint8 {
	v, _ := this.GetValue()
	return v.([]uint8)
}
func (this *dbusPropertyMDRaidBitmapLocation) GetValue() (interface{} /*[]uint8*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.UDisks2.MDRaid", "BitmapLocation").Store(&r)
	if err == nil && r.Signature().String() == "ay" {
		return r.Value().([]uint8), nil
	}
	return *new([]uint8), err
}
func (this *dbusPropertyMDRaidBitmapLocation) GetType() reflect.Type {
	return reflect.TypeOf((*[]uint8)(nil)).Elem()
}

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

func (this *dbusPropertyMDRaidChunkSize) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.ChunkSize is not writable")
}

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

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

func (this *dbusPropertyMDRaidActiveDevices) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.MDRaid.ActiveDevices is not writable")
}

func (this *dbusPropertyMDRaidActiveDevices) Get() [][]interface{} {
	v, _ := this.GetValue()
	return v.([][]interface{})
}
func (this *dbusPropertyMDRaidActiveDevices) GetValue() (interface{} /*[][]interface {}*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.UDisks2.MDRaid", "ActiveDevices").Store(&r)
	if err == nil && r.Signature().String() == "a(oiasta{sv})" {
		return r.Value().([][]interface{}), nil
	}
	return *new([][]interface{}), err
}
func (this *dbusPropertyMDRaidActiveDevices) GetType() reflect.Type {
	return reflect.TypeOf((*[][]interface{})(nil)).Elem()
}

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

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

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

	obj.UUID = &dbusPropertyMDRaidUUID{&property.BaseObserver{}, core}
	obj.Name = &dbusPropertyMDRaidName{&property.BaseObserver{}, core}
	obj.Level = &dbusPropertyMDRaidLevel{&property.BaseObserver{}, core}
	obj.NumDevices = &dbusPropertyMDRaidNumDevices{&property.BaseObserver{}, core}
	obj.Size = &dbusPropertyMDRaidSize{&property.BaseObserver{}, core}
	obj.SyncAction = &dbusPropertyMDRaidSyncAction{&property.BaseObserver{}, core}
	obj.SyncCompleted = &dbusPropertyMDRaidSyncCompleted{&property.BaseObserver{}, core}
	obj.SyncRate = &dbusPropertyMDRaidSyncRate{&property.BaseObserver{}, core}
	obj.SyncRemainingTime = &dbusPropertyMDRaidSyncRemainingTime{&property.BaseObserver{}, core}
	obj.Degraded = &dbusPropertyMDRaidDegraded{&property.BaseObserver{}, core}
	obj.BitmapLocation = &dbusPropertyMDRaidBitmapLocation{&property.BaseObserver{}, core}
	obj.ChunkSize = &dbusPropertyMDRaidChunkSize{&property.BaseObserver{}, core}
	obj.ActiveDevices = &dbusPropertyMDRaidActiveDevices{&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='org.freedesktop.UDisks2.MDRaid',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) == "org.freedesktop.UDisks2.MDRaid" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "UUID" {
						obj.UUID.Notify()

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

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

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

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

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

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

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

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

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

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

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

					} else if key == "ActiveDevices" {
						obj.ActiveDevices.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.UDisks2.MDRaid.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 == "UUID" {
						obj.UUID.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *MDRaid) { DestroyMDRaid(_obj) })
	return obj, nil
}
