1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is Mozilla IPC.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 2002
19
* the Initial Developer. All Rights Reserved.
22
* Darin Fisher <darin@netscape.com>
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#ifndef ipcMessage_h__
39
#define ipcMessage_h__
44
// ipc message format:
46
// +------------------------------------+
48
// +------------------+-----------------+
49
// | WORD : version | WORD : flags |
50
// +------------------+-----------------+
52
// +------------------------------------+
54
// +------------------------------------+
56
// header is 24 bytes. flags are defined below. default value of flags is
57
// zero. protocol implementations should ignore unrecognized flags. target
58
// is a 16 byte UUID indicating the intended receiver of this message.
61
struct ipcMessageHeader
69
#define IPC_MSG_VERSION (0x1)
70
#define IPC_MSG_HEADER_SIZE (sizeof(ipcMessageHeader))
71
#define IPC_MSG_GUESSED_SIZE (IPC_MSG_HEADER_SIZE + 64)
74
// the IPC message protocol supports synchronous messages. these messages can
75
// only be sent from a client to the daemon. a daemon module cannot send a
76
// synchronous message. the client sets the SYNC_QUERY flag to indicate that
77
// it is expecting a response with the SYNC_REPLY flag set.
79
#define IPC_MSG_FLAG_SYNC_QUERY (0x1)
80
#define IPC_MSG_FLAG_SYNC_REPLY (0x2)
82
//-----------------------------------------------------------------------------
84
//-----------------------------------------------------------------------------
93
, mMsgComplete(PR_FALSE)
95
ipcMessage(const nsID &target, const char *data, PRUint32 dataLen)
99
{ Init(target, data, dataLen); }
103
// reset message to uninitialized state
108
// create a copy of this message
110
ipcMessage *Clone() const;
113
// initialize message
116
// topic - message topic string
117
// data - message data (may be null to leave data uninitialized)
118
// dataLen - message data len
120
PRStatus Init(const nsID &target, const char *data, PRUint32 dataLen);
123
// copy data into the message's data section, starting from offset. this
124
// function can be used to write any portion of the message's data.
127
// offset - destination offset
128
// data - data to write
129
// dataLen - number of bytes to write
131
PRStatus SetData(PRUint32 offset, const char *data, PRUint32 dataLen);
134
// access message flags
136
void SetFlag(PRUint16 flag) { mMsgHdr->mFlags |= flag; }
137
void ClearFlag(PRUint16 flag) { mMsgHdr->mFlags &= ~flag; }
138
PRBool TestFlag(PRUint16 flag) const { return mMsgHdr->mFlags & flag; }
141
// if true, the message is complete and the members of the message
144
PRBool IsComplete() const { return mMsgComplete; }
147
// readonly accessors
149
const ipcMessageHeader *Header() const { return mMsgHdr; }
150
const nsID &Target() const { return mMsgHdr->mTarget; }
151
const char *Data() const { return (char *) mMsgHdr + IPC_MSG_HEADER_SIZE; }
152
PRUint32 DataLen() const { return mMsgHdr->mLen - IPC_MSG_HEADER_SIZE; }
153
const char *MsgBuf() const { return (char *) mMsgHdr; }
154
PRUint32 MsgLen() const { return mMsgHdr->mLen; }
157
// message comparison functions
160
// topic - message topic (may be null)
161
// data - message data (must not be null)
162
// dataLen - message data length
164
PRBool Equals(const nsID &target, const char *data, PRUint32 dataLen) const;
165
PRBool Equals(const ipcMessage *msg) const;
168
// write the message to a buffer segment; segment need not be large
169
// enough to hold entire message. called repeatedly.
171
PRStatus WriteTo(char *buf,
173
PRUint32 *bytesWritten,
177
// read the message from a buffer segment; segment need not contain
178
// the entire messgae. called repeatedly.
180
PRStatus ReadFrom(const char *buf,
186
// a message can be added to a singly-linked list.
188
class ipcMessage *mNext;
191
ipcMessageHeader *mMsgHdr;
195
PRPackedBool mMsgComplete;
198
#endif // !ipcMessage_h__