KWayland

resource.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "resource.h"
7 #include "clientconnection.h"
8 #include "resource_p.h"
9 
10 #include <wayland-server.h>
11 
12 namespace KWayland
13 {
14 namespace Server
15 {
16 QList<Resource::Private *> Resource::Private::s_allResources;
17 
18 Resource::Private::Private(Resource *q, Global *g, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
19  : parentResource(parentResource)
20  , global(g)
21  , q(q)
22  , m_interface(interface)
23  , m_interfaceImplementation(implementation)
24 {
25  s_allResources << this;
26 }
27 
28 Resource::Private::~Private()
29 {
30  s_allResources.removeAll(this);
31  if (resource) {
32  wl_resource_destroy(resource);
33  }
34 }
35 
36 void Resource::Private::create(ClientConnection *c, quint32 version, quint32 id)
37 {
38  Q_ASSERT(!resource);
39  Q_ASSERT(!client);
40  client = c;
41  resource = client->createResource(m_interface, version, id);
42  if (!resource) {
43  return;
44  }
45  wl_resource_set_implementation(resource, m_interfaceImplementation, this, unbind);
46 }
47 
48 void Resource::Private::unbind(wl_resource *r)
49 {
50  Private *p = cast<Private>(r);
51  Q_EMIT p->q->aboutToBeUnbound();
52  p->resource = nullptr;
53  Q_EMIT p->q->unbound();
54  p->q->deleteLater();
55 }
56 
57 void Resource::Private::resourceDestroyedCallback(wl_client *client, wl_resource *resource)
58 {
59  Q_UNUSED(client)
60  wl_resource_destroy(resource);
61 }
62 
63 Resource::Resource(Resource::Private *d, QObject *parent)
64  : QObject(parent)
65  , d(d)
66 {
67 }
68 
69 Resource::~Resource() = default;
70 
71 void Resource::create(ClientConnection *client, quint32 version, quint32 id)
72 {
73  d->create(client, version, id);
74 }
75 
77 {
78  return d->client;
79 }
80 
82 {
83  return d->global;
84 }
85 
86 wl_resource *Resource::resource()
87 {
88  return d->resource;
89 }
90 
91 wl_resource *Resource::parentResource() const
92 {
93  return d->parentResource;
94 }
95 
96 quint32 Resource::id() const
97 {
98  if (!d->resource) {
99  return 0;
100  }
101  return wl_resource_get_id(d->resource);
102 }
103 
104 }
105 }
quint32 id() const
Definition: resource.cpp:96
wl_resource * parentResource() const
Definition: resource.cpp:91
wl_resource * resource()
Definition: resource.cpp:86
Base class for all Globals.
Definition: global.h:46
Convenient Class which represents a wl_client.
ClientConnection * client()
Definition: resource.cpp:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Aug 1 2021 22:50:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.