Skip to content

Commit

Permalink
Remove ICallbackMsg, inherit CallbackMsg directly
Browse files Browse the repository at this point in the history
  • Loading branch information
LossyDragon committed Sep 29, 2024
1 parent 189a511 commit 7c7b6ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import `in`.dragonbra.javasteam.steam.handlers.steamuser.SteamUser
import `in`.dragonbra.javasteam.steam.handlers.steamuserstats.SteamUserStats
import `in`.dragonbra.javasteam.steam.handlers.steamworkshop.SteamWorkshop
import `in`.dragonbra.javasteam.steam.steamclient.callbackmgr.CallbackMsg
import `in`.dragonbra.javasteam.steam.steamclient.callbackmgr.ICallbackMsg
import `in`.dragonbra.javasteam.steam.steamclient.callbacks.CMListCallback
import `in`.dragonbra.javasteam.steam.steamclient.callbacks.ConnectedCallback
import `in`.dragonbra.javasteam.steam.steamclient.callbacks.DisconnectedCallback
Expand Down Expand Up @@ -57,7 +56,7 @@ class SteamClient @JvmOverloads constructor(

private val processStartTime: Date

private val callbackQueue = Channel<ICallbackMsg>(Channel.UNLIMITED)
private val callbackQueue = Channel<CallbackMsg>(Channel.UNLIMITED)

internal val jobManager: AsyncJobManager // What does this even do now?

Expand Down Expand Up @@ -142,28 +141,28 @@ class SteamClient @JvmOverloads constructor(
* Gets the next callback object in the queue, and removes it.
* @return The next callback in the queue, or null if no callback is waiting.
*/
fun getCallback(): ICallbackMsg? = callbackQueue.tryReceive().getOrNull()
fun getCallback(): CallbackMsg? = callbackQueue.tryReceive().getOrNull()

/**
* Blocks the calling thread until a callback object is posted to the queue, and removes it.
* @return The callback object from the queue.
*/
fun waitForCallback(): ICallbackMsg = runBlocking(Dispatchers.Default) {
fun waitForCallback(): CallbackMsg = runBlocking(Dispatchers.Default) {
callbackQueue.receive()
}

/**
* Asynchronously awaits until a callback object is posted to the queue, and removes it.
* @return The callback object from the queue.
*/
suspend fun waitForCallbackAsync(): ICallbackMsg = callbackQueue.receive()
suspend fun waitForCallbackAsync(): CallbackMsg = callbackQueue.receive()

/**
* Blocks the calling thread until a callback object is posted to the queue, or null after the timeout has elapsed.
* @param timeout The length of time to block in ms.
* @return A callback object from the queue if a callback has been posted, or null if the timeout has elapsed.
*/
fun waitForCallback(timeout: Long): ICallbackMsg? = runBlocking {
fun waitForCallback(timeout: Long): CallbackMsg? = runBlocking {
withTimeoutOrNull(timeout) {
callbackQueue.receive()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import `in`.dragonbra.javasteam.util.compat.Consumer
import java.io.Closeable

@Suppress("unused")
class Callback<TCall : ICallbackMsg> @JvmOverloads constructor(
class Callback<TCall : CallbackMsg> @JvmOverloads constructor(
override val callbackType: Class<out TCall>,
func: Consumer<TCall>?,
private var mgr: ICallbackMgrInternals? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CallbackManager(private val steamClient: SteamClient) : ICallbackMgrIntern
* @return true if a callback has been run, false otherwise.
*/
fun runCallbacks(): Boolean {
val call: ICallbackMsg = steamClient.getCallback() ?: return false
val call = steamClient.getCallback() ?: return false

handle(call)
return true
Expand All @@ -40,7 +40,7 @@ class CallbackManager(private val steamClient: SteamClient) : ICallbackMgrIntern
* @return true if a callback has been run, false otherwise.
*/
fun runWaitCallbacks(timeout: Long): Boolean {
val call: ICallbackMsg = steamClient.waitForCallback(timeout) ?: return false
val call = steamClient.waitForCallback(timeout) ?: return false

handle(call)
return true
Expand Down Expand Up @@ -90,7 +90,7 @@ class CallbackManager(private val steamClient: SteamClient) : ICallbackMgrIntern
* @param callbackFunc The function to invoke with the callback.
* @return An [Closeable]. Disposing of the return value will unsubscribe the callbackFunc .
*/
fun <TCallback : ICallbackMsg> subscribe(
fun <TCallback : CallbackMsg> subscribe(
callbackType: Class<out TCallback>,
jobID: JobID,
callbackFunc: Consumer<TCallback>,
Expand All @@ -107,7 +107,7 @@ class CallbackManager(private val steamClient: SteamClient) : ICallbackMgrIntern
* @param callbackFunc The function to invoke with the callback.
* @return An [Closeable]. Disposing of the return value will unsubscribe the callbackFunc.
*/
fun <TCallback : ICallbackMsg> subscribe(
fun <TCallback : CallbackMsg> subscribe(
callbackType: Class<out TCallback>,
callbackFunc: Consumer<TCallback>,
): Closeable = subscribe(callbackType, JobID.INVALID, callbackFunc)
Expand All @@ -124,7 +124,7 @@ class CallbackManager(private val steamClient: SteamClient) : ICallbackMgrIntern
registeredCallbacks.remove(callback)
}

private fun handle(call: ICallbackMsg) {
private fun handle(call: CallbackMsg) {
val type = call.javaClass

// find handlers interested in this callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import `in`.dragonbra.javasteam.types.JobID
* @author lngtr
* @since 2018-02-22
*/
abstract class CallbackMsg : ICallbackMsg {
abstract class CallbackMsg {

/**
* Gets or sets the job ID this callback refers to. If it is not a job callback, it will be [JobID.INVALID].
*/
override var jobID: JobID = JobID.INVALID
var jobID: JobID = JobID.INVALID
}

This file was deleted.

0 comments on commit 7c7b6ad

Please sign in to comment.