initial checkin for d-xpcom support using the ipc daemon, b=242530 (NOT PART OF THE BUILD)

This commit is contained in:
darin%meer.net 2004-05-14 06:19:28 +00:00
Родитель 739850c4eb
Коммит 28793746b8
8 изменённых файлов: 2240 добавлений и 0 удалений

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

@ -0,0 +1,48 @@
# vim: noexpandtab ts=4 sw=4
# ***** 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 *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src test
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,53 @@
# vim: noexpandtab ts=4 sw=4
# ***** 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 *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = ipcd
XPIDLSRCS = \
ipcIDConnectService.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,79 @@
/* vim:set ts=2 sw=2 et cindent: */
/* ***** 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 IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* 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 "nsISupports.idl"
/**
* This service provides methods similar to nsIComponentManager and
* nsIServiceManager. A ClientID parameter specifies the remote process
* in which the object should live.
*
* ipcIService can be used to determine the ClientID of a remote process.
*
* It is assumed that both processes have access to the same typelibs.
*/
[scriptable, uuid(fe07ed16-2710-4a1e-a4e2-81302b62bf0e)]
interface ipcIDConnectService : nsISupports
{
void createInstance(
in unsigned long aClientID,
in nsCIDRef aClass,
in nsIIDRef aIID,
[iid_is(aIID),retval] out nsQIResult result
);
void createInstanceByContractID(
in unsigned long aClientID,
in string aContractID,
in nsIIDRef aIID,
[iid_is(aIID),retval] out nsQIResult result
);
void getService(
in unsigned long aClientID,
in nsCIDRef aClass,
in nsIIDRef aIID,
[iid_is(aIID),retval] out nsQIResult result
);
void getServiceByContractID(
in unsigned long aClientID,
in string aContractID,
in nsIIDRef aIID,
[iid_is(aIID),retval] out nsQIResult result
);
};

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

@ -0,0 +1,66 @@
# vim: noexpandtab ts=4 sw=4
# ***** 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 *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = ipcd
LIBRARY_NAME = ipcddconnect_s
FORCE_STATIC_LIB = 1
MODULE_NAME = ipcd
FORCE_USE_PIC = 1
REQUIRES = \
xpcom \
string \
$(NULL)
CPPSRCS = \
ipcDConnectService.cpp \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/../../../shared/src \
$(NULL)
include $(topsrcdir)/config/rules.mk

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,101 @@
/* vim:set ts=2 sw=2 et cindent: */
/* ***** 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 IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* 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 "ipcIDConnectService.h"
#include "ipcdclient.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsCOMPtr.h"
#include "nsClassHashtable.h"
#include "nsHashKeys.h"
#include "xptcall.h"
#include "xptinfo.h"
class DConnectInstance;
typedef nsClassHashtable<nsVoidPtrHashKey, DConnectInstance> DConnectInstanceSet;
class ipcDConnectService : public ipcIDConnectService
, public ipcIMessageObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IPCIDCONNECTSERVICE
NS_DECL_IPCIMESSAGEOBSERVER
NS_HIDDEN_(nsresult) Init();
NS_HIDDEN_(nsresult) GetInterfaceInfo(const nsID &iid, nsIInterfaceInfo **);
NS_HIDDEN_(nsresult) GetIIDForMethodParam(nsIInterfaceInfo *iinfo,
const nsXPTMethodInfo *methodInfo,
const nsXPTParamInfo &paramInfo,
const nsXPTType &type,
PRUint16 methodIndex,
PRUint8 paramIndex,
nsXPTCMiniVariant *dispatchParams,
nsID &result);
NS_HIDDEN_(nsresult) StoreInstance(DConnectInstance *);
NS_HIDDEN_(void) DeleteInstance(DConnectInstance *);
private:
NS_HIDDEN ~ipcDConnectService();
NS_HIDDEN_(void) OnSetup(PRUint32 peer, const struct DConnectSetup *, PRUint32 opLen);
NS_HIDDEN_(void) OnRelease(PRUint32 peer, const struct DConnectRelease *);
NS_HIDDEN_(void) OnInvoke(PRUint32 peer, const struct DConnectInvoke *, PRUint32 opLen);
private:
nsCOMPtr<nsIInterfaceInfoManager> mIIM;
// table of local object instances allocated on behalf of a peer
DConnectInstanceSet mInstances;
};
#define IPC_DCONNECTSERVICE_CLASSNAME \
"ipcDConnectService"
#define IPC_DCONNECTSERVICE_CONTRACTID \
"@mozilla.org/ipc/dconnect-service;1"
#define IPC_DCONNECTSERVICE_CID \
{ /* 63a5d9dc-4828-425a-bd50-bd10a4b26f2c */ \
0x63a5d9dc, \
0x4828, \
0x425a, \
{0xbd, 0x50, 0xbd, 0x10, 0xa4, 0xb2, 0x6f, 0x2c} \
}

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

@ -0,0 +1,35 @@
# vim:set ts=8 sw=8 noet:
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dconnect
REQUIRES = ipcd \
nspr \
string \
xpcom \
necko \
$(NULL)
CPPSRCS = \
TestDConnect.cpp \
$(NULL)
SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX))
include $(topsrcdir)/config/config.mk
LIBS = \
$(EXTRA_DSO_LIBS) \
$(MOZ_JS_LIBS) \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,179 @@
#include "ipcIService.h"
#include "ipcIDConnectService.h"
#include "ipcCID.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsString.h"
#include "prmem.h"
#define RETURN_IF_FAILED(rv, step) \
PR_BEGIN_MACRO \
if (NS_FAILED(rv)) { \
printf("*** %s failed: rv=%x\n", step, rv); \
return rv;\
} \
PR_END_MACRO
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
static nsIEventQueue* gEventQ = nsnull;
static PRBool gKeepRunning = PR_TRUE;
static ipcIService *gIpcServ = nsnull;
static nsresult DoTest()
{
nsresult rv;
nsCOMPtr<ipcIDConnectService> dcon = do_GetService("@mozilla.org/ipc/dconnect-service;1", &rv);
RETURN_IF_FAILED(rv, "getting dconnect service");
PRUint32 remoteClientID = 1;
nsCOMPtr<nsIURL> url;
rv = dcon->CreateInstance(remoteClientID, kStandardURLCID, NS_GET_IID(nsIURL), getter_AddRefs(url));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> sup = do_QueryInterface(url, &rv);
NS_ENSURE_SUCCESS(rv, rv);
printf("*** calling QueryInterface\n");
nsCOMPtr<nsIURI> uri = do_QueryInterface(url, &rv);
NS_ENSURE_SUCCESS(rv, rv);
NS_NAMED_LITERAL_CSTRING(spec, "http://www.mozilla.org/");
printf("*** calling SetSpec\n");
rv = uri->SetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
nsCString buf;
rv = uri->GetSpec(buf);
NS_ENSURE_SUCCESS(rv, rv);
if (!buf.Equals(spec))
{
printf("*** GetSpec erroneously returned [%s]\n", buf.get());
return NS_ERROR_FAILURE;
}
PRBool match;
rv = uri->SchemeIs("http", &match);
if (NS_FAILED(rv) || !match)
{
printf("*** SchemeIs test failed [rv=%x]\n", rv);
return NS_ERROR_FAILURE;
}
nsCString resolvedSpec;
rv = uri->Resolve(NS_LITERAL_CSTRING("index.html"), resolvedSpec);
if (NS_FAILED(rv) || !resolvedSpec.EqualsLiteral("http://www.mozilla.org/index.html"))
{
printf("*** Resolve test failed [rv=%x result=%s]\n", rv, resolvedSpec.get());
return NS_ERROR_FAILURE;
}
PRInt32 port;
rv = uri->GetPort(&port);
if (NS_FAILED(rv) || port != -1)
{
printf("*** GetPort test failed [rv=%x port=%d]\n", rv, port);
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIURI> clonedURI;
rv = uri->Clone(getter_AddRefs(clonedURI));
if (NS_FAILED(rv) || !clonedURI)
{
printf("*** Clone test failed [rv=%x]\n", rv);
return NS_ERROR_FAILURE;
}
rv = clonedURI->GetSpec(buf);
if (NS_FAILED(rv) || !buf.Equals(spec))
{
printf("*** Clone test (2) failed [rv=%x buf=%s]\n", rv, buf.get());
return NS_ERROR_FAILURE;
}
url = do_QueryInterface(clonedURI, &rv);
if (NS_FAILED(rv))
{
printf("*** QI test failed [rv=%x]\n", rv);
return rv;
}
rv = url->SetFilePath(NS_LITERAL_CSTRING("/foo/bar/x.y.html?what"));
if (NS_FAILED(rv))
{
printf("*** SetFilePath test failed [rv=%x]\n", rv);
return rv;
}
printf("*** DoTest completed successfully :-)\n");
return NS_OK;
}
int main(int argc, char **argv)
{
nsresult rv;
{
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
if (registrar)
registrar->AutoRegister(nsnull);
// Create the Event Queue for this thread...
nsCOMPtr<nsIEventQueueService> eqs =
do_GetService(kEventQueueServiceCID, &rv);
RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)");
rv = eqs->CreateMonitoredThreadEventQueue();
RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue");
rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
RETURN_IF_FAILED(rv, "GetThreadEventQueue");
nsCOMPtr<ipcIService> ipcServ(do_GetService(IPC_SERVICE_CONTRACTID, &rv));
RETURN_IF_FAILED(rv, "do_GetService(ipcServ)");
NS_ADDREF(gIpcServ = ipcServ);
if (argc > 1) {
printf("*** using client name [%s]\n", argv[1]);
gIpcServ->AddName(argv[1]);
}
rv = DoTest();
RETURN_IF_FAILED(rv, "DoTest()");
PLEvent *ev;
while (gKeepRunning)
{
gEventQ->WaitForEvent(&ev);
gEventQ->HandleEvent(ev);
}
NS_RELEASE(gIpcServ);
printf("*** processing remaining events\n");
// process any remaining events
while (NS_SUCCEEDED(gEventQ->GetEvent(&ev)) && ev)
gEventQ->HandleEvent(ev);
printf("*** done\n");
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
rv = NS_ShutdownXPCOM(nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
}