Bug 1920241 - Update Persisted Search preferences text - r=daleharvey,fluent-reviewer...
[gecko.git] / ipc / glue / ScopedPort.h
blobe683ba894e578617114ac85a071f684446029ea9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_RawEndpoint_h
8 #define mozilla_ipc_RawEndpoint_h
10 #include "mojo/core/ports/port_ref.h"
12 namespace mozilla::ipc {
14 class NodeController;
16 /// A uniquely owned raw IPC endpoint, connected to our peers over the node
17 /// controller. This type can be sent over IPC channels to establish
18 /// connections.
19 ///
20 /// In general, prefer using Endpoint over ScopedPort for type safety reasons.
21 class ScopedPort {
22 using PortName = mojo::core::ports::PortName;
23 using PortRef = mojo::core::ports::PortRef;
25 public:
26 ScopedPort();
27 ~ScopedPort();
29 ScopedPort(PortRef aPort, NodeController* aController);
31 ScopedPort(ScopedPort&& aOther);
32 ScopedPort(const ScopedPort&) = delete;
34 ScopedPort& operator=(ScopedPort&& aOther);
35 ScopedPort& operator=(const ScopedPort&) = delete;
37 // Allow checking if this `ScopedPort` is valid or not.
38 bool IsValid() const { return mValid; }
39 explicit operator bool() const { return IsValid(); }
41 // Underlying port and controller which are used by this ScopedPort.
42 const PortName& Name() const { return mPort.name(); }
43 const PortRef& Port() const { return mPort; }
44 NodeController* Controller() const { return mController; }
46 // Release ownership over the contained `ScopedPort`, meaning that it will
47 // not be closed when this ScopedPort is destroyed. This will make the
48 // endpoint invalid.
49 PortRef Release();
51 private:
52 void Reset();
54 bool mValid = false;
55 PortRef mPort;
56 RefPtr<NodeController> mController;
58 // NOTE: This type does not contain PID information about the other process,
59 // which will need to be sent separately if necessary.
62 } // namespace mozilla::ipc
64 namespace IPC {
66 template <typename T>
67 struct ParamTraits;
69 template <>
70 struct ParamTraits<mozilla::ipc::ScopedPort> {
71 using paramType = mozilla::ipc::ScopedPort;
73 static void Write(MessageWriter* aWriter, paramType&& aParam);
74 static bool Read(MessageReader* aReader, paramType* aResult);
77 } // namespace IPC
79 #endif