replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / tizen / caedrserver.c
index 2355008..f527f1d 100644 (file)
  ******************************************************************/
 
 /**
- * @file    cabtserver.c
- * @brief   This    file provides the APIs to start and stop RFCOMM server.
+ * @file
+ *
+ * This file provides the APIs to start and stop RFCOMM server.
  */
 
-
 #include <string.h>
 #include <bluetooth.h>
-#include "caedrinterface.h"
 
+#include "caedrinterface.h"
 #include "caadapterutils.h"
 #include "caedrutils.h"
 #include "logger.h"
-#include "umutex.h"
+#include "octhread.h"
 #include "cacommon.h"
 #include "caedrdevicelist.h"
 
-static int32_t gMaxPendingConnections = 10;
-
-CAResult_t CAEDRServerStart(const char *serviceUUID, int32_t *serverFD)
-{
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "IN");
+static int32_t g_maxPendingConnections = 10;
 
-    bt_error_e err = BT_ERROR_NONE;
-    bool isRunning = false;
-    int32_t socketFD;
+/**
+ * Storing RfcommserverUUID
+ */
+static int g_serverFD = -1;
 
-    VERIFY_NON_NULL(serviceUUID, EDR_ADAPTER_TAG, "Service UUID is null");
-    VERIFY_NON_NULL(serverFD, EDR_ADAPTER_TAG, "Server fd holder is null");
+CAResult_t CAEDRServerStart()
+{
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
 
-    if (0 >= strlen(serviceUUID))
+    if(-1 != g_serverFD)
     {
-        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Invalid input: Empty service uuid!");
-        return CA_STATUS_INVALID_PARAM;
+        OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "%s Already running", __func__);
+        return CA_STATUS_OK;
     }
 
-    if (BT_ERROR_NONE != bt_adapter_is_service_used(serviceUUID, &isRunning))
+    bool isRunning = false;
+    bt_error_e err = bt_adapter_is_service_used(OIC_EDR_SERVICE_ID, &isRunning);
+    if (BT_ERROR_NONE != err)
     {
-        OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG,
-                  "Unable to find whether service is already running or not!");
+        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG,
+                  "Unable to find whether service is already running or not! error num[%x]", err);
         return CA_STATUS_FAILED;
     }
 
-    if (true == isRunning)
+    if (isRunning)
     {
-        OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "Service is already running with this UUID!");
+        OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Service is already running with this UUID!");
         return CA_SERVER_STARTED_ALREADY;
     }
 
-    // Registers a rfcomm socket with a specific service_uuid .
-    if (BT_ERROR_NONE != (err = bt_socket_create_rfcomm(serviceUUID, &socketFD)))
+    int socketFD = 0;
+    // Registers a rfcomm socket with a specific service_uuid.
+    err = bt_socket_create_rfcomm(OIC_EDR_SERVICE_ID, &socketFD);
+    if (BT_ERROR_NONE != err)
     {
-        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to create rfcomm socket!, error num [%x]",
-                  err);
+        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to create rfcomm socket!, error num [%x]", err);
         return CA_STATUS_FAILED;
     }
 
     // Start listening and accepting
-    if (BT_ERROR_NONE != (err = bt_socket_listen_and_accept_rfcomm(socketFD,
-                                gMaxPendingConnections)))
+    err = bt_socket_listen_and_accept_rfcomm(socketFD, g_maxPendingConnections);
+    if (BT_ERROR_NONE != err)
     {
-        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed in listen rfcomm socket!, error num [%x]",
-                  err);
+        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed in listen rfcomm socket!, error num [%x]", err);
 
         bt_socket_destroy_rfcomm(socketFD);
         return CA_STATUS_FAILED;
     }
 
-    *serverFD = socketFD;
+    g_serverFD = socketFD;
 
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "OUT");
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
 
-CAResult_t CAEDRServerStop(const int32_t serverFD)
+CAResult_t CAEDRServerStop()
 {
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "IN");
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
 
-    bt_error_e err = BT_ERROR_NONE;
-    if (BT_ERROR_NONE != (err = bt_socket_destroy_rfcomm(serverFD)))
+    if (-1 < g_serverFD)
     {
-        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed close server socket!, error num [%x]",
-                  err);
-        return CA_STATUS_FAILED;
+        bt_error_e err = bt_socket_destroy_rfcomm(g_serverFD);
+
+        if (BT_ERROR_NONE != err)
+        {
+            OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed close server socket!, error num [%x]", err);
+            return CA_STATUS_FAILED;
+        }
+        g_serverFD = -1;
     }
 
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "OUT");
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
     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
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "CAEDRServerTerminate");
+}
+
 CAResult_t CAEDRManagerReadData(void)
 {
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "IN");
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "OUT");
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
     return CA_NOT_SUPPORTED;
 }