Line data Source code
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/. */
6 :
7 : #ifndef mozilla_ipc_IPCStreamDestination_h
8 : #define mozilla_ipc_IPCStreamDestination_h
9 :
10 : #include "mozilla/AlreadyAddRefed.h"
11 :
12 : class nsIInputStream;
13 : class nsIAsyncInputStream;
14 : class nsIAsyncOutputStream;
15 :
16 : namespace mozilla {
17 : namespace ipc {
18 :
19 : class PChildToParentStreamParent;
20 : class PParentToChildStreamChild;
21 :
22 : // On the destination side, you must simply call TakeReader() upon receiving a
23 : // reference to the IPCStream{Child,Parent} actor. You do not need to maintain
24 : // a reference to the actor itself.
25 : class IPCStreamDestination
26 : {
27 : public:
28 : static IPCStreamDestination*
29 : Cast(PChildToParentStreamParent* aActor);
30 :
31 : static IPCStreamDestination*
32 : Cast(PParentToChildStreamChild* aActor);
33 :
34 : void
35 : SetDelayedStart(bool aDelayedStart);
36 :
37 : already_AddRefed<nsIInputStream>
38 : TakeReader();
39 :
40 : bool
41 : IsOnOwningThread() const;
42 :
43 : void
44 : DispatchRunnable(already_AddRefed<nsIRunnable>&& aRunnable);
45 :
46 : protected:
47 : IPCStreamDestination();
48 : virtual ~IPCStreamDestination();
49 :
50 : nsresult Initialize();
51 :
52 : // The implementation of the actor should call these methods.
53 :
54 : void
55 : ActorDestroyed();
56 :
57 : void
58 : BufferReceived(const nsCString& aBuffer);
59 :
60 : void
61 : CloseReceived(nsresult aRv);
62 :
63 : #ifdef DEBUG
64 : bool
65 0 : HasDelayedStart() const
66 : {
67 0 : return mDelayedStart;
68 : }
69 : #endif
70 :
71 : // These methods will be implemented by the actor.
72 :
73 : virtual void
74 : StartReading() = 0;
75 :
76 : virtual void
77 : RequestClose(nsresult aRv) = 0;
78 :
79 : virtual void
80 : TerminateDestination() = 0;
81 :
82 : private:
83 : nsCOMPtr<nsIAsyncInputStream> mReader;
84 : nsCOMPtr<nsIAsyncOutputStream> mWriter;
85 :
86 : // This is created by TakeReader() if we need to delay the reading of data.
87 : // We keep a reference to the stream in order to inform it when the actor goes
88 : // away. If that happens, the reading of data will not be possible anymore.
89 : class DelayedStartInputStream;
90 : RefPtr<DelayedStartInputStream> mDelayedStartInputStream;
91 :
92 : nsCOMPtr<nsIThread> mOwningThread;
93 : bool mDelayedStart;
94 : };
95 :
96 : } // namespace ipc
97 : } // namespace mozilla
98 :
99 : #endif // mozilla_ipc_IPCStreamDestination_h
|