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

KDE's Doxygen guidelines are available online.