send a message to wot and see what comes back
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / plugin / PluginConnector.java
index 46343a3..2e01f74 100644 (file)
 
 package net.pterodactylus.sone.freenet.plugin;
 
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
 import net.pterodactylus.sone.freenet.plugin.event.ReceivedReplyEvent;
 
 import com.google.common.eventbus.EventBus;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
+import freenet.clients.fcp.FCPPluginConnection;
+import freenet.clients.fcp.FCPPluginMessage;
+import freenet.pluginmanager.FredPluginFCPMessageHandler.ClientSideFCPMessageHandler;
 import freenet.pluginmanager.FredPluginTalker;
 import freenet.pluginmanager.PluginNotFoundException;
 import freenet.pluginmanager.PluginRespirator;
@@ -37,7 +44,9 @@ import freenet.support.api.Bucket;
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 @Singleton
-public class PluginConnector implements FredPluginTalker {
+public class PluginConnector implements FredPluginTalker, ClientSideFCPMessageHandler {
+
+       private static final Logger logger = Logger.getLogger(PluginConnector.class.getName());
 
        /** The event bus. */
        private final EventBus eventBus;
@@ -59,9 +68,24 @@ public class PluginConnector implements FredPluginTalker {
                this.pluginRespirator = pluginRespirator;
        }
 
-       //
-       // ACTIONS
-       //
+       public void start() throws PluginException {
+               try {
+                       FCPPluginConnection pluginConnection = pluginRespirator.connectToOtherPlugin("plugins.WebOfTrust.WebOfTrust", this);
+                       logger.fine("Got PluginConnection: " + pluginConnection);
+                       SimpleFieldSet simpleFieldSet = new SimpleFieldSetBuilder().put("Message", "Subscribe").put("To", "Identities").get();
+                       pluginConnection.send(FCPPluginMessage.construct(simpleFieldSet, null));
+               } catch (PluginNotFoundException pnfe1) {
+                       throw new PluginException(pnfe1);
+               } catch (IOException ioe1) {
+                       throw new PluginException(ioe1);
+               }
+       }
+
+       @Override
+       public FCPPluginMessage handlePluginFCPMessage(FCPPluginConnection connection, FCPPluginMessage message) {
+               logger.fine("Got Reply: " + message);
+               return null;
+       }
 
        /**
         * Sends a request to the given plugin.