Initial check in for remote xpcom module.

More documentation andd implementations is comming.

gotta go
work on this module would be continued after 01/10/2000


git-svn-id: svn://10.0.0.236/trunk@56470 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
idk%eng.sun.com
1999-12-23 01:16:05 +00:00
parent 4ceb98d7fd
commit b57eddb1c6
51 changed files with 4140 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#!gmake
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../..
topsrcdir = ../..
VPATH = .
srcdir = .
include $(DEPTH)/config/autoconf.mk
DIRS= \
common \
server \
client \
tests \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,35 @@
#!gmake
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS= \
common \
server \
client \
tests \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,30 @@
This document is under construction.
I am going to continue writing it after 01/10/2000
The main goal of module is to give services for calling xpcom objects across
process boundaries.
Currently we are providing one to one relation
1
server <== client
The reason of this is that this project was started to help blackwood
projects to use oji on solaris.
(Under solaris jvm is running in a separate process.)
In this specific case we need to have only one to one relation
(We have one jvm per mozilla running)
------------------------
sources are organized as follows:
server/ - server related
client/ - client related
common/ - related to bough
tests/ - tests for this
-----------------------------------
This code was tested under solaris only

17
mozilla/xpcom/remote/TODO Normal file
View File

@@ -0,0 +1,17 @@
* Figure out when to free memory allocated for marshaling/demarshaling
(I am going to use my on nsIAllocator for this.
I guess it would be convenient to free all memory allocated by this
allocator)
* Add marshaling for Interfaces.
(It would be done using IMarshalToolkit
We need to implement read/write interface for server and client side
and update code for MarshalToolkitImpl::read/ride Array in order to use
arrays of interfaces)
* Add handling of AddRef, Release and QueryInterface to RemoteObjectProxy
* Implement smarter Dispatcher and RPCChannel.
In order to use it in multi threading environment.

View File

@@ -0,0 +1,56 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = ../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rpcclient
MODULE = rpcclient
CPPSRCS = \
RPCChannelClientImpl.cpp \
RPCClientService.cpp \
RemoteObjectProxy.cpp \
$(NULL)
INCLUDES += -I../common -I../server
LIBS = \
-lxpcom \
-lxptinfo \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.h"
#include "RPCChannelClientImpl.h"
#include "prmem.h"
NS_IMPL_ISUPPORTS(RPCChannelClientImpl, NS_GET_IID(IRPCChannel));
RPCChannelClientImpl::RPCChannelClientImpl(ITransport * _transport) {
NS_INIT_REFCNT();
transport = _transport;
}
RPCChannelClientImpl::~RPCChannelClientImpl() {
NS_IF_RELEASE(transport);
}
NS_IMETHODIMP RPCChannelClientImpl::SendReceive(IRPCall * call) {
//nb temporary implamentation
if(!transport
|| !call) {
return NS_ERROR_NULL_POINTER;
}
void *rawData = NULL;
PRUint32 size = 0;
nsresult rv;
if (NS_FAILED(rv = call->GetRawData(&rawData,&size))) {
return rv;
}
transport->Write(rawData,size);
PR_Free(rawData);
rawData = NULL;
while (!NS_SUCCEEDED(transport->Read(&rawData,&size))) { //nb ugly just for testing
;
}
rv = call->Demarshal(rawData,size);
PR_Free(rawData);
return rv;
}

View File

@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __RPCChannelClientImpl_h__
#define __RPCChannelClientImpl_h__
#include "IRPCChannel.h"
#include "ITransport.h"
#include "IRPCall.h"
class RPCChannelClientImpl : public IRPCChannel {
public:
RPCChannelClientImpl(ITransport *transport);
virtual ~RPCChannelClientImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD SendReceive(IRPCall * call);
private:
ITransport *transport;
};
#endif __RPCChannelClientImpl_h__

View File

@@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "RPCClientService.h"
#include "RemoteObjectProxy.h"
#include "RPCChannelClientImpl.h"
#include "RPCallImpl.h"
#include "TransportImpl.h"
#include "IMarshalToolkit.h"
#include "MarshalToolkitImpl.h"
static IMarshalToolkit * marshalToolkit = new MarshalToolkitImpl();
RPCClientService * RPCClientService::instance = NULL;
char * RPCClientService::serverName = NULL;
RPCClientService::RPCClientService(void) {
transport = NULL;
rpcChannel = NULL;
}
RPCClientService::~RPCClientService(void) {
instance = NULL;
NS_IF_RELEASE(rpcChannel);
}
RPCClientService * RPCClientService::GetInstance(void) {
if (!instance) {
instance = new RPCClientService();
}
return instance;
}
void RPCClientService::Initialize(char *_serverName) {
serverName = _serverName;
}
NS_IMETHODIMP RPCClientService::CreateRPCall(IRPCall **result) {
if (!result) {
return NS_ERROR_NULL_POINTER;
}
*result = new RPCallImpl(marshalToolkit);
NS_ADDREF(*result);
return NS_OK;
}
NS_IMETHODIMP RPCClientService::CreateObjectProxy(OID oid, const nsIID &iid, nsISupports **result) {
if (!result) {
return NS_ERROR_NULL_POINTER;
}
*result = new RemoteObjectProxy(oid, iid);
NS_ADDREF(*result);
return NS_OK;
}
NS_IMETHODIMP RPCClientService::GetTransport(ITransport **result) {
if (!result) {
return NS_ERROR_NULL_POINTER;
}
if (!transport) {
transport = new TransportImpl(serverName);
if (!transport) {
return NS_ERROR_FAILURE;
}
}
NS_ADDREF(transport);
*result = transport;
return NS_OK;
}
NS_IMETHODIMP RPCClientService::GetRPCChannel(IRPCChannel **result) {
nsresult rv = NS_OK;
if (!result) {
return NS_ERROR_NULL_POINTER;
}
if (!rpcChannel) {
ITransport * _transport = NULL;
if (NS_FAILED(rv = GetTransport(&_transport))) {
return rv;
}
rpcChannel = new RPCChannelClientImpl(_transport);
if (!rpcChannel) {
return NS_ERROR_FAILURE;
}
NS_ADDREF(rpcChannel); //nb !! it is for future
}
NS_ADDREF(rpcChannel);
*result = rpcChannel;
return NS_OK;
}

View File

@@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __RPCClientServoce_h__
#define __RPCClientService_h__
#include "nsISupports.h"
#include "ITransport.h"
#include "IRPCall.h"
#include "IRPCChannel.h"
class RPCClientService {
public:
static RPCClientService * GetInstance(void);
static void Initialize(char *serverName);
~RPCClientService();
NS_IMETHOD GetRPCChannel(IRPCChannel **channel);
NS_IMETHOD CreateRPCall(IRPCall **rcall);
NS_IMETHOD CreateObjectProxy(OID oid, const nsIID &iid, nsISupports **result);
protected:
RPCClientService(void);
NS_IMETHOD GetTransport(ITransport **transport);
static RPCClientService * instance;
ITransport * transport;
IRPCChannel * rpcChannel;
static char * serverName;
};
#endif /* __RPCClientService_h__ */

View File

@@ -0,0 +1,100 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIInterfaceInfoManager.h"
#include "RemoteObjectProxy.h"
#include "IRPCall.h"
#include "IRPCChannel.h"
#include "RPCClientService.h"
NS_IMPL_ISUPPORTS(RemoteObjectProxy,NS_GET_IID(RemoteObjectProxy));
RemoteObjectProxy::RemoteObjectProxy(OID _oid, REFNSIID _iid ) {
NS_INIT_REFCNT();
oid = _oid;
iid = _iid;
interfaceInfo = NULL;
}
RemoteObjectProxy::~RemoteObjectProxy() {
NS_IF_RELEASE(interfaceInfo);
}
NS_IMETHODIMP RemoteObjectProxy::GetInterfaceInfo(nsIInterfaceInfo** info) {
printf("--RemoteObjectProxy::GetInterfaceInfo\n");
if(!info) {
return NS_ERROR_FAILURE;
}
if (!interfaceInfo) {
nsIInterfaceInfoManager* iimgr;
if(iimgr = XPTI_GetInterfaceInfoManager()) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
printf("--RemoteObjectProxy::GetInterfaceInfo NS_ERROR_FAILURE 1 \n");
return NS_ERROR_FAILURE;
}
NS_RELEASE(iimgr);
} else {
printf("--RemoteObjectProxy::GetInterfaceInfo NS_ERROR_FAILURE 2 \n");
return NS_ERROR_FAILURE;
}
}
NS_ADDREF(interfaceInfo);
*info = interfaceInfo;
return NS_OK;
}
NS_IMETHODIMP RemoteObjectProxy::CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) {
printf("--RemoteObjectProxy::CallMethod methodIndex %d\n", methodIndex);
RPCClientService * rpcService = RPCClientService::GetInstance();
IRPCall * call = NULL;
IRPCChannel *rpcChannel = NULL;
nsresult rv;
if (NS_FAILED(rv = rpcService->GetRPCChannel(&rpcChannel))) {
printf("--RemoteObjectProxy::CallMethod: failed to get channel\n");
return rv;
}
if (NS_FAILED(rv = rpcService->CreateRPCall(&call))) {
printf("--RemoteObjectProxy::CallMethod: failed to create call\n");
NS_IF_RELEASE(rpcChannel);
return rv;
}
if (NS_FAILED(rv = call->Marshal(iid,oid,methodIndex,info,params))) {
printf("--RemoteObjectProxy::CallMethod: failed marshal\n");
NS_IF_RELEASE(call);
NS_IF_RELEASE(rpcChannel);
return rv;
}
rv = rpcChannel->SendReceive(call);
NS_IF_RELEASE(call);
NS_IF_RELEASE(rpcChannel);
return rv;
}

View File

@@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __RemoteObjectProxy_h__
#define __RemoteObjectProxy_h__
#include "xptcall.h"
#include "nsISupports.h"
#include "IRPCChannel.h"
#include "rproxydefs.h"
// {59678963-A52B-11d3-837C-0004AC56C49E}
#define REMOTEOBJECTPROXY_IID \
{ 0x59678963, 0xa52b, 0x11d3, { 0x83, 0x7c, 0x0, 0x4, 0xac, 0x56, 0xc4, 0x9e } }
class RemoteObjectProxy : public nsXPTCStubBase {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(REMOTEOBJECTPROXY_IID)
NS_DECL_ISUPPORTS
RemoteObjectProxy(OID oid, const nsIID &iid );
virtual ~RemoteObjectProxy();
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
// call this method and return result
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params);
NS_IMETHOD GetOID(OID *_oid) { *_oid = oid; return NS_OK;}
private:
OID oid;
nsIID iid;
nsIInterfaceInfo * interfaceInfo;
};
#endif /* __RemoteObjectProxy_h__ */

View File

@@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __IMarshalToolkit_h__
#define __IMarshalToolkit_h__
#include <iostream.h>
#include "nsISupports.h"
#include "xptcall.h"
#include "nsIAllocator.h"
class IMarshalToolkit : public nsISupports {
public:
/* nsXPTType::T_I8, nsXPTType::T_U8, nsXPTType::T_I16, nsXPTType::T_U16
* nsXPTType::T_I32, nsXPTType::T_U32, nsXPTType::T_I64, nsXPTType::T_U64,
* nsXPTType::T_FLOAT, nsXPTType::T_DOUBLE, nsXPTType::T_BOOL, nsXPTType::T_CHAR, nsXPTType::T_WCHAR,
*/
NS_IMETHOD ReadSimple(istream *in, nsXPTCMiniVariant *value,nsXPTType * type, PRBool isOut, nsIAllocator * allocator = NULL) = 0;
NS_IMETHOD WriteSimple(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut) = 0;
/* nsXPTType::T_IID
*/
NS_IMETHOD ReadIID(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIAllocator * allocator = NULL) = 0;
NS_IMETHOD WriteIID(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut) = 0;
/* case nsXPTType::T_CHAR_STR:
* case nsXPTType::T_WCHAR_STR:
* case nsXPTType::T_PSTRING_SIZE_IS:
* case nsXPTType::T_PWSTRING_SIZE_IS:
*/
NS_IMETHOD ReadString(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIAllocator * allocator = NULL) = 0;
NS_IMETHOD WriteString(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, PRInt32 size = -1) = 0;
/* nsXPTType::T_INTERFACE, nsXPTType::T_INTERFACE_IS
*/
NS_IMETHOD ReadInterface(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIID * iid = NULL,
nsIAllocator * allocator = NULL) = 0;
NS_IMETHOD WriteInterface(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIID * iid = NULL) = 0;
/* nsXPTType::T_ARRAY
*/
NS_IMETHOD ReadArray(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsXPTType * datumType, nsIAllocator * allocator = NULL) = 0;
NS_IMETHOD WriteArray(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsXPTType * datumType, PRUint32 size) = 0;
};
#endif /* __IMarshalToolkit_h__ */

View File

@@ -0,0 +1,179 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <string.h>
#include "IPCbridge.h"
#define SERVER 1L
#define CLIENT 2L
const char * IPCBridge::PREFIX = "/tmp/.msg";
struct data_info {
long dataId;
size_t dataSize;
int dataBlock;
};
// constructor for both
IPCBridge::IPCBridge( const char* serverName)
{
if (serverName) {
fname = (char *)malloc(strlen(serverName) + strlen(PREFIX) + 1);
sprintf(fname,"%s%s",PREFIX,serverName);
initClient();
} else {
initServer();
}
}
// destructor
IPCBridge::~IPCBridge()
{
switch( this_side )
{
case SERVER:
// remove msg queue
msgctl(msg_handler, IPC_RMID, NULL);
// remove file
unlink(fname);
case CLIENT:
// free memory
free(fname);
break;
}
}
unsigned int IPCBridge::Read( void **data )
{
int status;
void *shmem;
struct data_info di;
/* read message about array */
status = msgrcv(msg_handler, &di, sizeof(struct data_info), other_side, IPC_NOWAIT);
if( status==-1 ) return 0;
/* attach shared memory block */
shmem = shmat(di.dataBlock, NULL, 0);
/* copy array to local memory */
*data = malloc(di.dataSize);
memcpy(*data, shmem, di.dataSize);
/* destroy shared memory block */
shmdt((char *)shmem);
status = shmctl(di.dataBlock, IPC_RMID, NULL);
/* return data */
return di.dataSize;
}
unsigned int IPCBridge::Write( unsigned int size, void *data )
{
int status;
int shm_handler;
void *shmem;
struct data_info di;
/* create and attach shared memory block */
shm_handler = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600);
shmem = shmat(shm_handler, NULL, 0);
/* copy array from local memory */
memcpy(shmem, data, size);
shmdt((char *)shmem);
/* create and send message about array */
di.dataId = this_side;
di.dataSize = size;
di.dataBlock = shm_handler;
status = msgsnd(msg_handler, &di, sizeof(struct data_info), IPC_NOWAIT);
if( status==-1 )
{
shmctl(shm_handler, IPC_RMID, NULL);
return 0;
}
/* return */
return size;
}
int IPCBridge::initServer( void )
{
int status;
int fs;
/* create exchange file */
/* name is /tmp/.mgg<pid_in_hex_mode> */
fname = get_name(getpid());
fs = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0600);
printf("--InitServer %s\n",fname);
/* create message queue */
msg_handler = msgget(IPC_PRIVATE, IPC_CREAT | 0600);
if (msg_handler < 0) {
printf("--IPCBridge::initServer failed. status\n");
perror(NULL);
}
this_side = SERVER;
other_side = CLIENT;
/* wrtie handler into exchange file */
status = write(fs, &msg_handler, sizeof(int));
close(fs);
return status;
}
int IPCBridge::initClient( void )
{
int status;
int fs;
/* create exchange filename */
/* name is /tmp/.msg<parent_pid_in_hex_mode> */
/* get message handler */
fs = open(fname,O_RDONLY);
status = read(fs,&msg_handler,sizeof(int));
this_side = CLIENT;
other_side = SERVER;
close(fs);
return status;
}
char *IPCBridge::get_name( pid_t pid )
{
char * p = (char *)malloc(100);
sprintf(p,"%s%x",PREFIX,pid);
printf("--get_name %s\n",p);
return p;
}

View File

@@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __IPCbridge_h__
#define __IPCbridge_h__
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
class IPCBridge {
public:
IPCBridge(const char* serverName = NULL);
~IPCBridge();
unsigned int Read( void** );
unsigned int Write( unsigned int, void* );
private:
const static char * PREFIX;
int msg_handler;
long this_side;
long other_side;
char *fname;
char *get_name( pid_t );
int initServer( void );
int initClient( void );
};
#endif /* __IPCbridge_h__ */

View File

@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __IRPCChannel_h__
#define __IRPCChannel_h__
#include "nsISupports.h"
#include "IRPCall.h"
// {59678951-A52B-11d3-837C-0004AC56C49E}
#define IRPCCHANNEL_IID \
{ 0x59678951, 0xa52b, 0x11d3, { 0x83, 0x7c, 0x0, 0x4, 0xac, 0x56, 0xc4, 0x9e } }
class IRPCChannel : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IRPCCHANNEL_IID)
NS_IMETHOD SendReceive(IRPCall * call) = 0;
};
#endif /* __IRPCChannel_h__ */

View File

@@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __IRPCall_h__
#define __IRPCall_h__
#include "nsISupports.h"
#include "xptcall.h"
#include "rproxydefs.h"
// {59678952-A52B-11d3-837C-0004AC56C49E}
#define IRPCALL_IID\
{ 0x59678952, 0xa52b, 0x11d3, { 0x83, 0x7c, 0x0, 0x4, 0xac, 0x56, 0xc4, 0x9e } }
class IRPCall : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IRPCALL_IID)
NS_IMETHOD Marshal(const nsIID &iid, OID oid, PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) = 0;
NS_IMETHOD Marshal() = 0;
NS_IMETHOD Demarshal(void * data, PRUint32 size) = 0;
NS_IMETHOD GetRawData(void ** data, PRUint32 *size) = 0;
//you should not free(params)
NS_IMETHOD GetXPTCData(OID *oid,PRUint32 *methodIndex,
PRUint32 *paramCount, nsXPTCVariant** params, nsresult **result) = 0;
};
#endif /* __IRPCall_h__ */

View File

@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __ITransport_h__
#define __ITransport_h__
#include "nsISupports.h"
// {59678953-A52B-11d3-837C-0004AC56C49E}
#define ITRANSPORT_IID \
{ 0x59678953, 0xa52b, 0x11d3, { 0x83, 0x7c, 0x0, 0x4, 0xac, 0x56, 0xc4, 0x9e } }
class ITransport : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(ITRANSPORT_IID)
NS_IMETHOD Read(void** data, PRUint32 * size) = 0;
NS_IMETHOD Write(void* data, PRUint32 size) = 0;
};
#endif /* __ITransport_h__ */

View File

@@ -0,0 +1,54 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = ../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rpccommon
MODULE = rpccommon
CPPSRCS = \
IPCbridge.cpp \
Queue.cpp \
TransportImpl.cpp \
MarshalToolkitImpl.cpp \
RPCallImpl.cpp \
$(NULL)
LIBS = \
-lxpcom \
-lxptinfo \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,307 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdlib.h>
#include <iostream.h>
#include "MarshalToolkitImpl.h"
NS_IMPL_ISUPPORTS(MarshalToolkitImpl, NS_GET_IID(nsISupports));
MarshalToolkitImpl::MarshalToolkitImpl(void) {
NS_INIT_REFCNT();
}
MarshalToolkitImpl::~MarshalToolkitImpl() {
}
PRInt16 MarshalToolkitImpl::GetSimpleSize(nsXPTType *type) {
PRInt16 size = -1;
switch(type->TagPart()) {
case nsXPTType::T_I8:
case nsXPTType::T_U8:
size = sizeof(PRInt8);
break;
case nsXPTType::T_I16:
case nsXPTType::T_U16:
size = sizeof(PRInt16);
break;
case nsXPTType::T_I32:
case nsXPTType::T_U32:
size = sizeof(PRInt32);
break;
case nsXPTType::T_I64:
case nsXPTType::T_U64:
size = sizeof(PRInt64);
break;
case nsXPTType::T_FLOAT:
size = sizeof(float);
break;
case nsXPTType::T_DOUBLE:
size = sizeof(double);
break;
case nsXPTType::T_BOOL:
size = sizeof(PRBool);
break;
case nsXPTType::T_CHAR:
size = sizeof(char);
break;
case nsXPTType::T_WCHAR:
size = sizeof(PRUnichar);
break;
default:
break;
}
return size;
}
NS_IMETHODIMP MarshalToolkitImpl::ReadSimple(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIAllocator * allocator) {
PRInt16 size = GetSimpleSize(type);
if (size <= 0 ) {
return NS_ERROR_FAILURE;
}
void * data = NULL;
if (isOut) {
if (allocator) {
value->val.p = allocator->Alloc(size);
}
data = value->val.p;
} else {
data = value;
}
in->read((char*)data,size);
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::WriteSimple(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut) {
PRInt16 size = GetSimpleSize(type);
if (size <= 0 ) {
return NS_ERROR_FAILURE;
}
void *data = (isOut)? value->val.p : value;
out->write((const char*)data,size);
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::ReadIID(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIAllocator * allocator) {
void * data = malloc(sizeof(nsIID)); // nb I guess it is more convinient
if (isOut) {
if (allocator) {
value->val.p = allocator->Alloc(sizeof(void*));
}
memcpy(value->val.p,(void *)&data,sizeof(void*));
} else {
value->val.p = data;
}
in->read((char*)data,sizeof(nsIID));
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::WriteIID(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut) {
void * data = NULL;
if (isOut) {
memcpy((void *)&data, value->val.p, sizeof(void*));
} else {
data = value->val.p;
}
out->write((const char*)data, sizeof(nsIID));
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::ReadString(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut,
nsIAllocator * allocator) {
PRUint32 length;
void *data = NULL;
PRBool isStringWithSize = PR_FALSE;
in->read((char*)&length, sizeof(PRUint32)); //length 0 means NULL string
PRUint32 actualLength = 0;
if (length) {
switch (type->TagPart()) {
case nsXPTType::T_CHAR_STR:
case nsXPTType::T_WCHAR_STR:
actualLength = length;
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
isStringWithSize = PR_TRUE;
actualLength = length - 1 ; //length could not be less than 2. It is impossible to have empty ("") string for this case
break;
default:
return NS_ERROR_FAILURE;
};
data = malloc(actualLength);
}
if (isOut) {
if (allocator) {
value->val.p = allocator->Alloc(sizeof(void*));
}
memcpy(value->val.p,(void *)&data,sizeof(void*));
} else {
value->val.p = data;
}
if (length-1 > 0) {
in->read((char*)data,length-1);
}
if (!isStringWithSize
&& length) {
((char*)data)[length-1]=0;
}
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::WriteString(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, PRInt32 size) {
void * data = NULL;
if (isOut) {
memcpy((void *)&data, value->val.p, sizeof(void*));
} else {
data = value->val.p;
}
PRUint32 length = 0;
if (!data) {
out->write((const char*)&length,sizeof(PRUint32));
return NS_OK;
}
switch (type->TagPart()) {
case nsXPTType::T_CHAR_STR:
case nsXPTType::T_WCHAR_STR:
length = strlen((char*)data);
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
length = size;
break;
default:
return NS_ERROR_FAILURE;
};
length++; //0 for NULL, 1 for "", etc.
out->write((const char*)&length,sizeof(PRUint32));
out->write((const char*)data, length-1);
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::ReadInterface(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIID * iid,
nsIAllocator * allocator) {
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP MarshalToolkitImpl::WriteInterface(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIID * iid) {
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP MarshalToolkitImpl::ReadArray(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsXPTType * datumType, nsIAllocator * allocator) {
PRUint32 length;
in->read((char*)&length,sizeof(PRUint32));
PRInt16 elemSize = GetSimpleSize(datumType);
if(elemSize<0) { //not simple
elemSize = sizeof(void*); //it has to be a pointer
}
void * data = malloc(elemSize*length);
if (isOut) {
if (allocator) {
value->val.p = allocator->Alloc(sizeof(void*));
}
memcpy(value->val.p,(void *)&data,sizeof(void*));
} else {
value->val.p = data;
}
char *current = (char*)data;
nsIID iid;
for (int i = 0; i < length;i++) {
switch(datumType->TagPart()) {
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
ReadSimple(in,(nsXPTCMiniVariant*)current,datumType,PR_FALSE,allocator);
break;
case nsXPTType::T_IID :
ReadIID(in,(nsXPTCMiniVariant*)current,datumType,PR_FALSE,allocator);
break;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
ReadString(in,(nsXPTCMiniVariant*)current,datumType,PR_FALSE,allocator);
break;
case nsXPTType::T_INTERFACE : //nb
break;
default:
return NS_ERROR_FAILURE;
}
current += elemSize;
}
return NS_OK;
}
NS_IMETHODIMP MarshalToolkitImpl::WriteArray(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsXPTType * datumType, PRUint32 length) {
PRInt16 elemSize = GetSimpleSize(datumType);
if(elemSize < 0) { //not simple
elemSize = sizeof(void*); //it has to be a pointer
}
char *current = NULL;
if (isOut) {
memcpy(&current,value->val.p,sizeof(void*));
} else {
current = (char*)value->val.p;
}
out->write((char*)&length,sizeof(PRUint32));
for (int i = 0; i < length;i++) {
switch(datumType->TagPart()) {
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
WriteSimple(out,(nsXPTCMiniVariant*)current,datumType,PR_FALSE);
break;
case nsXPTType::T_IID :
WriteIID(out,(nsXPTCMiniVariant*)current,datumType,PR_FALSE);
break;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
WriteString(out,(nsXPTCMiniVariant*)current,datumType,PR_FALSE);
break;
case nsXPTType::T_INTERFACE : //nb
break;
default:
return NS_ERROR_FAILURE;
}
current += elemSize;
}
return NS_OK;
}

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __MarshalToolkitImpl_h__
#define __MarshalToolkitImpl_h__
#include "nsISupports.h"
#include "xptcall.h"
#include "IMarshalToolkit.h"
class MarshalToolkitImpl : public IMarshalToolkit {
NS_DECL_ISUPPORTS
/* nsXPTType::T_I8, nsXPTType::T_U8, nsXPTType::T_I16, nsXPTType::T_U16
* nsXPTType::T_I32, nsXPTType::T_U32, nsXPTType::T_I64, nsXPTType::T_U64,
* nsXPTType::T_FLOAT, nsXPTType::T_DOUBLE, nsXPTType::T_BOOL, nsXPTType::T_CHAR, nsXPTType::T_WCHAR,
*/
NS_IMETHOD ReadSimple(istream *in, nsXPTCMiniVariant *value,nsXPTType * type, PRBool isOut, nsIAllocator * allocator = NULL);
NS_IMETHOD WriteSimple(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut);
/* nsXPTType::T_IID
*/
NS_IMETHOD ReadIID(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIAllocator * allocator = NULL);
NS_IMETHOD WriteIID(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut);
/* case nsXPTType::T_CHAR_STR:
* case nsXPTType::T_WCHAR_STR:
* case nsXPTType::T_PSTRING_SIZE_IS:
* case nsXPTType::T_PWSTRING_SIZE_IS:
*/
NS_IMETHOD ReadString(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIAllocator * allocator = NULL);
NS_IMETHOD WriteString(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, PRInt32 size = -1);
/* nsXPTType::T_INTERFACE, nsXPTType::T_INTERFACE_IS
*/
NS_IMETHOD ReadInterface(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIID * iid = NULL,
nsIAllocator * allocator = NULL);
NS_IMETHOD WriteInterface(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsIID * iid = NULL);
/* nsXPTType::T_ARRAY
*/
NS_IMETHOD ReadArray(istream *in, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsXPTType * datumType, nsIAllocator * allocator = NULL);
NS_IMETHOD WriteArray(ostream *out, nsXPTCMiniVariant *value, nsXPTType * type, PRBool isOut, nsXPTType * datumType, PRUint32 size);
MarshalToolkitImpl(void);
virtual ~MarshalToolkitImpl();
private:
PRInt16 GetSimpleSize(nsXPTType *type);
};
#endif /* __MarshalToolkitImpl_h__ */

View File

@@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "Queue.h"
struct QueueEntry {
void * ptr;
QueueEntry *next;
QueueEntry *prev;
QueueEntry(void* _ptr) {
next = prev = NULL;
ptr = _ptr;
}
};
Queue::Queue() {
m_head = NULL;
m_tail = NULL;
m_lock = PR_NewLock();
}
Queue::~Queue() {
while (Get())
;
PR_DestroyLock(m_lock);
}
nsresult Queue::Put(void *ptr) {
PR_Lock(m_lock);
QueueEntry* p = new QueueEntry(ptr);
if (!m_tail) {
m_tail = new QueueEntry(ptr);
}
else {
m_tail->next = new QueueEntry(ptr);
m_tail->next->prev = m_tail;
m_tail = m_tail->next;
}
if (!m_head)
m_head = m_tail;
PR_Unlock(m_lock);
return NS_OK;
}
void * Queue::Get() {
void *res;
PR_Lock(m_lock);
if (!m_head) {
m_tail = NULL;
PR_Unlock(m_lock);
return NULL;
}
QueueEntry* excluded;
excluded = m_head;
if (m_head->next)
m_head = m_head->next, m_head->prev = NULL;
else
m_head = m_tail = NULL;
res = excluded->ptr;
delete excluded;
PR_Unlock(m_lock);
return res;
}

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __Queue_h__
#define __Queue_h__
#include "nspr.h"
#include "nsError.h"
class QueueEntry;
class Queue {
public:
Queue();
~Queue();
void * Get();
nsresult Put(void *);
private:
QueueEntry * m_head;
QueueEntry * m_tail;
PRLock * m_lock;
};
#endif /* __Queue_h__ */

View File

@@ -0,0 +1,329 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdlib.h>
#include <strstream.h>
#include "RPCallImpl.h"
#include "prmem.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
NS_IMPL_ISUPPORTS(RPCallImpl, NS_GET_IID(IRPCall));
RPCallImpl::RPCallImpl(IMarshalToolkit * _marshalToolkit) {
NS_INIT_REFCNT();
params = NULL;
info = NULL;
oid = 0;
bundle = NULL;
size = 0;
callSide = unDefined;
interfaceInfo = NULL;
result = NS_ERROR_FAILURE;
marshalToolkit = _marshalToolkit;
}
RPCallImpl::~RPCallImpl() {
if (params) {
free(params);
}
if (bundle) {
free(bundle);
}
NS_IF_RELEASE(interfaceInfo);
}
NS_IMETHODIMP RPCallImpl::Marshal(const nsIID &_iid, OID _oid, PRUint16 _methodIndex,
const nsXPTMethodInfo* _info,
nsXPTCMiniVariant* _params) {
if (callSide == unDefined) {
callSide = onClient;
}
iid = _iid;
oid = _oid;
nsIInterfaceInfoManager *iimgr = NULL;
iimgr = XPTI_GetInterfaceInfoManager();
if (!iimgr) {
return NS_ERROR_FAILURE; //nb how are we going to handle critical errors?
}
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
NS_IF_RELEASE(iimgr);
printf("--RemoteObjectProxy::GetInterfaceInfo NS_ERROR_FAILURE 1 \n");
return NS_ERROR_FAILURE;
}
NS_IF_RELEASE(iimgr);
methodIndex = _methodIndex;
info = (nsXPTMethodInfo*) _info;
paramCount = info->GetParamCount();
if (paramCount > 0) {
params = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
if (params == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
for (int i = 0; i < paramCount; i++) {
(params)[i].Init(_params[i], info->GetParam(i).GetType());
if (info->GetParam(i).IsOut()) {
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
params[i].ptr = params[i].val.p = _params[i].val.p;
}
}
}
return Marshal();
}
NS_IMETHODIMP RPCallImpl::Marshal(void) {
ostrstream out;
if (callSide == onClient) {
out.write((const char *)&iid, sizeof(nsIID));
out.write((const char *)&oid, sizeof(OID));
out.write((const char *)&methodIndex, sizeof(PRUint16));
}
for (int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
nsXPTType type = param.GetType();
PRBool isOut = param.IsOut();
if ((callSide == onClient && !param.IsIn())
|| (callSide == onServer && !param.IsOut())) {
continue;
}
nsXPTCVariant *value = & params[i];
switch(type.TagPart()) {
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
marshalToolkit->WriteSimple(&out,value,&type,isOut);
break;
case nsXPTType::T_IID :
marshalToolkit->WriteIID(&out,value,&type,isOut);
break;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
marshalToolkit->WriteString(&out,value,&type,isOut);
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
marshalToolkit->WriteInterface(&out,value,&type,isOut,NULL);
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_ARRAY:
{
PRUint32 arraySize;
if(!GetArraySizeFromParam(interfaceInfo,info,param,methodIndex,i,params,GET_LENGTH, &arraySize)) {
return NS_ERROR_FAILURE;
}
if (type.TagPart() == nsXPTType::T_ARRAY) {
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, &param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
marshalToolkit->WriteArray(&out,value,&type,isOut,&datumType,arraySize);
} else {
marshalToolkit->WriteString(&out,value,&type,isOut, arraySize);
}
break;
}
default:
return NS_ERROR_FAILURE;
}
}
if (callSide == onServer) {
out.write((const char*)&result,sizeof(nsresult));
}
size = out.pcount();
bundle = malloc(size);
memcpy(bundle,out.str(),size);
return NS_OK;
}
NS_IMETHODIMP RPCallImpl::Demarshal(void * data, PRUint32 _size) {
if(callSide == unDefined) {
callSide = onServer;
}
istrstream in((const char*)data,_size);
nsIAllocator * allocator = NULL;
if (callSide == onServer) {
in.read((char*)&iid,sizeof(nsIID));
in.read((char*)&oid,sizeof(OID));
in.read((char*)&methodIndex,sizeof(PRUint16));
nsIInterfaceInfoManager *iimgr = NULL;
iimgr = XPTI_GetInterfaceInfoManager();
if (!iimgr) {
return NS_ERROR_FAILURE; //nb how are we going to handle critical errors?
}
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
NS_IF_RELEASE(iimgr);
printf("--RemoteObjectProxy::GetInterfaceInfo NS_ERROR_FAILURE 1 \n");
return NS_ERROR_FAILURE;
}
NS_IF_RELEASE(iimgr);
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo**)&info);
paramCount = info->GetParamCount();
if (paramCount > 0) {
params = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
if (params == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
allocator = nsAllocator::GetGlobalAllocator();
}
for (int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
nsXPTCMiniVariant tmpValue = params[i]; //we need to set value for client side
nsXPTCMiniVariant * value;
value = &tmpValue;
nsXPTType type = param.GetType();
if ( (callSide == onServer && !param.IsIn()
|| (callSide == onClient && !param.IsOut()))){
if (callSide == onServer) { //we need to allocate memory for out parametr
value->val.p = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is good
params[i].Init(*value,type);
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
params[i].ptr = params[i].val.p;
}
continue;
}
switch(type.TagPart()) {
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
marshalToolkit->ReadSimple(&in,value,&type,isOut,allocator);
break;
case nsXPTType::T_IID :
marshalToolkit->ReadIID(&in,value,&type,isOut,allocator);
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
marshalToolkit->ReadString(&in,value,&type,isOut,allocator);
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
marshalToolkit->ReadInterface(&in,value,&type,isOut,NULL,allocator);
break;
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, &param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
marshalToolkit->ReadArray(&in,value,&type,isOut,&datumType,allocator);
break;
}
default:
return NS_ERROR_FAILURE;
}
params[i].Init(*value,type);
if (isOut) {
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
params[i].ptr = params[i].val.p;
}
}
return NS_OK;
}
NS_IMETHODIMP RPCallImpl::GetRawData(void ** data, PRUint32 * _size) {
if (!bundle) {
return NS_ERROR_NULL_POINTER;
}
*data = malloc(size);
*_size = size;
memcpy(*data,bundle,size);
return NS_OK;
}
//you should not free(params)
NS_IMETHODIMP RPCallImpl::GetXPTCData(OID * _oid,PRUint32 *_methodIndex,
PRUint32 *_paramCount, nsXPTCVariant** _params, nsresult ** _result) {
*_oid = oid;
*_methodIndex = methodIndex;
*_paramCount = paramCount;
*_params = params;
*_result = &result;
return NS_OK;
}
PRBool RPCallImpl::GetArraySizeFromParam( nsIInterfaceInfo *interfaceInfo,
const nsXPTMethodInfo* method,
const nsXPTParamInfo& param,
uint16 methodIndex,
uint8 paramIndex,
nsXPTCMiniVariant* nativeParams,
SizeMode mode,
PRUint32* result) {
//code borrowed from mozilla/js/src/xpconnect/src/xpcwrappedjsclass.cpp
uint8 argnum;
nsresult rv;
if(mode == GET_SIZE) {
rv = interfaceInfo->GetSizeIsArgNumberForParam(methodIndex, &param, 0, &argnum);
} else {
rv = interfaceInfo->GetLengthIsArgNumberForParam(methodIndex, &param, 0, &argnum);
}
if(NS_FAILED(rv)) {
return PR_FALSE;
}
const nsXPTParamInfo& arg_param = method->GetParam(argnum);
const nsXPTType& arg_type = arg_param.GetType();
// XXX require PRUint32 here - need to require in compiler too!
if(arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_U32)
return PR_FALSE;
if(arg_param.IsOut())
*result = *(PRUint32*)nativeParams[argnum].val.p;
else
*result = nativeParams[argnum].val.u32;
return PR_TRUE;
}

View File

@@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __RPCallImpl_h__
#define __RPCallImpl_h__
#include "IRPCall.h"
#include "IMarshalToolkit.h"
class ostream;
class istream;
class nsIInterfaceInfo;
class RPCallImpl : public IRPCall {
public:
NS_DECL_ISUPPORTS
NS_IMETHOD Marshal(const nsIID &iid, OID oid, PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params);
NS_IMETHOD Marshal(void);
NS_IMETHOD Demarshal(void * data, PRUint32 size);
NS_IMETHOD GetRawData(void ** data, PRUint32 *size);
//you should not free(params)
NS_IMETHOD GetXPTCData(OID *oid,PRUint32 *methodIndex,
PRUint32 *paramCount, nsXPTCVariant** params, nsresult **result);
RPCallImpl(IMarshalToolkit * _marshalToolkit);
virtual ~RPCallImpl();
protected:
enum { unDefined, onServer, onClient } callSide;
enum SizeMode { GET_SIZE, GET_LENGTH } ;
nsIID iid;
OID oid;
PRUint16 methodIndex;
nsXPTMethodInfo* info;
nsXPTCVariant *params;
PRUint32 paramCount;
nsIInterfaceInfo * interfaceInfo;
void *bundle;
PRUint32 size;
nsresult result;
IMarshalToolkit * marshalToolkit;
static PRBool GetArraySizeFromParam( nsIInterfaceInfo *interfaceInfo,
const nsXPTMethodInfo* method,
const nsXPTParamInfo& param,
uint16 methodIndex,
uint8 paramIndex,
nsXPTCMiniVariant* nativeParams,
SizeMode mode,
PRUint32* result);
};
#endif /* __RPCallImpl_h__ */

View File

@@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "TransportImpl.h"
NS_IMPL_ISUPPORTS(TransportImpl, NS_GET_IID(ITransport));
NS_IMETHODIMP TransportImpl::Read(void** data, PRUint32 * size) {
if(!bridge) {
return NS_ERROR_FAILURE;
}
*size = bridge->Read(data);
if (*size > 0) {
printf("--TransportImpl::Read size %d\n",*size);
}
return (*size > 0 ) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP TransportImpl::Write(void* data, PRUint32 size) {
if(!bridge) {
return NS_ERROR_FAILURE;
}
if (!bridge->Write(size,data)) {
return NS_ERROR_FAILURE;
}
printf("--TransportImpl::Write size %d\n",size);
return NS_OK;
}
TransportImpl::TransportImpl(const char* serverName) {
NS_INIT_REFCNT();
bridge = new IPCBridge(serverName);
}
TransportImpl::~TransportImpl() {
if (bridge) {
delete bridge;
}
}

View File

@@ -0,0 +1,36 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __TransportImpl_h__
#define __TransportImpl_h__
#include "ITransport.h"
#include "IPCbridge.h"
class TransportImpl : public ITransport {
NS_DECL_ISUPPORTS
NS_IMETHOD Read(void** data, PRUint32 * size);
NS_IMETHOD Write(void* data, PRUint32 size);
TransportImpl(const char* serverName = NULL);
virtual ~TransportImpl();
protected:
IPCBridge * bridge; //nb temporary
};
#endif /* __TransportImpl_h__ */

View File

@@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __rproxydefs_h__
#define __rproxydefs_h__
#include "prtypes.h"
typedef PRInt32 OID;
#endif /* __rproxydefs_h__ */

View File

@@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "DispatcherImpl.h"
#include "RPCServerService.h"
#include "IRPCChannel.h"
#include "xptcall.h"
class ObjectDescription {
public:
nsISupports* p;
OID oid;
public:
ObjectDescription(nsISupports *_p, OID _oid) {
p = _p; oid = _oid;
}
~ObjectDescription() {
}
};
NS_IMPL_ISUPPORTS(DispatcherImpl, NS_GET_IID(IDispatcher));
DispatcherImpl::DispatcherImpl()
: m_objects(NULL), m_currentOID(0)
{
NS_INIT_REFCNT();
}
DispatcherImpl::~DispatcherImpl() {
PRUint32 size = m_objects->GetSize();
for (PRUint32 i = 0; i < size; i++) {
ObjectDescription* obj = (ObjectDescription*)(*m_objects)[i];
delete obj;
}
delete m_objects;
}
NS_IMETHODIMP DispatcherImpl::Dispatch(IRPCall *call) {
RPCServerService * rpcService = RPCServerService::GetInstance();
IRPCChannel *channel = NULL;
OID oid;
PRUint32 methodIndex;
PRUint32 paramCount;
nsXPTCVariant* params;
nsresult *result;
call->GetXPTCData(&oid,&methodIndex, &paramCount, &params, &result);
nsISupports * p = NULL;
OIDToPointer(&p,oid);
*result = XPTC_InvokeByIndex(p, methodIndex,
paramCount, params);
call->Marshal();
rpcService->GetRPCChannel(&channel);
channel->SendReceive(call);
return NS_OK;
}
NS_IMETHODIMP DispatcherImpl::OIDToPointer(nsISupports **_p,OID _oid) {
PRUint32 size = m_objects->GetSize();
PRUint32 i;
ObjectDescription* desc;
for (i = 0; i < size; i++) {
desc = (ObjectDescription*)(*m_objects)[i];
if (desc->oid == _oid) {
*_p = desc->p;
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP DispatcherImpl:: PointerToOID(OID *_oid, nsISupports *_p) {
PRUint32 size = m_objects->GetSize();
PRUint32 i;
ObjectDescription* desc;
for (i = 0; i < size; i++) {
desc = (ObjectDescription*)(*m_objects)[i];
if (desc->p == _p) {
*_oid = desc->oid;
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP DispatcherImpl::RegisterWithOID(nsISupports *_p, OID _oid) {
if (_p == NULL)
return NS_OK;
if (m_objects == NULL) {
m_objects = new nsVector();
if (m_objects == NULL)
return NS_ERROR_OUT_OF_MEMORY;
}
ObjectDescription* desc = new ObjectDescription(_p, _oid);
PRUint32 size = m_objects->GetSize();
PRUint32 i, rv;
rv = -1;
for (i = 0; i < size; i++) {
if ((*m_objects)[i] == NULL) {
fprintf(stderr, "Adding %p to index %d\n", desc, i);
(*m_objects)[i] = desc, rv = i;
break;
}
}
if (i >= size) {
fprintf(stderr, "Adding %p to the end\n", desc);
rv = m_objects->Add(desc);
}
return rv == -1 ? NS_ERROR_FAILURE : NS_OK;
}
NS_IMETHODIMP DispatcherImpl::UnregisterWithOID(nsISupports *_p, OID _oid) {
if (_p == NULL)
return NS_OK;
PRUint32 size = m_objects->GetSize();
PRUint32 i, rv;
rv = -1;
for (i = 0; i < size; i++) {
ObjectDescription* desc = (ObjectDescription*)(*m_objects)[i];
if (desc == NULL) continue;
if (desc->oid == _oid) {
// this is kind of security measure :)
if (desc->p == _p) {
delete desc;
(*m_objects)[i] = NULL;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP DispatcherImpl::GetOID(OID *_oid) {
*_oid = --m_currentOID;
return NS_OK;
}

View File

@@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __DispatcherImpl_h__
#define __DispatcherImpl_h__
#include "nsISupports.h"
#include "IRPCall.h"
#include "IDispatcher.h"
#include "rproxydefs.h"
#include "nsVector.h"
class DispatcherImpl : public IDispatcher {
public :
NS_DECL_ISUPPORTS
NS_IMETHOD Dispatch(IRPCall *call);
NS_IMETHOD OIDToPointer(nsISupports **p,OID oid);
NS_IMETHOD PointerToOID(OID *oid, nsISupports *p);
NS_IMETHOD RegisterWithOID(nsISupports *p, OID oid);
NS_IMETHOD UnregisterWithOID(nsISupports *p, OID oid);
NS_IMETHOD GetOID(OID *oid);
DispatcherImpl();
virtual ~DispatcherImpl();
private:
nsVector* m_objects; // vector of registred objects
OID m_currentOID;
};
#endif /* __DispatcherImpl_h__ */

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __IDispatcher_h__
#define __IDispatcher_h__
#include "nsISupports.h"
#include "IRPCall.h"
#include "rproxydefs.h"
// {59678955-A52B-11d3-837C-0004AC56C49E}
#define IDISPATCHER_IID \
{ 0x59678955, 0xa52b, 0x11d3, { 0x83, 0x7c, 0x0, 0x4, 0xac, 0x56, 0xc4, 0x9e } }
class IDispatcher : public nsISupports {
public :
NS_DEFINE_STATIC_IID_ACCESSOR(IDISPATCHER_IID)
NS_IMETHOD Dispatch(IRPCall *call) = 0;
NS_IMETHOD OIDToPointer(nsISupports **p,OID oid) = 0;
NS_IMETHOD PointerToOID(OID *oid, nsISupports *p) = 0;
NS_IMETHOD RegisterWithOID(nsISupports *p, OID oid) = 0;
NS_IMETHOD UnregisterWithOID(nsISupports *p, OID oid) = 0;
NS_IMETHOD GetOID(OID *oid) = 0;
};
#endif /* __IDispatcher_h__ */

View File

@@ -0,0 +1,55 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = ../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rpcserver
MODULE = rpcserver
CPPSRCS = \
DispatcherImpl.cpp \
RPCChannelServerImpl.cpp\
RPCServerService.cpp \
$(NULL)
INCLUDES += -I../common/
LIBS = \
-lxpcom \
-lxptinfo \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,119 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.h"
#include "RPCChannelServerImpl.h"
#include "nsIThread.h"
#include "nsIRunnable.h"
#include "RPCServerService.h"
#include "Queue.h"
#include "IDispatcher.h"
class RPCChannelRunner : public nsIRunnable {
public:
NS_DECL_ISUPPORTS
NS_IMETHOD Run() {
while(1) { //nb
rpcChannel->SendReceive(NULL);
PR_Sleep(100);
}
return NS_OK;
}
RPCChannelRunner(IRPCChannel *_rpcChannel) {
NS_INIT_REFCNT();
rpcChannel = _rpcChannel;
NS_ADDREF(rpcChannel);
}
virtual ~RPCChannelRunner() {
NS_IF_RELEASE(rpcChannel);
}
private:
IRPCChannel * rpcChannel;
};
NS_IMPL_ISUPPORTS(RPCChannelRunner, NS_GET_IID(nsIRunnable));
NS_IMPL_ISUPPORTS(RPCChannelServerImpl, NS_GET_IID(IRPCChannel));
RPCChannelServerImpl::RPCChannelServerImpl(ITransport * _transport) {
NS_INIT_REFCNT();
transport = _transport;
queue = new Queue();
rawData = NULL;
dispatcher = NULL;
service = NULL;
NS_NewThread(&thread,new RPCChannelRunner(this));
}
RPCChannelServerImpl::~RPCChannelServerImpl() {
NS_IF_RELEASE(dispatcher);
NS_IF_RELEASE(thread);
NS_IF_RELEASE(transport);
}
NS_IMETHODIMP RPCChannelServerImpl::SendReceive(IRPCall * call) {
if (call) {
queue->Put(call);
} else {
if (!rawData) {
IRPCall * call = (IRPCall*) queue->Get();
if (call) {
call->GetRawData(&rawData,&size);
NS_RELEASE(call);
}
}
if (rawData) {
if (NS_SUCCEEDED(transport->Write(rawData,size))) {
PR_Free(rawData);
rawData = NULL;
}
}
char *data;
PRUint32 s;
if (NS_SUCCEEDED(transport->Read((void**)&data,&s))) {
IRPCall *call = NULL;
if (!service) {
service = RPCServerService::GetInstance();
}
service->CreateRPCall(&call);
call->Demarshal(data,s); //nb error handling
PR_Free(data);
if (!dispatcher) {
service->GetDispatcher(&dispatcher);
}
dispatcher->Dispatch(call);
}
}
return NS_OK;
}

View File

@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __RPCChannelServerImpl_h__
#define __RPCChannelServerImpl_h__
#include "IRPCChannel.h"
#include "ITransport.h"
#include "IRPCall.h"
class nsIThread;
class Queue;
class IDispatcher;
class RPCServerService;
class RPCChannelServerImpl : public IRPCChannel {
public:
RPCChannelServerImpl(ITransport *transport);
virtual ~RPCChannelServerImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD SendReceive(IRPCall * call);
private:
nsIThread * thread;
ITransport *transport;
IDispatcher *dispatcher;
Queue * queue;
RPCServerService *service;
void * rawData;
PRUint32 size;
};
#endif __RPCChannelServerImpl_h__

View File

@@ -0,0 +1,108 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "RPCServerService.h"
#include "RPCallImpl.h"
#include "TransportImpl.h"
#include "DispatcherImpl.h"
#include "RPCChannelServerImpl.h"
#include "MarshalToolkitImpl.h"
static IMarshalToolkit * marshalToolkit = new MarshalToolkitImpl();
RPCServerService * RPCServerService::instance = NULL;
RPCServerService * RPCServerService::GetInstance() {
if (!instance) {
instance = new RPCServerService();
}
return instance;
}
NS_IMETHODIMP RPCServerService::CreateRPCall(IRPCall **result) {
if (!result) {
return NS_ERROR_NULL_POINTER;
}
*result = new RPCallImpl(marshalToolkit);
NS_ADDREF(*result);
return NS_OK;
}
NS_IMETHODIMP RPCServerService::GetTransport(ITransport **result) {
if (!result) {
return NS_ERROR_NULL_POINTER;
}
if (!transport) {
transport = new TransportImpl();
if (!transport) {
return NS_ERROR_FAILURE;
}
}
NS_ADDREF(transport);
*result = transport;
return NS_OK;
}
NS_IMETHODIMP RPCServerService::GetDispatcher(IDispatcher **result) {
if (!result) {
return NS_ERROR_NULL_POINTER;
}
if (!dispatcher) {
dispatcher = new DispatcherImpl();
if (!dispatcher) {
return NS_ERROR_FAILURE;
}
}
NS_ADDREF(dispatcher);
*result = dispatcher;
return NS_OK;
}
NS_IMETHODIMP RPCServerService::GetRPCChannel(IRPCChannel **result) {
nsresult rv = NS_OK;
if (!result) {
return NS_ERROR_NULL_POINTER;
}
if (!rpcChannel) {
ITransport * _transport = NULL;
if (NS_FAILED(rv = GetTransport(&_transport))) {
return rv;
}
rpcChannel = new RPCChannelServerImpl(_transport);
if (!rpcChannel) {
return NS_ERROR_FAILURE;
}
}
NS_ADDREF(rpcChannel);
*result = rpcChannel;
return NS_OK;
}
RPCServerService::RPCServerService() {
transport = NULL;
dispatcher = NULL;
GetRPCChannel(&rpcChannel);
}
RPCServerService::~RPCServerService() {
NS_IF_RELEASE(rpcChannel);
}

View File

@@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef __RPCServerServoce_h__
#define __RPCServerService_h__
#include "nsISupports.h"
#include "ITransport.h"
#include "IRPCall.h"
#include "IRPCChannel.h"
#include "IDispatcher.h"
class RPCServerService {
public:
static RPCServerService * GetInstance(void);
~RPCServerService();
NS_IMETHOD GetRPCChannel(IRPCChannel **channel);
NS_IMETHOD GetDispatcher(IDispatcher **dispatcher);
NS_IMETHOD CreateRPCall(IRPCall **rcall);
protected:
RPCServerService(void);
NS_IMETHOD GetTransport(ITransport **transport);
static RPCServerService * instance;
ITransport * transport;
IRPCChannel * rpcChannel;
IDispatcher * dispatcher;
};
#endif /* __RPCServerService_h__ */

View File

@@ -0,0 +1,53 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = ../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
SIMPLE_PROGRAMS = clientIn serverIn
XPIDL_MODULE = rpctest
XPIDLSRCS = nsIRPCTestIn.idl
INCLUDES += -I../common -I../server -I../client
LIBS = \
-lxpcom \
-lxptinfo \
-lrpcserver \
-lrpcclient \
-lrpccommon \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,53 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = ../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
SIMPLE_PROGRAMS = clientInOut serverInOut
XPIDL_MODULE = rpctest
XPIDLSRCS = nsIRPCTestInOut.idl
INCLUDES += -I../common -I../server -I../client
LIBS = \
-lxpcom \
-lxptinfo \
-lrpcserver \
-lrpcclient \
-lrpccommon \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,53 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = ../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
SIMPLE_PROGRAMS = clientOut serverOut
XPIDL_MODULE = rpctest
XPIDLSRCS = nsIRPCTestOut.idl
INCLUDES += -I../common -I../server -I../client
LIBS = \
-lxpcom \
-lxptinfo \
-lrpcserver \
-lrpcclient \
-lrpccommon \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,53 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH = ../..
topsrcdir = ../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
SIMPLE_PROGRAMS = clientInOut serverInOut
XPIDL_MODULE = rpctest
XPIDLSRCS = nsIRPCTestInOut.idl
INCLUDES += -I../common -I../server -I../client
LIBS = \
-lxpcom \
-lxptinfo \
-lrpcserver \
-lrpcclient \
-lrpccommon \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include "RPCClientService.h"
#include "nsISupports.h"
#include "nsISample.h"
#include "nsIRPCTest.h"
extern char* transportName;
int main(int argc, char **args) {
PRInt32 i;
if (argc < 2) {
printf("format clinet <server pid>\n");
exit(1);
}
RPCClientService::Initialize(args[1]);
RPCClientService * rpcService = RPCClientService::GetInstance();
nsIID iid;
nsIRPCTest *t1, *t2;
rpcService->CreateObjectProxy(1, NS_GET_IID(nsIRPCTest),(nsISupports**)&t1);
i = 1999;
printf("--before call %d\n",i);
t1->Test2(4321,&i);
printf("--after call %d\n",i);
rpcService->CreateObjectProxy(5, NS_GET_IID(nsIRPCTest),(nsISupports**)&t2);
i = 1998;
printf("____________________________________________\n");
printf("--before call %d\n",i);
t2->Test2(4320,&i);
printf("--after call %d\n",i);
printf("---------------------------------------------\n");
char *s1 = "hello";
char *s2 = "world";
t1->Test3(s1,&s2);
printf("s2 %s\n",s2);
printf("-----------------------------------------------\n");
PRUint32 arrayCount = 2;
char * array[2] = {"Hello","Pic"};
t1->Test4(arrayCount,array);
}

View File

@@ -0,0 +1,145 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include "RPCClientService.h"
#include "nsISupports.h"
#include "nsISample.h"
#include "nsIRPCTestIn.h"
extern char* transportName;
int main(int argc, char **args) {
if (argc < 2) {
printf("format client <server pid>\n");
exit(1);
}
RPCClientService::Initialize(args[1]);
RPCClientService * rpcService = RPCClientService::GetInstance();
nsIID iid;
nsIRPCTestIn *t1;
PRBool b;
PRUint8 o;
PRInt16 sInt;
PRInt32 lInt;
PRInt64 llInt;
PRUint16 usInt;
PRUint32 ulInt;
PRUint64 ullInt;
float f;
double d;
char c;
PRUnichar wc;
char* s;
PRUnichar ws;
rpcService->CreateObjectProxy(1, NS_GET_IID(nsIRPCTestIn),(nsISupports**)&t1);
b = PR_TRUE;
printf("--before call Test1 %d\n",b);
t1->Test1(b);
b = PR_FALSE;
printf("--before call Test1 %d\n",b);
t1->Test1(b);
printf("____________________________________________\n");
o = 0;
printf("--before call Test2 %d\n",o);
t1->Test2(o);
o = 124;
printf("--before call Test2 %d\n",o);
t1->Test2(o);
printf("____________________________________________\n");
sInt = -32768;
printf("--before call Test3 %d\n",sInt);
t1->Test3(sInt);
sInt = 32767;
printf("--before call Test3 %d\n",sInt);
t1->Test3(sInt);
printf("____________________________________________\n");
lInt = -2147483648;
printf("--before call Test4 %d\n",lInt);
t1->Test4(lInt);
lInt = 2147483647;
printf("--before call Test4 %d\n",lInt);
t1->Test4(lInt);
printf("____________________________________________\n");
llInt = -9223372036854775808;
printf("--before call Test5 %d\n",llInt);
t1->Test5(llInt);
llInt = 9223372036854775807;
printf("--before call Test5 %d\n",llInt);
t1->Test5(llInt);
printf("____________________________________________\n");
usInt = 32768;
printf("--before call Test6 %u\n",usInt);
t1->Test6(usInt);
usInt = 65535;
printf("--before call Test6 %u\n",usInt);
t1->Test6(usInt);
printf("____________________________________________\n");
ulInt = 0;
printf("--before call Test7 %u\n",ulInt);
t1->Test7(ulInt);
ulInt = 4294967295;
printf("--before call Test7 %u\n",ulInt);
t1->Test7(ulInt);
printf("____________________________________________\n");
ullInt = 0;
printf("--before call Test8 %u\n",ullInt);
t1->Test8(ullInt);
//ullInt = 9223372036854775807;
ullInt = 18446744073709551615;
printf("--before call Test8 %u\n",ullInt);
t1->Test8(ullInt);
printf("____________________________________________\n");
f = .123456789012345678901234567890;
printf("--before call Test9 %.38f\n",f);
t1->Test9(f);
f = 3.4E38;
printf("--before call Test9 %f\n",f);
t1->Test9(f);
printf("____________________________________________\n");
d = .170000001111000000111111000000111110000000111111;
printf("--before call Test10 %.50f\n",d);
t1->Test10(d);
d = 1.7E308;
printf("--before call Test10 %f\n",d);
t1->Test10(d);
printf("____________________________________________\n");
c = 'A';
printf("--before call Test %d\n",c);
t1->Test11(c);
c = 'Z';
printf("--before call Test %d\n",c);
t1->Test11(c);
printf("____________________________________________\n");
wc = 'A';
printf("--before call Test12 %d\n",wc);
t1->Test12(wc);
wc = 'Z';
printf("--before call Test12 %d\n",wc);
t1->Test12(wc);
printf("____________________________________________\n");
s = "This is a test.";
printf("--before call Test13 %s\n",s);
t1->Test13(s);
//s = ""; /* This is a bug... */
//printf("--before call Test13 %s\n",s);
//t1->Test13(s);
printf("____________________________________________\n");
}

View File

@@ -0,0 +1,136 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include "RPCClientService.h"
#include "nsISupports.h"
#include "nsISample.h"
#include "nsIRPCTestInOut.h"
extern char* transportName;
int main(int argc, char **args) {
if (argc < 2) {
printf("format client <server pid>\n");
exit(1);
}
RPCClientService::Initialize(args[1]);
RPCClientService * rpcService = RPCClientService::GetInstance();
nsIID iid;
nsIRPCTestInOut *t1;
PRBool b;
PRUint8 o;
PRInt16 sInt;
PRInt32 lInt;
PRInt64 llInt;
PRUint16 usInt;
PRUint32 ulInt;
PRUint64 ullInt;
float f;
double d;
char c;
PRUnichar wc;
char* s;
PRUnichar ws;
rpcService->CreateObjectProxy(1, NS_GET_IID(nsIRPCTestInOut),(nsISupports**)&t1);
#if 0
b = PR_TRUE;
printf("--before call Test1 %d\n",b);
t1->Test1(&b);
printf("--after call Test1 %d\n",b);
t1->Test1(&b);
#endif
printf("____________________________________________\n");
o = 124;
printf("--before call Test2 %d\n",o);
printf("--&o %p\n",&o);
t1->Test2(&o);
printf("--after call Test2 %d\n",o);
t1->Test2(&o);
printf("____________________________________________\n");
sInt = -32768;
printf("--before call Test3 %d\n",sInt);
t1->Test3(&sInt);
printf("--after call Test3 %d\n",sInt);
t1->Test3(&sInt);
printf("____________________________________________\n");
lInt = -2147483648;
printf("--before call Test4 %d\n",lInt);
t1->Test4(&lInt);
printf("--after call Test4 %d\n",lInt);
t1->Test4(&lInt);
printf("____________________________________________\n");
llInt = -9223372036854775808;
printf("--before call Test5 %d\n",llInt);
t1->Test5(&llInt);
printf("--after call Test5 %d\n",llInt);
t1->Test5(&llInt);
printf("____________________________________________\n");
// usInt = 32768;
// printf("--before call Test6 %u\n",usInt);
// t1->Test6(&usInt);
// printf("--after call Test6 %u\n",usInt);
// t1->Test6(&usInt);
printf("____________________________________________\n");
ulInt = 4294967295;
printf("--before call Test7 %u\n",ulInt);
t1->Test7(&ulInt);
printf("--after call Test7 %u\n",ulInt);
t1->Test7(&ulInt);
printf("____________________________________________\n");
ullInt = 18446744073709551615;
printf("--before call Test8 %u\n",ullInt);
t1->Test8(&ullInt);
printf("--after call Test8 %u\n",ullInt);
t1->Test8(&ullInt);
printf("____________________________________________\n");
f = .123456789012345678901234567890;
printf("--before call Test9 %.38f\n",f);
t1->Test9(&f);
printf("--after call Test9 %f\n",f);
t1->Test9(&f);
printf("____________________________________________\n");
d = 1.7E308;
printf("--before call Test10 %.50f\n",d);
t1->Test10(&d);
printf("--after call Test10 %f\n",d);
t1->Test10(&d);
printf("____________________________________________\n");
// c = 'A';
// printf("--before call Test %d\n",c);
// t1->Test11(&c);
// printf("--after call Test %d\n",c);
// t1->Test11(&c);
// printf("____________________________________________\n");
// wc = 'A';
// printf("--before call Test12 %d\n",wc);
// t1->Test12(&wc);
// printf("--after call Test12 %d\n",wc);
// t1->Test12(&wc);
// printf("____________________________________________\n");
s = "This is a test.";
// s = (char *) malloc(sizeof(char) * 50);
printf("--before call Test13 %s\n",s);
t1->Test13(&s);
printf("--before call Test13 %s\n",s);
t1->Test13(&s);
printf("____________________________________________\n");
}

View File

@@ -0,0 +1,133 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include "RPCClientService.h"
#include "nsISupports.h"
#include "nsISample.h"
#include "nsIRPCTestOut.h"
extern char* transportName;
int main(int argc, char **args) {
if (argc < 2) {
printf("format client <server pid>\n");
exit(1);
}
RPCClientService::Initialize(args[1]);
RPCClientService * rpcService = RPCClientService::GetInstance();
nsIID iid;
nsIRPCTestOut *t1;
PRBool b;
PRUint8 o;
PRInt16 sInt;
PRInt32 lInt;
PRInt64 llInt;
PRUint16 usInt;
PRUint32 ulInt;
PRUint64 ullInt;
float f;
double d;
char c;
PRUnichar wc;
char* s;
PRUnichar ws;
rpcService->CreateObjectProxy(1, NS_GET_IID(nsIRPCTestOut),(nsISupports**)&t1);
b = PR_TRUE;
printf("--before call Test1 %d\n",b);
t1->Test1(&b);
printf("--after call Test1 %d\n",b);
t1->Test1(&b);
printf("____________________________________________\n");
o = 124;
printf("--before call Test2 %d\n",o);
t1->Test2(&o);
printf("--after call Test2 %d\n",o);
t1->Test2(&o);
printf("____________________________________________\n");
sInt = -32768;
printf("--before call Test3 %d\n",sInt);
t1->Test3(&sInt);
printf("--after call Test3 %d\n",sInt);
t1->Test3(&sInt);
printf("____________________________________________\n");
lInt = -2147483648;
printf("--before call Test4 %d\n",lInt);
t1->Test4(&lInt);
printf("--after call Test4 %d\n",lInt);
t1->Test4(&lInt);
printf("____________________________________________\n");
llInt = -9223372036854775808;
printf("--before call Test5 %d\n",llInt);
t1->Test5(&llInt);
printf("--after call Test5 %d\n",llInt);
t1->Test5(&llInt);
printf("____________________________________________\n");
usInt = 32768;
printf("--before call Test6 %u\n",usInt);
t1->Test6(&usInt);
printf("--after call Test6 %u\n",usInt);
t1->Test6(&usInt);
printf("____________________________________________\n");
ulInt = 4294967295;
printf("--before call Test7 %u\n",ulInt);
t1->Test7(&ulInt);
printf("--after call Test7 %u\n",ulInt);
t1->Test7(&ulInt);
printf("____________________________________________\n");
ullInt = 18446744073709551615;
printf("--before call Test8 %u\n",ullInt);
t1->Test8(&ullInt);
printf("--after call Test8 %u\n",ullInt);
t1->Test8(&ullInt);
printf("____________________________________________\n");
f = .123456789012345678901234567890;
printf("--before call Test9 %.38f\n",f);
t1->Test9(&f);
printf("--after call Test9 %f\n",f);
t1->Test9(&f);
printf("____________________________________________\n");
d = 1.7E308;
printf("--before call Test10 %.50f\n",d);
t1->Test10(&d);
printf("--after call Test10 %f\n",d);
t1->Test10(&d);
printf("____________________________________________\n");
c = 'A';
printf("--before call Test %d\n",c);
t1->Test11(&c);
printf("--after call Test %d\n",c);
t1->Test11(&c);
printf("____________________________________________\n");
wc = 'A';
printf("--before call Test12 %d\n",wc);
t1->Test12(&wc);
printf("--after call Test12 %d\n",wc);
t1->Test12(&wc);
printf("____________________________________________\n");
s = "This is a test.";
// s = (char *) malloc(sizeof(char) * 50);
printf("--before call Test13 %s\n",s);
t1->Test13(&s);
printf("--before call Test13 %s\n",s);
t1->Test13(&s);
printf("____________________________________________\n");
}

View File

@@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.idl"
[scriptable, uuid(e7fc2bf4-1dd1-11b2-9253-8efe01a2f0d2)]
interface nsIRPCTest : nsISupports
{
void test1(inout long l);
void test2(in long l1,inout long l2);
void test3(in string s1,inout string s2);
void test4(in PRUint32 count,[array, size_is(count)] in string valueArray);
};

View File

@@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.idl"
[scriptable, uuid(9cc10d00-b191-11d3-ad1e-005004159574)]
interface nsIRPCTestIn : nsISupports
{
void test1(in boolean bool);
void test2(in octet oct);
void test3(in short s);
void test4(in long l);
void test5(in long long ll);
void test6(in unsigned short us);
void test7(in unsigned long ul);
void test8(in unsigned long long ull);
void test9(in float f);
void test10(in double d);
void test11(in char c);
void test12(in wchar wc);
void test13(in string str);
// void test14(in wstring wstr);
// void test20(in boolean abool);
};

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.idl"
[scriptable, uuid(e284f6a0-b701-11d3-ad26-005004159574)]
interface nsIRPCTestInOut : nsISupports
{
void test1(inout boolean bool);
void test2(inout octet oct);
void test3(inout short s);
void test4(inout long l);
void test5(inout long long ll);
void test6(inout unsigned short us);
void test7(inout unsigned long ul);
void test8(inout unsigned long long ull);
void test9(inout float f);
void test10(inout double d);
void test11(inout char c);
void test12(inout wchar wc);
void test13(inout string str);
// void test14(inout wstring wstr);
};

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.idl"
[scriptable, uuid(e284f6a0-b701-11d3-ad26-005004159574)]
interface nsIRPCTestOut : nsISupports
{
void test1(out boolean bool);
void test2(out octet oct);
void test3(out short s);
void test4(out long l);
void test5(out long long ll);
void test6(out unsigned short us);
void test7(out unsigned long ul);
void test8(out unsigned long long ull);
void test9(out float f);
void test10(out double d);
void test11(out char c);
void test12(out wchar wc);
void test13(out string str);
// void test14(out wstring wstr);
};

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include "RPCServerService.h"
#include "nsISupports.h"
#include "nsIJVMManager.h"
#include "nsIRPCTest.h"
#include <unistd.h>
#include "IDispatcher.h"
#include "nsIThread.h"
class nsRPCTestImpl : public nsIRPCTest {
NS_DECL_ISUPPORTS
nsRPCTestImpl() {
NS_INIT_REFCNT();
}
NS_IMETHOD Test1(PRInt32 *l) {
printf("Test1 this=%p\n", this);
printf("--nsRPCTestImpl::Test1 %d\n",*l);
*l = 1234;
printf("--nsRPCTestImpl::Test1 %d\n",*l);
return NS_OK;
}
NS_IMETHOD Test2(PRInt32 l1, PRInt32* l2) {
printf("Test2 this=%p\n", this);
printf("--nsRPCTestImpl::Test2 %d %d\n",l1,*l2);
*l2 = l1;
printf("--nsRPCTestImpl::Test2 %d %d\n",l1,*l2);
return NS_OK;
}
NS_IMETHOD Test3(const char *s1, char **s2) {
printf("Test3 s1 %s s2 %s\n",s1,*s2);
*s2 = "hi";
return NS_OK;
}
NS_IMETHOD Test4(PRUint32 count, const char **valueArray) {
printf("--Test4\n");
printf("count %d\n",count);
for (int i = 0; i < count; i++) {
printf("--valueArray[%d]=%s\n",i,valueArray[i]);
}
return NS_OK;
}
};
NS_IMPL_ISUPPORTS(nsRPCTestImpl, NS_GET_IID(nsIRPCTest));
int main(int argc, char **args) {
printf("%x\n",getpid());
nsRPCTestImpl * test1 = new nsRPCTestImpl();
nsRPCTestImpl * test2 = new nsRPCTestImpl();
RPCServerService * rpcService = RPCServerService::GetInstance();
IDispatcher *dispatcher;
rpcService->GetDispatcher(&dispatcher);
dispatcher->RegisterWithOID(test1, 1);
dispatcher->RegisterWithOID(test2, 5);
while(1) {
PR_Sleep(100);
}
}

View File

@@ -0,0 +1,159 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include "RPCServerService.h"
#include "nsISupports.h"
#include "nsIJVMManager.h"
#include "nsIRPCTestIn.h"
#include <unistd.h>
#include "IDispatcher.h"
#include "nsIThread.h"
class nsRPCTestInImpl : public nsIRPCTestIn {
NS_DECL_ISUPPORTS
nsRPCTestInImpl() {
NS_INIT_REFCNT();
}
NS_IMETHOD Test1(PRBool bool) {
printf("Test1 this=%p\n", this);
printf("--nsRPCTestInImpl::Test1 %d\n",bool);
return NS_OK;
}
NS_IMETHOD Test2(PRUint8 octet) {
printf("Test2 this=%p\n", this);
printf("--nsRPCTestInImpl::Test2 %d\n",octet);
return NS_OK;
}
NS_IMETHOD Test3(PRInt16 sInt) {
printf("Test3 this=%p\n", this);
printf("--nsRPCTestInImpl::Test3 %d\n",sInt);
return NS_OK;
}
NS_IMETHOD Test4(PRInt32 lInt) {
printf("Test4 this=%p\n", this);
printf("--nsRPCTestInImpl::Test4 %d\n",lInt);
return NS_OK;
}
NS_IMETHOD Test5(PRInt64 llInt) {
printf("Test5 this=%p\n", this);
printf("--nsRPCTestInImpl::Test5 %d\n",llInt);
return NS_OK;
}
NS_IMETHOD Test6(PRUint16 usInt) {
printf("Test6 this=%p\n", this);
printf("--nsRPCTestInImpl::Test6 %15u\n",usInt);
return NS_OK;
}
NS_IMETHOD Test7(PRUint32 ulInt) {
printf("Test7 this=%p\n", this);
printf("--nsRPCTestInImpl::Test7 %15u\n",ulInt);
return NS_OK;
}
NS_IMETHOD Test8(PRUint64 ullInt) {
printf("Test8 this=%p\n", this);
printf("--nsRPCTestInImpl::Test8 %15u\n",ullInt);
return NS_OK;
}
NS_IMETHOD Test9(float f) {
printf("Test9 this=%p\n", this);
printf("--nsRPCTestInImpl::Test9 %.50f\n",f);
return NS_OK;
}
NS_IMETHOD Test10(double d) {
printf("Test10 this=%p\n", this);
printf("--nsRPCTestInImpl::Test10 %.50f\n",d);
return NS_OK;
}
NS_IMETHOD Test11(char c) {
printf("Test11 this=%p\n", this);
printf("--nsRPCTestInImpl::Test11 %c\n",c);
return NS_OK;
}
NS_IMETHOD Test12(PRUnichar unic) {
printf("Test12 this=%p\n", this);
printf("--nsRPCTestInImpl::Test12 %c\n",unic);
return NS_OK;
}
NS_IMETHOD Test13(const char* s) {
printf("Test13 this=%p\n", this);
printf("--nsRPCTestInImpl::Test13 %s\n",s);
return NS_OK;
}
// NS_IMETHOD Test14(PRUnichar* unis) {
// printf("Test14 this=%p\n", this);
// printf("--nsRPCTestInImpl::Test14 %s\n",unis);
// return NS_OK;
// }
};
NS_IMPL_ISUPPORTS(nsRPCTestInImpl, NS_GET_IID(nsIRPCTestIn));
int main(int argc, char **args) {
printf("%x\n",getpid());
nsRPCTestInImpl * test1 = new nsRPCTestInImpl();
nsRPCTestInImpl * test2 = new nsRPCTestInImpl();
nsRPCTestInImpl * test3 = new nsRPCTestInImpl();
nsRPCTestInImpl * test4 = new nsRPCTestInImpl();
nsRPCTestInImpl * test5 = new nsRPCTestInImpl();
nsRPCTestInImpl * test6 = new nsRPCTestInImpl();
nsRPCTestInImpl * test7 = new nsRPCTestInImpl();
nsRPCTestInImpl * test8 = new nsRPCTestInImpl();
nsRPCTestInImpl * test9 = new nsRPCTestInImpl();
nsRPCTestInImpl * test10 = new nsRPCTestInImpl();
nsRPCTestInImpl * test11 = new nsRPCTestInImpl();
nsRPCTestInImpl * test12 = new nsRPCTestInImpl();
nsRPCTestInImpl * test13 = new nsRPCTestInImpl();
RPCServerService * rpcService = RPCServerService::GetInstance();
IDispatcher *dispatcher;
rpcService->GetDispatcher(&dispatcher);
dispatcher->RegisterWithOID(test1, 1);
dispatcher->RegisterWithOID(test2, 5);
dispatcher->RegisterWithOID(test3, 7);
dispatcher->RegisterWithOID(test4, 9);
dispatcher->RegisterWithOID(test5, 11);
dispatcher->RegisterWithOID(test6, 13);
dispatcher->RegisterWithOID(test7, 15);
dispatcher->RegisterWithOID(test8, 17);
dispatcher->RegisterWithOID(test9, 19);
dispatcher->RegisterWithOID(test10, 21);
dispatcher->RegisterWithOID(test11, 23);
dispatcher->RegisterWithOID(test12, 25);
dispatcher->RegisterWithOID(test13, 27);
while(1) {
PR_Sleep(100);
}
}

View File

@@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include <stream.h>
#include "RPCServerService.h"
#include "nsISupports.h"
#include "nsIJVMManager.h"
#include "nsIRPCTestInOut.h"
#include <unistd.h>
#include "IDispatcher.h"
#include "nsIThread.h"
class nsRPCTestInOutImpl : public nsIRPCTestInOut {
NS_DECL_ISUPPORTS
nsRPCTestInOutImpl() {
NS_INIT_REFCNT();
}
NS_IMETHOD Test1(PRBool *bool) {
printf("Test1 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test1 %d\n",*bool);
*bool = PR_FALSE;
return NS_OK;
}
NS_IMETHOD Test2(PRUint8 *octet) {
printf("Test2 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test2 %d\n",*octet);
*octet = 88;
return NS_OK;
}
NS_IMETHOD Test3(PRInt16 *sInt) {
printf("Test3 this=%p\n", this);
// printf("--nsRPCTestInOutImpl::Test3 %d\n",*sInt);
*sInt = 9999;
return NS_OK;
}
NS_IMETHOD Test4(PRInt32 *lInt) {
printf("Test4 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test4 %d\n",*lInt);
*lInt = 99999;
return NS_OK;
}
NS_IMETHOD Test5(PRInt64 *llInt) {
printf("Test5 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test5 %d\n",*llInt);
*llInt = 999999;
return NS_OK;
}
NS_IMETHOD Test6(PRUint16 *usInt) {
printf("Test6 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test6 %15u\n",*usInt);
*usInt = 9999;
return NS_OK;
}
NS_IMETHOD Test7(PRUint32 *ulInt) {
printf("Test7 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test7 %15u\n",*ulInt);
*ulInt = 99999;
return NS_OK;
}
NS_IMETHOD Test8(PRUint64 *ullInt) {
printf("Test8 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test8 %15u\n",*ullInt);
*ullInt = 9999999;
return NS_OK;
}
NS_IMETHOD Test9(float *f) {
printf("Test9 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test9 %.50f\n",*f);
*f = 999.999;
return NS_OK;
}
NS_IMETHOD Test10(double *d) {
printf("Test10 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test10 %.50f\n",*d);
*d = 9999999.9999999;
return NS_OK;
}
NS_IMETHOD Test11(char *c) {
printf("Test11 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test11 %c\n",*c);
*c = 'G';
return NS_OK;
}
NS_IMETHOD Test12(PRUnichar *unic) {
printf("Test12 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test12 %c\n",*unic);
*unic = 'G';
return NS_OK;
}
NS_IMETHOD Test13(char **s) {
printf("Test13 this=%p\n", this);
printf("--nsRPCTestInOutImpl::Test13 %s\n",*s);
*s = "remote ipc";
return NS_OK;
}
// NS_IMETHOD Test14(PRUnichar **unis) {
// printf("Test14 this=%p\n", this);
// printf("--nsRPCTestInOutImpl::Test14 %s\n",*unis);
// return NS_OK;
// }
};
NS_IMPL_ISUPPORTS(nsRPCTestInOutImpl, NS_GET_IID(nsIRPCTestInOut));
int main(int argc, char **args) {
printf("%x\n",getpid());
nsRPCTestInOutImpl * test1 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test2 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test3 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test4 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test5 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test6 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test7 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test8 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test9 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test10 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test11 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test12 = new nsRPCTestInOutImpl();
nsRPCTestInOutImpl * test13 = new nsRPCTestInOutImpl();
RPCServerService * rpcService = RPCServerService::GetInstance();
IDispatcher *dispatcher;
rpcService->GetDispatcher(&dispatcher);
dispatcher->RegisterWithOID(test1, 1);
dispatcher->RegisterWithOID(test2, 5);
dispatcher->RegisterWithOID(test3, 7);
dispatcher->RegisterWithOID(test4, 9);
dispatcher->RegisterWithOID(test5, 11);
dispatcher->RegisterWithOID(test6, 13);
dispatcher->RegisterWithOID(test7, 15);
dispatcher->RegisterWithOID(test8, 17);
dispatcher->RegisterWithOID(test9, 19);
dispatcher->RegisterWithOID(test10, 21);
dispatcher->RegisterWithOID(test11, 23);
dispatcher->RegisterWithOID(test12, 25);
dispatcher->RegisterWithOID(test13, 27);
while(1) {
PR_Sleep(100);
}
}

View File

@@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*/
#include <stdio.h>
#include <stream.h>
#include "RPCServerService.h"
#include "nsISupports.h"
#include "nsIJVMManager.h"
#include "nsIRPCTestOut.h"
#include <unistd.h>
#include "IDispatcher.h"
#include "nsIThread.h"
class nsRPCTestOutImpl : public nsIRPCTestOut {
NS_DECL_ISUPPORTS
nsRPCTestOutImpl() {
NS_INIT_REFCNT();
}
NS_IMETHOD Test1(PRBool *bool) {
printf("Test1 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test1 %d\n",*bool);
*bool = PR_FALSE;
return NS_OK;
}
NS_IMETHOD Test2(PRUint8 *octet) {
printf("Test2 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test2 %d\n",*octet);
*octet = 88;
return NS_OK;
}
NS_IMETHOD Test3(PRInt16 *sInt) {
printf("Test3 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test3 %d\n",*sInt);
*sInt = 9999;
return NS_OK;
}
NS_IMETHOD Test4(PRInt32 *lInt) {
printf("Test4 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test4 %d\n",*lInt);
*lInt = 99999;
return NS_OK;
}
NS_IMETHOD Test5(PRInt64 *llInt) {
printf("Test5 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test5 %d\n",*llInt);
*llInt = 999999;
return NS_OK;
}
NS_IMETHOD Test6(PRUint16 *usInt) {
printf("Test6 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test6 %15u\n",*usInt);
*usInt = 9999;
return NS_OK;
}
NS_IMETHOD Test7(PRUint32 *ulInt) {
printf("Test7 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test7 %15u\n",*ulInt);
*ulInt = 99999;
return NS_OK;
}
NS_IMETHOD Test8(PRUint64 *ullInt) {
printf("Test8 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test8 %15u\n",*ullInt);
*ullInt = 9999999;
return NS_OK;
}
NS_IMETHOD Test9(float *f) {
printf("Test9 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test9 %.50f\n",*f);
*f = 999.999;
return NS_OK;
}
NS_IMETHOD Test10(double *d) {
printf("Test10 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test10 %.50f\n",*d);
*d = 9999999.9999999;
return NS_OK;
}
NS_IMETHOD Test11(char *c) {
printf("Test11 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test11 %c\n",*c);
*c = 'G';
return NS_OK;
}
NS_IMETHOD Test12(PRUnichar *unic) {
printf("Test12 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test12 %c\n",*unic);
*unic = 'G';
return NS_OK;
}
NS_IMETHOD Test13(char **s) {
printf("Test13 this=%p\n", this);
printf("--nsRPCTestOutImpl::Test13 %s\n",*s);
*s = "remote ipc";
return NS_OK;
}
// NS_IMETHOD Test14(PRUnichar **unis) {
// printf("Test14 this=%p\n", this);
// printf("--nsRPCTestOutImpl::Test14 %s\n",*unis);
// return NS_OK;
// }
};
NS_IMPL_ISUPPORTS(nsRPCTestOutImpl, NS_GET_IID(nsIRPCTestOut));
int main(int argc, char **args) {
printf("%x\n",getpid());
nsRPCTestOutImpl * test1 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test2 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test3 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test4 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test5 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test6 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test7 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test8 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test9 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test10 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test11 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test12 = new nsRPCTestOutImpl();
nsRPCTestOutImpl * test13 = new nsRPCTestOutImpl();
RPCServerService * rpcService = RPCServerService::GetInstance();
IDispatcher *dispatcher;
rpcService->GetDispatcher(&dispatcher);
dispatcher->RegisterWithOID(test1, 1);
dispatcher->RegisterWithOID(test2, 5);
dispatcher->RegisterWithOID(test3, 7);
dispatcher->RegisterWithOID(test4, 9);
dispatcher->RegisterWithOID(test5, 11);
dispatcher->RegisterWithOID(test6, 13);
dispatcher->RegisterWithOID(test7, 15);
dispatcher->RegisterWithOID(test8, 17);
dispatcher->RegisterWithOID(test9, 19);
dispatcher->RegisterWithOID(test10, 21);
dispatcher->RegisterWithOID(test11, 23);
dispatcher->RegisterWithOID(test12, 25);
dispatcher->RegisterWithOID(test13, 27);
while(1) {
PR_Sleep(100);
}
}