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 ***** */
41
#include "ipcConfig.h"
43
#include "ipcMessage.h"
44
#include "ipcClient.h"
45
#include "ipcModuleReg.h"
46
#include "ipcModule.h"
47
#include "ipcCommandModule.h"
48
#include "ipcdPrivate.h"
51
//-----------------------------------------------------------------------------
56
PRFileDesc *fd = PR_GetInheritedFD(IPC_STARTUP_PIPE_NAME);
58
char c = IPC_STARTUP_PIPE_MAGIC;
64
//-----------------------------------------------------------------------------
67
IPC_DispatchMsg(ipcClient *client, const ipcMessage *msg)
72
// remember if client is expecting SYNC_REPLY. we'll add that flag to the
73
// next message sent to the client.
74
if (msg->TestFlag(IPC_MSG_FLAG_SYNC_QUERY)) {
75
PR_ASSERT(client->GetExpectsSyncReply() == PR_FALSE);
76
client->SetExpectsSyncReply(PR_TRUE);
79
if (msg->Target().Equals(IPCM_TARGET)) {
80
IPCM_HandleMsg(client, msg);
84
return IPC_DispatchMsg(client, msg->Target(), msg->Data(), msg->DataLen());
88
IPC_SendMsg(ipcClient *client, ipcMessage *msg)
96
for (int i=0; i<ipcClientCount; ++i)
97
IPC_SendMsg(&ipcClients[i], msg->Clone());
102
// add SYNC_REPLY flag to message if client is expecting...
103
if (client->GetExpectsSyncReply()) {
104
msg->SetFlag(IPC_MSG_FLAG_SYNC_REPLY);
105
client->SetExpectsSyncReply(PR_FALSE);
108
if (client->HasTarget(msg->Target()))
109
return IPC_PlatformSendMsg(client, msg);
111
LOG((" no registered message handler\n"));
115
//-----------------------------------------------------------------------------
116
// IPC daemon methods
117
//-----------------------------------------------------------------------------
120
IPC_SendMsg(ipcClient *client, const nsID &target, const void *data, PRUint32 dataLen)
122
return IPC_SendMsg(client, new ipcMessage(target, (const char *) data, dataLen));
126
IPC_GetClientByID(PRUint32 clientID)
128
// linear search OK since number of clients should be small
129
for (int i = 0; i < ipcClientCount; ++i) {
130
if (ipcClients[i].ID() == clientID)
131
return &ipcClients[i];
137
IPC_GetClientByName(const char *name)
139
// linear search OK since number of clients should be small
140
for (int i = 0; i < ipcClientCount; ++i) {
141
if (ipcClients[i].HasName(name))
142
return &ipcClients[i];
148
IPC_EnumClients(ipcClientEnumFunc func, void *closure)
151
for (int i = 0; i < ipcClientCount; ++i) {
152
if (func(closure, &ipcClients[i], ipcClients[i].ID()) == PR_FALSE)
158
IPC_GetClientID(ipcClient *client)
165
IPC_ClientHasName(ipcClient *client, const char *name)
169
return client->HasName(name);
173
IPC_ClientHasTarget(ipcClient *client, const nsID &target)
176
return client->HasTarget(target);
180
IPC_EnumClientNames(ipcClient *client, ipcClientNameEnumFunc func, void *closure)
184
const ipcStringNode *node = client->Names();
186
if (func(closure, client, node->Value()) == PR_FALSE)
193
IPC_EnumClientTargets(ipcClient *client, ipcClientTargetEnumFunc func, void *closure)
197
const ipcIDNode *node = client->Targets();
199
if (func(closure, client, node->Value()) == PR_FALSE)