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

import com.etherios.connector.emulator.CloudConnector;

import javax.microedition.midlet.MIDlet;

/**
 * Cloud Connector for Java ME Device Request sample application.
 * 
 * <p>This example waits for incoming requests to process them. If the target is
 * 'screenshot', the image 'image.png', located inside the 'res' directory, will
 * be uploaded to the specified directory in Device Cloud.</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
	protected void startApp() {
		connector = new CloudConnector();
		connectorEventsListener = new ConnectorEventsListener(connector);
		// Register the event listener.
		connector.registerEventsListener(connectorEventsListener);
		// Register the device requets listener.
		connector.registerDeviceRequestListener(new DeviceRequestListener(connector));
		// Start Cloud Connector.
		connector.start();
	}

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

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