Merge lp:~ken-vandine/ubuntu-system-settings/lp1337200 into lp:ubuntu-system-settings

Proposed by Ken VanDine
Status: Rejected
Rejected by: Sebastien Bacher
Proposed branch: lp:~ken-vandine/ubuntu-system-settings/lp1337200
Merge into: lp:ubuntu-system-settings
Diff against target: 138 lines (+58/-31)
1 file modified
plugins/battery/plugin/battery-plugin.cpp (+58/-31)
To merge this branch: bzr merge lp:~ken-vandine/ubuntu-system-settings/lp1337200
Reviewer Review Type Date Requested Status
Sebastien Bacher (community) Disapprove
Iain Lane Needs Information
PS Jenkins bot continuous-integration Approve
Review via email: mp+241747@code.launchpad.net

Commit message

Disconnect from upower on suspend and connect on resume

Description of the change

Disconnect from upower on suspend and connect on resume

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1204. By Ken VanDine

Moved up_client_enumerate_devices_sync to the constructor, we only need to call it once.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote :

One inline comment.

If we disconnect when suspended, what happens if a battery is added or removed then?

Can you add a test for this (how do you programatically suspend an application?) and fix it (call the callback on resuming) if it's broken?

review: Needs Information
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, can you explain why we need to disconnect from upower? With a suspend device not a lot should be happening, if there are events generated/queued while the device is sleeping and not getting any interaction then that seems to be the real bug to fix. Or do we plan to patch every single upower client to workaround the issue?

review: Needs Information
Revision history for this message
Sebastien Bacher (seb128) wrote :

(just read the bug comments, still it feels like wrong to have to workaround in every client)

Revision history for this message
Ken VanDine (ken-vandine) wrote :

It doesn't really fix the issue either, I think the only solution is to really fix upower.

Revision history for this message
Sebastien Bacher (seb128) wrote :

setting as rejected then

review: Disapprove

Unmerged revisions

1204. By Ken VanDine

Moved up_client_enumerate_devices_sync to the constructor, we only need to call it once.

1203. By Ken VanDine

Disconnect from upower on suspend and connect on resume

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/battery/plugin/battery-plugin.cpp'
--- plugins/battery/plugin/battery-plugin.cpp 2014-09-12 15:42:58 +0000
+++ plugins/battery/plugin/battery-plugin.cpp 2014-11-14 02:59:39 +0000
@@ -20,6 +20,7 @@
2020
21#include "battery-plugin.h"21#include "battery-plugin.h"
2222
23#include <QCoreApplication>
23#include <QDebug>24#include <QDebug>
24#include <QStringList>25#include <QStringList>
25#include <SystemSettings/ItemBase>26#include <SystemSettings/ItemBase>
@@ -39,8 +40,14 @@
39 ~BatteryItem();40 ~BatteryItem();
4041
41private:42private:
43 void up_connect();
44 void up_disconnect();
42 UpClient *m_client;45 UpClient *m_client;
46 QCoreApplication *m_app;
43 gulong m_addedHandler, m_removedHandler;47 gulong m_addedHandler, m_removedHandler;
48
49private Q_SLOTS:
50 void onApplicationStateChanged(Qt::ApplicationState st);
44};51};
4552
46void deviceChanged(UpClient *client,53void deviceChanged(UpClient *client,
@@ -48,44 +55,56 @@
48 gpointer user_data)55 gpointer user_data)
49{56{
50 BatteryItem *item (static_cast<BatteryItem *> (user_data));57 BatteryItem *item (static_cast<BatteryItem *> (user_data));
5158 GPtrArray *devices = up_client_get_devices (client);
52#if !UP_CHECK_VERSION(0, 99, 0)59 item->setVisibility (devices->len > 0);
53 gboolean ret = up_client_enumerate_devices_sync (client, nullptr, nullptr);60 g_ptr_array_unref (devices);
54 if (!ret) {
55 item->setVisibility (false);
56 } else
57#endif
58 {
59 GPtrArray *devices = up_client_get_devices (client);
60 item->setVisibility (devices->len > 0);
61 g_ptr_array_unref (devices);
62 }
63
64}61}
6562
66BatteryItem::BatteryItem(const QVariantMap &staticData, QObject *parent):63BatteryItem::BatteryItem(const QVariantMap &staticData, QObject *parent):
67 ItemBase(staticData, parent),64 ItemBase(staticData, parent),
68 m_client(up_client_new()),65 m_client(up_client_new()),
66 m_app(QCoreApplication::instance()),
69 m_addedHandler(0),67 m_addedHandler(0),
70 m_removedHandler(0)68 m_removedHandler(0)
71{69{
70#if !UP_CHECK_VERSION(0, 99, 0)
71 gboolean ret = up_client_enumerate_devices_sync (m_client, nullptr, nullptr);
72 if (!ret) {
73 setVisibility (false);
74 }
75#endif
76
72 deviceChanged(m_client, nullptr, this);77 deviceChanged(m_client, nullptr, this);
73 m_addedHandler = g_signal_connect (m_client,78 connect(m_app, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
74 "device-added",79 up_connect();
75 G_CALLBACK (::deviceChanged),80}
76 this /* user_data */);81
77 m_removedHandler = g_signal_connect (m_client,82void BatteryItem::onApplicationStateChanged(Qt::ApplicationState st)
78 "device-removed",83{
79 G_CALLBACK (::deviceChanged),84 if (st == Qt::ApplicationActive)
80 this /* user_data */);85 up_connect();
81}86 else
8287 up_disconnect();
83void BatteryItem::setVisibility(bool visible)88}
84{89
85 setVisible(visible);90void BatteryItem::up_connect()
86}91{
8792 if (!m_addedHandler) {
88BatteryItem::~BatteryItem()93 m_addedHandler = g_signal_connect (m_client,
94 "device-added",
95 G_CALLBACK (::deviceChanged),
96 this /* user_data */);
97 }
98
99 if (!m_removedHandler) {
100 m_removedHandler = g_signal_connect (m_client,
101 "device-removed",
102 G_CALLBACK (::deviceChanged),
103 this /* user_data */);
104 }
105}
106
107void BatteryItem::up_disconnect()
89{108{
90 if (m_addedHandler) {109 if (m_addedHandler) {
91 g_signal_handler_disconnect (m_client, m_addedHandler);110 g_signal_handler_disconnect (m_client, m_addedHandler);
@@ -96,7 +115,16 @@
96 g_signal_handler_disconnect (m_client, m_removedHandler);115 g_signal_handler_disconnect (m_client, m_removedHandler);
97 m_removedHandler = 0;116 m_removedHandler = 0;
98 }117 }
99118}
119
120void BatteryItem::setVisibility(bool visible)
121{
122 setVisible(visible);
123}
124
125BatteryItem::~BatteryItem()
126{
127 up_disconnect();
100 g_object_unref (m_client);128 g_object_unref (m_client);
101}129}
102130
@@ -105,7 +133,6 @@
105{133{
106}134}
107135
108
109ItemBase *BatteryPlugin::createItem(const QVariantMap &staticData,136ItemBase *BatteryPlugin::createItem(const QVariantMap &staticData,
110 QObject *parent)137 QObject *parent)
111{138{

Subscribers

People subscribed via source and target branches