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 (!doc.setContent(
Buffer,
false, &errormsg, &line, &column))
67 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Error parsing xml: Line: %1 Column: %2 Error: %3")
68 .arg(line).arg(column).arg(errormsg));
72 auto element = doc.documentElement();
73 bool notification =
false;
74 if (!element.isNull())
76 if (element.tagName() !=
"mythmessage" && element.tagName() !=
"mythnotification")
78 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Unknown UDP packet (not <mythmessage> XML)");
82 if (element.tagName() ==
"mythnotification")
85 if (
auto version = element.attribute(
"version",
"");
version.isEmpty())
87 LOG(VB_GENERAL, LOG_ERR,
LOC +
"<mythmessage> missing 'version' attribute");
93 std::chrono::seconds
timeout = 0s;
98 QString progress_text;
100 bool fullscreen =
false;
103 QString
type =
"normal";
105 auto node = element.firstChild();
106 while (!node.isNull())
108 auto dom = node.toElement();
111 auto tagname = dom.tagName();
112 if (tagname ==
"text")
114 else if (tagname ==
"timeout")
115 timeout = std::chrono::seconds(dom.text().toUInt());
116 else if (notification && tagname ==
"image")
118 else if (notification && tagname ==
"origin")
120 else if (notification && tagname ==
"description")
121 description = dom.text();
122 else if (notification && tagname ==
"extra")
124 else if (notification && tagname ==
"progress_text")
125 progress_text = dom.text();
126 else if (notification && tagname ==
"fullscreen")
127 fullscreen = dom.text().toLower() ==
"true";
128 else if (notification && tagname ==
"error")
129 error = dom.text().toLower() ==
"true";
130 else if (tagname ==
"visibility")
131 visibility = dom.text().toInt();
132 else if (tagname ==
"type")
134 else if (notification && tagname ==
"progress")
137 if (
progress = dom.text().toFloat(&ok); !ok)
142 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"Unknown element: %1")
146 node = node.nextSibling();
149 if (!msg.isEmpty() || !image.isEmpty() || !extra.isEmpty())
151 LOG(VB_GENERAL, LOG_INFO, QString(
"Received %1 '%2', timeout %3")
152 .arg(notification ?
"notification" :
"message",
153 msg, QString::number(
timeout.count())));
155 timeout = notification ? 5s : 0s;
158 origin = origin.isEmpty() ? tr(
"UDP Listener") : origin;
161 msg, origin, description, image, extra,
163 fullscreen,
static_cast<VNMask>(visibility));
167 QStringList
args(QString::number(
timeout.count()));
181 LOG(VB_GENERAL, LOG_ERR,
LOC +
182 "EnableUDPListener called after MythUDPListener instance is deleted");
198 do { std::this_thread::sleep_for(5us); }