/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package applications;

import java.util.Vector;

/**
 *
 * @author student
 */
public class CarbonControl {

    public static Vector<Trip> tripsDatabase = new Vector<Trip>();
    public static boolean CarbonEmissionsStarted = false;
    private static CarbonEmissions carbon = new CarbonEmissions();

    public static void StartCarbonEmissionCheck(String engineState) {

        if (engineState.equals("ON")) {

            //if the engine is on, and the CarbonEmissions thread hasn't been
            //started, start the thread
            if (CarbonEmissionsStarted == false) {
                CarbonEmissionsStarted = true;
                carbon.start = true; //set the flag
                
                getCarbon().start(); //start the thread
            }
        }
        //If the engine is off, but the thread is still running,
        //stop the thread and collect the data
        else if (engineState.equals("OFF")) {
            if (CarbonEmissionsStarted == true) {

                CarbonEmissionsStarted = false;
                carbon.start = false;

                Trip t = getCarbon().getMyTrip();
                tripsDatabase.add(t);

                //write entire database out to xml file.
                xmlpackage.CarbonEmissionsXMLWriter.writeToFile(applications.CarbonControl.tripsDatabase);
            }
        }
    }

    /**
     * @return the carbon
     */
    public static CarbonEmissions getCarbon() {
        return carbon;
    }

    /**
     * @param aCarbon the carbon to set
     */
    public static void setCarbon(CarbonEmissions aCarbon) {
        carbon = aCarbon;
    }
}
