From: omkar Date: Mon, 12 Jan 2015 23:20:00 +0000 (-0800) Subject: Adding adapter type parameter to C Samples X-Git-Tag: 1.2.0+RC1~1855^2~281^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b632925fdfefc36042b94dcf21d334539333139;p=platform%2Fupstream%2Fiotivity.git Adding adapter type parameter to C Samples Previously we had hard coded WIFI to be the default interface. Added code to allow users to pass adapter type as a command line argument. Change-Id: Id9e0cadf10746bd665212b79d36f7557ed5993d2 Signed-off-by: omkar --- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp index 59d4420..de4a8ed 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp @@ -44,6 +44,13 @@ static std::string coapServerIP = "255.255.255.255"; static std::string coapServerPort = "5683"; static std::string coapServerResource = "/a/led"; +#ifdef CA_INT +//The following variable determines the interface (wifi, ethernet etc.) +//to be used for sending unicast messages. Default set to WIFI. +static OCConnectivityType CA_CONNTYPE = OC_WIFI; +static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core"; +#endif + int gQuitFlag = 0; namespace { @@ -65,8 +72,15 @@ void handleSigInt(int signum) static void PrintUsage() { +#ifdef CA_INT + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2|3>"); +#else OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>"); +#endif OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources"); +#ifdef CA_INT + OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send unicast messages over Ethernet, WIFI, EDR or LE"); +#endif OC_LOG(INFO, TAG, "-t 1 : Discover Resources"); OC_LOG(INFO, TAG, "-t 2 : Discover Resources and" " Initiate Nonconfirmable Get/Put/Post Requests"); @@ -86,10 +100,9 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param ret = OCDoResource(&handle, method, query.str().c_str(), 0, (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL, - OC_WIFI, qos, &cbData, options, numOptions); + CA_CONNTYPE, qos, &cbData, options, numOptions); #else ret = OCDoResource(&handle, method, query.str().c_str(), 0, (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL, @@ -282,15 +295,26 @@ int InitDiscovery() } else { +#ifdef CA_INT + strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY); +#else strcpy(szQueryUri, OC_WELL_KNOWN_QUERY); +#endif } cbData.cb = discoveryReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to all but should be configurable - add as API param - ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI), - OC_LOW_QOS, &cbData, NULL, 0); + if (UNICAST_DISCOVERY) + { + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (CA_CONNTYPE), + OC_LOW_QOS, &cbData, NULL, 0); + } + else + { + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL), + OC_LOW_QOS, &cbData, NULL, 0); + } #else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); #endif @@ -309,7 +333,11 @@ int main(int argc, char* argv[]) uint8_t ifname[] = "eth0"; int opt; +#ifdef CA_INT + while ((opt = getopt(argc, argv, "u:t:c:")) != -1) +#else while ((opt = getopt(argc, argv, "u:t:")) != -1) +#endif { switch(opt) { @@ -319,6 +347,11 @@ int main(int argc, char* argv[]) case 't': TEST_CASE = atoi(optarg); break; + #ifdef CA_INT + case 'c': + CA_CONNTYPE = OCConnectivityType(atoi(optarg)); + break; + #endif default: PrintUsage(); return -1; diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp index dadf129..14adf75 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp @@ -75,6 +75,13 @@ testToTextMap queryInterface[] = { static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}"; +#ifdef CA_INT +//The following variable determines the interface (wifi, ethernet etc.) +//to be used for sending unicast messages. Default set to WIFI. +static OCConnectivityType CA_CONNTYPE = OC_WIFI; +static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core"; +#endif + // The handle for the observe registration OCDoHandle gObserveDoHandle; // After this crosses a threshold client deregisters for further observations @@ -98,7 +105,12 @@ int InitDiscovery(); void PrintUsage() { +#ifdef CA_INT + OC_LOG(INFO, TAG, "Usage : occlientcoll -t -c "); + OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send messages over Ethernet, WIFI, EDR or LE"); +#else OC_LOG(INFO, TAG, "Usage : occlientcoll -t "); +#endif 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"\ @@ -211,8 +223,7 @@ int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse) cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param - ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, (OC_WIFI), OC_LOW_QOS, + ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, CA_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0); #else ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS, @@ -239,9 +250,8 @@ int InitObserveRequest(OCClientResponse * clientResponse) OC_LOG_V(INFO, TAG, "OBSERVE payload from client = %s ", putPayload.c_str()); #ifdef CA_INT - // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param - ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_WIFI, OC_LOW_QOS, - &cbData, NULL, 0); + ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, CA_CONNTYPE, + OC_LOW_QOS, &cbData, NULL, 0); #else ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_LOW_QOS, &cbData, NULL, 0); @@ -273,9 +283,8 @@ int InitPutRequest(OCClientResponse * clientResponse) OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str()); #ifdef CA_INT - // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(), - OC_WIFI, OC_LOW_QOS, &cbData, NULL, 0); + CA_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0); #else ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(), OC_LOW_QOS, &cbData, NULL, 0); @@ -312,8 +321,7 @@ int InitGetRequest(OCClientResponse * clientResponse) cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param - ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_WIFI, OC_LOW_QOS, + ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, CA_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0); #else ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS, @@ -334,14 +342,17 @@ int InitDiscovery() /* Start a discovery query*/ char szQueryUri[64] = { 0 }; +#ifdef CA_INT + strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY); +#else strcpy(szQueryUri, OC_WELL_KNOWN_QUERY); +#endif cbData.cb = discoveryReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to all but should be configurable - add as API param - ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI), + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL, OC_LOW_QOS, &cbData, NULL, 0); #else @@ -362,13 +373,22 @@ int main(int argc, char* argv[]) { uint8_t ifname[] = "eth0"; int opt; +#ifdef CA_INT + while ((opt = getopt(argc, argv, "t:c:")) != -1) +#else while ((opt = getopt(argc, argv, "t:")) != -1) +#endif { switch(opt) { case 't': TEST = atoi(optarg); break; + #ifdef CA_INT + case 'c': + CA_CONNTYPE = OCConnectivityType(atoi(optarg)); + break; + #endif default: PrintUsage(); return -1; diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp index b980443..28db9db 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp @@ -37,6 +37,13 @@ static std::string coapServerIP = "255.255.255.255"; static std::string coapServerPort = "5683"; static std::string coapServerResource = "/a/led"; +#ifdef CA_INT +//The following variable determines the interface (wifi, ethernet etc.) +//to be used for sending unicast messages. Default set to WIFI. +static OCConnectivityType CA_CONNTYPE = OC_WIFI; +static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core"; +#endif + int gQuitFlag = 0; /* SIGINT handler: set gQuitFlag to 1 for graceful termination */ @@ -50,7 +57,12 @@ void handleSigInt(int signum) static void PrintUsage() { +#ifdef CA_INT + OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2|3>"); + OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send unicast messages over Ethernet, WIFI, EDR or LE"); +#else OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>"); +#endif 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"); @@ -70,9 +82,8 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param ret = OCDoResource(&handle, method, query.str().c_str(), 0, - NULL, OC_WIFI, qos, &cbData, options, numOptions); + NULL, CA_CONNTYPE, qos, &cbData, options, numOptions); #else ret = OCDoResource(&handle, method, query.str().c_str(), 0, NULL, qos, &cbData, options, numOptions); @@ -191,15 +202,26 @@ int InitDiscovery() } else { +#ifdef CA_INT + strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY); +#else strcpy(szQueryUri, OC_WELL_KNOWN_QUERY); +#endif } cbData.cb = discoveryReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; #ifdef CA_INT - // TODO-CA: The adapter type is set to all but should be configurable - add as API param - ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI), - OC_LOW_QOS, &cbData, NULL, 0); + if(UNICAST_DISCOVERY) + { + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, CA_CONNTYPE, + OC_LOW_QOS, &cbData, NULL, 0); + } + else + { + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL, + OC_LOW_QOS, &cbData, NULL, 0); + } #else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); #endif @@ -218,7 +240,11 @@ int main(int argc, char* argv[]) uint8_t ifname[] = "eth0"; int opt; +#ifdef CA_INT + while ((opt = getopt(argc, argv, "u:t:c:")) != -1) +#else while ((opt = getopt(argc, argv, "u:t:")) != -1) +#endif { switch(opt) { @@ -228,6 +254,11 @@ int main(int argc, char* argv[]) case 't': TEST_CASE = atoi(optarg); break; + #ifdef CA_INT + case 'c': + CA_CONNTYPE = OCConnectivityType(atoi(optarg)); + break; + #endif default: PrintUsage(); return -1;