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 http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_IPC_TOPLEVELACTORHOLDER_H
8 #define MOZILLA_IPC_TOPLEVELACTORHOLDER_H
10 #include "nsISupports.h"
12 namespace mozilla::ipc
{
14 // Class to let us close the actor when we're not using it anymore. You
15 // should create a single instance of this, and when you have no more
16 // references it will be destroyed and will Close() the underlying
18 // When you want to send something, you use something like
19 // aActor->Actor()->SendFoo()
21 // You can avoid calling Close() on an un-connected Actor (for example if
22 // Bind() fails) by calling RemoveActor();
24 class ToplevelActorHolder final
{
26 NS_INLINE_DECL_REFCOUNTING_ONEVENTTARGET(ToplevelActorHolder
)
28 explicit ToplevelActorHolder(T
* aActor
) : mActor(aActor
) {}
30 constexpr T
* Actor() const { return mActor
; }
31 inline void RemoveActor() { mActor
= nullptr; }
34 inline ~ToplevelActorHolder() {
43 } // namespace mozilla::ipc
45 #endif // MOZILLA_IPC_TOPLEVELACTORHOLDER_H