Merge lp:~thomas-voss/miracast-service/fix-trunk-build into lp:miracast-service

Proposed by Thomas Voß
Status: Merged
Approved by: Simon Fels
Approved revision: 104
Merged at revision: 104
Proposed branch: lp:~thomas-voss/miracast-service/fix-trunk-build
Merge into: lp:miracast-service
Diff against target: 518 lines (+490/-0)
4 files modified
debian/control (+1/-0)
tests/3rd_party/process-cpp-minimal/include/core/connection.h (+190/-0)
tests/3rd_party/process-cpp-minimal/include/core/signal.h (+297/-0)
tests/mcs/acceptance_tests/CMakeLists.txt (+2/-0)
To merge this branch: bzr merge lp:~thomas-voss/miracast-service/fix-trunk-build
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+279506@code.launchpad.net

Commit message

Fix trunk build. Note to self: *ALWAYS* test in a clean chroot.
Vendorize missing header files.

Description of the change

Fix trunk build. Note to self: *ALWAYS* test in a clean chroot.
Vendorize missing header files.

To post a comment you must log in.
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 'debian/control'
2--- debian/control 2015-12-03 12:23:27 +0000
3+++ debian/control 2015-12-03 20:54:23 +0000
4@@ -8,6 +8,7 @@
5 google-mock,
6 libboost-dev,
7 libboost-filesystem-dev,
8+ libboost-iostreams-dev,
9 libboost-system-dev,
10 libglib2.0-dev,
11 libgstreamer1.0-dev,
12
13=== added file 'tests/3rd_party/process-cpp-minimal/include/core/connection.h'
14--- tests/3rd_party/process-cpp-minimal/include/core/connection.h 1970-01-01 00:00:00 +0000
15+++ tests/3rd_party/process-cpp-minimal/include/core/connection.h 2015-12-03 20:54:23 +0000
16@@ -0,0 +1,190 @@
17+/*
18+ * Copyright © 2013 Canonical Ltd.
19+ *
20+ * This program is free software: you can redistribute it and/or modify it
21+ * under the terms of the GNU Lesser General Public License version 3,
22+ * as published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU Lesser General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU Lesser General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
33+ */
34+#ifndef COM_UBUNTU_CONNECTION_H_
35+#define COM_UBUNTU_CONNECTION_H_
36+
37+#include <functional>
38+#include <memory>
39+#include <mutex>
40+
41+namespace core
42+{
43+class ScopedConnection;
44+/**
45+ * @brief The Connection class models a signal-slot connection.
46+ */
47+class Connection
48+{
49+public:
50+ typedef std::function<void(const std::function<void()>&)> Dispatcher;
51+
52+ /**
53+ * @brief Checks if this instance corresponds to an active signal-slot connection.
54+ * @return true iff the instance corresponds to an active signal-slot connection.
55+ */
56+ inline bool is_connected() const
57+ {
58+ if (!d)
59+ return false;
60+
61+ return (d->disconnector ? true : false);
62+ }
63+
64+ /**
65+ * @brief End a signal-slot connection.
66+ */
67+ inline void disconnect()
68+ {
69+ if (d)
70+ d->disconnect();
71+ }
72+
73+ /**
74+ * @brief Installs a dispatcher for this signal-slot connection.
75+ * @param dispatcher The dispatcher to be used for signal emissions.
76+ */
77+ inline void dispatch_via(const Dispatcher& dispatcher)
78+ {
79+ if (d && d->dispatcher_installer)
80+ d->dispatcher_installer(dispatcher);
81+ }
82+
83+private:
84+ friend class ScopedConnection;
85+
86+ typedef std::function<void()> Disconnector;
87+ typedef std::function<void(const Dispatcher&)> DispatcherInstaller;
88+
89+ template<typename ... Arguments> friend class Signal;
90+
91+ inline Connection(const Disconnector& disconnector,
92+ const DispatcherInstaller& installer)
93+ : d(std::make_shared<Private>(disconnector, installer))
94+ {
95+ }
96+
97+ inline bool operator<(const Connection& rhs) const
98+ {
99+ return d < rhs.d;
100+ }
101+
102+ inline void reset()
103+ {
104+ if (d)
105+ d->reset();
106+ }
107+
108+ struct Private
109+ {
110+ Private(const Connection::Disconnector& disconnector,
111+ const Connection::DispatcherInstaller& dispatcher_installer)
112+ : disconnector(disconnector),
113+ dispatcher_installer(dispatcher_installer)
114+ {
115+ }
116+
117+ inline void reset()
118+ {
119+ std::lock_guard<std::mutex> lg(guard);
120+ reset_locked();
121+ }
122+
123+ inline void reset_locked()
124+ {
125+ static const Connection::Disconnector empty_disconnector{};
126+ static const Connection::DispatcherInstaller empty_dispatcher_installer{};
127+
128+ disconnector = empty_disconnector;
129+ dispatcher_installer = empty_dispatcher_installer;
130+ }
131+
132+ inline void disconnect()
133+ {
134+ static const Connection::Disconnector empty_disconnector{};
135+
136+ std::lock_guard<std::mutex> lg(guard);
137+
138+ if (disconnector)
139+ disconnector();
140+
141+ reset_locked();
142+ }
143+
144+ std::mutex guard;
145+ Connection::Disconnector disconnector;
146+ Connection::DispatcherInstaller dispatcher_installer;
147+ };
148+
149+ // The whole class is implicitly shared and we thus forward our complete
150+ // shared state to a private structure that is lifetime-managed by a shared_ptr.
151+ std::shared_ptr<Private> d;
152+};
153+
154+/**
155+ * @brief Scoped helper class to map signal-slot connection mgmt. to RAII.
156+ */
157+class ScopedConnection
158+{
159+public:
160+ /**
161+ * @brief Constructs an instance for an existing signal-slot connection.
162+ * @param c The existing signal-slot connection.
163+ */
164+ inline ScopedConnection(const Connection& c) : connection(c)
165+ {
166+ }
167+
168+ inline ScopedConnection(ScopedConnection&& rhs) : connection(std::move(rhs.connection))
169+ {
170+ }
171+
172+ ScopedConnection(const ScopedConnection&) = delete;
173+
174+ /**
175+ * @brief Disconnects the signal-slot connection.
176+ */
177+ inline ~ScopedConnection() noexcept(true)
178+ {
179+ try
180+ {
181+ connection.disconnect();
182+ } catch(...)
183+ {
184+ }
185+ }
186+
187+ inline ScopedConnection& operator=(ScopedConnection&& rhs)
188+ {
189+ connection = std::move(rhs.connection);
190+ return *this;
191+ }
192+
193+ ScopedConnection& operator=(const ScopedConnection&) = delete;
194+ bool operator==(const ScopedConnection&) = delete;
195+
196+ inline bool operator<(const ScopedConnection& rhs) const
197+ {
198+ return connection < rhs.connection;
199+ }
200+
201+private:
202+ Connection connection;
203+};
204+}
205+
206+#endif // COM_UBUNTU_CONNECTION_H_
207
208=== added file 'tests/3rd_party/process-cpp-minimal/include/core/signal.h'
209--- tests/3rd_party/process-cpp-minimal/include/core/signal.h 1970-01-01 00:00:00 +0000
210+++ tests/3rd_party/process-cpp-minimal/include/core/signal.h 2015-12-03 20:54:23 +0000
211@@ -0,0 +1,297 @@
212+/*
213+ * Copyright © 2013 Canonical Ltd.
214+ *
215+ * This program is free software: you can redistribute it and/or modify it
216+ * under the terms of the GNU Lesser General Public License version 3,
217+ * as published by the Free Software Foundation.
218+ *
219+ * This program is distributed in the hope that it will be useful,
220+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
221+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
222+ * GNU Lesser General Public License for more details.
223+ *
224+ * You should have received a copy of the GNU Lesser General Public License
225+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
226+ *
227+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
228+ */
229+#ifndef COM_UBUNTU_SIGNAL_H_
230+#define COM_UBUNTU_SIGNAL_H_
231+
232+#include <core/connection.h>
233+
234+#include <functional>
235+#include <iostream>
236+#include <list>
237+#include <mutex>
238+#include <set>
239+
240+namespace core
241+{
242+/**
243+ * @brief A signal class that observers can subscribe to.
244+ * @tparam Arguments List of argument types passed on to observers when the signal is emitted.
245+ */
246+template<typename ...Arguments>
247+class Signal
248+{
249+public:
250+ /**
251+ * @brief Slot is the function type that observers have to provide to connect to this signal.
252+ */
253+ typedef std::function<void(Arguments...)> Slot;
254+
255+private:
256+ struct SlotWrapper
257+ {
258+ void operator()(Arguments... args)
259+ {
260+ dispatcher(std::bind(slot, args...));
261+ }
262+
263+ Slot slot;
264+ Connection::Dispatcher dispatcher;
265+ Connection connection;
266+ };
267+
268+public:
269+ /**
270+ * @brief Signal constructs a new instance. Never throws.
271+ */
272+ inline Signal() noexcept(true) : d(new Private())
273+ {
274+ }
275+
276+ inline ~Signal()
277+ {
278+ std::lock_guard<std::mutex> lg(d->guard);
279+ for (auto slot : d->slot_list)
280+ slot.connection.reset();
281+ }
282+
283+ // Copy construction, assignment and equality comparison are disabled.
284+ Signal(const Signal&) = delete;
285+ Signal& operator=(const Signal&) = delete;
286+ bool operator==(const Signal&) const = delete;
287+
288+ /**
289+ * @brief Connects the provided slot to this signal instance.
290+ *
291+ * Calling this method is thread-safe and synchronized with any
292+ * other connect, signal emission or disconnect calls.
293+ *
294+ * @param slot The function to be called when the signal is emitted.
295+ * @return A connection object corresponding to the signal-slot connection.
296+ */
297+ inline Connection connect(const Slot& slot) const
298+ {
299+ // Helpers to initialize an invalid connection.
300+ static const Connection::Disconnector empty_disconnector{};
301+ static const Connection::DispatcherInstaller empty_dispatcher_installer{};
302+
303+ // The default dispatcher immediately executes the function object
304+ // provided as argument on whatever thread is currently running.
305+ static const Connection::Dispatcher default_dispatcher
306+ = [](const std::function<void()>& handler) { handler(); };
307+
308+ Connection conn{empty_disconnector, empty_dispatcher_installer};
309+
310+ std::lock_guard<std::mutex> lg(d->guard);
311+
312+ auto result = d->slot_list.insert(
313+ d->slot_list.end(),
314+ SlotWrapper{slot, default_dispatcher, conn});
315+
316+ // We implicitly share our internal state with the connection here
317+ // by passing in our private bits contained in 'd' to the std::bind call.
318+ // This admittedly uncommon approach allows us to cleanly manage connection
319+ // and signal lifetimes without the need to mark everything as mutable.
320+ conn.d->disconnector = std::bind(
321+ &Private::disconnect_slot_for_iterator,
322+ d,
323+ result);
324+ conn.d->dispatcher_installer = std::bind(
325+ &Private::install_dispatcher_for_iterator,
326+ d,
327+ std::placeholders::_1,
328+ result);
329+
330+ return conn;
331+ }
332+
333+ /**
334+ * @brief operator () emits the signal with the provided parameters.
335+ *
336+ * Please note that signal emissions might not be delivered immediately to
337+ * registered slots, depending on whether the respective connection is dispatched
338+ * via a queueing dispatcher. For that reason, the lifetime of the arguments has to
339+ * exceed the scope of the call to this operator and its surrounding scope.
340+ *
341+ * @param args The arguments to be passed on to registered slots.
342+ */
343+ inline void operator()(Arguments... args)
344+ {
345+ std::lock_guard<std::mutex> lg(d->guard);
346+ for(auto slot : d->slot_list)
347+ {
348+ slot(args...);
349+ }
350+ }
351+
352+private:
353+ struct Private
354+ {
355+ typedef std::list<SlotWrapper> SlotList;
356+
357+ inline void disconnect_slot_for_iterator(typename SlotList::iterator it)
358+ {
359+ std::lock_guard<std::mutex> lg(guard);
360+ slot_list.erase(it);
361+ }
362+
363+ inline void install_dispatcher_for_iterator(const Connection::Dispatcher& dispatcher,
364+ typename SlotList::iterator it)
365+ {
366+ std::lock_guard<std::mutex> lg(guard);
367+ it->dispatcher = dispatcher;
368+ }
369+
370+ std::mutex guard;
371+ SlotList slot_list;
372+ };
373+ std::shared_ptr<Private> d;
374+};
375+
376+/**
377+ * @brief A signal class that observers can subscribe to,
378+ * template specialization for signals without arguments.
379+ */
380+template<>
381+class Signal<void>
382+{
383+public:
384+ /**
385+ * @brief Slot is the function type that observers have to provide to connect to this signal.
386+ */
387+ typedef std::function<void()> Slot;
388+
389+private:
390+ struct SlotWrapper
391+ {
392+ void operator()()
393+ {
394+ dispatcher(slot);
395+ }
396+
397+ Slot slot;
398+ Connection::Dispatcher dispatcher;
399+ Connection connection;
400+ };
401+
402+public:
403+ /**
404+ * @brief Signal constructs a new instance. Never throws.
405+ */
406+ inline Signal() noexcept(true) : d(new Private())
407+ {
408+ }
409+
410+ inline ~Signal()
411+ {
412+ std::lock_guard<std::mutex> lg(d->guard);
413+ for (auto slot : d->slot_list)
414+ slot.connection.reset();
415+ }
416+
417+ // Copy construction, assignment and equality comparison are disabled.
418+ Signal(const Signal&) = delete;
419+ Signal& operator=(const Signal&) = delete;
420+ bool operator==(const Signal&) const = delete;
421+
422+ /**
423+ * @brief Connects the provided slot to this signal instance.
424+ *
425+ * Calling this method is thread-safe and synchronized with any
426+ * other connect, signal emission or disconnect calls.
427+ *
428+ * @param slot The function to be called when the signal is emitted.
429+ * @return A connection object corresponding to the signal-slot connection.
430+ */
431+ inline Connection connect(const Slot& slot) const
432+ {
433+ // Helpers to initialize an invalid connection.
434+ static const Connection::Disconnector empty_disconnector{};
435+ static const Connection::DispatcherInstaller empty_dispatcher_installer{};
436+
437+ // The default dispatcher immediately executes the function object
438+ // provided as argument on whatever thread is currently running.
439+ static const Connection::Dispatcher default_dispatcher
440+ = [](const std::function<void()>& handler) { handler(); };
441+
442+ Connection conn{empty_disconnector, empty_dispatcher_installer};
443+
444+ std::lock_guard<std::mutex> lg(d->guard);
445+
446+ auto result = d->slot_list.insert(
447+ d->slot_list.end(),
448+ SlotWrapper{slot, default_dispatcher, conn});
449+
450+ // We implicitly share our internal state with the connection here
451+ // by passing in our private bits contained in 'd' to the std::bind call.
452+ // This admittedly uncommon approach allows us to cleanly manage connection
453+ // and signal lifetimes without the need to mark everything as mutable.
454+ conn.d->disconnector = std::bind(
455+ &Private::disconnect_slot_for_iterator,
456+ d,
457+ result);
458+ conn.d->dispatcher_installer = std::bind(
459+ &Private::install_dispatcher_for_iterator,
460+ d,
461+ std::placeholders::_1,
462+ result);
463+
464+ return conn;
465+ }
466+
467+ /**
468+ * @brief operator () emits the signal.
469+ *
470+ * Please note that signal emissions might not be delivered immediately to
471+ * registered slots, depending on whether the respective connection is dispatched
472+ * via a queueing dispatcher.
473+ */
474+ inline void operator()()
475+ {
476+ std::lock_guard<std::mutex> lg(d->guard);
477+ for(auto slot : d->slot_list)
478+ {
479+ slot();
480+ }
481+ }
482+
483+private:
484+ struct Private
485+ {
486+ typedef std::list<SlotWrapper> SlotList;
487+
488+ inline void disconnect_slot_for_iterator(typename SlotList::iterator it)
489+ {
490+ std::lock_guard<std::mutex> lg(guard);
491+ slot_list.erase(it);
492+ }
493+
494+ inline void install_dispatcher_for_iterator(const Connection::Dispatcher& dispatcher,
495+ typename SlotList::iterator it)
496+ {
497+ std::lock_guard<std::mutex> lg(guard);
498+ it->dispatcher = dispatcher;
499+ }
500+
501+ std::mutex guard;
502+ SlotList slot_list;
503+ };
504+ std::shared_ptr<Private> d;
505+};
506+}
507+
508+#endif // COM_UBUNTU_SIGNAL_H_
509
510=== modified file 'tests/mcs/acceptance_tests/CMakeLists.txt'
511--- tests/mcs/acceptance_tests/CMakeLists.txt 2015-12-02 09:36:09 +0000
512+++ tests/mcs/acceptance_tests/CMakeLists.txt 2015-12-03 20:54:23 +0000
513@@ -1,3 +1,5 @@
514+include_directories(${CMAKE_SOURCE_DIR}/tests/3rd_party/process-cpp-minimal/include)
515+
516 add_executable(miracast_service_tests miracast_service_tests.cpp did_exit_cleanly.cpp)
517 target_link_libraries(miracast_service_tests miracast gtest gtest_main process-cpp)
518 add_test(miracast_service_tests miracast_service_tests)

Subscribers

People subscribed via source and target branches

to all changes: