Mir

Merge lp:~vanvugt/mir/super-simple-connect into lp:~mir-team/mir/trunk

Proposed by Daniel van Vugt
Status: Merged
Approved by: Robert Ancell
Approved revision: no longer in the source branch.
Merged at revision: 506
Proposed branch: lp:~vanvugt/mir/super-simple-connect
Merge into: lp:~mir-team/mir/trunk
Diff against target: 86 lines (+47/-0)
3 files modified
include/client/mir_toolkit/mir_client_library.h (+8/-0)
src/client/mir_client_library.cpp (+18/-0)
tests/acceptance-tests/test_client_library.cpp (+21/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/super-simple-connect
Reviewer Review Type Date Requested Status
Chris Halse Rogers Approve
Robert Ancell Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+153307@code.launchpad.net

Commit message

Prototype a super-simple synchronous wrapper for mir_connect().

Description of the change

Other client API functions will be converted pending agreement on the general approach.

But for the record, I don't like this proposal. I prefer:
  lp:~vanvugt/mir/optional-callbacks
but have been told this approach here is more likely to get approved.

To post a comment you must log in.
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I suspect someone will complain about reinterpret_cast. But consider the alternative with N callbacks (one for each API function) and each having to contain its own:
   *(static_cast<MirSomething**>(context)) = something;

I prefer the reinterpret_cast.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

This is pretty much what I was thinking of doing - although I was was going to prefix with "s" not suffix with "_sync", and wasn't going to use reinterpret_cast.

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

> This is pretty much what I was thinking of doing - although I was was going to
> prefix with "s" not suffix with "_sync", and wasn't going to use
> reinterpret_cast.

Oh, and I was going to use a separate header.

Revision history for this message
Kevin DuBois (kdub) wrote :

i like it. slight preference for suffixed names (as it is), no reinterpret, and a separate header

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

It's true that making up new words like "sconnect" is one way to avoid ambiguity. But it steepens the learning curve. Another possible convention is "mir_connect_now", which is a clear message to the reader that "mir_connect" might not connect /right now/.

Separate headers? I disagree. This function relates directly to the existing contents of mir_client_library.h. Separate headers would also steepen the learning curve and it would be generally bad design to have a "connect" function in a different header to its requisite disconnect function.

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

> It's true that making up new words like "sconnect" is one way to avoid
> ambiguity. But it steepens the learning curve. Another possible convention is
> "mir_connect_now", which is a clear message to the reader that "mir_connect"
> might not connect /right now/.
>
> Separate headers? I disagree. This function relates directly to the existing
> contents of mir_client_library.h. Separate headers would also steepen the
> learning curve and it would be generally bad design to have a "connect"
> function in a different header to its requisite disconnect function.

To clarify: I'm not blocking your approach. Just that I would have defined smir_connect(..) and smir_disconnect(..) and the rest of a synchronous API in a separate and independent header.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Looks good to me. I think *_sync is better than s* (it's more clear what "sync" means over "s") and don't see a need to use another header file.

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

Another +1 for *_sync vs s*.

I'm not averse to having a separate, synchronous, header, but I think that as long as we maintain the convention of having _sync stuck on the end of anything that can block it's not particularly necessary.

If you call mir_connect_sync, it's pretty clear you don't want asynchronous behaviour, so I don't think we need to segregate the sync calls out for client's safety.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/client/mir_toolkit/mir_client_library.h'
2--- include/client/mir_toolkit/mir_client_library.h 2013-03-07 08:04:05 +0000
3+++ include/client/mir_toolkit/mir_client_library.h 2013-03-14 09:36:34 +0000
4@@ -161,6 +161,14 @@
5 void *client_context);
6
7 /**
8+ * Perform a mir_connect() but also wait for and return the result.
9+ * \param [in] server A name identifying the server
10+ * \param [in] app_name A name referring to the application
11+ * \return The resulting MirConnection.
12+ */
13+MirConnection *mir_connect_sync(char const *server, char const *app_name);
14+
15+/**
16 * Test for a valid connection
17 * \param [in] connection the connection
18 * \return a non-zero value if the supplied connection is
19
20=== modified file 'src/client/mir_client_library.cpp'
21--- src/client/mir_client_library.cpp 2013-03-07 08:04:05 +0000
22+++ src/client/mir_client_library.cpp 2013-03-14 09:36:34 +0000
23@@ -42,6 +42,13 @@
24 namespace
25 {
26 mir_toolkit::MirConnection error_connection;
27+
28+// assign_result is compatible with all 2-parameter callbacks
29+void assign_result(void *result, void **context)
30+{
31+ *context = result;
32+}
33+
34 }
35
36 mir_toolkit::MirWaitHandle* mir_toolkit::mir_connect(char const* socket_file, char const* name, mir_connected_callback callback, void * context)
37@@ -67,6 +74,17 @@
38 }
39 }
40
41+MirConnection *mir_toolkit::mir_connect_sync(char const *server,
42+ char const *app_name)
43+{
44+ MirConnection *conn = nullptr;
45+ mir_wait_for(mir_connect(server, app_name,
46+ reinterpret_cast<mir_connected_callback>
47+ (assign_result),
48+ &conn));
49+ return conn;
50+}
51+
52 int mir_toolkit::mir_connection_is_valid(MirConnection * connection)
53 {
54 return MirConnection::is_valid(connection);
55
56=== modified file 'tests/acceptance-tests/test_client_library.cpp'
57--- tests/acceptance-tests/test_client_library.cpp 2013-03-07 08:04:05 +0000
58+++ tests/acceptance-tests/test_client_library.cpp 2013-03-14 09:36:34 +0000
59@@ -122,6 +122,27 @@
60 launch_client_process(client_config);
61 }
62
63+TEST_F(DefaultDisplayServerTestFixture, synchronous_connection)
64+{
65+ struct ClientConfig : ClientConfigCommon
66+ {
67+ void exec()
68+ {
69+ connection = NULL;
70+ connection = mir_connect_sync(mir_test_socket,
71+ __PRETTY_FUNCTION__);
72+
73+ ASSERT_TRUE(connection);
74+ EXPECT_TRUE(mir_connection_is_valid(connection));
75+ EXPECT_STREQ(mir_connection_get_error_message(connection), "");
76+
77+ mir_connection_release(connection);
78+ }
79+ } client_config;
80+
81+ launch_client_process(client_config);
82+}
83+
84 TEST_F(DefaultDisplayServerTestFixture, client_library_creates_surface)
85 {
86 struct ClientConfig : ClientConfigCommon

Subscribers

People subscribed via source and target branches