Split properties from DrmObject into DrmPropObject
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 25 May 2016 08:37:17 +0000 (11:37 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 25 May 2016 08:37:17 +0000 (11:37 +0300)
14 files changed:
libkms++/connector.cpp
libkms++/connector.h
libkms++/crtc.cpp
libkms++/crtc.h
libkms++/drmobject.cpp
libkms++/drmobject.h
libkms++/drmpropobject.cpp [new file with mode: 0644]
libkms++/drmpropobject.h [new file with mode: 0644]
libkms++/encoder.cpp
libkms++/encoder.h
libkms++/plane.cpp
libkms++/plane.h
py/pykmsbase.cpp
utils/kmsprint.cpp

index e108410251bdb6814ef65e88836eb43d7dbe9b31..b64cdf7c5f639aa744ca23b7acea9c30abfa6a8b 100644 (file)
@@ -57,7 +57,7 @@ struct ConnectorPriv
 };
 
 Connector::Connector(Card &card, uint32_t id, uint32_t idx)
-       :DrmObject(card, id, DRM_MODE_OBJECT_CONNECTOR, idx)
+       :DrmPropObject(card, id, DRM_MODE_OBJECT_CONNECTOR, idx)
 {
        m_priv = new ConnectorPriv();
 
index 1759af1963becabcda17e59c83fed9468f3ad800..6ccc9599973a6eefc4372aeb6381d1495d4a57ee 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <vector>
 
-#include "drmobject.h"
+#include "drmpropobject.h"
 #include "videomode.h"
 
 namespace kms
@@ -10,7 +10,7 @@ namespace kms
 
 struct ConnectorPriv;
 
-class Connector : public DrmObject
+class Connector : public DrmPropObject
 {
        friend class Card;
 public:
index deadd62b44550ba82d8857b4f2106e58f3dacfe9..d50a78d647ff9e5df577ba6588c20df8ea4aa80a 100644 (file)
@@ -18,7 +18,7 @@ struct CrtcPriv
 };
 
 Crtc::Crtc(Card &card, uint32_t id, uint32_t idx)
-       :DrmObject(card, id, DRM_MODE_OBJECT_CRTC, idx)
+       :DrmPropObject(card, id, DRM_MODE_OBJECT_CRTC, idx)
 {
        m_priv = new CrtcPriv();
        m_priv->drm_crtc = drmModeGetCrtc(this->card().fd(), this->id());
index 5e0f15a3cd08db44566e3a7e4841e5bf4541f8fa..f3b525acd7e70857e8fa3cd5dc2a87efc907c5bb 100644 (file)
@@ -2,14 +2,14 @@
 
 #include <vector>
 
-#include "drmobject.h"
+#include "drmpropobject.h"
 
 namespace kms
 {
 
 struct CrtcPriv;
 
-class Crtc : public DrmObject
+class Crtc : public DrmPropObject
 {
        friend class Card;
        friend class Connector;
index 76a7e8c2b992c6dfb579436fcd7087e8ccb34896..8abecc725bb955d6da237d664b316bd8e474d1cf 100644 (file)
@@ -20,7 +20,6 @@ DrmObject::DrmObject(Card& card, uint32_t object_type)
 DrmObject::DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx)
        :m_card(card), m_id(id), m_object_type(object_type), m_idx(idx)
 {
-       refresh_props();
 }
 
 DrmObject::~DrmObject()
@@ -28,54 +27,6 @@ DrmObject::~DrmObject()
 
 }
 
-void DrmObject::refresh_props()
-{
-       auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type());
-
-       if (props == nullptr)
-               return;
-
-       for (unsigned i = 0; i < props->count_props; ++i) {
-               uint32_t prop_id = props->props[i];
-               uint64_t prop_value = props->prop_values[i];
-
-               m_prop_values[prop_id] = prop_value;
-       }
-
-       drmModeFreeObjectProperties(props);
-}
-
-uint64_t DrmObject::get_prop_value(uint32_t id) const
-{
-       return m_prop_values.at(id);
-}
-
-uint64_t DrmObject::get_prop_value(const string& name) const
-{
-       for (auto pair : m_prop_values) {
-               auto prop = card().get_prop(pair.first);
-               if (name == prop->name())
-                       return m_prop_values.at(prop->id());
-       }
-
-       throw invalid_argument("property not found: " + name);
-}
-
-int DrmObject::set_prop_value(uint32_t id, uint64_t value)
-{
-       return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value);
-}
-
-int DrmObject::set_prop_value(const string &name, uint64_t value)
-{
-       Property* prop = card().get_prop(name);
-
-       if (prop == nullptr)
-               throw invalid_argument("property not found: " + name);
-
-       return set_prop_value(prop->id(), value);
-}
-
 void DrmObject::set_id(uint32_t id)
 {
        m_id = id;
index b7d16cc3d1c12b5a794359184b3ae99e40eb1ab0..a939aa7f70f53a2c74a545918c080eb992542949 100644 (file)
@@ -20,15 +20,6 @@ public:
        uint32_t object_type() const { return m_object_type; }
        uint32_t idx() const { return m_idx; }
 
-       void refresh_props();
-       uint64_t get_prop_value(uint32_t id) const;
-       uint64_t get_prop_value(const std::string& name) const;
-
-       const std::map<uint32_t, uint64_t>& get_prop_map() const { return m_prop_values; }
-
-       int set_prop_value(uint32_t id, uint64_t value);
-       int set_prop_value(const std::string& name, uint64_t value);
-
 protected:
        DrmObject(Card& card, uint32_t object_type);
        DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx = 0);
@@ -45,7 +36,5 @@ private:
        uint32_t m_id;
        uint32_t m_object_type;
        uint32_t m_idx;
-
-       std::map<uint32_t, uint64_t> m_prop_values;
 };
 }
diff --git a/libkms++/drmpropobject.cpp b/libkms++/drmpropobject.cpp
new file mode 100644 (file)
index 0000000..de9dfe3
--- /dev/null
@@ -0,0 +1,79 @@
+#include <string.h>
+#include <iostream>
+#include <stdexcept>
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include "kms++.h"
+
+using namespace std;
+
+namespace kms
+{
+
+DrmPropObject::DrmPropObject(Card& card, uint32_t object_type)
+       : DrmObject(card, object_type)
+{
+}
+
+DrmPropObject::DrmPropObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx)
+       : DrmObject(card, id, object_type, idx)
+{
+       refresh_props();
+}
+
+DrmPropObject::~DrmPropObject()
+{
+
+}
+
+void DrmPropObject::refresh_props()
+{
+       auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type());
+
+       if (props == nullptr)
+               return;
+
+       for (unsigned i = 0; i < props->count_props; ++i) {
+               uint32_t prop_id = props->props[i];
+               uint64_t prop_value = props->prop_values[i];
+
+               m_prop_values[prop_id] = prop_value;
+       }
+
+       drmModeFreeObjectProperties(props);
+}
+
+uint64_t DrmPropObject::get_prop_value(uint32_t id) const
+{
+       return m_prop_values.at(id);
+}
+
+uint64_t DrmPropObject::get_prop_value(const string& name) const
+{
+       for (auto pair : m_prop_values) {
+               auto prop = card().get_prop(pair.first);
+               if (name == prop->name())
+                       return m_prop_values.at(prop->id());
+       }
+
+       throw invalid_argument("property not found: " + name);
+}
+
+int DrmPropObject::set_prop_value(uint32_t id, uint64_t value)
+{
+       return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value);
+}
+
+int DrmPropObject::set_prop_value(const string &name, uint64_t value)
+{
+       Property* prop = card().get_prop(name);
+
+       if (prop == nullptr)
+               throw invalid_argument("property not found: " + name);
+
+       return set_prop_value(prop->id(), value);
+}
+
+}
diff --git a/libkms++/drmpropobject.h b/libkms++/drmpropobject.h
new file mode 100644 (file)
index 0000000..6dfd2a8
--- /dev/null
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <map>
+
+#include "drmobject.h"
+#include "decls.h"
+
+namespace kms
+{
+
+class DrmPropObject : public DrmObject
+{
+       friend class Card;
+public:
+       void refresh_props();
+       uint64_t get_prop_value(uint32_t id) const;
+       uint64_t get_prop_value(const std::string& name) const;
+
+       const std::map<uint32_t, uint64_t>& get_prop_map() const { return m_prop_values; }
+
+       int set_prop_value(uint32_t id, uint64_t value);
+       int set_prop_value(const std::string& name, uint64_t value);
+
+protected:
+       DrmPropObject(Card& card, uint32_t object_type);
+       DrmPropObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx = 0);
+
+       virtual ~DrmPropObject();
+
+private:
+       std::map<uint32_t, uint64_t> m_prop_values;
+};
+}
index ffef897044383b48c8f8318761c0e56259eeb4de..ba6b0765be53171a13bc6f2b40f14c37b10ee178 100644 (file)
@@ -31,7 +31,7 @@ static const map<int, string> encoder_types = {
 };
 
 Encoder::Encoder(Card &card, uint32_t id)
-       :DrmObject(card, id, DRM_MODE_OBJECT_ENCODER)
+       :DrmPropObject(card, id, DRM_MODE_OBJECT_ENCODER)
 {
        m_priv = new EncoderPriv();
        m_priv->drm_encoder = drmModeGetEncoder(this->card().fd(), this->id());
index 956a4c7c7a2804f200bba1850e1b697b98d0b30f..1b545729f62daebed192bb8209c5dbfaddbff1e1 100644 (file)
@@ -1,14 +1,14 @@
 #pragma once
 
 #include <vector>
-#include "drmobject.h"
+#include "drmpropobject.h"
 
 namespace kms
 {
 
 struct EncoderPriv;
 
-class Encoder : public DrmObject
+class Encoder : public DrmPropObject
 {
        friend class Card;
 public:
index b4934b8459bd6c544f21203ac64dc04d0fdbc4e1..b82c1b41ce8a44329a119b4b8dbd6f55a3f8bf28 100644 (file)
@@ -19,7 +19,7 @@ struct PlanePriv
 };
 
 Plane::Plane(Card &card, uint32_t id)
-       :DrmObject(card, id, DRM_MODE_OBJECT_PLANE)
+       :DrmPropObject(card, id, DRM_MODE_OBJECT_PLANE)
 {
        m_priv = new PlanePriv();
        m_priv->drm_plane = drmModeGetPlane(this->card().fd(), this->id());
index 91c403f9949a71322335eb4cd47c34be666aaf5e..3d9d4cd2a442f8712f12b66d18883817fdc08e91 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "drmobject.h"
+#include "drmpropobject.h"
 
 namespace kms
 {
@@ -14,7 +14,7 @@ enum class PlaneType
 
 struct PlanePriv;
 
-class Plane : public DrmObject
+class Plane : public DrmPropObject
 {
        friend class Card;
 public:
index b27ed3ca4389390c5e5a347cfb14715765272092..aa86d9f3df36d0a5dbce6041238372d89fb7b6d8 100644 (file)
@@ -25,12 +25,15 @@ void init_pykmsbase(py::module &m)
 
        py::class_<DrmObject, DrmObject*>(m, "DrmObject")
                        .def_property_readonly("id", &DrmObject::id)
-                       .def("refresh_props", &DrmObject::refresh_props)
-                       .def_property_readonly("prop_map", &DrmObject::get_prop_map)
                        .def_property_readonly("card", &DrmObject::card)
                        ;
 
-       py::class_<Connector, Connector*>(m, "Connector",  py::base<DrmObject>())
+       py::class_<DrmPropObject, DrmPropObject*>(m, "DrmPropObject", py::base<DrmObject>())
+                       .def("refresh_props", &DrmPropObject::refresh_props)
+                       .def_property_readonly("prop_map", &DrmPropObject::get_prop_map)
+                       ;
+
+       py::class_<Connector, Connector*>(m, "Connector",  py::base<DrmPropObject>())
                        .def_property_readonly("fullname", &Connector::fullname)
                        .def("get_default_mode", &Connector::get_default_mode)
                        .def("get_current_crtc", &Connector::get_current_crtc)
@@ -38,7 +41,7 @@ void init_pykmsbase(py::module &m)
                        .def("__repr__", [](const Connector& o) { return "<pykms.Connector " + to_string(o.id()) + ">"; })
                        ;
 
-       py::class_<Crtc, Crtc*>(m, "Crtc",  py::base<DrmObject>())
+       py::class_<Crtc, Crtc*>(m, "Crtc",  py::base<DrmPropObject>())
                        .def("set_mode", &Crtc::set_mode)
                        .def("page_flip", &Crtc::page_flip)
                        .def("set_plane", &Crtc::set_plane)
@@ -47,10 +50,10 @@ void init_pykmsbase(py::module &m)
                        .def("__repr__", [](const Crtc& o) { return "<pykms.Crtc " + to_string(o.id()) + ">"; })
                        ;
 
-       py::class_<Encoder, Encoder*>(m, "Encoder",  py::base<DrmObject>())
+       py::class_<Encoder, Encoder*>(m, "Encoder",  py::base<DrmPropObject>())
                        ;
 
-       py::class_<Plane, Plane*>(m, "Plane",  py::base<DrmObject>())
+       py::class_<Plane, Plane*>(m, "Plane",  py::base<DrmPropObject>())
                        .def("supports_crtc", &Plane::supports_crtc)
                        .def_property_readonly("plane_type", &Plane::plane_type)
                        .def("__repr__", [](const Plane& o) { return "<pykms.Plane " + to_string(o.id()) + ">"; })
index 7b9de8c0f76c2fe18b7584fe5ca73a939a08d47d..a57d33fffbeed29ff68507ec04f405b57aba6958 100644 (file)
@@ -49,7 +49,7 @@ void print_property(uint64_t val, const Property& p, int ind)
               p.name().c_str(), p.id(), p.to_str(val).c_str());
 }
 
-void print_properties(DrmObject& o, int ind)
+void print_properties(DrmPropObject& o, int ind)
 {
        auto pmap = o.get_prop_map();
        printf("%sProperties, %u in total:\n", width(ind, "").c_str(),