~unity-system-compositor-team/unity-system-compositor/trunk

« back to all changes in this revision

Viewing changes to src/powerd_mediator.cpp

  • Committer: CI bot
  • Author(s): Alberto Aguirre
  • Date: 2014-07-22 18:49:09 UTC
  • mfrom: (158.1.1 fix-1343919)
  • Revision ID: ps-jenkins@lists.canonical.com-20140722184909-hpbotgqhltjqesnh
Attempt to sync up sys state when powerd is already up (LP: #1343919) Fixes: 1343919
Approved by: PS Jenkins bot, Alexandros Frantzis

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
{
81
81
    qDBusRegisterMetaType<BrightnessParams>();
82
82
 
83
 
    if (powerd_interface->isValid())
84
 
    {
85
 
        init_brightness_params();
86
 
    }
87
83
    //Powerd interface may not be available right now or it may restart in the future
88
84
    //watch for changes so brightness params get initialized to the most recent values.
89
85
    connect(service_watcher.get(),
96
92
                                           "SysPowerStateChange",
97
93
                                           this,
98
94
                                           SLOT(powerd_state_changed(int)));
 
95
 
 
96
    if (powerd_interface->isValid())
 
97
    {
 
98
        init_brightness_params();
 
99
        //If powerd is already up it may already be in the active state
 
100
        //and the SysPowerStateChange signal could have already been broadcasted
 
101
        //before we got a chance to register a listener for it.
 
102
        //We will assume that if the active request succeeds that the system state
 
103
        //will become active at some point in the future - this is only a workaround
 
104
        //for the lack of a system state query api in powerd
 
105
        if (disable_suspend_request())
 
106
            system_state = active;
 
107
    }
99
108
}
100
109
 
101
110
PowerdMediator::~PowerdMediator() = default;
204
213
 
205
214
void PowerdMediator::disable_suspend()
206
215
{
 
216
    if (disable_suspend_request())
 
217
        wait_for_state(active);
 
218
}
 
219
 
 
220
bool PowerdMediator::disable_suspend_request()
 
221
{
207
222
    if (!acquired_sys_state)
208
223
    {
209
224
        QDBusReply<QString> reply = powerd_interface->call("requestSysState", "com.canonical.Unity.Screen", 1);
210
225
        if (reply.isValid())
211
226
        {
212
227
            sys_state_cookie = reply.value();
213
 
            wait_for_state(active);
214
228
            acquired_sys_state = true;
 
229
            return true;
215
230
        }
216
231
    }
 
232
    return false;
217
233
}
218
234
 
219
235
void PowerdMediator::init_brightness_params()