-
Notifications
You must be signed in to change notification settings - Fork 2
/
WlResource.cpp
46 lines (39 loc) · 1.24 KB
/
WlResource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "WlResource.h"
#include <wayland-server-core.h>
#include <stdio.h>
void WlResource::Destructor(struct wl_resource *resource)
{
delete WlResource::FromResource(resource);
}
int WlResource::Dispatcher(const void *impl, void *resource, uint32_t opcode, const struct wl_message *message, union wl_argument *args)
{
return WlResource::FromResource((struct wl_resource*)resource)->Dispatch(opcode, message, args);
}
bool WlResource::Init(struct wl_client *wl_client, uint32_t version, uint32_t id)
{
fResource = wl_resource_create(wl_client, Interface(), version, id);
if (fResource == NULL) {
wl_client_post_no_memory(wl_client);
return false;
}
wl_resource_set_dispatcher(fResource, Dispatcher, NULL, this, Destructor);
return true;
}
void WlResource::Destroy()
{
wl_resource_destroy(ToResource());
}
WlResource *WlResource::FromResource(struct wl_resource *resource)
{
if (resource == NULL)
return NULL;
WlResource *resourceOut = (WlResource*)wl_resource_get_user_data(resource);
if (resourceOut == NULL || !wl_resource_instance_of(resource, resourceOut->Interface(), NULL)) {
return NULL;
}
return resourceOut;
}
int WlResource::Dispatch(uint32_t opcode, const struct wl_message *message, union wl_argument *args)
{
return -1;
}