Merge lp:~unity-api-team/indicator-network/lp1411714-15.04 into lp:indicator-network/15.04

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: Antti Kaijanmäki
Approved revision: 472
Merged at revision: 474
Proposed branch: lp:~unity-api-team/indicator-network/lp1411714-15.04
Merge into: lp:indicator-network/15.04
Diff against target: 364 lines (+76/-78)
4 files modified
src/dbus-cpp/services/ofono.h (+10/-4)
src/indicator/modem.cpp (+53/-58)
src/menumodel-cpp/gio-helpers/util.cpp (+12/-15)
src/menumodel-cpp/gio-helpers/util.h (+1/-1)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/lp1411714-15.04
Reviewer Review Type Date Requested Status
Antti Kaijanmäki (community) Approve
Review via email: mp+248104@code.launchpad.net

Commit message

* Guard access to ofono::Modem properties that have a
  shared_ptr inside them with a mutex.
* simplify GMainLoopDispatcher

To post a comment you must log in.
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

14.09 approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/dbus-cpp/services/ofono.h'
--- src/dbus-cpp/services/ofono.h 2014-10-23 21:46:41 +0000
+++ src/dbus-cpp/services/ofono.h 2015-01-30 12:31:15 +0000
@@ -1034,8 +1034,9 @@
1034 break;1034 break;
1035 case Property::Interfaces::Type::NetworkRegistration:1035 case Property::Interfaces::Type::NetworkRegistration:
1036 {1036 {
1037 std::unique_lock<std::mutex> lock(_lock);
1037 if (std::find(newInterfaces.begin(), newInterfaces.end(), known) == newInterfaces.end() &&1038 if (std::find(newInterfaces.begin(), newInterfaces.end(), known) == newInterfaces.end() &&
1038 networkRegistration->get()) {1039 networkRegistration.get()) {
1039 networkRegistration.set(std::shared_ptr<NetworkRegistration>());1040 networkRegistration.set(std::shared_ptr<NetworkRegistration>());
1040 }1041 }
1041 break;1042 break;
@@ -1046,8 +1047,9 @@
1046 break;1047 break;
1047 case Property::Interfaces::Type::SimManager:1048 case Property::Interfaces::Type::SimManager:
1048 {1049 {
1050 std::unique_lock<std::mutex> lock(_lock);
1049 if (std::find(newInterfaces.begin(), newInterfaces.end(), known) == newInterfaces.end() &&1051 if (std::find(newInterfaces.begin(), newInterfaces.end(), known) == newInterfaces.end() &&
1050 simManager->get()) {1052 simManager.get()) {
1051 simManager.set(std::shared_ptr<SimManager>());1053 simManager.set(std::shared_ptr<SimManager>());
1052 }1054 }
1053 break;1055 break;
@@ -1080,7 +1082,8 @@
1080 break;1082 break;
1081 case Property::Interfaces::Type::NetworkRegistration:1083 case Property::Interfaces::Type::NetworkRegistration:
1082 {1084 {
1083 if (!networkRegistration->get()) {1085 std::unique_lock<std::mutex> lock(_lock);
1086 if (!networkRegistration.get()) {
1084 networkRegistration.set(std::make_shared<NetworkRegistration>(this->object));1087 networkRegistration.set(std::make_shared<NetworkRegistration>(this->object));
1085 }1088 }
1086 break;1089 break;
@@ -1091,7 +1094,8 @@
1091 break;1094 break;
1092 case Property::Interfaces::Type::SimManager:1095 case Property::Interfaces::Type::SimManager:
1093 {1096 {
1094 if (!simManager->get()) {1097 std::unique_lock<std::mutex> lock(_lock);
1098 if (!simManager.get()) {
1095 simManager.set(std::make_shared<SimManager>(this->object));1099 simManager.set(std::make_shared<SimManager>(this->object));
1096 }1100 }
1097 break;1101 break;
@@ -1174,6 +1178,8 @@
11741178
1175 std::shared_ptr<core::dbus::Signal<Signal::PropertyChanged, Signal::PropertyChanged::ArgumentType>> propertyChanged;1179 std::shared_ptr<core::dbus::Signal<Signal::PropertyChanged, Signal::PropertyChanged::ArgumentType>> propertyChanged;
11761180
1181 // this lock must be acquired for any access to networkRegistration or simManager
1182 std::mutex _lock;
1177 core::Property<NetworkRegistration::Ptr> networkRegistration;1183 core::Property<NetworkRegistration::Ptr> networkRegistration;
1178 core::Property<SimManager::Ptr> simManager;1184 core::Property<SimManager::Ptr> simManager;
11791185
11801186
=== modified file 'src/indicator/modem.cpp'
--- src/indicator/modem.cpp 2014-12-09 10:58:21 +0000
+++ src/indicator/modem.cpp 2015-01-30 12:31:15 +0000
@@ -65,20 +65,21 @@
65 });65 });
66 });66 });
6767
68 simManagerChanged(m_ofonoModem->simManager.get());68 std::unique_lock<std::mutex> lock(m_ofonoModem->_lock);
69 auto simmgr = m_ofonoModem->simManager.get();
70 auto netreg = m_ofonoModem->networkRegistration.get();
71 lock.unlock();
72
73 simManagerChanged(simmgr);
69 m_ofonoModem->simManager.changed().connect([that](org::ofono::Interface::SimManager::Ptr simmgr)74 m_ofonoModem->simManager.changed().connect([that](org::ofono::Interface::SimManager::Ptr simmgr)
70 {75 {
71 GMainLoopDispatch([that, simmgr](){76 that->simManagerChanged(simmgr);
72 that->simManagerChanged(simmgr);
73 });
74 });77 });
7578
76 networkRegistrationChanged(m_ofonoModem->networkRegistration.get());79 networkRegistrationChanged(netreg);
77 m_ofonoModem->networkRegistration.changed().connect([that](org::ofono::Interface::NetworkRegistration::Ptr netreg)80 m_ofonoModem->networkRegistration.changed().connect([that](org::ofono::Interface::NetworkRegistration::Ptr netreg)
78 {81 {
79 GMainLoopDispatch([that, netreg](){82 that->networkRegistrationChanged(netreg);
80 that->networkRegistrationChanged(netreg);
81 });
82 });83 });
8384
84 /// @todo hook up with system-settings to allow changing the identifier.85 /// @todo hook up with system-settings to allow changing the identifier.
@@ -93,14 +94,17 @@
93 } else {94 } else {
94 m_simIdentifier.set(path);95 m_simIdentifier.set(path);
95 }96 }
96
97}97}
9898
9999
100void100void
101Modem::Private::update()101Modem::Private::update()
102{102{
103 std::unique_lock<std::mutex> lock(m_ofonoModem->_lock);
103 auto simmgr = m_ofonoModem->simManager.get();104 auto simmgr = m_ofonoModem->simManager.get();
105 auto netreg = m_ofonoModem->networkRegistration.get();
106 lock.unlock();
107
104 if (simmgr) {108 if (simmgr) {
105 // update requiredPin109 // update requiredPin
106 switch(simmgr->pinRequired.get())110 switch(simmgr->pinRequired.get())
@@ -155,7 +159,6 @@
155 m_simStatus.set(SimStatus::not_available);159 m_simStatus.set(SimStatus::not_available);
156 }160 }
157161
158 auto netreg = m_ofonoModem->networkRegistration.get();
159 if (netreg) {162 if (netreg) {
160 m_operatorName.set(netreg->operatorName.get());163 m_operatorName.set(netreg->operatorName.get());
161 m_status.set(netreg->status.get());164 m_status.set(netreg->status.get());
@@ -172,75 +175,55 @@
172void175void
173Modem::Private::networkRegistrationChanged(org::ofono::Interface::NetworkRegistration::Ptr netreg)176Modem::Private::networkRegistrationChanged(org::ofono::Interface::NetworkRegistration::Ptr netreg)
174{177{
178 auto that = shared_from_this();
175 if (netreg) {179 if (netreg) {
176 auto that = shared_from_this();
177 netreg->operatorName.changed().connect([that](const std::string &)180 netreg->operatorName.changed().connect([that](const std::string &)
178 {181 {
179 GMainLoopDispatch([that]()182 GMainLoopDispatch([that]() { that->update(); });
180 {
181 that->update();
182 });
183 });183 });
184 netreg->status.changed().connect([that](org::ofono::Interface::NetworkRegistration::Status)184 netreg->status.changed().connect([that](org::ofono::Interface::NetworkRegistration::Status)
185 {185 {
186 GMainLoopDispatch([that]()186 GMainLoopDispatch([that]() { that->update(); });
187 {
188 that->update();
189 });
190 });187 });
191188
192 netreg->strength.changed().connect([that](std::int8_t)189 netreg->strength.changed().connect([that](std::int8_t)
193 {190 {
194 GMainLoopDispatch([that]()191 GMainLoopDispatch([that]() { that->update(); });
195 {
196 that->update();
197 });
198 });192 });
199193
200 netreg->technology.changed().connect([that](org::ofono::Interface::NetworkRegistration::Technology)194 netreg->technology.changed().connect([that](org::ofono::Interface::NetworkRegistration::Technology)
201 {195 {
202 GMainLoopDispatch([that]()196 GMainLoopDispatch([that]() { that->update(); });
203 {
204 that->update();
205 });
206 });197 });
207198
208 }199 }
209 update();200
201 GMainLoopDispatch([that]() { that->update(); });
210}202}
211203
212204
213void205void
214Modem::Private::simManagerChanged(org::ofono::Interface::SimManager::Ptr simmgr)206Modem::Private::simManagerChanged(org::ofono::Interface::SimManager::Ptr simmgr)
215{207{
208 auto that = shared_from_this();
216 if (simmgr) {209 if (simmgr) {
217 auto that = shared_from_this();
218 simmgr->present.changed().connect([that](bool)210 simmgr->present.changed().connect([that](bool)
219 {211 {
220 GMainLoopDispatch([that]()212 GMainLoopDispatch([that]() { that->update(); });
221 {
222 that->update();
223 });
224 });213 });
225214
226 simmgr->pinRequired.changed().connect([that](org::ofono::Interface::SimManager::PinType)215 simmgr->pinRequired.changed().connect([that](org::ofono::Interface::SimManager::PinType)
227 {216 {
228 GMainLoopDispatch([that]()217 GMainLoopDispatch([that]() { that->update(); });
229 {
230 that->update();
231 });
232 });218 });
233219
234 simmgr->retries.changed().connect([that](std::map<org::ofono::Interface::SimManager::PinType, std::uint8_t>)220 simmgr->retries.changed().connect([that](std::map<org::ofono::Interface::SimManager::PinType, std::uint8_t>)
235 {221 {
236 GMainLoopDispatch([that]()222 GMainLoopDispatch([that]() { that->update(); });
237 {
238 that->update();
239 });
240 });223 });
241224
242 }225 }
243 update();226 GMainLoopDispatch([that]() { that->update(); });
244}227}
245228
246Modem::Modem(org::ofono::Interface::Modem::Ptr ofonoModem)229Modem::Modem(org::ofono::Interface::Modem::Ptr ofonoModem)
@@ -261,7 +244,11 @@
261bool244bool
262Modem::enterPin(PinType type, const std::string &pin)245Modem::enterPin(PinType type, const std::string &pin)
263{246{
264 if (!d->m_ofonoModem->simManager.get()) {247 std::unique_lock<std::mutex> lock(d->m_ofonoModem->_lock);
248 auto simmgr = d->m_ofonoModem->simManager.get();
249 lock.unlock();
250
251 if (!simmgr) {
265 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager.");252 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager.");
266 }253 }
267254
@@ -269,11 +256,11 @@
269 case PinType::none:256 case PinType::none:
270 return true;257 return true;
271 case PinType::pin:258 case PinType::pin:
272 return d->m_ofonoModem->simManager.get()->enterPin(org::ofono::Interface::SimManager::PinType::pin,259 return simmgr->enterPin(org::ofono::Interface::SimManager::PinType::pin,
273 pin);260 pin);
274 case PinType::puk:261 case PinType::puk:
275 return d->m_ofonoModem->simManager.get()->enterPin(org::ofono::Interface::SimManager::PinType::puk,262 return simmgr->enterPin(org::ofono::Interface::SimManager::PinType::puk,
276 pin);263 pin);
277 break;264 break;
278 }265 }
279266
@@ -284,7 +271,11 @@
284bool271bool
285Modem::resetPin(PinType type, const std::string &puk, const std::string &pin)272Modem::resetPin(PinType type, const std::string &puk, const std::string &pin)
286{273{
287 if (!d->m_ofonoModem->simManager.get()) {274 std::unique_lock<std::mutex> lock(d->m_ofonoModem->_lock);
275 auto simmgr = d->m_ofonoModem->simManager.get();
276 lock.unlock();
277
278 if (!simmgr) {
288 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager.");279 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager.");
289 }280 }
290281
@@ -292,9 +283,9 @@
292 case PinType::none:283 case PinType::none:
293 return true;284 return true;
294 case PinType::puk:285 case PinType::puk:
295 return d->m_ofonoModem->simManager.get()->resetPin(org::ofono::Interface::SimManager::PinType::puk,286 return simmgr->resetPin(org::ofono::Interface::SimManager::PinType::puk,
296 puk,287 puk,
297 pin);288 pin);
298 default:289 default:
299 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": Not Supported.");290 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": Not Supported.");
300 }291 }
@@ -303,7 +294,11 @@
303bool294bool
304Modem::changePin(PinType type, const std::string &oldPin, const std::string &newPin)295Modem::changePin(PinType type, const std::string &oldPin, const std::string &newPin)
305{296{
306 if (!d->m_ofonoModem->simManager.get()) {297 std::unique_lock<std::mutex> lock(d->m_ofonoModem->_lock);
298 auto simmgr = d->m_ofonoModem->simManager.get();
299 lock.unlock();
300
301 if (!simmgr) {
307 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager.");302 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + ": no simManager.");
308 }303 }
309304
@@ -311,13 +306,13 @@
311 case PinType::none:306 case PinType::none:
312 return true;307 return true;
313 case PinType::pin:308 case PinType::pin:
314 return d->m_ofonoModem->simManager.get()->changePin(org::ofono::Interface::SimManager::PinType::pin,309 return simmgr->changePin(org::ofono::Interface::SimManager::PinType::pin,
315 oldPin,310 oldPin,
316 newPin);311 newPin);
317 case PinType::puk:312 case PinType::puk:
318 return d->m_ofonoModem->simManager.get()->changePin(org::ofono::Interface::SimManager::PinType::puk,313 return simmgr->changePin(org::ofono::Interface::SimManager::PinType::puk,
319 oldPin,314 oldPin,
320 newPin);315 newPin);
321 break;316 break;
322 }317 }
323318
324319
=== modified file 'src/menumodel-cpp/gio-helpers/util.cpp'
--- src/menumodel-cpp/gio-helpers/util.cpp 2014-12-09 14:56:21 +0000
+++ src/menumodel-cpp/gio-helpers/util.cpp 2015-01-30 12:31:15 +0000
@@ -19,43 +19,40 @@
1919
20#include "util.h"20#include "util.h"
2121
22// guards access to __funcs
22std::mutex GMainLoopDispatch::_lock;23std::mutex GMainLoopDispatch::_lock;
23std::list<GMainLoopDispatch::Func *> GMainLoopDispatch::_funcs;24std::list<GMainLoopDispatch::Func> GMainLoopDispatch::__funcs;
2425
25gboolean26gboolean
26GMainLoopDispatch::dispatch_cb(gpointer)27GMainLoopDispatch::dispatch_cb(gpointer)
27{28{
28 std::unique_lock<std::mutex> lock(_lock);29 std::unique_lock<std::mutex> lock(_lock);
29 for (auto func : _funcs) {30 auto funcs = __funcs;
30 lock.unlock();31 __funcs.clear();
31 (*func)();32 lock.unlock();
32 lock.lock();33
33 delete func;34 for (auto &func : funcs) {
35 func();
34 }36 }
35 _funcs.clear();
36 return G_SOURCE_REMOVE;37 return G_SOURCE_REMOVE;
37}38}
3839
39GMainLoopDispatch::GMainLoopDispatch(Func func, int priority, bool force_delayed)40GMainLoopDispatch::GMainLoopDispatch(Func func, int priority, bool force_delayed)
40{41{
41 std::unique_lock<std::mutex> lock(_lock);
42
43 if (!force_delayed &&42 if (!force_delayed &&
44 g_main_context_acquire(g_main_context_default())) {43 g_main_context_acquire(g_main_context_default())) {
45 // already running inside GMainLoop..44 // already running inside GMainLoop.
46 // free the lock and dispatch immediately.
47 lock.unlock();
48 func();45 func();
49 g_main_context_release(g_main_context_default());46 g_main_context_release(g_main_context_default());
50 } else {47 } else {
51 std::function<void()> *funcPtr = new std::function<void()>(func);48 std::unique_lock<std::mutex> lock(_lock);
52 if (_funcs.empty()) {49 if (__funcs.empty()) {
53 g_idle_add_full(priority,50 g_idle_add_full(priority,
54 GSourceFunc(GMainLoopDispatch::dispatch_cb),51 GSourceFunc(GMainLoopDispatch::dispatch_cb),
55 NULL,52 NULL,
56 NULL);53 NULL);
57 }54 }
58 _funcs.push_back(funcPtr);55 __funcs.push_back(func);
59 }56 }
60}57}
6158
6259
=== modified file 'src/menumodel-cpp/gio-helpers/util.h'
--- src/menumodel-cpp/gio-helpers/util.h 2014-12-09 14:56:21 +0000
+++ src/menumodel-cpp/gio-helpers/util.h 2015-01-30 12:31:15 +0000
@@ -74,7 +74,7 @@
74 typedef std::function<void()> Func;74 typedef std::function<void()> Func;
75 static std::mutex _lock;75 static std::mutex _lock;
76 // list keeps the order of the functions76 // list keeps the order of the functions
77 static std::list<Func *> _funcs;77 static std::list<Func> __funcs;
7878
79 //GMainLoopDispatch() = delete;79 //GMainLoopDispatch() = delete;
80 GMainLoopDispatch(Func func, int priority=G_PRIORITY_HIGH, bool force_delayed=false);80 GMainLoopDispatch(Func func, int priority=G_PRIORITY_HIGH, bool force_delayed=false);

Subscribers

People subscribed via source and target branches