factored out unix (file descriptor based) implementation to make way for

a windows WM_COPYDATA based implementation.
This commit is contained in:
darin@netscape.com
2002-11-06 01:11:07 +00:00
parent 461261d2af
commit ead7c21f87
17 changed files with 711 additions and 570 deletions

View File

@@ -35,43 +35,39 @@
*
* ***** END LICENSE BLOCK ***** */
#include <stdio.h>
#include "prio.h"
#include "plstr.h"
#include "ipcLog.h"
#include "ipcClient.h"
#include "ipcMessage.h"
#include "ipcd.h"
#include "ipcm.h"
int ipcClient::gLastID = 0;
#ifdef XP_UNIX
#include "prio.h"
#include "ipcdUnix.h"
#endif
PRUint32 ipcClient::gLastID = 0;
//
// called to initialize this client context
//
// return:
// PR_POLL_READ - to wait for the client socket to become readable
// PR_POLL_WRITE - to wait for the client socket to become writable
// assumptions:
// - object's memory has already been zero'd out.
//
int
void
ipcClient::Init()
{
mID = ++gLastID;
mInMsg = new ipcMessage();
mSendOffset = 0;
// every client must be able to handle IPCM messages.
mTargets.Append(IPCM_TARGET);
// wait for the client to send us a command
return PR_POLL_READ;
}
//
// called when this client context is going away
//
int
void
ipcClient::Finalize()
{
if (mInMsg)
@@ -79,9 +75,76 @@ ipcClient::Finalize()
mOutMsgQ.DeleteAll();
mNames.DeleteAll();
mTargets.DeleteAll();
return 0;
}
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);
}
PRBool
ipcClient::EnqueueOutboundMsg(ipcMessage *msg)
{
LOG(("enqueue outbound message\n"));
if (!HasTarget(msg->Target())) {
LOG((" no registered message handler\n"));
delete msg;
return PR_FALSE;
}
mOutMsgQ.Append(msg);
#ifdef XP_UNIX
//
// the message was successfully put on the queue...
//
// since our Process method may have already been called, we must ensure
// that the PR_POLL_WRITE flag is set.
//
IPC_ClientWritePending(this);
#endif
return PR_TRUE;
}
#ifdef XP_UNIX
//
// called to process a client socket
//
@@ -154,63 +217,6 @@ ipcClient::Process(PRFileDesc *fd, int poll_flags)
return ret_flags;
}
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);
}
PRBool
ipcClient::EnqueueOutboundMsg(ipcMessage *msg)
{
LOG(("enqueue outbound message\n"));
if (!HasTarget(msg->Target())) {
LOG((" no registered message handler\n"));
delete msg;
return PR_FALSE;
}
mOutMsgQ.Append(msg);
return PR_TRUE;
}
//
// called to write out any messages from the outgoing queue.
//
@@ -240,3 +246,4 @@ ipcClient::WriteMsgs(PRFileDesc *fd)
return 0;
}
#endif