Merge lp:~mhr3/unity/fix-1058619-6.0 into lp:unity/6.0

Proposed by Michal Hruby
Status: Merged
Approved by: Michal Hruby
Approved revision: no longer in the source branch.
Merged at revision: 2761
Proposed branch: lp:~mhr3/unity/fix-1058619-6.0
Merge into: lp:unity/6.0
Diff against target: 86 lines (+23/-5)
1 file modified
UnityCore/GLibDBusProxy.cpp (+23/-5)
To merge this branch: bzr merge lp:~mhr3/unity/fix-1058619-6.0
Reviewer Review Type Date Requested Status
Łukasz Zemczak Approve
Gord Allott (community) Approve
Review via email: mp+127958@code.launchpad.net

Commit message

Attempt to reconnect to DBus proxies if the initial connection fails

Description of the change

Make sure connection to DBus proxies is retried if it fails.

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

+1

review: Approve
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Good to go.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/GLibDBusProxy.cpp'
--- UnityCore/GLibDBusProxy.cpp 2012-09-05 15:45:00 +0000
+++ UnityCore/GLibDBusProxy.cpp 2012-10-04 08:30:54 +0000
@@ -36,6 +36,7 @@
3636
37namespace37namespace
38{38{
39const unsigned MAX_RECONNECTION_ATTEMPTS = 5;
39nux::logging::Logger logger("unity.glib.dbusproxy");40nux::logging::Logger logger("unity.glib.dbusproxy");
40}41}
4142
@@ -55,7 +56,7 @@
55 GDBusProxyFlags flags);56 GDBusProxyFlags flags);
56 ~Impl();57 ~Impl();
5758
58 void StartReconnectionTimeout();59 void StartReconnectionTimeout(unsigned timeout);
59 void Connect();60 void Connect();
6061
61 void Call(string const& method_name,62 void Call(string const& method_name,
@@ -91,6 +92,7 @@
91 glib::Object<GDBusProxy> proxy_;92 glib::Object<GDBusProxy> proxy_;
92 glib::Object<GCancellable> cancellable_;93 glib::Object<GCancellable> cancellable_;
93 bool connected_;94 bool connected_;
95 unsigned reconnection_attempts_;
9496
95 glib::Signal<void, GDBusProxy*, char*, char*, GVariant*> g_signal_connection_;97 glib::Signal<void, GDBusProxy*, char*, char*, GVariant*> g_signal_connection_;
96 glib::Signal<void, GDBusProxy*, GParamSpec*> name_owner_signal_;98 glib::Signal<void, GDBusProxy*, GParamSpec*> name_owner_signal_;
@@ -113,8 +115,9 @@
113 , flags_(flags)115 , flags_(flags)
114 , cancellable_(g_cancellable_new())116 , cancellable_(g_cancellable_new())
115 , connected_(false)117 , connected_(false)
118 , reconnection_attempts_(0)
116{119{
117 StartReconnectionTimeout();120 StartReconnectionTimeout(1);
118}121}
119122
120DBusProxy::Impl::~Impl()123DBusProxy::Impl::~Impl()
@@ -122,7 +125,7 @@
122 g_cancellable_cancel(cancellable_);125 g_cancellable_cancel(cancellable_);
123}126}
124127
125void DBusProxy::Impl::StartReconnectionTimeout()128void DBusProxy::Impl::StartReconnectionTimeout(unsigned timeout)
126{129{
127 LOG_DEBUG(logger) << "Starting reconnection timeout for " << name_;130 LOG_DEBUG(logger) << "Starting reconnection timeout for " << name_;
128131
@@ -134,7 +137,7 @@
134 return false;137 return false;
135 };138 };
136139
137 reconnect_timeout_.reset(new glib::TimeoutSeconds(1, callback));140 reconnect_timeout_.reset(new glib::TimeoutSeconds(timeout, callback));
138}141}
139142
140void DBusProxy::Impl::Connect()143void DBusProxy::Impl::Connect()
@@ -169,12 +172,27 @@
169 // therefore we should deal with the error before touching the impl pointer172 // therefore we should deal with the error before touching the impl pointer
170 if (!proxy || error)173 if (!proxy || error)
171 {174 {
172 LOG_WARNING(logger) << "Unable to connect to proxy: " << error;175 // if the cancellable was cancelled, "self" points to destroyed object
176 if (error && !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
177 {
178 if (self->reconnection_attempts_++ < MAX_RECONNECTION_ATTEMPTS)
179 {
180 LOG_WARNING(logger) << "Unable to connect to proxy: \"" << error
181 << "\"... Trying to reconnect (attempt "
182 << self->reconnection_attempts_ << ")";
183 self->StartReconnectionTimeout(3);
184 }
185 else
186 {
187 LOG_WARNING(logger) << "Unable to connect to proxy: " << error;
188 }
189 }
173 return;190 return;
174 }191 }
175192
176 LOG_DEBUG(logger) << "Sucessfully created proxy: " << self->object_path_;193 LOG_DEBUG(logger) << "Sucessfully created proxy: " << self->object_path_;
177194
195 self->reconnection_attempts_ = 0;
178 self->proxy_ = proxy;196 self->proxy_ = proxy;
179 self->g_signal_connection_.Connect(self->proxy_, "g-signal",197 self->g_signal_connection_.Connect(self->proxy_, "g-signal",
180 sigc::mem_fun(self, &Impl::OnProxySignal));198 sigc::mem_fun(self, &Impl::OnProxySignal));

Subscribers

People subscribed via source and target branches