mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
1) add clientUp and clientDown ipc module notifications
2) cleanup some comments in ipcModule.h
This commit is contained in:
parent
920fe572b1
commit
2ecabcccc4
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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__
|
||||
|
@ -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
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
|
@ -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[] =
|
||||
|
Loading…
Reference in New Issue
Block a user