added ipcModuleUtil.h to simplify using the new plug-in API
git-svn-id: svn://10.0.0.236/trunk@133267 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
c680f43b1c
commit
2acc29c026
@ -63,6 +63,7 @@ PROGRAM = mozipcd$(BIN_SUFFIX)
|
||||
|
||||
EXPORTS = \
|
||||
ipcModule.h \
|
||||
ipcModuleUtil.h \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
@ -77,20 +78,4 @@ LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)ipccom_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
# XXX -rdynamic is probably good for lots of other platforms
|
||||
#ifeq ($(OS_ARCH),Linux)
|
||||
#LIBS += -rdynamic
|
||||
#endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
#DEFINES += -DIPC_DAEMON
|
||||
#
|
||||
#ifeq ($(OS_ARCH),WINNT)
|
||||
#
|
||||
# need to install mozipcd.lib, which contains the symbols exported by the
|
||||
# daemon that modules will need to import.
|
||||
#
|
||||
#libs:: $(PROGRAM)
|
||||
# $(INSTALL) mozipcd.lib $(DIST)/lib
|
||||
#endif
|
||||
|
||||
@ -135,7 +135,13 @@ struct ipcCommandModule
|
||||
newMsg->Init(msg->InnerTarget(),
|
||||
msg->InnerData(),
|
||||
msg->InnerDataLen());
|
||||
IPC_SendMsg(destID, newMsg);
|
||||
|
||||
ipcClient *dest = IPC_GetClientByID(destID);
|
||||
if (!dest) {
|
||||
LOG((" destination client not found!\n"));
|
||||
return;
|
||||
}
|
||||
IPC_SendMsg(dest, newMsg);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
116
mozilla/modules/ipc/daemon/ipcModuleUtil.h
Normal file
116
mozilla/modules/ipc/daemon/ipcModuleUtil.h
Normal file
@ -0,0 +1,116 @@
|
||||
#ifndef ipcModuleUtil_h__
|
||||
#define ipcModuleUtil_h__
|
||||
|
||||
#include "prlog.h"
|
||||
#include "ipcModule.h"
|
||||
|
||||
extern ipcDaemonMethods *gIPCDaemonMethods;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// inline wrapper functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline PRStatus
|
||||
IPC_DispatchMsg(ipcClientHandle client, const ipcMessage *msg)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->dispatchMsg(client, msg);
|
||||
}
|
||||
|
||||
inline PRStatus
|
||||
IPC_SendMsg(ipcClientHandle client, const ipcMessage *msg)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->sendMsg(client, msg);
|
||||
}
|
||||
|
||||
inline ipcClientHandle
|
||||
IPC_GetClientByID(PRUint32 id)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->getClientByID(id);
|
||||
}
|
||||
|
||||
inline ipcClientHandle
|
||||
IPC_GetClientByName(const char *name)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->getClientByName(name);
|
||||
}
|
||||
|
||||
inline void
|
||||
IPC_EnumClients(ipcClientEnumFunc func, void *closure)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->enumClients(func, closure);
|
||||
}
|
||||
|
||||
inline PRUint32
|
||||
IPC_GetClientID(ipcClientHandle client)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->getClientID(client);
|
||||
}
|
||||
|
||||
inline const char *
|
||||
IPC_GetPrimaryClientName(ipcClientHandle client)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->getPrimaryClientName(client);
|
||||
}
|
||||
|
||||
inline PRBool
|
||||
IPC_ClientHasName(ipcClientHandle client, const char *name)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->clientHasName(client, name);
|
||||
}
|
||||
|
||||
inline PRBool
|
||||
IPC_ClientHasTarget(ipcClientHandle client, const nsID &target)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->clientHasTarget(client, target);
|
||||
}
|
||||
|
||||
inline void
|
||||
IPC_EnumClientNames(ipcClientHandle client, ipcClientNameEnumFunc func, void *closure)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->enumClientNames(client, func, closure);
|
||||
}
|
||||
|
||||
inline void
|
||||
IPC_EnumClientTargets(ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure)
|
||||
{
|
||||
PR_ASSERT(gIPCDaemonMethods);
|
||||
return gIPCDaemonMethods->enumClientTargets(client, func, closure);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// inline composite functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline PRStatus
|
||||
IPC_SendMsg(PRUint32 clientID, ipcMessage *msg)
|
||||
{
|
||||
ipcClient *client = IPC_GetClientByID(clientID);
|
||||
if (!client)
|
||||
return PR_FAILURE;
|
||||
return IPC_SendMsg(client, msg);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// module factory macros
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define IPC_IMPL_GETMODULES(_modName, _modEntries) \
|
||||
ipcDaemonMethods *gIPCDaemonMethods; \
|
||||
IPC_EXPORT int IPC_GetModules(ipcDaemonMethods *, ipcModuleEntry **); \
|
||||
int IPC_GetModules(ipcDaemonMethods *dmeths, ipcModuleEntry **ents) { \
|
||||
gIPCDaemonMethods = dmeths; \
|
||||
*ents = _modEntries; \
|
||||
return sizeof(_modEntries) / sizeof(ipcModuleEntry); \
|
||||
}
|
||||
|
||||
#endif // !ipcModuleUtil_h__
|
||||
@ -64,6 +64,8 @@ IPC_DispatchMsg(ipcClient *client, const ipcMessage *msg)
|
||||
PRStatus
|
||||
IPC_SendMsg(ipcClient *client, const ipcMessage *msg)
|
||||
{
|
||||
LOG(("IPC_SendMsg [clientID=%u]\n", client->ID()));
|
||||
|
||||
if (client == NULL) {
|
||||
//
|
||||
// broadcast
|
||||
@ -75,7 +77,7 @@ IPC_SendMsg(ipcClient *client, const ipcMessage *msg)
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
if (!client->HasTarget(msg->Target())) {
|
||||
LOG(("no registered message handler\n"));
|
||||
LOG((" no registered message handler\n"));
|
||||
return PR_FAILURE;
|
||||
}
|
||||
return IPC_PlatformSendMsg(client, msg);
|
||||
|
||||
@ -59,20 +59,4 @@ PRBool IPC_ClientHasTarget (ipcClientHandle client, const nsID &ta
|
||||
void IPC_EnumClientNames (ipcClientHandle client, ipcClientNameEnumFunc func, void *closure);
|
||||
void IPC_EnumClientTargets (ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// inline helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static inline PRStatus
|
||||
IPC_SendMsg(PRUint32 clientID, ipcMessage *msg)
|
||||
{
|
||||
PRStatus rv;
|
||||
ipcClient *client = IPC_GetClientByID(clientID);
|
||||
if (client)
|
||||
rv = IPC_SendMsg(client, msg);
|
||||
else
|
||||
rv = PR_FAILURE;
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif // !IPCD_H__
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include "ipcModule.h"
|
||||
#include "ipcModuleUtil.h"
|
||||
#include "ipcMessage.h"
|
||||
|
||||
IPC_EXPORT int IPC_GetModules(ipcDaemonMethods *, ipcModuleEntry **);
|
||||
|
||||
static const nsID TestModuleID =
|
||||
{ /* e628fc6e-a6a7-48c7-adba-f241d1128fb8 */
|
||||
0xe628fc6e,
|
||||
@ -12,8 +10,6 @@ static const nsID TestModuleID =
|
||||
{0xad, 0xba, 0xf2, 0x41, 0xd1, 0x12, 0x8f, 0xb8}
|
||||
};
|
||||
|
||||
static ipcDaemonMethods *gDaemonMethods;
|
||||
|
||||
struct TestModule
|
||||
{
|
||||
static void Shutdown()
|
||||
@ -27,29 +23,20 @@ struct TestModule
|
||||
ipcMessage outMsg;
|
||||
static const char buf[] = "pong";
|
||||
outMsg.Init(TestModuleID, buf, sizeof(buf));
|
||||
gDaemonMethods->sendMsg(client, &outMsg);
|
||||
IPC_SendMsg(client, &outMsg);
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
IPC_GetModules(ipcDaemonMethods *daemonMeths, ipcModuleEntry **entries)
|
||||
static ipcModuleMethods gTestMethods =
|
||||
{
|
||||
printf("*** testmodule: IPC_GetModules\n");
|
||||
IPC_MODULE_METHODS_VERSION,
|
||||
TestModule::Shutdown,
|
||||
TestModule::HandleMsg
|
||||
};
|
||||
|
||||
static ipcModuleMethods methods =
|
||||
{
|
||||
IPC_MODULE_METHODS_VERSION,
|
||||
TestModule::Shutdown,
|
||||
TestModule::HandleMsg
|
||||
};
|
||||
static ipcModuleEntry moduleEntry =
|
||||
{
|
||||
TestModuleID,
|
||||
&methods
|
||||
};
|
||||
static ipcModuleEntry gTestModuleEntry[] =
|
||||
{
|
||||
{ TestModuleID, &gTestMethods }
|
||||
};
|
||||
|
||||
gDaemonMethods = daemonMeths;
|
||||
|
||||
*entries = &moduleEntry;
|
||||
return 1;
|
||||
}
|
||||
IPC_IMPL_GETMODULES(TestModule, gTestModuleEntry)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user