2009-07-24 16:24:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: sw=4 ts=4 et :
|
|
|
|
*/
|
2009-07-01 22:45:19 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla IPC.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Chris Jones <jones.chris.g@gmail.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef mozilla_ipc_ProtocolUtils_h
|
|
|
|
#define mozilla_ipc_ProtocolUtils_h 1
|
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
#include "base/process.h"
|
2009-12-03 00:16:03 -08:00
|
|
|
#include "base/process_util.h"
|
2009-07-01 22:45:19 -07:00
|
|
|
#include "chrome/common/ipc_message_utils.h"
|
|
|
|
|
2009-10-29 10:50:28 -07:00
|
|
|
#include "prenv.h"
|
|
|
|
|
2009-12-04 10:45:21 -08:00
|
|
|
#include "mozilla/ipc/Shmem.h"
|
2009-12-03 00:16:28 -08:00
|
|
|
|
|
|
|
// WARNING: this takes into account the private, special-message-type
|
|
|
|
// enum in ipc_channel.h. They need to be kept in sync.
|
|
|
|
namespace {
|
|
|
|
enum {
|
2010-04-26 18:11:40 -07:00
|
|
|
SHMEM_DESTROYED_MESSAGE_TYPE = kuint16max - 5,
|
2010-01-26 22:41:32 -08:00
|
|
|
UNBLOCK_CHILD_MESSAGE_TYPE = kuint16max - 4,
|
|
|
|
BLOCK_CHILD_MESSAGE_TYPE = kuint16max - 3,
|
2009-12-04 10:45:21 -08:00
|
|
|
SHMEM_CREATED_MESSAGE_TYPE = kuint16max - 2,
|
2009-12-03 00:16:28 -08:00
|
|
|
GOODBYE_MESSAGE_TYPE = kuint16max - 1,
|
|
|
|
};
|
|
|
|
}
|
2009-07-01 22:45:19 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
|
2009-07-24 16:24:27 -07:00
|
|
|
// Used to pass references to protocol actors across the wire.
|
|
|
|
// Actors created on the parent-side have a positive ID, and actors
|
|
|
|
// allocated on the child side have a negative ID.
|
2009-07-01 22:45:19 -07:00
|
|
|
struct ActorHandle
|
|
|
|
{
|
2009-07-24 16:24:27 -07:00
|
|
|
int mId;
|
2009-07-01 22:45:19 -07:00
|
|
|
};
|
|
|
|
|
2010-07-15 12:27:43 -07:00
|
|
|
// Used internally to represent a "trigger" that might cause a state
|
|
|
|
// transition. Triggers are normalized across parent+child to Send
|
|
|
|
// and Recv (instead of child-in, child-out, parent-in, parent-out) so
|
|
|
|
// that they can share the same state machine implementation. To
|
|
|
|
// further normalize, |Send| is used for 'call', |Recv| for 'answer'.
|
|
|
|
struct Trigger
|
|
|
|
{
|
|
|
|
enum Action { Send, Recv };
|
|
|
|
|
|
|
|
Trigger(Action action, int32 msg) :
|
|
|
|
mAction(action),
|
|
|
|
mMsg(msg)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Action mAction;
|
|
|
|
int32 mMsg;
|
|
|
|
};
|
|
|
|
|
2009-07-20 09:59:51 -07:00
|
|
|
template<class ListenerT>
|
2009-07-01 22:45:19 -07:00
|
|
|
class /*NS_INTERFACE_CLASS*/ IProtocolManager
|
|
|
|
{
|
|
|
|
public:
|
2009-12-03 00:16:28 -08:00
|
|
|
enum ActorDestroyReason {
|
2011-03-21 09:00:00 -07:00
|
|
|
FailedConstructor,
|
2009-12-03 00:16:28 -08:00
|
|
|
Deletion,
|
|
|
|
AncestorDeletion,
|
|
|
|
NormalShutdown,
|
|
|
|
AbnormalShutdown
|
|
|
|
};
|
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
typedef base::ProcessHandle ProcessHandle;
|
|
|
|
|
2009-07-20 09:59:51 -07:00
|
|
|
virtual int32 Register(ListenerT*) = 0;
|
2009-07-24 16:24:27 -07:00
|
|
|
virtual int32 RegisterID(ListenerT*, int32) = 0;
|
2009-07-20 09:59:51 -07:00
|
|
|
virtual ListenerT* Lookup(int32) = 0;
|
2009-07-01 22:45:19 -07:00
|
|
|
virtual void Unregister(int32) = 0;
|
2010-01-26 20:56:09 -08:00
|
|
|
virtual void RemoveManagee(int32, ListenerT*) = 0;
|
2010-03-22 22:02:16 -07:00
|
|
|
|
2010-04-15 22:29:16 -07:00
|
|
|
virtual Shmem::SharedMemory* CreateSharedMemory(
|
2010-11-05 00:17:07 -07:00
|
|
|
size_t, SharedMemory::SharedMemoryType, bool, int32*) = 0;
|
2010-05-22 12:35:33 -07:00
|
|
|
virtual bool AdoptSharedMemory(Shmem::SharedMemory*, int32*) = 0;
|
2010-03-22 22:02:16 -07:00
|
|
|
virtual Shmem::SharedMemory* LookupSharedMemory(int32) = 0;
|
2010-05-22 12:35:33 -07:00
|
|
|
virtual bool IsTrackingSharedMemory(Shmem::SharedMemory*) = 0;
|
2010-04-26 18:11:40 -07:00
|
|
|
virtual bool DestroySharedMemory(Shmem&) = 0;
|
2010-03-22 22:02:16 -07:00
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
// XXX odd duck, acknowledged
|
2009-12-03 00:16:03 -08:00
|
|
|
virtual ProcessHandle OtherProcess() const = 0;
|
2009-07-01 22:45:19 -07:00
|
|
|
};
|
|
|
|
|
2009-10-29 10:50:28 -07:00
|
|
|
|
|
|
|
inline bool
|
|
|
|
LoggingEnabled()
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
|
|
|
return !!PR_GetEnv("MOZ_IPC_MESSAGE_LOG");
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-04 10:45:21 -08:00
|
|
|
|
2009-07-01 22:45:19 -07:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::ipc::ActorHandle>
|
|
|
|
{
|
2009-07-24 16:24:27 -07:00
|
|
|
typedef mozilla::ipc::ActorHandle paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
IPC::WriteParam(aMsg, aParam.mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
if (IPC::ReadParam(aMsg, aIter, &id)) {
|
|
|
|
aResult->mId = id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2009-07-01 22:45:19 -07:00
|
|
|
}
|
|
|
|
|
2009-07-24 16:24:27 -07:00
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"(%d)", aParam.mId));
|
|
|
|
}
|
2009-07-01 22:45:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace IPC
|
|
|
|
|
|
|
|
|
|
|
|
#endif // mozilla_ipc_ProtocolUtils_h
|