1 #include <xf86drm.h>
2 #include <xf86drmMode.h>
3
4 #include <kms++/kms++.h>
5
6 using namespace std;
7
8 namespace kms
9 {
10
Blob(Card & card,uint32_t blob_id)11 Blob::Blob(Card& card, uint32_t blob_id)
12 : DrmObject(card, blob_id, DRM_MODE_OBJECT_BLOB), m_created(false)
13 {
14 // XXX should we verify that the blob_id is a blob object?
15 }
16
Blob(Card & card,void * data,size_t len)17 Blob::Blob(Card& card, void* data, size_t len)
18 : DrmObject(card, DRM_MODE_OBJECT_BLOB), m_created(true)
19 {
20 uint32_t id;
21
22 int r = drmModeCreatePropertyBlob(card.fd(), data, len, &id);
23 if (r)
24 throw invalid_argument("FAILED TO CREATE PROP\n");
25
26 set_id(id);
27 }
28
~Blob()29 Blob::~Blob()
30 {
31 if (m_created)
32 drmModeDestroyPropertyBlob(card().fd(), id());
33 }
34
data()35 vector<uint8_t> Blob::data()
36 {
37 drmModePropertyBlobPtr blob = drmModeGetPropertyBlob(card().fd(), id());
38
39 if (!blob)
40 throw invalid_argument("Blob data not available");
41
42 uint8_t* data = (uint8_t*)blob->data;
43
44 auto v = vector<uint8_t>(data, data + blob->length);
45
46 drmModeFreePropertyBlob(blob);
47
48 return v;
49 }
50
51 }
52