From 9965a87e82da3742a8ae5ef07734c9b5cbd23b6b Mon Sep 17 00:00:00 2001 From: Omkar Hegde Date: Fri, 10 Jul 2015 16:21:17 -0700 Subject: [PATCH] Changed C Samples to use correct adapter type The C Samples were broken as a result of changing the samples for IPv6. Also, removed port 6298 from unicast discovery query and replaced some printf() with OC_LOG(). Removed Differentiation between IPv4 and IPv6 in the samples. Change-Id: I83859aaf468c991ca5406014359476d0f43d5745 Signed-off-by: Omkar Hegde Reviewed-on: https://gerrit.iotivity.org/gerrit/1623 Tested-by: jenkins-iotivity Reviewed-by: Erich Keane --- .../samples/linux/SimpleClientServer/occlient.cpp | 16 ++---- .../samples/linux/SimpleClientServer/occlient.h | 3 +- .../linux/SimpleClientServer/occlientbasicops.cpp | 65 ++++++++-------------- .../linux/SimpleClientServer/occlientbasicops.h | 3 +- .../linux/SimpleClientServer/occlientcoll.cpp | 26 ++------- .../linux/SimpleClientServer/occlientslow.cpp | 27 +++------ .../linux/SimpleClientServer/occlientslow.h | 3 +- .../samples/linux/secure/occlientbasicops.cpp | 28 +++------- .../stack/samples/linux/secure/occlientbasicops.h | 3 +- 9 files changed, 52 insertions(+), 122 deletions(-) diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index 841835a..d3f4b2a 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -79,11 +79,10 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1|2>"); + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1>"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); - OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); - OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); - OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "-c 0 : Use Default connectivity(IP)"); + OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request"); OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Nonconfirmable Get Request" @@ -833,17 +832,10 @@ int main(int argc, char* argv[]) return 0; } - if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IPV4) + if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP) { OC_CONNTYPE = CT_ADAPTER_IP; } - else if(CONNECTIVITY == CT_IPV6) - { - //TODO: Remove when IPv6 is available. - OC_LOG(ERROR, TAG, "IPv6 is currently not supported !!!!"); - PrintUsage(); - return -1; - } else { OC_LOG(INFO, TAG, "Default Connectivity type selected..."); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h index a8661ed..2ed2e3d 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h @@ -72,8 +72,7 @@ typedef enum { */ typedef enum { CT_ADAPTER_DEFAULT = 0, - CT_IPV4, - CT_IPV6, + CT_IP, MAX_CT } CLIENT_CONNECTIVITY_TYPE; diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp index 2ea10a1..8f1eb62 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp @@ -35,12 +35,12 @@ #define MAX_IP_ADDR_ST_SZ 16 //string size of "155.255.255.255" (15 + 1) #define MAX_PORT_ST_SZ 6 //string size of "65535" (5 + 1) -static int IPV4_ADDR_SIZE = 16; +static int IPV4_ADDR_SIZE = 24; static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; static int CONNECTIVITY = 0; -static const char UNICAST_DISCOVERY_QUERY[] = "coap://%s:6298/oic/res"; +static const char UNICAST_DISCOVERY_QUERY[] = "coap://%s/oic/res"; static std::string putPayload = "{\"oic\":[{\"rep\":{\"power\":15,\"state\":true}}]}"; //The following variable determines the interface protocol (IP, etc) @@ -64,16 +64,15 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2>"); + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1>"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and" " Initiate Nonconfirmable Get/Put/Post Requests"); OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate " "Confirmable Get/Put/Post Requests"); - OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); - OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); - OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "-c 0 : Default auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type"); } /* @@ -318,7 +317,8 @@ int InitDiscovery() if (UNICAST_DISCOVERY) { char ipv4addr[IPV4_ADDR_SIZE]; - OC_LOG(INFO, TAG, "Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15) "); + OC_LOG(INFO, TAG, "Enter IP address with port of the Server hosting resource"\ + "(Ex: 192.168.0.15:1234) "); if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin)) { @@ -491,7 +491,6 @@ int parseJSON(const char * resJSONPayload, char ** sid_c, void queryResource() { - printf("\n"); switch(TEST_CASE) { case TEST_DISCOVER_REQ: @@ -510,7 +509,6 @@ void queryResource() PrintUsage(); break; } - printf("\n"); } @@ -619,36 +617,30 @@ void printResourceList() { ResourceNode * iter; iter = resourceList; - printf("\nResource List\n"); + OC_LOG(INFO, TAG, "Resource List: "); while(iter) { - printf("*****************************************************\n"); - printf("sid = %s \n",iter->sid); - printf("uri = %s\n", iter->uri); - printf("ip = %s\n", iter->ip); - printf("port = %s\n", iter->port); + OC_LOG(INFO, TAG, "*****************************************************"); + OC_LOG_V(INFO, TAG, "sid = %s",iter->sid); + OC_LOG_V(INFO, TAG, "uri = %s", iter->uri); + OC_LOG_V(INFO, TAG, "ip = %s", iter->ip); + OC_LOG_V(INFO, TAG, "port = %s", iter->port); switch (iter->connType & CT_MASK_ADAPTER) { case CT_ADAPTER_IP: - printf("connType = %s\n","Default (IPv4) "); - break; - case CT_IP_USE_V4: - printf("connType = %s\n","IPv4"); - break; - case CT_IP_USE_V6: - printf("connType = %s\n","IPv6"); + OC_LOG(INFO, TAG, "connType = Default (IPv4)"); break; case OC_ADAPTER_GATT_BTLE: - printf("connType = %s\n","BLE"); + OC_LOG(INFO, TAG, "connType = BLE"); break; case OC_ADAPTER_RFCOMM_BTEDR: - printf("connType = %s\n","BT"); + OC_LOG(INFO, TAG, "connType = BT"); break; default: - printf("connType = %s\n","Invalid connType"); + OC_LOG(INFO, TAG, "connType = Invalid connType"); break; } - printf("*****************************************************\n"); + OC_LOG(INFO, TAG, "*****************************************************"); iter = iter->next; } } @@ -659,6 +651,7 @@ void freeResourceList() ResourceNode * temp; while(resourceList) { + temp = resourceList; resourceList = resourceList->next; OICFree((void *)temp->sid); @@ -685,6 +678,7 @@ int main(int argc, char* argv[]) TEST_CASE = atoi(optarg); break; case 'c': + CONNECTIVITY = atoi(optarg); break; default: @@ -708,27 +702,14 @@ int main(int argc, char* argv[]) return 0; } - if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP) { OC_CONNTYPE = CT_ADAPTER_IP;//CT_DEFAULT; } - else if(CONNECTIVITY == CT_IPV4) - { - OC_CONNTYPE = CT_IP_USE_V4; - } - else if(CONNECTIVITY == CT_IPV6) - { - OC_CONNTYPE = CT_IP_USE_V6; - - //TODO: Remove when IPv6 is available. - printf("\n\nIPv6 is currently not supported !!!!\n"); - PrintUsage(); - return -1; - } else { - printf("Default Connectivity type selected \n\n"); - OC_CONNTYPE = CT_ADAPTER_IP; + OC_LOG(INFO, TAG, "Default Connectivity type selected"); + PrintUsage(); } InitDiscovery(); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h index 4a0dd93..012a11a 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.h @@ -52,8 +52,7 @@ typedef enum { */ typedef enum { CT_ADAPTER_DEFAULT = 0, - CT_IPV4, - CT_IPV6, + CT_IP, MAX_CT } CLIENT_CONNECTIVITY_TYPE; diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp index 15c3c8b..1180b43 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp @@ -59,8 +59,7 @@ typedef enum */ typedef enum { CT_ADAPTER_DEFAULT = 0, - CT_IPV4, - CT_IPV6, + CT_IP, MAX_CT } CLIENT_CONNECTIVITY_TYPE; @@ -119,9 +118,8 @@ int InitDiscovery(); void PrintUsage() { OC_LOG(INFO, TAG, "Usage : occlientcoll -t -c "); - OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); - OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); - OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "-c 0 : Default auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type"); OC_LOG(INFO, TAG, "Test Case 1 : Discover Resources && Initiate GET Request on an "\ "available resource using default interface."); OC_LOG(INFO, TAG, "Test Case 2 : Discover Resources && Initiate GET Request on an "\ @@ -378,28 +376,16 @@ int main(int argc, char* argv[]) return 0; } - if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP) { - OC_CONNTYPE = CT_DEFAULT; - } - else if(CONNECTIVITY == CT_IPV4) - { - OC_CONNTYPE = CT_IP_USE_V4; - } - else if(CONNECTIVITY == CT_IPV6) - { - OC_CONNTYPE = CT_IP_USE_V6; - - //TODO: Remove when IPv6 is available. - OC_LOG(INFO, TAG, "Ipv6 is currently not supported..."); - PrintUsage(); - return -1; + OC_CONNTYPE = CT_ADAPTER_IP; } else { OC_LOG(INFO, TAG, "Default Connectivity type selected..."); OC_CONNTYPE = CT_ADAPTER_IP; } + InitDiscovery(); // Break from loop with Ctrl+C diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp index 7f55394..29b22c3 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp @@ -34,7 +34,7 @@ static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; static int CONNECTIVITY = 0; -static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:6298/oic/res"; +static const char * UNICAST_DISCOVERY_QUERY = "coap://%s/oic/res"; static std::string putPayload = "{\"state\":\"off\",\"power\":10}"; static std::string coapServerIP = "255.255.255.255"; static std::string coapServerPort = "5683"; @@ -44,7 +44,7 @@ static std::string coapServerResource = "/a/led"; //to be used for sending unicast messages. Default set to IP. static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP; static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res"; -static int IPV4_ADDR_SIZE = 16; +static int IPV4_ADDR_SIZE = 24; void StripNewLineChar(char* str); int gQuitFlag = 0; @@ -61,9 +61,8 @@ void handleSigInt(int signum) static void PrintUsage() { OC_LOG(INFO, TAG, "Usage : occlient -c <0|1|2> -u <0|1> -t <1|2|3>"); - OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); - OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); - OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); + OC_LOG(INFO, TAG, "-c 0 : Default auto-selection"); + OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request"); @@ -186,7 +185,8 @@ int InitDiscovery() if (UNICAST_DISCOVERY) { char ipv4addr[IPV4_ADDR_SIZE]; - OC_LOG(INFO, TAG, "Enter IPv4 address of the Server hosting resource (Ex: 192.168.0.15)"); + OC_LOG(INFO, TAG, "Enter IPv4:port of the Server hosting resource"\ + "(Ex: 192.168.0.15:1234)"); if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin)) { //Strip newline char from ipv4addr @@ -261,23 +261,10 @@ int main(int argc, char* argv[]) return 0; } - if(CONNECTIVITY == CT_ADAPTER_DEFAULT) + if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP) { OC_CONNTYPE = CT_ADAPTER_IP; } - else if(CONNECTIVITY == CT_IPV4) - { - OC_CONNTYPE = CT_IP_USE_V4; - } - else if(CONNECTIVITY == CT_IPV6) - { - OC_CONNTYPE = CT_IP_USE_V6; - - //TODO: Remove when IPv6 is available. - OC_LOG(INFO, TAG, "Ipv6 is currently not supported..."); - PrintUsage(); - return -1; - } else { OC_LOG(INFO, TAG, "Default Connectivity type selected..."); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h index fdb2204..3c91393 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.h @@ -53,8 +53,7 @@ typedef enum */ typedef enum { CT_ADAPTER_DEFAULT = 0, - CT_IPV4, - CT_IPV6, + CT_IP, MAX_CT } CLIENT_CONNECTIVITY_TYPE; diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp index 32a423b..3dabe56 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp @@ -36,8 +36,8 @@ static int UNICAST_DISCOVERY = 0; static int TEST_CASE = 0; static int CONN_TYPE = 0; -static int IPV4_ADDR_SIZE = 16; -static char UNICAST_DISCOVERY_QUERY[] = "coap://%s:6298/oic/res"; +static int IPV4_ADDR_SIZE = 24; +static char UNICAST_DISCOVERY_QUERY[] = "coap://%s/oic/res"; static char MULTICAST_DISCOVERY_QUERY[] = "/oic/res"; OCConnectivityType discoveryReqConnType = CT_ADAPTER_IP; @@ -68,15 +68,14 @@ void handleSigInt(int signum) static void PrintUsage() { - OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2>"); + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1>"); OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and" " Initiate Nonconfirmable Get/Put/Post Requests"); OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Confirmable Get/Put/Post Requests"); - OC_LOG(INFO, TAG, "-c 0 : Default IPv4 and IPv6 auto-selection"); + OC_LOG(INFO, TAG, "-c 0 : Default auto-selection"); OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type"); - OC_LOG(INFO, TAG, "-c 2 : IPv6 Connectivity Type (IPv6 not currently supported)"); } OCStackResult InvokeOCDoResource(std::ostringstream &query, @@ -242,7 +241,8 @@ int InitDiscovery() if (UNICAST_DISCOVERY) { char ipv4addr[IPV4_ADDR_SIZE]; - printf("Enter IPv4 address of the Server hosting secure resource (Ex: 11.12.13.14)\n"); + OC_LOG(INFO, TAG, "Enter IPv4 address:port of the Server hosting secure resource"\ + "(Ex: 11.12.13.14:1234)\n"); if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin)) { //Strip newline char from ipv4addr @@ -322,25 +322,13 @@ int main(int argc, char* argv[]) } - if(CONN_TYPE == CT_ADAPTER_DEFAULT) + if(CONN_TYPE == CT_ADAPTER_DEFAULT || CONN_TYPE == CT_IP) { discoveryReqConnType = CT_DEFAULT; } - else if(CONN_TYPE == CT_IPV4) - { - discoveryReqConnType = CT_IP_USE_V4; - } - else if(CONN_TYPE == CT_IPV6) - { - //TODO: Remove when IPv6 is available. - //discoveryReqConnType = CT_IP_USE_V6; - OC_LOG(ERROR, TAG, "IPv6 is currently not supported !!!!"); - PrintUsage(); - return -1; - } else { - printf("Using Default Connectivity type\n\n"); + OC_LOG(INFO, TAG, "Using Default Connectivity type"); PrintUsage(); } diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.h b/resource/csdk/stack/samples/linux/secure/occlientbasicops.h index 2262553..3fed75a 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.h +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.h @@ -43,8 +43,7 @@ typedef enum { */ typedef enum { CT_ADAPTER_DEFAULT = 0, - CT_IPV4, - CT_IPV6, + CT_IP, MAX_CT } CLIENT_CONNECTIVITY_TYPE; -- 2.7.4