csdk: fix minimal linux tests
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Wed, 20 Jul 2016 15:12:14 +0000 (17:12 +0200)
committerZiran Sun <ziran.sun@samsung.com>
Wed, 3 Aug 2016 13:31:59 +0000 (13:31 +0000)
Update to current API, and make them build by default.

Those samples files are good candidates
 to illustrate C API in plain C and not C++,
 specially for systems without recent g++ (ie: Tizen:2.2-)

Change-Id: I22e18903037a249e1dce4d29c2580ffe865caf50
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9515
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
resource/SConscript
resource/csdk/stack/test/linux/SConscript [new file with mode: 0644]
resource/csdk/stack/test/linux/occlient.c
resource/csdk/stack/test/linux/ocserver.c

index 554bb9d..1542c2f 100644 (file)
@@ -66,6 +66,7 @@ if target_os not in ['arduino','darwin','ios','android']:
 
 if target_os in ['linux', 'windows']:
        # Build C Samples
+       SConscript('csdk/stack/test/linux/SConscript')
        SConscript('csdk/stack/samples/linux/SimpleClientServer/SConscript')
 
        # Build secure samples
diff --git a/resource/csdk/stack/test/linux/SConscript b/resource/csdk/stack/test/linux/SConscript
new file mode 100644 (file)
index 0000000..dbc895c
--- /dev/null
@@ -0,0 +1,43 @@
+#******************************************************************
+#
+# Copyright: 2016, Samsung Electronics Co., Ltd.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+csdktest_env = env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+csdktest_env.PrependUnique(CPPPATH = [
+    '../../../stack/include',
+])
+
+csdktest_env.PrependUnique(LIBS = [
+    'octbstack',
+])
+
+csdktest_env.AppendUnique(LIBPATH = [
+    csdktest_env.get('BUILD_DIR'),
+])
+
+######################################################################
+# Source files and Targets
+######################################################################
+occlient = csdktest_env.Program('occlient', ['occlient.c'])
+ocserver = csdktest_env.Program('ocserver', ['ocserver.c'])
index d646439..1180def 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
 #include <ocstack.h>
 #include <logger.h>
 
@@ -43,7 +48,7 @@ OCStackApplicationResult applicationDiscoverCB(
         OCClientResponse * clientResponse) {
     OIC_LOG(INFO, TAG, "Entering applicationDiscoverCB (Application Layer CB)");
     OIC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %s:%d",
-                                    clientResponse->resJSONPayload,
+                                    clientResponse->resourceUri,
                                     clientResponse->devAddr.addr,
                                     clientResponse->devAddr.port);
     //return OC_STACK_DELETE_TRANSACTION;
@@ -51,7 +56,7 @@ OCStackApplicationResult applicationDiscoverCB(
 }
 
 int main() {
-    OIC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
+    OIC_LOG_V(INFO, TAG, "Starting occlient");
 
     /* Initialize OCStack*/
     if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
@@ -61,9 +66,9 @@ int main() {
 
     /* Start a discovery query*/
     char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
-    strcpy(szQueryUri, OC_EXPLICIT_DEVICE_DISCOVERY_URI);
-    if (OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS,
-            0, 0, 0) != OC_STACK_OK) {
+    strcpy(szQueryUri, OC_MULTICAST_DISCOVERY_URI);
+    if (OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, 
+            CT_DEFAULT, OC_LOW_QOS, 0, 0, 0) != OC_STACK_OK) {
         OIC_LOG(ERROR, TAG, "OCStack resource error");
         return 0;
     }
index c587a0b..ecc2c86 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
 #include <signal.h>
 #include <stdbool.h>
 #include <ocstack.h>
@@ -48,7 +53,7 @@ void handleSigInt(int signum) {
 }
 
 int main() {
-    OIC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
+    OIC_LOG_V(INFO, TAG, "Starting ocserver");
     if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) {
         OIC_LOG(ERROR, TAG, "OCStack init error");
         return 0;
@@ -91,6 +96,7 @@ OCStackResult createLightResource() {
                     "core.rw",
                     "/a/light",
                     0,
+                    NULL,
                     OC_DISCOVERABLE|OC_OBSERVABLE);
     return res;
 }