diff --git a/mozilla/modules/ipc/daemon/ipcClient.cpp b/mozilla/modules/ipc/daemon/ipcClient.cpp index 1cbe3f829b2..70b01579a0f 100644 --- a/mozilla/modules/ipc/daemon/ipcClient.cpp +++ b/mozilla/modules/ipc/daemon/ipcClient.cpp @@ -38,6 +38,7 @@ #include "ipcLog.h" #include "ipcClient.h" #include "ipcMessage.h" +#include "ipcModuleReg.h" #include "ipcd.h" #include "ipcm.h" @@ -60,6 +61,9 @@ ipcClient::Init() // every client must be able to handle IPCM messages. mTargets.Append(IPCM_TARGET); + + // see ipcCommandModule for this: + //IPC_NotifyClientUp(this); } // @@ -68,6 +72,8 @@ ipcClient::Init() void ipcClient::Finalize() { + IPC_NotifyClientDown(this); + mNames.DeleteAll(); mTargets.DeleteAll(); diff --git a/mozilla/modules/ipc/daemon/ipcCommandModule.cpp b/mozilla/modules/ipc/daemon/ipcCommandModule.cpp index b5dd44778eb..bffbe9b70f6 100644 --- a/mozilla/modules/ipc/daemon/ipcCommandModule.cpp +++ b/mozilla/modules/ipc/daemon/ipcCommandModule.cpp @@ -43,6 +43,7 @@ #include "ipcClient.h" #include "ipcMessage.h" #include "ipcMessageUtils.h" +#include "ipcModuleReg.h" #include "ipcd.h" #include "ipcm.h" @@ -114,6 +115,15 @@ struct ipcCommandModule LOG(("got CLIENT_HELLO\n")); IPC_SendMsg(client, new ipcmMessageClientID(client->ID())); + + // + // NOTE: it would almost make sense for this notification to live + // in the transport layer code. however, clients expect to receive + // a CLIENT_ID as the first message following a CLIENT_HELLO, so we + // must not allow modules to see a client until after we have sent + // the CLIENT_ID message. + // + IPC_NotifyClientUp(client); } static void diff --git a/mozilla/modules/ipc/daemon/ipcModule.h b/mozilla/modules/ipc/daemon/ipcModule.h index 908549db63a..310ea9185bf 100644 --- a/mozilla/modules/ipc/daemon/ipcModule.h +++ b/mozilla/modules/ipc/daemon/ipcModule.h @@ -86,7 +86,6 @@ struct ipcModuleMethods // called when a new message arrives for this module. // // params: - // // client - an opaque "handle" to an object representing the client that // sent the message. modules should not store the value of this // beyond the duration fo this function call. (e.g., the handle @@ -101,6 +100,16 @@ struct ipcModuleMethods const nsID &target, const void *data, PRUint32 dataLen); + + // + // called when a new client connects to the IPC daemon. + // + void (* clientUp) (ipcClientHandle client); + + // + // called when a client disconnects from the IPC daemon. + // + void (* clientDown) (ipcClientHandle client); }; //----------------------------------------------------------------------------- @@ -147,10 +156,11 @@ struct ipcDaemonMethods // message to all clients. // // params: - // client - if null, then broadcast message to all clients. otherwise, - // send message to the client specified. - // XXX:FIXME - // msg - the message to send. + // client - if null, then broadcast message to all clients. otherwise, + // send message to the client specified. + // target - message target + // data - message data + // dataLen - message data length // // returns: // PR_SUCCESS if message was sent (or queued up to be sent later). @@ -186,8 +196,8 @@ struct ipcDaemonMethods PRUint32 (* getClientID) (ipcClientHandle client); // - // returns the primary client name (NULL if the client did not specify a name). - // this is the name specified by the client in its "client hello" message. + // returns the primary client name (NULL if the client did not specify a + // name). this is the first element returned via |enumClientNames|. // const char * (* getPrimaryClientName) (ipcClientHandle client); diff --git a/mozilla/modules/ipc/daemon/ipcModuleReg.cpp b/mozilla/modules/ipc/daemon/ipcModuleReg.cpp index 416a4f70cf2..1fecc45d411 100644 --- a/mozilla/modules/ipc/daemon/ipcModuleReg.cpp +++ b/mozilla/modules/ipc/daemon/ipcModuleReg.cpp @@ -200,7 +200,7 @@ IPC_ShutdownModuleReg() // for (int i = ipcModuleCount - 1; i >= 0; --i) { ipcModuleRegEntry &entry = ipcModules[i]; - if (entry.methods) + if (entry.methods->shutdown) entry.methods->shutdown(); if (entry.lib) PR_UnloadLibrary(entry.lib); @@ -208,3 +208,23 @@ IPC_ShutdownModuleReg() // memset(ipcModules, 0, sizeof(ipcModules)); ipcModuleCount = 0; } + +void +IPC_NotifyClientUp(ipcClient *client) +{ + for (int i = 0; i < ipcModuleCount; ++i) { + ipcModuleRegEntry &entry = ipcModules[i]; + if (entry.methods->clientUp) + entry.methods->clientUp(client); + } +} + +void +IPC_NotifyClientDown(ipcClient *client) +{ + for (int i = 0; i < ipcModuleCount; ++i) { + ipcModuleRegEntry &entry = ipcModules[i]; + if (entry.methods->clientDown) + entry.methods->clientDown(client); + } +} diff --git a/mozilla/modules/ipc/daemon/ipcModuleReg.h b/mozilla/modules/ipc/daemon/ipcModuleReg.h index eda26a415ec..d1d46685277 100644 --- a/mozilla/modules/ipc/daemon/ipcModuleReg.h +++ b/mozilla/modules/ipc/daemon/ipcModuleReg.h @@ -59,4 +59,10 @@ void IPC_ShutdownModuleReg(); // ipcModuleMethods *IPC_GetModuleByTarget(const nsID &target); +// +// notifies all modules of client connect/disconnect +// +void IPC_NotifyClientUp(ipcClient *); +void IPC_NotifyClientDown(ipcClient *); + #endif // !ipcModuleReg_h__ diff --git a/mozilla/modules/ipc/daemon/ipcd.h b/mozilla/modules/ipc/daemon/ipcd.h index 95f83caab84..3bcd735c90c 100644 --- a/mozilla/modules/ipc/daemon/ipcd.h +++ b/mozilla/modules/ipc/daemon/ipcd.h @@ -61,7 +61,7 @@ void IPC_EnumClientNames (ipcClientHandle client, ipcClientNameE void IPC_EnumClientTargets (ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure); //----------------------------------------------------------------------------- -// ipcMessage equivalents... +// other internal IPCD methods //----------------------------------------------------------------------------- // diff --git a/mozilla/modules/ipc/testmodule/TestModule.cpp b/mozilla/modules/ipc/testmodule/TestModule.cpp index 001b1741015..fbd788677a7 100644 --- a/mozilla/modules/ipc/testmodule/TestModule.cpp +++ b/mozilla/modules/ipc/testmodule/TestModule.cpp @@ -32,6 +32,16 @@ struct TestModule static const char buf[] = "pong"; IPC_SendMsg(client, kTestModuleID, buf, sizeof(buf)); } + + static void ClientUp(ipcClientHandle client) + { + printf("*** TestModule::ClientUp [%u]\n", IPC_GetClientID(client)); + } + + static void ClientDown(ipcClientHandle client) + { + printf("*** TestModule::ClientDown [%u]\n", IPC_GetClientID(client)); + } }; static ipcModuleMethods gTestMethods = @@ -39,7 +49,9 @@ static ipcModuleMethods gTestMethods = IPC_MODULE_METHODS_VERSION, TestModule::Init, TestModule::Shutdown, - TestModule::HandleMsg + TestModule::HandleMsg, + TestModule::ClientUp, + TestModule::ClientDown }; static ipcModuleEntry gTestModuleEntry[] =