broadcast -> send

This commit is contained in:
Alexander Nozik 2023-08-16 20:27:23 +03:00
parent ce03540b37
commit 82dbb3a1f0
7 changed files with 13 additions and 13 deletions

View File

@ -12,7 +12,7 @@ import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.names.Name
import space.kscience.magix.api.MagixEndpoint
import space.kscience.magix.api.broadcast
import space.kscience.magix.api.send
import space.kscience.magix.api.subscribe
import kotlin.coroutines.CoroutineContext
@ -108,6 +108,6 @@ public class DeviceClient(
public fun MagixEndpoint.remoteDevice(context: Context, magixTarget: String, deviceName: Name): DeviceClient {
val subscription = subscribe(DeviceManager.magixFormat, originFilter = listOf(magixTarget)).map { it.second }
return DeviceClient(context, deviceName, subscription) {
broadcast(DeviceManager.magixFormat, it, magixTarget, id = stringUID())
send(DeviceManager.magixFormat, it, magixTarget, id = stringUID())
}
}

View File

@ -40,7 +40,7 @@ public fun DeviceManager.connectToMagix(
endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID)).onEach { (request, payload) ->
val responsePayload = respondHubMessage(payload)
if (responsePayload != null) {
endpoint.broadcast(
endpoint.send(
format = controlsMagixFormat,
target = request.sourceEndpoint,
origin = endpointID,
@ -54,7 +54,7 @@ public fun DeviceManager.connectToMagix(
}.launchIn(this)
hubMessageFlow(this).onEach { payload ->
endpoint.broadcast(
endpoint.send(
format = controlsMagixFormat,
origin = endpointID,
payload = payload,

View File

@ -75,7 +75,7 @@ public fun DeviceManager.launchTangoMagix(
): Job {
suspend fun respond(request: MagixMessage, payload: TangoPayload, payloadBuilder: (TangoPayload) -> TangoPayload) {
endpoint.broadcast(
endpoint.send(
tangoMagixFormat,
id = generateId(request),
parentId = request.id,
@ -125,7 +125,7 @@ public fun DeviceManager.launchTangoMagix(
}
} catch (ex: Exception) {
logger.error(ex) { "Error while responding to message" }
endpoint.broadcast(
endpoint.send(
tangoMagixFormat,
id = generateId(request),
parentId = request.id,

View File

@ -56,6 +56,6 @@ public interface MagixEndpoint {
}
/**
* An alias for [MagixEndpoint.broadcast]
* An alias for [MagixEndpoint.send]
*/
public suspend fun MagixEndpoint.send(message: MagixMessage): Unit = broadcast(message)

View File

@ -38,7 +38,7 @@ public fun <T> MagixEndpoint.subscribe(
* Send a message using given [format] to encode the message payload. The format field is also taken from [format].
*
*/
public suspend fun <T> MagixEndpoint.broadcast(
public suspend fun <T> MagixEndpoint.send(
format: MagixFormat<T>,
payload: T,
target: String? = null,

View File

@ -10,7 +10,7 @@ import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonNull
import space.kscience.magix.api.MagixEndpoint
import space.kscience.magix.api.MagixFormat
import space.kscience.magix.api.broadcast
import space.kscience.magix.api.send
import space.kscience.magix.api.subscribe
/**
@ -67,12 +67,12 @@ public fun CoroutineScope.launchMagixRegistry(
if (payload is MagixRegistryRequestMessage) {
try {
val value = registry.request(payload.propertyName, magixMessage.user)
endpoint.broadcast(
endpoint.send(
MagixRegistryMessage.format,
MagixRegistryValueMessage(payload.propertyName, value ?: JsonNull)
)
} catch (ex: Exception){
endpoint.broadcast(
endpoint.send(
MagixRegistryMessage.format,
MagixRegistryErrorMessage(payload.propertyName, ex::class.simpleName, ex.message)
)

View File

@ -9,7 +9,7 @@ import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import space.kscience.magix.api.MagixEndpoint
import space.kscience.magix.api.MagixMessage
import space.kscience.magix.api.broadcast
import space.kscience.magix.api.send
import space.kscience.magix.api.subscribe
internal fun generateId(request: MagixMessage): String = if (request.id != null) {
@ -47,7 +47,7 @@ public fun MagixEndpoint.launchHistory(
pageNumber,
lastPage = end
)
broadcast(
send(
format = MagixHistory.magixFormat,
payload = sendPayload,
target = request.sourceEndpoint,