]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - libkms++/drmobject.cpp
cmake: add (commented out) lines for static libc
[android/external-libkmsxx.git] / libkms++ / drmobject.cpp
1 #include <string.h>
2 #include <iostream>
3 #include <xf86drm.h>
4 #include <xf86drmMode.h>
6 #include "kms++.h"
8 using namespace std;
10 namespace kms
11 {
13 DrmObject::DrmObject(Card& card, uint32_t object_type)
14         :m_id(-1), m_card(card), m_object_type(object_type)
15 {
16 }
18 DrmObject::DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx)
19         :m_id(id), m_card(card), m_object_type(object_type), m_idx(idx)
20 {
21         refresh_props();
22 }
24 DrmObject::~DrmObject()
25 {
27 }
29 void DrmObject::refresh_props()
30 {
31         auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type());
33         if (props == nullptr)
34                 return;
36         for (unsigned i = 0; i < props->count_props; ++i) {
37                 uint32_t prop_id = props->props[i];
38                 uint64_t prop_value = props->prop_values[i];
40                 m_prop_values[prop_id] = prop_value;
41         }
43         drmModeFreeObjectProperties(props);
44 }
46 void DrmObject::print_props() const
47 {
48         for (auto it = m_prop_values.begin(); it != m_prop_values.end(); ++it) {
49                 cout << "\t" << card().get_prop(it->first)->name() <<
50                         " = " << it->second << endl;
51         }
52 }
54 uint64_t DrmObject::get_prop_value(uint32_t id) const
55 {
56         return m_prop_values.at(id);
57 }
59 uint64_t DrmObject::get_prop_value(const char *name) const
60 {
61         for (auto pair : m_prop_values) {
62                 auto prop = card().get_prop(pair.first);
63                 if (strcmp(name, prop->name()) == 0)
64                         return m_prop_values.at(prop->id());
65         }
67         throw invalid_argument(string(name) + ": property not found");
68 }
69 }