Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / SimpleClientServer / ocrouting.cpp
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
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <string>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <signal.h>
28 #include <pthread.h>
29 #include <array>
30 #include "ocstack.h"
31 #include "logger.h"
32 #include "ocpayload.h"
33
34 #define TAG "ocrouting"
35
36 int gQuitFlag = 0;
37
38 /* SIGINT handler: set gQuitFlag to 1 for graceful termination */
39 void handleSigInt(int signum)
40 {
41     if (signum == SIGINT)
42     {
43         gQuitFlag = 1;
44     }
45 }
46
47 int main()
48 {
49     OC_LOG(DEBUG, TAG, "OCRouting sample is starting...");
50
51     if (OCInit(NULL, 0, OC_GATEWAY) != OC_STACK_OK)
52     {
53         OC_LOG(ERROR, TAG, "OCStack init error");
54         return 0;
55     }
56
57     // Break from loop with Ctrl-C
58     OC_LOG(INFO, TAG, "Entering ocrouting main loop...");
59
60     signal(SIGINT, handleSigInt);
61
62     while (!gQuitFlag)
63     {
64         if (OCProcess() != OC_STACK_OK)
65         {
66             OC_LOG(ERROR, TAG, "OCStack process error");
67             return 0;
68         }
69     }
70
71     OC_LOG(INFO, TAG, "Exiting ocrouting main loop...");
72
73     if (OCStop() != OC_STACK_OK)
74     {
75         OC_LOG(ERROR, TAG, "OCStack process error");
76     }
77
78     return 0;
79 }