From f03bb7a05b60f050a3f886ed647bf367a5cbc4d4 Mon Sep 17 00:00:00 2001 From: Vijay Date: Wed, 24 Dec 2014 16:36:06 -0800 Subject: [PATCH] [CA Integration] Updated C sample apps to accept connectivity type param Change-Id: Ibb6ed2142e9f26981538c386ff38eeeca91f4f8e Signed-off-by: Vijay Kesavan --- .../samples/linux/SimpleClientServer/makefile | 4 +-- .../samples/linux/SimpleClientServer/occlient.cpp | 23 ++++++++++++++++ .../linux/SimpleClientServer/occlientbasicops.cpp | 13 +++++++++ .../linux/SimpleClientServer/occlientcoll.cpp | 31 ++++++++++++++++++++++ .../linux/SimpleClientServer/occlientslow.cpp | 15 +++++++++-- resource/examples/makefile | 9 ++++--- 6 files changed, 87 insertions(+), 8 deletions(-) diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/makefile b/resource/csdk/stack/samples/linux/SimpleClientServer/makefile index 26eaa6a..bc3a0e5 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/makefile +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/makefile @@ -67,10 +67,10 @@ INC_DIRS += -I$(CJSON_INC) # TODO-CA Remove -fstack-protector-all before merging to master CC_FLAGS.debug := -O0 -g3 -Wall -fstack-protector-all -ffunction-sections -fdata-sections -fno-exceptions \ - -std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG + -std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG -DCA_INT # TODO-CA Remove -fstack-protector-all before merging to master CC_FLAGS.release := -Os -Wall -fstack-protector-all -fdata-sections -Wl,--gc-sections -Wl,-s -fno-exceptions \ - -std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG + -std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG -DCA_INT LDLIBS += -loctbstack -lpthread -L$(CONNECTIVITY_DIR)/build/out -lconnectivity_abstraction CPPFLAGS += $(CC_FLAGS.$(BUILD)) $(LDLIBS) diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index d9dec6c..22ebc4a 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -104,9 +104,15 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; +#ifdef CA_INT + ret = OCDoResource(&handle, method, query.str().c_str(), 0, + (method == OC_REST_PUT) ? putPayload.c_str() : NULL, + (OC_WIFI), qos, &cbData, options, numOptions); +#else ret = OCDoResource(&handle, method, query.str().c_str(), 0, (method == OC_REST_PUT) ? putPayload.c_str() : NULL, qos, &cbData, options, numOptions); +#endif if (ret != OC_STACK_OK) { @@ -289,10 +295,17 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle, remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3); OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu); +#ifdef CA_INT + OC_LOG_V(INFO, TAG, + "Device =============> Discovered %s @ %d.%d.%d.%d:%d", + clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1], + remoteIpAddr[2], remoteIpAddr[3], remotePortNu); +#else OC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %d.%d.%d.%d:%d", clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1], remoteIpAddr[2], remoteIpAddr[3], remotePortNu); +#endif parseClientResponse(clientResponse); @@ -568,7 +581,12 @@ int InitDeviceDiscovery() (strlen(TEST_APP_MULTICAST_DEVICE_DISCOVERY_QUERY) + 1)); } +#ifdef CA_INT + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI | OC_LE), + OC_LOW_QOS, &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { @@ -601,7 +619,12 @@ int InitDiscovery() cbData.cb = discoveryReqCB; cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; +#ifdef CA_INT + ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI | OC_LE), + OC_LOW_QOS, &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp index a526935..a75b559 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp @@ -70,9 +70,16 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, 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, method, query.str().c_str(), 0, + (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL, + OC_WIFI, 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, qos, &cbData, options, numOptions); +#endif if (ret != OC_STACK_OK) { @@ -267,7 +274,13 @@ int InitDiscovery() 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_LE), + OC_LOW_QOS, &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp index e8db15a..d025407 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp @@ -210,8 +210,14 @@ int InitGetRequestToUnavailableResource(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, + &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); @@ -232,8 +238,14 @@ int InitObserveRequest(OCClientResponse * clientResponse) cbData.cd = NULL; 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); +#else ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); @@ -260,8 +272,14 @@ int InitPutRequest(OCClientResponse * clientResponse) cbData.cd = NULL; 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); +#else ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(), OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); @@ -293,8 +311,14 @@ int InitGetRequest(OCClientResponse * clientResponse) cbData.cb = getReqCB; 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, + &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); @@ -315,8 +339,15 @@ int InitDiscovery() 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_LE), + OC_LOW_QOS, + &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp index 689b015..4a374df 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp @@ -69,9 +69,14 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, 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, method, query.str().c_str(), 0, - NULL, - qos, &cbData, options, numOptions); + NULL, OC_WIFI, qos, &cbData, options, numOptions); +#else + ret = OCDoResource(&handle, method, query.str().c_str(), 0, + NULL, qos, &cbData, options, numOptions); +#endif if (ret != OC_STACK_OK) { @@ -191,7 +196,13 @@ int InitDiscovery() 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_LE), + OC_LOW_QOS, &cbData, NULL, 0); +#else ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); +#endif if (ret != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack resource error"); diff --git a/resource/examples/makefile b/resource/examples/makefile index 3387126..bc411b8 100755 --- a/resource/examples/makefile +++ b/resource/examples/makefile @@ -26,9 +26,10 @@ CXX := g++ #CXX := clang OUT_DIR := $(BUILD) -CXX_FLAGS.debug := -O0 -g3 -std=c++0x -Wall -pthread +#TODO-CA Remove the CA Flag later +CXX_FLAGS.debug := -O0 -g3 -std=c++0x -Wall -pthread -DCA_INT -CXX_FLAGS.release := -O3 -std=c++0x -Wall -pthread +CXX_FLAGS.release := -O3 -std=c++0x -Wall -pthread -DCA_INT CXX_INC := -I../include/ CXX_INC += -I../oc_logger/include @@ -117,8 +118,8 @@ devicediscoveryserver: devicediscoveryserver.cpp devicediscoveryclient: devicediscoveryclient.cpp $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ devicediscoveryclient.cpp $(CXX_INC) $(CXX_LIBS) - - + + ocicuc_target: cd ocicuc && $(MAKE) apps -- 2.7.4