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

Side by Side Diff: src/main.cc

Issue 4304002: cashew: don't invoke D-Bus methods from within a D-Bus handler (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Created 10 years, 1 month 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 <glib.h> 12 #include <glib.h>
13 13
14 #include <dbus-c++/dbus.h> 14 #include <dbus-c++/dbus.h>
15 #include <dbus-c++/glib-integration.h> 15 #include <dbus-c++/glib-integration.h>
16 #include <gflags/gflags.h> 16 #include <gflags/gflags.h>
17 #include <glog/logging.h> 17 #include <glog/logging.h>
18 18
19 #include "src/cashew_server.h" 19 #include "src/cashew_server.h"
20 #include "src/service_manager.h" 20 #include "src/service_manager.h"
21 21
22 namespace cashew { 22 namespace cashew {
23 23
24 static const int kMillisecondsPerSecond = 1000;
25 static const int kDBusConnectionTimeoutMilliseconds =
26 1 * kMillisecondsPerSecond;
27
24 typedef int Signal; 28 typedef int Signal;
25 typedef void (*SignalHandler)(Signal signal); 29 typedef void (*SignalHandler)(Signal signal);
26 30
27 int InstallSignalHandler(const Signal signal, 31 int InstallSignalHandler(const Signal signal,
28 const SignalHandler signal_handler, 32 const SignalHandler signal_handler,
29 const sigset_t& mask) { 33 const sigset_t& mask) {
30 DLOG(INFO) << "installing handler for signal " << signal; 34 DLOG(INFO) << "installing handler for signal " << signal;
31 struct sigaction action; 35 struct sigaction action;
32 memset(&action, 0, sizeof(action)); 36 memset(&action, 0, sizeof(action));
33 action.sa_handler = signal_handler; 37 action.sa_handler = signal_handler;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if (cashew::dispatcher == NULL) { 116 if (cashew::dispatcher == NULL) {
113 LOG(ERROR) << "couldn't create dbus dispatcher"; 117 LOG(ERROR) << "couldn't create dbus dispatcher";
114 cashew::CleanUpForExit(); 118 cashew::CleanUpForExit();
115 exit(EXIT_FAILURE); 119 exit(EXIT_FAILURE);
116 } 120 }
117 DBus::default_dispatcher = cashew::dispatcher; 121 DBus::default_dispatcher = cashew::dispatcher;
118 cashew::dispatcher->attach(NULL); 122 cashew::dispatcher->attach(NULL);
119 123
120 DLOG(INFO) << "creating service manager"; 124 DLOG(INFO) << "creating service manager";
121 DBus::Connection client_conn = DBus::Connection::SystemBus(); 125 DBus::Connection client_conn = DBus::Connection::SystemBus();
126 client_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds);
122 cashew::service_manager = new(std::nothrow) cashew::ServiceManager( 127 cashew::service_manager = new(std::nothrow) cashew::ServiceManager(
123 client_conn); 128 client_conn);
124 if (cashew::service_manager == NULL) { 129 if (cashew::service_manager == NULL) {
125 LOG(ERROR) << "couldn't create service manager"; 130 LOG(ERROR) << "couldn't create service manager";
126 cashew::CleanUpForExit(); 131 cashew::CleanUpForExit();
127 exit(EXIT_FAILURE); 132 exit(EXIT_FAILURE);
128 } 133 }
129 134
130 DLOG(INFO) << "creating cashew server"; 135 DLOG(INFO) << "creating cashew server";
131 // TODO(vlaviano): can we share a single conn for client and server roles? 136 // TODO(vlaviano): can we share a single conn for client and server roles?
132 DBus::Connection server_conn = DBus::Connection::SystemBus(); 137 DBus::Connection server_conn = DBus::Connection::SystemBus();
133 server_conn.request_name(cashew::CashewServer::kServiceName); 138 server_conn.request_name(cashew::CashewServer::kServiceName);
139 server_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds);
134 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn, 140 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn,
135 cashew::service_manager); 141 cashew::service_manager);
136 if (cashew::server == NULL) { 142 if (cashew::server == NULL) {
137 LOG(ERROR) << "couldn't create cashew server"; 143 LOG(ERROR) << "couldn't create cashew server";
138 cashew::CleanUpForExit(); 144 cashew::CleanUpForExit();
139 exit(EXIT_FAILURE); 145 exit(EXIT_FAILURE);
140 } 146 }
141 147
142 if (cashew::InstallSignalHandlers() < 0) { 148 if (cashew::InstallSignalHandlers() < 0) {
143 LOG(ERROR) << "couldn't install signal handlers"; 149 LOG(ERROR) << "couldn't install signal handlers";
144 cashew::CleanUpForExit(); 150 cashew::CleanUpForExit();
145 exit(EXIT_FAILURE); 151 exit(EXIT_FAILURE);
146 } 152 }
147 153
148 DLOG(INFO) << "entering event loop"; 154 DLOG(INFO) << "entering event loop";
149 g_main_loop_run(cashew::main_loop); 155 g_main_loop_run(cashew::main_loop);
150 DLOG(INFO) << "exited event loop"; 156 DLOG(INFO) << "exited event loop";
151 cashew::CleanUpForExit(); 157 cashew::CleanUpForExit();
152 exit(EXIT_SUCCESS); 158 exit(EXIT_SUCCESS);
153 } 159 }
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