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

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

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

	Timezone        *dbusPropertyTimedate1Timezone
	LocalRTC        *dbusPropertyTimedate1LocalRTC
	CanNTP          *dbusPropertyTimedate1CanNTP
	NTP             *dbusPropertyTimedate1NTP
	NTPSynchronized *dbusPropertyTimedate1NTPSynchronized
	TimeUSec        *dbusPropertyTimedate1TimeUSec
	RTCTimeUSec     *dbusPropertyTimedate1RTCTimeUSec
}

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

	obj.Timezone.Reset()
	obj.LocalRTC.Reset()
	obj.CanNTP.Reset()
	obj.NTP.Reset()
	obj.NTPSynchronized.Reset()
	obj.TimeUSec.Reset()
	obj.RTCTimeUSec.Reset()
}

func (obj *Timedate1) SetTime(arg0 int64, arg1 bool, arg2 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.timedate1.SetTime", 0, arg0, arg1, arg2).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate1) SetTimezone(arg0 string, arg1 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.timedate1.SetTimezone", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate1) SetLocalRTC(arg0 bool, arg1 bool, arg2 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.timedate1.SetLocalRTC", 0, arg0, arg1, arg2).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Timedate1) SetNTP(arg0 bool, arg1 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.timedate1.SetNTP", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

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

func (this *dbusPropertyTimedate1Timezone) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.Timezone is not writable")
}

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

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

func (this *dbusPropertyTimedate1LocalRTC) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.LocalRTC is not writable")
}

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

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

func (this *dbusPropertyTimedate1CanNTP) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.CanNTP is not writable")
}

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

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

func (this *dbusPropertyTimedate1NTP) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.NTP is not writable")
}

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

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

func (this *dbusPropertyTimedate1NTPSynchronized) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.NTPSynchronized is not writable")
}

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

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

func (this *dbusPropertyTimedate1TimeUSec) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.TimeUSec is not writable")
}

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

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

func (this *dbusPropertyTimedate1RTCTimeUSec) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.timedate1.RTCTimeUSec is not writable")
}

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

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

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

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

	obj.Timezone = &dbusPropertyTimedate1Timezone{&property.BaseObserver{}, core}
	obj.LocalRTC = &dbusPropertyTimedate1LocalRTC{&property.BaseObserver{}, core}
	obj.CanNTP = &dbusPropertyTimedate1CanNTP{&property.BaseObserver{}, core}
	obj.NTP = &dbusPropertyTimedate1NTP{&property.BaseObserver{}, core}
	obj.NTPSynchronized = &dbusPropertyTimedate1NTPSynchronized{&property.BaseObserver{}, core}
	obj.TimeUSec = &dbusPropertyTimedate1TimeUSec{&property.BaseObserver{}, core}
	obj.RTCTimeUSec = &dbusPropertyTimedate1RTCTimeUSec{&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.timedate1',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.timedate1" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Timezone" {
						obj.Timezone.Notify()

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

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

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

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

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

					} else if key == "RTCTimeUSec" {
						obj.RTCTimeUSec.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.timedate1.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 == "Timezone" {
						obj.Timezone.Notify()

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

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

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

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

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

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

	runtime.SetFinalizer(obj, func(_obj *Timedate1) { DestroyTimedate1(_obj) })
	return obj, nil
}
