*not part of the build*

urpConnect update
a=lsv@sparc.spb.su,
  sep@sparc.spb.su
This commit is contained in:
idk%eng.sun.com 2001-06-12 04:47:40 +00:00
parent bb749d670f
commit 6c73ffba85
23 changed files with 491 additions and 116 deletions

View File

@ -18,7 +18,7 @@
# Rights Reserved.
#
# Contributor(s):
# Sergey Lunegov <lsv@sparc.spb.su>
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../../../..

View File

@ -17,32 +17,26 @@
* Rights Reserved.
*
* Contributor(s):
* Sergey Lunegov <lsv@sparc.spb.su>
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIServiceManager.h"
#include "nsCRT.h"
#include "urpComponentFactory.h"
#include "bcIXPCOMStubsAndProxies.h"
#include "bcXPCOMStubsAndProxiesCID.h"
#include "bcIORBComponent.h"
#include "bcORBComponentCID.h"
#include "urpStub.h"
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBComponent,BC_ORBCOMPONENT_CID);
NS_IMPL_THREADSAFE_ISUPPORTS1(urpComponentFactory, nsIFactory)
static nsISupports* compM = nsnull;
//static nsISupports* compM = nsnull;
//nsCOMPtr<nsIComponentManager> compM = nsnull;
urpComponentFactory::urpComponentFactory(const char *_location, const nsCID &aCID) {
urpComponentFactory::urpComponentFactory(const char *_location, const nsCID &aCID, nsIComponentManager* m) {
NS_INIT_ISUPPORTS();
location = nsCRT::strdup(_location);
aClass = aCID;
compM = m;
}
urpComponentFactory::~urpComponentFactory() {
printf("destructor or urpComponentFactory\n");
nsCRT::free((char*)location);
}
@ -51,35 +45,10 @@ urpComponentFactory::~urpComponentFactory() {
NS_IMETHODIMP urpComponentFactory::CreateInstance(nsISupports *aOuter, const nsIID & iid, void * *result) {
printf("--urpComponentFactory::CreateInstance\n");
nsresult r;
if(!compM) {
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--urpComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBComponent, &r);
if (NS_FAILED(r)) {
printf("--urpComponentFactory::CreateInstance bcORB failed \n");
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcOID oid;
urpTransport* transport = new urpConnector();
PRStatus status = transport->Open("socket,host=indra,port=20009");
if(status != PR_SUCCESS) {
printf("Error during opening connection\n");
exit(-1);
}
bcIStub *stub = new urpStub(transport->GetConnection());
oid = orb->RegisterStub(stub);
printf("--urpComponentFactory::CreateInstance after GetOID\n");
nsISupports *proxy;
printf("--[c++]urpComponentFactory::CreateInstance iid:%s cid:%s\n",iid.ToString(), aClass.ToString());
xpcomStubsAndProxies->GetProxy(oid, NS_GET_IID(nsIComponentManager), orb, &proxy);
compM = proxy;
}
((nsIComponentManager*)(compM))->CreateInstance(aClass, nsnull, iid, result);
nsIFactory* factory;
((nsIComponentManager*)(compM))->FindFactory(aClass, &factory);
factory->CreateInstance(aOuter, iid, result);
NS_RELEASE(factory);
printf("--urpComponentFactory::CreateInstance end\n");
return NS_OK;
}

View File

@ -17,7 +17,7 @@
* Rights Reserved.
*
* Contributor(s):
* Sergey Lunegov <lsv@sparc.spb.su>
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __urpComponentFactory_h
#define __urpComponentFactory_h
@ -27,11 +27,13 @@ class urpComponentFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
urpComponentFactory(const char *location, const nsCID &aCID);
urpComponentFactory(const char *location, const nsCID &aCID,
nsIComponentManager* m);
virtual ~urpComponentFactory();
private:
char *location;
nsCID aClass;
nsCOMPtr<nsIComponentManager> compM;
};
#endif

View File

@ -17,7 +17,7 @@
* Rights Reserved.
*
* Contributor(s):
* Sergey Lunegov <lsv@sparc.spb.su>
* Igor Kushnirskiy <idk@eng.sun.com>
*/
/*
@ -33,7 +33,16 @@
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "bcIXPCOMStubsAndProxies.h"
#include "bcXPCOMStubsAndProxiesCID.h"
#include "bcIORBComponent.h"
#include "bcORBComponentCID.h"
#include "urpStub.h"
#include "urpManager.h"
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBComponent,BC_ORBCOMPONENT_CID);
const char urpComponentTypeName[] = URPCOMPONENTTYPENAME;
@ -50,6 +59,13 @@ const char xpcomKeyName[] = "software/mozilla/XPCOM/components";
NS_IMPL_THREADSAFE_ISUPPORTS(urpComponentLoader,NS_GET_IID(nsIComponentLoader));
nsCOMPtr<nsIComponentManager> compM = nsnull;
static bcIORB* orb = nsnull;
static urpTransport* transport;
static urpManager* man;
static bcIStub* stub;
static nsISupports* proxy;
urpComponentLoader::urpComponentLoader()
: mCompMgr(NULL),
@ -57,9 +73,37 @@ urpComponentLoader::urpComponentLoader()
{
NS_INIT_REFCNT();
printf("--urpComponentLoader::urpComponentLoader \n");
nsresult r;
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--urpComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return;
}
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBComponent, &r);
if (NS_FAILED(r)) {
printf("--urpComponentFactory::CreateInstance bcORB failed \n");
return;
}
_orb->GetORB(&orb);
bcOID oid;
transport = new urpConnector();
PRStatus status = transport->Open("socket,host=indra,port=20009");
if(status != PR_SUCCESS) {
printf("Error during opening connection\n");
exit(-1);
}
man = new urpManager(PR_TRUE, nsnull, transport->GetConnection());
stub = new urpStub(man);
oid = orb->RegisterStub(stub);
xpcomStubsAndProxies->GetProxy(oid, NS_GET_IID(nsIComponentManager), orb, &proxy);
compM = (nsIComponentManager*)proxy;
}
urpComponentLoader::~urpComponentLoader() { //nb
delete stub;
delete man;
delete transport;
NS_RELEASE(proxy);
printf("--urpComponentLoader::~urpComponentLoader \n");
}
@ -77,7 +121,8 @@ NS_IMETHODIMP urpComponentLoader::GetFactory(const nsIID & aCID, const char *aLo
fprintf(stderr, "--urpComponentLoader::GetFactory(%s,%s,%s)\n", cidString, aLocation, aType);
delete [] cidString;
#endif
nsIFactory *f = new urpComponentFactory(aLocation, aCID);
nsIFactory *f = new urpComponentFactory(aLocation, aCID, compM);
NS_ADDREF(f);
*_retval = f;
return NS_OK;
}
@ -414,6 +459,7 @@ UnregisterRemoteLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString urpLoader;
printf("URP component loader is being unregistered\n");
rv = catman->GetCategoryEntry("component-loader", urpComponentTypeName,
getter_Copies(urpLoader));
if (NS_FAILED(rv)) return rv;
@ -421,8 +467,7 @@ UnregisterRemoteLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
// only unregister if we're the current JS component loader
if (!strcmp(urpLoader, URP_COMPONENTLOADER_ContractID)) {
return catman->DeleteCategoryEntry("component-loader",
urpComponentTypeName, PR_TRUE,
getter_Copies(urpLoader));
urpComponentTypeName, PR_TRUE,getter_Copies(urpLoader));
}
return NS_OK;
}

View File

@ -17,7 +17,7 @@
* Rights Reserved.
*
* Contributor(s):
* Sergey Lunegov <lsv@sparc.spb.su>
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef _urpComponentLoader_h
#define _urpComponentLoader_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):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsISupports.idl"
[scriptable, uuid(e2f5cf82-4ffa-4c55-ad72-9b3a8a4c4b04)]
interface urpInit : nsISupports
{
};
%{ C++
#define URPINIT_CID \
{ /*55503e25-0a47-48e8-b6ae-b41d0f4e170b*/ \
0x55503e25, \
0x0a47, \
0x48e8, \
{0xb6, 0xae, 0xb4, 0x1d, 0x0f, 0x4e, 0x17, 0x0b} \
}
#define URPINIT_PROGID "urpInit"
%}

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):
#
# Sergey Lunegov <lsv@sparc.spb.su>
DEPTH = ../../../../../../
topsrcdir = ../../../../../../
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = urpInit
MODULE = urpInit
IS_COMPONENT = 1
XPIDLSRCS = Init.idl
CXXFLAGS += -I$(topsrcdir)/java/xpcom/xpcom -I$(JDKHOME)/include -I$(topsrcdir)/java/xpcom/java/src -I$(topsrcdir)/java/xpcom/connect/xpcom -I../
CPPSRCS = \
initImpl.cpp \
initImplFactory.cpp \
$(NULL)
LIBS = -L./ -L$(DIST)/bin/components/ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,131 @@
/* -*- 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):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include "initImpl.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIComponentManager.h"
#include "urpITest.h"
static char * className = "initImpl";
NS_IMPL_ISUPPORTS1(initImpl, urpInit);
initImpl::initImpl() {
NS_INIT_REFCNT();
printf("Constructor of initImpl\n");
nsresult rv;
urpITest * serverComponent;
urpITest* anComp;
rv = nsComponentManager::CreateInstance("urpTest",
nsnull,
NS_GET_IID(urpITest),
(void**)&serverComponent);
if (NS_FAILED(rv)) {
printf("Create instance failed in initImpl!!!");
exit(-1);
}
/*
rv = nsComponentManager::CreateInstance("urpTest",
nsnull,
NS_GET_IID(urpITest),
(void**)&anComp);
if (NS_FAILED(rv)) {
printf("Create instance failed in initImpl sec!!!");
exit(-1);
}
*/
int l = 2000;
serverComponent->Test1(&l);
printf("in initImpl after Test1 %d\n",l);
/*
anComp->Test1(&l);
printf("in initImpl after Test1 %d\n",l);
*/
/*******************************************/
PRInt32 l2 = 2000;
l = 1999;
serverComponent->Test2(l,&l2);
printf("--urpTestImpl after Test2 l2=%d\n",l2);
/*******************************************/
const char * s1 = "s1";
char * s2 = "s2";
serverComponent->Test3(s1,&s2);
printf("--urpTestImpl after Test3 s2=%s\n",s2);
/*******************************************/
char ** valueArray = (char **)malloc(sizeof(char*)*4);
valueArray[0] = "hi";
valueArray[1] = "there";
valueArray[2] = "a";
valueArray[3] = "b";
serverComponent->Test4(4,(const char **)valueArray);
/*******************************************/
char ***valueArray2 = &valueArray;
printf("call object\n");
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
printf("after calling object\n");
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
valueArray2 = (char ***)&valueArray;
serverComponent->Test5(4,valueArray2);
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
{
urpITest *p1;
serverComponent->Test7(&p1);
printf("p1=%p",p1);
PRInt32 l = 1234;
PRInt32 r;
p1->Test1(&l);
urpITest *p3;
printf("--before QueryInterface calling \n");
if (NS_SUCCEEDED(p1->QueryInterface(NS_GET_IID(urpITest),(void**)&p3)))
{
l=2000;
p3->Test1(&l);
printf("l in client after test1 %ld\n",l);
}
delete p1;
delete p3;
}
delete serverComponent;
}
initImpl::~initImpl() {
}

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):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __initImpl_h
#define __initImpl_h
#include "Init.h"
class initImpl : public urpInit {
NS_DECL_ISUPPORTS
NS_DECL_URPINIT
initImpl();
virtual ~initImpl();
};
#endif /* __urpTestImpl_h */

View File

@ -0,0 +1,38 @@
/* -*- 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):
Client QA Team, St. Petersburg, Russia
*/
#include "nsIGenericFactory.h"
#include "initImpl.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(initImpl)
static nsModuleComponentInfo components[] =
{
{ "Init Component", URPINIT_CID, URPINIT_PROGID, initImplConstructor,
NULL /* NULL if you dont need one */,
NULL /* NULL if you dont need one */
}
};
NS_IMPL_NSGETMODULE("urpInitFactory", components)

View File

@ -0,0 +1,11 @@
<html>
<head>
<script>
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var tl = Components.classes["urpInit"].createInstance();
</script>
</head>
<body>
This file can be used to start BlackConnect tests.
</body>

View File

@ -0,0 +1,3 @@
70ef013d-bca9-4226-bdd4-42a92cf6930d
uprTest
urpTest

View File

@ -30,7 +30,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = client
DIRS = client Init
LIBRARY_NAME = urpTest
MODULE = urpTest
@ -47,13 +47,13 @@ CPPSRCS = \
server.cpp \
$(NULL)
LIBS = -L./ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
LIBS = -L./ -L$(DIST)/bin/components/ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
../urpStub.o \
../urpMarshalToolkit.o \
../urpManager.o \
../transport/llTransport.o ../transport/urpPacket.o \
../transport/urpTransport.o \
-L../../java/src
$(NULL)
EXTRA_DSO_LDOPTS += \
../transport/llTransport.o ../transport/urpPacket.o \

View File

@ -41,12 +41,14 @@ CPPSRCS = \
client.cpp \
$(NULL)
LIBS = -L./ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
LIBS = -L./ -L$(DIST)/bin/components/ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
../../urpStub.o \
../../urpMarshalToolkit.o \
../../urpManager.o \
../../transport/llTransport.o ../../transport/urpPacket.o \
../../transport/urpTransport.o \
../urpTestImpl.o
include $(topsrcdir)/config/rules.mk

View File

@ -43,6 +43,8 @@
#include "urpStub.h"
#include "urpITest.h"
#include "urpTestImpl.h"
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
@ -76,8 +78,8 @@ nsIInterfaceInfo *interfaceInfo;
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = NULL;
// urpITest *object = new urpTestImpl();
// object->AddRef();
urpITest *object = new urpTestImpl();
object->AddRef();
urpITest *proxy = NULL;
urpTransport* transport = new urpConnector();
PRStatus status = transport->Open(connectString);
@ -85,7 +87,8 @@ nsIInterfaceInfo *interfaceInfo;
printf("Error during opening connection\n");
exit(-1);
}
stub = new urpStub(transport->GetConnection());
urpManager* man = new urpManager(PR_TRUE, nsnull, transport->GetConnection());
stub = new urpStub(man);
bcOID oid = orb->RegisterStub(stub);
printf("---urpTestImpl oid=%ld iid=%s\n",oid, NS_GET_IID(urpITest).ToString());
r = xpcomStubsAndProxies->GetProxy(oid,NS_GET_IID(urpITest),orb,(nsISupports**)&proxy);
@ -101,7 +104,7 @@ nsIInterfaceInfo *interfaceInfo;
valueArray[2] = "a";
valueArray[3] = "b";
PRInt32 l1 = 1999;
PRInt32 l1 = 99;
PRInt32 ret;
PRInt32 rt;
// object->Test1(&l1);
@ -109,14 +112,14 @@ nsIInterfaceInfo *interfaceInfo;
proxy->Test1(&l1);
printf("--urpTestImpl after Test1 l=%d %d\n",l1,ret);
/*******************************************/
PRInt32 l2 = 2000;
PRInt32 l2 = 2020;
l1 = 1999;
proxy->Test2(l1,&l2);
printf("--urpTestImpl after Test2 l2=%d\n",l2);
/*******************************************/
const char * s1 = "s1";
char * s2 = "s2";
const char * s1 = "s111";
char * s2 = "s2222";
proxy->Test3(s1,&s2);
printf("--urpTestImpl after Test3 s2=%s\n",s2);
/*******************************************/

View File

@ -128,7 +128,7 @@ PRStatus llTCPTransport::Open( char *name, llSideType type )
PR_SetSocketOption( fd, &sopt );
addr.inet.family = AF_INET;
addr.inet.port = port;
addr.inet.port = PR_htons(port);
addr.inet.ip = PR_htonl(INADDR_ANY);
status = PR_Bind( fd, &addr );
if( status == PR_SUCCESS ) PR_Listen( fd, 5 );
@ -150,7 +150,9 @@ PRStatus llTCPTransport::Open( char *name, llSideType type )
PRStatus llTCPTransport::Close( void )
{
return PR_Close( fd );
if( type == llServer )
return PR_Close( fd );
return PR_SUCCESS; // client is always successful
}
llConnection * llTCPTransport::ProvideConnection( void )
@ -232,8 +234,11 @@ PRStatus llPipeTransport::Open( char *name, llSideType type )
PRStatus llPipeTransport::Close( void )
{
PRNetAddr addr;
PR_GetSockName( fd, &addr );
PR_Delete( addr.local.path );
return PR_Close( fd );
if( type == llServer ) {
PRNetAddr addr;
PR_GetSockName( fd, &addr );
PR_Delete( addr.local.path );
return PR_Close( fd );
}
return PR_SUCCESS; // client is always successful
}

View File

@ -78,12 +78,12 @@ void urpPacket::WriteShort( short shortValue ){
// Write Section 4 bytes
void urpPacket::WriteInt( int intValue ){
intValue = PR_htons( intValue );
intValue = PR_htonl( intValue );
WriteBytes( &intValue, 4 );
}
void urpPacket::WriteLong( long longValue ){
longValue = PR_htons( longValue );
longValue = PR_htonl( longValue );
WriteBytes( &longValue, 4 );
}

View File

@ -69,6 +69,15 @@ struct localThreadArg {
}
};
struct monitCall {
PRMonitor *mon;
bcICall* call;
monitCall(PRMonitor *m, bcICall* c) {
this->mon = m;
this->call = c;
}
};
void thread_start( void *arg )
{
urpManager *manager = ((localThreadArg *)arg)->mgr;
@ -79,10 +88,10 @@ void thread_start( void *arg )
urpManager::urpManager(PRBool IsClient, bcIORB *orb, urpConnection* conn) {
broker = orb;
connection = conn;
connTable = nsnull;
monitTable = new nsHashtable(20);
if(IsClient) {
//then
connTable = nsnull;
connection = conn;
localThreadArg *arg = new localThreadArg( this, conn, PR_TRUE );
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
thread_start,
@ -95,6 +104,9 @@ urpManager::urpManager(PRBool IsClient, bcIORB *orb, urpConnection* conn) {
printf("Error couldn't run listener\n");
exit(-1);
}
} else {
connection = nsnull;
connTable = new nsHashtable(20);
}
}
@ -112,10 +124,6 @@ void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
bcICall *call,
PRUint32 paramCount, const nsXPTMethodInfo* info) {
printf("this is method sendUrpRequest and mid is %x\n",methodIndex);
if(connection == nsnull) {
printf("Connection is NULL in SendUrpRequest\n");
exit(-1);
}
long size = 0;
long messagesCount = 0;
urpPacket* message = new urpPacket();
@ -166,7 +174,13 @@ printf("OID is written %ld\n", thrID);
broker = call->GetORB();
mt->WriteParams(call, paramCount, info, interfaceInfo, message, methodIndex);
delete mt;
connection->Write(message);
if(connTable) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
urpConnection* con = connTable->Get(&thrHK);
con->Write(message);
} else
connection->Write(message);
delete message;
}
@ -181,14 +195,8 @@ urpManager::ReadReply(urpPacket* message, char header,
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
nsresult rv = NS_OK;
printf("this is method readReply\n");
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
if((header & NEWTID) != 0) { // new thread id ?
printf("new threadID\n");
bcTID tid = mt->ReadThreadID(message);
}
else
printf("old threadID\n");
rv = mt->ReadParams(paramCount, info, message, interfaceInfo, methodIndex, call, broker, connection);
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
rv = mt->ReadParams(paramCount, info, message, interfaceInfo, methodIndex, call, broker, this);
delete mt;
return rv;
}
@ -197,8 +205,6 @@ nsresult
urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
nsresult rv = NS_OK;
if(!isClient) {
if(connTable == nsnull)
connTable = new nsHashtable(20);
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
connTable->Put(&thrHK, conn);
@ -212,7 +218,20 @@ urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
rv = ReadLongRequest(header, message);
else { // a reply
bcIID iid; bcOID oid; bcMID mid;
call->GetParams(&iid, &oid, &mid);
bcTID tid;
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
if((header & NEWTID) != 0) { // new thread id ?
printf("new threadID\n");
tid = mt->ReadThreadID(message);
}
else
printf("old threadID\n");
delete mt;
threadHashKey thrHK(tid);
monitCall* mc = monitTable->Get(&thrHK);
mc->call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
@ -229,11 +248,10 @@ urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid, (const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
ReadReply(message, header, call, paramCount, info, interfaceInfo, mid);
PR_EnterMonitor(mon);
PR_Notify(mon);
PR_ExitMonitor(mon);
mon = NULL;
ReadReply(message, header, mc->call, paramCount, info, interfaceInfo, mid);
PR_EnterMonitor(mc->mon);
PR_Notify(mc->mon);
PR_ExitMonitor(mc->mon);
}
}
else // only a short request header
@ -274,9 +292,10 @@ urpManager::SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
if(connTable) {
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
connection = (urpConnection*)connTable->Get(&thrHK);
}
connection->Write(message);
urpConnection* con = (urpConnection*)connTable->Get(&thrHK);
con->Write(message);
} else
connection->Write(message);
delete message;
return rv;
}
@ -337,7 +356,7 @@ char* name;
interfaceInfo->GetMethodInfo(methodId,(const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
bcICall *call = broker->CreateCall(&iid, &oid, methodId);
mt->ReadParams(paramCount, info, message, interfaceInfo, methodId, call, broker, connection);
mt->ReadParams(paramCount, info, message, interfaceInfo, methodId, call, broker, this);
delete mt;
//nb return value; excepion handling
broker->SendReceive(call);
@ -347,7 +366,20 @@ char* name;
nsresult
urpManager::SetCall(bcICall* call, PRMonitor *m) {
this->call = call;
this->mon = m;
printf("method SetCall %p %p %p\n",call, m, this);
monitCall* mc = new monitCall(m, call);
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
monitTable->Put(&thrHK, mc);
return NS_OK;
}
nsresult
urpManager::RemoveCall() {
printf("method RemoveCall\n");
bcTID thrID = (bcTID)PR_GetCurrentThread();
threadHashKey thrHK(thrID);
monitCall* mc = monitTable->Remove(&thrHK);
delete mc;
return NS_OK;
}

View File

@ -40,16 +40,13 @@ public:
PRUint32 paramCount, const nsXPTMethodInfo* info);
nsresult ReadMessage(urpConnection* conn, PRBool ic);
nsresult SetCall(bcICall* call, PRMonitor *m);
nsresult RemoveCall();
private:
nsHashtable* connTable;
nsHashtable* monitTable;
bcIORB *broker;
urpConnection* connection;
PRMonitor *mon;
/* for ReadReply */
bcICall* call;
PRUint32 paramCount;
nsXPTMethodInfo* info;
bcMID mid;
nsIInterfaceInfo *interfaceInfo;
void TransformMethodIDAndIID();
nsresult ReadReply(urpPacket* message, char header,

View File

@ -242,7 +242,7 @@ nsresult
urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex, bcIAllocator* allocator,
bcIMarshaler* m, bcIORB *broker, urpConnection* conn) {
bcIMarshaler* m, bcIORB *broker, urpManager* man) {
void* data = allocator->Alloc(sizeof(void*));
nsresult r = NS_OK;
switch(type) {
@ -321,7 +321,7 @@ urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
nsIID iid = ReadType(message);
nsISupports *proxy = NULL;
if (oid != 0) {
urpStub* stub = new urpStub(conn);
urpStub* stub = new urpStub(man);
broker->RegisterStubWithOID(stub, &oid);
}
m->WriteSimple(&oid, XPTType2bcXPType(type));
@ -345,7 +345,7 @@ urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
m->WriteSimple(&arraySize,bc_T_U32);
char *current = *(char**)data;
for (int i = 0; i < arraySize; i++) {
ReadElement(param,datumType.TagPart(),interfaceInfo, message, methodIndex, allocator, m, broker, conn);
ReadElement(param,datumType.TagPart(),interfaceInfo, message, methodIndex, allocator, m, broker, man);
}
} else {
size_t length = 0;
@ -368,7 +368,7 @@ urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
}
nsresult
urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpConnection* conn) {
urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpManager* man) {
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
bcIMarshaler* m = call->GetMarshaler();
int i;
@ -384,7 +384,7 @@ urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info,
}
rv = ReadElement(&param, param.GetType().TagPart(), interfaceInfo,
message, methodIndex, allocator, m, orb, conn);
message, methodIndex, allocator, m, orb, man);
if(NS_FAILED(rv)) {
delete allocator;
delete m;

View File

@ -6,6 +6,7 @@
#include "bcDefs.h"
#include "urpTransport.h"
#include "bcIORB.h"
#include "urpManager.h"
#include "nsHashtable.h"
@ -34,7 +35,7 @@ public:
urpMarshalToolkit(PRBool isClient);
~urpMarshalToolkit();
nsresult ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpConnection* conn);
nsresult ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpManager* man);
nsresult WriteParams(bcICall *call, PRUint32 paramCount, const nsXPTMethodInfo * info, nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex);
void WriteType(bcIID iid, urpPacket* message);
@ -54,7 +55,7 @@ private:
nsresult ReadElement(nsXPTParamInfo * param, uint8 type,
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
PRUint16 methodIndex, bcIAllocator * allocator,
bcIMarshaler* m, bcIORB *orb, urpConnection* conn);
bcIMarshaler* m, bcIORB *orb, urpManager* man);
bcXPType XPTType2bcXPType(uint8 type);
};

View File

@ -30,13 +30,13 @@
#include "urpManager.h"
urpStub::urpStub(urpConnection* conn) {
manager = new urpManager(PR_TRUE, nsnull, conn);
//here zavodim condWait i peredaem v urpManager
urpStub::urpStub(urpManager* man) {
manager = man;
}
urpStub::~urpStub() {
printf("destructor of urpStub\n");
if(manager)
delete manager;
}
@ -63,16 +63,21 @@ void urpStub::Dispatch(bcICall *call) {
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid, (const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
printf("ThreadID is written %d\n",paramCount);
PRMonitor* mon = PR_NewMonitor();
PR_EnterMonitor(mon);
manager->SetCall(call, mon);
printf("ThreadID is written %d %p %p %p %p\n",paramCount, call, mon, manager, this);
nsresult rv = manager->SetCall(call, mon);
if(NS_FAILED(rv)) {
printf("Error of SetCall in method Dispatch\n");
exit(-1);
}
manager->SendUrpRequest(oid, iid, mid, interfaceInfo, call, paramCount,
info);
if(NS_FAILED(PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT))) {
printf("Can't wait on cond var\n");
exit(-1);
}
rv = manager->RemoveCall();
PR_ExitMonitor(mon);
PR_DestroyMonitor(mon);
}

View File

@ -30,7 +30,7 @@
class urpStub : public bcIStub {
public:
urpStub(urpConnection* conn);
urpStub(urpManager* man);
virtual ~urpStub();
virtual void Dispatch(bcICall *call) ;
private: