package meerkat.comm;

import com.google.protobuf.Message;
import meerkat.protobuf.Comm;

/**
 * A generic communication channel that supports point-to-point and broadcast operation
 */

public interface Channel {
    /**
     * Return the id of the channel's endpoint (this will be used as the source of message sent from the channel).
     * @return
     */
    public int getSourceId();

    public interface ReceiverCallback {
        public void receiveMessage(Comm.BroadcastMessage envelope);
    }

    /**
     * sends a private message
     * @param destUser destination user's identifier
     * @param msg message
     */
    public void sendMessage(int destUser, Message msg);


    /**
     * broadcasts a message to all parties (including the sender)
     * @param msg message
     */
    public void broadcastMessage(Message msg);

    /**
     * Register a callback to handle received messages.
     * The callback is called in the <b>Channel</b> thread, so no long processing should
     * occur in the callback method.
     * @param callback
     */
    public void registerReceiverCallback(ReceiverCallback callback);
}
