MythTV  master
mythdrmproperty.cpp
Go to the documentation of this file.
1 // MythTV
3 
4 // C++
5 #include <algorithm>
6 
7 // Qt
8 #include <QStringList>
9 
19 MythDRMProperty::MythDRMProperty(Type mType, uint32_t Id, uint32_t Flags, const char * Name)
20  : m_type(mType),
21  m_id(Id),
22  m_readOnly(Flags & DRM_MODE_PROP_IMMUTABLE),
23  m_atomic(Flags & DRM_MODE_PROP_ATOMIC),
24  m_name(Name)
25 {
26 }
27 
28 DRMProps MythDRMProperty::GetProperties(int FD, const uint32_t ObjectId, uint32_t ObjectType)
29 {
30  DRMProps result;
31  if (auto * props = drmModeObjectGetProperties(FD, ObjectId, ObjectType); props)
32  {
33  for (uint32_t index = 0; index < props->count_props; ++index)
34  {
35  if (auto * prop = drmModeGetProperty(FD, props->props[index]); prop)
36  {
37  auto value = props->prop_values[index];
38  if (prop->flags & DRM_MODE_PROP_RANGE)
39  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMRangeProperty(value, prop)));
40  else if (prop->flags & DRM_MODE_PROP_ENUM)
41  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMEnumProperty(value, prop)));
42  else if (prop->flags & DRM_MODE_PROP_BITMASK)
43  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMBitmaskProperty(value, prop)));
44  else if (prop->flags & DRM_MODE_PROP_BLOB)
45  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMBlobProperty(FD, value, prop)));
46  else if (prop->flags & DRM_MODE_PROP_OBJECT)
47  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMObjectProperty(prop)));
48  else if (prop->flags & DRM_MODE_PROP_SIGNED_RANGE)
49  result.emplace_back(std::shared_ptr<MythDRMProperty>(new MythDRMSignedRangeProperty(value, prop)));
50  drmModeFreeProperty(prop);
51  }
52  }
53  drmModeFreeObjectProperties(props);
54  }
55  return result;
56 }
57 
59 {
60  for (const auto & prop : Properties)
61  if (Name.compare(prop->m_name, Qt::CaseInsensitive) == 0)
62  return prop;
63 
64  return nullptr;
65 }
66 
67 MythDRMRangeProperty::MythDRMRangeProperty(uint64_t Value, drmModePropertyPtr Property)
68  : MythDRMProperty(Range, Property->prop_id, Property->flags, Property->name),
69  m_value(Value)
70 {
71  for (int i = 0; i < Property->count_values; ++i)
72  {
73  auto value = Property->values[i];
74  m_min = std::min(value, m_min);
75  m_max = std::max(value, m_max);
76  }
77 }
78 
80 {
81  return QString("%1 Value: %2 Range: %3<->%4").arg(m_name).arg(m_value).arg(m_min).arg(m_max);
82 }
83 
85  : MythDRMProperty(SignedRange, Property->prop_id, Property->flags, Property->name),
86  m_value(static_cast<int64_t>(Value))
87 {
88  for (int i = 0; i < Property->count_values; ++i)
89  {
90  auto value = static_cast<int64_t>(Property->values[i]);
91  m_min = std::min(value, m_min);
92  m_max = std::max(value, m_max);
93  }
94 }
95 
97 {
98  return QString("%1 Value: %2 Range: %3<->%4").arg(m_name).arg(m_value).arg(m_min).arg(m_max);
99 }
100 
101 MythDRMEnumProperty::MythDRMEnumProperty(uint64_t Value, drmModePropertyPtr Property)
102  : MythDRMProperty(Enum, Property->prop_id, Property->flags, Property->name),
103  m_value(Value)
104 {
105  for (int i = 0; i < Property->count_enums; ++i)
106  m_enums.emplace(Property->enums[i].value, Property->enums[i].name);
107 }
108 
110 {
111  QStringList values;
112  for (const auto & value : m_enums)
113  values.append(QString("%1(%2)").arg(value.first).arg(value.second));
114  return QString("%1 Value: %2 Values: %3").arg(m_name).arg(m_value).arg(values.join(", "));
115 }
116 
117 MythDRMBitmaskProperty::MythDRMBitmaskProperty(uint64_t Value, drmModePropertyPtr Property)
118  : MythDRMEnumProperty(Value, Property)
119 {
120  m_type = Bitmask;
121 }
122 
123 MythDRMBlobProperty::MythDRMBlobProperty(int FD, uint64_t Value, drmModePropertyPtr Property)
124  : MythDRMProperty(Blob, Property->prop_id, Property->flags, Property->name)
125 {
126  if (auto * blob = drmModeGetPropertyBlob(FD, static_cast<uint32_t>(Value)); blob)
127  {
128  m_blob = QByteArray(reinterpret_cast<const char *>(blob->data), static_cast<int>(blob->length));
129  drmModeFreePropertyBlob(blob);
130  }
131 }
132 
134  : MythDRMProperty(Object, Property->prop_id, Property->flags, Property->name)
135 {
136 }
mythdrmproperty.h
MythDRMRangeProperty::MythDRMRangeProperty
MythDRMRangeProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:67
DRMProps
std::vector< DRMProp > DRMProps
Definition: mythdrmproperty.h:8
MythDRMObjectProperty::MythDRMObjectProperty
MythDRMObjectProperty(drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:133
MythDRMObjectProperty
Definition: mythdrmproperty.h:84
MythDRMProperty::m_name
QString m_name
Definition: mythdrmproperty.h:33
MythDRMRangeProperty::m_max
uint64_t m_max
Definition: mythdrmproperty.h:49
MythDRMProperty::MythDRMProperty
MythDRMProperty(Type mType, uint32_t Id, uint32_t Flags, const char *Name)
Definition: mythdrmproperty.cpp:19
MythDRMEnumProperty::m_value
uint64_t m_value
Definition: mythdrmproperty.h:67
MythDRMBlobProperty::MythDRMBlobProperty
MythDRMBlobProperty(int FD, uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:123
MythDRMEnumProperty::m_enums
std::map< uint64_t, QString > m_enums
Definition: mythdrmproperty.h:68
MythDRMEnumProperty::MythDRMEnumProperty
MythDRMEnumProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:101
MythDRMBitmaskProperty
Definition: mythdrmproperty.h:71
Property
Definition: upnpcdsobjects.h:47
MythDRMEnumProperty
Definition: mythdrmproperty.h:62
MythDRMProperty::GetProperty
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
Definition: mythdrmproperty.cpp:58
MythDRMProperty::Type
Type
Definition: mythdrmproperty.h:13
MythDRMRangeProperty
Definition: mythdrmproperty.h:42
MythDRMSignedRangeProperty::MythDRMSignedRangeProperty
MythDRMSignedRangeProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:84
Properties
QMultiMap< QString, Property * > Properties
Definition: upnpcdsobjects.h:98
DRMProp
std::shared_ptr< class MythDRMProperty > DRMProp
Definition: mythdrmproperty.h:7
MythDRMEnumProperty::ToString
QString ToString() override
Definition: mythdrmproperty.cpp:109
MythDRMSignedRangeProperty::m_max
int64_t m_max
Definition: mythdrmproperty.h:59
MythDRMBlobProperty::m_blob
QByteArray m_blob
Definition: mythdrmproperty.h:81
MythDRMSignedRangeProperty
Definition: mythdrmproperty.h:52
MythDRMProperty::m_type
Type m_type
Definition: mythdrmproperty.h:29
MythDRMRangeProperty::m_min
uint64_t m_min
Definition: mythdrmproperty.h:48
Name
Definition: channelsettings.cpp:103
MythDRMBlobProperty
Definition: mythdrmproperty.h:77
MythDRMSignedRangeProperty::ToString
QString ToString() override
Definition: mythdrmproperty.cpp:96
MythDRMSignedRangeProperty::m_min
int64_t m_min
Definition: mythdrmproperty.h:58
MythDRMRangeProperty::ToString
QString ToString() override
Definition: mythdrmproperty.cpp:79
MythDRMSignedRangeProperty::m_value
int64_t m_value
Definition: mythdrmproperty.h:57
MythDRMProperty
A wrapper around a DRM object property.
Definition: mythdrmproperty.h:10
MythDRMRangeProperty::m_value
uint64_t m_value
Definition: mythdrmproperty.h:47
MythDRMProperty::Bitmask
@ Bitmask
Definition: mythdrmproperty.h:18
MythDRMProperty::GetProperties
static DRMProps GetProperties(int FD, uint32_t ObjectId, uint32_t ObjectType)
Definition: mythdrmproperty.cpp:28
MythDRMBitmaskProperty::MythDRMBitmaskProperty
MythDRMBitmaskProperty(uint64_t Value, drmModePropertyPtr Property)
Definition: mythdrmproperty.cpp:117