Modify flora license version.
[platform/core/messaging/msg-service.git] / msg_helper / main.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <glib.h>
19 #include <sys/time.h>
20 #include <stdlib.h>
21
22 #include "MsgHelper.h"
23 #include "MsgUtilFile.h"
24 #include "MsgCppTypes.h"
25 #include "MsgDebug.h"
26
27 static GMainLoop *loop;
28
29 static gboolean _worker_done(void* data)
30 {
31         if (g_main_loop_is_running(loop))
32                 g_main_loop_quit(loop);
33
34         return 0;
35 }
36
37 // may called by threads
38 void worker_done()
39 {
40         g_idle_add(_worker_done,NULL);
41 }
42
43 int main(int argc, char** argv)
44 {
45
46         MSG_DEBUG("############### Start msg_helper ###############");
47
48 #if !GLIB_CHECK_VERSION(2, 31, 0)
49         g_thread_init(NULL);
50 #endif
51
52         bool notEnd = false;
53
54         if(argc < 1)
55         {
56                 MSG_DEBUG("No arguments to run msg_helper.");
57                 return 0;
58         }
59
60         MSG_DEBUG("argv[0] [%s] ", argv[0]);
61
62         if(g_strcmp0(argv[0], MSG_NORMAL_SOUND_START) == 0)
63         {
64                 MsgSoundPlayStart(false);
65                 notEnd = true;
66         }
67         if(g_strcmp0(argv[0], MSG_EMERGENCY_SOUND_START) == 0)
68         {
69                 MsgSoundPlayStart(true);
70                 notEnd = true;
71         }
72         else if(g_strcmp0(argv[0],MSG_SOUND_STOP) == 0)
73         {
74                 MsgSoundPlayStop();
75         }
76
77         if(notEnd)
78         {
79                 loop = g_main_loop_new(NULL, FALSE);
80
81                 if (MsgSensorConnect() == MSG_SUCCESS)
82                         if (MsgRegSensorCB(&worker_done) != MSG_SUCCESS)
83                                 MsgSensorDisconnect();
84
85                 if (loop != NULL)
86                 {
87                         MSG_DEBUG("Waiting for working jobs to be finished!!!");
88
89                         // Run GMainLoop
90                         g_main_loop_run(loop);
91                 }
92                 else
93                 {
94                         MSG_DEBUG("Fail to create g_main_loop!!!");
95                         MsgSensorDisconnect();
96                 }
97         }
98
99         return 0;
100 }