| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cromo_server.h" | 5 #include "cromo_server.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <syslog.h> | 9 #include <syslog.h> |
| 10 #include <sys/signalfd.h> | 10 #include <sys/signalfd.h> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 g_main_loop_quit(main_loop); | 54 g_main_loop_quit(main_loop); |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 g_timeout_add_seconds(1, test_for_exit, &kExitTries); | 57 g_timeout_add_seconds(1, test_for_exit, &kExitTries); |
| 58 } | 58 } |
| 59 | 59 |
| 60 static gboolean do_signal(void *arg) { | 60 static gboolean do_signal(void *arg) { |
| 61 int sig = reinterpret_cast<int>(arg); | 61 int sig = reinterpret_cast<int>(arg); |
| 62 LOG(INFO) << "Signal: " << sig; | 62 LOG(INFO) << "Signal: " << sig; |
| 63 | 63 |
| 64 if (sig == SIGTERM) { | 64 if (sig == SIGTERM || sig == SIGINT) { |
| 65 exit_main_loop(); | 65 exit_main_loop(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 return FALSE; | 68 return FALSE; |
| 69 } | 69 } |
| 70 | 70 |
| 71 static void *handle_signals(void *arg) { | 71 static void *handle_signals(void *arg) { |
| 72 sigset_t sigs; | 72 sigset_t sigs; |
| 73 siginfo_t info; | 73 siginfo_t info; |
| 74 info.si_signo = 0; | 74 info.si_signo = 0; |
| 75 sigemptyset(&sigs); | 75 sigemptyset(&sigs); |
| 76 sigaddset(&sigs, SIGTERM); | 76 sigaddset(&sigs, SIGTERM); |
| 77 sigaddset(&sigs, SIGINT); | 77 sigaddset(&sigs, SIGINT); |
| 78 LOG(INFO) << "waiting for signals"; | 78 LOG(INFO) << "waiting for signals"; |
| 79 while (info.si_signo != SIGTERM) { | 79 while (info.si_signo != SIGTERM && info.si_signo != SIGINT) { |
| 80 sigwaitinfo(&sigs, &info); | 80 sigwaitinfo(&sigs, &info); |
| 81 g_idle_add(do_signal, reinterpret_cast<void*>(info.si_signo)); | 81 g_idle_add(do_signal, reinterpret_cast<void*>(info.si_signo)); |
| 82 } | 82 } |
| 83 return NULL; | 83 return NULL; |
| 84 } | 84 } |
| 85 | 85 |
| 86 static gboolean setup_signals(void* arg) { | 86 static gboolean setup_signals(void* arg) { |
| 87 pthread_t thr; | 87 pthread_t thr; |
| 88 pthread_create(&thr, NULL, handle_signals, NULL); | 88 pthread_create(&thr, NULL, handle_signals, NULL); |
| 89 return FALSE; | 89 return FALSE; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 192 |
| 193 block_signals(); | 193 block_signals(); |
| 194 | 194 |
| 195 DBus::default_dispatcher = &dispatcher; | 195 DBus::default_dispatcher = &dispatcher; |
| 196 dispatcher.attach(NULL); | 196 dispatcher.attach(NULL); |
| 197 | 197 |
| 198 DBus::Connection conn = DBus::Connection::SystemBus(); | 198 DBus::Connection conn = DBus::Connection::SystemBus(); |
| 199 conn.request_name(CromoServer::kServiceName); | 199 conn.request_name(CromoServer::kServiceName); |
| 200 | 200 |
| 201 server = new CromoServer(conn); | 201 server = new CromoServer(conn); |
| 202 MessageHandler m(server); | |
| 203 char buf[256]; | 202 char buf[256]; |
| 204 snprintf(buf, sizeof(buf), "type='signal',interface='%s',member='%s'", | 203 snprintf(buf, sizeof(buf), "type='signal',interface='%s',member='%s'", |
| 205 kDBusInterface, kDBusNameOwnerChanged); | 204 kDBusInterface, kDBusNameOwnerChanged); |
| 206 conn.add_match(buf); | 205 conn.add_match(buf); |
| 207 snprintf(buf, sizeof(buf), "type='signal',interface='%s',member='%s'", | 206 snprintf(buf, sizeof(buf), "type='signal',interface='%s',member='%s'", |
| 208 power_manager::kPowerManagerInterface, | 207 power_manager::kPowerManagerInterface, |
| 209 power_manager::kSuspendDelay); | 208 power_manager::kSuspendDelay); |
| 210 conn.add_match(buf); | 209 conn.add_match(buf); |
| 211 DBus::MessageSlot mslot; | 210 DBus::MessageSlot mslot; |
| 212 mslot = &m; | 211 mslot = new MessageHandler(server); |
| 213 if (!conn.add_filter(mslot)) { | 212 if (!conn.add_filter(mslot)) { |
| 214 LOG(ERROR) << "Can't add filter"; | 213 LOG(ERROR) << "Can't add filter"; |
| 215 } else { | 214 } else { |
| 216 LOG(INFO) << "Registered filter."; | 215 LOG(INFO) << "Registered filter."; |
| 217 } | 216 } |
| 218 | 217 |
| 219 // Add carriers before plugins so that they can be overidden | 218 // Add carriers before plugins so that they can be overidden |
| 220 AddBaselineCarriers(server); | 219 AddBaselineCarriers(server); |
| 221 | 220 |
| 222 // Instantiate modem handlers for each type of hardware supported | 221 // Instantiate modem handlers for each type of hardware supported |
| 223 PluginManager::LoadPlugins(server, FLAGS_plugins); | 222 PluginManager::LoadPlugins(server, FLAGS_plugins); |
| 224 server->CheckForPowerDaemon(); | 223 server->CheckForPowerDaemon(); |
| 225 | 224 |
| 226 dispatcher.enter(); | 225 dispatcher.enter(); |
| 227 g_thread_init(NULL); | 226 g_thread_init(NULL); |
| 228 main_loop = g_main_loop_new(NULL, false); | 227 main_loop = g_main_loop_new(NULL, false); |
| 229 g_idle_add(setup_signals, NULL); | 228 g_idle_add(setup_signals, NULL); |
| 230 g_main_loop_run(main_loop); | 229 g_main_loop_run(main_loop); |
| 231 | 230 |
| 232 return 0; | 231 return 0; |
| 233 } | 232 } |
| OLD | NEW |