added update check result as global MQTT topic
This commit is contained in:
@@ -145,15 +145,20 @@ class DataSink : virtual public DataHandler {
|
|||||||
*/
|
*/
|
||||||
virtual ~DataSink() {}
|
virtual ~DataSink() {}
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
bool isDataSink() override { return true; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the sink of an updated @a Message.
|
* Notify the sink of an updated @a Message.
|
||||||
* @param message the updated @a Message.
|
* @param message the updated @a Message.
|
||||||
*/
|
*/
|
||||||
virtual void notifyUpdate(Message* 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:
|
protected:
|
||||||
/** the allowed access levels. */
|
/** the allowed access levels. */
|
||||||
|
|||||||
@@ -357,6 +357,11 @@ void MainLoop::run() {
|
|||||||
if (result == "200 OK") {
|
if (result == "200 OK") {
|
||||||
m_updateCheck = message == "" ? "unknown" : message;
|
m_updateCheck = message == "" ? "unknown" : message;
|
||||||
logNotice(lf_main, "update check: %s", message.c_str());
|
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 {
|
} else {
|
||||||
logError(lf_main, "update check error: %s", result.c_str());
|
logError(lf_main, "update check error: %s", result.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,7 +261,8 @@ void on_connect(
|
|||||||
|
|
||||||
|
|
||||||
MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages)
|
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;
|
bool enabled = g_port != 0;
|
||||||
m_publishByField = false;
|
m_publishByField = false;
|
||||||
m_mosquitto = NULL;
|
m_mosquitto = NULL;
|
||||||
@@ -478,6 +479,13 @@ void MqttHandler::notifyTopic(string topic, string data) {
|
|||||||
publishMessage(message, ostream);
|
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() {
|
void MqttHandler::run() {
|
||||||
time_t lastTaskRun, now, start, lastSignal = 0;
|
time_t lastTaskRun, now, start, lastSignal = 0;
|
||||||
bool signal = false;
|
bool signal = false;
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ class MqttHandler : public DataSink, public DataSource, public Thread {
|
|||||||
*/
|
*/
|
||||||
void notifyTopic(string topic, string data);
|
void notifyTopic(string topic, string data);
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
void notifyUpdateCheckResult(string checkResult) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// @copydoc
|
// @copydoc
|
||||||
@@ -135,6 +137,9 @@ class MqttHandler : public DataSink, public DataSource, public Thread {
|
|||||||
|
|
||||||
/** whether the connection to the broker is established. */
|
/** whether the connection to the broker is established. */
|
||||||
bool m_connected;
|
bool m_connected;
|
||||||
|
|
||||||
|
/** the last update check result. */
|
||||||
|
string m_lastUpdateCheckResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|||||||
Reference in New Issue
Block a user