patch for bug 242248 "IPC synchronous message support needs to be reworked" (not yet used for anything)
git-svn-id: svn://10.0.0.236/trunk@155858 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -107,7 +107,7 @@ struct ipcCommandModule
|
||||
{
|
||||
LOG(("got PING\n"));
|
||||
|
||||
IPC_SendMsg(client, new ipcmMessagePing());
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -115,7 +115,7 @@ struct ipcCommandModule
|
||||
{
|
||||
LOG(("got CLIENT_HELLO\n"));
|
||||
|
||||
IPC_SendMsg(client, new ipcmMessageClientID(client->ID()));
|
||||
IPC_SendMsg(client, new ipcmMessageClientID(IPCM_GetRequestIndex(rawMsg), client->ID()));
|
||||
|
||||
//
|
||||
// NOTE: it would almost make sense for this notification to live
|
||||
@@ -136,6 +136,9 @@ struct ipcCommandModule
|
||||
const char *name = msg->Name();
|
||||
if (name)
|
||||
client->AddName(name);
|
||||
|
||||
// TODO: send better status code (e.g., suppose name already defined for client)
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -147,6 +150,9 @@ struct ipcCommandModule
|
||||
const char *name = msg->Name();
|
||||
if (name)
|
||||
client->DelName(name);
|
||||
|
||||
// TODO: send better status code (e.g., suppose name not defined for client)
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -156,6 +162,9 @@ struct ipcCommandModule
|
||||
|
||||
ipcMessageCast<ipcmMessageClientAddTarget> msg(rawMsg);
|
||||
client->AddTarget(msg->Target());
|
||||
|
||||
// TODO: send better status code (e.g., suppose target already defined for client)
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -165,6 +174,9 @@ struct ipcCommandModule
|
||||
|
||||
ipcMessageCast<ipcmMessageClientDelTarget> msg(rawMsg);
|
||||
client->DelTarget(msg->Target());
|
||||
|
||||
// TODO: send better status code (e.g., suppose target not defined for client)
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -172,18 +184,22 @@ struct ipcCommandModule
|
||||
{
|
||||
LOG(("got QUERY_CLIENT_BY_NAME\n"));
|
||||
|
||||
PRUint32 requestIndex = IPCM_GetRequestIndex(rawMsg);
|
||||
|
||||
ipcMessageCast<ipcmMessageQueryClientByName> msg(rawMsg);
|
||||
|
||||
ipcClient *result = IPC_GetClientByName(msg->Name());
|
||||
if (result) {
|
||||
LOG((" client exists w/ ID = %u\n", result->ID()));
|
||||
IPC_SendMsg(client, new ipcmMessageClientID(result->ID()));
|
||||
IPC_SendMsg(client, new ipcmMessageClientID(requestIndex, result->ID()));
|
||||
}
|
||||
else {
|
||||
LOG((" client does not exist\n"));
|
||||
IPC_SendMsg(client, new ipcmMessageError(IPCM_ERROR_CLIENT_NOT_FOUND));
|
||||
IPC_SendMsg(client, new ipcmMessageResult(requestIndex, IPCM_ERROR_NO_CLIENT));
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
OnQueryClientInfo(ipcClient *client, const ipcMessage *rawMsg)
|
||||
{
|
||||
@@ -196,6 +212,7 @@ struct ipcCommandModule
|
||||
nsID **targets = BuildIDArray(result->Targets());
|
||||
|
||||
IPC_SendMsg(client, new ipcmMessageClientInfo(result->ID(),
|
||||
msg->RequestIndex(),
|
||||
(const char **) names,
|
||||
(const nsID **) targets));
|
||||
|
||||
@@ -204,9 +221,10 @@ struct ipcCommandModule
|
||||
}
|
||||
else {
|
||||
LOG((" client does not exist\n"));
|
||||
IPC_SendMsg(client, new ipcmMessageError(IPCM_ERROR_CLIENT_NOT_FOUND));
|
||||
IPC_SendMsg(client, new ipcmMessageError(IPCM_ERROR_CLIENT_NOT_FOUND, msg->RequestIndex()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
OnForward(ipcClient *client, const ipcMessage *rawMsg)
|
||||
@@ -215,14 +233,20 @@ struct ipcCommandModule
|
||||
|
||||
ipcMessageCast<ipcmMessageForward> msg(rawMsg);
|
||||
|
||||
ipcClient *dest = IPC_GetClientByID(msg->DestClientID());
|
||||
ipcClient *dest = IPC_GetClientByID(msg->ClientID());
|
||||
if (!dest) {
|
||||
LOG((" destination client not found!\n"));
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_ERROR_NO_CLIENT));
|
||||
return;
|
||||
}
|
||||
ipcMessage *newMsg = new ipcMessage(msg->InnerTarget(),
|
||||
msg->InnerData(),
|
||||
msg->InnerDataLen());
|
||||
// inform client that its message will be forwarded
|
||||
IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
|
||||
|
||||
ipcMessage *newMsg = new ipcmMessageForward(IPCM_MSG_PSH_FORWARD,
|
||||
client->ID(),
|
||||
msg->InnerTarget(),
|
||||
msg->InnerData(),
|
||||
msg->InnerDataLen());
|
||||
IPC_SendMsg(dest, newMsg);
|
||||
}
|
||||
};
|
||||
@@ -233,26 +257,29 @@ IPCM_HandleMsg(ipcClient *client, const ipcMessage *rawMsg)
|
||||
static ipcCommandModule::MsgHandler handlers[] =
|
||||
{
|
||||
ipcCommandModule::OnPing,
|
||||
NULL, // ERROR
|
||||
ipcCommandModule::OnForward,
|
||||
ipcCommandModule::OnClientHello,
|
||||
NULL, // CLIENT_ID
|
||||
NULL, // CLIENT_INFO
|
||||
ipcCommandModule::OnClientAddName,
|
||||
ipcCommandModule::OnClientDelName,
|
||||
ipcCommandModule::OnClientAddTarget,
|
||||
ipcCommandModule::OnClientDelTarget,
|
||||
ipcCommandModule::OnQueryClientByName,
|
||||
ipcCommandModule::OnQueryClientInfo,
|
||||
ipcCommandModule::OnForward,
|
||||
ipcCommandModule::OnQueryClientByName
|
||||
};
|
||||
|
||||
int type = IPCM_GetMsgType(rawMsg);
|
||||
LOG(("IPCM_HandleMsg [type=%d]\n", type));
|
||||
int type = IPCM_GetType(rawMsg);
|
||||
LOG(("IPCM_HandleMsg [type=%x]\n", type));
|
||||
|
||||
if (type < IPCM_MSG_TYPE_UNKNOWN) {
|
||||
if (handlers[type]) {
|
||||
ipcCommandModule::MsgHandler handler = handlers[type];
|
||||
handler(client, rawMsg);
|
||||
}
|
||||
if (!(type & IPCM_MSG_CLASS_REQ)) {
|
||||
LOG(("not a request -- ignoring message\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
type &= ~IPCM_MSG_CLASS_REQ;
|
||||
type--;
|
||||
if (type < 0 || type >= (int) (sizeof(handlers)/sizeof(handlers[0]))) {
|
||||
LOG(("unknown request -- ignoring message\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
(handlers[type])(client, rawMsg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user