esbase

package
v2.23.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: GPL-3.0 Imports: 57 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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.

View Source
var ErrNoProcessNames = errors.New("no process names to kill")

ErrNoProcessNames means a kill was asked for nothing at all.

Functions

func CheckInstallPath

func CheckInstallPath(exe, want string) error

CheckInstallPath refuses to install a service that would start a binary other than exe. Both paths are compared after resolving symlinks.

func CheckRunningInstallPath

func CheckRunningInstallPath(want string) error

CheckRunningInstallPath is CheckInstallPath for the running binary.

func HotkeygenControlNames

func HotkeygenControlNames() []string

HotkeygenControlNames lists the controls HotkeygenControls defines, for Options.ControlNames.

func HotkeygenControls

func HotkeygenControls(stop func() error) map[string]platforms.Control

HotkeygenControls builds the system launcher controls around hotkeygen, for Options.Controls.

func HotkeygenExit

func HotkeygenExit(ctx context.Context) error

HotkeygenExit sends the universal exit signal through hotkeygen, the recommended way to exit games and emulators where hotkeygen runs.

func ValidProcessName

func ValidProcessName(name string) bool

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

func (s ESSystem) ParseExtensions() []string

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

type ESSystemList struct {
	XMLName xml.Name   `xml:"systemList"`
	Systems []ESSystem `xml:"system"`
}

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 New

func New(opts *Options) *Platform

New returns a platform for the operating system opts describes.

func (*Platform) ConsoleManager

func (*Platform) ConsoleManager() platforms.ConsoleManager

func (*Platform) ForwardCmd

func (p *Platform) ForwardCmd(env *platforms.CmdEnv) (platforms.CmdResult, error)

func (*Platform) ID

func (p *Platform) ID() string

func (*Platform) InputCoverage

func (*Platform) InputCoverage() platforms.InputClass

InputCoverage implements platforms.InputActivitySource.

func (*Platform) LaunchMedia

func (p *Platform) LaunchMedia(
	cfg *config.Instance, path string, launcher *platforms.Launcher, db *database.Database,
	opts *platforms.LaunchOptions,
) error

func (*Platform) LaunchSystem

func (p *Platform) LaunchSystem(_ *config.Instance, systemID string) error

func (*Platform) Launchers

func (p *Platform) Launchers(cfg *config.Instance) []platforms.Launcher

func (*Platform) LookupMapping

func (*Platform) LookupMapping(_ *tokens.Token) (string, bool)

func (*Platform) ManagedByPackageManager

func (p *Platform) ManagedByPackageManager() bool

func (*Platform) PresentUI

func (p *Platform) PresentUI(
	_ context.Context,
	event *models.UIEvent,
) (func() error, error)

func (*Platform) RefreshLauncherDependencies

func (p *Platform) RefreshLauncherDependencies() error

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 (p *Platform) ReturnToMenu() error

func (*Platform) RootDirs

func (p *Platform) RootDirs(cfg *config.Instance) []string

func (*Platform) ScanHook

func (*Platform) ScanHook(_ *tokens.Token) error

func (*Platform) Scrapers

func (*Platform) Scrapers(cfg *config.Instance) map[string]platforms.Scraper

func (*Platform) Screenshot

func (*Platform) Screenshot() (*platforms.ScreenshotResult, error)

func (*Platform) SetTrackedProcess

func (p *Platform) SetTrackedProcess(proc *os.Process)

func (*Platform) Settings

func (p *Platform) Settings() platforms.Settings

func (*Platform) StartPost

func (p *Platform) StartPost(
	_ context.Context,
	cfg *config.Instance,
	launcherManager platforms.LauncherContextManager,
	activeMedia func() *models.ActiveMedia,
	setActiveMedia func(*models.ActiveMedia),
	_ *database.Database,
	_ *idle.Scheduler,
) error

func (*Platform) StartPre

func (p *Platform) StartPre(cfg *config.Instance) error

func (*Platform) Stop

func (p *Platform) Stop() error

func (*Platform) StopActiveLauncher

func (p *Platform) StopActiveLauncher(reason platforms.StopIntent) error

func (*Platform) SupportedReaders

func (p *Platform) SupportedReaders(cfg *config.Instance) []readers.Reader

func (*Platform) UpdatePayload

func (p *Platform) UpdatePayload() []updatepayload.File

func (*Platform) WatchInput

func (*Platform) WatchInput(ctx context.Context, responsive bool, onActivity func()) error

WatchInput implements platforms.InputActivitySource.

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.

func (*ProcessKiller) Kill

func (k *ProcessKiller) Kill(ctx context.Context, names []string) (int, error)

Kill ends every process called one of names and reports how many it signalled. Invalid names are skipped.

func (*ProcessKiller) KillNow

func (k *ProcessKiller) KillNow(names []string) (int, error)

KillNow sends SIGKILL to every process called one of names, as killall -9 does, and reports how many it signalled. Invalid names are skipped.

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

func (s *ServiceInstaller) UninstallCommand(ctx context.Context, out io.Writer) error

UninstallCommand runs the -uninstall flag and tells the user on out.

Jump to

Keyboard shortcuts

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