Rollback multiplatform commits
This commit reverts the following commits: -06b279e8b6
-a5a7b8841c
-bf992bf6c5
-00747f3707
-528e6ca388
-e8535cd25a
-36da65b45e
-a1e843f61e
This commit is contained in:
parent
06748dcdf1
commit
ebe2a85444
127 changed files with 1067 additions and 1922 deletions
|
@ -17,12 +17,8 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
kotlin {
|
||||
// Dependencies
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
// sos!engine
|
||||
implementation(project(":base"))
|
||||
}
|
||||
}
|
||||
// Dependencies
|
||||
dependencies {
|
||||
// sos!engine
|
||||
implementation(project(":base"))
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package de.staropensource.engine.ansi
|
|||
|
||||
import de.staropensource.engine.ansi.AnsiSubsystem.Companion.logger
|
||||
import de.staropensource.engine.base.implementable.formatter.TwoCycleFormatterImpl
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Formats a string using ANSI
|
|
@ -24,7 +24,6 @@ import de.staropensource.engine.base.implementable.Subsystem
|
|||
import de.staropensource.engine.base.logging.Logger
|
||||
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* The ANSI subsystem.
|
|
@ -17,12 +17,8 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
kotlin {
|
||||
// Dependencies
|
||||
sourceSets {
|
||||
jvmMain.dependencies {
|
||||
// OSHI
|
||||
implementation("${property("dependencyOshiIdentifier") as String}:${property("dependencyOshiVersion") as String}")
|
||||
}
|
||||
}
|
||||
// Dependencies
|
||||
dependencies {
|
||||
// OSHI
|
||||
implementation("${property("dependencyOshiIdentifier") as String}:${property("dependencyOshiVersion") as String}")
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
/**
|
||||
* Interface for platform-specific data.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@ApiStatus.NonExtendable
|
||||
interface PlatformData {
|
||||
/**
|
||||
* Contains platform-specific data.
|
||||
*
|
||||
* **DO NOT VIEW OR MODIFY.**
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
val platformData: MutableMap<String, Any?>
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
|
||||
/**
|
||||
* Bootstraps this platform.
|
||||
*
|
||||
* Invoked by [de.staropensource.engine.base.Engine.bootstrap] first.
|
||||
*
|
||||
* @throws Throwable on error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(Throwable::class)
|
||||
expect fun platformEngineBootstrap()
|
||||
|
||||
/**
|
||||
* Initializes this platform.
|
||||
*
|
||||
* Invoked by [de.staropensource.engine.base.Engine.initialize] first.
|
||||
*
|
||||
* @throws Throwable on error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(Throwable::class)
|
||||
expect fun platformEngineInitialize()
|
||||
|
||||
/**
|
||||
* Reloads this platform.
|
||||
*
|
||||
* Invoked by [de.staropensource.engine.base.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)
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
/**
|
||||
* Terminates the platform.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformTerminate(exitcode: UByte)
|
||||
|
||||
/**
|
||||
* Returns the time in milliseconds.
|
||||
*
|
||||
* Should only be used for
|
||||
* comparing time intervals.
|
||||
* **Should not be stored as
|
||||
* this method may return a
|
||||
* timestamp from platform
|
||||
* to platform.**
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformMilliseconds(): ULong
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
import de.staropensource.engine.base.implementable.stream.ReadStream
|
||||
import de.staropensource.engine.base.implementable.stream.WriteStream
|
||||
import de.staropensource.engine.base.utility.Process
|
||||
|
||||
/**
|
||||
* Platform-specific implementation of [Process].
|
||||
*
|
||||
* @constructor Initializes this platform implementation
|
||||
* @param process [Process] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract class ProcessPlatform (
|
||||
val process: Process
|
||||
) {
|
||||
// -----> Lifecycle
|
||||
/**
|
||||
* Initializes the process.
|
||||
*
|
||||
* @throws Throwable on error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(Throwable::class)
|
||||
abstract fun start()
|
||||
|
||||
/**
|
||||
* Kills the process.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract fun kill()
|
||||
|
||||
|
||||
// -----> Getters
|
||||
abstract fun isAlive(): Boolean
|
||||
abstract fun getPid(): Long
|
||||
abstract fun getExitCode(): UByte?
|
||||
|
||||
|
||||
// -----> Stream getters
|
||||
/**
|
||||
* Returns the standard input stream.
|
||||
*
|
||||
* @return standard input stream
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract fun getStandardInput(): WriteStream
|
||||
|
||||
/**
|
||||
* Returns the standard output stream.
|
||||
*
|
||||
* @return standard output stream
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract fun getStandardOutput(): ReadStream
|
||||
|
||||
/**
|
||||
* Returns the standard error stream.
|
||||
*
|
||||
* @return standard error stream
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract fun getStandardError(): ReadStream
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [ProcessPlatform] implementation
|
||||
* for the supplied [Process] instance.
|
||||
*
|
||||
* @param process [Process] instance
|
||||
* @return matching [ProcessPlatform] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformProcessCreate(process: Process): ProcessPlatform
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
import de.staropensource.engine.base.implementable.stream.ReadStream
|
||||
import de.staropensource.engine.base.implementable.stream.Stream
|
||||
import de.staropensource.engine.base.implementable.stream.WriteStream
|
||||
|
||||
/**
|
||||
* Platform-specific implementation of [Stream].
|
||||
*
|
||||
* @constructor Initializes this platform implementation
|
||||
* @param stream [Stream] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract class StreamPlatform(
|
||||
val stream: Stream
|
||||
) {
|
||||
/**
|
||||
* Starts a watching thread for the specified stream.
|
||||
*
|
||||
* @param stream [Stream] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
abstract fun startWatchingThread()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [StreamPlatform] implementation
|
||||
* for the supplied [Stream] instance.
|
||||
*
|
||||
* @param stream [Stream] instance
|
||||
* @return matching [StreamPlatform] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformStreamCreate(stream: Stream): StreamPlatform
|
||||
|
||||
/**
|
||||
* Returns a [ReadStream] representing
|
||||
* the standard input of the current
|
||||
* process.
|
||||
*
|
||||
* @return [ReadStream] instance representing the standard input
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformStreamStandardInput(): ReadStream
|
||||
|
||||
/**
|
||||
* Returns a [WriteStream] representing
|
||||
* the standard output of the current
|
||||
* process.
|
||||
*
|
||||
* @return [WriteStream] instance representing the standard output
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformStreamStandardOutput(): WriteStream
|
||||
|
||||
/**
|
||||
* Returns a [WriteStream] representing
|
||||
* the standard error of the current
|
||||
* process.
|
||||
*
|
||||
* @return [WriteStream] instance representing the standard error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
internal expect fun platformStreamStandardError(): WriteStream
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Platform-specific implementations
|
||||
* and helper classes.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
package de.staropensource.engine.base.platform
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type.environment
|
||||
|
||||
/**
|
||||
* Represents a graphics card.
|
||||
*
|
||||
* @constructor Initializes this class
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class GraphicsCard internal constructor(
|
||||
val name: String,
|
||||
val deviceIdentifier: String,
|
||||
val manufacturer: String,
|
||||
val version: String,
|
||||
val videoMemory: ULong,
|
||||
)
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type.environment
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
|
||||
/**
|
||||
* Represents all operating systems
|
||||
* detected and supported by the engine.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
enum class OperatingSystem {
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [Linux](https://kernel.org) kernel
|
||||
* on some kind of Linux distribution.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
LINUX,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [FreeBSD](https://freebsd.org) kernel
|
||||
* and likely the FreeBSD operating system.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
FREEBSD,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [NetBSD](https://netbsd.org) kernel
|
||||
* and likely the NetBSD operating system.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
NETBSD,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [OpenBSD](https://openbsd.org) kernel
|
||||
* and likely the OpenBSD operating system.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
OPENBSD,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under [Android](https://android.com), and
|
||||
* by extension the [Linux kernel](https://kernel.org).
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
ANDROID,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under [Windows](https://windows.com), and
|
||||
* by extension the [Windows NT kernel](https://en.wikipedia.org/wiki/Ntoskrnl.exe).
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
WINDOWS,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under [macOS](https://apple.com/macos), and
|
||||
* by extension under the [XNU kernel](https://github.com/apple-oss-distributions/xnu).
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
MACOS;
|
||||
|
||||
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.utility." else ""}Environment\$OperatingSystem.${name}"
|
||||
|
||||
/**
|
||||
* Returns the human-friendly name
|
||||
* of this operating system.
|
||||
*
|
||||
* @return human-friendly name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun humanFriendly(): String = when (this) {
|
||||
LINUX -> "Linux"
|
||||
FREEBSD -> "FreeBSD"
|
||||
NETBSD -> "NetBSD"
|
||||
OPENBSD -> "OpenBSD"
|
||||
ANDROID -> "Android"
|
||||
WINDOWS -> "Windows"
|
||||
MACOS -> "macOS"
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data types returned by [Environment].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
package de.staropensource.engine.base.type.environment
|
||||
|
||||
import de.staropensource.engine.base.utility.Environment
|
|
@ -1,336 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility
|
||||
|
||||
import de.staropensource.engine.base.type.environment.GraphicsCard
|
||||
import de.staropensource.engine.base.type.environment.OperatingSystem
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Provides information about the
|
||||
* environment the application runs in.
|
||||
*
|
||||
* @constructor Initializes this class
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Suppress("Unused", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
expect class Environment private constructor() {
|
||||
/**
|
||||
* Companion class of [Environment].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
companion object {
|
||||
// -----> Update methods
|
||||
/**
|
||||
* Unsets the environment.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
internal fun unset()
|
||||
|
||||
/**
|
||||
* Detects and updates the environment.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
internal fun detect()
|
||||
|
||||
|
||||
// -----> Getters
|
||||
// -------> General
|
||||
/**
|
||||
* Returns the amount of
|
||||
* bits this platform targets.
|
||||
*
|
||||
* This may be 32, 64 or an
|
||||
* even higher value.
|
||||
*
|
||||
* @return maximum of supported bits
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getOperatingSystem(): OperatingSystem?
|
||||
|
||||
/**
|
||||
* Returns the point in time where
|
||||
* the system the engine is
|
||||
* running on has started.
|
||||
*
|
||||
* @return time of system startup
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getTimeOfStartup(): Instant?
|
||||
|
||||
/**
|
||||
* Returns whether the current process
|
||||
* is elevated and is able to execute
|
||||
* superuser/administrator actions.
|
||||
*
|
||||
* @return elevated?
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isElevated(): Boolean?
|
||||
|
||||
/**
|
||||
* Returns the amount of bits
|
||||
* this platform targets.
|
||||
*
|
||||
* This may be 32, 64 or an
|
||||
* even higher value.
|
||||
*
|
||||
* @return maximum of supported bits
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getBitness(): Int?
|
||||
|
||||
// -------> Computer
|
||||
/**
|
||||
* Returns the name of the
|
||||
* manufacturer of this computer.
|
||||
*
|
||||
* @return computer manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getComputerManufacturer(): String?
|
||||
|
||||
/**
|
||||
* Returns the name of the
|
||||
* model of this computer.
|
||||
*
|
||||
* @return computer model name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getComputerModel(): String?
|
||||
|
||||
// -------> Firmware (BIOS, UEFI, etc.)
|
||||
/**
|
||||
* Returns the name of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getFirmwareName(): String?
|
||||
|
||||
/**
|
||||
* Returns the description of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware description
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getFirmwareDescription(): String?
|
||||
|
||||
/**
|
||||
* Returns the name of the manufacturer of this
|
||||
* computer's firmware (BIOS, UEFI, etc.).
|
||||
*
|
||||
* @return firmware manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getFirmwareManufacturer(): String?
|
||||
|
||||
/**
|
||||
* Returns the version of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware version
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getFirmwareVersion(): String?
|
||||
|
||||
/**
|
||||
* Returns the release date of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware release date
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getFirmwareReleaseDate(): String?
|
||||
|
||||
// -------> Motherboard
|
||||
/**
|
||||
* Returns the name of the model of
|
||||
* this computer's motherboard.
|
||||
*
|
||||
* @return motherboard model name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMotherboardModel(): String?
|
||||
|
||||
/**
|
||||
* Returns the version of this
|
||||
* computer's motherboard.
|
||||
*
|
||||
* @return motherboard version
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMotherboardVersion(): String?
|
||||
|
||||
/**
|
||||
* Returns the serial number of
|
||||
* this computer's motherboard.
|
||||
*
|
||||
* @return motherboard serial number
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMotherboardSerialNumber(): String?
|
||||
|
||||
/**
|
||||
* Returns the name of the manufacturer
|
||||
* of this computer's motherboard.
|
||||
*
|
||||
* @return motherboard manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMotherboardManufacturer(): String?
|
||||
|
||||
// -------> Memory
|
||||
/**
|
||||
* Returns the total amount of physical
|
||||
* memory this system has in bytes.
|
||||
*
|
||||
* @return amount of physical memory in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMemoryTotal(): Long?
|
||||
|
||||
/**
|
||||
* Returns the amount of available
|
||||
* physical memory in bytes.
|
||||
*
|
||||
* @return amount of physical memory in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMemoryAvailable(): Long?
|
||||
|
||||
/**
|
||||
* Returns the amount of available
|
||||
* physical memory in bytes.
|
||||
*
|
||||
* @return amount of physical memory in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMemoryUsed(): Long?
|
||||
|
||||
/**
|
||||
* Returns the size of a
|
||||
* memory page in bytes.
|
||||
*
|
||||
* @return size of a memory page in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getMemoryPageSize(): ULong?
|
||||
|
||||
// -------> CPU
|
||||
/**
|
||||
* Returns the maximum clock speed of
|
||||
* the logical processors of the CPU
|
||||
* installed in this computer in Hz.
|
||||
*
|
||||
* @return maximum clock speed of logical processors in Hz or `-1` if it couldn't be determined
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getCPUMaximumFrequency(): Long?
|
||||
|
||||
/**
|
||||
* Returns the estimated current clock
|
||||
* speed of the logical processors of the
|
||||
* CPU installed in this computer in Hz.
|
||||
*
|
||||
* Each item in the returned array
|
||||
* stands for one logical processor.
|
||||
*
|
||||
* Depending on the platform the engine
|
||||
* runs on, this may or may not be
|
||||
* implemented. The algorithm used for
|
||||
* calculating this estimate depends on
|
||||
* the platform targeted. Some special
|
||||
* restrictions apply to certain platforms.
|
||||
* In short: Do not rely on the values
|
||||
* in the array returned by this method.
|
||||
*
|
||||
* @return current clock rate of logical processors in Hz or an empty array
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getCPUCurrentFrequency(): LongArray?
|
||||
|
||||
/**
|
||||
* Returns the current amount of
|
||||
* logical processors of the CPU
|
||||
* installed in this computer.
|
||||
*
|
||||
* This value may change over time
|
||||
* on some platforms. Be sure to
|
||||
* query this number frequently to
|
||||
* avoid out of date information.
|
||||
*
|
||||
* @return amount of logical processors
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getCPULogicalCount(): Int?
|
||||
|
||||
/**
|
||||
* Returns the amount of physical
|
||||
* processors installed in this computer.
|
||||
*
|
||||
* @return amount of physical processors
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getCPUPhysicalCount(): Int?
|
||||
|
||||
// -------> CPU
|
||||
/**
|
||||
* Returns an array of graphics cards
|
||||
* installed in this computer.
|
||||
*
|
||||
* @return array of [GraphicsCard] instances
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getGPUs(): Array<GraphicsCard>?
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility.misc
|
||||
|
||||
/**
|
||||
* Returns if currently
|
||||
* running on the main thread.
|
||||
*
|
||||
* @return `true` if running on the main thread, `false` if not, `null` if not supported
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
expect fun onMainThread(): Boolean?
|
|
@ -1,106 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility.misc
|
||||
|
||||
import de.staropensource.engine.base.type.Origin
|
||||
|
||||
/**
|
||||
* Returns the method caller.
|
||||
*
|
||||
* @param depth how deep to go into the stack trace
|
||||
* @return deepest method caller
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
expect fun methodCaller(depth: UInt = 1u): Origin
|
||||
|
||||
/**
|
||||
* Returns the `Caused by: ` header
|
||||
* usually found in JVM stacktraces.
|
||||
*
|
||||
* @param throwable [Throwable] to use
|
||||
* @return stacktrace header
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun stacktraceHeader(throwable: Throwable): String {
|
||||
return "Caused by: ${throwable::class.qualifiedName ?: "<anonymous>"}${if (throwable.message == null) "" else ": ${throwable.message}"}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the stacktrace
|
||||
* as it is usually found in JVM
|
||||
* stacktraces.
|
||||
*
|
||||
* @param throwable [Throwable] to use
|
||||
* @param indent if to add a tab character (`\t`) as indentation
|
||||
* @return stacktrace body
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
expect fun stacktraceBody(throwable: Throwable, indent: Boolean = true): String
|
||||
|
||||
/**
|
||||
* Returns a recursively resolved
|
||||
* collection of stacktraces, all
|
||||
* derived from the passed [throwable].
|
||||
*
|
||||
* Use this method if you intend to
|
||||
* print an exception's stacktrace or
|
||||
* want to display it nicely elsewhere.
|
||||
*
|
||||
*
|
||||
* @param throwable [Throwable] to use
|
||||
* @param indent if to add a tab character (`\t`) as indentation
|
||||
* @param includeHeader if to include the `Caused by` stacktrace header (see [stacktraceHeader])
|
||||
* @param depth how deep to recurse into [Throwable]s
|
||||
* @return recursively resolved stacktrace
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun stacktraceRecursive(throwable: Throwable, indent: Boolean = true, includeHeader: Boolean = true, depth: UInt = 10u): String = buildString {
|
||||
// Append header
|
||||
if (includeHeader) {
|
||||
append(stacktraceHeader(throwable))
|
||||
append("\n")
|
||||
}
|
||||
|
||||
// Append body
|
||||
append(stacktraceBody(throwable, indent = indent))
|
||||
|
||||
// Recurse downwards
|
||||
if (throwable.cause != null) {
|
||||
append("\n")
|
||||
if (depth == 0u)
|
||||
append("...")
|
||||
else
|
||||
append(stacktraceRecursive(throwable.cause!!, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u)))
|
||||
}
|
||||
|
||||
platformSTUHandleRecursiveThrowables(throwable, indent, includeHeader, depth)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles platform-specific [Throwable]s recursively.
|
||||
*
|
||||
* @param throwable [Throwable] to use
|
||||
* @param indent if to add a tab character (`\t`) as indentation
|
||||
* @param includeHeader if to include the `Caused by` stacktrace header (see [stacktraceHeader])
|
||||
* @param depth how deep to recurse into [Throwable]s
|
||||
* @return stacktraces
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
expect fun platformSTUHandleRecursiveThrowables(throwable: Throwable, indent: Boolean = true, includeHeader: Boolean = true, depth: UInt = 10u): String
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
actual fun platformTerminate(exitcode: UByte) = Runtime.getRuntime().exit(exitcode.toInt())
|
||||
actual fun platformMilliseconds(): ULong = System.currentTimeMillis().toULong()
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
import de.staropensource.engine.base.implementable.stream.ReadStream
|
||||
import de.staropensource.engine.base.implementable.stream.Stream
|
||||
import de.staropensource.engine.base.implementable.stream.WriteStream
|
||||
import de.staropensource.engine.base.implementation.stream.JavaReadStream
|
||||
import de.staropensource.engine.base.implementation.stream.JavaWriteStream
|
||||
import de.staropensource.engine.base.utility.Process
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
private typealias JProcess = java.lang.Process
|
||||
|
||||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
/**
|
||||
* Java implementation of [ProcessPlatform].
|
||||
*
|
||||
* @constructor Initializes this platform implementation
|
||||
* @param process [Process] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private class ProcessPlatformImpl (process: Process) : ProcessPlatform(process) {
|
||||
/**
|
||||
* Contains an instance of Java's
|
||||
* [java.lang.Process] class.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var jProcess: JProcess? = null
|
||||
|
||||
/**
|
||||
* Contains the standard input
|
||||
* [Stream] of this [Process].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
var standardInput: WriteStream? = null
|
||||
|
||||
/**
|
||||
* Contains the standard output
|
||||
* [Stream] of this [Process].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
var standardOutput: ReadStream? = null
|
||||
|
||||
/**
|
||||
* Contains the standard error
|
||||
* [Stream] of this [Process].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
var standardError: ReadStream? = null
|
||||
|
||||
|
||||
// -----> Lifecycle
|
||||
override fun start() {
|
||||
val builder: ProcessBuilder = ProcessBuilder()
|
||||
|
||||
// Reset environment
|
||||
if (process.launchedWithFreshEnvironment)
|
||||
builder.environment().clear()
|
||||
|
||||
// Pass arguments
|
||||
builder
|
||||
.command(listOf(process.executable.toStringRaw()).plus(process.arguments))
|
||||
.directory(process.workingDirectory.file)
|
||||
.environment().putAll(process.environmentVariables)
|
||||
|
||||
// Start process
|
||||
jProcess = builder.start()
|
||||
|
||||
// Set streams
|
||||
standardError = StandardOutputErrorStream(process, jProcess!!.errorStream)
|
||||
standardOutput = StandardOutputErrorStream(process, jProcess!!.inputStream)
|
||||
standardInput = StandardInputStream(process, jProcess!!.outputStream)
|
||||
|
||||
// Attach process exit handling
|
||||
jProcess!!.onExit().thenAccept {
|
||||
process.platformDeath()
|
||||
}
|
||||
}
|
||||
|
||||
override fun kill() {
|
||||
jProcess!!.destroyForcibly()
|
||||
}
|
||||
|
||||
|
||||
// -----> Getters
|
||||
override fun isAlive(): Boolean = jProcess!!.isAlive
|
||||
|
||||
override fun getPid(): Long = jProcess!!.pid()
|
||||
|
||||
override fun getExitCode(): UByte? = try {
|
||||
jProcess!!.exitValue().toUByte()
|
||||
} catch (_: IllegalThreadStateException) {
|
||||
null
|
||||
}
|
||||
|
||||
|
||||
// -----> Stream getters
|
||||
override fun getStandardInput(): WriteStream = standardInput!!
|
||||
override fun getStandardOutput(): ReadStream = standardOutput!!
|
||||
override fun getStandardError(): ReadStream = standardError!!
|
||||
}
|
||||
|
||||
|
||||
// -----> Actual methods
|
||||
actual fun platformProcessCreate(process: Process): ProcessPlatform = ProcessPlatformImpl(process)
|
||||
|
||||
|
||||
// -----> Inner classes
|
||||
/**
|
||||
* Used for the standard input
|
||||
* stream of a [Process].
|
||||
*
|
||||
* @constructor Initializes this stream
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private class StandardInputStream(
|
||||
val process: Process,
|
||||
stream: OutputStream,
|
||||
) : JavaWriteStream(
|
||||
stream,
|
||||
autoFlushAfter = 100UL
|
||||
) {
|
||||
// -----> Closure
|
||||
override fun close() {
|
||||
if (!process.isAlive())
|
||||
super.close()
|
||||
}
|
||||
|
||||
// -----> Writing
|
||||
// Assist in flushing
|
||||
override fun writeByte(byte: Byte): Stream {
|
||||
super.writeByte(byte)
|
||||
if (byte.toInt() == 0x0A)
|
||||
flush()
|
||||
return this
|
||||
}
|
||||
|
||||
override fun writeBytes(bytes: ByteArray): Stream {
|
||||
super.writeBytes(bytes)
|
||||
if (bytes.contains((0x0A).toByte()))
|
||||
flush()
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for the standard output
|
||||
* and standard error streams
|
||||
* of a [Process].
|
||||
*
|
||||
* @constructor Initializes this stream
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private class StandardOutputErrorStream(
|
||||
val process: Process,
|
||||
stream: InputStream,
|
||||
) : JavaReadStream(stream) {
|
||||
override fun close() {
|
||||
if (!process.isAlive())
|
||||
super.close()
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.platform
|
||||
|
||||
import de.staropensource.engine.base.Engine.Companion.logger
|
||||
import de.staropensource.engine.base.annotation.NonKotlinContact
|
||||
import de.staropensource.engine.base.exception.io.IOAccessException
|
||||
import de.staropensource.engine.base.implementable.stream.ReadStream
|
||||
import de.staropensource.engine.base.implementable.stream.Stream
|
||||
import de.staropensource.engine.base.implementable.stream.WriteStream
|
||||
import de.staropensource.engine.base.implementation.stream.JavaReadStream
|
||||
import de.staropensource.engine.base.implementation.stream.JavaWriteStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
/**
|
||||
* Java implementation of [StreamPlatform].
|
||||
*
|
||||
* @constructor Initializes this platform implementation
|
||||
* @param stream [Stream] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private class StreamPlatformImpl(stream: Stream) : StreamPlatform(stream) {
|
||||
override fun startWatchingThread() {
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Stream watch thread for Stream ${javaClass.name}#${hashCode()}")
|
||||
.uncaughtExceptionHandler { thread, ueh -> logger.crash("Unable to watch Stream ${javaClass.name}#${hashCode()}", throwable = ueh.cause, fatal = true) }
|
||||
.start {
|
||||
while (!stream.closed && stream.watching)
|
||||
stream.skipNextByte()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----> Actual methods
|
||||
actual fun platformStreamCreate(stream: Stream): StreamPlatform = StreamPlatformImpl(stream)
|
||||
actual fun platformStreamStandardInput(): ReadStream = object : JavaReadStream(System.`in`) {
|
||||
override fun close() = Unit
|
||||
override fun closeStream() = Unit
|
||||
}
|
||||
actual fun platformStreamStandardOutput(): WriteStream = object : JavaWriteStream(System.out) {
|
||||
override fun close() = Unit
|
||||
override fun closeStream() = Unit
|
||||
}
|
||||
actual fun platformStreamStandardError(): WriteStream = object : JavaWriteStream(System.err) {
|
||||
override fun close() = Unit
|
||||
override fun closeStream() = Unit
|
||||
}
|
||||
|
||||
|
||||
// -----> Extension methods
|
||||
/**
|
||||
* Returns this stream as
|
||||
* a Java [InputStream].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun Stream.getJavaInputStream(): InputStream = platformData.getOrPut("inputStream") { InputFileStream(this) } as InputStream
|
||||
|
||||
/**
|
||||
* Returns this stream as
|
||||
* a Java [OutputStream].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun Stream.getJavaOutputStream(): OutputStream = platformData.getOrPut("outputStream") { OutputFileStream(this) } as OutputStream
|
||||
|
||||
|
||||
// ----> Helper classes
|
||||
/**
|
||||
* An implementation of Java
|
||||
* [InputStream]s for [Stream]s.
|
||||
*
|
||||
* @constructor Initializes this stream
|
||||
* @param stream [Stream] to use
|
||||
* @throws IOException on IO error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private class InputFileStream
|
||||
@NonKotlinContact
|
||||
constructor(val stream: Stream)
|
||||
: InputStream() {
|
||||
/**
|
||||
* Reads the next byte.
|
||||
*
|
||||
* @return byte read
|
||||
* @throws IOException on IO error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
override fun read(): Int = try {
|
||||
stream.readNextByte()?.toInt() ?: -1
|
||||
} catch (exception: IOAccessException) {
|
||||
throw IOException("Failed reading the next byte", exception)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of Java
|
||||
* [OutputStream]s for [Stream]s.
|
||||
*
|
||||
* @constructor Initializes this stream
|
||||
* @param stream [Stream] to use
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@NonKotlinContact
|
||||
private class OutputFileStream
|
||||
@NonKotlinContact
|
||||
constructor(val stream: Stream)
|
||||
: OutputStream() {
|
||||
/**
|
||||
* Writes (or rather: appends) a byte.
|
||||
*
|
||||
* @param byte byte to append
|
||||
* @throws IOException on IO error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
override fun write(byte: Int) {
|
||||
try {
|
||||
stream.writeByte(byte.toByte())
|
||||
} catch (exception: IOAccessException) {
|
||||
throw IOException("Failed writing the next byte", exception)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility
|
||||
|
||||
import de.staropensource.engine.base.Engine.Companion.logger
|
||||
import de.staropensource.engine.base.type.environment.GraphicsCard
|
||||
import de.staropensource.engine.base.type.environment.OperatingSystem
|
||||
import kotlinx.datetime.Instant
|
||||
import oshi.PlatformEnum
|
||||
import oshi.SystemInfo
|
||||
import oshi.hardware.HardwareAbstractionLayer
|
||||
|
||||
@Suppress("Unused", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
actual class Environment private actual constructor() {
|
||||
actual companion object {
|
||||
// -----> Internal properties
|
||||
/**
|
||||
* Contains the [oshi.software.os.OperatingSystem]
|
||||
* implementation used for accessing
|
||||
* information about the operating
|
||||
* system the engine is running on.
|
||||
*
|
||||
* @return [oshi.software.os.OperatingSystem] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var os: oshi.software.os.OperatingSystem? = null
|
||||
|
||||
/**
|
||||
* Contains the [HardwareAbstractionLayer]
|
||||
* implementation used for accessing
|
||||
* hardware information of the system the
|
||||
* engine is running on.
|
||||
*
|
||||
* @return [HardwareAbstractionLayer] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var hw: HardwareAbstractionLayer? = null
|
||||
|
||||
@JvmStatic
|
||||
actual fun unset() {
|
||||
os = null
|
||||
hw = null
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
actual fun detect() {
|
||||
val si: SystemInfo = SystemInfo()
|
||||
os = si.operatingSystem
|
||||
hw = si.hardware
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
actual fun getOperatingSystem(): OperatingSystem? {
|
||||
when (SystemInfo.getCurrentPlatform()) {
|
||||
PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> return OperatingSystem.LINUX
|
||||
PlatformEnum.FREEBSD -> return OperatingSystem.FREEBSD
|
||||
PlatformEnum.NETBSD -> return OperatingSystem.NETBSD
|
||||
PlatformEnum.OPENBSD -> return OperatingSystem.OPENBSD
|
||||
//PlatformEnum.ANDROID -> return OperatingSystem.ANDROID // android is not yet supported by the engine, have to figure that one out sometime
|
||||
PlatformEnum.WINDOWS, PlatformEnum.WINDOWSCE -> return OperatingSystem.WINDOWS
|
||||
PlatformEnum.MACOS -> return OperatingSystem.MACOS
|
||||
else -> {
|
||||
logger.crash("Unsupported operating system '" + SystemInfo.getCurrentPlatform().name + "' reported by OSHI")
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
actual fun getTimeOfStartup(): Instant? {
|
||||
if (os == null)
|
||||
return null
|
||||
|
||||
return Instant.fromEpochSeconds(epochSeconds = os!!.systemBootTime)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
actual fun isElevated(): Boolean? = os?.isElevated
|
||||
|
||||
@JvmStatic
|
||||
actual fun getBitness(): Int? = os?.bitness
|
||||
|
||||
@JvmStatic
|
||||
actual fun getComputerManufacturer(): String? = hw?.computerSystem?.manufacturer
|
||||
|
||||
@JvmStatic
|
||||
actual fun getComputerModel(): String? = hw?.computerSystem?.model
|
||||
|
||||
@JvmStatic
|
||||
actual fun getFirmwareName(): String? = hw?.computerSystem?.firmware?.name
|
||||
|
||||
@JvmStatic
|
||||
actual fun getFirmwareDescription(): String? = hw?.computerSystem?.firmware?.description
|
||||
|
||||
@JvmStatic
|
||||
actual fun getFirmwareManufacturer(): String? = hw?.computerSystem?.firmware?.manufacturer
|
||||
|
||||
@JvmStatic
|
||||
actual fun getFirmwareVersion(): String? = hw?.computerSystem?.firmware?.version
|
||||
|
||||
@JvmStatic
|
||||
actual fun getFirmwareReleaseDate(): String? = hw?.computerSystem?.firmware?.releaseDate
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMotherboardModel(): String? = hw?.computerSystem?.baseboard?.model
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMotherboardVersion(): String? = hw?.computerSystem?.baseboard?.version
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMotherboardSerialNumber(): String? = hw?.computerSystem?.baseboard?.serialNumber
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMotherboardManufacturer(): String? = hw?.computerSystem?.baseboard?.manufacturer
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMemoryTotal(): Long? = hw?.memory?.total
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMemoryAvailable(): Long? = hw?.memory?.available
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMemoryUsed(): Long? = hw?.memory?.total?.minus(hw!!.memory!!.available)
|
||||
|
||||
@JvmStatic
|
||||
actual fun getMemoryPageSize(): ULong? = hw?.memory?.pageSize?.toULong()
|
||||
|
||||
@JvmStatic
|
||||
actual fun getCPUMaximumFrequency(): Long? = hw?.processor?.maxFreq
|
||||
|
||||
@JvmStatic
|
||||
actual fun getCPUCurrentFrequency(): LongArray? = hw?.processor?.currentFreq
|
||||
|
||||
@JvmStatic
|
||||
actual fun getCPULogicalCount(): Int? = hw?.processor?.logicalProcessorCount
|
||||
|
||||
@JvmStatic
|
||||
actual fun getCPUPhysicalCount(): Int? = hw?.processor?.physicalProcessorCount
|
||||
|
||||
@JvmStatic
|
||||
actual fun getGPUs(): Array<GraphicsCard>? = hw?.graphicsCards?.map { graphicsCard -> GraphicsCard(
|
||||
graphicsCard.name,
|
||||
graphicsCard.deviceId,
|
||||
graphicsCard.vendor,
|
||||
graphicsCard.versionInfo,
|
||||
graphicsCard.vRam.toULong(),
|
||||
) }?.toTypedArray()
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility.misc
|
||||
|
||||
actual fun onMainThread(): Boolean? = Thread.currentThread().threadId() == 1L
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility.misc
|
||||
|
||||
import de.staropensource.engine.base.type.Origin
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
|
||||
actual fun methodCaller(depth: UInt): Origin {
|
||||
val stacktrace: Array<StackTraceElement> = Throwable().stackTrace
|
||||
var element: StackTraceElement? = null
|
||||
|
||||
// Get wanted element
|
||||
element = if (depth.plus(2u).toInt() > stacktrace.size)
|
||||
stacktrace[stacktrace.size - 1]
|
||||
else
|
||||
stacktrace[depth.plus(2u).toInt()]
|
||||
|
||||
// Return origin
|
||||
return Origin(
|
||||
packageName = element.className.substringBeforeLast('.'),
|
||||
className = element.className.substringAfterLast('.'),
|
||||
methodName = element.methodName,
|
||||
lineNumber = element.lineNumber.toUInt(),
|
||||
)
|
||||
}
|
||||
|
||||
actual fun stacktraceBody(throwable: Throwable, indent: Boolean): String = buildString {
|
||||
for (element: StackTraceElement in throwable.stackTrace) {
|
||||
if (!isEmpty())
|
||||
append("\n")
|
||||
if (indent)
|
||||
append("\t")
|
||||
|
||||
append("at ")
|
||||
append(element)
|
||||
}
|
||||
}
|
||||
|
||||
actual fun platformSTUHandleRecursiveThrowables(throwable: Throwable, indent: Boolean, includeHeader: Boolean, depth: UInt): String = buildString {
|
||||
if (throwable is ClassNotFoundException) {
|
||||
val exception: ClassNotFoundException = throwable
|
||||
if (exception.exception != null) {
|
||||
append("\n")
|
||||
if (depth == 0u)
|
||||
append("...")
|
||||
else
|
||||
append(stacktraceRecursive(exception.exception, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u)))
|
||||
}
|
||||
} else if (throwable is ExceptionInInitializerError) {
|
||||
val exception: ExceptionInInitializerError = throwable
|
||||
if (exception.exception != null) {
|
||||
append("\n")
|
||||
if (depth == 0u)
|
||||
append("...")
|
||||
else
|
||||
append(stacktraceRecursive(exception.exception, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u)))
|
||||
}
|
||||
} else if (throwable is InvocationTargetException) {
|
||||
val exception: InvocationTargetException = throwable
|
||||
if (exception.targetException != null) {
|
||||
append("\n")
|
||||
if (depth == 0u)
|
||||
append("...")
|
||||
else
|
||||
append(stacktraceRecursive(exception.targetException, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u)))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,14 +22,11 @@ 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 kotlin.jvm.JvmStatic
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.charset.StandardCharsets
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
|
@ -53,7 +50,6 @@ class Engine private constructor() {
|
|||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
internal val logger: Logger = Logger(channel = "engine-core")
|
||||
|
||||
/**
|
||||
|
@ -61,7 +57,6 @@ class Engine private constructor() {
|
|||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
var state: State = State.UNINITIALIZED
|
||||
internal set
|
||||
|
||||
|
@ -78,7 +73,6 @@ class Engine private constructor() {
|
|||
* @see bootstrap
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
var bootstrapping: Boolean? = null
|
||||
|
||||
/**
|
||||
|
@ -87,7 +81,6 @@ class Engine private constructor() {
|
|||
* @see Subsystem
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
private val subsystems: MutableSet<Subsystem> = mutableSetOf()
|
||||
|
||||
/**
|
||||
|
@ -98,7 +91,6 @@ class Engine private constructor() {
|
|||
* @see BuildInformation
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
var info: BuildInformation? = null
|
||||
|
||||
|
||||
|
@ -110,7 +102,6 @@ class Engine private constructor() {
|
|||
* @return array of registered [Subsystem]s
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getSubsystems(): Array<Subsystem> = subsystems.toTypedArray()
|
||||
|
||||
/**
|
||||
|
@ -119,14 +110,11 @@ class Engine private constructor() {
|
|||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getSubsystem(subsystemClass: KClass<out Subsystem>): Subsystem? {
|
||||
return getSubsystems().find { subsystem -> try {
|
||||
subsystem::class.qualifiedName!! == subsystemClass.qualifiedName!!
|
||||
} catch (_: NullPointerException) {
|
||||
false
|
||||
} }
|
||||
}
|
||||
fun getSubsystem(subsystemClass: KClass<out Subsystem>): Subsystem? = getSubsystems().find { subsystem -> try {
|
||||
subsystem::class.qualifiedName!! == subsystemClass.qualifiedName!!
|
||||
} catch (_: NullPointerException) {
|
||||
false
|
||||
} }
|
||||
|
||||
/**
|
||||
* Registers the specified subsystem.
|
||||
|
@ -140,7 +128,6 @@ class Engine private constructor() {
|
|||
* @see Subsystem
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun registerSubsystem(subsystem: Subsystem) {
|
||||
// Check for state
|
||||
if (bootstrapping == true)
|
||||
|
@ -188,7 +175,9 @@ class Engine private constructor() {
|
|||
logger.info("Bootstrapping")
|
||||
|
||||
// Run bootstrapping code
|
||||
platformEngineBootstrap()
|
||||
// -> Run checks
|
||||
if (Charset.defaultCharset() != StandardCharsets.UTF_8)
|
||||
logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8")
|
||||
|
||||
// Bootstrap subsystems
|
||||
logger.verb("Bootstrapping subsystems")
|
||||
|
@ -243,7 +232,6 @@ class Engine private constructor() {
|
|||
logger.info("Initializing")
|
||||
|
||||
// Run initialization code
|
||||
platformEngineInitialize()
|
||||
Environment.detect()
|
||||
FileAccess.updateDefaultPaths()
|
||||
info = BuildInformation(loadPrefix = "sosengine-base")
|
||||
|
@ -304,7 +292,7 @@ class Engine private constructor() {
|
|||
logger.info("Reloading")
|
||||
|
||||
// Run reload code
|
||||
platformEngineReload()
|
||||
// *none yet*
|
||||
|
||||
// Reload subsystems
|
||||
logger.verb("Reloading subsystems")
|
||||
|
@ -400,7 +388,13 @@ class Engine private constructor() {
|
|||
state = State.SHUTTING_DOWN
|
||||
val infoLocal: BuildInformation? = info
|
||||
|
||||
// Shut subsystems down
|
||||
// Run shutdown code
|
||||
Environment.unset()
|
||||
FileAccess.deleteScheduled()
|
||||
FileAccess.unsetDefaultPaths()
|
||||
info = null
|
||||
|
||||
// Initialize subsystems
|
||||
logger.verb("Shutting subsystems down")
|
||||
for (subsystem: Subsystem in subsystems) {
|
||||
val subsystemVersion: String = subsystem.getVersion()
|
||||
|
@ -417,13 +411,6 @@ 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("""
|
|
@ -35,7 +35,6 @@ import de.staropensource.engine.base.type.logging.Feature
|
|||
import de.staropensource.engine.base.type.logging.Level
|
||||
import de.staropensource.engine.base.type.logging.OperationMode
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
|
@ -25,9 +25,10 @@ package de.staropensource.engine.base.annotation
|
|||
* the public API.
|
||||
*
|
||||
* Using anything non-Kotlin in conjunction with
|
||||
* the StarOpenSource Engine is highly
|
||||
* discouraged, as the engine is optimized for
|
||||
* multiplatform usage.
|
||||
* the StarOpenSource Engine is highly discouraged,
|
||||
* as the engine may be multiplatform in future
|
||||
* releases and will not support using other
|
||||
* languages.
|
||||
*
|
||||
* Using anything in contact with non-Kotlin code
|
||||
* is therefore deemed unsafe and should be
|
|
@ -44,7 +44,7 @@ import kotlin.text.iterator
|
|||
* @since v1-alpha10
|
||||
*/
|
||||
abstract class TwoCycleFormatterImpl: TwoCycleFormatter() {
|
||||
@Suppress("NestedBlockDepth", "CyclomaticComplexMethod")
|
||||
@Suppress("NestedBlockDepth")
|
||||
override fun parse(message: String): Array<String> {
|
||||
val components: MutableList<String> = mutableListOf()
|
||||
var currentComponent: StringBuilder = StringBuilder()
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package de.staropensource.engine.base.implementable.logging
|
||||
|
||||
import de.staropensource.engine.base.logging.Processor
|
||||
import de.staropensource.engine.base.type.logging.Call
|
||||
|
||||
/**
|
|
@ -22,4 +22,4 @@
|
|||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
package de.staropensource.engine.base.implementable
|
||||
package de.staropensource.engine.base.implementable;
|
|
@ -19,13 +19,14 @@
|
|||
|
||||
package de.staropensource.engine.base.implementable.stream
|
||||
|
||||
import de.staropensource.engine.base.Engine.Companion.logger
|
||||
import de.staropensource.engine.base.annotation.NonKotlinContact
|
||||
import de.staropensource.engine.base.exception.io.IOAccessException
|
||||
import de.staropensource.engine.base.implementable.PlatformData
|
||||
import de.staropensource.engine.base.platform.StreamPlatform
|
||||
import de.staropensource.engine.base.platform.platformStreamCreate
|
||||
import de.staropensource.engine.base.platform.platformStreamStandardError
|
||||
import de.staropensource.engine.base.platform.platformStreamStandardInput
|
||||
import de.staropensource.engine.base.platform.platformStreamStandardOutput
|
||||
import de.staropensource.engine.base.implementation.stream.JavaReadStream
|
||||
import de.staropensource.engine.base.implementation.stream.JavaWriteStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
/**
|
||||
* Makes streaming data easy.
|
||||
|
@ -39,7 +40,7 @@ import de.staropensource.engine.base.platform.platformStreamStandardOutput
|
|||
abstract class Stream(
|
||||
val streamMode: StreamMode,
|
||||
val autoFlushAfter: ULong = 100UL,
|
||||
) : AutoCloseable, PlatformData {
|
||||
) : AutoCloseable {
|
||||
/**
|
||||
* Companion object of [Stream].
|
||||
*
|
||||
|
@ -53,7 +54,10 @@ abstract class Stream(
|
|||
* @see <a href="https://man.archlinux.org/man/stdin.3">stdin(3)</a>
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
val standardInput: ReadStream = platformStreamStandardInput()
|
||||
val standardInput: ReadStream = object : JavaReadStream(System.`in`) {
|
||||
override fun close() = Unit
|
||||
override fun closeStream() = Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the standard output as a [Stream].
|
||||
|
@ -62,7 +66,10 @@ abstract class Stream(
|
|||
* @see <a href="https://man.archlinux.org/man/stdout.3">stdout(3)</a>
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
val standardOutput: WriteStream = platformStreamStandardOutput()
|
||||
val standardOutput: WriteStream = object : JavaWriteStream(System.out) {
|
||||
override fun close() = Unit
|
||||
override fun closeStream() = Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the standard error as a [Stream].
|
||||
|
@ -70,22 +77,13 @@ abstract class Stream(
|
|||
* @see <a href="https://man.archlinux.org/man/stderr.3">stderr(3)</a>
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
val standardError: WriteStream = platformStreamStandardError()
|
||||
val standardError: WriteStream = object : JavaWriteStream(System.err) {
|
||||
override fun close() = Unit
|
||||
override fun closeStream() = Unit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----> Platform-specific
|
||||
override val platformData: MutableMap<String, Any?> = mutableMapOf()
|
||||
|
||||
/**
|
||||
* Platform-specific [StreamPlatform]
|
||||
* instance for this [Stream].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private val platform: StreamPlatform = platformStreamCreate(this)
|
||||
|
||||
|
||||
// -----> Properties
|
||||
/**
|
||||
* Indicates whether this stream is closed.
|
||||
|
@ -135,6 +133,22 @@ abstract class Stream(
|
|||
*/
|
||||
val pipes: MutableList<Stream> = mutableListOf()
|
||||
|
||||
/**
|
||||
* Contains the Java [InputStream]
|
||||
* for this [Stream] instance.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var inputStream: InputFileStream? = null
|
||||
|
||||
/**
|
||||
* Contains the Java [OutputStream]
|
||||
* for this [Stream] instance.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var outputStream: OutputFileStream? = null
|
||||
|
||||
|
||||
// -----> Closure
|
||||
/**
|
||||
|
@ -219,7 +233,7 @@ abstract class Stream(
|
|||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(IOAccessException::class)
|
||||
fun writeString(string: String): Stream = writeBytes(string.encodeToByteArray())
|
||||
fun writeString(string: String): Stream = writeBytes(string.toByteArray())
|
||||
|
||||
/**
|
||||
* Writes (or rather: appends)
|
||||
|
@ -231,7 +245,7 @@ abstract class Stream(
|
|||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(IOAccessException::class)
|
||||
fun write(value: Any): Stream = writeBytes(value.toString().encodeToByteArray())
|
||||
fun write(value: Any): Stream = writeBytes(value.toString().toByteArray())
|
||||
|
||||
/**
|
||||
* Flushes all currently
|
||||
|
@ -380,6 +394,7 @@ abstract class Stream(
|
|||
* if wanting to only pipe the bytes
|
||||
* of this [Stream] to other streams.
|
||||
*
|
||||
* @param threshold amount of bytes to be read before terminating or `0` to watch indefinitely
|
||||
* @return this instance
|
||||
* @throws IOAccessException on IO error
|
||||
* @since v1-alpha10
|
||||
|
@ -391,7 +406,14 @@ abstract class Stream(
|
|||
|
||||
watching = true
|
||||
|
||||
platform.startWatchingThread()
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Stream watch thread for Stream ${javaClass.name}#${hashCode()}")
|
||||
.uncaughtExceptionHandler { thread, ueh -> logger.crash("Unable to watch Stream ${javaClass.name}#${hashCode()}", throwable = ueh.cause, fatal = true) }
|
||||
.start {
|
||||
while (!closed && watching)
|
||||
skipNextByte()
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
@ -452,7 +474,7 @@ abstract class Stream(
|
|||
*
|
||||
* Make sure to call this method
|
||||
* before returning from
|
||||
* [readNextByte], [readNBytes]
|
||||
* [readBytes], [readNBytes]
|
||||
* and [readRemainingBytes].
|
||||
*
|
||||
* @param byte [Byte] to pipe
|
||||
|
@ -472,7 +494,7 @@ abstract class Stream(
|
|||
*
|
||||
* Make sure to call this method
|
||||
* before returning from
|
||||
* [readNextByte], [readNBytes]
|
||||
* [readBytes], [readNBytes]
|
||||
* and [readRemainingBytes].
|
||||
*
|
||||
* @param bytes [ByteArray] to pipe
|
||||
|
@ -618,6 +640,36 @@ abstract class Stream(
|
|||
}
|
||||
|
||||
|
||||
// -----> Java interoperability
|
||||
/**
|
||||
* Returns this stream as
|
||||
* a Java [InputStream].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@NonKotlinContact
|
||||
fun toInputStream(): InputStream {
|
||||
if (inputStream == null)
|
||||
inputStream = InputFileStream(this)
|
||||
|
||||
return inputStream!!
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this stream as
|
||||
* a Java [OutputStream].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@NonKotlinContact
|
||||
fun toOutputStream(): OutputStream {
|
||||
if (outputStream == null)
|
||||
outputStream = OutputFileStream(this)
|
||||
|
||||
return outputStream!!
|
||||
}
|
||||
|
||||
|
||||
// -----> Inner classes
|
||||
/**
|
||||
* Represents the mode in which
|
||||
|
@ -650,4 +702,62 @@ abstract class Stream(
|
|||
*/
|
||||
READ_WRITE,
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of Java
|
||||
* [InputStream]s for [Stream]s.
|
||||
*
|
||||
* @constructor Initializes this stream
|
||||
* @param stream [Stream] to use
|
||||
* @throws IOException on IO error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
class InputFileStream
|
||||
@NonKotlinContact
|
||||
internal constructor(val stream: Stream)
|
||||
: InputStream() {
|
||||
/**
|
||||
* Reads the next byte.
|
||||
*
|
||||
* @return byte read
|
||||
* @throws IOException on IO error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
override fun read(): Int = try {
|
||||
stream.readNextByte()?.toInt() ?: -1
|
||||
} catch (exception: IOAccessException) {
|
||||
throw IOException("Failed reading the next byte", exception)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of Java
|
||||
* [OutputStream]s for [Stream]s.
|
||||
*
|
||||
* @constructor Initializes this stream
|
||||
* @param stream [Stream] to use
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@NonKotlinContact
|
||||
class OutputFileStream
|
||||
@NonKotlinContact
|
||||
internal constructor(val stream: Stream)
|
||||
: OutputStream() {
|
||||
/**
|
||||
* Writes (or rather: appends) a byte.
|
||||
*
|
||||
* @param byte byte to append
|
||||
* @throws IOException on IO error
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
override fun write(byte: Int) {
|
||||
try {
|
||||
stream.writeByte(byte.toByte())
|
||||
} catch (exception: IOAccessException) {
|
||||
throw IOException("Failed writing the next byte", exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* [Stream]s.
|
||||
* [Streams].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
|
@ -20,17 +20,15 @@
|
|||
package de.staropensource.engine.base.implementation.logging
|
||||
|
||||
import de.staropensource.engine.base.implementable.ShutdownHandler
|
||||
import de.staropensource.engine.base.platform.platformTerminate
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* [ShutdownHandler] implementation which
|
||||
* simply terminates the application.
|
||||
* [ShutdownHandler] implementation using
|
||||
* Kotlin's [exitProcess] method.
|
||||
*
|
||||
* @constructor Initializes this shutdown handler
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
class KotlinShutdownHandler private constructor() : ShutdownHandler {
|
||||
/**
|
||||
* Companion object of [KotlinShutdownHandler].
|
||||
|
@ -48,6 +46,6 @@ class KotlinShutdownHandler private constructor() : ShutdownHandler {
|
|||
}
|
||||
|
||||
override fun exit(exitcode: UByte) {
|
||||
platformTerminate(exitcode)
|
||||
exitProcess(exitcode.toInt())
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementation.logging
|
|||
|
||||
import de.staropensource.engine.base.implementable.formatter.Formatter
|
||||
import de.staropensource.engine.base.implementable.formatter.OneCycleFormatter
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.text.iterator
|
||||
|
||||
/**
|
|
@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementation.logging.adapter
|
|||
|
||||
import de.staropensource.engine.base.implementable.logging.Adapter
|
||||
import de.staropensource.engine.base.type.logging.Call
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* [Adapter] for printing messages
|
|
@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementation.logging.crashcategory
|
|||
|
||||
import de.staropensource.engine.base.implementable.logging.CrashCategory
|
||||
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* [CrashCategory] implementation
|
|
@ -23,7 +23,9 @@ import de.staropensource.engine.base.implementable.logging.CrashCategory
|
|||
import de.staropensource.engine.base.type.logging.Call
|
||||
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||
import de.staropensource.engine.base.utility.Environment
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
|
||||
/**
|
||||
* [CrashCategory] implementation
|
|
@ -23,7 +23,6 @@ import de.staropensource.engine.base.implementable.logging.CrashCategory
|
|||
import de.staropensource.engine.base.type.logging.Call
|
||||
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||
import de.staropensource.engine.base.utility.misc.StackTraceUtils
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* [CrashCategory] implementation
|
|
@ -143,22 +143,22 @@ open class SOSLSv2FormatBuilder(call: Call, channelSettings: ChannelSettings?) :
|
|||
|
||||
if (enabledFeatures.contains(Feature.DATE))
|
||||
format
|
||||
.append(datetime.dayOfMonth.toString().padStart(2, padChar = '0'))
|
||||
.append("%02d".format(datetime.dayOfMonth))
|
||||
.append(".")
|
||||
.append(datetime.monthNumber.toString().padStart(2, padChar = '0'))
|
||||
.append("%02d".format(datetime.monthNumber))
|
||||
.append(".")
|
||||
.append(datetime.year.toString().padStart(4, padChar = '0'))
|
||||
.append("%04d".format(datetime.year))
|
||||
|
||||
if (enabledFeatures.contains(Feature.DATE) && enabledFeatures.contains(Feature.TIME))
|
||||
format.append(" ")
|
||||
|
||||
if (enabledFeatures.contains(Feature.TIME))
|
||||
format
|
||||
.append(datetime.hour.toString().padStart(2, padChar = '0'))
|
||||
.append("%02d".format(datetime.hour))
|
||||
.append(":")
|
||||
.append(datetime.minute.toString().padStart(2, padChar = '0'))
|
||||
.append("%02d".format(datetime.minute))
|
||||
.append(":")
|
||||
.append(datetime.second.toString().padStart(2, padChar = '0'))
|
||||
.append("%02d".format(datetime.second))
|
||||
|
||||
if (enabledFeatures.contains(Feature.DATE) || enabledFeatures.contains(Feature.TIME)) {
|
||||
if (enabledFeatures.contains(Feature.FORMATTING))
|
|
@ -20,7 +20,6 @@
|
|||
package de.staropensource.engine.base.implementation.stream
|
||||
|
||||
import de.staropensource.engine.base.implementable.stream.Stream
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* A [Stream] which does nothing
|
|
@ -29,4 +29,4 @@ import de.staropensource.engine.base.implementable.stream.Stream
|
|||
* @param stringRead string to provide for reading
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
open class StringReadStream(val stringRead: String) : ByteReadStream(bytesRead = stringRead.encodeToByteArray())
|
||||
open class StringReadStream(val stringRead: String) : ByteReadStream(bytesRead = stringRead.toByteArray())
|
|
@ -29,7 +29,7 @@ import de.staropensource.engine.base.implementable.stream.Stream
|
|||
* @param stringRead string to provide for reading
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
open class StringStream(val stringRead: String) : ByteStream(bytesRead = stringRead.encodeToByteArray()) {
|
||||
open class StringStream(val stringRead: String) : ByteStream(bytesRead = stringRead.toByteArray()) {
|
||||
/**
|
||||
* Returns the written string.
|
||||
*
|
|
@ -21,7 +21,6 @@ package de.staropensource.engine.base.logging
|
|||
|
||||
import de.staropensource.engine.base.implementable.logging.Filter
|
||||
import de.staropensource.engine.base.type.logging.Call
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Handles call filtering.
|
|
@ -27,11 +27,9 @@ import de.staropensource.engine.base.implementation.stream.FileAccessStream
|
|||
import de.staropensource.engine.base.implementation.stream.LoggerStream
|
||||
import de.staropensource.engine.base.type.logging.Call
|
||||
import de.staropensource.engine.base.type.logging.Level
|
||||
import de.staropensource.engine.base.utility.misc.methodCaller
|
||||
import de.staropensource.engine.base.utility.misc.StackTraceUtils
|
||||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Frontend for sos!engine's logging system.
|
||||
|
@ -121,10 +119,10 @@ class Logger {
|
|||
* @param callerDepth determines the depth at which to discover the method caller
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun log(level: Level, message: String, levelData: Map<String, Any?> = emptyMap(), callerDepth: UInt = 0u) {
|
||||
fun log(level: Level, message: String, levelData: Map<String, Object?> = emptyMap(), callerDepth: UInt = 0u) {
|
||||
// Create 'Call' instance
|
||||
var call: Call = Call(
|
||||
methodCaller(depth = callerDepth.plus(1u)),
|
||||
StackTraceUtils.methodCaller(depth = callerDepth.plus(1u)),
|
||||
level,
|
||||
message,
|
||||
channel
|
||||
|
@ -132,7 +130,7 @@ class Logger {
|
|||
|
||||
// Run processing
|
||||
if (level == Level.CRASH)
|
||||
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrElse("fatal") { true } as Boolean)
|
||||
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrDefault("fatal", true) as Boolean)
|
||||
else {
|
||||
if (Processor.check(call))
|
||||
return
|
||||
|
@ -212,8 +210,8 @@ class Logger {
|
|||
*/
|
||||
fun crash(error: String, throwable: Throwable? = null, fatal: Boolean = true) {
|
||||
log(Level.CRASH, error, levelData = mapOf(
|
||||
Pair("throwable", throwable as Any?),
|
||||
Pair("fatal", fatal as Any?)
|
||||
Pair("throwable", throwable as Object?),
|
||||
Pair("fatal", fatal as Object?)
|
||||
), callerDepth = 1u)
|
||||
}
|
||||
|
||||
|
@ -244,5 +242,5 @@ class Logger {
|
|||
* @return [FileAccessStream] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toStream(level: Level): LoggerStream = stream[level] ?: LoggerStream(this, level)
|
||||
fun toStream(level: Level): LoggerStream = stream.computeIfAbsent(level) { level -> LoggerStream(this, level) }
|
||||
}
|
|
@ -28,8 +28,7 @@ import de.staropensource.engine.base.type.logging.Call
|
|||
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||
import de.staropensource.engine.base.type.logging.Feature
|
||||
import de.staropensource.engine.base.type.logging.OperationMode
|
||||
import de.staropensource.engine.base.utility.misc.stacktraceRecursive
|
||||
import kotlin.jvm.JvmStatic
|
||||
import de.staropensource.engine.base.utility.misc.StackTraceUtils
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
|
||||
/**
|
||||
|
@ -88,7 +87,7 @@ class Processor private constructor() {
|
|||
* @param call [Call] metadata
|
||||
* @see EngineConfiguration.logThreadingHandler
|
||||
* @see ChannelSettings.formatter
|
||||
* @see ChannelSettings.adapters
|
||||
* @see ChannelSettings.adapter
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
|
@ -103,7 +102,7 @@ class Processor private constructor() {
|
|||
try {
|
||||
format = (EngineConfiguration.logFormatBuilder).primaryConstructor!!.call(call, channelSettings)
|
||||
} catch (throwable: Throwable) {
|
||||
println("Logger system failure: Configured FormatBuilder implementation '" + ((EngineConfiguration.logFormatBuilder).qualifiedName ?: "<anonymous>") + "' does not have a primary 'constructor(Call, ChannelSettings?)'. Log messages cannot be processed.\n${stacktraceRecursive(throwable)}")
|
||||
println("Logger system failure: Configured FormatBuilder implementation '" + ((EngineConfiguration.logFormatBuilder).qualifiedName ?: "<anonymous>") + "' does not have a primary 'constructor(Call, ChannelSettings?)'. Log messages cannot be processed.\n${StackTraceUtils.stacktraceRecursive(throwable)}")
|
||||
return
|
||||
}
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
package de.staropensource.engine.base.type
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Defines a data type which can have
|
|
@ -24,7 +24,6 @@ import de.staropensource.engine.base.implementable.logging.Adapter
|
|||
import de.staropensource.engine.base.implementable.formatter.Formatter
|
||||
import de.staropensource.engine.base.implementation.logging.NoOperationFormatter
|
||||
import de.staropensource.engine.base.implementation.logging.adapter.PrintlnAdapter
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Holds the configuration of one
|
|
@ -22,4 +22,4 @@
|
|||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
package de.staropensource.engine.base.type
|
||||
package de.staropensource.engine.base.type;
|
|
@ -23,4 +23,4 @@
|
|||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
package de.staropensource.engine.base.type.versioning
|
||||
package de.staropensource.engine.base.type.versioning;
|
|
@ -19,9 +19,10 @@
|
|||
|
||||
package de.staropensource.engine.base.utility
|
||||
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.math.round
|
||||
import kotlin.math.roundToLong
|
||||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Converts between various data size units.
|
||||
|
@ -150,7 +151,11 @@ data class DataSize(
|
|||
* @return modified [Double]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun formatTo(number: Double): Double = round(number.times(1000)).div(1000)
|
||||
fun formatTo(number: Double): Double {
|
||||
val decimalFormat = DecimalFormat("#.####", DecimalFormatSymbols(Locale.ROOT))
|
||||
decimalFormat.roundingMode = RoundingMode.HALF_UP
|
||||
return decimalFormat.format(number).toDouble()
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs miscellaneous operations
|
||||
|
@ -161,7 +166,11 @@ data class DataSize(
|
|||
* @return modified [Double]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun formatOf(number: Double): ULong = number.roundToLong().toULong()
|
||||
fun formatOf(number: Double): ULong {
|
||||
val decimalFormat = DecimalFormat("#", DecimalFormatSymbols(Locale.ROOT))
|
||||
decimalFormat.roundingMode = RoundingMode.HALF_UP
|
||||
return decimalFormat.format(number).toULong()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,508 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility
|
||||
|
||||
import de.staropensource.engine.base.Engine.Companion.logger
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
|
||||
import kotlinx.datetime.Instant
|
||||
import oshi.PlatformEnum
|
||||
import oshi.SystemInfo
|
||||
import oshi.hardware.HardwareAbstractionLayer
|
||||
|
||||
/**
|
||||
* Provides information about the
|
||||
* environment the application runs in.
|
||||
*
|
||||
* @constructor Initializes this class
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class Environment private constructor() {
|
||||
/**
|
||||
* Companion class of [Environment].
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
companion object {
|
||||
// -----> Internal properties
|
||||
/**
|
||||
* Contains the [oshi.software.os.OperatingSystem]
|
||||
* implementation used for accessing
|
||||
* information about the operating
|
||||
* system the engine is running on.
|
||||
*
|
||||
* @return [oshi.software.os.OperatingSystem] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var os: oshi.software.os.OperatingSystem? = null
|
||||
|
||||
/**
|
||||
* Contains the [HardwareAbstractionLayer]
|
||||
* implementation used for accessing
|
||||
* hardware information of the system the
|
||||
* engine is running on.
|
||||
*
|
||||
* @return [HardwareAbstractionLayer] instance
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
private var hw: HardwareAbstractionLayer? = null
|
||||
|
||||
|
||||
// -----> Update methods
|
||||
/**
|
||||
* Unsets the environment.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
internal fun unset() {
|
||||
os = null
|
||||
hw = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects and updates the environment.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
internal fun detect() {
|
||||
val si: SystemInfo = SystemInfo()
|
||||
os = si.operatingSystem
|
||||
hw = si.hardware
|
||||
}
|
||||
|
||||
|
||||
// -----> Getters
|
||||
// -------> General
|
||||
/**
|
||||
* Returns the amount of
|
||||
* bits this platform targets.
|
||||
*
|
||||
* This may be 32, 64 or an
|
||||
* even higher value.
|
||||
*
|
||||
* @return maximum of supported bits
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getOperatingSystem(): OperatingSystem? {
|
||||
when (SystemInfo.getCurrentPlatform()) {
|
||||
PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> return LINUX
|
||||
PlatformEnum.FREEBSD -> return FREEBSD
|
||||
PlatformEnum.NETBSD -> return NETBSD
|
||||
PlatformEnum.OPENBSD -> return OPENBSD
|
||||
//PlatformEnum.ANDROID -> Environment.getOperatingSystem() = Environment.OperatingSystem.ANDROID // android is not yet supported by the engine, have to figure that one out sometime
|
||||
PlatformEnum.WINDOWS, PlatformEnum.WINDOWSCE -> return WINDOWS
|
||||
PlatformEnum.MACOS -> return MACOS
|
||||
else -> {
|
||||
logger.crash("Unsupported operating system '" + SystemInfo.getCurrentPlatform().name + "' reported by OSHI")
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the point in time where
|
||||
* the system the engine is
|
||||
* running on has started.
|
||||
*
|
||||
* @return time of system startup
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getTimeOfStartup(): Instant? {
|
||||
if (os == null)
|
||||
return null
|
||||
|
||||
return Instant.fromEpochSeconds(epochSeconds = os!!.systemBootTime)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current process
|
||||
* is elevated and is able to execute
|
||||
* superuser/administrator actions.
|
||||
*
|
||||
* @return elevated?
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun isElevated(): Boolean? = os?.isElevated
|
||||
|
||||
/**
|
||||
* Returns the amount of bits
|
||||
* this platform targets.
|
||||
*
|
||||
* This may be 32, 64 or an
|
||||
* even higher value.
|
||||
*
|
||||
* @return maximum of supported bits
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getBitness(): Int? = os?.bitness
|
||||
|
||||
// -------> Computer
|
||||
/**
|
||||
* Returns the name of the
|
||||
* manufacturer of this computer.
|
||||
*
|
||||
* @return computer manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getComputerManufacturer(): String? = hw?.computerSystem?.manufacturer
|
||||
|
||||
/**
|
||||
* Returns the name of the
|
||||
* model of this computer.
|
||||
*
|
||||
* @return computer model name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getComputerModel(): String? = hw?.computerSystem?.model
|
||||
|
||||
// -------> Firmware (BIOS, UEFI, etc.)
|
||||
/**
|
||||
* Returns the name of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getFirmwareName(): String? = hw?.computerSystem?.firmware?.name
|
||||
|
||||
/**
|
||||
* Returns the description of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware description
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getFirmwareDescription(): String? = hw?.computerSystem?.firmware?.description
|
||||
|
||||
/**
|
||||
* Returns the name of the manufacturer of this
|
||||
* computer's firmware (BIOS, UEFI, etc.).
|
||||
*
|
||||
* @return firmware manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getFirmwareManufacturer(): String? = hw?.computerSystem?.firmware?.manufacturer
|
||||
|
||||
/**
|
||||
* Returns the version of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware version
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getFirmwareVersion(): String? = hw?.computerSystem?.firmware?.version
|
||||
|
||||
/**
|
||||
* Returns the release date of the firmware (BIOS,
|
||||
* UEFI, etc.) installed on this computer.
|
||||
*
|
||||
* @return firmware release date
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getFirmwareReleaseDate(): String? = hw?.computerSystem?.firmware?.releaseDate
|
||||
|
||||
// -------> Motherboard
|
||||
/**
|
||||
* Returns the name of the model of
|
||||
* this computer's motherboard.
|
||||
*
|
||||
* @return motherboard model name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMotherboardModel(): String? = hw?.computerSystem?.baseboard?.model
|
||||
|
||||
/**
|
||||
* Returns the version of this
|
||||
* computer's motherboard.
|
||||
*
|
||||
* @return motherboard version
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMotherboardVersion(): String? = hw?.computerSystem?.baseboard?.version
|
||||
|
||||
/**
|
||||
* Returns the serial number of
|
||||
* this computer's motherboard.
|
||||
*
|
||||
* @return motherboard serial number
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMotherboardSerialNumber(): String? = hw?.computerSystem?.baseboard?.serialNumber
|
||||
|
||||
/**
|
||||
* Returns the name of the manufacturer
|
||||
* of this computer's motherboard.
|
||||
*
|
||||
* @return motherboard manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMotherboardManufacturer(): String? = hw?.computerSystem?.baseboard?.manufacturer
|
||||
|
||||
// -------> Memory
|
||||
/**
|
||||
* Returns the total amount of physical
|
||||
* memory this system has in bytes.
|
||||
*
|
||||
* @return amount of physical memory in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMemoryTotal(): Long? = hw?.memory?.total
|
||||
|
||||
/**
|
||||
* Returns the amount of available
|
||||
* physical memory in bytes.
|
||||
*
|
||||
* @return amount of physical memory in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMemoryAvailable(): Long? = hw?.memory?.available
|
||||
|
||||
/**
|
||||
* Returns the amount of available
|
||||
* physical memory in bytes.
|
||||
*
|
||||
* @return amount of physical memory in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMemoryUsed(): Long? = hw?.memory?.total?.minus(hw!!.memory!!.available)
|
||||
|
||||
/**
|
||||
* Returns the size of a
|
||||
* memory page in bytes.
|
||||
*
|
||||
* @return size of a memory page in bytes
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getMemoryPageSize(): Long? = hw?.memory?.pageSize
|
||||
|
||||
// -------> CPU
|
||||
/**
|
||||
* Returns the maximum clock speed of
|
||||
* the logical processors of the CPU
|
||||
* installed in this computer in Hz.
|
||||
*
|
||||
* @return maximum clock speed of logical processors in Hz or `-1` if it couldn't be determined
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getCPUMaximumFrequency(): Long? = hw?.processor?.maxFreq
|
||||
|
||||
/**
|
||||
* Returns the estimated current clock
|
||||
* speed of the logical processors of the
|
||||
* CPU installed in this computer in Hz.
|
||||
*
|
||||
* Each item in the returned array
|
||||
* stands for one logical processor.
|
||||
*
|
||||
* Depending on the platform the engine
|
||||
* runs on, this may or may not be
|
||||
* implemented. The algorithm used for
|
||||
* calculating this estimate depends on
|
||||
* the platform targeted. Some special
|
||||
* restrictions apply to certain platforms.
|
||||
* In short: Do not rely on the values
|
||||
* in the array returned by this method.
|
||||
*
|
||||
* @return current clock rate of logical processors in Hz or an empty array
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getCPUCurrentFrequency(): LongArray? = hw?.processor?.currentFreq
|
||||
|
||||
/**
|
||||
* Returns the current amount of
|
||||
* logical processors of the CPU
|
||||
* installed in this computer.
|
||||
*
|
||||
* This value may change over time
|
||||
* on some platforms. Be sure to
|
||||
* query this number frequently to
|
||||
* avoid out of date information.
|
||||
*
|
||||
* @return amount of logical processors
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getCPULogicalCount(): Int? = hw?.processor?.logicalProcessorCount
|
||||
|
||||
/**
|
||||
* Returns the amount of physical
|
||||
* processors installed in this computer.
|
||||
*
|
||||
* @return amount of physical processors
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getCPUPhysicalCount(): Int? = hw?.processor?.physicalProcessorCount
|
||||
|
||||
// -------> CPU
|
||||
/**
|
||||
* Returns an array of graphics cards
|
||||
* installed in this computer.
|
||||
*
|
||||
* @return array of [GraphicsCard] instances
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getGPUs(): Array<GraphicsCard>? = hw?.graphicsCards?.map { graphicsCard -> GraphicsCard(graphicsCard) }?.toTypedArray()
|
||||
}
|
||||
|
||||
// -----> Data types
|
||||
/**
|
||||
* Represents all operating systems
|
||||
* detected and supported by the engine.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
enum class OperatingSystem {
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [Linux](https://kernel.org) kernel
|
||||
* on some kind of Linux distribution.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
LINUX,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [FreeBSD](https://freebsd.org) kernel
|
||||
* and likely the FreeBSD operating system.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
FREEBSD,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [NetBSD](https://netbsd.org) kernel
|
||||
* and likely the NetBSD operating system.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
NETBSD,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under the [OpenBSD](https://openbsd.org) kernel
|
||||
* and likely the OpenBSD operating system.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
OPENBSD,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under [Android](https://android.com), and
|
||||
* by extension the [Linux kernel](https://kernel.org).
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
ANDROID,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under [Windows](https://windows.com), and
|
||||
* by extension the [Windows NT kernel](https://en.wikipedia.org/wiki/Ntoskrnl.exe).
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
WINDOWS,
|
||||
|
||||
/**
|
||||
* Identifies that the application is running
|
||||
* under [macOS](https://apple.com/macos), and
|
||||
* by extension under the [XNU kernel](https://github.com/apple-oss-distributions/xnu).
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
MACOS;
|
||||
|
||||
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.utility." else ""}Environment\$OperatingSystem.${name}"
|
||||
|
||||
/**
|
||||
* Returns the human-friendly name
|
||||
* of this operating system.
|
||||
*
|
||||
* @return human-friendly name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun humanFriendly(): String = when (this) {
|
||||
LINUX -> "Linux"
|
||||
FREEBSD -> "FreeBSD"
|
||||
NETBSD -> "NetBSD"
|
||||
OPENBSD -> "OpenBSD"
|
||||
ANDROID -> "Android"
|
||||
WINDOWS -> "Windows"
|
||||
MACOS -> "macOS"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a graphics card.
|
||||
*
|
||||
* @constructor Initializes this class
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
class GraphicsCard internal constructor(val graphicsCard: oshi.hardware.GraphicsCard) {
|
||||
/**
|
||||
* Returns the name of this graphics card.
|
||||
*
|
||||
* @return name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getName(): String = graphicsCard.name
|
||||
|
||||
/**
|
||||
* Returns the device identifier
|
||||
* of this graphics card.
|
||||
*
|
||||
* @return device identifier
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getDeviceIdentifier(): String = graphicsCard.deviceId
|
||||
|
||||
/**
|
||||
* Returns the name of the manufacturer
|
||||
* of this graphics card.
|
||||
*
|
||||
* @return manufacturer name
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getManufacturer(): String = graphicsCard.vendor
|
||||
|
||||
/**
|
||||
* Returns the version of
|
||||
* this graphics card.
|
||||
*
|
||||
* @return version
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getVersion(): String = graphicsCard.versionInfo
|
||||
|
||||
/**
|
||||
* Returns the amount of VRAM provided
|
||||
* by this graphics card in bytes.
|
||||
*
|
||||
* @return amount of total VRAM
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun getVideoMemory(): Long = graphicsCard.vRam
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ import java.io.IOException
|
|||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.nio.file.attribute.PosixFilePermissions
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* Provides a simplified way of
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue