Merge lp:~ted/ubuntu-app-launch/mir-26 into lp:ubuntu-app-launch

Proposed by Ted Gould on 2017-02-01
Status: Merged
Approved by: Ted Gould on 2017-02-02
Approved revision: 283
Merged at revision: 284
Proposed branch: lp:~ted/ubuntu-app-launch/mir-26
Merge into: lp:ubuntu-app-launch
Diff against target: 141 lines (+23/-28)
4 files modified
libubuntu-app-launch/ubuntu-app-launch.cpp (+10/-9)
tests/mir-mock.cpp (+3/-13)
ubuntu-app-test/src/CMakeLists.txt (+1/-1)
ubuntu-app-test/src/ubuntu-app-test.cpp (+9/-5)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/mir-26
Reviewer Review Type Date Requested Status
Alan Griffiths 2017-02-01 Needs Fixing on 2017-02-02
unity-api-1-bot continuous-integration Needs Fixing on 2017-02-02
Review via email: mp+316173@code.launchpad.net

Commit Message

Handle deprecated functions in Mir 0.26

To post a comment you must log in.
lp:~ted/ubuntu-app-launch/mir-26 updated on 2017-02-01
282. By Ted Gould on 2017-02-01

Remove mir_wait_for() in ubuntu-app-test as well

lp:~ted/ubuntu-app-launch/mir-26 updated on 2017-02-02
283. By Ted Gould on 2017-02-01

Remove mir_client_fd_callback and mir_wait_for() from the mir mock

unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
Alan Griffiths (alan-griffiths) wrote :

Looks reasonable. (I'd probably have used pthread_cond_t in a C program.)

review: Approve
Alan Griffiths (alan-griffiths) wrote :

Actually, Mir 0.26.1 will be along real soon with a _sync version of this API.

As a temporary measure until that becomes available I recommend disabling the deprecated diagnostic around the call site.

review: Needs Fixing
Cemil Azizoglu (cemil-azizoglu) wrote :

Mir 0.26.1 is in ticket #2435

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntu-app-launch/ubuntu-app-launch.cpp'
2--- libubuntu-app-launch/ubuntu-app-launch.cpp 2017-01-23 22:43:47 +0000
3+++ libubuntu-app-launch/ubuntu-app-launch.cpp 2017-02-02 00:05:08 +0000
4@@ -936,28 +936,29 @@
5 static void
6 get_mir_session_fd_helper (MirPromptSession * session, size_t count, int const * fdin, void * user_data)
7 {
8+ auto promise = static_cast<std::promise<int> *>(user_data);
9+
10 if (count != 1) {
11 g_warning("Mir trusted session returned %d FDs instead of one", (int)count);
12+ promise->set_value(0);
13 return;
14 }
15
16- int * retfd = (int *)user_data;
17- *retfd = fdin[0];
18+ promise->set_value(fdin[0]);
19 }
20
21 /* Setup to get the FD from Mir, blocking */
22 static int
23 get_mir_session_fd (MirPromptSession * session)
24 {
25- int retfd = 0;
26- MirWaitHandle * wait = mir_prompt_session_new_fds_for_prompt_providers(session,
27+ std::promise<int> promise;
28+
29+ mir_prompt_session_new_fds_for_prompt_providers(session,
30 1,
31 get_mir_session_fd_helper,
32- &retfd);
33-
34- mir_wait_for(wait);
35-
36- return retfd;
37+ &promise);
38+
39+ return promise.get_future().get();
40 }
41
42 static GList * open_proxies = NULL;
43
44=== modified file 'tests/mir-mock.cpp'
45--- tests/mir-mock.cpp 2015-12-18 17:21:20 +0000
46+++ tests/mir-mock.cpp 2017-02-02 00:05:08 +0000
47@@ -33,13 +33,12 @@
48 }
49
50 MirWaitHandle *
51-mir_prompt_session_new_fds_for_prompt_providers (MirPromptSession * session, unsigned int numfds, mir_client_fd_callback cb, void * data) {
52+mir_prompt_session_new_fds_for_prompt_providers (MirPromptSession * session, unsigned int numfds, void(*cb)(MirPromptSession * session, size_t count, int const * fdin, void * user_data), void * data) {
53 if (reinterpret_cast<char *>(session) != valid_trust_session) {
54 std::cerr << "Releasing a Mir Trusted Prompt that isn't valid" << std::endl;
55 exit(1);
56 }
57
58- /* TODO: Put in another thread to be more mir like */
59 std::thread * thread = new std::thread([session, numfds, cb, data]() {
60 int fdlist[numfds];
61
62@@ -49,20 +48,11 @@
63 cb(session, numfds, fdlist, data);
64 });
65
66+ thread->detach();
67+
68 return reinterpret_cast<MirWaitHandle *>(thread);
69 }
70
71-void
72-mir_wait_for (MirWaitHandle * wait)
73-{
74- auto thread = reinterpret_cast<std::thread *>(wait);
75-
76- if (thread->joinable())
77- thread->join();
78-
79- delete thread;
80-}
81-
82 static const char * valid_connection_str = "Valid Mir Connection";
83 static std::pair<std::string, std::string> last_connection;
84 static bool valid_connection = true;
85
86=== modified file 'ubuntu-app-test/src/CMakeLists.txt'
87--- ubuntu-app-test/src/CMakeLists.txt 2015-02-23 17:51:44 +0000
88+++ ubuntu-app-test/src/CMakeLists.txt 2017-02-02 00:05:08 +0000
89@@ -1,6 +1,6 @@
90
91 include_directories("${CMAKE_SOURCE_DIR}/libubuntu-app-launch")
92-add_executable(ubuntu-app-test ubuntu-app-test.c)
93+add_executable(ubuntu-app-test ubuntu-app-test.cpp)
94 set_target_properties(ubuntu-app-test PROPERTIES OUTPUT_NAME "ubuntu-app-test")
95 target_link_libraries(ubuntu-app-test ubuntu-launcher ${MIR_LIBRARIES})
96 install(TARGETS ubuntu-app-test RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}/app-test")
97
98=== renamed file 'ubuntu-app-test/src/ubuntu-app-test.c' => 'ubuntu-app-test/src/ubuntu-app-test.cpp'
99--- ubuntu-app-test/src/ubuntu-app-test.c 2015-04-03 17:30:45 +0000
100+++ ubuntu-app-test/src/ubuntu-app-test.cpp 2017-02-02 00:05:08 +0000
101@@ -25,6 +25,8 @@
102
103 #include <sys/wait.h>
104
105+#include <future>
106+
107 gboolean
108 timeout (gpointer ploop)
109 {
110@@ -47,13 +49,15 @@
111 void
112 fd_getter (MirPromptSession * session, size_t count, int const * fdsin, void * pfds)
113 {
114+ auto promise = reinterpret_cast<std::promise<int> *>(pfds);
115+
116 if (count != 1) {
117 g_warning("Didn't get the right number of FDs");
118+ promise->set_value(0);
119 return;
120 }
121
122- int * fds = (int *)pfds;
123- fds[0] = fdsin[0];
124+ promise->set_value(fdsin[0]);
125 }
126
127 int
128@@ -98,10 +102,10 @@
129
130 MirPromptSession * session = mir_connection_create_prompt_session_sync(mir, pid, NULL, NULL);
131
132- int fd = 0;
133- MirWaitHandle * wait = mir_prompt_session_new_fds_for_prompt_providers(session, 1, fd_getter, &fd);
134+ std::promise<int> fdpromise;
135+ mir_prompt_session_new_fds_for_prompt_providers(session, 1, fd_getter, &fdpromise);
136
137- mir_wait_for(wait);
138+ auto fd = fdpromise.get_future().get();
139
140 if (fd == 0) {
141 g_critical("Unable to get FD for prompt session");

Subscribers

People subscribed via source and target branches