Esempio n. 1
0
void PowerdProxy::Enable()
{
	LOG_TRACE("Entering function %s", __FUNCTION__);
	LOG_DEBUG("Enabling battery and charging signals");

	EnableChargerSignals();
	EnableBatterySignals();
}
void PowerdProxy::Enable()
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Enabling battery and charging signals"));

	EnableChargerSignals();
	EnableBatterySignals();
}
Esempio n. 3
0
void PowerdProxy::BatteryStatusSignal(MojServiceMessage *msg,
	const MojObject& response, MojErr err)
{
	LOG_TRACE("Entering function %s", __FUNCTION__);
	LOG_DEBUG("Received battery status signal: %s",
		MojoObjectJson(response).c_str());

	if (err != MojErrNone) {
		m_batteryStatusSubscribed = false;

		if (MojoCall::IsPermanentFailure(msg, response, err)) {
			LOG_WARNING(MSGID_BATTERY_STATUS_SIG_FAIL,0,
				"Subscription to battery status signal experienced an uncorrectable failure: %s",
				MojoObjectJson(response).c_str());
			m_batteryStatus.reset();
		} else {
			LOG_WARNING(MSGID_BATTERY_SIG_ENABLE,0,
				"Subscription to battery status signal failed, resubscribing: %s",
				MojoObjectJson(response).c_str());
			EnableBatterySignals();
		}
		return;
	}

	if (!m_batteryStatusSubscribed) {
		m_batteryStatusSubscribed = true;
		TriggerBatteryStatus();
	}

	MojInt64 batteryPercent;
	bool found = response.get(_T("percent"), batteryPercent);
	if (found) {
		MojInt64 oldBatteryPercent = m_batteryPercent;

		/* Set battery percent first, because as the requirements become met,
		 * Activities may start and events might be generated which include
		 * the state of the associated battery requirement. */
		m_batteryPercent = batteryPercent;

		if (batteryPercent < oldBatteryPercent) {
			BatteryRequirement::MultiTable::iterator newWatermark =
				m_batteryRequirements.upper_bound(batteryPercent,
					BatteryRequirement::KeyComp());

			/* Currently met requirements may wish to generate updates.
			 * Some of those requirements are about to be unmet due to
			 * battery drain.  Do not generate separate udpates. */
			std::for_each(m_batteryRequirements.begin(), newWatermark,
				boost::mem_fn(&Requirement::Updated));

			std::for_each(newWatermark,
				m_batteryRequirements.upper_bound(oldBatteryPercent,
					BatteryRequirement::KeyComp()),
				boost::mem_fn(&Requirement::Unmet));
		} else if (batteryPercent > oldBatteryPercent) {
			BatteryRequirement::MultiTable::iterator oldWatermark =
				m_batteryRequirements.upper_bound(oldBatteryPercent,
					BatteryRequirement::KeyComp());

			/* Some unmet requirements are about to be met.  For the
			 * currently met ones, just generate an update */
			std::for_each(m_batteryRequirements.begin(), oldWatermark,
				boost::mem_fn(&Requirement::Updated));
			std::for_each(oldWatermark,
				m_batteryRequirements.upper_bound(batteryPercent,
					BatteryRequirement::KeyComp()),
				boost::mem_fn(&Requirement::Met));
		}
	}
}