Line data Source code
1 : /*
2 : * Copyright (C) 2023 Sky UK
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Lesser General Public
6 : * License as published by the Free Software Foundation;
7 : * version 2.1 of the License.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Lesser General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public
15 : * License along with this library; if not, write to the Free Software
16 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 : */
18 :
19 : #pragma once
20 :
21 : #include <functional>
22 : #include <memory>
23 :
24 : class Message
25 : {
26 : public:
27 : virtual ~Message() {}
28 : virtual void handle() = 0;
29 : virtual void skip() {};
30 : };
31 :
32 : class IMessageQueue
33 : {
34 : public:
35 519 : virtual ~IMessageQueue() = default;
36 : virtual void start() = 0;
37 : virtual void stop() = 0;
38 : virtual void clear() = 0;
39 : virtual std::shared_ptr<Message> waitForMessage() = 0;
40 : virtual bool postMessage(const std::shared_ptr<Message> &msg) = 0;
41 : virtual void processMessages() = 0;
42 : virtual bool scheduleInEventLoop(const std::function<void()> &func) = 0;
43 : virtual bool callInEventLoop(const std::function<void()> &func) = 0;
44 : };
45 :
46 : class IMessageQueueFactory
47 : {
48 : public:
49 251 : virtual ~IMessageQueueFactory() = default;
50 : static std::shared_ptr<IMessageQueueFactory> createFactory();
51 : virtual std::unique_ptr<IMessageQueue> createMessageQueue() const = 0;
52 : };
|