broadcast -> send
This commit is contained in:
parent
ce03540b37
commit
82dbb3a1f0
@ -12,7 +12,7 @@ import space.kscience.dataforge.meta.Meta
|
|||||||
import space.kscience.dataforge.misc.DFExperimental
|
import space.kscience.dataforge.misc.DFExperimental
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.magix.api.MagixEndpoint
|
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 space.kscience.magix.api.subscribe
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
@ -108,6 +108,6 @@ public class DeviceClient(
|
|||||||
public fun MagixEndpoint.remoteDevice(context: Context, magixTarget: String, deviceName: Name): DeviceClient {
|
public fun MagixEndpoint.remoteDevice(context: Context, magixTarget: String, deviceName: Name): DeviceClient {
|
||||||
val subscription = subscribe(DeviceManager.magixFormat, originFilter = listOf(magixTarget)).map { it.second }
|
val subscription = subscribe(DeviceManager.magixFormat, originFilter = listOf(magixTarget)).map { it.second }
|
||||||
return DeviceClient(context, deviceName, subscription) {
|
return DeviceClient(context, deviceName, subscription) {
|
||||||
broadcast(DeviceManager.magixFormat, it, magixTarget, id = stringUID())
|
send(DeviceManager.magixFormat, it, magixTarget, id = stringUID())
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,7 +40,7 @@ public fun DeviceManager.connectToMagix(
|
|||||||
endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID)).onEach { (request, payload) ->
|
endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID)).onEach { (request, payload) ->
|
||||||
val responsePayload = respondHubMessage(payload)
|
val responsePayload = respondHubMessage(payload)
|
||||||
if (responsePayload != null) {
|
if (responsePayload != null) {
|
||||||
endpoint.broadcast(
|
endpoint.send(
|
||||||
format = controlsMagixFormat,
|
format = controlsMagixFormat,
|
||||||
target = request.sourceEndpoint,
|
target = request.sourceEndpoint,
|
||||||
origin = endpointID,
|
origin = endpointID,
|
||||||
@ -54,7 +54,7 @@ public fun DeviceManager.connectToMagix(
|
|||||||
}.launchIn(this)
|
}.launchIn(this)
|
||||||
|
|
||||||
hubMessageFlow(this).onEach { payload ->
|
hubMessageFlow(this).onEach { payload ->
|
||||||
endpoint.broadcast(
|
endpoint.send(
|
||||||
format = controlsMagixFormat,
|
format = controlsMagixFormat,
|
||||||
origin = endpointID,
|
origin = endpointID,
|
||||||
payload = payload,
|
payload = payload,
|
||||||
|
@ -75,7 +75,7 @@ public fun DeviceManager.launchTangoMagix(
|
|||||||
): Job {
|
): Job {
|
||||||
|
|
||||||
suspend fun respond(request: MagixMessage, payload: TangoPayload, payloadBuilder: (TangoPayload) -> TangoPayload) {
|
suspend fun respond(request: MagixMessage, payload: TangoPayload, payloadBuilder: (TangoPayload) -> TangoPayload) {
|
||||||
endpoint.broadcast(
|
endpoint.send(
|
||||||
tangoMagixFormat,
|
tangoMagixFormat,
|
||||||
id = generateId(request),
|
id = generateId(request),
|
||||||
parentId = request.id,
|
parentId = request.id,
|
||||||
@ -125,7 +125,7 @@ public fun DeviceManager.launchTangoMagix(
|
|||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
logger.error(ex) { "Error while responding to message" }
|
logger.error(ex) { "Error while responding to message" }
|
||||||
endpoint.broadcast(
|
endpoint.send(
|
||||||
tangoMagixFormat,
|
tangoMagixFormat,
|
||||||
id = generateId(request),
|
id = generateId(request),
|
||||||
parentId = request.id,
|
parentId = request.id,
|
||||||
|
@ -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)
|
public suspend fun MagixEndpoint.send(message: MagixMessage): Unit = broadcast(message)
|
@ -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].
|
* 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>,
|
format: MagixFormat<T>,
|
||||||
payload: T,
|
payload: T,
|
||||||
target: String? = null,
|
target: String? = null,
|
||||||
|
@ -10,7 +10,7 @@ import kotlinx.serialization.json.JsonElement
|
|||||||
import kotlinx.serialization.json.JsonNull
|
import kotlinx.serialization.json.JsonNull
|
||||||
import space.kscience.magix.api.MagixEndpoint
|
import space.kscience.magix.api.MagixEndpoint
|
||||||
import space.kscience.magix.api.MagixFormat
|
import space.kscience.magix.api.MagixFormat
|
||||||
import space.kscience.magix.api.broadcast
|
import space.kscience.magix.api.send
|
||||||
import space.kscience.magix.api.subscribe
|
import space.kscience.magix.api.subscribe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,12 +67,12 @@ public fun CoroutineScope.launchMagixRegistry(
|
|||||||
if (payload is MagixRegistryRequestMessage) {
|
if (payload is MagixRegistryRequestMessage) {
|
||||||
try {
|
try {
|
||||||
val value = registry.request(payload.propertyName, magixMessage.user)
|
val value = registry.request(payload.propertyName, magixMessage.user)
|
||||||
endpoint.broadcast(
|
endpoint.send(
|
||||||
MagixRegistryMessage.format,
|
MagixRegistryMessage.format,
|
||||||
MagixRegistryValueMessage(payload.propertyName, value ?: JsonNull)
|
MagixRegistryValueMessage(payload.propertyName, value ?: JsonNull)
|
||||||
)
|
)
|
||||||
} catch (ex: Exception){
|
} catch (ex: Exception){
|
||||||
endpoint.broadcast(
|
endpoint.send(
|
||||||
MagixRegistryMessage.format,
|
MagixRegistryMessage.format,
|
||||||
MagixRegistryErrorMessage(payload.propertyName, ex::class.simpleName, ex.message)
|
MagixRegistryErrorMessage(payload.propertyName, ex::class.simpleName, ex.message)
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ import kotlinx.serialization.json.JsonElement
|
|||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
import space.kscience.magix.api.MagixEndpoint
|
import space.kscience.magix.api.MagixEndpoint
|
||||||
import space.kscience.magix.api.MagixMessage
|
import space.kscience.magix.api.MagixMessage
|
||||||
import space.kscience.magix.api.broadcast
|
import space.kscience.magix.api.send
|
||||||
import space.kscience.magix.api.subscribe
|
import space.kscience.magix.api.subscribe
|
||||||
|
|
||||||
internal fun generateId(request: MagixMessage): String = if (request.id != null) {
|
internal fun generateId(request: MagixMessage): String = if (request.id != null) {
|
||||||
@ -47,7 +47,7 @@ public fun MagixEndpoint.launchHistory(
|
|||||||
pageNumber,
|
pageNumber,
|
||||||
lastPage = end
|
lastPage = end
|
||||||
)
|
)
|
||||||
broadcast(
|
send(
|
||||||
format = MagixHistory.magixFormat,
|
format = MagixHistory.magixFormat,
|
||||||
payload = sendPayload,
|
payload = sendPayload,
|
||||||
target = request.sourceEndpoint,
|
target = request.sourceEndpoint,
|
||||||
|
Loading…
Reference in New Issue
Block a user