RD Server Sample App
[platform/upstream/iotivity.git] / service / resource-directory / samples / rd_main.c
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #include "rd_server.h"
21
22 #include <signal.h>
23 #include <unistd.h>
24
25 int g_quitFlag = 0;
26
27 void handleSigInt(int signum);
28
29 /*
30 * This method is an entry point of Resource Directory.
31 * This function should be run only on the device that it could be host device.
32 */
33
34 int main()
35 {
36     printf("OCResourceDirectory is starting...\n");
37
38     if (OCRDStart() != OC_STACK_OK)
39     {
40         printf("OCRDStart failed...\n");
41         return 0;
42     }
43
44     printf("OCRDStart successfully...\n");
45
46     signal(SIGINT, handleSigInt);
47     while (!g_quitFlag)
48     {
49         if (OCProcess() != OC_STACK_OK)
50         {
51             OCRDStop();
52             printf("OCStack process error\n");
53             return 0;
54         }
55     }
56
57     if (OCRDStop() != OC_STACK_OK)
58     {
59         printf("OCRDStop failed...\n");
60     }
61     else
62     {
63         printf("OCRDStop success...\n");
64     }
65
66     printf("Exiting OCResourceDirectory main loop...\n");
67     return 0;
68
69 }
70
71 /*
72 * This is a signal handling function for SIGINT(CTRL+C).
73 * A Resource Directory handle the SIGINT signal for safe exit.
74 *
75 * @param[in] signal
76 *                 signal number of caught signal.
77 */
78 void handleSigInt(int signum)
79 {
80     if (signum == SIGINT)
81     {
82         g_quitFlag = 1;
83     }
84 }