Commit 3211ab84 authored by Jaehong Jo's avatar Jaehong Jo Committed by Jon A. Cruz

Modified edrinterface for initiaize and terminate

I Modified edrinterface header file for initiaize and terminate
it will be worked more commonly

Change-Id: I20d40db3110d35d27259713453fbf0ec47599f62
Signed-off-by: default avatarjihwan.seo <jihwan.seo@samsung.com>
Signed-off-by: default avatarJaehong Jo <jaehong.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4787Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarJon A. Cruz <jonc@osg.samsung.com>
parent 57154999
......@@ -163,8 +163,9 @@ void CAEDRClientUnsetCallbacks();
/**
* Used to initialize the EDR client module where mutex is initialized.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
void CAEDRInitializeClient(ca_thread_pool_t handle);
CAResult_t CAEDRClientInitialize();
/**
* Destroys the Device list and mutex.
......@@ -220,15 +221,13 @@ CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
/**
* Start RFCOMM server for given service UUID
*
* @param[in] handle Threadpool Handle.
*
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*
*/
CAResult_t CAEDRServerStart(ca_thread_pool_t handle);
CAResult_t CAEDRServerStart();
/**
* Stop RFCOMM server
......@@ -239,6 +238,13 @@ CAResult_t CAEDRServerStart(ca_thread_pool_t handle);
*/
CAResult_t CAEDRServerStop();
/**
* Used to initialize the EDR server module where mutex is initialized.
* @param[in] threadPool Threadpool Handle.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle);
/**
* Terminate server for EDR.
*/
......
......@@ -51,8 +51,6 @@ static const char CLASSPATH_BT_UUID[] = "java/util/UUID";
static const char CLASSPATH_CONTEXT[] = "android/content/Context";
static const char CLASSPATH_OUTPUT[] = "java/io/OutputStream";
static ca_thread_pool_t g_threadPoolHandle = NULL;
static JavaVM *g_jvm;
static jobject g_context;
......@@ -396,18 +394,21 @@ static CAResult_t CAEDRCreateMutex()
return CA_STATUS_OK;
}
void CAEDRInitialize(ca_thread_pool_t handle)
CAResult_t CAEDRInitialize()
{
OIC_LOG(DEBUG, TAG, "CAEDRInitialize");
g_threadPoolHandle = handle;
CAEDRCoreJniInit();
CAEDRJniInitContext();
// init mutex
CAEDRCreateMutex();
CAResult_t result = CAEDRCreateMutex();
if(CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAEDRInitialize - Could not create mutex");
return result;
}
bool isAttached = false;
JNIEnv* env;
......@@ -420,7 +421,7 @@ void CAEDRInitialize(ca_thread_pool_t handle)
if (JNI_OK != res)
{
OIC_LOG(ERROR, TAG, "AttachCurrentThread failed");
return;
return CA_STATUS_NOT_INITIALIZED;
}
isAttached = true;
}
......@@ -452,6 +453,8 @@ void CAEDRInitialize(ca_thread_pool_t handle)
}
OIC_LOG(DEBUG, TAG, "OUT");
return result;
}
void CAEDRTerminate()
......@@ -1187,9 +1190,10 @@ void CAEDRNativeSocketClose(JNIEnv *env, const char *address)
OIC_LOG(DEBUG, TAG, "disconnected");
}
void CAEDRInitializeClient(ca_thread_pool_t handle)
CAResult_t CAEDRClientInitialize()
{
CAEDRInitialize(handle);
CAResult_t result = CAEDRInitialize();
return result;
}
void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback)
......
......@@ -50,9 +50,9 @@ CAResult_t CAEDRCreateJNIInterfaceObject(jobject context);
/**
* Initialize client for EDR.
* @param[in] handle thread pool handle object.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
void CAEDRInitialize(ca_thread_pool_t handle);
CAResult_t CAEDRInitialize();
/**
* Terminate server for EDR.
......
......@@ -35,7 +35,7 @@
#include "oic_string.h"
//#define DEBUG_MODE
#define TAG PCF("CA_EDR_SERVER")
#define TAG PCF("OIC_CA_EDR_SERVER")
#define MAX_PDU_BUFFER (1024)
static const char METHODID_OBJECTNONPARAM[] = "()Landroid/bluetooth/BluetoothAdapter;";
......@@ -150,6 +150,12 @@ static void CAReceiveHandler(void *data)
while (true != *(ctx->stopFlag))
{
if (!CAEDRNativeIsEnableBTAdapter(env))
{
OIC_LOG(ERROR, TAG, "BT adpater is not enable");
break;
}
// if new socket object is added in socket list after below logic is ran.
// new socket will be started to read after next while loop
uint32_t length = CAEDRGetSocketListLength();
......@@ -251,17 +257,18 @@ static void CAAcceptHandler(void *data)
return;
}
CAResult_t CAEDRServerStart(ca_thread_pool_t handle)
/**
* implement for adapter common method.
*/
CAResult_t CAEDRServerStart()
{
CAResult_t res = CAEDRServerInitialize(handle);
if (CA_STATUS_OK != res)
if (!g_threadPoolHandle)
{
OIC_LOG(ERROR, TAG, "CAEDRServerInitialize failed");
CAEDRServerStop();
return CA_STATUS_FAILED;
return CA_STATUS_NOT_INITIALIZED;
}
res = CAEDRStartUnicastServer(false);
CAEDRServerStartAcceptThread();
CAResult_t res = CAEDRStartUnicastServer(false);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "CAEDRStartUnicastServer failed");
......@@ -423,33 +430,17 @@ void CAEDRServerJniInit()
CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle)
{
OIC_LOG(DEBUG, TAG, "CAEDRServerInitialize");
VERIFY_NON_NULL(handle, TAG, "handle is NULL");
g_threadPoolHandle = handle;
CAEDRServerJniInit();
CAResult_t res = CAEDRServerStartAcceptThread();
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "CAEDRServerCreateMutex failed");
return res;
}
OIC_LOG(DEBUG, TAG, "OUT");
return res;
// init mutex
CAResult_t result = CAEDRServerCreateMutex();
return result;
}
CAResult_t CAEDRServerStartAcceptThread()
{
CAEDRServerJniInit();
// init mutex
CAResult_t ret = CAEDRServerCreateMutex();
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TAG, "CAEDRServerCreateMutex failed");
return ret;
}
bool isAttached = false;
JNIEnv* env;
jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6);
......@@ -650,12 +641,6 @@ CAResult_t CAEDRStopMulticastServer()
CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id, CAAdapterServerType_t type)
{
if (!CAEDRNativeIsEnableBTAdapter(env))
{
OIC_LOG(ERROR, TAG, "BT adpater is not enable");
return CA_STATUS_INVALID_PARAM;
}
if ((*env)->ExceptionCheck(env))
{
(*env)->ExceptionDescribe(env);
......
......@@ -43,13 +43,6 @@ typedef void (*CAPacketReceiveCallback)(const char *address, const char *data);
*/
void CAEDRServerJniInit();
/**
* Initialize server for EDR.
* @param[in] handle thread pool handle object.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle);
/**
* Start Accept Thread.
* @return ::CA_STATUS_OK or Appropriate error code.
......
......@@ -158,18 +158,30 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
g_errorCallback = errorCallback;
// Initialize EDR Network Monitor
CAResult_t err = CAEDRInitializeNetworkMonitor(handle);
if (CA_STATUS_OK != err)
CAResult_t res = CAEDRInitializeNetworkMonitor(handle);
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR N/w Monitor Initialize failed!, error number [%d]",
err);
return err;
res);
return res;
}
CAEDRSetNetworkChangeCallback(CAEDRNotifyNetworkStatus);
CAEDRSetPacketReceivedCallback(CAAdapterRecvData);
CAEDRSetErrorHandler(CAEDRErrorHandler);
CAEDRInitializeClient(handle);
res = CAEDRClientInitialize();
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR Client Initialize failed, error number [%d]", res);
return res;
}
res = CAEDRServerInitialize(handle);
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR Server Initialize failed, error number [%d]", res);
return res;
}
static const CAConnectivityHandler_t handler =
{
......@@ -392,7 +404,7 @@ CAResult_t CAStartServer()
}
CAResult_t err = CA_STATUS_OK;
if (CA_STATUS_OK != (err = CAEDRServerStart(g_edrThreadPool)))
if (CA_STATUS_OK != (err = CAEDRServerStart()))
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to start RFCOMM server!, error num [%d]",
err);
......
......@@ -73,7 +73,7 @@ static ca_mutex g_multicastDataListMutex = NULL;
/**
* This function creates mutex.
*/
static void CAEDRManagerInitializeMutex(void);
static CAResult_t CAEDRManagerInitializeMutex(void);
/**
* This function frees mutex.
......@@ -552,8 +552,9 @@ void CAEDRClientUnsetCallbacks(void)
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
void CAEDRManagerInitializeMutex(void)
CAResult_t CAEDRManagerInitializeMutex(void)
{
CAResult_t result = CA_STATUS_OK;
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
if (!g_edrDeviceListMutex)
......@@ -566,7 +567,14 @@ void CAEDRManagerInitializeMutex(void)
g_multicastDataListMutex = ca_mutex_new();
}
if (!g_edrDeviceListMutex || !g_multicastDataListMutex)
{
result = CA_STATUS_NOT_INITIALIZED;
}
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
return result;
}
void CAEDRManagerTerminateMutex(void)
......@@ -588,11 +596,12 @@ void CAEDRManagerTerminateMutex(void)
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
void CAEDRInitializeClient(ca_thread_pool_t handle)
CAResult_t CAEDRClientInitialize()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
CAEDRManagerInitializeMutex();
CAResult_t result = CAEDRManagerInitializeMutex();
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
return result;
}
void CAEDRClientTerminate()
......
......@@ -42,7 +42,7 @@ static int32_t g_maxPendingConnections = 10;
*/
static int g_serverFD = -1;
CAResult_t CAEDRServerStart(ca_thread_pool_t handle)
CAResult_t CAEDRServerStart()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
......@@ -106,6 +106,12 @@ CAResult_t CAEDRServerStop()
return CA_STATUS_OK;
}
CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "CAEDRServerInitialize");
return CA_STATUS_OK;
}
void CAEDRServerTerminate()
{
// This is just a dummy
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment