@tokamakdev/platform-android-arm64 0.1.1-beta.152 → 0.1.1-beta.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android-arm64/lib/TokamakRuntime/libtokamak.a +2 -2
- package/android-arm64/native-shell/app/TokamakApplication.kt +1 -1
- package/android-arm64/native-shell/plugin/TokamakExports.kt +1 -1
- package/android-arm64/native-shell/plugin/TokamakPlugin.kt +3 -22
- package/android-arm64/native-shell/plugin/TokamakPluginRequests.kt +9 -14
- package/android-arm64/native-shell/plugin/TokamakResources.kt +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/android-arm64/lib/TokamakRuntime/libtokamak.a
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 35491552 bytes
|
|
4
|
+
sha256: c6c8fa2befb1c13110a8277ac80a59d60429bd236abca8351ff68e17dc66e372
|
|
@@ -58,7 +58,7 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
58
58
|
/** The running runtime, started on first use. Blocks while it starts. */
|
|
59
59
|
internal val runtime: TokamakRuntime by started
|
|
60
60
|
|
|
61
|
-
private lateinit var workerRequests: TokamakPluginRequests
|
|
61
|
+
private lateinit var workerRequests: TokamakPluginRequests
|
|
62
62
|
|
|
63
63
|
/** The plugins as the runtime calls them, on its own threads. */
|
|
64
64
|
private val workerPlugins =
|
|
@@ -259,7 +259,7 @@ abstract class TokamakDispatch<P : TokamakPlugin>(val plugin: P, protected val h
|
|
|
259
259
|
|
|
260
260
|
/** Retains [value], replying with its ID, until the subscription ends. */
|
|
261
261
|
protected fun retain(reply: TokamakPluginBytesReply, value: Any): () -> Unit =
|
|
262
|
-
host.resources.retain(value
|
|
262
|
+
host.resources.retain(value, reply)
|
|
263
263
|
|
|
264
264
|
/** Retains what the suspending [block] returns, replying with its ID, until the subscription ends. */
|
|
265
265
|
protected fun retain(method: String, reply: TokamakPluginBytesReply, block: suspend () -> Any): () -> Unit {
|
|
@@ -119,7 +119,7 @@ private val uiExecutor by lazy {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* A native plugin, created once per process with the app's [TokamakHost]. A
|
|
122
|
+
* A native plugin, created once per process with the app's [TokamakHost]. A call or subscription
|
|
123
123
|
* that throws replies with the exception.
|
|
124
124
|
*/
|
|
125
125
|
interface TokamakPlugin {
|
|
@@ -136,15 +136,10 @@ interface TokamakPlugin {
|
|
|
136
136
|
payload: ByteArray,
|
|
137
137
|
body: TokamakPluginBody,
|
|
138
138
|
reply: TokamakPluginBytesReply,
|
|
139
|
-
): (() -> Unit)? =
|
|
140
|
-
call(method, decodePluginValue(payload), body) {
|
|
141
|
-
reply(TokamakPluginResult.encoded(it.mapCatching(::encodePluginValue), true))
|
|
142
|
-
}
|
|
139
|
+
): (() -> Unit)? = throw TokamakPluginError.notSupported("$id.$method does not take a body")
|
|
143
140
|
|
|
144
141
|
fun subscribeBytes(method: String, payload: ByteArray, reply: TokamakPluginBytesReply): () -> Unit =
|
|
145
|
-
|
|
146
|
-
reply(TokamakPluginResult.encoded(it.mapCatching(::encodePluginValue), false))
|
|
147
|
-
}
|
|
142
|
+
throw TokamakPluginError.notSupported("$id.$method is not supported")
|
|
148
143
|
|
|
149
144
|
/** Returns cancellation for pending work when the platform supports it. */
|
|
150
145
|
fun call(method: String, arguments: Any?, reply: TokamakPluginReply): (() -> Unit)? {
|
|
@@ -152,20 +147,6 @@ interface TokamakPlugin {
|
|
|
152
147
|
return null
|
|
153
148
|
}
|
|
154
149
|
|
|
155
|
-
/** A call whose [body] of bytes the Worker streams, which the plugin reads one chunk at a time. */
|
|
156
|
-
fun call(method: String, arguments: Any?, body: TokamakPluginBody, reply: TokamakPluginReply): (() -> Unit)? {
|
|
157
|
-
reply(Result.failure(TokamakPluginError.notSupported("$id.$method does not take a body")))
|
|
158
|
-
return null
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
fun subscribe(
|
|
162
|
-
method: String,
|
|
163
|
-
arguments: Any?,
|
|
164
|
-
reply: TokamakPluginReply,
|
|
165
|
-
): () -> Unit {
|
|
166
|
-
throw TokamakPluginError.notSupported("$id.$method is not supported")
|
|
167
|
-
}
|
|
168
|
-
|
|
169
150
|
/** Receives the intent that started the app's activity, and each intent it receives later. */
|
|
170
151
|
fun onIntent(intent: Intent) = Unit
|
|
171
152
|
}
|
|
@@ -9,10 +9,10 @@ enum class TokamakPluginRequest { CALL, CALL_WITH_BODY, SUBSCRIBE }
|
|
|
9
9
|
* Runs the Worker's requests on the executor each plugin chooses, and passes replies straight to the
|
|
10
10
|
* runtime with [send]; [pull] asks the Worker for the next chunk of a call's body.
|
|
11
11
|
*/
|
|
12
|
-
class TokamakPluginRequests
|
|
12
|
+
class TokamakPluginRequests(
|
|
13
13
|
private val plugins: Map<String, TokamakPlugin>,
|
|
14
|
-
private val pull: (
|
|
15
|
-
private val send: (
|
|
14
|
+
private val pull: (Long) -> Unit,
|
|
15
|
+
private val send: (Long, TokamakPluginResult) -> Unit,
|
|
16
16
|
) {
|
|
17
17
|
/** A pending call or subscription. Only its serial executor touches [cancellation], so a cancellation runs after the operation started. */
|
|
18
18
|
private class Request(val executor: Executor) {
|
|
@@ -20,9 +20,9 @@ class TokamakPluginRequests<K>(
|
|
|
20
20
|
var cancellation: (() -> Unit)? = null
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
private val pending = mutableMapOf<
|
|
23
|
+
private val pending = mutableMapOf<Long, Request>()
|
|
24
24
|
|
|
25
|
-
fun run(key:
|
|
25
|
+
fun run(key: Long, kind: TokamakPluginRequest, plugin: String, method: String, payload: ByteArray) {
|
|
26
26
|
val target = plugins[plugin]
|
|
27
27
|
if (target == null || method.isEmpty()) {
|
|
28
28
|
send(key, failure(TokamakPluginError.notSupported("Plugin is not supported")))
|
|
@@ -55,19 +55,14 @@ class TokamakPluginRequests<K>(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** Answers the pending read of the call [key]'s body with the chunk the Worker sent. */
|
|
58
|
-
fun chunk(key:
|
|
58
|
+
fun chunk(key: Long, chunk: TokamakPluginResult) {
|
|
59
59
|
synchronized(pending) { pending[key]?.body }?.receive(chunk)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
fun cancel(key:
|
|
62
|
+
fun cancel(key: Long) {
|
|
63
63
|
synchronized(pending) { pending.remove(key) }?.let(::cancel)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
fun cancelAll() {
|
|
67
|
-
val requests = synchronized(pending) { pending.values.toList().also { pending.clear() } }
|
|
68
|
-
requests.forEach(::cancel)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
66
|
/** Runs the operation's cancellation on its executor. */
|
|
72
67
|
private fun cancel(request: Request) {
|
|
73
68
|
request.executor.execute {
|
|
@@ -76,10 +71,10 @@ class TokamakPluginRequests<K>(
|
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
private fun isPending(key:
|
|
74
|
+
private fun isPending(key: Long, request: Request) = synchronized(pending) { pending[key] === request }
|
|
80
75
|
|
|
81
76
|
/** Removes [request], returning whether it was pending. */
|
|
82
|
-
private fun remove(key:
|
|
77
|
+
private fun remove(key: Long, request: Request) = synchronized(pending) {
|
|
83
78
|
(pending[key] === request).also { if (it) pending.remove(key) }
|
|
84
79
|
}
|
|
85
80
|
|
|
@@ -7,10 +7,10 @@ class TokamakResources {
|
|
|
7
7
|
private val objects = HashMap<String, Any>()
|
|
8
8
|
|
|
9
9
|
/** Keeps [value], replies with its ID, and returns the release to return from `subscribe`. */
|
|
10
|
-
fun retain(value: Any, reply:
|
|
10
|
+
fun retain(value: Any, reply: TokamakPluginBytesReply): () -> Unit {
|
|
11
11
|
val id = UUID.randomUUID().toString()
|
|
12
12
|
synchronized(this) { objects[id] = value }
|
|
13
|
-
reply(
|
|
13
|
+
reply(TokamakPluginResult(encodePluginValue(id), false, false))
|
|
14
14
|
return { synchronized(this) { objects.remove(id) } }
|
|
15
15
|
}
|
|
16
16
|
|