Mir

Merge lp:~robertcarr/mir/fix-input-build-clang into lp:~mir-team/mir/trunk

Proposed by Robert Carr
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 554
Proposed branch: lp:~robertcarr/mir/fix-input-build-clang
Merge into: lp:~mir-team/mir/trunk
Diff against target: 409 lines (+15/-299)
6 files modified
3rd_party/android-deps/std/Looper.h (+2/-286)
3rd_party/android-deps/utils/RefBase.h (+4/-4)
include/test/mir_test_doubles/mock_event_filter.h (+1/-4)
tests/integration-tests/input/android/test_android_input_manager.cpp (+4/-4)
tests/integration-tests/input/android/test_fake_event_hub_to_event_filter.cpp (+1/-1)
tests/unit-tests/input/android/test_android_input_manager.cpp (+3/-0)
To merge this branch: bzr merge lp:~robertcarr/mir/fix-input-build-clang
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Review via email: mp+156634@code.launchpad.net

Commit message

Fix input build in clang.

Description of the change

Fix droidinput build in clang. Removal of ASIO looper is discussed here:

https://code.launchpad.net/~robertcarr/mir/receive-input-in-client

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

excellent

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/android-deps/std/Looper.h'
2--- 3rd_party/android-deps/std/Looper.h 2013-03-13 04:54:15 +0000
3+++ 3rd_party/android-deps/std/Looper.h 2013-04-02 16:41:38 +0000
4@@ -20,290 +20,6 @@
5 #ifndef MIR_ANDROID_UBUNTU_LOOPER_H_
6 #define MIR_ANDROID_UBUNTU_LOOPER_H_
7
8-#include ANDROIDFW_UTILS(RefBase.h)
9-
10-#include <boost/asio.hpp>
11-#include <boost/asio/posix/stream_descriptor.hpp>
12-#include <boost/bind.hpp>
13-#include <boost/exception/all.hpp>
14-
15-#include <algorithm>
16-#include <atomic>
17-#include <chrono>
18-#include <mutex>
19-#include <stdexcept>
20-#include <thread>
21-#include <vector>
22-
23-// This includes some cut & paste from android/looper.h (the enums) and
24-// util/Looper.h (the android::Looper interface).
25-
26-namespace mir_input
27-{
28-/**
29- * For callback-based event loops, this is the prototype of the function
30- * that is called when a file descriptor event occurs.
31- * It is given the file descriptor it is associated with,
32- * a bitmask of the poll events that were triggered (typically ALOOPER_EVENT_INPUT),
33- * and the data pointer that was originally supplied.
34- *
35- * Implementations should return 1 to continue receiving callbacks, or 0
36- * to have this file descriptor and callback unregistered from the looper.
37- */
38-typedef int (*ALooper_callbackFunc)(int fd, int events, void* data);
39-
40-/**
41- * Flags for file descriptor events that a looper can monitor.
42- *
43- * These flag bits can be combined to monitor multiple events at once.
44- */
45-enum {
46- /**
47- * The file descriptor is available for read operations.
48- */
49-
50- ALOOPER_EVENT_INPUT = 1 << 0,
51-
52- /**
53- * The file descriptor is available for write operations.
54- */
55- ALOOPER_EVENT_OUTPUT = 1 << 1,
56-
57- /**
58- * The file descriptor has encountered an error condition.
59- *
60- * The looper always sends notifications about errors; it is not necessary
61- * to specify this event flag in the requested event set.
62- */
63- ALOOPER_EVENT_ERROR = 1 << 2,
64-
65- /**
66- * The file descriptor was hung up.
67- * For example, indicates that the remote end of a pipe or socket was closed.
68- *
69- * The looper always sends notifications about hangups; it is not necessary
70- * to specify this event flag in the requested event set.
71- */
72- ALOOPER_EVENT_HANGUP = 1 << 3,
73-
74- /**
75- * The file descriptor is invalid.
76- * For example, the file descriptor was closed prematurely.
77- *
78- * The looper always sends notifications about invalid file descriptors; it is not necessary
79- * to specify this event flag in the requested event set.
80- */
81- ALOOPER_EVENT_INVALID = 1 << 4
82-};
83-
84-enum {
85- /**
86- * Result from ALooper_pollOnce() and ALooper_pollAll():
87- * The poll was awoken using wake() before the timeout expired
88- * and no callbacks were executed and no other file descriptors were ready.
89- */
90- ALOOPER_POLL_WAKE = -1,
91-
92- /**
93- * Result from ALooper_pollOnce() and ALooper_pollAll():
94- * One or more callbacks were executed.
95- */
96- ALOOPER_POLL_CALLBACK = -2,
97-
98- /**
99- * Result from ALooper_pollOnce() and ALooper_pollAll():
100- * The timeout expired.
101- */
102- ALOOPER_POLL_TIMEOUT = -3,
103-
104- /**
105- * Result from ALooper_pollOnce() and ALooper_pollAll():
106- * An error occurred.
107- */
108- ALOOPER_POLL_ERROR = -4
109-};
110-
111-/**
112- * A polling loop that supports monitoring file descriptor events, optionally
113- * using callbacks.
114- *
115- * A looper can be associated with a thread although there is no requirement that it must be.
116- */
117-class Looper : public ::android::RefBase {
118-protected:
119- virtual ~Looper() { std::lock_guard<std::mutex> lock(mutex); io_service.stop(); files.clear(); }
120-
121-public:
122- /**
123- * Creates a looper.
124- *
125- * If allowNonCallbaks is true, the looper will allow file descriptors to be
126- * registered without associated callbacks. This assumes that the caller of
127- * pollOnce() is prepared to handle callback-less events itself.
128- */
129- Looper(bool allowNonCallbacks) : woken(false)
130- { if (allowNonCallbacks) BOOST_THROW_EXCEPTION(std::logic_error("Callback-less events not allowed")); }
131-
132- /**
133- * Waits for events to be available, with optional timeout in milliseconds.
134- * Invokes callbacks for all file descriptors on which an event occurred.
135- *
136- * If the timeout is zero, returns immediately without blocking.
137- * If the timeout is negative, waits indefinitely until an event appears.
138- *
139- * Returns ALOOPER_POLL_WAKE if the poll was awoken using wake() before
140- * the timeout expired and no callbacks were invoked and no other file
141- * descriptors were ready.
142- *
143- * Returns ALOOPER_POLL_CALLBACK if one or more callbacks were invoked.
144- *
145- * Returns ALOOPER_POLL_TIMEOUT if there was no data before the given
146- * timeout expired.
147- *
148- * Returns ALOOPER_POLL_ERROR if an error occurred.
149- *
150- * Returns a value >= 0 containing an identifier if its file descriptor has data
151- * and it has no callback function (requiring the caller here to handle it).
152- * In this (and only this) case outFd, outEvents and outData will contain the poll
153- * events and data associated with the fd, otherwise they will be set to NULL.
154- *
155- * This method does not return until it has finished invoking the appropriate callbacks
156- * for all file descriptors that were signalled.
157- */
158-
159- inline int pollOnce(int timeoutMillis) {
160- bool callbacks{false};
161-
162- // Outwit valgrind (otherwise AndroidInputManagerAndCursorListenerSetup.* test
163- // runs very erratically and slowly).
164- std::this_thread::yield();
165-
166- boost::system::error_code ec;
167-
168- if (timeoutMillis == 0)
169- {
170- callbacks |= io_service.poll(ec);
171- }
172- else if (timeoutMillis > 0)
173- {
174- boost::asio::deadline_timer timer(
175- io_service,
176- boost::posix_time::milliseconds(timeoutMillis));
177-
178- callbacks |= io_service.run_one(ec);
179- }
180- else
181- {
182- callbacks |= io_service.run_one(ec);
183- }
184-
185- if (ec) return ALOOPER_POLL_ERROR;
186- else if (woken.load()) return ALOOPER_POLL_WAKE;
187- else if (callbacks) return ALOOPER_POLL_CALLBACK;
188- else return ALOOPER_POLL_TIMEOUT;
189- }
190-
191- /**
192- * Wakes the poll asynchronously.
193- *
194- * This method can be called on any thread.
195- * This method returns immediately.
196- */
197- void wake() { io_service.post([&] () {woken.store(true); }); }
198-
199- /**
200- * Adds a new file descriptor to be polled by the looper.
201- * If the same file descriptor was previously added, it is replaced.
202- *
203- * "fd" is the file descriptor to be added.
204- * "ident" is an identifier for this event, which is returned from pollOnce().
205- * The identifier must be >= 0, or ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
206- * "events" are the poll events to wake up on. Typically this is ALOOPER_EVENT_INPUT.
207- * "callback" is the function to call when there is an event on the file descriptor.
208- * "data" is a private data pointer to supply to the callback.
209- *
210- * There are two main uses of this function:
211- *
212- * (1) If "callback" is non-NULL, then this function will be called when there is
213- * data on the file descriptor. It should execute any events it has pending,
214- * appropriately reading from the file descriptor. The 'ident' is ignored in this case.
215- *
216- * (2) If "callback" is NULL, the 'ident' will be returned by ALooper_pollOnce
217- * when its file descriptor has data available, requiring the caller to take
218- * care of processing it.
219- *
220- * Returns 1 if the file descriptor was added, 0 if the arguments were invalid.
221- *
222- * This method can be called on any thread.
223- * This method may block briefly if it needs to wake the poll.
224- *
225- * The callback may either be specified as a bare function pointer or as a smart
226- * pointer callback object. The smart pointer should be preferred because it is
227- * easier to avoid races when the callback is removed from a different thread.
228- * See removeFd() for details.
229- */
230- int addFd(int fd, int ident, int events, ALooper_callbackFunc callback, void* data)
231- { (void)ident;
232- std::lock_guard<std::mutex> lock(mutex);
233- files.emplace_back(io_service, fd);
234-
235- if (events & ALOOPER_EVENT_INPUT)
236- boost::asio::async_read(files.back(), boost::asio::null_buffers(),
237- boost::bind(callback, fd, events, data));
238-
239- return 1;
240- }
241-
242- /**
243- * Removes a previously added file descriptor from the looper.
244- *
245- * When this method returns, it is safe to close the file descriptor since the looper
246- * will no longer have a reference to it. However, it is possible for the callback to
247- * already be running or for it to run one last time if the file descriptor was already
248- * signalled. Calling code is responsible for ensuring that this case is safely handled.
249- * For example, if the callback takes care of removing itself during its own execution either
250- * by returning 0 or by calling this method, then it can be guaranteed to not be invoked
251- * again at any later time unless registered anew.
252- *
253- * A simple way to avoid this problem is to use the version of addFd() that takes
254- * a sp<LooperCallback> instead of a bare function pointer. The LooperCallback will
255- * be released at the appropriate time by the Looper.
256- *
257- * Returns 1 if the file descriptor was removed, 0 if none was previously registered.
258- *
259- * This method can be called on any thread.
260- * This method may block briefly if it needs to wake the poll.
261- */
262- int removeFd(int fd) {
263- std::lock_guard<std::mutex> lock(mutex);
264- auto erase_me = std::find_if(files.begin(), files.end(),
265- [=] (boost::asio::posix::stream_descriptor& ff){ return fd == ff.native(); });
266-
267- if (erase_me == files.end()) return 0;
268- files.erase(erase_me);
269- return 1;
270- }
271-
272-private:
273- std::atomic<bool> woken;
274- boost::asio::io_service io_service;
275- std::mutex mutable mutex;
276- std::vector<boost::asio::posix::stream_descriptor> files;
277-};
278-}
279-
280-namespace android
281-{
282-using ::mir_input::ALooper_callbackFunc;
283-using ::mir_input::ALOOPER_EVENT_INPUT;
284-using ::mir_input::ALOOPER_EVENT_OUTPUT;
285-using ::mir_input::ALOOPER_EVENT_ERROR;
286-using ::mir_input::ALOOPER_EVENT_HANGUP;
287-using ::mir_input::ALOOPER_EVENT_INVALID;
288-using ::mir_input::ALOOPER_POLL_WAKE;
289-using ::mir_input::ALOOPER_POLL_CALLBACK;
290-using ::mir_input::ALOOPER_POLL_TIMEOUT;
291-using ::mir_input::ALOOPER_POLL_ERROR;
292-using ::mir_input::Looper;
293-} // namespace android
294+#include <utils/Looper.h>
295+
296 #endif /* MIR_ANDROID_UBUNTU_LOOPER_H_ */
297
298=== modified file '3rd_party/android-deps/utils/RefBase.h'
299--- 3rd_party/android-deps/utils/RefBase.h 2013-03-13 04:54:15 +0000
300+++ 3rd_party/android-deps/utils/RefBase.h 2013-04-02 16:41:38 +0000
301@@ -167,10 +167,10 @@
302 {
303 public:
304 inline LightRefBase() : mCount(0) { }
305- inline void incStrong(const void* id) const {
306+ inline void incStrong(const void* /* id */) const {
307 android_atomic_inc(&mCount);
308 }
309- inline void decStrong(const void* id) const {
310+ inline void decStrong(const void* /* id */) const {
311 if (android_atomic_dec(&mCount) == 1) {
312 delete static_cast<const T*>(this);
313 }
314@@ -187,8 +187,8 @@
315
316 private:
317 friend class ReferenceMover;
318- inline static void moveReferences(void* d, void const* s, size_t n,
319- const ReferenceConverterBase& caster) { }
320+ inline static void moveReferences(void* /* d */, void const* /* s */, size_t /* n */,
321+ const ReferenceConverterBase& /* caster */) { }
322
323 private:
324 mutable android_atomic_int32_t mCount;
325
326=== modified file 'include/test/mir_test_doubles/mock_event_filter.h'
327--- include/test/mir_test_doubles/mock_event_filter.h 2013-03-13 04:54:15 +0000
328+++ include/test/mir_test_doubles/mock_event_filter.h 2013-04-02 16:41:38 +0000
329@@ -36,11 +36,7 @@
330 MOCK_METHOD1(handles, bool(const MirEvent&));
331 };
332 }
333-}
334-}
335
336-namespace
337-{
338 MATCHER_P(IsKeyEventWithKey, key, "")
339 {
340 if (arg.type != MIR_INPUT_EVENT_TYPE_KEY)
341@@ -71,5 +67,6 @@
342 return (coords->x == dx) && (coords->y == dy);
343 }
344 }
345+}
346
347 #endif // MIR_TEST_DOUBLES_MOCK_EVENT_FILTER_H_
348
349=== modified file 'tests/integration-tests/input/android/test_android_input_manager.cpp'
350--- tests/integration-tests/input/android/test_android_input_manager.cpp 2013-03-29 16:51:35 +0000
351+++ tests/integration-tests/input/android/test_android_input_manager.cpp 2013-04-02 16:41:38 +0000
352@@ -104,7 +104,7 @@
353
354 EXPECT_CALL(
355 event_filter,
356- handles(KeyDownEvent()))
357+ handles(mt::KeyDownEvent()))
358 .Times(1)
359 .WillOnce(ReturnFalseAndWakeUp(&wait_condition));
360
361@@ -125,7 +125,7 @@
362
363 EXPECT_CALL(
364 event_filter,
365- handles(ButtonDownEvent()))
366+ handles(mt::ButtonDownEvent()))
367 .Times(1)
368 .WillOnce(ReturnFalseAndWakeUp(&wait_condition));
369
370@@ -148,10 +148,10 @@
371 InSequence seq;
372
373 EXPECT_CALL(event_filter,
374- handles(MotionEvent(100, 100)))
375+ handles(mt::MotionEvent(100, 100)))
376 .WillOnce(Return(false));
377 EXPECT_CALL(event_filter,
378- handles(MotionEvent(200, 100)))
379+ handles(mt::MotionEvent(200, 100)))
380 .WillOnce(ReturnFalseAndWakeUp(&wait_condition));
381 }
382
383
384=== modified file 'tests/integration-tests/input/android/test_fake_event_hub_to_event_filter.cpp'
385--- tests/integration-tests/input/android/test_fake_event_hub_to_event_filter.cpp 2013-03-13 08:09:52 +0000
386+++ tests/integration-tests/input/android/test_fake_event_hub_to_event_filter.cpp 2013-04-02 16:41:38 +0000
387@@ -103,7 +103,7 @@
388
389 mir::WaitCondition wait_condition;
390
391- EXPECT_CALL(event_filter, handles(KeyDownEvent())).Times(1)
392+ EXPECT_CALL(event_filter, handles(mt::KeyDownEvent())).Times(1)
393 .WillOnce(ReturnFalseAndWakeUp(&wait_condition));
394
395 event_hub->synthesize_builtin_keyboard_added();
396
397=== modified file 'tests/unit-tests/input/android/test_android_input_manager.cpp'
398--- tests/unit-tests/input/android/test_android_input_manager.cpp 2013-03-29 16:51:35 +0000
399+++ tests/unit-tests/input/android/test_android_input_manager.cpp 2013-04-02 16:41:38 +0000
400@@ -40,6 +40,9 @@
401
402 #include <initializer_list>
403
404+#include <sys/types.h>
405+#include <sys/socket.h>
406+
407 namespace droidinput = android;
408
409 namespace mi = mir::input;

Subscribers

People subscribed via source and target branches