コード例 #1
0
ファイル: calenwmonitor.c プロジェクト: ryanmmmmm/iotivity
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerNWConnectionStateChangeCallback(
        JNIEnv *env, jobject obj, jobject device, jint status, jint newState)
{
    OIC_LOG_V(DEBUG, TAG, "caLeGattServerNWConnectionStateChangeCallback - status %d, newstate %d",
              status, newState);
    VERIFY_NON_NULL_VOID(env, TAG, "env");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj");
    VERIFY_NON_NULL_VOID(device, TAG, "device");

    if (CONNECTION_FAILED_TO_BE_EASTABLISHED != status)
    {
        if (g_bleConnectionStateChangedCallback)
        {
            jstring jni_remoteAddress = CALEGetAddressFromBTDevice(env, device);
            if (!jni_remoteAddress)
            {
                OIC_LOG(ERROR, TAG, "jni_remoteAddress is null");
                return;
            }

            const char* address = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
            if (!address)
            {
                OIC_LOG(ERROR, TAG, "address is null");
                return;
            }

            // STATE_DISCONNECTED
            jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE,
                                                            "STATE_DISCONNECTED");

            // STATE_CONNECTED
            jint state_connected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE,
                                                         "STATE_CONNECTED");

            if (state_disconnected == newState)
            {
                OIC_LOG_V(DEBUG, TAG, "LE Disconnected state is %d, %s", newState, address);
                g_bleConnectionStateChangedCallback(CA_ADAPTER_GATT_BTLE, address, false);
            }
            else if (state_connected == newState)
            {
                OIC_LOG_V(DEBUG, TAG, "LE Connected state is %d, %s", newState, address);
                g_bleConnectionStateChangedCallback(CA_ADAPTER_GATT_BTLE, address, true);
            }
            else
            {
                OIC_LOG_V(DEBUG, TAG, "Unknown state : %d, %s", newState, address);
            }

            (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, address);
        }
    }
}
コード例 #2
0
ファイル: calenwmonitor.c プロジェクト: ryanmmmmm/iotivity
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeClientInterface_caLeGattNWConnectionStateChangeCallback(JNIEnv *env,
                                                                                 jobject obj,
                                                                                 jobject gatt,
                                                                                 jint status,
                                                                                 jint newState)
{
    OIC_LOG_V(DEBUG, TAG, "CALeGattNWConnectionStateChangeCallback - status %d, newstate %d",
              status, newState);
    VERIFY_NON_NULL_VOID(env, TAG, "env");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj");
    VERIFY_NON_NULL_VOID(gatt, TAG, "gatt");

    jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE,
                                                    "STATE_DISCONNECTED");
    if (state_disconnected == newState)
    {
        jstring jni_address = CALEClientGetAddressFromGattObj(env, gatt);
        if (!jni_address)
        {
            OIC_LOG(ERROR, TAG, "jni_address is null");
            return;
        }

        const char* address = (*env)->GetStringUTFChars(env, jni_address, NULL);
        if (!address)
        {
            OIC_LOG(ERROR, TAG, "address is null");
            return;
        }

        if (CONNECTION_FAILED_TO_BE_EASTABLISHED != status)
        {
            if (g_bleConnectionStateChangedCallback)
            {
                OIC_LOG_V(DEBUG, TAG, "LE Disconnected state is %d, %s", newState, address);
                g_bleConnectionStateChangedCallback(CA_ADAPTER_GATT_BTLE, address, false);
            }
        }

        (*env)->ReleaseStringUTFChars(env, jni_address, address);
    }
}
コード例 #3
0
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeServerInterface_caLeGattServerNWConnectionStateChangeCallback(
        JNIEnv *env, jobject obj, jobject device, jint status, jint newState)
{
    OIC_LOG(DEBUG, TAG, " Gatt Server NWConnectionStateChange Callback");

    VERIFY_NON_NULL_VOID(env, TAG, "env");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj");
    VERIFY_NON_NULL_VOID(device, TAG, "device");
    (void)status;

    // STATE_DISCONNECTED
    jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE,
                                                    "STATE_DISCONNECTED");
    if (state_disconnected == newState)
    {
        jstring jni_remoteAddress = CALEGetAddressFromBTDevice(env, device);
        if (!jni_remoteAddress)
        {
            OIC_LOG(ERROR, TAG, "jni_remoteAddress is null");
            return;
        }

        const char* address = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL);
        if (!address)
        {
            OIC_LOG(ERROR, TAG, "address is null");
            return;
        }

        if (g_bleConnectionStateChangedCallback)
        {
            g_bleConnectionStateChangedCallback(CA_ADAPTER_GATT_BTLE, address, false);
        }

        (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, address);
    }
}
コード例 #4
0
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeClientInterface_caLeStateChangedCallback(JNIEnv *env, jobject obj,
                                                                   jint status)
{
    VERIFY_NON_NULL_VOID(env, TAG, "env is null");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");

    OIC_LOG_V(DEBUG, TAG, "CaLeClientInterface - Network State Changed : status(%d)", status);

    if (!g_bleDeviceStateChangedCallback)
    {
        OIC_LOG(ERROR, TAG, "gNetworkChangeCb is null");
        return;
    }

    jint state_on = CALEGetConstantsValue(env, CLASSPATH_BT_ADAPTER, "STATE_ON");
    jint state_off = CALEGetConstantsValue(env, CLASSPATH_BT_ADAPTER, "STATE_OFF");
    jint state_turning_off = CALEGetConstantsValue(env, CLASSPATH_BT_ADAPTER, "STATE_TURNING_OFF");

    if (state_on == status) // STATE_ON:12
    {
        CANetworkStatus_t newStatus = CA_INTERFACE_UP;
        CALEClientCreateDeviceList();
        CALEServerCreateCachedDeviceList();

        g_bleDeviceStateChangedCallback(newStatus);
    }
    else if (state_turning_off == status) // BT_STATE_TURNING_OFF:13
    {
        // gatt Device list will be removed.
        // so it is need to create list again when adapter is enabled.
        CAStopLEGattClient();
    }
    else if (state_off == status) // STATE_OFF:10
    {
        CALEClientStopMulticastServer();

        // remove obj for client
        CAResult_t res = CALEClientRemoveAllGattObjs(env);
        if (CA_STATUS_OK != res)
        {
            OIC_LOG(ERROR, TAG, "CALEClientRemoveAllGattObjs has failed");
        }

        res = CALEClientResetDeviceStateForAll();
        if (CA_STATUS_OK != res)
        {
            OIC_LOG(ERROR, TAG, "CALEClientResetDeviceStateForAll has failed");
        }

        // remove obj for server
        res = CALEServerRemoveAllDevices(env);
        if (CA_STATUS_OK != res)
        {
            OIC_LOG(ERROR, TAG, "CALEServerRemoveAllDevices has failed");
        }

        CALEClientSetScanFlag(false);

        CANetworkStatus_t newStatus = CA_INTERFACE_DOWN;
        g_bleDeviceStateChangedCallback(newStatus);
    }
}
コード例 #5
0
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeClientInterface_caManagerLeGattConnectionStateChangeCB(
        JNIEnv *env, jobject obj, jobject gatt, jint status, jint newState)
{
    OIC_LOG_V(DEBUG, TAG, "caManagerLeGattConnectionStateChangeCB-status(%d), newState(%d)",
              status, newState);

    VERIFY_NON_NULL_VOID(env, TAG, "env");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj");
    VERIFY_NON_NULL_VOID(gatt, TAG, "gatt");

    jint state_connected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_CONNECTED");
    jint state_disconnected = CALEGetConstantsValue(env, CLASSPATH_BT_PROFILE, "STATE_DISCONNECTED");
    jint gatt_success = CALEGetConstantsValue(env, CLASSPATH_BT_GATT, "GATT_SUCCESS");

    jstring jni_address = CAManagerGetAddressFromGatt(env, gatt);
    if (!jni_address)
    {
        OIC_LOG(ERROR, TAG, "CAManagerGetAddressFromGatt is null");
        return;
    }

    char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
    if (!address)
    {
        OIC_LOG(ERROR, TAG, "address is null");
        return;
    }

    OIC_LOG_V(INFO, TAG, "connection state : status(%d), addr:(%s), newState(%d)",
              status, address, newState);

    if (gatt_success == status && state_connected == newState) // le connected
    {
        OIC_LOG(DEBUG, TAG, "LE is connected");
        CAResult_t res = CAManagerReadRemoteRssi(env, gatt);
        if (CA_STATUS_OK != res)
        {
            OIC_LOG(ERROR, TAG, "CAManagerReadRemoteRssi has failed");
            (*env)->ReleaseStringUTFChars(env, jni_address, address);
            return;
        }
    }
    else if (state_disconnected == newState)// le disconnected
    {
        if (LINK_LOSS == status || REMOTE_DISCONNECT == status)
        {
            OIC_LOG(DEBUG, TAG, "LE is disconnected");

            if (g_connStateCB)
            {
                OIC_LOG_V(DEBUG, TAG, "LE Disconnected state is %d, %s", newState, address);
                g_connStateCB(CA_ADAPTER_GATT_BTLE, address, false);
                OIC_LOG(DEBUG, TAG, "LE Disconnected state callback is called");
            }

            if (!CAManagerIsMatchedACData(env, jni_address))
            {
                OIC_LOG_V(DEBUG, TAG, "this[%s] is not target address for Auto Connection",
                          address);
                (*env)->ReleaseStringUTFChars(env, jni_address, address);
                return;
            }

            CAManagerSetAutoConnectionFlag(env, jni_address, false);

            CAResult_t res = CAManagerStartAutoConnection(env, jni_address);
            if (CA_STATUS_OK != res)
            {
                (*env)->ReleaseStringUTFChars(env, jni_address, address);
                OIC_LOG(ERROR, TAG, "CAManagerStartAutoConnection has failed");
                return;
            }
        }
        else if (ACCEPT_TIMEOUT_EXCEPTION == status)
        {
            CAManagerProcessRecovery(env, START_RECOVERY);
        }
    }
    (*env)->ReleaseStringUTFChars(env, jni_address, address);
    (*env)->DeleteLocalRef(env, jni_address);
}
コード例 #6
0
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback(
        JNIEnv *env, jobject obj, jint state)
{
    OIC_LOG(DEBUG, TAG, "caManagerAdapterStateChangedCallback");
    VERIFY_NON_NULL_VOID(env, TAG, "env");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj");

    jint state_on = CALEGetConstantsValue(env, CLASSPATH_BT_ADAPTER, "STATE_ON");
    jint state_off = CALEGetConstantsValue(env, CLASSPATH_BT_ADAPTER, "STATE_OFF");
    jint state_turning_off = CALEGetConstantsValue(env, CLASSPATH_BT_ADAPTER, "STATE_TURNING_OFF");

    if (state_on == state)
    {
        OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_on");
        if (g_adapterStateCB)
        {
            g_adapterStateCB(CA_ADAPTER_GATT_BTLE, true);
        }

        // when BT state is on. recovery flag has to be reset.
        CAManagerSetBTRecovery(false);

        // find target device for autoconnect
        size_t length = CAManagerGetACDataLength();
        OIC_LOG_V(DEBUG, TAG, "target device : %d", length);
        for (size_t idx = 0; idx < length; idx++)
        {
            jstring leAddress = CAManagerGetLEAddressFromACData(env, idx);
            if (leAddress)
            {
                CAResult_t res = CAManagerStartAutoConnection(env, leAddress);
                if (CA_STATUS_OK != res)
                {
                    OIC_LOG(ERROR, TAG, "CAManagerStartAutoConnection has failed");
                    return;
                }
            }
        }
    }
    else if (state_off == state)
    {
        OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_off");
        if (g_adapterStateCB)
        {
            g_adapterStateCB(CA_ADAPTER_GATT_BTLE, false);
        }

        // reset autoconnect flag for all target devices
        size_t length = CAManagerGetACDataLength();
        for (size_t idx = 0; idx < length; idx++)
        {
            jstring address = CAManagerGetLEAddressFromACData(env, idx);
            if (address)
            {
                CAManagerSetAutoConnectionFlag(env, address, false);
            }
        }

        // check whether BT recovery is needed or not
        if (CAManagerIsRecoveryFlagSet())
        {
            CAManagerProcessRecovery(env, STATE_OFF);
        }
    }
    else if (state_turning_off == state)
    {
        OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_turning_off");
        return;
    }
    else
    {
        OIC_LOG(INFO, TAG, "AdapterStateChangedCallback state is not available");
        return;
    }
}