state

package
v0.0.0-...-bb2c1c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package state is where all the logic happens. There is a global state that is updated when events are received, and in response it gives command to execute to the platforms. Those commands can be to change the local filesystem, to change the remote Cozy, or for controls (exit for example).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sync

func Sync(platform Platform) error

Sync is the event loop to update the state and send commands, via the platform.

Types

type CmdChanges

type CmdChanges struct {
	Limit       int
	Seq         *remote.Seq
	SkipTrashed bool
}

CmdChanges is a command to fetch the changes feed of the Cozy.

func (CmdChanges) Exec

func (cmd CmdChanges) Exec(platform Platform)

Exec is required by Command interface.

type CmdCreateDir

type CmdCreateDir struct {
	ParentID     remote.ID
	Name         string
	LocalID      local.ID
	ParentLinkID common.ID
}

CmdCreateDir is a command for creating a directory on the Cozy.

func (CmdCreateDir) Exec

func (cmd CmdCreateDir) Exec(platform Platform)

Exec is required by Command interface.

type CmdMkdir

type CmdMkdir struct {
	Path         string
	RemoteID     remote.ID
	ParentLinkID common.ID
}

CmdMkdir is a command for creating a directory on the local file system.

func (CmdMkdir) Exec

func (cmd CmdMkdir) Exec(platform Platform)

Exec is required by Command interface.

type CmdRefreshToken

type CmdRefreshToken struct {
	Clock types.Clock
}

CmdRefreshToken is a command to refresh the access token of the OAuth client.

func (CmdRefreshToken) Exec

func (cmd CmdRefreshToken) Exec(platform Platform)

Exec is required by Command interface.

type CmdScan

type CmdScan struct {
	Path string
}

CmdScan is a command to list files and directories inside a directory.

func (CmdScan) Exec

func (cmd CmdScan) Exec(platform Platform)

Exec is required by Command interface.

type CmdStat

type CmdStat struct {
	Path string
}

CmdStat is a command for making a stat call on a file. It allows to know if it is a file or a directory, the size, the inode number, etc.

func (CmdStat) Exec

func (cmd CmdStat) Exec(platform Platform)

Exec is required by Command interface.

type CmdStop

type CmdStop struct{}

CmdStop is a command for stopping the client.

func (CmdStop) Exec

func (cmd CmdStop) Exec(platform Platform)

Exec is required by Command interface.

type CmdSynchronized

type CmdSynchronized struct {
	Clock types.Clock
}

CmdSynchronized is a command to let the Cozy know that the client has reach a stable point of synchronization.

func (CmdSynchronized) Exec

func (cmd CmdSynchronized) Exec(platform Platform)

Exec is required by Command interface.

type Command

type Command interface {
	Exec(platform Platform)
}

Command is used to ask the local filesystem or the remote Cozy to execute things.

type Event

type Event interface {
	Update(state *State) []Command
}

Event is a way to give information to update the state when a change happens on the local filesystem or the remote Cozy.

type EventChangesDone

type EventChangesDone struct {
	Cmd     CmdChanges
	Docs    []*remote.ChangedDoc
	Seq     *remote.Seq
	Pending int
	Error   error
}

EventChangesDone is used to notify of the result of the changes feed.

func (EventChangesDone) Update

func (e EventChangesDone) Update(state *State) []Command

Update is required by Event interface.

type EventCreateDirDone

type EventCreateDirDone struct {
	Cmd   CmdCreateDir
	Doc   *remote.Doc
	Error error
}

EventCreateDirDone is notified when a directory has been by the desktop client on the Cozy.

func (EventCreateDirDone) Update

func (e EventCreateDirDone) Update(state *State) []Command

Update is required by Event interface.

type EventMkdirDone

type EventMkdirDone struct {
	Cmd   CmdMkdir
	Info  fs.FileInfo
	Error error
}

EventMkdirDone is notified when a directory has been by the desktop client on the local file system.

func (EventMkdirDone) Update

func (e EventMkdirDone) Update(state *State) []Command

Update is required by Event interface.

type EventScanDone

type EventScanDone struct {
	Cmd     CmdScan
	Path    string
	Entries []fs.DirEntry
	Error   error
}

EventScanDone is notified after the scan has been done to send back the result, a list of DirEntry.

func (EventScanDone) Update

func (e EventScanDone) Update(state *State) []Command

Update is required by Event interface.

type EventStart

type EventStart struct{}

EventStart is used to starts the client.

func (EventStart) Update

func (e EventStart) Update(state *State) []Command

Update is required by Event interface.

type EventStatDone

type EventStatDone struct {
	Cmd   CmdStat
	Info  fs.FileInfo
	Error error
}

EventStatDone is an event notified after a stat call was made to send back the result.

func (EventStatDone) Update

func (e EventStatDone) Update(state *State) []Command

Update is required by Event interface.

type EventSynchronized

type EventSynchronized struct {
	Cmd   CmdSynchronized
	Error error
}

EventSynchronized is notified when the Cozy has been informed of the synchronization, or the call has failed.

func (EventSynchronized) Update

func (e EventSynchronized) Update(state *State) []Command

Update is required by Event interface.

type EventTokenRefreshed

type EventTokenRefreshed struct {
	Cmd   CmdRefreshToken
	Error error
}

EventTokenRefreshed is notified when the access token has been refreshed, or when the attempt has failed.

func (EventTokenRefreshed) Update

func (e EventTokenRefreshed) Update(state *State) []Command

Update is required by Event interface.

type Platform

type Platform interface {
	FS() local.FS
	Client() remote.Client
	Notify(event Event)
	NextEvent() Event
	Exec(cmd Command)
}

Platform is used as a way to plug a local.FS and remote.Client. They can execute commands and send events via the platform.

type State

type State struct {
	Links *common.Links
	Nodes *local.Nodes
	Docs  *remote.Docs
	Clock types.Clock
}

State is the global state of the client. It is updated with the information from the notified events. And the decisions to which commands to send is based on this state.

Directories

Path Synopsis
Package types is just for sharing some basic types between packages without introducing a loop of imports.
Package types is just for sharing some basic types between packages without introducing a loop of imports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL