Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: sw=4 ts=4 et : |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef ipc_glue_MessageLink_h |
michael@0 | 9 | #define ipc_glue_MessageLink_h 1 |
michael@0 | 10 | |
michael@0 | 11 | #include "base/basictypes.h" |
michael@0 | 12 | #include "base/message_loop.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "mozilla/WeakPtr.h" |
michael@0 | 15 | #include "mozilla/ipc/Transport.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace ipc { |
michael@0 | 19 | |
michael@0 | 20 | class MessageChannel; |
michael@0 | 21 | |
michael@0 | 22 | struct HasResultCodes |
michael@0 | 23 | { |
michael@0 | 24 | enum Result { |
michael@0 | 25 | MsgProcessed, |
michael@0 | 26 | MsgDropped, |
michael@0 | 27 | MsgNotKnown, |
michael@0 | 28 | MsgNotAllowed, |
michael@0 | 29 | MsgPayloadError, |
michael@0 | 30 | MsgProcessingError, |
michael@0 | 31 | MsgRouteError, |
michael@0 | 32 | MsgValueError |
michael@0 | 33 | }; |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | enum Side { |
michael@0 | 37 | ParentSide, |
michael@0 | 38 | ChildSide, |
michael@0 | 39 | UnknownSide |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | enum ChannelState { |
michael@0 | 43 | ChannelClosed, |
michael@0 | 44 | ChannelOpening, |
michael@0 | 45 | ChannelConnected, |
michael@0 | 46 | ChannelTimeout, |
michael@0 | 47 | ChannelClosing, |
michael@0 | 48 | ChannelError |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | // What happens if Interrupt calls race? |
michael@0 | 52 | enum RacyInterruptPolicy { |
michael@0 | 53 | RIPError, |
michael@0 | 54 | RIPChildWins, |
michael@0 | 55 | RIPParentWins |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | class MessageListener |
michael@0 | 59 | : protected HasResultCodes, |
michael@0 | 60 | public mozilla::SupportsWeakPtr<MessageListener> |
michael@0 | 61 | { |
michael@0 | 62 | public: |
michael@0 | 63 | MOZ_DECLARE_REFCOUNTED_TYPENAME(MessageListener) |
michael@0 | 64 | typedef IPC::Message Message; |
michael@0 | 65 | |
michael@0 | 66 | virtual ~MessageListener() { } |
michael@0 | 67 | |
michael@0 | 68 | virtual void OnChannelClose() = 0; |
michael@0 | 69 | virtual void OnChannelError() = 0; |
michael@0 | 70 | virtual Result OnMessageReceived(const Message& aMessage) = 0; |
michael@0 | 71 | virtual Result OnMessageReceived(const Message& aMessage, Message *& aReply) = 0; |
michael@0 | 72 | virtual Result OnCallReceived(const Message& aMessage, Message *& aReply) = 0; |
michael@0 | 73 | virtual void OnProcessingError(Result aError) = 0; |
michael@0 | 74 | virtual void OnChannelConnected(int32_t peer_pid) {} |
michael@0 | 75 | virtual bool OnReplyTimeout() { |
michael@0 | 76 | return false; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | virtual void OnEnteredCxxStack() { |
michael@0 | 80 | NS_RUNTIMEABORT("default impl shouldn't be invoked"); |
michael@0 | 81 | } |
michael@0 | 82 | virtual void OnExitedCxxStack() { |
michael@0 | 83 | NS_RUNTIMEABORT("default impl shouldn't be invoked"); |
michael@0 | 84 | } |
michael@0 | 85 | virtual void OnEnteredCall() { |
michael@0 | 86 | NS_RUNTIMEABORT("default impl shouldn't be invoked"); |
michael@0 | 87 | } |
michael@0 | 88 | virtual void OnExitedCall() { |
michael@0 | 89 | NS_RUNTIMEABORT("default impl shouldn't be invoked"); |
michael@0 | 90 | } |
michael@0 | 91 | virtual RacyInterruptPolicy MediateInterruptRace(const Message& parent, |
michael@0 | 92 | const Message& child) |
michael@0 | 93 | { |
michael@0 | 94 | return RIPChildWins; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | virtual void ProcessRemoteNativeEventsInInterruptCall() { |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | // FIXME/bug 792652: this doesn't really belong here, but a |
michael@0 | 101 | // large refactoring is needed to put it where it belongs. |
michael@0 | 102 | virtual int32_t GetProtocolTypeId() = 0; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | class MessageLink |
michael@0 | 106 | { |
michael@0 | 107 | public: |
michael@0 | 108 | typedef IPC::Message Message; |
michael@0 | 109 | |
michael@0 | 110 | MessageLink(MessageChannel *aChan); |
michael@0 | 111 | virtual ~MessageLink(); |
michael@0 | 112 | |
michael@0 | 113 | // n.b.: These methods all require that the channel monitor is |
michael@0 | 114 | // held when they are invoked. |
michael@0 | 115 | virtual void EchoMessage(Message *msg) = 0; |
michael@0 | 116 | virtual void SendMessage(Message *msg) = 0; |
michael@0 | 117 | virtual void SendClose() = 0; |
michael@0 | 118 | |
michael@0 | 119 | virtual bool Unsound_IsClosed() const = 0; |
michael@0 | 120 | virtual uint32_t Unsound_NumQueuedMessages() const = 0; |
michael@0 | 121 | |
michael@0 | 122 | protected: |
michael@0 | 123 | MessageChannel *mChan; |
michael@0 | 124 | }; |
michael@0 | 125 | |
michael@0 | 126 | class ProcessLink |
michael@0 | 127 | : public MessageLink, |
michael@0 | 128 | public Transport::Listener |
michael@0 | 129 | { |
michael@0 | 130 | void OnCloseChannel(); |
michael@0 | 131 | void OnChannelOpened(); |
michael@0 | 132 | void OnTakeConnectedChannel(); |
michael@0 | 133 | void OnEchoMessage(Message* msg); |
michael@0 | 134 | |
michael@0 | 135 | void AssertIOThread() const |
michael@0 | 136 | { |
michael@0 | 137 | NS_ABORT_IF_FALSE(mIOLoop == MessageLoop::current(), |
michael@0 | 138 | "not on I/O thread!"); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | public: |
michael@0 | 142 | ProcessLink(MessageChannel *chan); |
michael@0 | 143 | virtual ~ProcessLink(); |
michael@0 | 144 | void Open(Transport* aTransport, MessageLoop *aIOLoop, Side aSide); |
michael@0 | 145 | |
michael@0 | 146 | // Run on the I/O thread, only when using inter-process link. |
michael@0 | 147 | // These methods acquire the monitor and forward to the |
michael@0 | 148 | // similarly named methods in AsyncChannel below |
michael@0 | 149 | // (OnMessageReceivedFromLink(), etc) |
michael@0 | 150 | virtual void OnMessageReceived(const Message& msg) MOZ_OVERRIDE; |
michael@0 | 151 | virtual void OnChannelConnected(int32_t peer_pid) MOZ_OVERRIDE; |
michael@0 | 152 | virtual void OnChannelError() MOZ_OVERRIDE; |
michael@0 | 153 | |
michael@0 | 154 | virtual void EchoMessage(Message *msg) MOZ_OVERRIDE; |
michael@0 | 155 | virtual void SendMessage(Message *msg) MOZ_OVERRIDE; |
michael@0 | 156 | virtual void SendClose() MOZ_OVERRIDE; |
michael@0 | 157 | |
michael@0 | 158 | virtual bool Unsound_IsClosed() const MOZ_OVERRIDE; |
michael@0 | 159 | virtual uint32_t Unsound_NumQueuedMessages() const MOZ_OVERRIDE; |
michael@0 | 160 | |
michael@0 | 161 | protected: |
michael@0 | 162 | Transport* mTransport; |
michael@0 | 163 | MessageLoop* mIOLoop; // thread where IO happens |
michael@0 | 164 | Transport::Listener* mExistingListener; // channel's previous listener |
michael@0 | 165 | }; |
michael@0 | 166 | |
michael@0 | 167 | class ThreadLink : public MessageLink |
michael@0 | 168 | { |
michael@0 | 169 | public: |
michael@0 | 170 | ThreadLink(MessageChannel *aChan, MessageChannel *aTargetChan); |
michael@0 | 171 | virtual ~ThreadLink(); |
michael@0 | 172 | |
michael@0 | 173 | virtual void EchoMessage(Message *msg) MOZ_OVERRIDE; |
michael@0 | 174 | virtual void SendMessage(Message *msg) MOZ_OVERRIDE; |
michael@0 | 175 | virtual void SendClose() MOZ_OVERRIDE; |
michael@0 | 176 | |
michael@0 | 177 | virtual bool Unsound_IsClosed() const MOZ_OVERRIDE; |
michael@0 | 178 | virtual uint32_t Unsound_NumQueuedMessages() const MOZ_OVERRIDE; |
michael@0 | 179 | |
michael@0 | 180 | protected: |
michael@0 | 181 | MessageChannel* mTargetChan; |
michael@0 | 182 | }; |
michael@0 | 183 | |
michael@0 | 184 | } // namespace ipc |
michael@0 | 185 | } // namespace mozilla |
michael@0 | 186 | |
michael@0 | 187 | #endif // ifndef ipc_glue_MessageLink_h |
michael@0 | 188 |