3ec52cee42f55543e857e24e80e2477331022cf7
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / freenet / plugin / PluginRespiratorFacade.kt
1 /**
2  * Sone - PluginRespiratorFacade.kt - Copyright © 2019 David ‘Bombe’ Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /* Yes, this handle Fred-based stuff that’s mostly deprecated. */
19 @file:Suppress("DEPRECATION")
20
21 package net.pterodactylus.sone.freenet.plugin
22
23 import freenet.pluginmanager.*
24 import freenet.support.*
25 import freenet.support.api.*
26 import javax.inject.*
27
28 /**
29  * Facade for the only method of a [plugin respirator][PluginRespirator] that Sone actually uses,
30  * for easier testing.
31  */
32 interface PluginRespiratorFacade {
33
34         @Throws(PluginNotFoundException::class)
35         fun getPluginTalker(pluginTalker: FredPluginTalker, pluginName: String, identifier: String): PluginTalkerFacade
36
37 }
38
39 /**
40  * Facade for a [plugin talker][PluginTalker], for easier testing.
41  */
42 interface PluginTalkerFacade {
43
44         fun send(pluginParameters: SimpleFieldSet, data: Bucket?)
45
46 }
47
48 /**
49  * Fred-based [PluginRespiratorFacade] implementation that proxies the given real [PluginRespirator].
50  */
51 class FredPluginRespiratorFacade @Inject constructor(private val pluginRespirator: PluginRespirator) : PluginRespiratorFacade {
52
53         override fun getPluginTalker(pluginTalker: FredPluginTalker, pluginName: String, identifier: String) =
54                         FredPluginTalkerFacade(pluginRespirator.getPluginTalker(pluginTalker, pluginName, identifier))
55
56 }
57
58 /**
59  * Fred-based [PluginTalkerFacade] implementation that proxies the given real [PluginTalker].
60  */
61 class FredPluginTalkerFacade(private val pluginTalker: PluginTalker) : PluginTalkerFacade {
62
63         override fun send(pluginParameters: SimpleFieldSet, data: Bucket?) =
64                         pluginTalker.send(pluginParameters, data)
65
66 }