send a message to wot and see what comes back
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / plugin / PluginConnector.java
index b842350..2e01f74 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - PluginConnector.java - Copyright © 2010–2012 David Roden
+ * Sone - PluginConnector.java - Copyright © 2010–2015 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 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;
@@ -35,7 +43,10 @@ import freenet.support.api.Bucket;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class PluginConnector implements FredPluginTalker {
+@Singleton
+public class PluginConnector implements FredPluginTalker, ClientSideFCPMessageHandler {
+
+       private static final Logger logger = Logger.getLogger(PluginConnector.class.getName());
 
        /** The event bus. */
        private final EventBus eventBus;
@@ -57,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.