Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/main.cc

Issue 3576011: Cashew: track cellular service state. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: Make debug logging less verbose Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/device.cc ('k') | src/service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <config.h> 5 #include <config.h>
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include <dbus-c++/dbus.h> 12 #include <dbus-c++/dbus.h>
13 #include <gflags/gflags.h> 13 #include <gflags/gflags.h>
14 #include <glog/logging.h> 14 #include <glog/logging.h>
15 15
16 #include "src/cashew_server.h" 16 #include "src/cashew_server.h"
17 #include "src/service_manager.h"
17 18
18 namespace cashew { 19 namespace cashew {
19 20
20 typedef int Signal; 21 typedef int Signal;
21 typedef void (*SignalHandler)(Signal signal); 22 typedef void (*SignalHandler)(Signal signal);
22 23
23 int InstallSignalHandler(const Signal signal, 24 int InstallSignalHandler(const Signal signal,
24 const SignalHandler signal_handler, 25 const SignalHandler signal_handler,
25 const sigset_t& mask) { 26 const sigset_t& mask) {
26 DLOG(INFO) << "installing handler for signal " << signal; 27 DLOG(INFO) << "installing handler for signal " << signal;
27 struct sigaction action; 28 struct sigaction action;
28 memset(&action, 0, sizeof(action)); 29 memset(&action, 0, sizeof(action));
29 action.sa_handler = signal_handler; 30 action.sa_handler = signal_handler;
30 action.sa_mask = mask; 31 action.sa_mask = mask;
31 return sigaction(signal, &action, NULL); 32 return sigaction(signal, &action, NULL);
32 } 33 }
33 34
34 static DBus::BusDispatcher *dispatcher = NULL; 35 static DBus::BusDispatcher *dispatcher = NULL;
35 36
36 static CashewServer *server = NULL; 37 static CashewServer *server = NULL;
37 38
39 static ServiceManager *service_manager = NULL;
40
38 static void OnSignal(int signal) { 41 static void OnSignal(int signal) {
39 DLOG(INFO) << "received signal " << signal; 42 DLOG(INFO) << "received signal " << signal;
40 if (dispatcher) { 43 if (dispatcher) {
41 dispatcher->leave(); 44 dispatcher->leave();
42 } 45 }
43 } 46 }
44 47
45 int InstallSignalHandlers() { 48 int InstallSignalHandlers() {
46 sigset_t mask; 49 sigset_t mask;
47 if (sigemptyset(&mask) < 0) { 50 if (sigemptyset(&mask) < 0) {
(...skipping 17 matching lines...) Expand all
65 return -1; 68 return -1;
66 } 69 }
67 return 0; 70 return 0;
68 } 71 }
69 72
70 // should not be called while event loop is running 73 // should not be called while event loop is running
71 static void CleanUpForExit() { 74 static void CleanUpForExit() {
72 DLOG(INFO) << "cleaning up"; 75 DLOG(INFO) << "cleaning up";
73 delete server; 76 delete server;
74 server = NULL; 77 server = NULL;
78 delete service_manager;
79 service_manager = NULL;
75 DBus::default_dispatcher = NULL; 80 DBus::default_dispatcher = NULL;
76 DBus::BusDispatcher *dispatcher_to_delete = dispatcher; 81 DBus::BusDispatcher *dispatcher_to_delete = dispatcher;
77 dispatcher = NULL; 82 dispatcher = NULL;
78 delete dispatcher_to_delete; 83 delete dispatcher_to_delete;
79 // TODO(vlaviano): uncomment when we get a newer version of glog 84 // TODO(vlaviano): uncomment when we get a newer version of glog
80 // google::ShutdownGoogleLogging(); 85 // google::ShutdownGoogleLogging();
81 } 86 }
82 87
83 } // namespace cashew 88 } // namespace cashew
84 89
(...skipping 10 matching lines...) Expand all
95 LOG(ERROR) << "couldn't create dbus dispatcher"; 100 LOG(ERROR) << "couldn't create dbus dispatcher";
96 cashew::CleanUpForExit(); 101 cashew::CleanUpForExit();
97 exit(EXIT_FAILURE); 102 exit(EXIT_FAILURE);
98 } 103 }
99 DBus::default_dispatcher = cashew::dispatcher; 104 DBus::default_dispatcher = cashew::dispatcher;
100 105
101 // TODO(vlaviano): policies 106 // TODO(vlaviano): policies
102 107
103 // TODO(vlaviano): back-end carrier apis 108 // TODO(vlaviano): back-end carrier apis
104 109
110 DLOG(INFO) << "creating service manager";
111 DBus::Connection client_conn = DBus::Connection::SystemBus();
112 cashew::service_manager = new(std::nothrow) cashew::ServiceManager(
113 client_conn);
114 if (cashew::service_manager == NULL) {
115 LOG(ERROR) << "couldn't create service manager";
116 cashew::CleanUpForExit();
117 exit(EXIT_FAILURE);
118 }
119
105 DLOG(INFO) << "creating cashew server"; 120 DLOG(INFO) << "creating cashew server";
106 DBus::Connection conn = DBus::Connection::SystemBus(); 121 // TODO(vlaviano): can we share a single conn for client and server roles?
107 conn.request_name(cashew::CashewServer::kServiceName); 122 DBus::Connection server_conn = DBus::Connection::SystemBus();
108 cashew::server = new(std::nothrow) cashew::CashewServer(conn); 123 server_conn.request_name(cashew::CashewServer::kServiceName);
124 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn,
125 *cashew::service_manager);
109 if (cashew::server == NULL) { 126 if (cashew::server == NULL) {
110 LOG(ERROR) << "couldn't create cashew server"; 127 LOG(ERROR) << "couldn't create cashew server";
111 cashew::CleanUpForExit(); 128 cashew::CleanUpForExit();
112 exit(EXIT_FAILURE); 129 exit(EXIT_FAILURE);
113 } 130 }
114 131
115 if (cashew::InstallSignalHandlers() < 0) { 132 if (cashew::InstallSignalHandlers() < 0) {
116 LOG(ERROR) << "couldn't install signal handlers"; 133 LOG(ERROR) << "couldn't install signal handlers";
117 cashew::CleanUpForExit(); 134 cashew::CleanUpForExit();
118 exit(EXIT_FAILURE); 135 exit(EXIT_FAILURE);
119 } 136 }
120 137
121 DLOG(INFO) << "entering event loop"; 138 DLOG(INFO) << "entering event loop";
122 cashew::dispatcher->enter(); 139 cashew::dispatcher->enter();
123 DLOG(INFO) << "exited event loop"; 140 DLOG(INFO) << "exited event loop";
124 cashew::CleanUpForExit(); 141 cashew::CleanUpForExit();
125 exit(EXIT_SUCCESS); 142 exit(EXIT_SUCCESS);
126 } 143 }
OLDNEW
« no previous file with comments | « src/device.cc ('k') | src/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698