// Path: DeviceService/src/com/ratio/exceptions/DeviceManagerException.java
// public class DeviceManagerException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceManagerException(String s) {
// 		super(s);
// 	}
// 	public DeviceManagerException(String error, String errorValue) {
//     	super(String.format("%s %s", error, errorValue));
// 	}
// }
// 
// Path: DeviceService/src/com/ratio/exceptions/DeviceNameNotFoundException.java
// public class DeviceNameNotFoundException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceNameNotFoundException(String s) {
// 		super(s);
// 	}
// }


import java.util.ArrayList;
import java.util.UUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;
import com.ratio.deviceService.IDeviceCommand;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
		Intent broadcastIntent = new Intent(ACTION_CONNECTION_STATE);
		broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
		broadcastIntent.putExtra(EXTRA_STATE, connState);
		sendBroadcast(broadcastIntent);
	}
	
	// report that we are attempting to reconnect to a device
	public void onRetryReconnect(BluetoothDevice device, int retriesLeft) {
		Intent broadcastIntent = new Intent(ACTION_RETRY_RECONNECT);
		broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
		broadcastIntent.putExtra(EXTRA_RETRIES_LEFT, retriesLeft);
		sendBroadcast(broadcastIntent);
		
	}
	
	// report that we have failed in our attempts to reconnect to a device
	public void onReconnectFailed(BluetoothDevice device) {
		Intent broadcastIntent = new Intent(ACTION_RECONNECT_FAILED);
		broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
		sendBroadcast(broadcastIntent);	
	}
	
	// report that we have discovered the services published by a device.
	public void onServicesDiscovered(BluetoothDevice device, BluetoothGatt gatt) {
		try {
			BTDeviceProfile profile = mDeviceManager.getDeviceProfile(device.getAddress());
			Intent broadcastIntent = new Intent(ACTION_SERVICES_DISCOVERED);
			broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
			broadcastIntent.putExtra(EXTRA_SERVICES, profile.mServiceProfileList);
			sendBroadcast(broadcastIntent);	
// Path: DeviceService/src/com/ratio/exceptions/DeviceManagerException.java
// public class DeviceManagerException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceManagerException(String s) {
// 		super(s);
// 	}
// 	public DeviceManagerException(String error, String errorValue) {
//     	super(String.format("%s %s", error, errorValue));
// 	}
// }
// 
// Path: DeviceService/src/com/ratio/exceptions/DeviceNameNotFoundException.java
// public class DeviceNameNotFoundException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceNameNotFoundException(String s) {
// 		super(s);
// 	}
// }


// Path: DeviceService/src/com/ratio/deviceService/DeviceService.java
import java.util.ArrayList;
import java.util.UUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;
import com.ratio.deviceService.IDeviceCommand;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

		Intent broadcastIntent = new Intent(ACTION_CONNECTION_STATE);
		broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
		broadcastIntent.putExtra(EXTRA_STATE, connState);
		sendBroadcast(broadcastIntent);
	}
	
	// report that we are attempting to reconnect to a device
	public void onRetryReconnect(BluetoothDevice device, int retriesLeft) {
		Intent broadcastIntent = new Intent(ACTION_RETRY_RECONNECT);
		broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
		broadcastIntent.putExtra(EXTRA_RETRIES_LEFT, retriesLeft);
		sendBroadcast(broadcastIntent);
		
	}
	
	// report that we have failed in our attempts to reconnect to a device
	public void onReconnectFailed(BluetoothDevice device) {
		Intent broadcastIntent = new Intent(ACTION_RECONNECT_FAILED);
		broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
		sendBroadcast(broadcastIntent);	
	}
	
	// report that we have discovered the services published by a device.
	public void onServicesDiscovered(BluetoothDevice device, BluetoothGatt gatt) {
		try {
			BTDeviceProfile profile = mDeviceManager.getDeviceProfile(device.getAddress());
			Intent broadcastIntent = new Intent(ACTION_SERVICES_DISCOVERED);
			broadcastIntent.putExtra(EXTRA_DEVICE_ADDRESS, device.getAddress());
			broadcastIntent.putExtra(EXTRA_SERVICES, profile.mServiceProfileList);
			sendBroadcast(broadcastIntent);	
		} catch (DeviceNameNotFoundException dnnfex) {