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
Родитель 2cc4fc61de
Коммит e138d3f3ae
23 изменённых файлов: 386 добавлений и 529 удалений

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

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

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

@ -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;
}

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

@ -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

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

@ -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;
}

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

@ -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

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

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

@ -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

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

@ -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() {
}

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

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

@ -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)

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

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

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

@ -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 \

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

@ -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

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

@ -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);
/*******************************************/

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

@ -1,239 +0,0 @@
/* -*- 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):
* Serge Pikalev <sep@sparc.spb.su>
*
*/
#include <stdio.h>
#include <string.h>
#include "llTransport.h"
#include "private/pprio.h"
// ========== llTransport def ==========
char * llTransport::ParseParam( char *in_str, char *param_name )
{
// move point to "=<value>,<something>" string
char *value = strstr( in_str, param_name ) + strlen(param_name);
if( (value == NULL) || (*value != '=') ) {
return NULL;
}
value++; // move to "<value>,<something>" string
// extract value
char *valueend = strpbrk( value, ",;" );
if( valueend == NULL ) for( valueend = value; *valueend != 0; valueend++ );
int valuesize = valueend - value;
char *retvalue = (char*)PR_Malloc( valuesize + 1 );
memcpy( retvalue, value, valuesize ); retvalue[valuesize] = 0;
return retvalue;
}
// ========== llConnection default destructor ==========
llConnection::~llConnection()
{
}
// ========== llSocketConnection ==========
llSocketConnection::~llSocketConnection()
{
PR_Close(socket);
}
PRInt32 llSocketConnection::Read( void *buf, PRInt32 amount )
{
return PR_Recv( socket, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT );
}
PRInt32 llSocketConnection::Write( void *buf, PRInt32 amount )
{
return PR_Send( socket, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT );
}
// ========== llTCPTransport ==========
static PRStatus fill_addr_by_name( char *hostname,
PRUint16 port,
PRNetAddr *addr )
{
PRStatus status;
PRIntn result;
PRHostEnt hostentry;
char buf[PR_NETDB_BUF_SIZE];
status = PR_GetHostByName( hostname, buf, PR_NETDB_BUF_SIZE, &hostentry );
if( status == PR_FAILURE ) {
return PR_FAILURE;
}
result = PR_EnumerateHostEnt( 0, &hostentry, port, addr );
if( result == 0 ) {
return PR_FAILURE;
}
return PR_SUCCESS;
}
static PRFileDesc *create_socket( PRUint16 family )
{
switch( family )
{
case AF_INET: return PR_NewTCPSocket();
case AF_UNIX: return (PRFileDesc *)PR_Socket( AF_UNIX, SOCK_STREAM, 0 );
}
return NULL;
}
PRStatus llTCPTransport::Open( char *name, llSideType type )
{
PRStatus status;
PRSocketOptionData sopt;
this->type = type;
char *host = ParseParam( name, "host" );
char *portStr = ParseParam( name, "port" );
PRUint16 port = atoi( portStr );
if( type==llServer ) // prepare to accept
{
fd = create_socket( AF_INET );
if ( fd == NULL ) {
status = PR_FAILURE;
}
else
{
sopt.option = PR_SockOpt_Reuseaddr;
sopt.value.reuse_addr = PR_TRUE;
PR_SetSocketOption( fd, &sopt );
addr.inet.family = AF_INET;
addr.inet.port = port;
addr.inet.ip = PR_htonl(INADDR_ANY);
status = PR_Bind( fd, &addr );
if( status == PR_SUCCESS ) PR_Listen( fd, 5 );
}
PR_Free( host );
PR_Free( portStr );
return status;
}
if( type == llClient ) // prepare to connect
{
status = fill_addr_by_name( host, port, &addr );
// free allocated mem
PR_Free( host );
PR_Free( portStr );
return status;
}
return PR_FAILURE;
}
PRStatus llTCPTransport::Close( void )
{
return PR_Close( fd );
}
llConnection * llTCPTransport::ProvideConnection( void )
{
PRSocketOptionData sopt;
PRFileDesc *socket;
if( type == llServer )
{
// fd is constant
socket = PR_Accept( fd, &addr, PR_INTERVAL_NO_TIMEOUT );
if ( socket == NULL ) {
return NULL;
}
} else
if( type == llClient )
{
// addr is constant
socket = create_socket( addr.raw.family );
if ( socket == NULL ) {
return NULL;
}
PRStatus status = PR_Connect( socket, &addr, PR_INTERVAL_NO_TIMEOUT );
if ( status == PR_FAILURE ) {
return NULL;
}
}
// set option to blocking read/write ops
sopt.option = PR_SockOpt_Nonblocking;
sopt.value.non_blocking = PR_FALSE;
PR_SetSocketOption( socket, &sopt );
llSocketConnection *cnt = new llSocketConnection();
cnt->socket = socket;
return cnt;
}
// ========== llPipeTransport ==========
PRStatus llPipeTransport::Open( char *name, llSideType type )
{
PRStatus status;
PRSocketOptionData sopt;
this->type = type;
const char prefix[] = "/tmp/OSL_PIPE_";
char *path = ParseParam( name, "name" );
addr.local.family = AF_UNIX;
strcpy( addr.local.path, prefix );
strcpy( addr.local.path+sizeof(prefix)-1, path );
PR_Free( path );
if( type == llServer ) // prepare to accept
{
fd = create_socket( AF_UNIX );
if( fd == NULL ) return PR_FAILURE;
sopt.option = PR_SockOpt_Reuseaddr;
sopt.value.reuse_addr = PR_TRUE;
PR_SetSocketOption( fd, &sopt );
status = PR_Bind( fd, &addr );
if ( status == PR_FAILURE ) {
return PR_FAILURE;
}
PR_Listen( fd, 5 );
return PR_SUCCESS;
}
if ( type == llClient ) {
return PR_SUCCESS;
}
return PR_FAILURE;
}
PRStatus llPipeTransport::Close( void )
{
PRNetAddr addr;
PR_GetSockName( fd, &addr );
PR_Delete( addr.local.path );
return PR_Close( fd );
}

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

@ -1,182 +0,0 @@
/* -*- 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):
* Serge Pikalev <sep@sparc.spb.su>
*
*/
#include <stdio.h>
#include <nspr.h>
#include <prmem.h>
#include <prnetdb.h>
#include "urpPacket.h"
// Constructor/Destructor
urpPacket::urpPacket() {
buff = NULL;
buffSize = 0;
messageCount = 0;
point = 0;
}
urpPacket::~urpPacket() {
PR_Free( buff );
}
// property section
void urpPacket::SetMessageCount( int msgCount ){
messageCount = msgCount;
}
int urpPacket::GetMessageCount( void ){
return messageCount;
}
// read/write section
void urpPacket::WriteBytes( void *bytes, int size ){
if ( buffSize - point < size ) {
buff = PR_Realloc( buff, buffSize += ((size<BUFSIZ)?BUFSIZ:size) );
}
memcpy( (char *)buff+point, bytes, size ); point += size;
}
//
// Write Section =======================================
//
void urpPacket::WriteByte( char byteValue ){
WriteBytes( &byteValue, 1 );
}
void urpPacket::WriteBoolean( char boolValue ){
WriteBytes( &boolValue, 1 );
}
// Write Section 2 bytes
void urpPacket::WriteShort( short shortValue ){
shortValue = PR_htons( shortValue ); // host to network
WriteBytes( &shortValue, 2 );
}
// Write Section 4 bytes
void urpPacket::WriteInt( int intValue ){
intValue = PR_htons( intValue );
WriteBytes( &intValue, 4 );
}
void urpPacket::WriteLong( long longValue ){
longValue = PR_htons( longValue );
WriteBytes( &longValue, 4 );
}
void urpPacket::WriteFloat( float floatValue ){
WriteBytes( &floatValue, 4 );
}
// Write Section 8 bytes
void urpPacket::WriteDouble( double doubleValue ){
WriteBytes( &doubleValue, 8 );
}
// Write Section arrays
void urpPacket::WriteOctetStream( char* stream, int size ){
if ( size < 0xff ) {
WriteByte( (char)size );
} else { /* write compressed */
WriteByte( 0xff );
WriteLong( size );
}
WriteBytes( stream, size );
}
void urpPacket::WriteString( char* str, int size ) {
// probably something to do about string
// ...
WriteOctetStream( str, size );
}
//
// Read Section =======================================
//
// read 1 byte
char urpPacket::ReadByte( void ) {
return ((char *)buff)[point++];
}
char urpPacket::ReadBoolean( void ) {
return ((char *)buff)[point++];
}
// read 2 bytes
short urpPacket::ReadShort( void ) {
short retShort;
memcpy( &retShort, ((char *)buff)+point, 2 ); point += 2;
return PR_ntohs(retShort);
}
int urpPacket::ReadInt( void ) {
int retInt;
memcpy( &retInt, ((char *)buff)+point, 4 ); point += 4;
return PR_ntohl(retInt);
}
long urpPacket::ReadLong( void ) {
long retLong;
memcpy( &retLong, ((char *)buff)+point, 4 ); point += 4;
return PR_ntohl(retLong);
}
float urpPacket::ReadFloat( void ) {
float retFloat;
memcpy( &retFloat, ((char *)buff)+point, 4 ); point += 4;
return retFloat;
}
// read 8 bytes
double urpPacket::ReadDouble( void ) {
double retDouble;
memcpy( &retDouble, ((char *)buff)+point, 8 ); point += 8;
return retDouble;
}
char * urpPacket::ReadOctetStream( int& size ) {
// read packed size
if( ((char *)buff)[point] == (char)0xff ) {
point++; size = ReadInt();
}
else size = (int)ReadByte();
// read array
char *retStream = (char *)PR_Malloc( size+1 ); // add 1 byte for string needs
memcpy( retStream, ((char *)buff)+point, size );
point += size;
return retStream;
}
char * urpPacket::ReadString( int& size ) {
char * retString = ReadOctetStream( size );
// probaly something to do about string (convert from UTF8)
retString[size] = 0; // make string null-terminated
// ...
return retString;
}

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

@ -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;
}

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

@ -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,

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

@ -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;

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

@ -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);
};

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

@ -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);
}

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

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