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

	EnableChargerSignals();
	EnableBatterySignals();
}
Ejemplo n.º 2
0
void PowerdProxy::Enable()
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Enabling battery and charging signals"));

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

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

		if (MojoCall::IsPermanentFailure(msg, response, err)) {
			LOG_WARNING(MSGID_CHRGR_STATUS_SIG_FAIL,0,
				"Subscription to charger status signal experienced an uncorrectable failure: %s",
				MojoObjectJson(response).c_str());
			m_chargerStatus.reset();
		} else {
			LOG_WARNING(MSGID_CHRGR_SIG_ENABLE,0,
				"Subscription to charger status signal failed, resubscribing: %s",
				MojoObjectJson(response).c_str());
			EnableChargerSignals();
		}
		return;
	}

	if (!m_chargerStatusSubscribed) {
		m_chargerStatusSubscribed = true;
		TriggerChargerStatus();
	}

	/* Not all responses will contain charger information... for example,
	 * the initial subscription result. */
	MojString chargerType;
	bool found = false;
	MojErr err2 = response.get(_T("type"), chargerType, found);
	if (err2) {
		LOG_ERROR(MSGID_CHRGR_SIG_NO_TYPE, 1,PMLOGKFV("ERROR","%d",err2),
			"Error retrieving charger type from charger status signal response");
		return;
	} else if (found) {
		bool connected;
		found = response.get(_T("connected"), connected);
		if (!found) {
			LOG_WARNING(MSGID_CHRGR_NOT_CONNECTED,1,PMLOGKS("TYPE",chargerType.data()),
				"Charger type found, but not it's connected");
			return;
		}

		if (chargerType == "usb") {
			m_usbChargerConnected = connected;
		} else if (chargerType == "inductive") {
			m_inductiveChargerConnected = connected;
		} else {
			LOG_WARNING(MSGID_CHRGR_TYPE_UNKNOWN, 1, PMLOGKS("TYPE",chargerType.data()),
				"Unknown charger type");
			return;
		}

		found = false;
		MojString name;
		err2 = response.get(_T("name"), name, found);
		if (err2) {
			LOG_ERROR(MSGID_CHRGR_NO_NAME,2, PMLOGKS("TYPE",chargerType.data()),
				PMLOGKFV("ERR", "%d", err2),
				"Error retrieving the specific name of charger");
		} else if (found) {
			if (name == "puck") {
				m_onPuck = connected;
			}
		}

		if (m_onPuck) {
			if (!m_dockedRequirementCore->IsMet()) {
				LOG_DEBUG("Device is now docked");
				m_dockedRequirementCore->Met();
				std::for_each(m_dockedRequirements.begin(),
					m_dockedRequirements.end(),
					boost::mem_fn(&Requirement::Met));
			}
		} else {
			if (m_dockedRequirementCore->IsMet()) {
				LOG_DEBUG("Device is no longer docked");
				m_dockedRequirementCore->Unmet();
				std::for_each(m_dockedRequirements.begin(),
					m_dockedRequirements.end(),
					boost::mem_fn(&Requirement::Unmet));
			}
		}

		if (m_inductiveChargerConnected || m_usbChargerConnected) {
			if (!m_chargingRequirementCore->IsMet()) {
				LOG_DEBUG("Device is now charging");
				m_chargingRequirementCore->Met();
				std::for_each(m_chargingRequirements.begin(),
					m_chargingRequirements.end(),
					boost::mem_fn(&Requirement::Met));
			}
		} else {
			if (m_chargingRequirementCore->IsMet()) {
				LOG_DEBUG("Device is no longer charging");
				m_chargingRequirementCore->Unmet();
				std::for_each(m_chargingRequirements.begin(),
					m_chargingRequirements.end(),
					boost::mem_fn(&Requirement::Unmet));
			}
		}
	}
}
Ejemplo n.º 4
0
void PowerdProxy::ChargerStatusSignal(MojServiceMessage *msg,
	const MojObject& response, MojErr err)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Received charger status signal: %s"),
		MojoObjectJson(response).c_str());

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

		if (MojoCall::IsPermanentFailure(msg, response, err)) {
			MojLogError(s_log, _T("Subscription to charger status signal "
				"experienced an uncorrectable failure: %s"),
				MojoObjectJson(response).c_str());
			m_chargerStatus.reset();
		} else {
			MojLogWarning(s_log, _T("Subscription to charger status signal "
				"failed, resubscribing: %s"),
				MojoObjectJson(response).c_str());
			EnableChargerSignals();
		}
		return;
	}

	if (!m_chargerStatusSubscribed) {
		m_chargerStatusSubscribed = true;
		TriggerChargerStatus();
	}

	/* Not all responses will contain charger information... for example,
	 * the initial subscription result. */
	MojString chargerType;
	bool found = false;
	MojErr err2 = response.get(_T("type"), chargerType, found);
	if (err2) {
		MojLogError(s_log, _T("Error %d retrieving charger type from charger "
			"status signal response"), err2);
		return;
	} else if (found) {
		bool connected;
		found = response.get(_T("connected"), connected);
		if (!found) {
			MojLogWarning(s_log, _T("Charger type \"%s\" found, but not "
				"whether or not it's connected"), chargerType.data());
			return;
		}

		if (chargerType == "usb") {
			m_usbChargerConnected = connected;
		} else if (chargerType == "inductive") {
			m_inductiveChargerConnected = connected;
		} else {
			MojLogWarning(s_log, _T("Unknown charger type \"%s\" found"),
				chargerType.data());
			return;
		}

		found = false;
		MojString name;
		err2 = response.get(_T("name"), name, found);
		if (err2) {
			MojLogError(s_log, _T("Error %d retrieving the specific "
				"name of charger of type \"%s\""), err2, chargerType.data());
		} else if (found) {
			if (name == "puck") {
				m_onPuck = connected;
			}
		}

		if (m_onPuck) {
			if (!m_dockedRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is now docked"));
				m_dockedRequirementCore->Met();
				std::for_each(m_dockedRequirements.begin(),
					m_dockedRequirements.end(),
					boost::mem_fn(&Requirement::Met));
			}
		} else {
			if (m_dockedRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is no longer docked"));
				m_dockedRequirementCore->Unmet();
				std::for_each(m_dockedRequirements.begin(),
					m_dockedRequirements.end(),
					boost::mem_fn(&Requirement::Unmet));
			}
		}

		if (m_inductiveChargerConnected || m_usbChargerConnected) {
			if (!m_chargingRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is now charging"));
				m_chargingRequirementCore->Met();
				std::for_each(m_chargingRequirements.begin(),
					m_chargingRequirements.end(),
					boost::mem_fn(&Requirement::Met));
			}
		} else {
			if (m_chargingRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is no longer charging"));
				m_chargingRequirementCore->Unmet();
				std::for_each(m_chargingRequirements.begin(),
					m_chargingRequirements.end(),
					boost::mem_fn(&Requirement::Unmet));
			}
		}
	}
}