aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-05-22 07:28:07 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-05-22 07:28:07 +0200
commit31faad73568712e9e77cfbd0bf50f3b7cc2ede00 (patch)
tree72329d00812aafab57c593d6d818845a8afc5fa8 /src
parent94e42b28636c7b629574dddd082f1ac9caab403e (diff)
downloadODR-AudioEnc-31faad73568712e9e77cfbd0bf50f3b7cc2ede00.tar.gz
ODR-AudioEnc-31faad73568712e9e77cfbd0bf50f3b7cc2ede00.tar.bz2
ODR-AudioEnc-31faad73568712e9e77cfbd0bf50f3b7cc2ede00.zip
Make stats output JSON-compatible
JSON is a subset of YAML, so YAML parsers still work
Diffstat (limited to 'src')
-rw-r--r--src/StatsPublish.cpp26
-rw-r--r--src/StatsPublish.h2
2 files changed, 15 insertions, 13 deletions
diff --git a/src/StatsPublish.cpp b/src/StatsPublish.cpp
index 5998913..7e49ad1 100644
--- a/src/StatsPublish.cpp
+++ b/src/StatsPublish.cpp
@@ -88,28 +88,30 @@ void StatsPublisher::notify_overrun()
void StatsPublisher::send_stats()
{
- // Manually build YAML, as it's quite easy.
- stringstream yaml;
- yaml << "---\n";
- yaml << "program: " << PACKAGE_NAME << "\n";
- yaml << "version: " <<
+ // Manually build JSON. We can be certain that
+ // our fields don't contain quotes
+ stringstream json;
+ json << "{ ";
+ json << "\"program\": \"" << PACKAGE_NAME << "\", ";
+ json << "\"version\": \"" <<
#if defined(GITVERSION)
GITVERSION
#else
PACKAGE_VERSION
#endif
- << "\n";
- yaml << "audiolevels: { left: " << m_audio_left << ", right: " << m_audio_right << "}\n";
- yaml << "driftcompensation: { underruns: " << m_num_underruns << ", overruns: " << m_num_overruns << "}\n";
+ << "\", ";
+ json << "\"audiolevels\": { \"left\": " << m_audio_left << ", \"right\": " << m_audio_right << "}, ";
+ json << "\"driftcompensation\": { \"underruns\": " << m_num_underruns << ", \"overruns\": " << m_num_overruns << "} ";
+ json << "}";
- const auto yamlstr = yaml.str();
+ const auto jsonstr = json.str();
struct sockaddr_un claddr;
memset(&claddr, 0, sizeof(struct sockaddr_un));
claddr.sun_family = AF_UNIX;
snprintf(claddr.sun_path, sizeof(claddr.sun_path), "%s", m_socket_path.c_str());
- int ret = ::sendto(m_sock, yamlstr.data(), yamlstr.size(), 0,
+ int ret = ::sendto(m_sock, jsonstr.data(), jsonstr.size(), 0,
(struct sockaddr *) &claddr, sizeof(struct sockaddr_un));
if (ret == -1) {
// This suppresses the -Wlogical-op warning
@@ -128,9 +130,9 @@ void StatsPublisher::send_stats()
fprintf(stderr, "Statistics send failed: %s\n", strerror(errno));
}
}
- else if (ret != (ssize_t)yamlstr.size()) {
+ else if (ret != (ssize_t)jsonstr.size()) {
fprintf(stderr, "Statistics send incorrect length: %d bytes of %zu transmitted\n",
- ret, yamlstr.size());
+ ret, jsonstr.size());
}
else if (not m_destination_available) {
fprintf(stderr, "Stats destination is now available at %s\n", m_socket_path.c_str());
diff --git a/src/StatsPublish.h b/src/StatsPublish.h
index 7ff7da4..06a738d 100644
--- a/src/StatsPublish.h
+++ b/src/StatsPublish.h
@@ -29,7 +29,7 @@
*
* Currently, only audio levels are collected.
*
- * Output is formatted in YAML
+ * Output is formatted in JSON
*/
class StatsPublisher {
public: