[CA Integration] Updated C sample apps to accept connectivity type param
authorVijay <vijay.s.kesavan@intel.com>
Thu, 25 Dec 2014 00:36:06 +0000 (16:36 -0800)
committerVijay <vijay.s.kesavan@intel.com>
Thu, 25 Dec 2014 00:36:06 +0000 (16:36 -0800)
Change-Id: Ibb6ed2142e9f26981538c386ff38eeeca91f4f8e
Signed-off-by: Vijay Kesavan <vijay.s.kesavan@intel.com>
resource/csdk/stack/samples/linux/SimpleClientServer/makefile
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientcoll.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp
resource/examples/makefile

index 26eaa6a..bc3a0e5 100644 (file)
@@ -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)
index d9dec6c..22ebc4a 100644 (file)
@@ -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");
index a526935..a75b559 100644 (file)
@@ -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");
index e8db15a..d025407 100644 (file)
@@ -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");
index 689b015..4a374df 100644 (file)
@@ -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");
index 3387126..bc411b8 100755 (executable)
@@ -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