// vim: et sw=4 sts=4 tabstop=4
package com.issc.gatt;

import com.issc.Bluebit;
import com.issc.util.Log;

import java.util.List;
import java.util.UUID;

import android.bluetooth.BluetoothDevice;

import com.samsung.android.sdk.bt.gatt.BluetoothGatt;
import com.samsung.android.sdk.bt.gatt.BluetoothGattCallback;
import com.samsung.android.sdk.bt.gatt.BluetoothGattCharacteristic;
import com.samsung.android.sdk.bt.gatt.BluetoothGattDescriptor;
import com.samsung.android.sdk.bt.gatt.BluetoothGattService;

/**
 * This is a wrapper.
 *
 * It will be an interface to help us to avoid depending on any specific
 * platform.
 **/
public class GattCharacteristic {

    public final static int WRITE_TYPE_DEFAULT = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
    public final static int WRITE_TYPE_NO_RESPONSE = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE;

    private BluetoothGattCharacteristic mChr;

    public GattCharacteristic(BluetoothGattCharacteristic chr) {
        mChr = chr;
    }

    public BluetoothGattCharacteristic getCharacteristic() {
        return mChr;
    }

    public BluetoothGattDescriptor getDescriptor(UUID uuid) {
        return mChr.getDescriptor(uuid);
    }

    public List<BluetoothGattDescriptor> getDescriptors() {
        return mChr.getDescriptors();
    }

    public Integer getIntValue(int type, int offset) {
        return mChr.getIntValue(type, offset);
    }

    public int getPermissions() {
        return mChr.getPermissions();
    }

    public int getProperties() {
        return mChr.getProperties();
    }

    public UUID getUuid() {
        return mChr.getUuid();
    }

    public byte[] getValue() {
        return mChr.getValue();
    }

    public boolean setValue(byte[] value) {
        return mChr.setValue(value);
    }

    public void setWriteType(int writeType) {
        if (writeType == WRITE_TYPE_NO_RESPONSE) {
            mChr.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
        } else {
            mChr.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
        }
    }
}


@@ -101,16 +101,44 @@
 l.Log;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -1122,33 +1122,24 @@
 %0A    public 
-Bluetooth
 GattDescript
@@ -1175,32 +1175,51 @@
 %0A        return 
+new GattDescriptor(
 mChr.getDescript
@@ -1226,16 +1226,17 @@
 or(uuid)
+)
 ;%0A    %7D%0A
@@ -1247,16 +1247,64 @@
  public 
+List%3CGattDescriptor%3E getDescriptors() %7B%0A        
 List%3CBlu
@@ -1317,32 +1317,44 @@
 GattDescriptor%3E 
+dscs = mChr.
 getDescriptors()
@@ -1345,34 +1345,33 @@
 getDescriptors()
- %7B
+;
 %0A        return 
@@ -1367,36 +1367,201 @@
     
-return mChr.getDescriptors()
+ArrayList%3CGattDescriptor%3E list = new ArrayList%3CGattDescriptor%3E();%0A        for (BluetoothGattDescriptor dsc: dscs) %7B%0A            list.add(new GattDescriptor(dsc));%0A        %7D%0A%0A        return list
 ;%0A  

GattCharacteristic use GattDescriptor