further revisions following review w/ dougt

This commit is contained in:
darin%netscape.com 2002-11-21 07:57:09 +00:00
Родитель c26e0f935a
Коммит 62a475fcce
9 изменённых файлов: 13 добавлений и 1303 удалений

Просмотреть файл

@ -1,77 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef ipcProto_h__
#define ipcProto_h__
#if defined(XP_WIN)
//
// use WM_COPYDATA messages
//
#include "prprf.h"
#define IPC_WINDOW_CLASS "Mozilla:IPCWindowClass"
#define IPC_WINDOW_NAME "Mozilla:IPCWindow"
#define IPC_CLIENT_WINDOW_CLASS "Mozilla:IPCAppWindowClass"
#define IPC_CLIENT_WINDOW_NAME_PREFIX "Mozilla:IPCAppWindow:"
#define IPC_SYNC_EVENT_NAME "Local\\MozillaIPCSyncEvent"
#define IPC_DAEMON_APP_NAME "mozipcd.exe"
#define IPC_PATH_SEP_CHAR '\\'
#define IPC_CLIENT_WINDOW_NAME_MAXLEN (sizeof(IPC_CLIENT_WINDOW_NAME_PREFIX) + 20)
// writes client name into buf. buf must be at least
// IPC_CLIENT_WINDOW_NAME_MAXLEN bytes in length.
inline void IPC_GetClientWindowName(PRUint32 pid, char *buf)
{
PR_snprintf(buf, IPC_CLIENT_WINDOW_NAME_MAXLEN, "%s%u",
IPC_CLIENT_WINDOW_NAME_PREFIX, pid);
}
#else
//
// use UNIX domain socket
//
#define IPC_PORT 0
#define IPC_SOCKET_TYPE "ipc"
#define IPC_DEFAULT_SOCKET_PATH "/tmp/.mozilla-ipc/ipcd"
#define IPC_DAEMON_APP_NAME "mozipcd"
#define IPC_PATH_SEP_CHAR '/'
#endif
#endif // !ipcProto_h__

Просмотреть файл

@ -1,236 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "ipcLog.h"
#include "ipcClient.h"
#include "ipcMessage.h"
#include "ipcModuleReg.h"
#include "ipcd.h"
#include "ipcm.h"
#ifdef XP_UNIX
#include "prio.h"
#endif
PRUint32 ipcClient::gLastID = 0;
//
// called to initialize this client context
//
// assumptions:
// - object's memory has already been zero'd out.
//
void
ipcClient::Init()
{
mID = ++gLastID;
// every client must be able to handle IPCM messages.
mTargets.Append(IPCM_TARGET);
// XXX cleanup
// see ipcCommandModule for this:
//IPC_NotifyClientUp(this);
}
//
// called when this client context is going away
//
void
ipcClient::Finalize()
{
IPC_NotifyClientDown(this);
mNames.DeleteAll();
mTargets.DeleteAll();
#ifdef XP_UNIX
mInMsg.Reset();
mOutMsgQ.DeleteAll();
#endif
}
void
ipcClient::AddName(const char *name)
{
LOG(("adding client name: %s\n", name));
if (HasName(name))
return;
mNames.Append(name);
}
void
ipcClient::DelName(const char *name)
{
LOG(("deleting client name: %s\n", name));
mNames.FindAndDelete(name);
}
void
ipcClient::AddTarget(const nsID &target)
{
LOG(("adding client target\n"));
if (HasTarget(target))
return;
mTargets.Append(target);
}
void
ipcClient::DelTarget(const nsID &target)
{
LOG(("deleting client target\n"));
//
// cannot remove the IPCM target
//
if (!target.Equals(IPCM_TARGET))
mTargets.FindAndDelete(target);
}
#ifdef XP_UNIX
//
// called to process a client socket
//
// params:
// fd - the client socket
// poll_flags - the state of the client socket
//
// return:
// 0 - to end session with this client
// PR_POLL_READ - to wait for the client socket to become readable
// PR_POLL_WRITE - to wait for the client socket to become writable
//
int
ipcClient::Process(PRFileDesc *fd, int poll_flags)
{
// XXX check if not read OR write
if ((poll_flags & PR_POLL_ERR) ||
(poll_flags & PR_POLL_HUP) ||
(poll_flags & PR_POLL_EXCEPT) ||
(poll_flags & PR_POLL_NVAL)) {
//
// expect Finalize method to be called next.
//
LOG(("client socket appears to have closed\n"));
return 0;
}
// always wait for more data
int ret_flags = PR_POLL_READ;
if (poll_flags & PR_POLL_READ) {
LOG(("client socket is now readable\n"));
char buf[1024]; // XXX 4k?
PRInt32 n;
// find out how much data is available for reading...
// n = PR_Available(fd);
n = PR_Read(fd, buf, sizeof(buf));
if (n <= 0)
return 0; // cancel connection
const char *ptr = buf;
while (n) {
PRUint32 nread;
PRBool complete;
// XXX check return value
mInMsg.ReadFrom(ptr, PRUint32(n), &nread, &complete);
if (complete) {
IPC_DispatchMsg(this, &mInMsg);
mInMsg.Reset();
}
n -= nread;
ptr += nread;
}
}
if (poll_flags & PR_POLL_WRITE) {
LOG(("client socket is now writable\n"));
if (mOutMsgQ.First())
WriteMsgs(fd);
}
if (mOutMsgQ.First())
ret_flags |= PR_POLL_WRITE;
return ret_flags;
}
//
// called to write out any messages from the outgoing queue.
//
int
ipcClient::WriteMsgs(PRFileDesc *fd)
{
while (mOutMsgQ.First()) {
const char *buf = (const char *) mOutMsgQ.First()->MsgBuf();
PRInt32 bufLen = (PRInt32) mOutMsgQ.First()->MsgLen();
if (mSendOffset) {
buf += mSendOffset;
bufLen -= mSendOffset;
}
PRInt32 nw = PR_Write(fd, buf, bufLen);
if (nw <= 0)
break;
LOG(("wrote %d bytes\n", nw));
if (nw == bufLen)
mOutMsgQ.DeleteFirst();
// XXX mSendOffset = 0;
else
mSendOffset += nw;
}
return 0;
}
#endif

Просмотреть файл

@ -1,244 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef ipcModule_h__
#define ipcModule_h__
#include "nsID.h"
// XXX cruft
#define IPC_EXPORT extern "C" NS_EXPORT
class ipcMessage;
//
// a client handle is used to efficiently reference a client instance object
// used by the daemon to represent a connection with a particular client app.
//
// modules should treat it as an opaque type.
//
typedef class ipcClient *ipcClientHandle;
//-----------------------------------------------------------------------------
// interface implemented by the module:
//-----------------------------------------------------------------------------
//
// the version of ipcModuleMethods data structure.
//
#define IPC_MODULE_METHODS_VERSION (1<<16) // 1.0
//
// each module defines the following structure:
//
struct ipcModuleMethods
{
//
// this field holds the version of the data structure, which is always the
// value of IPC_MODULE_METHODS_VERSION against which the module was built.
//
PRUint32 version;
//
// called after this module is registered.
//
void (* init) (void);
//
// called when this module will no longer be accessed.
//
void (* shutdown) (void);
//
// 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
// may be invalid after this function call returns.) modules
// wishing to hold onto a reference to a "client" should store
// the client's ID (see IPC_GetClientID).
// target - message target
// data - message data
// dataLen - message data length
//
void (* handleMsg) (ipcClientHandle client,
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);
};
//-----------------------------------------------------------------------------
// interface implemented by the daemon:
//-----------------------------------------------------------------------------
//
// the version of ipcDaemonMethods data structure.
//
#define IPC_DAEMON_METHODS_VERSION (1<<16) // 1.0
typedef PRBool (* ipcClientEnumFunc) (void *closure, ipcClientHandle client, PRUint32 clientID);
typedef PRBool (* ipcClientNameEnumFunc) (void *closure, ipcClientHandle client, const char *name);
typedef PRBool (* ipcClientTargetEnumFunc) (void *closure, ipcClientHandle client, const nsID &target);
//
// the daemon provides the following structure:
//
struct ipcDaemonMethods
{
PRUint32 version;
//
// called to send a message to another module.
//
// params:
// client - identifies the client from which this message originated.
// target - message target
// data - message data
// dataLen - message data length
//
// returns:
// PR_SUCCESS if message was dispatched.
// PR_FAILURE if message could not be dispatched (possibly because
// no module is registered for the given message target).
//
PRStatus (* dispatchMsg) (ipcClientHandle client,
const nsID &target,
const void *data,
PRUint32 dataLen);
//
// called to send a message to a particular client or to broadcast a
// message to all clients.
//
// params:
// 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).
// PR_FAILURE if message could not be sent (possibly because the client
// does not have a registered observer for the msg's target).
//
PRStatus (* sendMsg) (ipcClientHandle client,
const nsID &target,
const void *data,
PRUint32 dataLen);
//
// called to lookup a client handle given its client ID. each client has
// a unique ID.
//
ipcClientHandle (* getClientByID) (PRUint32 clientID);
//
// called to lookup a client by name or alias. names are not necessary
// unique to individual clients. this function returns the client first
// registered under the given name.
//
ipcClientHandle (* getClientByName) (const char *name);
//
// called to enumerate all clients.
//
void (* enumClients) (ipcClientEnumFunc func, void *closure);
//
// returns the client ID of the specified client.
//
PRUint32 (* getClientID) (ipcClientHandle client);
//
// 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);
//
// functions for inspecting the names and targets defined for a particular
// client instance.
//
PRBool (* clientHasName) (ipcClientHandle client, const char *name);
PRBool (* clientHasTarget) (ipcClientHandle client, const nsID &target);
void (* enumClientNames) (ipcClientHandle client, ipcClientNameEnumFunc func, void *closure);
void (* enumClientTargets) (ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure);
};
//-----------------------------------------------------------------------------
// interface exported by a DSO implementing one or more modules:
//-----------------------------------------------------------------------------
struct ipcModuleEntry
{
//
// identifies the message target of this module.
//
nsID target;
//
// module methods
//
ipcModuleMethods *methods;
};
//
// IPC_EXPORT int IPC_GetModules(const ipcDaemonMethods *, const ipcModuleEntry **);
//
// params:
// methods - the daemon's methods
// entries - the module entries defined by the DSO
//
// returns:
// length of the |entries| array.
//
typedef int (* ipcGetModulesFunc) (const ipcDaemonMethods *methods, const ipcModuleEntry **entries);
#endif // !ipcModule_h__

Просмотреть файл

@ -1,247 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <string.h>
#include <stdlib.h>
#include "prlink.h"
#include "prio.h"
#include "prlog.h"
#include "plstr.h"
#include "ipcConfig.h"
#include "ipcLog.h"
#include "ipcModuleReg.h"
#include "ipcModule.h"
#include "ipcCommandModule.h"
#include "ipcd.h"
//-----------------------------------------------------------------------------
struct ipcModuleRegEntry
{
nsID target;
ipcModuleMethods *methods;
PRLibrary *lib;
};
#define IPC_MAX_MODULE_COUNT 64
static ipcModuleRegEntry ipcModules[IPC_MAX_MODULE_COUNT];
static int ipcModuleCount = 0;
//-----------------------------------------------------------------------------
static PRStatus
AddModule(const nsID &target, ipcModuleMethods *methods, const char *libPath)
{
if (ipcModuleCount == IPC_MAX_MODULE_COUNT) {
LOG(("too many modules!\n"));
return PR_FAILURE;
}
if (!methods) {
PR_NOT_REACHED("null module methods");
return PR_FAILURE;
}
//
// each ipcModuleRegEntry holds a reference to a PRLibrary, and on
// shutdown, each PRLibrary reference will be released. this ensures
// that the library will not be unloaded until all of the modules in
// that library are shutdown.
//
ipcModules[ipcModuleCount].target = target;
ipcModules[ipcModuleCount].methods = methods;
ipcModules[ipcModuleCount].lib = PR_LoadLibrary(libPath);
++ipcModuleCount;
return PR_SUCCESS;
}
static void
InitModuleFromLib(const char *modulesDir, const char *fileName)
{
LOG(("InitModuleFromLib [%s]\n", fileName));
static const ipcDaemonMethods gDaemonMethods =
{
IPC_DAEMON_METHODS_VERSION,
IPC_DispatchMsg,
IPC_SendMsg,
IPC_GetClientByID,
IPC_GetClientByName,
IPC_EnumClients,
IPC_GetClientID,
IPC_GetPrimaryClientName,
IPC_ClientHasName,
IPC_ClientHasTarget,
IPC_EnumClientNames,
IPC_EnumClientTargets
};
int dLen = strlen(modulesDir);
int fLen = strlen(fileName);
char *buf = (char *) malloc(dLen + 1 + fLen + 1);
memcpy(buf, modulesDir, dLen);
buf[dLen] = IPC_PATH_SEP_CHAR;
memcpy(buf + dLen + 1, fileName, fLen);
buf[dLen + 1 + fLen] = '\0';
PRLibrary *lib = PR_LoadLibrary(buf);
if (lib) {
ipcGetModulesFunc func =
(ipcGetModulesFunc) PR_FindFunctionSymbol(lib, "IPC_GetModules");
LOG((" func=%p\n", (void*) func));
if (func) {
const ipcModuleEntry *entries = NULL;
int count = func(&gDaemonMethods, &entries);
for (int i=0; i<count; ++i) {
if (AddModule(entries[i].target, entries[i].methods, buf)) {
if (entries[i].methods->init)
entries[i].methods->init();
}
}
}
PR_UnloadLibrary(lib);
}
free(buf);
}
//-----------------------------------------------------------------------------
// ipcModuleReg API
//-----------------------------------------------------------------------------
//
// search for a module registered under the specified id
//
ipcModuleMethods *
IPC_GetModuleByTarget(const nsID &target)
{
for (int i=0; i<ipcModuleCount; ++i) {
ipcModuleRegEntry &entry = ipcModules[i];
if (entry.target.Equals(target))
return entry.methods;
}
return NULL;
}
void
IPC_InitModuleReg(const char *exePath)
{
if (!(exePath && *exePath))
return;
//
// register plug-in modules
//
static const char relModDir[] = "ipc/modules"; // XXX fix slashes
char *p = PL_strrchr(exePath, IPC_PATH_SEP_CHAR);
if (p == NULL) {
LOG(("unexpected exe path\n"));
return;
}
int baseLen = p - exePath;
int finalLen = baseLen + 1 + sizeof(relModDir);
// build full path to ipc modules
char *modulesDir = (char*) malloc(finalLen);
memcpy(modulesDir, exePath, baseLen);
modulesDir[baseLen] = IPC_PATH_SEP_CHAR;
memcpy(modulesDir + baseLen + 1, relModDir, sizeof(relModDir));
LOG(("loading libraries in %s\n", modulesDir));
//
// scan directory for IPC modules
//
PRDir *dir = PR_OpenDir(modulesDir);
if (dir) {
PRDirEntry *ent;
while ((ent = PR_ReadDir(dir, PR_SKIP_BOTH)) != NULL) {
//
// locate extension, and check if dynamic library
//
char *p = strrchr(ent->name, '.');
if (p && PL_strcasecmp(p, MOZ_DLL_SUFFIX) == 0)
InitModuleFromLib(modulesDir, ent->name);
}
PR_CloseDir(dir);
}
free(modulesDir);
}
void
IPC_ShutdownModuleReg()
{
//
// shutdown modules in reverse order
//
while (ipcModuleCount) {
ipcModuleRegEntry &entry = ipcModules[--ipcModuleCount];
if (entry.methods->shutdown)
entry.methods->shutdown();
if (entry.lib)
PR_UnloadLibrary(entry.lib);
}
}
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);
}
}

Просмотреть файл

@ -1,72 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef ipcModuleReg_h__
#define ipcModuleReg_h__
#include "ipcModule.h"
//
// called to init the module registry. this may only be called once at
// startup or once after calling IPC_ShutdownModuleReg.
//
// params:
// exePath - path to the daemon executable. modules are loaded from a
// directory relative to the daemon executable.
//
void IPC_InitModuleReg(const char *exePath);
//
// called to shutdown the module registry. this may be called more than
// once and need not follow a call to IPC_InitModuleReg.
//
void IPC_ShutdownModuleReg();
//
// returns the ipcModuleMethods for the given target.
//
ipcModuleMethods *IPC_GetModuleByTarget(const nsID &target);
// XXX "handle msg for target" instead
//
// notifies all modules of client connect/disconnect
//
void IPC_NotifyClientUp(ipcClient *);
void IPC_NotifyClientDown(ipcClient *);
#endif // !ipcModuleReg_h__

Просмотреть файл

@ -1,156 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef ipcModuleUtil_h__
#define ipcModuleUtil_h__
#include "prlog.h"
#include "ipcModule.h"
extern const ipcDaemonMethods *gIPCDaemonMethods;
//-----------------------------------------------------------------------------
// inline wrapper functions
//
// XXX only usable inside module.. blah
//-----------------------------------------------------------------------------
inline PRStatus
IPC_DispatchMsg(ipcClientHandle client, const nsID &target, const void *data, PRUint32 dataLen)
{
PR_ASSERT(gIPCDaemonMethods);
return gIPCDaemonMethods->dispatchMsg(client, target, data, dataLen);
}
inline PRStatus
IPC_SendMsg(ipcClientHandle client, const nsID &target, const void *data, PRUint32 dataLen)
{
PR_ASSERT(gIPCDaemonMethods);
return gIPCDaemonMethods->sendMsg(client, target, data, dataLen);
}
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);
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);
gIPCDaemonMethods->enumClientNames(client, func, closure);
}
inline void
IPC_EnumClientTargets(ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure)
{
PR_ASSERT(gIPCDaemonMethods);
gIPCDaemonMethods->enumClientTargets(client, func, closure);
}
//-----------------------------------------------------------------------------
// inline composite functions
//-----------------------------------------------------------------------------
inline PRStatus
IPC_SendMsg(PRUint32 clientID, const nsID &target, const void *data, PRUint32 dataLen)
{
ipcClient *client = IPC_GetClientByID(clientID);
if (!client)
return PR_FAILURE;
return IPC_SendMsg(client, target, data, dataLen);
}
//-----------------------------------------------------------------------------
// module factory macros
//-----------------------------------------------------------------------------
#define IPC_IMPL_GETMODULES(_modName, _modEntries) \
const ipcDaemonMethods *gIPCDaemonMethods; \
IPC_EXPORT int \
IPC_GetModules(const ipcDaemonMethods *dmeths, const ipcModuleEntry **ents) { \
/* XXX do version checking */ \
gIPCDaemonMethods = dmeths; \
*ents = _modEntries; \
return sizeof(_modEntries) / sizeof(ipcModuleEntry); \
}
#endif // !ipcModuleUtil_h__

Просмотреть файл

@ -1,194 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "ipcConfig.h"
#include "ipcLog.h"
#include "ipcMessage.h"
#include "ipcClient.h"
#include "ipcModuleReg.h"
#include "ipcModule.h"
#include "ipcCommandModule.h"
#include "ipcdPrivate.h"
#include "ipcd.h"
PRStatus
IPC_DispatchMsg(ipcClient *client, const ipcMessage *msg)
{
// XXX assert args valid
//
if (msg->Target().Equals(IPCM_TARGET)) {
IPCM_HandleMsg(client, msg);
return PR_SUCCESS;
}
return IPC_DispatchMsg(client, msg->Target(), msg->Data(), msg->DataLen());
}
PRStatus
IPC_SendMsg(ipcClient *client, ipcMessage *msg)
{
if (client == NULL) {
//
// broadcast
//
for (int i=0; i<ipcClientCount; ++i)
IPC_SendMsg(&ipcClients[i], msg->Clone());
delete msg;
return PR_SUCCESS;
}
if (client->HasTarget(msg->Target()))
return IPC_PlatformSendMsg(client, msg);
LOG((" no registered message handler\n"));
return PR_FAILURE;
}
//-----------------------------------------------------------------------------
// IPC daemon methods
//-----------------------------------------------------------------------------
PRStatus
IPC_DispatchMsg(ipcClient *client, const nsID &target, const void *data, PRUint32 dataLen)
{
// lookup handler for this message's topic and forward message to it.
// XXX methods should be |const|
ipcModuleMethods *methods = IPC_GetModuleByTarget(target);
if (methods) {
// XXX make sure handleMsg not null
methods->handleMsg(client, target, data, dataLen);
return PR_SUCCESS;
}
LOG(("no registered module; ignoring message\n"));
return PR_FAILURE;
}
PRStatus
IPC_SendMsg(ipcClient *client, const nsID &target, const void *data, PRUint32 dataLen)
{
return IPC_SendMsg(client, new ipcMessage(target, (const char *) data, dataLen));
}
ipcClient *
IPC_GetClientByID(PRUint32 clientID)
{
// linear search OK since number of clients should be small
for (int i = 0; i < ipcClientCount; ++i) {
if (ipcClients[i].ID() == clientID)
return &ipcClients[i];
}
return NULL;
}
ipcClient *
IPC_GetClientByName(const char *name)
{
// linear search OK since number of clients should be small
for (int i = 0; i < ipcClientCount; ++i) {
if (ipcClients[i].HasName(name))
return &ipcClients[i];
}
return NULL;
}
void
IPC_EnumClients(ipcClientEnumFunc func, void *closure)
{
// XXX null check
// XXX check return val for STOP
for (int i = 0; i < ipcClientCount; ++i)
func(closure, &ipcClients[i], ipcClients[i].ID());
}
PRUint32
IPC_GetClientID(ipcClient *client)
{
// XXX null check
return client->ID();
}
const char *
IPC_GetPrimaryClientName(ipcClient *client)
{
// XXX null check
// XXX eliminate
return client->PrimaryName();
}
PRBool
IPC_ClientHasName(ipcClient *client, const char *name)
{
// XXX null check
return client->HasName(name);
}
PRBool
IPC_ClientHasTarget(ipcClient *client, const nsID &target)
{
// XXX null check
return client->HasTarget(target);
}
void
IPC_EnumClientNames(ipcClient *client, ipcClientNameEnumFunc func, void *closure)
{
const ipcStringNode *node = client->Names();
while (node) {
if (func(closure, client, node->Value()) == PR_FALSE)
break;
node = node->mNext;
}
}
void
IPC_EnumClientTargets(ipcClient *client, ipcClientTargetEnumFunc func, void *closure)
{
const ipcIDNode *node = client->Targets();
while (node) {
if (func(closure, client, node->Value()) == PR_FALSE)
break;
node = node->mNext;
}
}
// XXX remove
ipcClient *
IPC_GetClients(PRUint32 *count)
{
*count = (PRUint32) ipcClientCount;
return ipcClients;
}

Просмотреть файл

@ -1,77 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla IPC.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef IPCD_H__
#define IPCD_H__
#include "ipcModule.h"
#include "ipcMessage.h"
//-----------------------------------------------------------------------------
// IPC daemon methods (see struct ipcDaemonMethods)
//
// these functions may only be called directly from within the daemon. plug-in
// modules must access these through the ipcDaemonMethods structure.
//-----------------------------------------------------------------------------
PRStatus IPC_DispatchMsg (ipcClientHandle client, const nsID &target, const void *data, PRUint32 dataLen);
PRStatus IPC_SendMsg (ipcClientHandle client, const nsID &target, const void *data, PRUint32 dataLen);
ipcClientHandle IPC_GetClientByID (PRUint32 id);
ipcClientHandle IPC_GetClientByName (const char *name);
void IPC_EnumClients (ipcClientEnumFunc func, void *closure);
PRUint32 IPC_GetClientID (ipcClientHandle client);
const char *IPC_GetPrimaryClientName (ipcClientHandle client);
PRBool IPC_ClientHasName (ipcClientHandle client, const char *name);
PRBool IPC_ClientHasTarget (ipcClientHandle client, const nsID &target);
void IPC_EnumClientNames (ipcClientHandle client, ipcClientNameEnumFunc func, void *closure);
void IPC_EnumClientTargets (ipcClientHandle client, ipcClientTargetEnumFunc func, void *closure);
//-----------------------------------------------------------------------------
// other internal IPCD methods
//-----------------------------------------------------------------------------
//
// dispatch message
//
PRStatus IPC_DispatchMsg(ipcClientHandle client, const ipcMessage *msg);
//
// send message, takes ownership of |msg|.
//
PRStatus IPC_SendMsg(ipcClientHandle client, ipcMessage *msg);
#endif // !IPCD_H__

Просмотреть файл

@ -59,6 +59,17 @@
#include "ipcdPrivate.h"
#include "ipcd.h"
void
IPC_Sleep(int seconds)
{
while (seconds > 0) {
LOG(("\rsleeping for %d seconds...", seconds));
PR_Sleep(PR_SecondsToInterval(1));
--seconds;
}
LOG(("\ndone sleeping\n"));
}
//-----------------------------------------------------------------------------
// ipc directory and locking...
//-----------------------------------------------------------------------------
@ -413,6 +424,8 @@ int main(int argc, char **argv)
end:
IPC_ShutdownModuleReg();
//IPC_Sleep(5);
// it is critical that we release the lock before closing the socket,
// otherwise, a client might launch another daemon that would be unable
// to acquire the lock and would then leave the client without a daemon.