Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / ipc / glue / MessageLink.h
blob1ad33030b7428a40fd3d4bae447f9e91753e6d90
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=4 et :
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef ipc_glue_MessageLink_h
9 #define ipc_glue_MessageLink_h
11 #include <cstdint>
12 #include "base/message_loop.h"
13 #include "mojo/core/ports/node.h"
14 #include "mojo/core/ports/port_ref.h"
15 #include "mozilla/Assertions.h"
16 #include "mozilla/UniquePtr.h"
17 #include "mozilla/ipc/ScopedPort.h"
19 namespace IPC {
20 class Message;
21 class MessageReader;
22 class MessageWriter;
23 } // namespace IPC
25 namespace mozilla {
26 namespace ipc {
28 class MessageChannel;
29 class NodeController;
31 struct HasResultCodes {
32 enum Result {
33 MsgProcessed,
34 MsgDropped,
35 MsgNotKnown,
36 MsgNotAllowed,
37 MsgPayloadError,
38 MsgProcessingError,
39 MsgRouteError,
40 MsgValueError
44 enum Side : uint8_t { ParentSide, ChildSide, UnknownSide };
46 const char* StringFromIPCSide(Side side);
48 class MessageLink {
49 public:
50 typedef IPC::Message Message;
52 explicit MessageLink(MessageChannel* aChan);
53 virtual ~MessageLink();
55 // n.b.: These methods all require that the channel monitor is
56 // held when they are invoked.
57 virtual void SendMessage(mozilla::UniquePtr<Message> msg) = 0;
59 // Synchronously close the connection, such that no further notifications will
60 // be delivered to the MessageChannel instance. Must be called with the
61 // channel monitor held.
62 virtual void Close() = 0;
64 virtual bool IsClosed() const = 0;
66 #ifdef FUZZING_SNAPSHOT
67 virtual Maybe<mojo::core::ports::PortName> GetPortName() { return Nothing(); }
68 #endif
70 protected:
71 MessageChannel* mChan;
74 class PortLink final : public MessageLink {
75 using PortRef = mojo::core::ports::PortRef;
76 using PortStatus = mojo::core::ports::PortStatus;
77 using UserMessage = mojo::core::ports::UserMessage;
78 using UserMessageEvent = mojo::core::ports::UserMessageEvent;
80 public:
81 PortLink(MessageChannel* aChan, ScopedPort aPort);
82 virtual ~PortLink();
84 void SendMessage(UniquePtr<Message> aMessage) override;
85 void Close() override;
87 bool IsClosed() const override;
89 #ifdef FUZZING_SNAPSHOT
90 Maybe<mojo::core::ports::PortName> GetPortName() override {
91 return Some(mPort.name());
93 #endif
95 private:
96 class PortObserverThunk;
97 friend class PortObserverThunk;
99 void OnPortStatusChanged();
101 // Called either when an error is detected on the port from the port observer,
102 // or when `SendClose()` is called.
103 void Clear();
105 const RefPtr<NodeController> mNode;
106 const PortRef mPort;
108 RefPtr<PortObserverThunk> mObserver;
111 } // namespace ipc
112 } // namespace mozilla
114 #endif // ifndef ipc_glue_MessageLink_h