initial coding for nsImapProxyEvent

This commit is contained in:
jefft%netscape.com 1999-03-23 02:18:53 +00:00
parent 50c9cb8329
commit c3b5f4333c
5 changed files with 224 additions and 5 deletions

View File

@ -26,15 +26,18 @@ REQUIRES=xpcom js nspr netlib
CPPSRCS= nsImapUrl.cpp \
nsImapProtocol.cpp \
nsImapProxyEvent.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsImapUrl.obj \
.\$(OBJDIR)\nsImapProtocol.obj \
.\$(OBJDIR)\nsImapProxyEvent.obj \
$(NULL)
EXPORTS= nsImapUrl.h \
nsImapProtocol.h \
nsImapProxyEvent.h \
$(NULL)
LINCS= \

View File

@ -20,6 +20,7 @@
#include "nsImapProtocol.h"
#include "nscore.h"
#include "nsImapProxyEvent.h"
// netlib required files
#include "nsIStreamListener.h"
@ -92,6 +93,7 @@ nsImapProtocol::nsImapProtocol()
m_thread = nsnull;
m_monitor = nsnull;
m_imapThreadIsRunning = PR_FALSE;
m_consumer = nsnull;
}
nsresult nsImapProtocol::Initialize(PLEventQueue * aSinkEventQueue)
@ -247,10 +249,8 @@ nsImapProtocol::GetThreadEventQueue(PLEventQueue **aEventQueue)
// *** should subclassing PLEventQueue and ref count it ***
// *** need to find a way to prevent dangling pointer ***
// *** a callback mechanism or a semaphor control thingy ***
PR_CEnterMonitor(this);
*aEventQueue = m_eventQueue;
PR_CNotify(this);
PR_CExitMonitor(this);
if (aEventQueue)
*aEventQueue = m_eventQueue;
return NS_OK;
}
@ -280,7 +280,6 @@ NS_IMETHODIMP nsImapProtocol::OnDataAvailable(nsIURL* aURL, nsIInputStream *aISt
// we would read a line from the stream and then parse it.....I think this function can
// effectively replace ReadLineFromSocket...
return NS_OK;
}
@ -423,6 +422,8 @@ nsresult nsImapProtocol::LoadUrl(nsIURL * aURL, nsISupports * aConsumer)
NS_ASSERTION(0, "I don't think we should get here for imap urls");
}
} // if we have an imap url and a transport
if (aConsumer)
m_consumer = aConsumer;
} // if we received a url!
return rv;

View File

@ -103,6 +103,7 @@ private:
static void ImapThreadMain(void *aParm);
void ImapThreadMainLoop(void);
PRBool ImapThreadIsRunning();
nsISupports *m_consumer;
// initialization function given a new url and transport layer

View File

@ -0,0 +1,141 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "msgCore.h" // precompiled header
#include "nspr.h"
#include "nsImapProxyEvent.h"
#include "nsCOMPtr.h"
#include <windows.h> // for InterlockedIncrement
nsImapEvent::~nsImapEvent()
{
}
void
nsImapEvent::InitEvent()
{
PL_InitEvent(this, nsnull,
(PLHandleEventProc) imap_event_handler,
(PLDestroyEventProc) imap_event_destructor);
}
void
nsImapEvent::PostEvent(PLEventQueue* aEventQ)
{
NS_PRECONDITION(nsnull != aEventQ, "PostEvent: aEventQ is null");
InitEvent();
PL_PostEvent(aEventQ, this);
}
void PR_CALLBACK
nsImapEvent::imap_event_handler(PLEvent *aEvent)
{
nsImapEvent* ev = (nsImapEvent*) aEvent;
ev->HandleEvent();
}
void PR_CALLBACK
nsImapEvent::imap_event_destructor(PLEvent *aEvent)
{
nsImapEvent* ev = (nsImapEvent*) aEvent;
delete ev;
}
nsImapLogProxy::nsImapLogProxy(nsIImapLog* aImapLog,
PLEventQueue* aEventQ,
PRThread* aThread)
{
NS_PRECONDITION(aImapLog && aEventQ,
"nsImapLogProxy: invalid aImapLog or aEventQ");
NS_INIT_REFCNT();
m_realImapLog = aImapLog;
NS_ADDREF(m_realImapLog);
m_eventQueue = aEventQ;
m_thread = aThread;
}
nsImapLogProxy::~nsImapLogProxy()
{
NS_IF_RELEASE(m_realImapLog);
}
/*
* Implementation of thread save nsISupports methods ....
*/
static NS_DEFINE_IID(kIImapLogIID, NS_IIMAPLOG_IID);
NS_IMPL_THREADSAFE_ISUPPORTS(nsImapLogProxy, kIImapLogIID);
NS_IMETHODIMP nsImapLogProxy::HandleImapLogData(const char *aLogData)
{
NS_PRECONDITION(aLogData, "HandleImapLogData: invalid log data");
nsresult res = NS_OK;
if(PR_GetCurrentThread() == m_thread)
{
nsImapLogProxyEvent *ev = new nsImapLogProxyEvent(this, aLogData);
if (nsnull == ev)
{
res = NS_ERROR_OUT_OF_MEMORY;
}
else
{
ev->PostEvent(m_eventQueue);
}
}
else
{
res = m_realImapLog->HandleImapLogData(aLogData);
}
return res;
}
nsIImapLog*
ns_NewImapLogProxy(nsIImapLog* aImapLog,
PLEventQueue* aEventQ,
PRThread* aThread)
{
return new nsImapLogProxy(aImapLog, aEventQ, aThread);
}
nsImapLogProxyEvent::nsImapLogProxyEvent(nsImapLogProxy* aProxy,
const char* aLogData)
{
NS_PRECONDITION(aProxy && aLogData,
"nsImapLogProxyEvent: invalid aProxy or aLogData");
m_logData = PL_strdup(aLogData);
m_proxy = aProxy;
NS_ADDREF(m_proxy);
}
nsImapLogProxyEvent::~nsImapLogProxyEvent()
{
PR_Free(m_logData);
NS_RELEASE(m_proxy);
}
NS_IMETHODIMP
nsImapLogProxyEvent::HandleEvent()
{
return m_proxy->m_realImapLog->HandleImapLogData(m_logData);
}

View File

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsImapProxyEvent_h__
#define nsImapProxyEvent_h__
#include "plevent.h"
#include "prthread.h"
#include "nsISupports.h"
#include "nsIURL.h"
#include "nsIImapLog.h"
class nsImapLogProxy : public nsIImapLog
{
public:
nsImapLogProxy(nsIImapLog* aImapLog,
PLEventQueue* aEventQ,
PRThread* aThread);
virtual ~nsImapLogProxy();
NS_DECL_ISUPPORTS
NS_IMETHOD HandleImapLogData(const char* aLogData);
nsIImapLog* m_realImapLog;
private:
PLEventQueue* m_eventQueue;
PRThread* m_thread;
};
/* ******* Imap Base Event struct ******** */
struct nsImapEvent : public PLEvent
{
virtual ~nsImapEvent();
virtual void InitEvent();
NS_IMETHOD HandleEvent() = 0;
void PostEvent(PLEventQueue* aEventQ);
static void PR_CALLBACK imap_event_handler(PLEvent* aEvent);
static void PR_CALLBACK imap_event_destructor(PLEvent *aEvent);
};
struct nsImapLogProxyEvent : public nsImapEvent
{
nsImapLogProxyEvent(nsImapLogProxy* aProxy, const char* aLogData);
virtual ~nsImapLogProxyEvent();
NS_IMETHOD HandleEvent();
char *m_logData;
nsImapLogProxy *m_proxy;
};
nsIImapLog* ns_NewImapLogProxy(nsIImapLog* aImapLog,
PLEventQueue* aEventQ,
PRThread* aThread);
#endif