~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/ipc/ipcd/shared/src/ipcMessage.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
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/
 
8
 *
 
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
 
12
 * License.
 
13
 *
 
14
 * The Original Code is Mozilla IPC.
 
15
 *
 
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.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Darin Fisher <darin@netscape.com>
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#ifndef ipcMessage_h__
 
39
#define ipcMessage_h__
 
40
 
 
41
#include "nsID.h"
 
42
 
 
43
//
 
44
// ipc message format:
 
45
//
 
46
//   +------------------------------------+
 
47
//   | DWORD : length                     |
 
48
//   +------------------+-----------------+
 
49
//   | WORD  : version  | WORD : flags    |
 
50
//   +------------------+-----------------+
 
51
//   | nsID  : target                     |
 
52
//   +------------------------------------+
 
53
//   | data                               |
 
54
//   +------------------------------------+
 
55
//
 
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.
 
59
//
 
60
 
 
61
struct ipcMessageHeader
 
62
{
 
63
    PRUint32 mLen;
 
64
    PRUint16 mVersion;
 
65
    PRUint16 mFlags;
 
66
    nsID     mTarget;
 
67
};
 
68
 
 
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)
 
72
 
 
73
//
 
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.
 
78
//
 
79
#define IPC_MSG_FLAG_SYNC_QUERY (0x1)
 
80
#define IPC_MSG_FLAG_SYNC_REPLY (0x2)
 
81
 
 
82
//-----------------------------------------------------------------------------
 
83
// ipcMessage
 
84
//-----------------------------------------------------------------------------
 
85
 
 
86
class ipcMessage
 
87
{
 
88
public:
 
89
    ipcMessage()
 
90
        : mNext(NULL)
 
91
        , mMsgHdr(NULL)
 
92
        , mMsgOffset(0)
 
93
        , mMsgComplete(PR_FALSE)
 
94
        { }
 
95
    ipcMessage(const nsID &target, const char *data, PRUint32 dataLen)
 
96
        : mNext(NULL)
 
97
        , mMsgHdr(NULL)
 
98
        , mMsgOffset(0)
 
99
        { Init(target, data, dataLen); }
 
100
   ~ipcMessage();
 
101
 
 
102
    //
 
103
    // reset message to uninitialized state
 
104
    //
 
105
    void Reset();
 
106
 
 
107
    // 
 
108
    // create a copy of this message
 
109
    //
 
110
    ipcMessage *Clone() const;
 
111
 
 
112
    //
 
113
    // initialize message
 
114
    //
 
115
    // param:
 
116
    //   topic   - message topic string
 
117
    //   data    - message data (may be null to leave data uninitialized)
 
118
    //   dataLen - message data len
 
119
    //
 
120
    PRStatus Init(const nsID &target, const char *data, PRUint32 dataLen);
 
121
 
 
122
    //
 
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.
 
125
    //
 
126
    // param:
 
127
    //   offset  - destination offset
 
128
    //   data    - data to write
 
129
    //   dataLen - number of bytes to write
 
130
    //
 
131
    PRStatus SetData(PRUint32 offset, const char *data, PRUint32 dataLen);
 
132
 
 
133
    //
 
134
    // access message flags
 
135
    //
 
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; }
 
139
 
 
140
    //
 
141
    // if true, the message is complete and the members of the message
 
142
    // can be accessed.
 
143
    //
 
144
    PRBool IsComplete() const { return mMsgComplete; }
 
145
 
 
146
    //
 
147
    // readonly accessors
 
148
    //
 
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; }
 
155
 
 
156
    //
 
157
    // message comparison functions
 
158
    //
 
159
    // param:
 
160
    //   topic   - message topic (may be null)
 
161
    //   data    - message data (must not be null)
 
162
    //   dataLen - message data length 
 
163
    //
 
164
    PRBool Equals(const nsID &target, const char *data, PRUint32 dataLen) const;
 
165
    PRBool Equals(const ipcMessage *msg) const;
 
166
 
 
167
    //
 
168
    // write the message to a buffer segment; segment need not be large
 
169
    // enough to hold entire message.  called repeatedly.
 
170
    //
 
171
    PRStatus WriteTo(char     *buf,
 
172
                     PRUint32  bufLen,
 
173
                     PRUint32 *bytesWritten,
 
174
                     PRBool   *complete);
 
175
 
 
176
    //
 
177
    // read the message from a buffer segment; segment need not contain
 
178
    // the entire messgae.  called repeatedly.
 
179
    //
 
180
    PRStatus ReadFrom(const char *buf,
 
181
                      PRUint32    bufLen,
 
182
                      PRUint32   *bytesRead,
 
183
                      PRBool     *complete);
 
184
 
 
185
    //
 
186
    // a message can be added to a singly-linked list.
 
187
    //
 
188
    class ipcMessage *mNext;
 
189
 
 
190
private:
 
191
    ipcMessageHeader *mMsgHdr;
 
192
 
 
193
    // XXX document me
 
194
    PRUint32          mMsgOffset;
 
195
    PRPackedBool      mMsgComplete;
 
196
};
 
197
 
 
198
#endif // !ipcMessage_h__