Merge lp:~alan-griffiths/miral/raii-for-blob-and-cookie into lp:miral

Proposed by Alan Griffiths on 2017-03-07
Status: Merged
Approved by: Alan Griffiths on 2017-03-15
Approved revision: 534
Merged at revision: 534
Proposed branch: lp:~alan-griffiths/miral/raii-for-blob-and-cookie
Merge into: lp:miral
Diff against target: 122 lines (+102/-0)
3 files modified
include/mir/client/blob.h (+50/-0)
include/mir/client/cookie.h (+50/-0)
miral/CMakeLists.txt (+2/-0)
To merge this branch: bzr merge lp:~alan-griffiths/miral/raii-for-blob-and-cookie
Reviewer Review Type Date Requested Status
Andreas Pokorny (community) Approve on 2017-03-15
Gerry Boland Approve on 2017-03-15
Kevin DuBois (community) 2017-03-07 Approve on 2017-03-14
Review via email: mp+319229@code.launchpad.net

Commit Message

[libmirclientcpp] RAII wrappers for MirBlob and MirCookie

To post a comment you must log in.
Kevin DuBois (kdub) wrote :

lgtm

review: Approve
Gerry Boland (gerboland) wrote :

Why include a default constructor at all?

review: Needs Information
Andreas Pokorny (andreas-pokorny) wrote :

What is the purpose of those two friend declarations?

review: Needs Information
Alan Griffiths (alan-griffiths) wrote :

> Why include a default constructor at all?

It makes it less surprising to use - e.g. it can be placed in a container.

Alan Griffiths (alan-griffiths) wrote :

> What is the purpose of those two friend declarations?

To make it impossible to pass the handle class directly to the release function. Vis:

    Cookie cookie;
    mir_cookie_release(cookie);

error: use of deleted function ‘void {anonymous}::mir_cookie_release(const {anonymous}::Cookie&)’

Gerry Boland (gerboland) wrote :

Ok for me

review: Approve
Andreas Pokorny (andreas-pokorny) wrote :

oh nice to know

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'include/mir/client/blob.h'
2--- include/mir/client/blob.h 1970-01-01 00:00:00 +0000
3+++ include/mir/client/blob.h 2017-03-07 16:36:50 +0000
4@@ -0,0 +1,50 @@
5+/*
6+ * Copyright © 2017 Canonical Ltd.
7+ *
8+ * This program is free software: you can redistribute it and/or modify it
9+ * under the terms of the GNU General Public License version 3,
10+ * as published by the Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ *
20+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
21+ */
22+
23+#ifndef MIR_CLIENT_BLOB_H
24+#define MIR_CLIENT_BLOB_H
25+
26+#include <mir_toolkit/mir_blob.h>
27+
28+#include <memory>
29+
30+namespace mir
31+{
32+namespace client
33+{
34+class Blob
35+{
36+public:
37+ Blob() = default;
38+ explicit Blob(MirBlob* blob) : self{blob, deleter} {}
39+
40+ operator MirBlob*() const { return self.get(); }
41+
42+ void reset() { self.reset(); }
43+ void reset(MirBlob* blob) { self.reset(blob, deleter); }
44+
45+ friend void mir_blob_release(Blob const&) = delete;
46+
47+private:
48+ static void deleter(MirBlob* blob) { mir_blob_release(blob); }
49+ std::shared_ptr<MirBlob> self;
50+};
51+}
52+}
53+
54+#endif //MIR_CLIENT_BLOB_H
55
56=== added file 'include/mir/client/cookie.h'
57--- include/mir/client/cookie.h 1970-01-01 00:00:00 +0000
58+++ include/mir/client/cookie.h 2017-03-07 16:36:50 +0000
59@@ -0,0 +1,50 @@
60+/*
61+ * Copyright © 2017 Canonical Ltd.
62+ *
63+ * This program is free software: you can redistribute it and/or modify it
64+ * under the terms of the GNU General Public License version 3,
65+ * as published by the Free Software Foundation.
66+ *
67+ * This program is distributed in the hope that it will be useful,
68+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
69+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70+ * GNU General Public License for more details.
71+ *
72+ * You should have received a copy of the GNU General Public License
73+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
74+ *
75+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
76+ */
77+
78+#ifndef MIR_CLIENT_COOKIE_H
79+#define MIR_CLIENT_COOKIE_H
80+
81+#include <mir_toolkit/mir_cookie.h>
82+
83+#include <memory>
84+
85+namespace mir
86+{
87+namespace client
88+{
89+class Cookie
90+{
91+public:
92+ Cookie() = default;
93+ explicit Cookie(MirCookie const* cookie) : self{cookie, deleter} {}
94+
95+ operator MirCookie const*() const { return self.get(); }
96+
97+ void reset() { self.reset(); }
98+ void reset(MirCookie const* cookie) { self.reset(cookie, deleter); }
99+
100+ friend void mir_cookie_release(Cookie const&) = delete;
101+
102+private:
103+ static void deleter(MirCookie const* cookie) { mir_cookie_release(cookie); }
104+ std::shared_ptr<MirCookie const> self;
105+};
106+}
107+}
108+
109+#endif //MIR_CLIENT_COOKIE_H
110
111=== modified file 'miral/CMakeLists.txt'
112--- miral/CMakeLists.txt 2017-03-06 09:26:47 +0000
113+++ miral/CMakeLists.txt 2017-03-07 16:36:50 +0000
114@@ -53,6 +53,8 @@
115 workspace_policy.cpp ${CMAKE_SOURCE_DIR}/include/miral/workspace_policy.h
116 window_management_policy.cpp ${CMAKE_SOURCE_DIR}/include/miral/window_management_policy.h
117 window_manager_tools.cpp ${CMAKE_SOURCE_DIR}/include/miral/window_manager_tools.h
118+ ${CMAKE_SOURCE_DIR}/include/mir/client/blob.h
119+ ${CMAKE_SOURCE_DIR}/include/mir/client/cookie.h
120 ${CMAKE_SOURCE_DIR}/include/mir/client/window_spec.h
121 ${CMAKE_SOURCE_DIR}/include/mir/client/window_id.h
122 ${CMAKE_SOURCE_DIR}/include/mir/client/connection.h

Subscribers

People subscribed via source and target branches