/**
* 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.
/**
* 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
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.
*/
void CAEDRServerTerminate();
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;
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;
if (JNI_OK != res)
{
OIC_LOG(ERROR, TAG, "AttachCurrentThread failed");
- return;
+ return CA_STATUS_NOT_INITIALIZED;
}
isAttached = true;
}
}
OIC_LOG(DEBUG, TAG, "OUT");
+
+ return result;
}
void CAEDRTerminate()
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)
/**
* 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.
#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;";
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();
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");
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);
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);
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.
*/
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 =
{
}
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);
/**
* This function creates mutex.
*/
-static void CAEDRManagerInitializeMutex(void);
+static CAResult_t CAEDRManagerInitializeMutex(void);
/**
* This function frees mutex.
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)
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)
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()
*/
static int g_serverFD = -1;
-CAResult_t CAEDRServerStart(ca_thread_pool_t handle)
+CAResult_t CAEDRServerStart()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
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