Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / notification-manager / SampleApp / linux / notificationManager / main.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 #include <signal.h>
22 #include <unistd.h>
23
24 #include "hosting.h"
25
26 int g_quitFlag = 0;
27
28 void handleSigInt(int signum);
29
30 /*
31 * This method is an entry point of Resource Hosting Manager.
32 * This function should be run only on the device that it could be host device.
33 */
34 int main()
35 {
36     printf("OCResourceHosting is starting...\n");
37
38     if (OICStartCoordinate() != OC_STACK_OK)
39     {
40         printf("OICStartCoordinate fail\n");
41         return 0;
42     }
43
44     printf("OCResourceHosting Started Successfully \n");
45
46     signal(SIGINT, handleSigInt);
47     while (!g_quitFlag)
48     {
49         sleep(2);
50     }
51
52     if (OICStopCoordinate() != OC_STACK_OK)
53     {
54         printf("OICStopCoordinate error\n");
55     }
56     else
57     {
58         printf("OICStopCoordinate success\n");
59     }
60
61     printf("Exiting occlient main loop...\n");
62     return 0;
63
64 }
65
66 /*
67 * This is a signal handling function for SIGINT(CTRL+C).
68 * A Resource Coordinator handle the SIGINT signal for safe exit.
69 *
70 * @param[in] signal
71 *                 signal number of caught signal.
72 */
73 void handleSigInt(int signum)
74 {
75     if (signum == SIGINT)
76     {
77         g_quitFlag = 1;
78     }
79 }