1// 2// Copyright (C) 2012 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17#ifndef SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ 18#define SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ 19 20#include <string> 21 22#include <base/time/time.h> 23 24namespace shill { 25 26// This class provides events from the power manager. To use this class, create 27// a subclass from PowerManagerProxyDelegate and implement its member functions. 28// Call ProxyFactory::CreatePowerManagerProxy() to create an instance of this 29// proxy, passing it a pointer to the delegate you created. When an event from 30// the power manager is received, your delegate's member function will be 31// called. You retain ownership of the delegate and must ensure that the proxy 32// is deleted before the delegate. 33class PowerManagerProxyInterface { 34 public: 35 virtual ~PowerManagerProxyInterface() {} 36 37 // Sends a request to the power manager to wait for this client for up to 38 // |timeout| before suspending the system. |description| is a 39 // human-readable string describing the delay's purpose. Assigns an ID 40 // corresponding to the registered delay to |delay_id_out| and returns 41 // true on success. 42 virtual bool RegisterSuspendDelay(base::TimeDelta timeout, 43 const std::string& description, 44 int* delay_id_out) = 0; 45 46 // Unregisters a previously-registered suspend delay. Returns true on 47 // success. 48 virtual bool UnregisterSuspendDelay(int delay_id) = 0; 49 50 // Calls the power manager's HandleSuspendReadiness method. |delay_id| should 51 // contain the ID returned via RegisterSuspendDelay() and |suspend_id| should 52 // contain the ID from OnSuspendImminent(). Returns true on success. 53 virtual bool ReportSuspendReadiness(int delay_id, int suspend_id) = 0; 54 55 // Sends a request to the power manager to wait for this client for up to 56 // |timeout| before suspending the system from a dark resume. Arguments 57 // are as explained for |RegisterSuspendDelay|. Returns true on success. 58 virtual bool RegisterDarkSuspendDelay(base::TimeDelta timeout, 59 const std::string& description, 60 int* delay_id_out) = 0; 61 62 // Unregisters a previously-registered dark suspend delay. Returns true on 63 // success. 64 virtual bool UnregisterDarkSuspendDelay(int delay_id) = 0; 65 66 // Calls the power manager's HandleDarkSuspendReadiness method. Arguments are 67 // as explained for ReportSuspendReadiness. Returns true on success. 68 virtual bool ReportDarkSuspendReadiness(int delay_id, int suspend_id) = 0; 69 70 // Calls the power manager's RecordDarkResumeWakeReason method to record the 71 // wake reason for the current dark resume. Returns true on success. 72 virtual bool RecordDarkResumeWakeReason(const std::string& wake_reason) = 0; 73}; 74 75// PowerManager signal delegate to be associated with the proxy. 76class PowerManagerProxyDelegate { 77 public: 78 virtual ~PowerManagerProxyDelegate() {} 79 80 // Broadcast by the power manager when it's about to suspend. Delegates 81 // that have registered through RegisterSuspendDelay() should tell the power 82 // manager that they're ready to suspend by calling ReportSuspendReadiness() 83 // with the delay ID returned by RegisterSuspendDelay() and |suspend_id|. 84 virtual void OnSuspendImminent(int suspend_id) = 0; 85 86 // Broadcast by the power manager when a suspend attempt has completed. 87 virtual void OnSuspendDone(int suspend_id) = 0; 88 89 // Broadcast by the power manager when the system enters dark resume. 90 // Delegates that have registered through RegisterDarkSuspendDelay() should 91 // tell the power manager when they are ready to suspend from the dark resume 92 // by calling ReportDarkSuspendResume() with the delay ID returned by 93 // RegisterDarkSuspendDelay() and |suspend_id|. 94 virtual void OnDarkSuspendImminent(int suspend_id) = 0; 95}; 96 97} // namespace shill 98 99#endif // SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ 100