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

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

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

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

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Manager',sender='" + obj.DestName + "',member='SeatAdded'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Manager',sender='" + obj.DestName + "',member='SeatRemoved'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Manager',sender='" + obj.DestName + "',member='SystemIdleHintChanged'")

}

func (obj *Manager) Restart() (_err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.Restart", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) CanRestart() (can_restart bool, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.CanRestart", 0).Store(&can_restart)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) Stop() (_err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.Stop", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) CanStop() (can_stop bool, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.CanStop", 0).Store(&can_stop)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) OpenSession() (cookie string, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.OpenSession", 0).Store(&cookie)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) OpenSessionWithParameters(parameters interface{}) (cookie string, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.OpenSessionWithParameters", 0, parameters).Store(&cookie)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) CloseSession(cookie string) (result bool, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.CloseSession", 0, cookie).Store(&result)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSeats() (seats []dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSeats", 0).Store(&seats)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSessions() (sessions []dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSessions", 0).Store(&sessions)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSessionForCookie(cookie string) (ssid dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSessionForCookie", 0, cookie).Store(&ssid)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSessionForUnixProcess(pid uint32) (ssid dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSessionForUnixProcess", 0, pid).Store(&ssid)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetCurrentSession() (ssid dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetCurrentSession", 0).Store(&ssid)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSessionsForUnixUser(uid uint32) (sessions []dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSessionsForUnixUser", 0, uid).Store(&sessions)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSessionsForUser(uid uint32) (sessions []dbus.ObjectPath, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSessionsForUser", 0, uid).Store(&sessions)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSystemIdleHint() (idle_hint bool, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSystemIdleHint", 0).Store(&idle_hint)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) GetSystemIdleSinceHint() (iso8601_datetime string, _err error) {
	_err = obj.core.Call("org.freedesktop.ConsoleKit.Manager.GetSystemIdleSinceHint", 0).Store(&iso8601_datetime)
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Manager) ConnectSeatAdded(callback func(sid dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Manager.SeatAdded" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(dbus.ObjectPath))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Manager) ConnectSeatRemoved(callback func(sid dbus.ObjectPath)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Manager.SeatRemoved" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*dbus.ObjectPath)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(dbus.ObjectPath))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

func (obj *Manager) ConnectSystemIdleHintChanged(callback func(hint bool)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "org.freedesktop.ConsoleKit.Manager.SystemIdleHintChanged" || 1 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*bool)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(bool))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

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

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Manager',sender='" + obj.DestName + "',member='SeatAdded'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Manager',sender='" + obj.DestName + "',member='SeatRemoved'")

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.ConsoleKit.Manager',sender='" + obj.DestName + "',member='SystemIdleHintChanged'")

	runtime.SetFinalizer(obj, func(_obj *Manager) { DestroyManager(_obj) })
	return obj, nil
}
