Example #1
0
func NewSessionBus() (*Connection, os.Error){
	bus := new(Connection)
	bus.path = os.Getenv("DBUS_SESSION_BUS_ADDRESS")

	var re *regexp.Regexp
	re, _ = regexp.Compile("^unix:abstract=(.*),guid=(.*)")

	m := re.ExecuteString(bus.path)
	if nil != m {
		abPath := bus.path[m[2]:m[3]] // get regexp 1st group
		addr, _ := net.ResolveUnixAddr("unix", "\x00"+abPath)
		conn, err := net.DialUnix("unix", nil, addr)
		if err != nil{
			return nil, err
		}
		bus.conn = conn
		return bus,nil
	}

	return nil, os.NewError("NewSessionBus Failed")
}