libkms++/property: Add const std::string to_str(uint64_t val) const
authorJyri Sarha <jsarha@ti.com>
Tue, 20 Oct 2015 13:50:57 +0000 (16:50 +0300)
committerJyri Sarha <jsarha@ti.com>
Tue, 20 Oct 2015 16:18:32 +0000 (19:18 +0300)
libkms++/property.cpp
libkms++/property.h

index e01bf604cab40e2b504c1b05e10fde6571ec810d..3b8a0b805ec1d8a774aa4cf34246ba59762bd60a 100644 (file)
@@ -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 += " <broken range>";
+       } 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;
+}
 }
index ffab8d0cd05c911d22b1e1ab82c24e7b3a62ddf6..4cb265351a19c16c9cb6da69874f89be5d9ea527 100644 (file)
@@ -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();