[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain/tools/java/net/tinyos/drain DrainConnector.java, 1.5, 1.6

Kamin Whitehouse kaminw at users.sourceforge.net
Wed Jul 20 10:10:11 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/java/net/tinyos/drain
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16470/Drain/tools/java/net/tinyos/drain

Modified Files:
	DrainConnector.java 
Log Message:
fixed some ugliness in the constructors

Index: DrainConnector.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/java/net/tinyos/drain/DrainConnector.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DrainConnector.java	16 Jul 2005 21:26:35 -0000	1.5
--- DrainConnector.java	20 Jul 2005 17:10:08 -0000	1.6
***************
*** 1,98 ****
! package net.tinyos.drain;
! 
! import net.tinyos.message.*;
! import net.tinyos.util.*;
! 
! import org.apache.log4j.*;
! 
! import java.io.*; 
! import java.text.*;
! import java.util.*;
! import java.net.*;
! 
! public class DrainConnector implements MessageListener {
! 
!   public static int TOS_UART_ADDR = 0x7e;
!   public static int DEFAULT_MOTE_ID = 0xfffe;
!   public static int BCAST_ID = 0xff;
!     
!   private MoteIF moteIF;
! 
!   private Logger log = Logger.getLogger(DrainConnector.class.getName());
! 
!   private int spAddr;
! 
!   private HashMap idTable = new HashMap();
! 
!   public DrainConnector() {
!     spAddr = DrainLib.setSPAddr();
!     moteIF = DrainLib.startMoteIF();
!     moteIF.registerListener(new DrainMsg(), this);
!     log.info("Started myAddr = " + spAddr + ", listening for DrainMsg");
!   }
! 
!   public DrainConnector(int p_spAddr, MoteIF p_moteIF) {
!     spAddr = p_spAddr;
!     moteIF = p_moteIF;
!     moteIF.registerListener(new DrainMsg(), this);
!   }
! 
!   public void registerListener(int id, MessageListener m) {
!     HashSet listenerSet = (HashSet) idTable.get(new Integer(id));
!     
!     if (listenerSet == null) {
!       listenerSet = new HashSet();
!       idTable.put(new Integer(id), listenerSet);
!     }
!     listenerSet.add(m);
!     log.info("New Listener for id=" + id);
!   }
! 
!   public void deregisterListener(int id, MessageListener m) {
!     HashSet listenerSet = (HashSet) idTable.get(new Integer(id));
!     
!     if (listenerSet == null) {
! 	throw new IllegalArgumentException("No listeners registered for message type "+id);
!     }
!     listenerSet.remove(m);
!   }
! 
!   synchronized public void messageReceived(int to, Message m) {
! 
!     DrainMsg mhMsg = (DrainMsg)m;
! 
!     log.debug("incoming: localDest: " + to +
! 	      " type:" + mhMsg.get_type() +
! 	      " hops:" + (16 - mhMsg.get_ttl()) +
! 	      " source:" + mhMsg.get_source() + 
! 	      " finalDest:" + mhMsg.get_dest());
! 
!     if (to != spAddr && to != MoteIF.TOS_BCAST_ADDR && to != TOS_UART_ADDR) {
!       log.debug("Dropping message not for me.");
!       return;
!     }
! 
!     HashSet promiscuousSet = (HashSet) idTable.get(new Integer(BCAST_ID));
!     HashSet listenerSet = (HashSet) idTable.get(new Integer(mhMsg.get_type()));
!     
!     if (listenerSet != null && promiscuousSet != null) {
!       listenerSet.addAll(promiscuousSet);
!     } else if (listenerSet == null && promiscuousSet != null) {
!       listenerSet = promiscuousSet;
!     }
! 
!     if (listenerSet == null) {
!       log.debug("No Listener for type: " + mhMsg.get_type());
!       return;
!     }
! 
!     for(Iterator it = listenerSet.iterator(); it.hasNext(); ) {
!       MessageListener ml = (MessageListener) it.next();
!       ml.messageReceived(to, mhMsg);
!     }
!   }
!   
!   public static void main(String args[]) {
!     DrainConnector dc = new DrainConnector();
!   }
! }
--- 1,96 ----
! package net.tinyos.drain;
! 
! import net.tinyos.message.*;
! import net.tinyos.util.*;
! 
! import org.apache.log4j.*;
! 
! import java.io.*; 
! import java.text.*;
! import java.util.*;
! import java.net.*;
! 
! public class DrainConnector implements MessageListener {
! 
!   public static int TOS_UART_ADDR = 0x7e;
!   public static int DEFAULT_MOTE_ID = 0xfffe;
!   public static int BCAST_ID = 0xff;
!     
!   private MoteIF moteIF;
! 
!   private Logger log = Logger.getLogger(DrainConnector.class.getName());
! 
!   private int spAddr;
! 
!   private HashMap idTable = new HashMap();
! 
!   public DrainConnector() {
!     this(DrainLib.setSPAddr(), DrainLib.startMoteIF());
!   }
! 
!   public DrainConnector(int p_spAddr, MoteIF p_moteIF) {
!     spAddr = p_spAddr;
!     moteIF = p_moteIF;
!     moteIF.registerListener(new DrainMsg(), this);
!     log.info("Started myAddr = " + spAddr + ", listening for DrainMsg");
!   }
! 
!   public void registerListener(int id, MessageListener m) {
!     HashSet listenerSet = (HashSet) idTable.get(new Integer(id));
!     
!     if (listenerSet == null) {
!       listenerSet = new HashSet();
!       idTable.put(new Integer(id), listenerSet);
!     }
!     listenerSet.add(m);
!     log.info("New Listener for id=" + id);
!   }
! 
!   public void deregisterListener(int id, MessageListener m) {
!     HashSet listenerSet = (HashSet) idTable.get(new Integer(id));
!     
!     if (listenerSet == null) {
! 	throw new IllegalArgumentException("No listeners registered for message type "+id);
!     }
!     listenerSet.remove(m);
!   }
! 
!   synchronized public void messageReceived(int to, Message m) {
! 
!     DrainMsg mhMsg = (DrainMsg)m;
! 
!     log.debug("incoming: localDest: " + to +
! 	      " type:" + mhMsg.get_type() +
! 	      " hops:" + (16 - mhMsg.get_ttl()) +
! 	      " source:" + mhMsg.get_source() + 
! 	      " finalDest:" + mhMsg.get_dest());
! 
!     if (to != spAddr && to != MoteIF.TOS_BCAST_ADDR && to != TOS_UART_ADDR) {
!       log.debug("Dropping message not for me.");
!       return;
!     }
! 
!     HashSet promiscuousSet = (HashSet) idTable.get(new Integer(BCAST_ID));
!     HashSet listenerSet = (HashSet) idTable.get(new Integer(mhMsg.get_type()));
!     
!     if (listenerSet != null && promiscuousSet != null) {
!       listenerSet.addAll(promiscuousSet);
!     } else if (listenerSet == null && promiscuousSet != null) {
!       listenerSet = promiscuousSet;
!     }
! 
!     if (listenerSet == null) {
!       log.debug("No Listener for type: " + mhMsg.get_type());
!       return;
!     }
! 
!     for(Iterator it = listenerSet.iterator(); it.hasNext(); ) {
!       MessageListener ml = (MessageListener) it.next();
!       ml.messageReceived(to, mhMsg);
!     }
!   }
!   
!   public static void main(String args[]) {
!     DrainConnector dc = new DrainConnector();
!   }
! }



More information about the Tinyos-beta-commits mailing list