package org.inaetics.dronessimulator.drone.components.radio;

import org.apache.log4j.Logger;
import org.inaetics.dronessimulator.common.protocol.TextMessage;
import org.inaetics.dronessimulator.common.protocol.MessageTopic;
import org.inaetics.dronessimulator.common.protocol.StateMessage;
import org.inaetics.dronessimulator.drone.droneinit.DroneInit;
import org.inaetics.dronessimulator.pubsub.api.Message;
import org.inaetics.dronessimulator.pubsub.api.MessageHandler;
import org.inaetics.dronessimulator.pubsub.api.subscriber.Subscriber;
import org.inaetics.dronessimulator.pubsub.api.publisher.Publisher;


import java.io.IOException;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Radio implements MessageHandler {
    private static final Logger logger = Logger.getLogger(Radio.class);

    private volatile Subscriber m_subscriber;
    private volatile Publisher m_publisher;
    private volatile DroneInit m_drone;
    private ConcurrentLinkedQueue<String> received_queue = new ConcurrentLinkedQueue<String>();

    /**
     * FELIX CALLBACKS
     */
    public void start() {
        try {
            this.m_subscriber.addTopic(MessageTopic.RADIO);
        } catch (IOException e) {
            logger.fatal(e);
        }
        this.m_subscriber.addHandler(StateMessage.class, this);
    }

    public void sendText(String text){
        TextMessage msg = new TextMessage();
        msg.setText(text);
        try{
            m_publisher.send(MessageTopic.RADIO, msg);
        } catch(IOException e){
            logger.fatal(e);
        }
    }

    public ConcurrentLinkedQueue<String> getMessages(){
        return received_queue;
    }

    /**
     * -- MESSAGEHANDLER
     */
    public void handleMessage(Message message) {
        if (message instanceof TextMessage){
            TextMessage textMessage = (TextMessage) message;
            received_queue.add(textMessage.getText());

        }
    }

}

@@ -686,16 +686,93 @@
 Queue;%0A%0A
+/**%0A * Radio component wich makes drone to drone communication possible.%0A */%0A
 public c
@@ -810,16 +810,50 @@
 ndler %7B%0A
+    /**%0A     * The logger%0A     */%0A
     priv
@@ -913,24 +913,66 @@
 io.class);%0A%0A
+    /** Reference to Subscriber bundle */%0A
     private 
@@ -1001,24 +1001,65 @@
 subscriber;%0A
+    /** Reference to Publisher bundle */%0A
     private 
@@ -1086,24 +1086,66 @@
 _publisher;%0A
+    /** Reference to Drone Init bundle */%0A
     private 
@@ -1172,16 +1172,55 @@
 _drone;%0A
+    /** Queue with received strings */%0A
     priv
@@ -1583,32 +1583,140 @@
 , this);%0A    %7D%0A%0A
+    /**%0A     * Sends a text to other drones through the radio%0A     * @param text the text to send.%0A     */%0A%0A
     public void 
@@ -1952,24 +1952,125 @@
    %7D%0A    %7D%0A%0A
+    /**%0A     * Retrieves the queue with received messages%0A     * @return queue with messages%0A     */%0A
     public C

Add documentation to radio