From 905eacc3b638e70f25958b7c25f09077b143e387 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Tue, 20 Oct 2015 16:50:57 +0300 Subject: libkms++/property: Add const std::string to_str(uint64_t val) const --- libkms++/property.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ libkms++/property.h | 1 + 2 files changed, 41 insertions(+) (limited to 'libkms++') diff --git a/libkms++/property.cpp b/libkms++/property.cpp index e01bf60..3b8a0b8 100644 --- a/libkms++/property.cpp +++ b/libkms++/property.cpp @@ -36,4 +36,44 @@ const string& Property::name() const { return m_name; } + +const std::string Property::to_str(uint64_t val) const +{ + drmModePropertyPtr p = m_priv->drm_prop; + string ret; + + if (p->flags & DRM_MODE_PROP_ENUM) { + for (int i = 0; i < p->count_enums; i++) { + if (p->enums[i].value == val) { + ret += string("\"") + p->enums[i].name + "\""; + break; + } + } + ret += " (enum: " + to_string(val) + ")"; + } else if (p->flags & DRM_MODE_PROP_RANGE) { + ret += to_string(val); + if (p->count_values == 2) + ret += " [" + to_string(p->values[0]) + "-" + + to_string(p->values[1]) + "]"; + else + ret += " "; + } else if (p->flags & DRM_MODE_PROP_BLOB) { + ret += "Blob id: " + to_string(val); + + auto blob = drmModeGetPropertyBlob(card().fd(), (uint32_t) val); + if (blob) { + ret += " length: " + to_string(blob->length); + drmModeFreePropertyBlob(blob); + } + } else { + ret += to_string(val); + } + + if (p->flags & DRM_MODE_PROP_PENDING) + ret += " (pendig)"; + if (p->flags & DRM_MODE_PROP_IMMUTABLE) + ret += " (immutable)"; + + return ret; +} } diff --git a/libkms++/property.h b/libkms++/property.h index ffab8d0..4cb2653 100644 --- a/libkms++/property.h +++ b/libkms++/property.h @@ -15,6 +15,7 @@ public: const std::string& name() const; + const std::string to_str(uint64_t val) const; private: Property(Card& card, uint32_t id); ~Property(); -- cgit v1.2.3