/**
 *	Generated by Dragonfly SDK
 *
 */
package snapandshakeslideshow.servicetracker;

import org.osgi.framework.BundleContext;
import com.buglabs.application.AbstractServiceTracker;
import snapandshakeslideshow.*;

 /**
 *	Service tracker for the BugApp Bundle;
 *
 */
public class SnapAndShakeSlideShowServiceTracker extends AbstractServiceTracker {
	private SnapAndShakeSlideShowApplication application;	
	private BundleContext context;

	public SnapAndShakeSlideShowServiceTracker(BundleContext context) {
		super(context);
		this.context = context;
	}
	
	/**
	 * Determines if the application can start.
	 */
	public boolean canStart() {
		return super.canStart();
	}
	
	/**
	 * If canStart returns true
     * this method is called to start the application.
     * Place your fun logic here. 
	 */
	public void doStart() {
		if(!getApplication().isAlive()) {
			if(getApplication().getRan()) {
				application = new SnapAndShakeSlideShowApplication(this);
			}
			getApplication().start();
		}

	}

	/**
	 * Called when a service that this application depends is unregistered.
	 */
	public void doStop() {
		getApplication().tearDown();

	}

	/**
	 * Allows the user to set the service dependencies by
     * adding them to services list returned by getServices().
     * i.e.nl getServices().add(MyService.class.getName());
	 */
	public void initServices() {
		getServices().addAll(getApplication().getServices());
	}
	
	/**
	 * Returns the application thread.
	 */
	public SnapAndShakeSlideShowApplication getApplication() {
		if(application == null) {
			application = new SnapAndShakeSlideShowApplication(this);
		}
		
		return application;
	}
	
	public BundleContext getContext(){
		return context;
	}
}