2 #include <QCoreApplication>
3 #include <QDomDocument>
4 #include <QHostAddress>
15 #define LOC QString("UDPListener: ")
34 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Enabling");
51 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Disabling");
65 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
66 if (!doc.setContent(
Buffer,
false, &errormsg, &line, &column))
68 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error parsing xml: Line: %1 Column: %2 Error: %3")
69 .arg(line).arg(column).arg(errormsg));
73 auto parseResult = doc.setContent(
Buffer);
76 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error parsing xml: Line: %1 Column: %2 Error: %3")
77 .arg(parseResult.errorLine).arg(parseResult.errorColumn).arg(parseResult.errorMessage));
82 auto element = doc.documentElement();
83 bool notification =
false;
84 if (!element.isNull())
86 if (element.tagName() !=
"mythmessage" && element.tagName() !=
"mythnotification")
88 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Unknown UDP packet (not <mythmessage> XML)");
92 if (element.tagName() ==
"mythnotification")
95 if (
auto version = element.attribute(
"version",
"");
version.isEmpty())
97 LOG(VB_GENERAL, LOG_ERR,
LOC +
"<mythmessage> missing 'version' attribute");
103 std::chrono::seconds
timeout = 0s;
108 QString progress_text;
110 bool fullscreen =
false;
113 QString
type =
"normal";
115 auto node = element.firstChild();
116 while (!node.isNull())
118 auto dom = node.toElement();
121 auto tagname = dom.tagName();
122 if (tagname ==
"text")
124 else if (tagname ==
"timeout")
125 timeout = std::chrono::seconds(dom.text().toUInt());
126 else if (notification && tagname ==
"image")
128 else if (notification && tagname ==
"origin")
130 else if (notification && tagname ==
"description")
131 description = dom.text();
132 else if (notification && tagname ==
"extra")
134 else if (notification && tagname ==
"progress_text")
135 progress_text = dom.text();
136 else if (notification && tagname ==
"fullscreen")
137 fullscreen = dom.text().toLower() ==
"true";
138 else if (notification && tagname ==
"error")
139 error = dom.text().toLower() ==
"true";
140 else if (tagname ==
"visibility")
141 visibility = dom.text().toInt();
142 else if (tagname ==
"type")
144 else if (notification && tagname ==
"progress")
147 if (
progress = dom.text().toFloat(&ok); !ok)
152 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Unknown element: %1")
156 node = node.nextSibling();
159 if (!msg.isEmpty() || !image.isEmpty() || !extra.isEmpty())
161 LOG(VB_GENERAL, LOG_INFO, QString(
"Received %1 '%2', timeout %3")
162 .arg(notification ?
"notification" :
"message",
163 msg, QString::number(
timeout.count())));
165 timeout = notification ? 5s : 0s;
168 origin = origin.isEmpty() ? tr(
"UDP Listener") : origin;
171 msg, origin, description, image, extra,
173 fullscreen,
static_cast<VNMask>(visibility));
177 QStringList
args(QString::number(
timeout.count()));
191 LOG(VB_GENERAL, LOG_ERR,
LOC +
192 "EnableUDPListener called after MythUDPListener instance is deleted");
208 do { std::this_thread::sleep_for(5us); }