import java.lang.reflect.*;
import java.net.URL;
import gw.*;

public class Ex2_6
{
    public static double TIMEOUT = 2.0;
    private GWPort proxy;

    Ex2_6(String gateway)
    {
        try {
            URL portURL = new URL("http://restsoap:AIIT@" + gateway + "/gw/soap");
            GWServiceLocator locator = new GWServiceLocator();
            proxy = locator.getGWPort(portURL);
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(2);
        }
    }

    public void get(double t1Offset, double t2Offset, String name, String addr)
    {
        GW__eventsReadRelative_Result result;
        GW__Event_Result[] results;
        GW__Event value;
        Nx_node_stats_t event;
        org.apache.axis.types.UnsignedInt offset = 
          new org.apache.axis.types.UnsignedInt(0);

        try {
            // TODO: begin
            //result = <fill-in-your-code>;
            //results = result.getResults();
            //for (int i = 0; i < results.length; i++) {
            //    value = <fill-in-your-code>;
            //    event = <fill-in-your-code>;
            //    System.out.println( 
            //      "Mote " + <fill-in-your-code> +
            //      " timestamp " + <fill-in-your-code> + 
            //      " sent " + <fill-in-your-code> +
            //      " delivered " + <fill-in-your-code>
            //    );
            //}
            // TODO: end
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(2);
        }
    }

    public static void main(String [] args)
    {
        if (args.length != 1 && args.length != 2) {
            System.out.println("Usage: java Ex2_6 gateway [mote]");
            System.exit(3);
        }
        String gateway = args[0];
        String attrName;
        String mote;
        if (args.length == 1)
            mote = "ffffffffffffffff";
        else
            mote = args[1];
        Ex2_6 get = new Ex2_6(gateway);

        double t1Offset = -86400.0;   // one day before
        double t2Offset = 0.0;        // now
        attrName = "NodeStatsEvent";

        get.get(t1Offset, t2Offset, attrName, mote);
    }
}