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

Side by Side Diff: src/main.cc

Issue 5284004: Revert "cashew: do not delete DBus::ObjectProxy objects from D-Bus callbacks" (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
« no previous file with comments | « src/cashew_server.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>
(...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
52 g_main_loop_quit(main_loop); 50 g_main_loop_quit(main_loop);
53 } 51 }
54 } 52 }
55 53
56 int InstallSignalHandlers() { 54 int InstallSignalHandlers() {
57 sigset_t mask; 55 sigset_t mask;
58 if (sigemptyset(&mask) < 0) { 56 if (sigemptyset(&mask) < 0) {
59 PLOG(ERROR) << "sigemptyset failed"; 57 PLOG(ERROR) << "sigemptyset failed";
60 return -1; 58 return -1;
61 } 59 }
(...skipping 11 matching lines...) Expand all
73 } 71 }
74 if (InstallSignalHandler(SIGTERM, OnSignal, mask) < 0) { 72 if (InstallSignalHandler(SIGTERM, OnSignal, mask) < 0) {
75 PLOG(ERROR) << "couldn't install SIGTERM handler"; 73 PLOG(ERROR) << "couldn't install SIGTERM handler";
76 return -1; 74 return -1;
77 } 75 }
78 return 0; 76 return 0;
79 } 77 }
80 78
81 // should not be called while event loop is running 79 // should not be called while event loop is running
82 static void CleanUpForExit() { 80 static void CleanUpForExit() {
83 DCHECK(main_loop == NULL || !g_main_loop_is_running(main_loop));
84 DLOG(INFO) << "cleaning up"; 81 DLOG(INFO) << "cleaning up";
85 delete server; 82 delete server;
86 server = NULL; 83 server = NULL;
87 delete service_manager; 84 delete service_manager;
88 service_manager = NULL; 85 service_manager = NULL;
89 DBus::default_dispatcher = NULL; 86 DBus::default_dispatcher = NULL;
90 delete dispatcher; 87 delete dispatcher;
91 dispatcher = NULL; 88 dispatcher = NULL;
92 if (main_loop != NULL) { 89 if (main_loop != NULL) {
93 g_main_loop_unref(main_loop); 90 g_main_loop_unref(main_loop);
(...skipping 27 matching lines...) Expand all
121 cashew::CleanUpForExit(); 118 cashew::CleanUpForExit();
122 exit(EXIT_FAILURE); 119 exit(EXIT_FAILURE);
123 } 120 }
124 DBus::default_dispatcher = cashew::dispatcher; 121 DBus::default_dispatcher = cashew::dispatcher;
125 cashew::dispatcher->attach(NULL); 122 cashew::dispatcher->attach(NULL);
126 123
127 DLOG(INFO) << "creating service manager"; 124 DLOG(INFO) << "creating service manager";
128 DBus::Connection client_conn = DBus::Connection::SystemBus(); 125 DBus::Connection client_conn = DBus::Connection::SystemBus();
129 client_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds); 126 client_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds);
130 cashew::service_manager = new(std::nothrow) cashew::ServiceManager( 127 cashew::service_manager = new(std::nothrow) cashew::ServiceManager(
131 client_conn, cashew::main_loop); 128 client_conn);
132 if (cashew::service_manager == NULL) { 129 if (cashew::service_manager == NULL) {
133 LOG(ERROR) << "couldn't create service manager"; 130 LOG(ERROR) << "couldn't create service manager";
134 cashew::CleanUpForExit(); 131 cashew::CleanUpForExit();
135 exit(EXIT_FAILURE); 132 exit(EXIT_FAILURE);
136 } 133 }
137 134
138 DLOG(INFO) << "creating cashew server"; 135 DLOG(INFO) << "creating cashew server";
139 // 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?
140 DBus::Connection server_conn = DBus::Connection::SystemBus(); 137 DBus::Connection server_conn = DBus::Connection::SystemBus();
141 server_conn.request_name(cashew::CashewServer::kServiceName); 138 server_conn.request_name(cashew::CashewServer::kServiceName);
142 server_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds); 139 server_conn.set_timeout(cashew::kDBusConnectionTimeoutMilliseconds);
143 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn, 140 cashew::server = new(std::nothrow) cashew::CashewServer(server_conn,
144 cashew::service_manager, cashew::main_loop); 141 cashew::service_manager);
145 if (cashew::server == NULL) { 142 if (cashew::server == NULL) {
146 LOG(ERROR) << "couldn't create cashew server"; 143 LOG(ERROR) << "couldn't create cashew server";
147 cashew::CleanUpForExit(); 144 cashew::CleanUpForExit();
148 exit(EXIT_FAILURE); 145 exit(EXIT_FAILURE);
149 } 146 }
150 147
151 if (cashew::InstallSignalHandlers() < 0) { 148 if (cashew::InstallSignalHandlers() < 0) {
152 LOG(ERROR) << "couldn't install signal handlers"; 149 LOG(ERROR) << "couldn't install signal handlers";
153 cashew::CleanUpForExit(); 150 cashew::CleanUpForExit();
154 exit(EXIT_FAILURE); 151 exit(EXIT_FAILURE);
155 } 152 }
156 153
157 DLOG(INFO) << "entering event loop"; 154 DLOG(INFO) << "entering event loop";
158 g_main_loop_run(cashew::main_loop); 155 g_main_loop_run(cashew::main_loop);
159 DLOG(INFO) << "exited event loop"; 156 DLOG(INFO) << "exited event loop";
160 cashew::CleanUpForExit(); 157 cashew::CleanUpForExit();
161 exit(EXIT_SUCCESS); 158 exit(EXIT_SUCCESS);
162 } 159 }
OLDNEW
« no previous file with comments | « src/cashew_server.cc ('k') | src/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698