libkms++/property: Add const std::string to_str(uint64_t val) const
[android/external-libkmsxx.git] / libkms++ / property.cpp
index e01bf604cab40e2b504c1b05e10fde6571ec810d..3b8a0b805ec1d8a774aa4cf34246ba59762bd60a 100644 (file)
@@ -36,4 +36,44 @@ const string& Property::name() const
 {
        return m_name;
 }
 {
        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;
+}
 }
 }