1 /* Fred’s plugin stuff is mostly deprecated. ¯\_(ツ)_/¯ */
2 @file:Suppress("DEPRECATION")
4 package net.pterodactylus.sone.freenet.plugin
6 import freenet.pluginmanager.*
7 import freenet.support.*
8 import freenet.support.api.*
9 import kotlinx.coroutines.*
10 import kotlinx.coroutines.channels.*
14 * [PluginConnector] implementation that uses a [PluginRespiratorFacade] and coroutines to send
15 * a request to another plugin and receive a reply.
17 class FredPluginConnector @Inject constructor(private val pluginRespiratorFacade: PluginRespiratorFacade) : PluginConnector {
19 override suspend fun sendRequest(pluginName: String, fields: SimpleFieldSet, data: Bucket?): PluginReply {
20 val receivedReply = Channel<PluginReply>()
21 val responseReceiver = FredPluginTalker { _, _, responseFields, responseData ->
23 receivedReply.send(PluginReply(responseFields, responseData))
27 val pluginTalker = pluginRespiratorFacade.getPluginTalker(responseReceiver, pluginName, "")
28 pluginTalker.send(fields, data)
29 return receivedReply.receive()
30 } catch (e: PluginNotFoundException) {
31 throw PluginException(cause = e)