mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-15 22:44:13 +00:00
Not part of the build yet. a=chofmann. Initial check in of imap framework.
Imap factory is used to build the imap dll component.
This commit is contained in:
parent
8256161ceb
commit
6ad016b233
67
mailnews/imap/build/makefile.win
Normal file
67
mailnews/imap/build/makefile.win
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#!gmake
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
DEPTH=..\..\..
|
||||||
|
MODULE=mailnews
|
||||||
|
|
||||||
|
MAKE_OBJ_TYPE=DLL
|
||||||
|
DLLNAME=msgimap
|
||||||
|
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||||
|
|
||||||
|
EXPORTS= \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
CPPSRCS= \
|
||||||
|
nsImapFactory.cpp \
|
||||||
|
|
||||||
|
CPP_OBJS=\
|
||||||
|
.\$(OBJDIR)\nsImapFactory.obj \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
# XXX linking in raptor is a heinous crime that will go away once we
|
||||||
|
# have a more DOM-based mechanism for constructing elements and
|
||||||
|
# hooking in to their changes.
|
||||||
|
|
||||||
|
LLIBS=\
|
||||||
|
$(DIST)\lib\xpcom32.lib \
|
||||||
|
$(DIST)\lib\xplib.lib \
|
||||||
|
$(DIST)\lib\msgcore.lib \
|
||||||
|
$(DIST)\lib\imap.lib \
|
||||||
|
$(LIBNSPR) \
|
||||||
|
$(DIST)\lib\plc3.lib \
|
||||||
|
$(DIST)\lib\raptorbase.lib \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
MISCDEP=$(LLIBS)
|
||||||
|
|
||||||
|
# XXX Note dependencies on implementation dirs for factory methods.
|
||||||
|
|
||||||
|
LINCS= \
|
||||||
|
-I$(PUBLIC)\xpcom \
|
||||||
|
-I$(PUBLIC)\mailnews \
|
||||||
|
-I$(PUBLIC)\raptor \
|
||||||
|
-I$(PUBLIC)\netlib \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include <$(DEPTH)\config\rules.mak>
|
||||||
|
|
||||||
|
install:: $(DLL)
|
||||||
|
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||||
|
|
||||||
|
clobber::
|
||||||
|
rm -f $(DIST)\bin\$(DLLNAME)
|
||||||
|
|
216
mailnews/imap/build/nsImapFactory.cpp
Normal file
216
mailnews/imap/build/nsImapFactory.cpp
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
/* -*- 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 "msgCore.h" // for pre-compiled headers...
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsIFactory.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsMsgLocalCID.h"
|
||||||
|
#include "pratom.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
// include files for components this factory creates...
|
||||||
|
#include "nsImapUrl.h"
|
||||||
|
#include "nsImapProtocol.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||||
|
static NS_DEFINE_CID(kCImapUrl, NS_IMAPURL_CID);
|
||||||
|
static NS_DEFINE_CID(kCImapProtocol, NS_IMAPPROTOCOL_CID);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static PRInt32 g_InstanceCount = 0;
|
||||||
|
static PRInt32 g_LockCount = 0;
|
||||||
|
|
||||||
|
class nsImapFactory : public nsIFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// nsISupports methods
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
nsImapFactory(const nsCID &aClass, const char* aClassName, const char* aProgID);
|
||||||
|
|
||||||
|
// nsIFactory methods
|
||||||
|
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult);
|
||||||
|
NS_IMETHOD LockFactory(PRBool aLock);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual ~nsImapFactory();
|
||||||
|
|
||||||
|
nsCID mClassID;
|
||||||
|
char* mClassName;
|
||||||
|
char* mProgID;
|
||||||
|
};
|
||||||
|
|
||||||
|
nsImapFactory::nsImapFactory(const nsCID &aClass, const char* aClassName, const char* aProgID)
|
||||||
|
: mClassID(aClass), mClassName(nsCRT::strdup(aClassName)), mProgID(nsCRT::strdup(aProgID))
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsImapFactory::~nsImapFactory()
|
||||||
|
{
|
||||||
|
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||||
|
delete[] mClassName;
|
||||||
|
delete[] mProgID;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsImapFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||||
|
{
|
||||||
|
if (aResult == NULL)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
// Always NULL result, in case of failure
|
||||||
|
*aResult = NULL;
|
||||||
|
|
||||||
|
// we support two interfaces....nsISupports and nsFactory.....
|
||||||
|
if (aIID.Equals(::nsISupports::GetIID()))
|
||||||
|
*aResult = (void *)(nsISupports*)this;
|
||||||
|
else if (aIID.Equals(nsIFactory::GetIID()))
|
||||||
|
*aResult = (void *)(nsIFactory*)this;
|
||||||
|
|
||||||
|
if (*aResult == NULL)
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
|
||||||
|
AddRef(); // Increase reference count for caller
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsImapFactory)
|
||||||
|
NS_IMPL_RELEASE(nsImapFactory)
|
||||||
|
|
||||||
|
nsresult nsImapFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
if (aResult == NULL)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
*aResult = NULL;
|
||||||
|
|
||||||
|
nsISupports *inst = nsnull;
|
||||||
|
|
||||||
|
// ClassID check happens here
|
||||||
|
// Whenever you add a new class that supports an interface, plug it in here!!!
|
||||||
|
|
||||||
|
// do they want a local datasource ?
|
||||||
|
if (mClassID.Equals(kCImapUrl))
|
||||||
|
{
|
||||||
|
inst = NS_STATIC_CAST(nsIImapUrl*, new nsImapUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mClassID.Equals(kCImapProtocol))
|
||||||
|
{
|
||||||
|
inst = NS_STATIC_CAST(nsIImapProtocol *, new nsImapProtocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inst == nsnull)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
rv = inst->QueryInterface(aIID, aResult);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
delete inst;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsImapFactory::LockFactory(PRBool aLock)
|
||||||
|
{
|
||||||
|
if (aLock)
|
||||||
|
PR_AtomicIncrement(&g_LockCount);
|
||||||
|
else
|
||||||
|
PR_AtomicDecrement(&g_LockCount);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the proper factory to the caller.
|
||||||
|
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
|
||||||
|
const nsCID &aClass,
|
||||||
|
const char *aClassName,
|
||||||
|
const char *aProgID,
|
||||||
|
nsIFactory **aFactory)
|
||||||
|
{
|
||||||
|
if (nsnull == aFactory)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
*aFactory = new nsImapFactory(aClass, aClassName, aProgID);
|
||||||
|
|
||||||
|
if (aFactory)
|
||||||
|
return (*aFactory)->QueryInterface(nsIFactory::GetIID(), (void**)aFactory); // they want a Factory Interface so give it to them
|
||||||
|
else
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
|
||||||
|
{
|
||||||
|
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT nsresult
|
||||||
|
NSRegisterSelf(nsISupports* aServMgr, const char* path)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
nsIComponentManager* compMgr;
|
||||||
|
rv = servMgr->GetService(kComponentManagerCID,
|
||||||
|
nsIComponentManager::GetIID(),
|
||||||
|
(nsISupports**)&compMgr);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = compMgr->RegisterComponent(kCImapUrl, nsnull, nsnull,
|
||||||
|
path, PR_TRUE, PR_TRUE);
|
||||||
|
if (NS_FAILED(rv)) goto done;
|
||||||
|
|
||||||
|
rv = compMgr->RegisterComponent(kCImapProtocol, nsnull, nsnull,
|
||||||
|
path, PR_TRUE, PR_TRUE);
|
||||||
|
if (NS_FAILED(rv)) goto done;
|
||||||
|
|
||||||
|
done:
|
||||||
|
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" NS_EXPORT nsresult
|
||||||
|
NSUnregisterSelf(nsISupports* aServMgr, const char* path)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
nsIComponentManager* compMgr;
|
||||||
|
rv = servMgr->GetService(kComponentManagerCID,
|
||||||
|
nsIComponentManager::GetIID(),
|
||||||
|
(nsISupports**)&compMgr);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = compMgr->UnregisterFactory(kCImapUrl, path);
|
||||||
|
if (NS_FAILED(rv)) goto done;
|
||||||
|
|
||||||
|
rv = compMgr->UnregisterFactory(kCImapProtocol, path);
|
||||||
|
if (NS_FAILED(rv)) goto done;
|
||||||
|
|
||||||
|
done:
|
||||||
|
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||||
|
return rv;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user