added update check result as global MQTT topic

This commit is contained in:
john30
2017-03-26 18:18:30 +02:00
parent 9831183624
commit db9085233c
4 changed files with 27 additions and 4 deletions
+8 -3
View File
@@ -145,15 +145,20 @@ class DataSink : virtual public DataHandler {
*/
virtual ~DataSink() {}
// @copydoc
bool isDataSink() override { return true; }
/**
* Notify the sink of an updated @a Message.
* @param message the updated @a Message.
*/
virtual void notifyUpdate(Message* message);
// @copydoc
bool isDataSink() override { return true; }
/**
* Notify the sink of the latest update check result.
* @param checkResult a string describing available updates, or empty if no update is available.
*/
virtual void notifyUpdateCheckResult(string checkResult) {}
protected:
/** the allowed access levels. */
+5
View File
@@ -357,6 +357,11 @@ void MainLoop::run() {
if (result == "200 OK") {
m_updateCheck = message == "" ? "unknown" : message;
logNotice(lf_main, "update check: %s", message.c_str());
if (!dataSinks.empty()) {
for (list<DataSink*>::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) {
(*it)->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck);
}
}
} else {
logError(lf_main, "update check error: %s", result.c_str());
}
+9 -1
View File
@@ -261,7 +261,8 @@ void on_connect(
MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages)
: DataSink(userInfo, "mqtt"), DataSource(busHandler), Thread(), m_messages(messages), m_connected(false) {
: DataSink(userInfo, "mqtt"), DataSource(busHandler), Thread(), m_messages(messages), m_connected(false),
m_lastUpdateCheckResult(".") {
bool enabled = g_port != 0;
m_publishByField = false;
m_mosquitto = NULL;
@@ -478,6 +479,13 @@ void MqttHandler::notifyTopic(string topic, string data) {
publishMessage(message, ostream);
}
void MqttHandler::notifyUpdateCheckResult(string checkResult) {
if (checkResult != m_lastUpdateCheckResult) {
m_lastUpdateCheckResult = checkResult;
publishTopic(m_globalTopic+"updatecheck", checkResult.empty() ? "OK" : checkResult);
}
}
void MqttHandler::run() {
time_t lastTaskRun, now, start, lastSignal = 0;
bool signal = false;
+5
View File
@@ -80,6 +80,8 @@ class MqttHandler : public DataSink, public DataSource, public Thread {
*/
void notifyTopic(string topic, string data);
// @copydoc
void notifyUpdateCheckResult(string checkResult) override;
protected:
// @copydoc
@@ -135,6 +137,9 @@ class MqttHandler : public DataSink, public DataSource, public Thread {
/** whether the connection to the broker is established. */
bool m_connected;
/** the last update check result. */
string m_lastUpdateCheckResult;
};
} // namespace ebusd