summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/ActorProtocol.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/ActorProtocol.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/ActorProtocol.h')
-rw-r--r--xbmc/utils/ActorProtocol.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/xbmc/utils/ActorProtocol.h b/xbmc/utils/ActorProtocol.h
new file mode 100644
index 0000000..97297a6
--- /dev/null
+++ b/xbmc/utils/ActorProtocol.h
@@ -0,0 +1,114 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "threads/CriticalSection.h"
12
13#include <cstddef>
14#include <memory>
15#include <queue>
16#include <string>
17
18class CEvent;
19
20namespace Actor
21{
22
23class CPayloadWrapBase
24{
25public:
26 virtual ~CPayloadWrapBase() = default;
27};
28
29template<typename Payload>
30class CPayloadWrap : public CPayloadWrapBase
31{
32public:
33 ~CPayloadWrap() override = default;
34 CPayloadWrap(Payload *data) {m_pPayload.reset(data);};
35 CPayloadWrap(Payload &data) {m_pPayload.reset(new Payload(data));};
36 Payload *GetPlayload() {return m_pPayload.get();};
37protected:
38 std::unique_ptr<Payload> m_pPayload;
39};
40
41class Protocol;
42
43class Message
44{
45 friend class Protocol;
46
47 static constexpr size_t MSG_INTERNAL_BUFFER_SIZE = 32;
48
49public:
50 int signal;
51 bool isSync = false;
52 bool isSyncFini;
53 bool isOut;
54 bool isSyncTimeout;
55 size_t payloadSize;
56 uint8_t buffer[MSG_INTERNAL_BUFFER_SIZE];
57 uint8_t *data = nullptr;
58 std::unique_ptr<CPayloadWrapBase> payloadObj;
59 Message *replyMessage = nullptr;
60 Protocol &origin;
61 CEvent *event = nullptr;
62
63 void Release();
64 bool Reply(int sig, void *data = nullptr, size_t size = 0);
65
66private:
67 explicit Message(Protocol &_origin) noexcept
68 :origin(_origin) {}
69};
70
71class Protocol
72{
73public:
74 Protocol(std::string name, CEvent* inEvent, CEvent *outEvent)
75 :portName(name), containerInEvent(inEvent), containerOutEvent(outEvent) {}
76 Protocol(std::string name)
77 : Protocol(name, nullptr, nullptr) {}
78 ~Protocol();
79 Message *GetMessage();
80 void ReturnMessage(Message *msg);
81 bool SendOutMessage(int signal,
82 const void* data = nullptr,
83 size_t size = 0,
84 Message* outMsg = nullptr);
85 bool SendOutMessage(int signal, CPayloadWrapBase *payload, Message *outMsg = nullptr);
86 bool SendInMessage(int signal,
87 const void* data = nullptr,
88 size_t size = 0,
89 Message* outMsg = nullptr);
90 bool SendInMessage(int signal, CPayloadWrapBase *payload, Message *outMsg = nullptr);
91 bool SendOutMessageSync(
92 int signal, Message** retMsg, int timeout, const void* data = nullptr, size_t size = 0);
93 bool SendOutMessageSync(int signal, Message **retMsg, int timeout, CPayloadWrapBase *payload);
94 bool ReceiveOutMessage(Message **msg);
95 bool ReceiveInMessage(Message **msg);
96 void Purge();
97 void PurgeIn(int signal);
98 void PurgeOut(int signal);
99 void DeferIn(bool value) {inDefered = value;};
100 void DeferOut(bool value) {outDefered = value;};
101 void Lock() {criticalSection.lock();};
102 void Unlock() {criticalSection.unlock();};
103 std::string portName;
104
105protected:
106 CEvent *containerInEvent, *containerOutEvent;
107 CCriticalSection criticalSection;
108 std::queue<Message*> outMessages;
109 std::queue<Message*> inMessages;
110 std::queue<Message*> freeMessageQueue;
111 bool inDefered = false, outDefered = false;
112};
113
114}