Beispiel #1
0
func (c *clock) Tick(t time.Time) error {
	c.t = t
	fmt.Printf("tick: %s\n", c.t.Format(c.format))

	buf := c.freeBuf()
	c.paint(buf, t)
	buf.busy = true

	if err := c.surface.Attach(buf.Id(), 0, 0); err != nil {
		return errgo.Trace(err)
	}
	if err := c.surface.Damage(0, 0, c.w, c.h); err != nil {
		return errgo.Trace(err)
	}

	//frame := c.wlc.NewCallback(c)
	//if err := c.surface.Frame(frame.Id()); err != nil {
	//    return errgo.Trace(err)
	//}

	if err := c.surface.Commit(); err != nil {
		return errgo.Trace(err)
	}

	if err := c.sync(); err != nil {
		return errgo.Trace(err)
	}

	return nil
}
Beispiel #2
0
func (c *clock) getRegistry() error {
	c.registry = c.wlc.NewRegistry(c)
	if err := c.display.GetRegistry(c.registry.Id()); err != nil {
		return errgo.Trace(err)
	}

	if err := c.sync(); err != nil {
		return errgo.Trace(err)
	}

	return nil
}
Beispiel #3
0
// NewAgentConfig returns a new config object suitable for use for a
// machine or unit agent.
func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error) {
	if configParams.DataDir == "" {
		return nil, errgo.Trace(requiredError("data directory"))
	}
	logDir := DefaultLogDir
	if configParams.LogDir != "" {
		logDir = configParams.LogDir
	}
	if configParams.Tag == "" {
		return nil, errgo.Trace(requiredError("entity tag"))
	}
	if configParams.UpgradedToVersion == version.Zero {
		return nil, errgo.Trace(requiredError("upgradedToVersion"))
	}
	if configParams.Password == "" {
		return nil, errgo.Trace(requiredError("password"))
	}
	if len(configParams.CACert) == 0 {
		return nil, errgo.Trace(requiredError("CA certificate"))
	}
	// Note that the password parts of the state and api information are
	// blank.  This is by design.
	config := &configInternal{
		logDir:            logDir,
		dataDir:           configParams.DataDir,
		jobs:              configParams.Jobs,
		upgradedToVersion: configParams.UpgradedToVersion,
		tag:               configParams.Tag,
		nonce:             configParams.Nonce,
		caCert:            configParams.CACert,
		oldPassword:       configParams.Password,
		values:            configParams.Values,
	}
	if len(configParams.StateAddresses) > 0 {
		config.stateDetails = &connectionDetails{
			addresses: configParams.StateAddresses,
		}
	}
	if len(configParams.APIAddresses) > 0 {
		config.apiDetails = &connectionDetails{
			addresses: configParams.APIAddresses,
		}
	}
	if err := config.check(); err != nil {
		return nil, err
	}
	if config.values == nil {
		config.values = make(map[string]string)
	}
	config.configFilePath = ConfigPath(config.dataDir, config.tag)
	return config, nil
}
Beispiel #4
0
func (c *clock) sync() error {
	cb := new(callback)
	scb := c.wlc.NewCallback(cb)
	if err := c.display.Sync(scb.Id()); err != nil {
		return errgo.Trace(err)
	}
	for !cb.done {
		if err := c.conn.Next(); err != nil {
			return errgo.Trace(err)
		}
	}
	return nil
}
Beispiel #5
0
func (c *clock) createSurface() error {
	g := c.compositorGlobal
	c.compositor = c.wlc.NewCompositor(c)
	if err := c.registry.Bind(g.Name, g.Interface, g.Version, c.compositor.Id()); err != nil {
		return errgo.Trace(err)
	}

	c.surface = c.wlc.NewSurface(c)
	if err := c.compositor.CreateSurface(c.surface.Id()); err != nil {
		return errgo.Trace(err)
	}
	if err := c.surface.Damage(0, 0, c.w, c.h); err != nil {
		return errgo.Trace(err)
	}

	g = c.xdgShellGlobal
	c.shell = c.xdgc.NewShell(c)
	if err := c.registry.Bind(g.Name, g.Interface, g.Version, c.shell.Id()); err != nil {
		return errgo.Trace(err)
	}
	if err := c.shell.UseUnstableVersion(3); err != nil {
		return errgo.Trace(err)
	}

	c.shellSurface = c.xdgc.NewSurface(c)
	if err := c.shell.GetXdgSurface(c.shellSurface.Id(), c.surface.Id()); err != nil {
		return errgo.Trace(err)
	}

	if err := c.shellSurface.SetTitle("clock"); err != nil {
		return errgo.Trace(err)
	}

	return nil
}
Beispiel #6
0
func checkAddrs(addrs []string, what string) error {
	if len(addrs) == 0 {
		return errgo.Trace(requiredError(what))
	}
	for _, a := range addrs {
		if !validAddr.MatchString(a) {
			return errgo.New("invalid %s %q", what, a)
		}
	}
	return nil
}
Beispiel #7
0
// NewStateMachineConfig returns a configuration suitable for
// a machine running the state server.
func NewStateMachineConfig(configParams AgentConfigParams, serverInfo params.StateServingInfo) (ConfigSetterWriter, error) {
	if serverInfo.Cert == "" {
		return nil, errgo.Trace(requiredError("state server cert"))
	}
	if serverInfo.PrivateKey == "" {
		return nil, errgo.Trace(requiredError("state server key"))
	}
	if serverInfo.StatePort == 0 {
		return nil, errgo.Trace(requiredError("state port"))
	}
	if serverInfo.APIPort == 0 {
		return nil, errgo.Trace(requiredError("api port"))
	}
	config, err := NewAgentConfig(configParams)
	if err != nil {
		return nil, err
	}
	config.SetStateServingInfo(serverInfo)
	return config, nil
}
Beispiel #8
0
func (c *configInternal) check() error {
	if c.stateDetails == nil && c.apiDetails == nil {
		return errgo.Trace(requiredError("state or API addresses"))
	}
	if c.stateDetails != nil {
		if err := checkAddrs(c.stateDetails.addresses, "state server address"); err != nil {
			return err
		}
	}
	if c.apiDetails != nil {
		if err := checkAddrs(c.apiDetails.addresses, "API server address"); err != nil {
			return err
		}
	}
	return nil
}
Beispiel #9
0
func (c *clock) createBuffers() error {
	g := c.shmGlobal
	c.shm = c.wlc.NewShm(c)
	if err := c.registry.Bind(g.Name, g.Interface, g.Version, c.shm.Id()); err != nil {
		return errgo.Trace(err)
	}

	// collect shm formats
	if err := c.sync(); err != nil {
		return errgo.Trace(err)
	}

	// allocate pool for 2 buffers
	poolSize := int32(len(c.buffers)) * c.bufSize

	shmO, err := shm.Open("clock", os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
	if err != nil {
		return errgo.Trace(err)
	}
	defer shmO.Close()
	if err := shmO.Truncate(int64(poolSize)); err != nil {
		return errgo.Trace(err)
	}

	if c.bufsMap, err = gommap.Map(shmO.Fd(), gommap.PROT_READ|gommap.PROT_WRITE, gommap.MAP_SHARED); err != nil {
		return errgo.Trace(err)
	}

	shmPool := c.wlc.NewShmPool(c)
	if err := c.shm.CreatePool(shmPool.Id(), shmO.Fd(), poolSize); err != nil {
		return errgo.Trace(err)
	}

	for i := range c.buffers {
		buf := new(buffer)
		buf.img.Rect = image.Rect(0, 0, int(c.w), int(c.h))
		buf.img.Stride = int(c.w) * 4
		buf.img.Pix = c.bufsMap[i*int(c.bufSize) : (i+1)*int(c.bufSize)]

		buf.ClientBuffer = c.wlc.NewBuffer(buf)
		if err := shmPool.CreateBuffer(
			buf.Id(),           // Id
			int32(i)*c.bufSize, // Offset
			c.w,                // Width
			c.h,                // Height
			c.stride,           // Stride
			0,                  // Format
		); err != nil {
			return errgo.Trace(err)
		}
		c.buffers[i] = buf
	}

	//if err := shmPool.Destroy(); err != nil {
	//    return errgo.Trace(err)
	//}

	if err := c.sync(); err != nil {
		return errgo.Trace(err)
	}

	return nil
}
Beispiel #10
0
// xdg_shell.Shell events
func (c *clock) Ping(serial uint32) error {
	if err := c.shell.Pong(serial); err != nil {
		return errgo.Trace(err)
	}
	return nil
}