diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt
index 7f5560e..ce62f84 100644
--- a/base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt
+++ b/base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt
@@ -22,11 +22,13 @@ package de.staropensource.engine.base
import de.staropensource.engine.base.exception.EngineInitializationFailureException
import de.staropensource.engine.base.implementable.Subsystem
import de.staropensource.engine.base.logging.Logger
+import de.staropensource.engine.base.platform.platformEngineBootstrap
+import de.staropensource.engine.base.platform.platformEngineInitialize
+import de.staropensource.engine.base.platform.platformEngineReload
+import de.staropensource.engine.base.platform.platformEngineShutdown
import de.staropensource.engine.base.utility.Environment
import de.staropensource.engine.base.utility.FileAccess
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
-import java.nio.charset.Charset
-import java.nio.charset.StandardCharsets
import kotlin.jvm.JvmStatic
import kotlin.reflect.KClass
@@ -186,9 +188,7 @@ class Engine private constructor() {
logger.info("Bootstrapping")
// Run bootstrapping code
- // -> Run checks
- if (Charset.defaultCharset() != StandardCharsets.UTF_8)
- logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8")
+ platformEngineBootstrap()
// Bootstrap subsystems
logger.verb("Bootstrapping subsystems")
@@ -243,6 +243,7 @@ class Engine private constructor() {
logger.info("Initializing")
// Run initialization code
+ platformEngineInitialize()
Environment.detect()
FileAccess.updateDefaultPaths()
info = BuildInformation(loadPrefix = "sosengine-base")
@@ -303,7 +304,7 @@ class Engine private constructor() {
logger.info("Reloading")
// Run reload code
- // *none yet*
+ platformEngineReload()
// Reload subsystems
logger.verb("Reloading subsystems")
@@ -399,13 +400,7 @@ class Engine private constructor() {
state = State.SHUTTING_DOWN
val infoLocal: BuildInformation? = info
- // Run shutdown code
- Environment.unset()
- FileAccess.deleteScheduled()
- FileAccess.unsetDefaultPaths()
- info = null
-
- // Initialize subsystems
+ // Shut subsystems down
logger.verb("Shutting subsystems down")
for (subsystem: Subsystem in subsystems) {
val subsystemVersion: String = subsystem.getVersion()
@@ -422,6 +417,13 @@ class Engine private constructor() {
}
}
+ // Run shutdown code
+ Environment.unset()
+ FileAccess.deleteScheduled()
+ FileAccess.unsetDefaultPaths()
+ info = null
+ platformEngineShutdown(final, crashed)
+
// Print shutdown message
if (final)
logger.info("""
diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/EnginePlatform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/EnginePlatform.kt
new file mode 100644
index 0000000..c2dea57
--- /dev/null
+++ b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/EnginePlatform.kt
@@ -0,0 +1,70 @@
+/*
+ * STAROPENSOURCE ENGINE SOURCE FILE
+ * Copyright (c) 2024 The StarOpenSource Engine Authors
+ * Licensed under the GNU General Public License v3.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.staropensource.engine.base.platform
+
+import de.staropensource.engine.base.Engine
+
+/**
+ * Bootstraps this platform.
+ *
+ * Invoked by [Engine.bootstrap] first.
+ *
+ * @throws Throwable on error
+ * @since v1-alpha10
+ */
+@Throws(Throwable::class)
+expect fun platformEngineBootstrap()
+
+/**
+ * Initializes this platform.
+ *
+ * Invoked by [Engine.initialize] first.
+ *
+ * @throws Throwable on error
+ * @since v1-alpha10
+ */
+@Throws(Throwable::class)
+expect fun platformEngineInitialize()
+
+/**
+ * Reloads this platform.
+ *
+ * Invoked by [Engine.reload] first.
+ *
+ * @throws Throwable on error
+ * @since v1-alpha10
+ */
+@Throws(Throwable::class)
+expect fun platformEngineReload()
+
+/**
+ * Shuts this platform down.
+ *
+ * Invoked by one of the
+ * engine's shutdown methods
+ * last.
+ *
+ * @param final whether this is the last time the engine shuts down. Doesn't actually shut the application down, just changes some messages and does other things
+ * @param crashed enables super careful mode to prevent further breakage
+ * @throws Throwable on error
+ * @since v1-alpha10
+ */
+@Throws(Throwable::class)
+expect fun platformEngineShutdown(final: Boolean, crashed: Boolean = false)
diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/EnginePlatformImpl.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/EnginePlatformImpl.kt
new file mode 100644
index 0000000..648051c
--- /dev/null
+++ b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/EnginePlatformImpl.kt
@@ -0,0 +1,37 @@
+/*
+ * STAROPENSOURCE ENGINE SOURCE FILE
+ * Copyright (c) 2024 The StarOpenSource Engine Authors
+ * Licensed under the GNU General Public License v3.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.staropensource.engine.base.platform
+
+import de.staropensource.engine.base.Engine.Companion.logger
+import java.nio.charset.Charset
+import java.nio.charset.StandardCharsets
+
+@Throws(Throwable::class)
+actual fun platformEngineBootstrap() {
+ if (Charset.defaultCharset() != StandardCharsets.UTF_8)
+ logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8")
+}
+
+@Throws(Throwable::class)
+actual fun platformEngineInitialize() = Unit
+@Throws(Throwable::class)
+actual fun platformEngineReload() = Unit
+@Throws(Throwable::class)
+actual fun platformEngineShutdown(final: Boolean, crashed: Boolean) = Unit