package jp.naist.inet_lab.android.ipv6multicast;

import android.content.Context;
import android.net.wifi.WifiManager;

/**
 * Manage communicating over the IP multicast.
 * 
 * @author yohei-ka
 * 
 */
public class MulticastManager {

    /**
     * A state of a MulticastLock on the WiFi interface
     */
    protected WifiManager.MulticastLock multicast_lock;

    public MulticastManager() {

    }

    /**
     * Join the specified multicast group.
     * 
     * @param group_address
     *            Address of the multicast group (Human readable string)
     */
    public void join(String group_address) {

    }

    /**
     * Leave the multicast group that already joined.
     */
    public void leave() {

    }

    /**
     * Send data to the joined multicast group.
     * 
     * @param data
     *            Data that you want to send
     * @return Size of the data that I actually sent
     */
    public int sendData(byte[] data) {
        return 0;
    }

    /**
     * Receive data from the joined multicast group.
     * 
     * @param buffer_size
     *            Maximum size by byte that I receive
     * @return Size of the data that I actually received
     */
    public int receiveData(int buffer_size) {
        return 0;
    }

    /**
     * Enable IP multicast on WiFi interface.
     * 
     * A developer who want to use IP multicast on WiFi interface MUST call this
     * method manually before joining a multicast group. Also, you don't forget
     * to call disableMulticastOnWifi(). It may cause battery issue if you
     * forget to call that method.
     * 
     * 
     * @param context
     *            Context of the application
     * @param tag
     *            A tag for identify a state of the WiFi. This tag is only used
     *            internally.
     */
    public void enableMulticastOnWifi(Context context, String tag) {
        WifiManager wifiman = (WifiManager) context
                .getSystemService(android.content.Context.WIFI_SERVICE);
        this.multicast_lock = wifiman.createMulticastLock(tag);
        this.multicast_lock.setReferenceCounted(true);
        this.multicast_lock.acquire();
    }

    /**
     * Disable IP multicast on WiFi interface.
     */
    public void disableMulticastOnWifi() {
        this.multicast_lock.release();
    }

}

@@ -43,16 +43,145 @@
 icast;%0A%0A
+import java.io.IOException;%0Aimport java.net.InetAddress;%0Aimport java.net.MulticastSocket;%0Aimport java.net.UnknownHostException;%0A%0A
 import a
@@ -354,24 +354,220 @@
 tManager %7B%0A%0A
+    /**%0A     * An address of the joined multicast group.%0A     */%0A    InetAddress group_address;%0A%0A    /**%0A     * A socket for communicating over the multicast.%0A     */%0A    MulticastSocket socket;%0A%0A
     /**%0A    
@@ -809,16 +809,19 @@
 _address
+_hr
 %0A     * 
@@ -832,16 +832,19 @@
        A
+n a
 ddress o
@@ -875,79 +875,1234 @@
 uman
- readable string)%0A     */%0A    public void join(String group_address) %7B%0A
+-readable string)%0A     * @param local_port%0A     *            A port number which bind on the local. If specify 0 as a port%0A     *            number, it may automatically choose a port number from%0A     *            available ports.%0A     * @throws UnknownHostException%0A     *             The specified group address is not found, or invalid format.%0A     */%0A    public void join(String group_address_hr, int local_port)%0A            throws UnknownHostException %7B%0A        // Convert the human-readable address to a machine-readable address%0A        this.group_address = InetAddress.getByName(group_address_hr);%0A%0A        // Create a socket and join the multicast group%0A        try %7B%0A            this.socket = new MulticastSocket(local_port);%0A            this.socket.joinGroup(this.group_address);%0A        %7D catch (IOException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    /**%0A     * Join the specified multicast group.%0A     * %0A     * A local port will automatically chosen from available ports.%0A     * %0A     * @see MulticastManager#join(String, int)%0A     */%0A    public void join(String group_address_hr) throws UnknownHostException %7B%0A        this.join(group_address_hr, 0);
 %0A   

Implement MulticastManager#join, with except to handling the IOException.