Documentation
¶
Overview ¶
Package esbase is the shared platform for systems whose EmulationStation is Batocera's fork, which runs games and reports them through an HTTP API on localhost:1234.
Index ¶
- Constants
- Variables
- func CheckInstallPath(exe, want string) error
- func CheckRunningInstallPath(want string) error
- func HotkeygenControlNames() []string
- func HotkeygenControls(stop func() error) map[string]platforms.Control
- func HotkeygenExit(ctx context.Context) error
- func ValidProcessName(name string) bool
- type API
- type ESSystem
- type ESSystemConfig
- type ESSystemList
- type Options
- type Platform
- func (*Platform) ConsoleManager() platforms.ConsoleManager
- func (p *Platform) ForwardCmd(env *platforms.CmdEnv) (platforms.CmdResult, error)
- func (p *Platform) ID() string
- func (*Platform) InputCoverage() platforms.InputClass
- func (p *Platform) LaunchMedia(cfg *config.Instance, path string, launcher *platforms.Launcher, ...) error
- func (p *Platform) LaunchSystem(_ *config.Instance, systemID string) error
- func (p *Platform) Launchers(cfg *config.Instance) []platforms.Launcher
- func (*Platform) LookupMapping(_ *tokens.Token) (string, bool)
- func (p *Platform) ManagedByPackageManager() bool
- func (p *Platform) PresentUI(_ context.Context, event *models.UIEvent) (func() error, error)
- func (p *Platform) RefreshLauncherDependencies() error
- func (*Platform) RendersUIKind(kind models.UIEventKind) bool
- func (p *Platform) ReturnToMenu() error
- func (p *Platform) RootDirs(cfg *config.Instance) []string
- func (*Platform) ScanHook(_ *tokens.Token) error
- func (*Platform) Scrapers(cfg *config.Instance) map[string]platforms.Scraper
- func (*Platform) Screenshot() (*platforms.ScreenshotResult, error)
- func (p *Platform) SetTrackedProcess(proc *os.Process)
- func (p *Platform) Settings() platforms.Settings
- func (p *Platform) StartPost(_ context.Context, cfg *config.Instance, ...) error
- func (p *Platform) StartPre(cfg *config.Instance) error
- func (p *Platform) Stop() error
- func (p *Platform) StopActiveLauncher(reason platforms.StopIntent) error
- func (p *Platform) SupportedReaders(cfg *config.Instance) []readers.Reader
- func (p *Platform) UpdatePayload() []updatepayload.File
- func (*Platform) WatchInput(ctx context.Context, responsive bool, onActivity func()) error
- type ProcessKiller
- type ServiceInstaller
- func (s *ServiceInstaller) Install(ctx context.Context) error
- func (s *ServiceInstaller) InstallCommand(ctx context.Context, binaryPath string, out io.Writer) error
- func (s *ServiceInstaller) Uninstall(ctx context.Context) error
- func (s *ServiceInstaller) UninstallCommand(ctx context.Context, out io.Writer) error
Constants ¶
const ( // ESSystemsConfigFile is the main ES systems config file. ESSystemsConfigFile = "es_systems.cfg" // ESSystemsOverlayPattern is the glob pattern for overlay config files. ESSystemsOverlayPattern = "es_systems_*.cfg" )
Variables ¶
var ELECSystemAliases = map[string]string{
"amiga": "amiga500",
"atarijaguar": "jaguar",
"atarilynx": "lynx",
"bbcmicro": "bbc",
"coleco": "colecovision",
"famicom": "nes",
"fbn": "fbneo",
"gamegearh": "gamegear",
"gamepocketcomputer": "gamepock",
"gbah": "gba",
"gbav": "gba",
"gbch": "gbc",
"gbh": "gb",
"genesis": "megadrive",
"genh": "megadrive",
"ggh": "gamegear",
"laserdisc": "daphne",
"mac": "macintosh",
"megadrive-japan": "megadrive",
"megadriveh": "megadrive",
"moto": "thomson",
"msx": "msx1",
"ndsiware": "nds",
"neocd": "neogeocd",
"nesh": "nes",
"odyssey": "odyssey2",
"pc": "dos",
"pc-8800": "pc88",
"pc-9800": "pc98",
"pico-8": "pico8",
"pspminis": "psp",
"segacd": "megacd",
"sfc": "snes",
"sg-1000": "sg1000",
"sgfx": "supergrafx",
"snesh": "snes",
"snesmsu1": "snes-msu1",
"tg16": "pcengine",
"tg16cd": "pcenginecd",
"tic-80": "tic80",
"vic20": "c20",
"videopac": "odyssey2",
"wasm-4": "wasm4",
"wiiware": "wii",
"wonderswan": "wswan",
"wonderswancolor": "wswanc",
}
ELECSystemAliases maps the EmulationStation system names and ROM folders ROCKNIX and AmberELEC share, from their common 351ELEC lineage, to the ES-DE folders for the same systems. Systems with no ES-DE counterpart, and non-game systems, are left out.
var ErrNoProcessNames = errors.New("no process names to kill")
ErrNoProcessNames means a kill was asked for nothing at all.
Functions ¶
func CheckInstallPath ¶
CheckInstallPath refuses to install a service that would start a binary other than exe. Both paths are compared after resolving symlinks.
func CheckRunningInstallPath ¶
CheckRunningInstallPath is CheckInstallPath for the running binary.
func HotkeygenControlNames ¶
func HotkeygenControlNames() []string
HotkeygenControlNames lists the controls HotkeygenControls defines, for Options.ControlNames.
func HotkeygenControls ¶
HotkeygenControls builds the system launcher controls around hotkeygen, for Options.Controls.
func HotkeygenExit ¶
HotkeygenExit sends the universal exit signal through hotkeygen, the recommended way to exit games and emulators where hotkeygen runs.
func ValidProcessName ¶
ValidProcessName reports whether name is a bare process name, as killall takes one: no path, no whitespace, no option, nothing else.
Types ¶
type API ¶
type API interface {
RunningGame() (esapi.RunningGameResponse, bool, error)
EmuKill() error
Launch(path string) error
Notify(msg string) error
GameKnown(systemName, path string) (bool, error)
ReloadGames() error
}
API is the part of EmulationStation's HTTP API the platform uses.
type ESSystem ¶
type ESSystem struct {
Name string `xml:"name"`
Path string `xml:"path"`
Extension string `xml:"extension"`
}
ESSystem represents a single system entry from es_systems.cfg.
func (ESSystem) ParseExtensions ¶
ParseExtensions splits the space-separated extension string from ES config into a deduplicated slice of extensions. Each extension is normalized to lowercase with a leading dot.
type ESSystemConfig ¶
type ESSystemConfig struct {
// Systems maps system name to its configuration.
Systems map[string]ESSystem
}
ESSystemConfig holds parsed ES system configuration.
func ParseESSystemsConfig ¶
func ParseESSystemsConfig(configDir string) (*ESSystemConfig, error)
ParseESSystemsConfig parses EmulationStation config files and returns discovered system configurations. It reads the main config file and any overlay files (es_systems_*.cfg).
func (*ESSystemConfig) GetROMPaths ¶
func (c *ESSystemConfig) GetROMPaths(relativeRoot string, skip ...string) []string
GetROMPaths returns deduplicated ROM paths from parsed ES config. Paths are expanded (environment variables resolved) and normalized. Systems named in skip are left out.
type ESSystemList ¶
ESSystemList is the root element of es_systems.cfg.
type Options ¶
type Options struct {
// API reaches EmulationStation. Nil uses its HTTP API on localhost:1234.
API API
// ExcludedSystems are ES-DE folders this system's EmulationStation has
// no system for. A game indexed there cannot be started: ES's launch API
// does nothing for it, while Core reports the launch as done.
ExcludedSystems map[string]struct{}
// HasKodi reports whether Kodi is installed. Nil means it always is.
// Without Kodi the Kodi launchers are left out.
HasKodi func() bool
// SystemAliases maps this system's EmulationStation system names and
// ROM folder names to the ES-DE folder that describes the same system,
// for names ES-DE spells differently.
SystemAliases map[string]string
// NonGameSystems are EmulationStation systems that hold tools, music
// or screenshots rather than games. Their paths are not ROM roots.
NonGameSystems []string
// UpdatePayload lists the platform-owned files an update installs.
UpdatePayload func() []updatepayload.File
// ManagedByPackageManager reports whether a package manager owns this
// install. Nil means it never does.
ManagedByPackageManager func() bool
// ExitGame asks the running game to exit before the stop falls back to
// KillGame. Nil skips straight to KillGame.
ExitGame func(ctx context.Context) error
// KillGame is the fallback a stop repeats while EmulationStation still
// reports a game. Nil uses EmulationStation's /emukill.
KillGame func() error
// Controls builds the controls of every EmulationStation system launcher
// around stop. Nil offers only stop.
Controls func(stop func() error) map[string]platforms.Control
// ControlNames lists the controls Controls defines, for games the
// tracker finds running. Nil lists only stop.
ControlNames func() []string
// ID is the platform ID.
ID string
// DataDir, ConfigDir and LogDir are hardcoded because the service may
// start before HOME is set.
DataDir string
ConfigDir string
LogDir string
// DefaultROMRoot is always indexed, and relative ES system paths resolve
// against it.
DefaultROMRoot string
// ESConfigDirs hold es_systems.cfg and es_systems_*.cfg overlays, read
// in order so a later directory overrides an earlier one.
ESConfigDirs []string
// KillRetryDelay is how long a stop waits between KillGame attempts.
KillRetryDelay time.Duration
// OnlyESSystems leaves out ES-DE folders that no system in the parsed
// ES config uses, for systems whose ES system list varies by device.
// It has no effect when no ES config could be read.
OnlyESSystems bool
}
Options describes how one operating system differs from the others that run Batocera's EmulationStation.
type Platform ¶
type Platform struct {
shared.InputManager
// contains filtered or unexported fields
}
Platform is a platform built on Batocera's EmulationStation. Build it with New; the options decide what differs between operating systems.
func (*Platform) ConsoleManager ¶
func (*Platform) ConsoleManager() platforms.ConsoleManager
func (*Platform) ForwardCmd ¶
func (*Platform) InputCoverage ¶
func (*Platform) InputCoverage() platforms.InputClass
InputCoverage implements platforms.InputActivitySource.
func (*Platform) LaunchMedia ¶
func (*Platform) LaunchSystem ¶
func (*Platform) ManagedByPackageManager ¶
func (*Platform) RefreshLauncherDependencies ¶
RefreshLauncherDependencies invalidates external EmulationStation config so the following launcher rebuild reparses current system paths and extensions.
func (*Platform) RendersUIKind ¶
func (*Platform) RendersUIKind(kind models.UIEventKind) bool
RendersUIKind reports the events PresentUI can show: only notices and loaders, which are shown as EmulationStation notifications.
func (*Platform) ReturnToMenu ¶
func (*Platform) Screenshot ¶
func (*Platform) Screenshot() (*platforms.ScreenshotResult, error)
func (*Platform) SetTrackedProcess ¶
func (*Platform) StopActiveLauncher ¶
func (p *Platform) StopActiveLauncher(reason platforms.StopIntent) error
func (*Platform) SupportedReaders ¶
func (*Platform) UpdatePayload ¶
func (p *Platform) UpdatePayload() []updatepayload.File
type ProcessKiller ¶
type ProcessKiller struct {
FS afero.Fs
Clock clockwork.Clock
Signal func(pid int, sig syscall.Signal) error
// ProcPath is where processes are listed, normally /proc.
ProcPath string
Grace time.Duration
Poll time.Duration
// SelfPID is never signalled.
SelfPID int
}
ProcessKiller ends processes by name as killall does: SIGTERM, then SIGKILL for any still alive once the grace period or the caller's context runs out.
func NewProcessKiller ¶
func NewProcessKiller() *ProcessKiller
NewProcessKiller returns a killer for this system's processes.
type ServiceInstaller ¶
type ServiceInstaller struct {
FS afero.Fs
Cmd command.Executor
// Path is where the service file goes, and Content what it holds.
Path string
Content string
// Stop runs before Enable so a reinstall replaces a running service
// instead of leaving the old binary up; failures are ignored because the
// service may not be running.
Stop [][]string
// Enable runs in order after the file is written; each must succeed.
Enable [][]string
// Disable runs before the file is removed; failures are ignored because
// the service may not be running or registered.
Disable [][]string
// Reload runs after the file is removed.
Reload [][]string
Mode os.FileMode
}
ServiceInstaller writes the file that starts Core with the system and registers it with the system's service manager.
func SystemdUnitInstaller ¶
func SystemdUnitInstaller(path, name, unit string) *ServiceInstaller
SystemdUnitInstaller installs unit as a system service named name at path, enabled and (re)started so a reinstall runs the new binary.
func (*ServiceInstaller) Install ¶
func (s *ServiceInstaller) Install(ctx context.Context) error
Install writes the service file and enables it. When enabling fails, a service this call created is removed again, while one that was already installed gets its previous file back rather than being removed.
func (*ServiceInstaller) InstallCommand ¶
func (s *ServiceInstaller) InstallCommand(ctx context.Context, binaryPath string, out io.Writer) error
InstallCommand runs the -install flag: it installs the service when the running binary is binaryPath, the one the service starts, and tells the user on out.
func (*ServiceInstaller) Uninstall ¶
func (s *ServiceInstaller) Uninstall(ctx context.Context) error
Uninstall disables the service and removes its file.
func (*ServiceInstaller) UninstallCommand ¶
UninstallCommand runs the -uninstall flag and tells the user on out.