~mir-team/mir/rename-everything

« back to all changes in this revision

Viewing changes to tests/include/mir_test_doubles/triggered_main_loop.h

Move TriggeredMainLoop to separate translation unit to be able to reuse it elsewhere.

Approved by Kevin DuBois, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2015 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: Andreas Pokorny <andreas.pokorny@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef MIR_TEST_DOUBLES_TRIGGERED_MAIN_LOOP_H_
 
20
#define MIR_TEST_DOUBLES_TRIGGERED_MAIN_LOOP_H_
 
21
 
 
22
#include "mir_test_doubles/mock_main_loop.h"
 
23
 
 
24
#include <vector>
 
25
 
 
26
namespace mir
 
27
{
 
28
namespace test
 
29
{
 
30
namespace doubles
 
31
{
 
32
 
 
33
class TriggeredMainLoop : public ::testing::NiceMock<MockMainLoop>
 
34
{
 
35
public:
 
36
    using fd_callback = std::function<void(int)>;
 
37
    using signal_callback = std::function<void(int)>;
 
38
    using callback = std::function<void()>;
 
39
 
 
40
    void register_fd_handler(std::initializer_list<int> fds, void const* owner, fd_callback const& handler) override;
 
41
    void unregister_fd_handler(void const* owner) override;
 
42
    std::unique_ptr<mir::time::Alarm> notify_in(std::chrono::milliseconds delay, callback call) override;
 
43
    void enqueue(void const* owner, ServerAction const& action) override;
 
44
 
 
45
    void trigger_pending_fds();
 
46
    void fire_all_alarms();
 
47
    void trigger_server_actions();
 
48
 
 
49
private:
 
50
    std::vector<callback> timeout_callbacks;
 
51
 
 
52
    struct Item
 
53
    {
 
54
        int fd;
 
55
        void const* owner;
 
56
        fd_callback callback;
 
57
    };
 
58
    std::vector<Item> fd_callbacks;
 
59
    std::vector<ServerAction> actions;
 
60
};
 
61
 
 
62
}
 
63
}
 
64
}
 
65
 
 
66
#endif