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

Side by Side Diff: src/main.cc

Issue 5380002: cashew: defer all D-Bus signal processing to main loop (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Created 10 years 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
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>
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 static DBus::Glib::BusDispatcher *dispatcher = NULL; 42 static DBus::Glib::BusDispatcher *dispatcher = NULL;
43 static GMainLoop *main_loop = NULL; 43 static GMainLoop *main_loop = NULL;
44 static CashewServer *server = NULL; 44 static CashewServer *server = NULL;
45 static ServiceManager *service_manager = NULL; 45 static ServiceManager *service_manager = NULL;
46 46
47 static void OnSignal(int signal) { 47 static void OnSignal(int signal) {
48 DLOG(INFO) << "received signal " << signal; 48 DLOG(INFO) << "received signal " << signal;
49 if (main_loop != NULL) { 49 if (main_loop != NULL) {
50 // TODO(vlaviano): g_idle_add a callback to quit the main loop instead of
51 // doing it directly here to remove some low severity races
50 g_main_loop_quit(main_loop); 52 g_main_loop_quit(main_loop);
51 } 53 }
52 } 54 }
53 55
54 int InstallSignalHandlers() { 56 int InstallSignalHandlers() {
55 sigset_t mask; 57 sigset_t mask;
56 if (sigemptyset(&mask) < 0) { 58 if (sigemptyset(&mask) < 0) {
57 PLOG(ERROR) << "sigemptyset failed"; 59 PLOG(ERROR) << "sigemptyset failed";
58 return -1; 60 return -1;
59 } 61 }
(...skipping 11 matching lines...) Expand all
71 } 73 }
72 if (InstallSignalHandler(SIGTERM, OnSignal, mask) < 0) { 74 if (InstallSignalHandler(SIGTERM, OnSignal, mask) < 0) {
73 PLOG(ERROR) << "couldn't install SIGTERM handler"; 75 PLOG(ERROR) << "couldn't install SIGTERM handler";
74 return -1; 76 return -1;
75 } 77 }
76 return 0; 78 return 0;
77 } 79 }
78 80
79 // should not be called while event loop is running 81 // should not be called while event loop is running
80 static void CleanUpForExit() { 82 static void CleanUpForExit() {
83 DCHECK(main_loop == NULL || !g_main_loop_is_running(main_loop));
81 DLOG(INFO) << "cleaning up"; 84 DLOG(INFO) << "cleaning up";
82 delete server; 85 delete server;
83 server = NULL; 86 server = NULL;
84 delete service_manager; 87 delete service_manager;
85 service_manager = NULL; 88 service_manager = NULL;
86 DBus::default_dispatcher = NULL; 89 DBus::default_dispatcher = NULL;
87 delete dispatcher; 90 delete dispatcher;
88 dispatcher = NULL; 91 dispatcher = NULL;
89 if (main_loop != NULL) { 92 if (main_loop != NULL) {
90 g_main_loop_unref(main_loop); 93 g_main_loop_unref(main_loop);
(...skipping 27 matching lines...) Expand all
118 cashew::CleanUpForExit(); 121 cashew::CleanUpForExit();
119 exit(EXIT_FAILURE); 122 exit(EXIT_FAILURE);
120 } 123 }
121 DBus::default_dispatcher = cashew::dispatcher; 124 DBus::default_dispatcher = cashew::dispatcher;
122 cashew::dispatcher->attach(NULL); 125 cashew::dispatcher->attach(NULL);
123 126
124 DLOG(INFO) << "creating service manager"; 127 DLOG(INFO) << "creating service manager";
125 DBus::Connection client_conn = DBus::Connection::SystemBus(); 128 DBus::Connection client_conn = DBus::Connection::SystemBus();
126 client_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds); 129 client_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds);
127 cashew::service_manager = new(std::nothrow) cashew::ServiceManager( 130 cashew::service_manager = new(std::nothrow) cashew::ServiceManager(
128 client_conn); 131 client_conn, cashew::main_loop);
129 if (cashew::service_manager == NULL) { 132 if (cashew::service_manager == NULL) {
130 LOG(ERROR) << "couldn't create service manager"; 133 LOG(ERROR) << "couldn't create service manager";
131 cashew::CleanUpForExit(); 134 cashew::CleanUpForExit();
132 exit(EXIT_FAILURE); 135 exit(EXIT_FAILURE);
133 } 136 }
134 137
135 DLOG(INFO) << "creating cashew server"; 138 DLOG(INFO) << "creating cashew server";
136 // TODO(vlaviano): can we share a single conn for client and server roles? 139 // TODO(vlaviano): can we share a single conn for client and server roles?
137 DBus::Connection server_conn = DBus::Connection::SystemBus(); 140 DBus::Connection server_conn = DBus::Connection::SystemBus();
138 server_conn.request_name(cashew::CashewServer::kServiceName); 141 server_conn.request_name(cashew::CashewServer::kServiceName);
139 server_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds); 142 server_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds);
140 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn, 143 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn,
141 cashew::service_manager); 144 cashew::service_manager, cashew::main_loop);
142 if (cashew::server == NULL) { 145 if (cashew::server == NULL) {
143 LOG(ERROR) << "couldn't create cashew server"; 146 LOG(ERROR) << "couldn't create cashew server";
144 cashew::CleanUpForExit(); 147 cashew::CleanUpForExit();
145 exit(EXIT_FAILURE); 148 exit(EXIT_FAILURE);
146 } 149 }
147 150
148 if (cashew::InstallSignalHandlers() < 0) { 151 if (cashew::InstallSignalHandlers() < 0) {
149 LOG(ERROR) << "couldn't install signal handlers"; 152 LOG(ERROR) << "couldn't install signal handlers";
150 cashew::CleanUpForExit(); 153 cashew::CleanUpForExit();
151 exit(EXIT_FAILURE); 154 exit(EXIT_FAILURE);
152 } 155 }
153 156
154 DLOG(INFO) << "entering event loop"; 157 DLOG(INFO) << "entering event loop";
155 g_main_loop_run(cashew::main_loop); 158 g_main_loop_run(cashew::main_loop);
156 DLOG(INFO) << "exited event loop"; 159 DLOG(INFO) << "exited event loop";
157 cashew::CleanUpForExit(); 160 cashew::CleanUpForExit();
158 exit(EXIT_SUCCESS); 161 exit(EXIT_SUCCESS);
159 } 162 }
OLDNEW
« no previous file with comments | « src/device.cc ('k') | src/property_changed_handler.h » ('j') | src/property_changed_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698