/**
 * 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.firmwareupdate;

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

/**
 * Cloud Connector for Java ME Firmware Update sample application.
 * 
 * <p>This example simulates a firmware update. Once the connection is 
 * established, the application waits until a firmware update request is 
 * received and simulates the update process.</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 ConnectorEventsListener connectorEventsListener;

	@Override
	public void startApp() {
		connector = new CloudConnector(new FirmwareHook());
		connectorEventsListener = new ConnectorEventsListener(connector);
		// Register the event listeners.
		connector.registerEventsListener(connectorEventsListener);
		// Start Cloud Connector.
		connector.start();
	}

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

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