org.iu.gps
Class VRMI

java.lang.Object
  |
  +--org.iu.gps.VRMI
All Implemented Interfaces:
GPSListener, java.lang.Runnable

public class VRMI
extends java.lang.Object
implements GPSListener, java.lang.Runnable

The VRMI class encapsulates all "higher" GPS funcionality. Mainly, VRMI deals with the various kinds of triggers: - time-based triggers (periodical reporting) - distance-based triggers - region-based triggers (if the user enters/exits a given polygonal area)


Field Summary
protected  boolean die
           
protected  GPSDriver gpsDriver
           
protected  GPSInfo gpsInfo
           
protected static int triggerid
           
protected  java.util.Vector triggers
           
 
Constructor Summary
VRMI(GPSDriver _gpsDriver)
          Main constructor
 
Method Summary
 int addDistanceTrigger(VRMITriggerListener recv, boolean persistant, double ds, long dt)
          Adds a trigger that reports the new location if the current location changes more than a given distance, or if the user did not move for longer than a given period of time.
 int addPeriodicTrigger(VRMITriggerListener recv, boolean persistant, long dt)
          Adds a trigger that periodically reports the current location.
 int addRegionTrigger(VRMITriggerListener recv, boolean persistant, double[][] region, boolean enter, boolean exit)
          Adds a trigger that reports if the user enters or exits a given region.
protected  int addTrigger(TriggerInfo ti)
          Private method to add a trigger to the triggers vector.
protected  void checkTriggers()
          Checks in list of triggers if a trigger has to be sent.
protected  void finalize()
          Method
 GPSInfo getCurrentGPSInfo()
          Return current GPS info as retrieved latest from GPS driver.
 void gpsEvent(GPSInfo _gpsInfo)
          GPS callback.
static boolean pointInPoly(double[][] poly, double[] p)
          Test if the given point is within a polygon.
 void removeTrigger(int id)
          Remove the trigger given in
 void run()
          In this thread, we call checkTriggers every second to be sure that time triggers are send even if the GPS driver does not deliver events.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

triggerid

protected static int triggerid

gpsDriver

protected GPSDriver gpsDriver

triggers

protected java.util.Vector triggers

die

protected boolean die

gpsInfo

protected GPSInfo gpsInfo
Constructor Detail

VRMI

public VRMI(GPSDriver _gpsDriver)
     throws java.lang.Exception
Main constructor
Parameters:
_gpsDriver - Parameter
Throws:
java.lang.Exception - Exception
Method Detail

pointInPoly

public static boolean pointInPoly(double[][] poly,
                                  double[] p)
Test if the given point is within a polygon. Beam intersection algorithm, runtime is O(n) (n=edges). Works for simple polygons, even for polys with holes IFF the hole is connected with a vertical edge (both y equal).
Parameters:
poly - The 2D-polygon to use.
p - The 2D-point to test for inclusion.
Returns:
Returned Value

getCurrentGPSInfo

public GPSInfo getCurrentGPSInfo()
Return current GPS info as retrieved latest from GPS driver.
Returns:
The currentGPSInfo value

addPeriodicTrigger

public int addPeriodicTrigger(VRMITriggerListener recv,
                              boolean persistant,
                              long dt)
Adds a trigger that periodically reports the current location.
Parameters:
recv - The VRMICallback that receives the trigger.
persistant - Specifies if trigger is one-shot (false) or persistant(true)
dt - Period of time in milliseconds.
Returns:
Returns an integer that identifies the trigger.

addDistanceTrigger

public int addDistanceTrigger(VRMITriggerListener recv,
                              boolean persistant,
                              double ds,
                              long dt)
Adds a trigger that reports the new location if the current location changes more than a given distance, or if the user did not move for longer than a given period of time.
Parameters:
recv - The VRMICallback that receives the trigger.
persistant - Specifies if trigger is one-shot (false) or persistant(true)
ds - Distance in meters.
dt - Period of time in milliseconds.
Returns:
Returns an integer that identifies the trigger.

addRegionTrigger

public int addRegionTrigger(VRMITriggerListener recv,
                            boolean persistant,
                            double[][] region,
                            boolean enter,
                            boolean exit)
Adds a trigger that reports if the user enters or exits a given region.
Parameters:
recv - The VRMICallback that receives the trigger.
persistant - Specifies if trigger is one-shot (false) or persistant(true)
region - 2D-polygon that specifies the region.
enter - Specifies if entering the region should be reported.
exit - Specifies if exiting the region should be reported.
Returns:
Returns an integer that identifies the trigger.

removeTrigger

public void removeTrigger(int id)
Remove the trigger given in
Parameters:
id - Parameter

gpsEvent

public void gpsEvent(GPSInfo _gpsInfo)
GPS callback. Retrieves latest GPSInfo from GPS driver.
Specified by:
gpsEvent in interface GPSListener
Parameters:
_gpsInfo - Parameter

run

public void run()
In this thread, we call checkTriggers every second to be sure that time triggers are send even if the GPS driver does not deliver events.
Specified by:
run in interface java.lang.Runnable

finalize

protected void finalize()
Method
Overrides:
finalize in class java.lang.Object

checkTriggers

protected void checkTriggers()
Checks in list of triggers if a trigger has to be sent. Note: this method uses the instance variable gpsInfo which has to be set to the current gpsInfo from the GPS driver.

addTrigger

protected int addTrigger(TriggerInfo ti)
Private method to add a trigger to the triggers vector.
Parameters:
ti - The feature to be added to the Trigger attribute
Returns:
Returned Value