/**
 * Copyright (c) 2014 Etherios, a Division of Digi International, Inc.
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Etherios 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */
package com.etherios.connector.binarydatapoints;

import com.etherios.connector.emulator.CloudConnector;
import javax.microedition.midlet.MIDlet;

/**
 * Cloud Connector for Java ME Binary Data Points sample application.
 * 
 * <p>This example simulates an application that monitors the vital signs of a 
 * patient and sends them to Device Cloud. Since they are sensitive and 
 * confidential data, the application sends them as encrypted binary data using 
 * binary data points.</p>
 *
 * <p>For a complete description on the example, refer to the 'ReadMe.txt' file
 * included in the root directory.</p>
 */
public class MainApp extends MIDlet {

	/* Variables */

	private static CloudConnector connector;
	
	private static PatientMonitor monitor;

	@Override
	public void startApp() {
		connector = new CloudConnector();
		// Register the event listeners.
		connector.registerEventsListener(new ConnectorEventsListener(connector));
		// Start Cloud Connector.
		connector.start();
		
		monitor = new PatientMonitor(connector);
		// Start the monitoring and encrypt the constants.
		monitor.start(true);
	}

	@Override
	public void pauseApp() {
		monitor.stop();
		connector.stop();
	}

	@Override
	public void destroyApp(boolean unconditional) {
		monitor.stop();
		connector.stop();
		notifyDestroyed();
	}
}
