#include "caadapterutils.h"
#include "caremotehandler.h"
-//#define DEBUG_MODE
#define TAG PCF("OIC_CA_EDR_CLIENT")
static const char METHODID_CONTEXTNONPARAM[] = "()Landroid/content/Context;";
static jobject g_context;
/**
- * @var g_mutexUnicastServer
- * @brief Mutex to synchronize unicast server
- */
-static ca_mutex g_mutexUnicastServer = NULL;
-
-/**
- * @var g_stopUnicast
- * @brief Flag to control the Receive Unicast Data Thread
- */
-static bool g_stopUnicast = false;
-
-/**
- * @var g_mutexMulticastServer
- * @brief Mutex to synchronize secure multicast server
- */
-static ca_mutex g_mutexMulticastServer = NULL;
-
-/**
- * @var g_stopMulticast
- * @brief Flag to control the Receive Multicast Data Thread
- */
-static bool g_stopMulticast = false;
-
-/**
- * @var g_stopAccept
- * @brief Flag to control the Accept Thread
- */
-static bool g_stopAccept = false;
-
-/**
* @var g_mutexStateList
* @brief Mutex to synchronize device state list
*/
return CA_STATUS_FAILED;
}
- //getApplicationContext
- jclass contextClass = (*env)->FindClass(env, CLASSPATH_CONTEXT);
- if (!contextClass)
+
+ jmethodID mid_getApplicationContext = CAGetJNIMethodID(env, CLASSPATH_CONTEXT,
+ "getApplicationContext",
+ METHODID_CONTEXTNONPARAM);
+ if (!mid_getApplicationContext)
{
- OIC_LOG(ERROR, TAG, "Could not get context object class");
+ OIC_LOG(ERROR, TAG, "Could not get getApplicationContext method");
return CA_STATUS_FAILED;
}
- jmethodID getApplicationContextMethod = (*env)->GetMethodID(env, contextClass,
- "getApplicationContext",
- METHODID_CONTEXTNONPARAM);
- if (!getApplicationContextMethod)
+ jobject jApplicationContext = (*env)->CallObjectMethod(env, context,
+ mid_getApplicationContext);
+ if (!jApplicationContext)
{
- OIC_LOG(ERROR, TAG, "Could not get getApplicationContext method");
+ OIC_LOG(ERROR, TAG, "Could not get application context");
return CA_STATUS_FAILED;
}
return CA_STATUS_FAILED;
}
- (*env)->NewObject(env, EDRJniInterface, EDRInterfaceConstructorMethod, context);
+ (*env)->NewObject(env, EDRJniInterface, EDRInterfaceConstructorMethod, jApplicationContext);
OIC_LOG(DEBUG, TAG, "NewObject Success");
return CA_STATUS_OK;
static void CAEDRDestroyMutex()
{
- if (g_mutexUnicastServer)
- {
- ca_mutex_free(g_mutexUnicastServer);
- g_mutexUnicastServer = NULL;
- }
-
- if (g_mutexMulticastServer)
- {
- ca_mutex_free(g_mutexMulticastServer);
- g_mutexMulticastServer = NULL;
- }
-
if (g_mutexStateList)
{
ca_mutex_free(g_mutexStateList);
static CAResult_t CAEDRCreateMutex()
{
- g_mutexUnicastServer = ca_mutex_new();
- if (!g_mutexUnicastServer)
- {
- OIC_LOG(ERROR, TAG, "Failed to created mutex!");
- return CA_STATUS_FAILED;
- }
-
- g_mutexMulticastServer = ca_mutex_new();
- if (!g_mutexMulticastServer)
- {
- OIC_LOG(ERROR, TAG, "Failed to created mutex!");
-
- CAEDRDestroyMutex();
- return CA_STATUS_FAILED;
- }
-
g_mutexStateList = ca_mutex_new();
if (!g_mutexStateList)
{
isAttached = true;
}
- g_stopAccept = true;
- g_stopMulticast = true;
- g_stopUnicast = true;
-
if (isAttached)
{
(*g_jvm)->DetachCurrentThread(g_jvm);
return result;
}
- OIC_LOG(DEBUG, TAG, "sent data");
-
if (isAttached)
{
OIC_LOG(DEBUG, TAG, "DetachCurrentThread");
if (!CAEDRNativeIsEnableBTAdapter(env))
{
- OIC_LOG(ERROR, TAG, "BT adpater is not enable");
- return CA_STATUS_INVALID_PARAM;
+ OIC_LOG(INFO, TAG, "BT adapter is not enabled");
+ return CA_ADAPTER_NOT_ENABLED;
}
if (STATE_DISCONNECTED == CAEDRIsConnectedDevice(address))
{
// connect before send data
- OIC_LOG(DEBUG, TAG, "connect before send data");
+ OIC_LOG_V(DEBUG, TAG, "try to connect with [%s] before sending data", address);
CAResult_t res = CAEDRNativeConnect(env, address);
if (CA_STATUS_OK != res)
CAResult_t CAEDRNativeConnect(JNIEnv *env, const char *address)
{
VERIFY_NON_NULL(address, TAG, "address is null");
- OIC_LOG(DEBUG, TAG, "btConnect..");
if (!CAEDRNativeIsEnableBTAdapter(env))
{
- OIC_LOG(ERROR, TAG, "BT adpater is not enable");
- return CA_STATUS_INVALID_PARAM;
+ OIC_LOG(INFO, TAG, "BT adapter is not enabled");
+ return CA_ADAPTER_NOT_ENABLED;
}
jclass jni_cid_BTAdapter = (*env)->FindClass(env, CLASSPATH_BT_ADPATER);
CAEDRUpdateDeviceState(STATE_CONNECTED, address);
ca_mutex_unlock(g_mutexStateList);
- OIC_LOG(DEBUG, TAG, "connected");
+ OIC_LOG(DEBUG, TAG, "successfully connected");
return CA_STATUS_OK;
}
CAEDRUpdateDeviceState(STATE_DISCONNECTED, address);
ca_mutex_unlock(g_mutexStateList);
- OIC_LOG(DEBUG, TAG, "disconnected");
+ OIC_LOG_V(DEBUG, TAG, "disconnected with [%s]", address);
}
CAResult_t CAEDRClientInitialize()