Fixed klockwork memory leaks and modified the logs
[platform/upstream/iotivity.git] / resource / csdk / connectivity / samples / tizen / interfacesample.c
index 9ea21a3..64d29a6 100644 (file)
 *
 ******************************************************************/
 
+//***************************************************************
+//
+// This file is for internal test only.
+// Do NOT use this file to test CA on Tizen.
+//
+//***************************************************************
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
 #define MOD_NAME "TizenSample"
 
-/**
- * Enable/disable one or more of the following macros to enable/disable 
- * functionality of that particular adapter type in the interfacesample.
- */
-//#define WIFI_ADAPTER_TEST
-#define BT_ADAPTER_TEST
-//#define BLE_ADAPTER_TEST
-
 #if defined(WIFI_ADAPTER_TEST)
 #include "cawifiadapter.h"
-#include "caethernetadapter.h"
 static u_thread_pool_t gWiFiThreadPool = NULL;
-#elif defined(BT_ADAPTER_TEST)
+#endif
+#if defined(BT_ADAPTER_TEST)
 #include "caedradapter.h"
 static  u_thread_pool_t gBTThreadPool = NULL;
-#elif defined(BLE_ADAPTER_TEST)
+#endif
+#if defined(BLE_ADAPTER_TEST)
 #include "caleadapter.h"
 static u_thread_pool_t gLEThreadPool = NULL;
 #endif
 
-static GMainLoop *mainloop;
-static GIOChannel *channel;
-static guint g_test_io_watch_id;
-static GError *g_err_Sample;
+static GMainLoop *mainloop = NULL;
+static GIOChannel *channel = NULL;
+static guint g_test_io_watch_id = 0;
+static GError *g_err_Sample = NULL;
 
-static CALocalConnectivity_t *localWifiEndpoint = NULL;
 //Hardcoded coap data for Test
 static char coapData[500] =
     "{\"oc:\[{href\":\"/a/light\",\"ref\":{\"power\":\"20\",\"state\":\"true\"}}]}";
@@ -96,7 +95,7 @@ void initializeThreadPool(CAConnectivityType_t type)
     {
         if (CA_STATUS_OK != u_thread_pool_init(3, &gWiFiThreadPool))
         {
-            printf("Failed to create thread pool for BT adapter!\n");
+            printf("Failed to create thread pool for WIFI adapter!\n");
             return;
         }
     }
@@ -104,9 +103,9 @@ void initializeThreadPool(CAConnectivityType_t type)
 #ifdef BLE_ADAPTER_TEST
     if (CA_LE == type && NULL == gLEThreadPool)
     {
-        if (CA_STATUS_OK != u_thread_pool_init(3, &gLEThreadPool))
+        if (CA_STATUS_OK != u_thread_pool_init(5, &gLEThreadPool))
         {
-            printf("Failed to create thread pool for BT adapter!\n");
+            printf("Failed to create thread pool for BLE adapter!\n");
             return;
         }
     }
@@ -312,6 +311,7 @@ int16_t interfaceMulticastStartServer(CAConnectivityType_t connType, int serverT
         printf("Invoking start server method\n");
         startServer();
     }
+    return 0;
 }
 
 int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
@@ -343,11 +343,11 @@ int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
         if (strlen(remoteIPAddress) == 0)
         {
             printf("Invalid device address\n");
-            return;
+            return -1;
         }
         endpoint.connectivityType = CA_WIFI;
         strncpy(endpoint.addressInfo.IP.ipAddress, remoteIPAddress, CA_IPADDR_SIZE);
-        endpoint.addressInfo.IP.port = 5283; /* Send the corresponding port here */
+        endpoint.addressInfo.IP.port = 5683; /* Send the corresponding port here */
 
         int sdatalen = tempConnectivityHandlers->handler.sendData(&endpoint, coapData,
                        strlen(coapData));
@@ -373,7 +373,7 @@ int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
         if (strlen(deviceaddress) == 0)
         {
             printf("Invlaid device address\n");
-            return;
+            return -1;
         }
 
         endpoint.connectivityType = CA_EDR;
@@ -397,7 +397,7 @@ int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
         if (strlen(deviceaddress) == 0)
         {
             printf("Invlaid device address\n");
-            return;
+            return -1;
         }
 
         //Get the service uuid from user
@@ -408,12 +408,12 @@ int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
         if (strlen(uuid) == 0)
         {
             printf("Invlaid service uuid\n");
-            return;
+            return -1;
         }
 
         endpoint.connectivityType = CA_LE;
-        strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
-        endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+        strncpy(endpoint.addressInfo.LE.leMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
+        endpoint.addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
         endpoint.resourceUri = strdup(uuid);
 
         tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData));
@@ -453,6 +453,7 @@ int16_t interfaceSendMulticastData(CAConnectivityType_t connType)
     {
         tempConnectivityHandlers->handler.sendDataToAll(coapData, strlen(coapData));
     }
+    return 0;
 }
 
 void interfaceReadData(CAConnectivityType_t connType)
@@ -955,6 +956,7 @@ void testTerminateBTInterface(void)
 
     printf( "Terminating BT Adapter thread pool");
     u_thread_pool_free(gBTThreadPool);
+    gBTThreadPool = NULL;
 }
 #endif //BT_ADAPTER_TEST
 
@@ -987,6 +989,7 @@ void testTerminateWIFIInterface(void)
     // Freeing threadpool for wifi communication adapter
     printf( "Terminating WIFI Adapter thread pool");
     u_thread_pool_free(gWiFiThreadPool);
+    gWiFiThreadPool = NULL;
 
     //Terminate the Wifi communication adapter
     CATerminateWIfI();
@@ -1024,6 +1027,7 @@ void testTerminateBLEInterface(void)
 
     printf( "Terminating BLE Adapter thread pool");
     u_thread_pool_free(gLEThreadPool);
+    gLEThreadPool = NULL;
 
     printf("testTerminateBLEInterface OUT\n");
 }
@@ -1056,7 +1060,6 @@ static gboolean testThread(GIOChannel *source, GIOCondition condition , gpointer
     gchar buf[10] = {'\0'};
     gsize read = 0;
 
-
     if (g_io_channel_read(channel, buf, 10, &read) != G_IO_ERROR_NONE)
     {
         printf("g_io_channel_read error!!!\n");