Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / tizen / 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 <iostream>
31 #include "ocstack.h"
32 #include "logger.h"
33 #include "ocpayload.h"
34
35 using namespace std;
36
37 #define TAG "ocrouting"
38
39 int gQuitFlag = 0;
40
41 /* SIGINT handler: set gQuitFlag to 1 for graceful termination */
42 void handleSigInt(int signum)
43 {
44     if (signum == SIGINT)
45     {
46         gQuitFlag = 1;
47     }
48 }
49
50 int main()
51 {
52     cout << "\nOCRouting sample is starting...";
53
54     if (OCInit(NULL, 0, OC_GATEWAY) != OC_STACK_OK)
55     {
56         cout << "\nOCStack init error";
57         return 0;
58     }
59
60     // Break from loop with Ctrl-C
61     cout << "\nEntering ocrouting main loop...";
62
63     signal(SIGINT, handleSigInt);
64
65     while (!gQuitFlag)
66     {
67         if (OCProcess() != OC_STACK_OK)
68         {
69             cout << "\nOCStack process error";
70             return 0;
71         }
72     }
73
74     cout << "\nExiting ocrouting main loop...";
75
76     if (OCStop() != OC_STACK_OK)
77     {
78         cout << "\nOCStack process error";
79     }
80
81     return 0;
82 }