RD Server Sample App
authorHabib Virji <habib.virji@samsung.com>
Tue, 18 Aug 2015 13:45:23 +0000 (14:45 +0100)
committerUze Choi <uzchoi@samsung.com>
Wed, 19 Aug 2015 04:20:28 +0000 (04:20 +0000)
Sample application to start and stop resource directory server.

Change-Id: Ic55e66c5e1ce297370cc76de4d92e7ca09702b10
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2234
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-directory/SConscript
service/resource-directory/samples/SConscript [new file with mode: 0644]
service/resource-directory/samples/rd_main.c [new file with mode: 0644]

index fb69246..76200c2 100755 (executable)
@@ -76,3 +76,8 @@ else :
     rdsdk = rd_env.StaticLibrary('resource_directory', rd_src)
 
 rd_env.InstallTarget(rdsdk, 'libresource_directory')
+
+######################################################################
+# Samples for the resource directory
+######################################################################
+SConscript('samples/SConscript')
diff --git a/service/resource-directory/samples/SConscript b/service/resource-directory/samples/SConscript
new file mode 100644 (file)
index 0000000..531e795
--- /dev/null
@@ -0,0 +1,32 @@
+##
+# ResourceDirectory Sample Apps build script
+##
+
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+rd_sample_app_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+rd_sample_app_env.AppendUnique(CPPPATH = ['../include'])
+
+rd_sample_app_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra', '-std=c++0x'])
+rd_sample_app_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+rd_sample_app_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
+rd_sample_app_env.PrependUnique(LIBS = ['resource_directory', 'oc', 'octbstack'])
+
+if env.get('SECURED') == '1':
+    rd_sample_app_env.AppendUnique(LIBS = ['tinydtls'])
+
+####################################################################
+# Source files and Targets
+######################################################################
+rd_server = rd_sample_app_env.Program('rd_server', 'rd_main.c')
+
+Alias("resource_directory", [rd_server])
+
+env.AppendTarget('resource_directory')
diff --git a/service/resource-directory/samples/rd_main.c b/service/resource-directory/samples/rd_main.c
new file mode 100644 (file)
index 0000000..41d5abf
--- /dev/null
@@ -0,0 +1,84 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "rd_server.h"
+
+#include <signal.h>
+#include <unistd.h>
+
+int g_quitFlag = 0;
+
+void handleSigInt(int signum);
+
+/*
+* This method is an entry point of Resource Directory.
+* This function should be run only on the device that it could be host device.
+*/
+
+int main()
+{
+    printf("OCResourceDirectory is starting...\n");
+
+    if (OCRDStart() != OC_STACK_OK)
+    {
+        printf("OCRDStart failed...\n");
+        return 0;
+    }
+
+    printf("OCRDStart successfully...\n");
+
+    signal(SIGINT, handleSigInt);
+    while (!g_quitFlag)
+    {
+        if (OCProcess() != OC_STACK_OK)
+        {
+            OCRDStop();
+            printf("OCStack process error\n");
+            return 0;
+        }
+    }
+
+    if (OCRDStop() != OC_STACK_OK)
+    {
+        printf("OCRDStop failed...\n");
+    }
+    else
+    {
+        printf("OCRDStop success...\n");
+    }
+
+    printf("Exiting OCResourceDirectory main loop...\n");
+    return 0;
+
+}
+
+/*
+* This is a signal handling function for SIGINT(CTRL+C).
+* A Resource Directory handle the SIGINT signal for safe exit.
+*
+* @param[in] signal
+*                 signal number of caught signal.
+*/
+void handleSigInt(int signum)
+{
+    if (signum == SIGINT)
+    {
+        g_quitFlag = 1;
+    }
+}