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

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

	Number      *dbusPropertyPartitionNumber
	Type        *dbusPropertyPartitionType
	Flags       *dbusPropertyPartitionFlags
	Offset      *dbusPropertyPartitionOffset
	Size        *dbusPropertyPartitionSize
	Name        *dbusPropertyPartitionName
	UUID        *dbusPropertyPartitionUUID
	Table       *dbusPropertyPartitionTable
	IsContainer *dbusPropertyPartitionIsContainer
	IsContained *dbusPropertyPartitionIsContained
}

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

	obj.Number.Reset()
	obj.Type.Reset()
	obj.Flags.Reset()
	obj.Offset.Reset()
	obj.Size.Reset()
	obj.Name.Reset()
	obj.UUID.Reset()
	obj.Table.Reset()
	obj.IsContainer.Reset()
	obj.IsContained.Reset()
}

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

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

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

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

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

func (this *dbusPropertyPartitionNumber) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.Number is not writable")
}

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

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

func (this *dbusPropertyPartitionType) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.Type is not writable")
}

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

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

func (this *dbusPropertyPartitionFlags) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.Flags is not writable")
}

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

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

func (this *dbusPropertyPartitionOffset) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.Offset is not writable")
}

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

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

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

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

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

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

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

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

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

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

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

func (this *dbusPropertyPartitionTable) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.Table is not writable")
}

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

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

func (this *dbusPropertyPartitionIsContainer) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.IsContainer is not writable")
}

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

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

func (this *dbusPropertyPartitionIsContained) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.UDisks2.Partition.IsContained is not writable")
}

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

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

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

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

	obj.Number = &dbusPropertyPartitionNumber{&property.BaseObserver{}, core}
	obj.Type = &dbusPropertyPartitionType{&property.BaseObserver{}, core}
	obj.Flags = &dbusPropertyPartitionFlags{&property.BaseObserver{}, core}
	obj.Offset = &dbusPropertyPartitionOffset{&property.BaseObserver{}, core}
	obj.Size = &dbusPropertyPartitionSize{&property.BaseObserver{}, core}
	obj.Name = &dbusPropertyPartitionName{&property.BaseObserver{}, core}
	obj.UUID = &dbusPropertyPartitionUUID{&property.BaseObserver{}, core}
	obj.Table = &dbusPropertyPartitionTable{&property.BaseObserver{}, core}
	obj.IsContainer = &dbusPropertyPartitionIsContainer{&property.BaseObserver{}, core}
	obj.IsContained = &dbusPropertyPartitionIsContained{&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.Partition',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.Partition" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Number" {
						obj.Number.Notify()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Partition) { DestroyPartition(_obj) })
	return obj, nil
}
