Skip to content

Commit

Permalink
rename RemoteCall to RemoteObject
Browse files Browse the repository at this point in the history
  • Loading branch information
StageGuard committed Nov 16, 2024
1 parent b947b7c commit 2cc2b83
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class RemoteAnitorrentEngine(
override suspend fun getDownloader(): TorrentDownloader {
return RemoteTorrentDownloader(
fetchRemoteScope,
RetryRemoteCall(fetchRemoteScope) { getBinderOrFail().downlaoder },
RetryRemoteObject(fetchRemoteScope) { getBinderOrFail().downlaoder },
connectivityAware,
)
}
Expand All @@ -127,7 +127,7 @@ class RemoteAnitorrentEngine(
crossinline transact: I.(String) -> Unit
) = scope.launch {
val stateFlow = settingsFlow.stateIn(this)
val remoteCall = RetryRemoteCall(fetchRemoteScope) { getBinder() }
val remoteCall = RetryRemoteObject(fetchRemoteScope) { getBinder() }

connection.connected
.filter { it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import kotlin.coroutines.resumeWithException
/**
* Wrapper for remote call
*/
interface RemoteCall<I : IInterface> {
interface RemoteObject<I : IInterface> {
fun <R : Any?> call(block: I.() -> R): R
}

/**
* Impl for remote call safely with retry mechanism.
*/
class RetryRemoteCall<I : IInterface>(
class RetryRemoteObject<I : IInterface>(
private val scope: CoroutineScope,
private val getRemote: suspend () -> I
) : RemoteCall<I> {
) : RemoteObject<I> {
private val logger = logger(this::class)

private val remote: MutableStateFlow<I?> = MutableStateFlow(null)
Expand Down Expand Up @@ -91,7 +91,7 @@ class RetryRemoteCall<I : IInterface>(
*
* [IDisposableHandle] takes responsibility to pass cancellation to server.
*/
suspend inline fun <I : IInterface, T : Any> RemoteCall<I>.callSuspendCancellable(
suspend inline fun <I : IInterface, T : Any> RemoteObject<I>.callSuspendCancellable(
crossinline transact: I.(RemoteContinuation<T>) -> IDisposableHandle?,
): T = suspendCancellableCoroutine { cont ->
val disposable = call {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import kotlin.coroutines.CoroutineContext
@RequiresApi(Build.VERSION_CODES.O_MR1)
class RemoteTorrentDownloader(
private val fetchRemoteScope: CoroutineScope,
private val remote: RemoteCall<IRemoteTorrentDownloader>,
private val remote: RemoteObject<IRemoteTorrentDownloader>,
private val connectivityAware: ConnectivityAware
) : TorrentDownloader {
override val totalStats: Flow<TorrentDownloader.Stats> = callbackFlow {
Expand Down Expand Up @@ -94,7 +94,7 @@ class RemoteTorrentDownloader(
): TorrentSession {
return RemoteTorrentSession(
fetchRemoteScope,
RetryRemoteCall(fetchRemoteScope) {
RetryRemoteObject(fetchRemoteScope) {
remote.callSuspendCancellable { cont ->
startDownload(
data.toParceled(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.io.RandomAccessFile
@RequiresApi(Build.VERSION_CODES.O_MR1)
class RemoteTorrentFileEntry(
private val fetchRemoteScope: CoroutineScope,
private val remote: RemoteCall<IRemoteTorrentFileEntry>,
private val remote: RemoteObject<IRemoteTorrentFileEntry>,
private val connectivityAware: ConnectivityAware
) : TorrentFileEntry {
override val fileStats: Flow<TorrentFileEntry.Stats> = callbackFlow {
Expand Down Expand Up @@ -82,7 +82,7 @@ class RemoteTorrentFileEntry(
override fun createHandle(): TorrentFileHandle {
return RemoteTorrentFileHandle(
fetchRemoteScope,
RetryRemoteCall(fetchRemoteScope) { remote.call { createHandle() } },
RetryRemoteObject(fetchRemoteScope) { remote.call { createHandle() } },
connectivityAware,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import me.him188.ani.app.torrent.api.files.TorrentFileEntry
@RequiresApi(Build.VERSION_CODES.O_MR1)
class RemoteTorrentFileEntryList(
private val fetchRemoteScope: CoroutineScope,
private val remote: RemoteCall<IRemoteTorrentFileEntryList>,
private val remote: RemoteObject<IRemoteTorrentFileEntryList>,
private val connectivityAware: ConnectivityAware
) : AbstractList<TorrentFileEntry>() {
override val size: Int get() = remote.call { size }

override fun get(index: Int): TorrentFileEntry {
return RemoteTorrentFileEntry(
fetchRemoteScope,
RetryRemoteCall(fetchRemoteScope) { remote.call { get(index) } },
RetryRemoteObject(fetchRemoteScope) { remote.call { get(index) } },
connectivityAware,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import me.him188.ani.utils.coroutines.IO_
@RequiresApi(Build.VERSION_CODES.O_MR1)
class RemoteTorrentFileHandle(
private val fetchRemoteScope: CoroutineScope,
private val remote: RemoteCall<IRemoteTorrentFileHandle>,
private val remote: RemoteObject<IRemoteTorrentFileHandle>,
private val connectivityAware: ConnectivityAware
) : TorrentFileHandle {
override val entry: TorrentFileEntry
get() = RemoteTorrentFileEntry(
fetchRemoteScope,
RetryRemoteCall(fetchRemoteScope) { remote.call { torrentFileEntry } },
RetryRemoteObject(fetchRemoteScope) { remote.call { torrentFileEntry } },
connectivityAware,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import me.him188.ani.utils.coroutines.IO_
@RequiresApi(Build.VERSION_CODES.O_MR1)
class RemoteTorrentSession(
private val fetchRemoteScope: CoroutineScope,
private val remote: RemoteCall<IRemoteTorrentSession>,
private val remote: RemoteObject<IRemoteTorrentSession>,
private val connectivityAware: ConnectivityAware
) : TorrentSession {
override val sessionStats: Flow<TorrentSession.Stats?> = callbackFlow {
Expand Down Expand Up @@ -70,7 +70,7 @@ class RemoteTorrentSession(
override suspend fun getFiles(): List<TorrentFileEntry> {
return RemoteTorrentFileEntryList(
fetchRemoteScope,
RetryRemoteCall(fetchRemoteScope) {
RetryRemoteObject(fetchRemoteScope) {
remote.callSuspendCancellable { cont ->
getFiles(
object : ContTorrentSessionGetFiles.Stub() {
Expand Down

0 comments on commit 2cc2b83

Please sign in to comment.