2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: sw=2 ts=4 et :
|
2013-09-28 05:42:08 +04:00
|
|
|
*/
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef ipc_glue_MessageLink_h
|
|
|
|
#define ipc_glue_MessageLink_h 1
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
|
|
|
#include "mozilla/WeakPtr.h"
|
|
|
|
#include "mozilla/ipc/Transport.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class MessageChannel;
|
|
|
|
|
|
|
|
struct HasResultCodes {
|
|
|
|
enum Result {
|
|
|
|
MsgProcessed,
|
|
|
|
MsgDropped,
|
|
|
|
MsgNotKnown,
|
|
|
|
MsgNotAllowed,
|
|
|
|
MsgPayloadError,
|
|
|
|
MsgProcessingError,
|
|
|
|
MsgRouteError,
|
|
|
|
MsgValueError
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-21 20:04:14 +03:00
|
|
|
enum Side : uint8_t { ParentSide, ChildSide, UnknownSide };
|
2013-09-28 05:42:08 +04:00
|
|
|
|
|
|
|
class MessageLink {
|
|
|
|
public:
|
|
|
|
typedef IPC::Message Message;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
explicit MessageLink(MessageChannel* aChan);
|
2013-09-28 05:42:08 +04:00
|
|
|
virtual ~MessageLink();
|
|
|
|
|
|
|
|
// n.b.: These methods all require that the channel monitor is
|
|
|
|
// held when they are invoked.
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void EchoMessage(Message* msg) = 0;
|
|
|
|
virtual void SendMessage(Message* msg) = 0;
|
2013-09-28 05:42:08 +04:00
|
|
|
virtual void SendClose() = 0;
|
|
|
|
|
|
|
|
virtual bool Unsound_IsClosed() const = 0;
|
|
|
|
virtual uint32_t Unsound_NumQueuedMessages() const = 0;
|
|
|
|
|
|
|
|
protected:
|
2019-05-01 11:47:10 +03:00
|
|
|
MessageChannel* mChan;
|
2013-09-28 05:42:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ProcessLink : public MessageLink, public Transport::Listener {
|
|
|
|
void OnCloseChannel();
|
|
|
|
void OnChannelOpened();
|
|
|
|
void OnTakeConnectedChannel();
|
2019-05-01 11:47:10 +03:00
|
|
|
void OnEchoMessage(Message* msg);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-28 05:42:08 +04:00
|
|
|
void AssertIOThread() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mIOLoop == MessageLoop::current(), "not on I/O thread!");
|
2013-09-28 05:42:08 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-28 05:42:08 +04:00
|
|
|
public:
|
2019-05-01 11:47:10 +03:00
|
|
|
explicit ProcessLink(MessageChannel* chan);
|
2013-09-28 05:42:08 +04:00
|
|
|
virtual ~ProcessLink();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-09 05:19:33 +04:00
|
|
|
// The ProcessLink will register itself as the IPC::Channel::Listener on the
|
|
|
|
// transport passed here. If the transport already has a listener registered
|
|
|
|
// then a listener chain will be established (the ProcessLink listener
|
|
|
|
// methods will be called first and may call some methods on the original
|
|
|
|
// listener as well). Once the channel is closed (either via normal shutdown
|
|
|
|
// or a pipe error) the chain will be destroyed and the original listener
|
|
|
|
// will again be registered.
|
2019-05-01 11:47:10 +03:00
|
|
|
void Open(Transport* aTransport, MessageLoop* aIOLoop, Side aSide);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-28 05:42:08 +04:00
|
|
|
// Run on the I/O thread, only when using inter-process link.
|
|
|
|
// These methods acquire the monitor and forward to the
|
|
|
|
// similarly named methods in AsyncChannel below
|
|
|
|
// (OnMessageReceivedFromLink(), etc)
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void OnMessageReceived(Message&& msg) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void OnChannelConnected(int32_t peer_pid) override;
|
|
|
|
virtual void OnChannelError() override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void EchoMessage(Message* msg) override;
|
|
|
|
virtual void SendMessage(Message* msg) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SendClose() override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Unsound_IsClosed() const override;
|
|
|
|
virtual uint32_t Unsound_NumQueuedMessages() const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-15 01:54:00 +03:00
|
|
|
protected:
|
|
|
|
void OnChannelConnectError();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-28 05:42:08 +04:00
|
|
|
protected:
|
2019-05-01 11:47:10 +03:00
|
|
|
Transport* mTransport;
|
|
|
|
MessageLoop* mIOLoop; // thread where IO happens
|
|
|
|
Transport::Listener* mExistingListener; // channel's previous listener
|
2013-09-28 05:42:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ThreadLink : public MessageLink {
|
|
|
|
public:
|
2019-05-01 11:47:10 +03:00
|
|
|
ThreadLink(MessageChannel* aChan, MessageChannel* aTargetChan);
|
2013-09-28 05:42:08 +04:00
|
|
|
virtual ~ThreadLink();
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual void EchoMessage(Message* msg) override;
|
|
|
|
virtual void SendMessage(Message* msg) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SendClose() override;
|
2013-09-28 05:42:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Unsound_IsClosed() const override;
|
|
|
|
virtual uint32_t Unsound_NumQueuedMessages() const override;
|
2013-09-28 05:42:08 +04:00
|
|
|
|
|
|
|
protected:
|
2019-05-01 11:47:10 +03:00
|
|
|
MessageChannel* mTargetChan;
|
2013-09-28 05:42:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // ifndef ipc_glue_MessageLink_h
|