Created
August 11, 2011 18:06
-
-
Save jconnolly/1140309 to your computer and use it in GitHub Desktop.
GPS NMEA printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generated by Dragonfly SDK. | |
*/ | |
package gpsstreamtest; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Map; | |
import com.buglabs.bug.module.gps.pub.INMEASentenceProvider; | |
import com.buglabs.bug.module.gps.pub.INMEARawFeed; | |
import org.osgi.framework.BundleActivator; | |
import org.osgi.framework.BundleContext; | |
import org.osgi.util.tracker.ServiceTracker; | |
import com.buglabs.application.ServiceTrackerHelper; | |
/** | |
* BundleActivator for GPSStreamTest. The OSGi entry point to the application. | |
* | |
*/ | |
public class Activator implements BundleActivator { | |
/** | |
* OSGi services the application depends on. | |
*/ | |
private static final String[] services = { | |
INMEASentenceProvider.class.getName(), | |
INMEARawFeed.class.getName(), }; | |
private ServiceTracker serviceTracker; | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext | |
* ) | |
*/ | |
public void start(BundleContext context) throws Exception { | |
serviceTracker = ServiceTrackerHelper.openServiceTracker(context, | |
services, new ServiceTrackerHelper.ManagedInlineRunnable() { | |
@Override | |
public void run(Map<Object, Object> services) { | |
INMEASentenceProvider inmeasentenceprovider = (INMEASentenceProvider) services | |
.get(INMEASentenceProvider.class.getName()); | |
INMEARawFeed inmearawfeed = (INMEARawFeed) services | |
.get(INMEARawFeed.class.getName()); | |
try { | |
BufferedReader reader = new BufferedReader( | |
new InputStreamReader(inmearawfeed | |
.getInputStream())); | |
String read; | |
while ((read = reader.readLine()) != null) { | |
System.out.println(reader.readLine()); | |
} | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
// Warning, this method will be called from within the | |
// same thread as the OSGi framework. Long running | |
// operations should be avoided here. | |
// Implement application here. | |
} | |
@Override | |
public void shutdown() { | |
// TODO Perform cleanup operations as necessary. | |
} | |
}); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) | |
*/ | |
public void stop(BundleContext context) throws Exception { | |
// Will cause the ManagedRunnable.shutdown() to be called. | |
serviceTracker.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment