Merge lp:~alan-griffiths/miral/persistant-surface-store into lp:miral

Proposed by Alan Griffiths
Status: Rejected
Rejected by: Alan Griffiths
Proposed branch: lp:~alan-griffiths/miral/persistant-surface-store
Merge into: lp:miral
Diff against target: 329 lines (+281/-0)
6 files modified
include/miral/toolkit/persistent_id.h (+46/-0)
miral/CMakeLists.txt (+2/-0)
miral/persistent_surface_store.cpp (+53/-0)
miral/persistent_surface_store.h (+71/-0)
test/CMakeLists.txt (+1/-0)
test/persistent_surface_store.cpp (+108/-0)
To merge this branch: bzr merge lp:~alan-griffiths/miral/persistant-surface-store
Reviewer Review Type Date Requested Status
Chris Halse Rogers Disapprove
Alan Griffiths Needs Information
Review via email: mp+302408@code.launchpad.net

Description of the change

I'm not sure how best to expose this functionality. I suspect that servers will only ever want to retrieve the Window/WindowInfo corresponding to a persistent ID.

If that's the case, then adding WindowManagerTools::window_for_id() is probably more useful than exposing the whole class implemented here.

Thoughts/suggestions?

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

*Discussion requested*

review: Needs Information
Revision history for this message
Chris Halse Rogers (raof) wrote :

I think you're correct; the shell is likely only interested in WindowManagerTools::window_for_id() in the short term.

In the longer term, we'll need to provide a way to *persist* the PersistentSurfaceStore; I was expecting that could be done by the shell providing an implementation of it that wrote to disc, but on second thoughts I think we might actually want shells to provide us with a key/value store implementation.

Either way, that's something that this miral::PersistentSurfaceStore doesn't help with.

review: Disapprove
276. By Alan Griffiths

Fix for lp:1611337 has landed

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> I think you're correct; the shell is likely only interested in
> WindowManagerTools::window_for_id() in the short term.

I caught up with <dednick> on IRC, he concurs.

Unmerged revisions

276. By Alan Griffiths

Fix for lp:1611337 has landed

275. By Alan Griffiths

Cleanup CMakeLists.txt

274. By Alan Griffiths

Split implementation code out of test

273. By Alan Griffiths

merge lp:miral

272. By Alan Griffiths

Simpler workaround

271. By Alan Griffiths

Workaround lp:1611337

270. By Alan Griffiths

merge :push

269. By Alan Griffiths

Tidy code

268. By Alan Griffiths

Split out miral/toolkit/persistent_id.h

267. By Alan Griffiths

PersistentSurfaceStore.server_can_identify_surface_specified_by_client

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'include/miral/toolkit/persistent_id.h'
--- include/miral/toolkit/persistent_id.h 1970-01-01 00:00:00 +0000
+++ include/miral/toolkit/persistent_id.h 2016-08-10 09:21:16 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIRAL_TOOLKIT_PERSISTENT_ID_H
20#define MIRAL_TOOLKIT_PERSISTENT_ID_H
21
22#include <mir_toolkit/mir_surface.h>
23
24#include <memory>
25
26namespace miral
27{
28namespace toolkit
29{
30/// Handle class for MirPersistentId - provides automatic reference counting
31class PersistentId
32{
33public:
34 explicit PersistentId(MirPersistentId* id) : self{id, deleter} {}
35 explicit PersistentId(MirSurface* surface) : PersistentId{mir_surface_request_persistent_id_sync(surface)} {}
36
37 auto c_str() const -> char const* { return mir_persistent_id_as_string(self.get()); }
38
39private:
40 static void deleter(MirPersistentId* id) { mir_persistent_id_release(id); }
41 std::shared_ptr<MirPersistentId> self;
42};
43}
44}
45
46#endif //MIRAL_TOOLKIT_PERSISTENT_ID_H
047
=== modified file 'miral/CMakeLists.txt'
--- miral/CMakeLists.txt 2016-08-04 16:26:20 +0000
+++ miral/CMakeLists.txt 2016-08-10 09:21:16 +0000
@@ -8,6 +8,7 @@
8add_library(miral-internal STATIC8add_library(miral-internal STATIC
9 basic_window_manager.cpp basic_window_manager.h window_manager_tools_implementation.h9 basic_window_manager.cpp basic_window_manager.h window_manager_tools_implementation.h
10 mru_window_list.cpp mru_window_list.h10 mru_window_list.cpp mru_window_list.h
11 persistent_surface_store.cpp persistent_surface_store.h
11)12)
1213
13add_library(miral SHARED14add_library(miral SHARED
@@ -30,6 +31,7 @@
30 window_manager_tools.cpp ${CMAKE_SOURCE_DIR}/include/miral/window_manager_tools.h31 window_manager_tools.cpp ${CMAKE_SOURCE_DIR}/include/miral/window_manager_tools.h
31 ${CMAKE_SOURCE_DIR}/include/miral/stream_specification.h32 ${CMAKE_SOURCE_DIR}/include/miral/stream_specification.h
32 ${CMAKE_SOURCE_DIR}/include/miral/toolkit/surface_spec.h33 ${CMAKE_SOURCE_DIR}/include/miral/toolkit/surface_spec.h
34 ${CMAKE_SOURCE_DIR}/include/miral/toolkit/persistent_id.h
33 ${CMAKE_SOURCE_DIR}/include/miral/toolkit/connection.h35 ${CMAKE_SOURCE_DIR}/include/miral/toolkit/connection.h
34)36)
3537
3638
=== added file 'miral/persistent_surface_store.cpp'
--- miral/persistent_surface_store.cpp 1970-01-01 00:00:00 +0000
+++ miral/persistent_surface_store.cpp 2016-08-10 09:21:16 +0000
@@ -0,0 +1,53 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#include "persistent_surface_store.h"
20
21#include <mir/shell/persistent_surface_store.h>
22#include <mir/server.h>
23#include <mir/version.h>
24
25miral::PersistentSurfaceStore::PersistentSurfaceStore() = default;
26miral::PersistentSurfaceStore::~PersistentSurfaceStore() = default;
27miral::PersistentSurfaceStore::PersistentSurfaceStore(PersistentSurfaceStore const&) = default;
28miral::PersistentSurfaceStore& miral::PersistentSurfaceStore::operator=(PersistentSurfaceStore const&) = default;
29
30void miral::PersistentSurfaceStore::operator()(mir::Server& server)
31{
32#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 24, 0)
33 server.add_init_callback[this] { self = server.the_persistent_surface_store(); });
34#else
35 (void)server;
36#endif
37}
38
39auto miral::PersistentSurfaceStore::id_for_surface(std::shared_ptr<mir::scene::Surface> const& surface) -> Id
40{
41 if (auto myself = self.lock())
42 return myself->id_for_surface(surface).serialize_to_string();
43 else
44 throw std::logic_error{"PersistentSurfaceStore not initialized"};
45}
46
47auto miral::PersistentSurfaceStore::surface_for_id(Id const& id) const -> std::shared_ptr<mir::scene::Surface>
48{
49 if (auto myself = self.lock())
50 return myself->surface_for_id(id);
51 else
52 return {};
53}
054
=== added file 'miral/persistent_surface_store.h'
--- miral/persistent_surface_store.h 1970-01-01 00:00:00 +0000
+++ miral/persistent_surface_store.h 2016-08-10 09:21:16 +0000
@@ -0,0 +1,71 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIRAL_PERSISTENT_SURFACE_STORE_H
20#define MIRAL_PERSISTENT_SURFACE_STORE_H
21
22#include <memory>
23#include <string>
24
25namespace mir
26{
27class Server;
28namespace scene { class Surface; }
29namespace shell { class PersistentSurfaceStore; }
30}
31
32namespace miral
33{
34class PersistentSurfaceStore
35{
36public:
37 PersistentSurfaceStore();
38 ~PersistentSurfaceStore();
39 PersistentSurfaceStore(PersistentSurfaceStore const&);
40 PersistentSurfaceStore& operator=(PersistentSurfaceStore const&);
41
42 void operator()(mir::Server& server);
43
44 using Id = std::string;
45
46 /**
47 * \brief Acquire ID for a Surface
48 * \param [in] surface Surface to query or generate an ID for
49 * \return The ID for this surface.
50 * \note If \arg surface has not yet had an ID generated, this generates its ID.
51 * \note This does not extend the lifetime of \arg surface.
52 * \warning Prior to Mir-0.24 the underlying APIs are not available: we throw logic_error.
53 */
54 auto id_for_surface(std::shared_ptr<mir::scene::Surface> const& surface) -> Id;
55
56 /**
57 * \brief Lookup Surface by ID.
58 * \param [in] id ID of surface to lookup
59 * \return The surface with ID \arg id. If this surface has been destroyed,
60 * but the store retains a reference, returns nullptr.
61 * \throws std::out_of_range if the store has no reference for a surface with \arg id.
62 * \warning Prior to Mir-0.24 the underlying APIs are not available: we return nullptr.
63 */
64 auto surface_for_id(Id const& id) const -> std::shared_ptr<mir::scene::Surface>;
65
66private:
67 std::weak_ptr<mir::shell::PersistentSurfaceStore> self;
68};
69}
70
71#endif //MIRAL_PERSISTENT_SURFACE_STORE_H
072
=== modified file 'test/CMakeLists.txt'
--- test/CMakeLists.txt 2016-08-02 09:05:46 +0000
+++ test/CMakeLists.txt 2016-08-10 09:21:16 +0000
@@ -9,6 +9,7 @@
9add_executable(miral-test9add_executable(miral-test
10 mru_window_list.cpp10 mru_window_list.cpp
11 active_outputs.cpp11 active_outputs.cpp
12 persistent_surface_store.cpp
12)13)
1314
14target_link_libraries(miral-test15target_link_libraries(miral-test
1516
=== added file 'test/persistent_surface_store.cpp'
--- test/persistent_surface_store.cpp 1970-01-01 00:00:00 +0000
+++ test/persistent_surface_store.cpp 2016-08-10 09:21:16 +0000
@@ -0,0 +1,108 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#include "../miral/persistent_surface_store.h"
20
21#include <miral/toolkit/persistent_id.h>
22
23#include <mir/test/doubles/wrap_shell_to_track_latest_surface.h>
24#include <mir_test_framework/connected_client_with_a_surface.h>
25
26#include <gtest/gtest.h>
27#include <gmock/gmock.h>
28
29namespace msh = mir::shell;
30namespace ms = mir::scene;
31namespace mt = mir::test;
32namespace mtd = mt::doubles;
33namespace mtf = mir_test_framework;
34
35using namespace mir::geometry;
36using namespace testing;
37
38namespace
39{
40struct PersistentSurfaceStore : mtf::ConnectedClientWithASurface
41{
42 void SetUp() override
43 {
44 server.wrap_shell([this](std::shared_ptr<msh::Shell> const& wrapped)
45 {
46 auto const msc = std::make_shared<mtd::WrapShellToTrackLatestSurface>(wrapped);
47 shell = msc;
48 return msc;
49 });
50
51#if MIR_SERVER_VERSION < MIR_VERSION_NUMBER(0, 25, 0)
52 preset_display({}); // Workaround for lp:1611337
53#endif
54 persistent_surface_store(server);
55 mtf::ConnectedClientWithASurface::SetUp();
56 }
57
58 void TearDown() override
59 {
60 mtf::ConnectedClientWithASurface::TearDown();
61 }
62
63 std::shared_ptr<ms::Surface> latest_shell_surface() const
64 {
65 auto myshell = shell.lock();
66 EXPECT_THAT(myshell, NotNull());
67 auto const result = myshell->latest_surface.lock();
68 EXPECT_THAT(result, NotNull());
69 return result;
70 }
71
72 miral::PersistentSurfaceStore persistent_surface_store;
73
74private:
75 std::weak_ptr<mtd::WrapShellToTrackLatestSurface> shell;
76};
77}
78
79TEST_F(PersistentSurfaceStore, server_and_client_persistent_id_matches)
80{
81 auto const shell_server_surface = latest_shell_surface();
82 ASSERT_THAT(shell_server_surface, NotNull());
83
84 miral::toolkit::PersistentId client_surface_id{surface};
85
86#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 24, 0)
87 auto const server_surface_id = persistent_surface_store.id_for_surface(shell_server_surface);
88
89 auto const client_surface_id_string = client_surface_id.c_str();
90
91 ASSERT_THAT(server_surface_id, Eq(client_surface_id_string));
92#else
93 EXPECT_THROW(persistent_surface_store.id_for_surface(shell_server_surface), std::logic_error);
94#endif
95}
96
97TEST_F(PersistentSurfaceStore, server_can_identify_surface_specified_by_client)
98{
99 miral::toolkit::PersistentId client_surface_id{surface};
100
101 auto const server_surface = persistent_surface_store.surface_for_id(client_surface_id.c_str());
102
103#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 24, 0)
104 ASSERT_THAT(server_surface, Eq(latest_shell_surface()));
105#else
106 ASSERT_THAT(server_surface, IsNull());
107#endif
108}

Subscribers

People subscribed via source and target branches