*not part of the build*
urp connect update git-svn-id: svn://10.0.0.236/trunk@96522 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -18,7 +18,8 @@
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
# Serge Pikalev <sep@sparc.spb.su>
|
||||
#
|
||||
#
|
||||
DEPTH = ../../../../
|
||||
topsrcdir = $(DEPTH)
|
||||
@@ -33,18 +34,19 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
DIRS = transport test
|
||||
DIRS = transport test loader
|
||||
|
||||
CXXFLAGS += -I$(CONNECT_SRC)/public -I$(topsrcdir)/java/xpcom/xpcom -Itransport
|
||||
CXXFLAGS += -I$(CONNECT_SRC)/public -I$(topsrcdir)/java/xpcom/xpcom -Itransport
|
||||
CPPSRCS = \
|
||||
urpMarshalToolkit.cpp \
|
||||
urpManager.cpp \
|
||||
urpStub.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
urpMarshalToolkit.h \
|
||||
urpStub.h \
|
||||
urpManager.h \
|
||||
$(NULL)
|
||||
|
||||
LIBS = \
|
||||
-lxpcom \
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
# Serge Pikalev <sep@sparc.spb.su>
|
||||
#
|
||||
#
|
||||
DEPTH = ../../../../
|
||||
topsrcdir = $(DEPTH)
|
||||
@@ -33,18 +34,19 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
DIRS = transport test
|
||||
DIRS = transport test loader
|
||||
|
||||
CXXFLAGS += -I$(CONNECT_SRC)/public -I$(topsrcdir)/java/xpcom/xpcom -Itransport
|
||||
CXXFLAGS += -I$(CONNECT_SRC)/public -I$(topsrcdir)/java/xpcom/xpcom -Itransport
|
||||
CPPSRCS = \
|
||||
urpMarshalToolkit.cpp \
|
||||
urpManager.cpp \
|
||||
urpStub.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
urpMarshalToolkit.h \
|
||||
urpStub.h \
|
||||
urpManager.h \
|
||||
$(NULL)
|
||||
|
||||
LIBS = \
|
||||
-lxpcom \
|
||||
|
||||
50
mozilla/java/xpcom/urp/src/loader/Makefile.in
Normal file
50
mozilla/java/xpcom/urp/src/loader/Makefile.in
Normal file
@@ -0,0 +1,50 @@
|
||||
#!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 Sun Microsystems,
|
||||
# Inc. Portions created by Sun are
|
||||
# Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Sergey Lunegov <lsv@sparc.spb.su>
|
||||
#
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
MODULE = urploader
|
||||
LIBRARY_NAME = urploader
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
urpComponentLoader.cpp \
|
||||
urpComponentFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
../transport/llTransport.o ../transport/urpPacket.o \
|
||||
../transport/urpTransport.o \
|
||||
../urpStub.o \
|
||||
../urpMarshalToolkit.o \
|
||||
../urpManager.o
|
||||
|
||||
CXXFLAGS += -I../transport/ $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
99
mozilla/java/xpcom/urp/src/loader/urpComponentFactory.cpp
Normal file
99
mozilla/java/xpcom/urp/src/loader/urpComponentFactory.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* -*- 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):
|
||||
* Sergey Lunegov <lsv@sparc.spb.su>
|
||||
*/
|
||||
#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;
|
||||
|
||||
urpComponentFactory::urpComponentFactory(const char *_location, const nsCID &aCID) {
|
||||
NS_INIT_ISUPPORTS();
|
||||
location = nsCRT::strdup(_location);
|
||||
aClass = aCID;
|
||||
}
|
||||
|
||||
urpComponentFactory::~urpComponentFactory() {
|
||||
nsCRT::free((char*)location);
|
||||
}
|
||||
|
||||
/* void CreateInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result);
|
||||
*/
|
||||
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);
|
||||
printf("--urpComponentFactory::CreateInstance end\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void LockFactory (in PRBool lock); */
|
||||
NS_IMETHODIMP urpComponentFactory::LockFactory(PRBool lock)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
mozilla/java/xpcom/urp/src/loader/urpComponentFactory.h
Normal file
39
mozilla/java/xpcom/urp/src/loader/urpComponentFactory.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- 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):
|
||||
* Sergey Lunegov <lsv@sparc.spb.su>
|
||||
*/
|
||||
#ifndef __urpComponentFactory_h
|
||||
#define __urpComponentFactory_h
|
||||
#include "nsIFactory.h"
|
||||
|
||||
class urpComponentFactory : public nsIFactory {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFACTORY
|
||||
urpComponentFactory(const char *location, const nsCID &aCID);
|
||||
virtual ~urpComponentFactory();
|
||||
private:
|
||||
char *location;
|
||||
nsCID aClass;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
441
mozilla/java/xpcom/urp/src/loader/urpComponentLoader.cpp
Normal file
441
mozilla/java/xpcom/urp/src/loader/urpComponentLoader.cpp
Normal file
@@ -0,0 +1,441 @@
|
||||
/* -*- 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):
|
||||
* Sergey Lunegov <lsv@sparc.spb.su>
|
||||
*/
|
||||
|
||||
/*
|
||||
A bunch of stuff was copied from mozJSComponentLoader.cpp
|
||||
*/
|
||||
#include <fstream.h>
|
||||
#include "nsICategoryManager.h"
|
||||
#include "urpComponentLoader.h"
|
||||
#include "urpComponentFactory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
|
||||
const char urpComponentTypeName[] = URPCOMPONENTTYPENAME;
|
||||
|
||||
/* XXX export properly from libxpcom, for now this will let Mac build */
|
||||
#ifdef RHAPSODY
|
||||
extern const char fileSizeValueName[]; // = "FileSize";
|
||||
extern const char lastModValueName[]; // = "LastModTimeStamp";
|
||||
extern const char xpcomKeyName[]; // = "Software/Mozilla/XPCOM";
|
||||
#else
|
||||
const char fileSizeValueName[] = "FileSize";
|
||||
const char lastModValueName[] = "LastModTimeStamp";
|
||||
const char xpcomKeyName[] = "software/mozilla/XPCOM/components";
|
||||
#endif
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS(urpComponentLoader,NS_GET_IID(nsIComponentLoader));
|
||||
|
||||
urpComponentLoader::urpComponentLoader()
|
||||
: mCompMgr(NULL),
|
||||
|
||||
mXPCOMKey(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
printf("--urpComponentLoader::urpComponentLoader \n");
|
||||
}
|
||||
|
||||
urpComponentLoader::~urpComponentLoader() { //nb
|
||||
printf("--urpComponentLoader::~urpComponentLoader \n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the factory for a given component.
|
||||
*/
|
||||
/* nsIFactory getFactory (in nsIIDRef aCID, in string aLocation, in string aType); */
|
||||
NS_IMETHODIMP urpComponentLoader::GetFactory(const nsIID & aCID, const char *aLocation, const char *aType, nsIFactory **_retval) {
|
||||
printf("--urpComponentLoader::GetFactory \n");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
#ifdef DEBUG
|
||||
char *cidString = aCID.ToString();
|
||||
fprintf(stderr, "--urpComponentLoader::GetFactory(%s,%s,%s)\n", cidString, aLocation, aType);
|
||||
delete [] cidString;
|
||||
#endif
|
||||
nsIFactory *f = new urpComponentFactory(aLocation, aCID);
|
||||
*_retval = f;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the loader.
|
||||
*
|
||||
* We use nsISupports here because nsIRegistry isn't IDLized yet.
|
||||
*/
|
||||
/* void init (in nsIComponentManager aCompMgr, in nsISupports aRegistry); */
|
||||
NS_IMETHODIMP urpComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) {
|
||||
printf("--urpComponentLoader::Init \n");
|
||||
nsresult rv;
|
||||
mCompMgr = aCompMgr;
|
||||
mRegistry = do_QueryInterface(aReg, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mRegistry->GetSubtree(nsIRegistry::Common, xpcomKeyName,
|
||||
&mXPCOMKey);
|
||||
if (NS_FAILED(rv))
|
||||
/* if we can't get the XPCOM key, just skip all registry ops */
|
||||
mRegistry = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a component of the appropriate type is registered,
|
||||
* to give the component loader an opportunity to do things like
|
||||
* annotate the registry and such.
|
||||
*/
|
||||
/* void onRegister (in nsIIDRef aCID, in string aType, in string aClassName, in string aContractID, in string aLocation, in boolean aReplace, in boolean aPersist); */
|
||||
NS_IMETHODIMP urpComponentLoader::OnRegister(const nsIID & aCID, const char *aType, const char *aClassName, const char *aContractID, const char *aLocation, PRBool aReplace, PRBool aPersist) { //nb
|
||||
printf("--urpComponentLoader::OnRegister \n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* AutoRegister components in the given directory.
|
||||
*/
|
||||
NS_IMETHODIMP urpComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsIFile *aDirectory) {
|
||||
printf("--urpComponentLoader::AutoRegisterComponents \n");
|
||||
return RegisterComponentsInDir(aWhen,aDirectory);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP urpComponentLoader::AutoUnregisterComponent(PRInt32 when,
|
||||
nsIFile *component,
|
||||
PRBool *unregistered) {
|
||||
//nb need to impelement
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult urpComponentLoader::RegisterComponentsInDir(PRInt32 when, nsIFile *dir)
|
||||
{
|
||||
nsresult rv;
|
||||
PRBool isDir;
|
||||
|
||||
if (NS_FAILED(rv = dir->IsDirectory(&isDir)))
|
||||
return rv;
|
||||
|
||||
if (!isDir)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Create a directory iterator
|
||||
nsCOMPtr<nsISimpleEnumerator> dirIterator;
|
||||
rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// whip through the directory to register every file
|
||||
nsIFile *dirEntry = NULL;
|
||||
PRBool more = PR_FALSE;
|
||||
|
||||
rv = dirIterator->HasMoreElements(&more);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
while (more == PR_TRUE)
|
||||
{
|
||||
rv = dirIterator->GetNext((nsISupports**)&dirEntry);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = dirEntry->IsDirectory(&isDir);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (isDir == PR_TRUE)
|
||||
{
|
||||
// This is a directory. Grovel for components into the directory.
|
||||
rv = RegisterComponentsInDir(when, dirEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRBool registered;
|
||||
// This is a file. Try to register it.
|
||||
rv = AutoRegisterComponent(when, dirEntry, ®istered);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(dirEntry);
|
||||
}
|
||||
rv = dirIterator->HasMoreElements(&more);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* AutoRegister the given component.
|
||||
*
|
||||
* Returns true if the component was registered, false if it couldn't
|
||||
* attempt to register the component (wrong type) and ``throws'' an
|
||||
* NS_FAILED code if there was an error during registration.
|
||||
*/
|
||||
/* boolean autoRegisterComponent (in long aWhen, in nsIFile aComponent); */
|
||||
|
||||
/* copied from mozJSComponentLoader.cpp */
|
||||
NS_IMETHODIMP urpComponentLoader::AutoRegisterComponent(PRInt32 when, nsIFile *component, PRBool *registered) {
|
||||
//printf("--urpComponentLoader::AutoRegisterComponent \n");
|
||||
nsresult rv;
|
||||
if (!registered)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
const char javaExtension[] = ".urp.info";
|
||||
int javaExtensionLen = 9;
|
||||
nsXPIDLCString leafName;
|
||||
|
||||
*registered = PR_FALSE;
|
||||
|
||||
/* we only do files */
|
||||
PRBool isFile = PR_FALSE;
|
||||
if (NS_FAILED(rv = component->IsFile(&isFile)) || !isFile)
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = component->GetLeafName(getter_Copies(leafName))))
|
||||
return rv;
|
||||
int len = PL_strlen(leafName);
|
||||
|
||||
/* if it's not javaExtension return now */
|
||||
if (len < javaExtensionLen || // too short
|
||||
PL_strcasecmp(leafName + len - javaExtensionLen, javaExtension))
|
||||
return NS_OK;
|
||||
|
||||
printf("--urpComponentLoader: registering urpComponent component %s\n",(const char *)leafName);
|
||||
rv = AttemptRegistration(component, PR_FALSE);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
printf("registered module %s\n", (const char *)leafName);
|
||||
else if (rv == NS_ERROR_FACTORY_REGISTER_AGAIN)
|
||||
printf("deferred module %s\n", (const char *)leafName);
|
||||
else
|
||||
printf("failed to register %s\n", (const char *)leafName);
|
||||
*registered = (PRBool) NS_SUCCEEDED(rv);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
nsresult urpComponentLoader::AttemptRegistration(nsIFile *component,
|
||||
PRBool deferred) {
|
||||
nsXPIDLCString registryLocation;
|
||||
nsresult rv;
|
||||
nsIModule *module;
|
||||
|
||||
rv = mCompMgr->RegistryLocationForSpec(component,
|
||||
getter_Copies(registryLocation));
|
||||
nsXPIDLCString str;
|
||||
component->GetPath(getter_Copies(str));
|
||||
const char* location = nsCRT::strdup(str);
|
||||
ifstream in(location);
|
||||
char cidStr[500], contractid[1000], desc[1000];
|
||||
in.getline(cidStr,1000);
|
||||
in.getline(contractid,1000);
|
||||
in.getline(desc,1000);
|
||||
printf("%s %s %s", cidStr, contractid, desc);
|
||||
nsCID cid;
|
||||
cid.Parse((const char *)cidStr);
|
||||
mCompMgr->RegisterComponentWithType(cid, desc, contractid, component, registryLocation, PR_TRUE, PR_TRUE, urpComponentTypeName);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
/* no need to check registry data on deferred reg */
|
||||
SetRegistryInfo(registryLocation, component);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult urpComponentLoader::SetRegistryInfo(const char *registryLocation,
|
||||
nsIFile *component)
|
||||
{
|
||||
if (!mRegistry.get())
|
||||
return NS_OK; // silent failure
|
||||
|
||||
nsresult rv;
|
||||
nsRegistryKey key;
|
||||
|
||||
rv = mRegistry->AddSubtreeRaw(mXPCOMKey, registryLocation, &key);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRInt64 modDate;
|
||||
|
||||
if (NS_FAILED(rv = component->GetLastModificationDate(&modDate)) ||
|
||||
NS_FAILED(rv = mRegistry->SetLongLong(key, lastModValueName, &modDate)))
|
||||
return rv;
|
||||
|
||||
PRInt64 fileSize;
|
||||
if (NS_FAILED(rv = component->GetFileSize(&fileSize)) ||
|
||||
NS_FAILED(rv = mRegistry->SetLongLong(key, fileSizeValueName, &fileSize)))
|
||||
return rv;
|
||||
printf("SetRegistryInfo(%s) => (%d,%d)\n", registryLocation,
|
||||
(int)modDate, (int)fileSize);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool urpComponentLoader::HasChanged(const char *registryLocation, nsIFile *component) {
|
||||
/* if we don't have a registry handle, force registration of component */
|
||||
if (!mRegistry)
|
||||
return PR_TRUE;
|
||||
|
||||
nsRegistryKey key;
|
||||
if (NS_FAILED(mRegistry->GetSubtreeRaw(mXPCOMKey, registryLocation, &key)))
|
||||
return PR_TRUE;
|
||||
|
||||
/* check modification date */
|
||||
PRInt64 regTime, lastTime;
|
||||
if (NS_FAILED(mRegistry->GetLongLong(key, lastModValueName, ®Time)))
|
||||
return PR_TRUE;
|
||||
|
||||
if (NS_FAILED(component->GetLastModificationDate(&lastTime)) || LL_NE(lastTime, regTime))
|
||||
return PR_TRUE;
|
||||
|
||||
/* check file size */
|
||||
PRInt64 regSize;
|
||||
if (NS_FAILED(mRegistry->GetLongLong(key, fileSizeValueName, ®Size)))
|
||||
return PR_TRUE;
|
||||
PRInt64 size;
|
||||
if (NS_FAILED(component->GetFileSize(&size)) || LL_NE(size,regSize) )
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any deferred (NS_ERROR_FACTORY_REGISTER_AGAIN) components.
|
||||
* Return registered-any-components?
|
||||
*/
|
||||
/* boolean registerDeferredComponents (in long aWhen); */
|
||||
NS_IMETHODIMP urpComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, PRBool *aRegistered) {
|
||||
printf("--urpComponentLoader::RegisterDeferredComponents \n");
|
||||
nsresult rv;
|
||||
*aRegistered = PR_FALSE;
|
||||
PRUint32 count;
|
||||
rv = mDeferredComponents.Count(&count);
|
||||
printf("mJCL: registering deferred (%d)\n", count);
|
||||
if (NS_FAILED(rv) || !count)
|
||||
return NS_OK;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
nsCOMPtr<nsIFile> component;
|
||||
|
||||
rv = mDeferredComponents.GetElementAt(i, getter_AddRefs(supports));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
component = do_QueryInterface(supports, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
rv = AttemptRegistration(component, PR_TRUE /* deferred */);
|
||||
if (rv != NS_ERROR_FACTORY_REGISTER_AGAIN) {
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*aRegistered = PR_TRUE;
|
||||
mDeferredComponents.RemoveElementAt(i);
|
||||
}
|
||||
}
|
||||
rv = mDeferredComponents.Count(&count);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (*aRegistered)
|
||||
printf("mJCL: registered deferred, %d left\n", count);
|
||||
else
|
||||
printf("mJCL: didn't register any components, %d left\n", count);
|
||||
}
|
||||
/* are there any fatal errors? */
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unload all components that are willing.
|
||||
*/
|
||||
/* void unloadAll (in long aWhen); */
|
||||
NS_IMETHODIMP urpComponentLoader::UnloadAll(PRInt32 aWhen) { //nb
|
||||
printf("--urpComponentLoader::UnloadAll \n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
/* XXX this should all be data-driven, via NS_IMPL_GETMODULE_WITH_CATEGORIES */
|
||||
static NS_METHOD
|
||||
RegisterRemoteLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
printf("--URPLoader got registered\n");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString previous;
|
||||
rv = catman->AddCategoryEntry("component-loader", urpComponentTypeName,
|
||||
URP_COMPONENTLOADER_ContractID,
|
||||
PR_TRUE, PR_TRUE, getter_Copies(previous));
|
||||
if(NS_FAILED(rv))
|
||||
printf("Adding of remote-comp-loader is failed\n");
|
||||
else
|
||||
printf("Adding of remote-comp-loader is succeseded\n");
|
||||
nsXPIDLCString urpLoader;
|
||||
rv = catman->GetCategoryEntry("component-loader", urpComponentTypeName,
|
||||
getter_Copies(urpLoader));
|
||||
if (NS_FAILED(rv))
|
||||
printf("didn't got category entry\n");
|
||||
else
|
||||
printf("got category entry\n");
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
UnregisterRemoteLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
const char *registryLocation, const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString urpLoader;
|
||||
rv = catman->GetCategoryEntry("component-loader", urpComponentTypeName,
|
||||
getter_Copies(urpLoader));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// 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));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(urpComponentLoader);
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "URP component loader", URP_COMPONENTLOADER_CID,
|
||||
URP_COMPONENTLOADER_ContractID,
|
||||
urpComponentLoaderConstructor,
|
||||
RegisterRemoteLoader, UnregisterRemoteLoader }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("URP component loader", components);
|
||||
|
||||
|
||||
|
||||
65
mozilla/java/xpcom/urp/src/loader/urpComponentLoader.h
Normal file
65
mozilla/java/xpcom/urp/src/loader/urpComponentLoader.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*- 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):
|
||||
* Sergey Lunegov <lsv@sparc.spb.su>
|
||||
*/
|
||||
#ifndef _urpComponentLoader_h
|
||||
#define _urpComponentLoader_h
|
||||
#include "nsIComponentLoader.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsSupportsArray.h"
|
||||
|
||||
#define URP_COMPONENTLOADER_ContractID \
|
||||
"@mozilla.org/blackwood/starconnect/remote-component-loader;1"
|
||||
|
||||
/* 0d6b5198-1dd2-11b2-b2f0-ed49ba755db8 */
|
||||
#define URP_COMPONENTLOADER_CID \
|
||||
{ 0xdcc5322f, 0x06e5, 0x4a3f, \
|
||||
{0x92, 0xe8, 0xde, 0xe6, 0x8f, 0x26, 0x0d, 0x8f }}
|
||||
|
||||
#define URPCOMPONENTTYPENAME "application/remote-component"
|
||||
|
||||
class urpComponentLoader : public nsIComponentLoader {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOMPONENTLOADER
|
||||
|
||||
urpComponentLoader();
|
||||
virtual ~urpComponentLoader();
|
||||
protected:
|
||||
nsCOMPtr<nsIRegistry> mRegistry;
|
||||
nsCOMPtr<nsIComponentManager> mCompMgr;
|
||||
nsRegistryKey mXPCOMKey;
|
||||
nsSupportsArray mDeferredComponents;
|
||||
|
||||
nsresult RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
|
||||
nsresult AttemptRegistration(nsIFile *component, PRBool deferred);
|
||||
PRBool HasChanged(const char *registryLocation, nsIFile *component);
|
||||
nsresult SetRegistryInfo(const char *registryLocation, nsIFile *component);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
DIRS = client
|
||||
|
||||
LIBRARY_NAME = urpTest
|
||||
MODULE = urpTest
|
||||
IS_COMPONENT = 1
|
||||
@@ -41,24 +43,23 @@ CXXFLAGS += -I$(topsrcdir)/java/xpcom/xpcom -I../transport -I$(JDKHOME)/
|
||||
|
||||
CPPSRCS = \
|
||||
urpTestImpl.cpp \
|
||||
urpTestImplFactory.cpp \
|
||||
server.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LIBS += \
|
||||
bcorb bcxpcomstubs \
|
||||
$(NULL)
|
||||
|
||||
LIBS = -L./ -L$(DIST)/bin/components/ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
|
||||
LIBS = -L./ $(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 \
|
||||
-L../../java/src
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
../transport/llTransport.o ../transport/urpPacket.o \
|
||||
../transport/urpTransport.o \
|
||||
../urpStub.o \
|
||||
../urpMarshalToolkit.o \
|
||||
../urpManager.o \
|
||||
$(NULL)
|
||||
|
||||
|
||||
7
mozilla/java/xpcom/urp/src/test/README
Normal file
7
mozilla/java/xpcom/urp/src/test/README
Normal file
@@ -0,0 +1,7 @@
|
||||
1. cd in $(MOZILLA_FIVE_HOME)/java/xpcom/urp/src; run 'gmake'
|
||||
|
||||
2. for server running : cd $(MOZILLA_FIVE_HOME)/dist/bin;
|
||||
run 'server socket,host=YourHost,port=YourPort'
|
||||
|
||||
6. for client running: cd $(MOZILLA_FIVE_HOME)/dist/bin;
|
||||
run 'client socket,host=YourHost,port=YourPort'
|
||||
101
mozilla/java/xpcom/urp/src/test/Simple_Server.cpp
Normal file
101
mozilla/java/xpcom/urp/src/test/Simple_Server.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIPref.h"
|
||||
#include "plevent.h"
|
||||
#include "prmem.h"
|
||||
#include "prnetdb.h"
|
||||
#include "prthread.h"
|
||||
|
||||
#include "urpManager.h"
|
||||
#include "urpTransport.h"
|
||||
|
||||
#include "urpITest.h"
|
||||
#include "bcIORBComponent.h"
|
||||
#include "bcORBComponentCID.h"
|
||||
#include "urpTestImpl.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "bcIXPCOMStubsAndProxies.h"
|
||||
#include "bcXPCOMStubsAndProxiesCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
|
||||
|
||||
struct localThreadArg {
|
||||
urpManager *mgr;
|
||||
urpConnection *conn;
|
||||
localThreadArg( urpManager *mgr, urpConnection *conn ) {
|
||||
this->mgr = mgr;
|
||||
this->conn = conn;
|
||||
}
|
||||
};
|
||||
|
||||
void thread_start_server( void *arg )
|
||||
{
|
||||
urpManager *manager = ((localThreadArg *)arg)->mgr;
|
||||
urpConnection *connection = ((localThreadArg *)arg)->conn;
|
||||
nsresult rv = manager->ReadMessage( connection, PR_FALSE );
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
|
||||
char *connectString = "socket,host=localhost,port=2009";
|
||||
if( argc == 2 ) connectString = argv[1];
|
||||
|
||||
nsresult rv = NS_InitXPCOM(NULL, NULL);
|
||||
NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" );
|
||||
|
||||
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("bcXPCOMStubsAndProxie failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
bcIStub *stub = nsnull;
|
||||
urpITest *object = new urpTestImpl();
|
||||
object->AddRef();
|
||||
urpITest *proxy = nsnull;
|
||||
xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
|
||||
bcOID oid = orb->RegisterStub(stub);
|
||||
|
||||
urpTransport* trans = new urpAcceptor();
|
||||
PRStatus status = trans->Open(connectString);
|
||||
if(status == PR_SUCCESS) printf("succes %ld\n",oid);
|
||||
else printf("failed\n");
|
||||
object->AddRef();
|
||||
urpManager* mngr = new urpManager(PR_FALSE, orb, nsnull);
|
||||
rv = NS_OK;
|
||||
while(NS_SUCCEEDED(rv)) {
|
||||
// rv = mngr->HandleRequest(trans->GetConnection());
|
||||
urpConnection *conn = trans->GetConnection();
|
||||
if( conn != NULL ) {
|
||||
// handle request in new thread
|
||||
localThreadArg *arg = new localThreadArg( mngr, conn );
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start_server,
|
||||
arg,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
if( thr == nsnull ) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIPref.h"
|
||||
#include "plevent.h"
|
||||
#include "prmem.h"
|
||||
#include "prnetdb.h"
|
||||
#include "prthread.h"
|
||||
|
||||
#include "urpManager.h"
|
||||
#include "urpTransport.h"
|
||||
|
||||
#include "urpITest.h"
|
||||
#include "bcIORBComponent.h"
|
||||
#include "bcORBComponentCID.h"
|
||||
#include "urpTestImpl.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "bcIXPCOMStubsAndProxies.h"
|
||||
#include "bcXPCOMStubsAndProxiesCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
|
||||
static NS_DEFINE_CID(compManag, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
struct localThreadArg {
|
||||
urpManager *mgr;
|
||||
urpConnection *conn;
|
||||
localThreadArg( urpManager *mgr, urpConnection *conn ) {
|
||||
this->mgr = mgr;
|
||||
this->conn = conn;
|
||||
}
|
||||
};
|
||||
|
||||
void thread_start_server( void *arg )
|
||||
{
|
||||
urpManager *manager = ((localThreadArg *)arg)->mgr;
|
||||
urpConnection *connection = ((localThreadArg *)arg)->conn;
|
||||
nsresult rv = manager->ReadMessage( connection, PR_FALSE );
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
|
||||
char *connectString = "socket,host=localhost,port=2009";
|
||||
if( argc == 2 ) connectString = argv[1];
|
||||
|
||||
nsresult rv = NS_InitXPCOM(NULL, NULL);
|
||||
NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" );
|
||||
|
||||
(void) nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
|
||||
|
||||
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("bcXPCOMStubsAndProxie failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
bcIStub *stub = nsnull;
|
||||
NS_WITH_SERVICE(nsIComponentManager, mComp, compManag, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("compManager failed\n");
|
||||
return -1;
|
||||
}
|
||||
urpITest *proxy = nsnull;
|
||||
xpcomStubsAndProxies->GetStub((nsISupports*)mComp, &stub);
|
||||
bcOID oid = orb->RegisterStub(stub);
|
||||
|
||||
urpTransport* trans = new urpAcceptor();
|
||||
PRStatus status = trans->Open(connectString);
|
||||
if(status == PR_SUCCESS) printf("succes %ld\n",oid);
|
||||
else printf("failed\n");
|
||||
urpManager* mngr = new urpManager(PR_FALSE, orb, nsnull);
|
||||
rv = NS_OK;
|
||||
while(NS_SUCCEEDED(rv)) {
|
||||
// rv = mngr->HandleRequest(trans->GetConnection());
|
||||
urpConnection *conn = trans->GetConnection();
|
||||
if( conn != NULL ) {
|
||||
// handle request in new thread
|
||||
localThreadArg *arg = new localThreadArg( mngr, conn );
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start_server,
|
||||
arg,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
if( thr == nsnull ) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -41,12 +41,12 @@ CPPSRCS = \
|
||||
client.cpp \
|
||||
$(NULL)
|
||||
|
||||
LIBS = -L./ -L$(DIST)/bin/components/ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
|
||||
LIBS = -L./ $(XPCOM_LIBS) $(NSPR_LIBS) $(EXTRA_DSO_LIBS) \
|
||||
../../urpStub.o \
|
||||
../../urpMarshalToolkit.o \
|
||||
../../urpManager.o \
|
||||
../urpTestImpl.o \
|
||||
../../transport/llTransport.o ../../transport/urpPacket.o \
|
||||
../../transport/urpTransport.o
|
||||
../../transport/urpTransport.o \
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "urpTestImpl.h"
|
||||
#include "urpManager.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "bcORBComponentCID.h"
|
||||
#include "bcIStub.h"
|
||||
#include "urpStub.h"
|
||||
#include "urpITest.h"
|
||||
|
||||
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
@@ -75,12 +76,18 @@ 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;
|
||||
stub = new urpStub(connectString);
|
||||
urpTransport* transport = new urpConnector();
|
||||
PRStatus status = transport->Open(connectString);
|
||||
if(status != PR_SUCCESS) {
|
||||
printf("Error during opening connection\n");
|
||||
exit(-1);
|
||||
}
|
||||
stub = new urpStub(transport->GetConnection());
|
||||
bcOID oid = orb->RegisterStub(stub);
|
||||
printf("---urpTestImpl iid=%s\n",NS_GET_IID(urpITest).ToString());
|
||||
printf("---urpTestImpl oid=%ld iid=%s\n",oid, NS_GET_IID(urpITest).ToString());
|
||||
r = xpcomStubsAndProxies->GetProxy(oid,NS_GET_IID(urpITest),orb,(nsISupports**)&proxy);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--urpTestImpl test failed\n");
|
||||
@@ -97,7 +104,7 @@ nsIInterfaceInfo *interfaceInfo;
|
||||
PRInt32 l1 = 1999;
|
||||
PRInt32 ret;
|
||||
PRInt32 rt;
|
||||
object->Test1(&l1);
|
||||
// object->Test1(&l1);
|
||||
l1 = 1999;
|
||||
proxy->Test1(&l1);
|
||||
printf("--urpTestImpl after Test1 l=%d %d\n",l1,ret);
|
||||
@@ -124,7 +131,7 @@ nsIInterfaceInfo *interfaceInfo;
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
|
||||
}
|
||||
object->Test5(4,valueArray2);
|
||||
// object->Test5(4,valueArray2);
|
||||
printf("after calling object\n");
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
|
||||
@@ -138,7 +145,7 @@ nsIInterfaceInfo *interfaceInfo;
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
proxy->Test6(object);
|
||||
// proxy->Test6(object);
|
||||
/*********************************************/
|
||||
{
|
||||
urpITest *p1;
|
||||
@@ -152,9 +159,11 @@ nsIInterfaceInfo *interfaceInfo;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// trans->Close();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "plevent.h"
|
||||
#include "prmem.h"
|
||||
#include "prnetdb.h"
|
||||
#include "prthread.h"
|
||||
|
||||
#include "urpManager.h"
|
||||
#include "urpTransport.h"
|
||||
@@ -25,6 +26,22 @@
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
|
||||
|
||||
struct localThreadArg {
|
||||
urpManager *mgr;
|
||||
urpConnection *conn;
|
||||
localThreadArg( urpManager *mgr, urpConnection *conn ) {
|
||||
this->mgr = mgr;
|
||||
this->conn = conn;
|
||||
}
|
||||
};
|
||||
|
||||
void thread_start_server( void *arg )
|
||||
{
|
||||
urpManager *manager = ((localThreadArg *)arg)->mgr;
|
||||
urpConnection *connection = ((localThreadArg *)arg)->conn;
|
||||
nsresult rv = manager->ReadMessage( connection, PR_FALSE );
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
|
||||
char *connectString = "socket,host=localhost,port=2009";
|
||||
@@ -46,22 +63,39 @@ printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
|
||||
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
bcIStub *stub = NULL;
|
||||
bcIStub *stub = nsnull;
|
||||
urpITest *object = new urpTestImpl();
|
||||
object->AddRef();
|
||||
urpITest *proxy = NULL;
|
||||
urpITest *proxy = nsnull;
|
||||
xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
|
||||
bcOID oid = orb->RegisterStub(stub);
|
||||
|
||||
urpTransport* trans = new urpAcceptor();
|
||||
PRStatus status = trans->Open(connectString);
|
||||
if(status == PR_SUCCESS) printf("succes\n");
|
||||
if(status == PR_SUCCESS) printf("succes %ld\n",oid);
|
||||
else printf("failed\n");
|
||||
object->AddRef();
|
||||
urpManager* mngr = new urpManager(trans, orb);
|
||||
urpManager* mngr = new urpManager(PR_FALSE, orb, nsnull);
|
||||
rv = NS_OK;
|
||||
while(NS_SUCCEEDED(rv)) {
|
||||
rv = mngr->HandleRequest(trans->GetConnection());
|
||||
// rv = mngr->HandleRequest(trans->GetConnection());
|
||||
urpConnection *conn = trans->GetConnection();
|
||||
if( conn != NULL ) {
|
||||
// handle request in new thread
|
||||
localThreadArg *arg = new localThreadArg( mngr, conn );
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start_server,
|
||||
arg,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
if( thr == nsnull ) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -35,3 +35,15 @@ interface urpITest : nsISupports
|
||||
void test7(out urpITest o);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define URPTEST_CID \
|
||||
{ /*70ef013d-bca9-4226-bdd4-42a92cf6930d*/ \
|
||||
0x70ef013d, \
|
||||
0xbca9, \
|
||||
0x4226, \
|
||||
{0xbd, 0xd4, 0x42, 0xa9, 0x2c, 0xf6, 0x93, 0x0d} \
|
||||
}
|
||||
|
||||
#define URPTEST_PROGID "urpTest"
|
||||
|
||||
%}
|
||||
|
||||
@@ -29,6 +29,16 @@
|
||||
|
||||
static char * className = "urpTestImpl";
|
||||
|
||||
NS_IMPL_ISUPPORTS1(urpTestImpl, urpITest);
|
||||
|
||||
urpTestImpl::urpTestImpl() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
urpTestImpl::~urpTestImpl() {
|
||||
}
|
||||
|
||||
/*
|
||||
nsrefcnt urpTestImpl::AddRef(void) {
|
||||
static const char * methodName="AddRef";
|
||||
printf("--%s::%s this=%p",className, methodName,this);
|
||||
@@ -62,7 +72,7 @@ NS_IMETHODIMP urpTestImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/*void test1(inout long l);*/
|
||||
NS_IMETHODIMP urpTestImpl::Test1(PRInt32 *l) {
|
||||
@@ -159,147 +169,3 @@ NS_IMETHODIMP urpTestImpl::Test7(urpITest **o) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "bcIXPCOMStubsAndProxies.h"
|
||||
#include "bcXPCOMStubsAndProxiesCID.h"
|
||||
#include "bcIORBComponent.h"
|
||||
#include "bcORBComponentCID.h"
|
||||
#include "bcIStub.h"
|
||||
#include "urpStub.h"
|
||||
|
||||
static NS_DEFINE_CID(kORBCIID,BC_ORBCOMPONENT_CID);
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
|
||||
static void test(void) {
|
||||
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
bcIID iid = NS_GET_IID(urpITest);
|
||||
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
printf("zdes ploho\n");
|
||||
return; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
printf("ne tak zdes\n");
|
||||
return;
|
||||
}
|
||||
nsresult r;
|
||||
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--urpTestImpl test failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--urpTestImpl test failed\n");
|
||||
return;
|
||||
}
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
bcIStub *stub = NULL;
|
||||
urpITest *object = new urpTestImpl();
|
||||
object->AddRef();
|
||||
urpITest *proxy = NULL;
|
||||
// xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
|
||||
stub = new urpStub("socket,host=shiva,port=2009");
|
||||
printf("yatatatata\n");
|
||||
bcOID oid = orb->RegisterStub(stub);
|
||||
printf("---urpTestImpl iid=%s\n",NS_GET_IID(urpITest).ToString());
|
||||
r = xpcomStubsAndProxies->GetProxy(oid,NS_GET_IID(urpITest),orb,(nsISupports**)&proxy);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--urpTestImpl test failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
char ** valueArray = (char **)malloc(sizeof(char*)*4);
|
||||
valueArray[0] = "hi";
|
||||
valueArray[1] = "there";
|
||||
valueArray[2] = "a";
|
||||
valueArray[3] = "b";
|
||||
|
||||
PRInt32 l1 = 1999;
|
||||
PRInt32 ret;
|
||||
PRInt32 rt;
|
||||
object->Test1(&l1);
|
||||
l1 = 1999;
|
||||
proxy->Test1(&l1);
|
||||
printf("--urpTestImpl after Test1 l=%d %d\n",l1,ret);
|
||||
/*******************************************/
|
||||
PRInt32 l2 = 2000;
|
||||
l1 = 1999;
|
||||
proxy->Test2(l1,&l2);
|
||||
printf("--urpTestImpl after Test2 l2=%d\n",l2);
|
||||
|
||||
/*******************************************/
|
||||
const char * s1 = "s1";
|
||||
char * s2 = "s2";
|
||||
proxy->Test3(s1,&s2);
|
||||
printf("--urpTestImpl after Test3 s2=%s\n",s2);
|
||||
/*******************************************/
|
||||
|
||||
|
||||
proxy->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]);
|
||||
}
|
||||
object->Test5(4,valueArray2);
|
||||
printf("after calling object\n");
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
|
||||
}
|
||||
|
||||
|
||||
valueArray2 = (char ***)&valueArray;
|
||||
proxy->Test5(4,valueArray2);
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
|
||||
}
|
||||
|
||||
/*********************************************/
|
||||
proxy->Test6(object);
|
||||
/*********************************************/
|
||||
{
|
||||
urpITest *p1;
|
||||
proxy->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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static int counter = 0; //we do not need to call it on unload time;
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr,
|
||||
nsIFile *location,
|
||||
nsIModule** result) //I am using it for runnig test *only*
|
||||
{
|
||||
if (counter == 0) {
|
||||
counter ++;
|
||||
test();
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,23 +26,23 @@
|
||||
|
||||
class urpTestImpl : public urpITest {
|
||||
NS_DECL_ISUPPORTS
|
||||
urpTestImpl() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
NS_DECL_URPITEST
|
||||
urpTestImpl();
|
||||
virtual ~urpTestImpl();
|
||||
/*void test1(inout long l);*/
|
||||
NS_IMETHOD Test1(PRInt32 *l);
|
||||
// NS_IMETHOD Test1(PRInt32 *l);
|
||||
/*void test2(in long l1,inout long l2);*/
|
||||
NS_IMETHOD Test2(PRInt32 l1, PRInt32* l2);
|
||||
// NS_IMETHOD Test2(PRInt32 l1, PRInt32* l2);
|
||||
/*void test3(in string s1,inout string s2);*/
|
||||
NS_IMETHOD Test3(const char *s1, char **s2);
|
||||
// NS_IMETHOD Test3(const char *s1, char **s2);
|
||||
/*void test4(in PRUint32 count,[array, size_is(count)] in string valueArray);*/
|
||||
NS_IMETHOD Test4(PRUint32 count, const char **valueArray);
|
||||
// NS_IMETHOD Test4(PRUint32 count, const char **valueArray);
|
||||
/*void test5(in PRUint32 count,[array, size_is(count)] inout string valueArray);*/
|
||||
NS_IMETHOD Test5(PRUint32 count, char ***valueArray);
|
||||
// NS_IMETHOD Test5(PRUint32 count, char ***valueArray);
|
||||
/*void test6(in urpITest o);*/
|
||||
NS_IMETHOD Test6(class urpITest *o);
|
||||
// NS_IMETHOD Test6(class urpITest *o);
|
||||
/* void test7 (out urpITest o); */
|
||||
NS_IMETHOD Test7(urpITest **o);
|
||||
// NS_IMETHOD Test7(urpITest **o);
|
||||
};
|
||||
|
||||
#endif /* __urpTestImpl_h */
|
||||
|
||||
38
mozilla/java/xpcom/urp/src/test/urpTestImplFactory.cpp
Normal file
38
mozilla/java/xpcom/urp/src/test/urpTestImplFactory.cpp
Normal 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 "urpTestImpl.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(urpTestImpl)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "URP Test Component", URPTEST_CID, URPTEST_PROGID, urpTestImplConstructor,
|
||||
NULL /* NULL if you dont need one */,
|
||||
NULL /* NULL if you dont need one */
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("urpITestFactory", components)
|
||||
@@ -229,3 +229,11 @@ PRStatus llPipeTransport::Open( char *name, llSideType type )
|
||||
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
PRStatus llPipeTransport::Close( void )
|
||||
{
|
||||
PRNetAddr addr;
|
||||
PR_GetSockName( fd, &addr );
|
||||
PR_Delete( addr.local.path );
|
||||
return PR_Close( fd );
|
||||
}
|
||||
|
||||
@@ -61,13 +61,14 @@ protected:
|
||||
PRNetAddr addr; // only for client needs
|
||||
public:
|
||||
PRStatus Open( char *name, llSideType type );
|
||||
PRStatus Close( void );
|
||||
virtual PRStatus Close( void );
|
||||
llConnection * ProvideConnection( void );
|
||||
};
|
||||
|
||||
class llPipeTransport : public llTCPTransport {
|
||||
public:
|
||||
PRStatus Open( char *name, llSideType type );
|
||||
PRStatus Close( void );
|
||||
};
|
||||
|
||||
#endif // llTransport_included
|
||||
|
||||
@@ -49,9 +49,9 @@ protected:
|
||||
llTransport *trans;
|
||||
llSideType type;
|
||||
|
||||
public:
|
||||
urpTransport();
|
||||
|
||||
public:
|
||||
PRBool IsClient( void );
|
||||
PRBool IsServer( void );
|
||||
|
||||
|
||||
@@ -23,54 +23,85 @@
|
||||
#include "prmem.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "xptcall.h"
|
||||
#include "nsCRT.h"
|
||||
#include "urpManager.h"
|
||||
#include <unistd.h>
|
||||
#include "urpStub.h"
|
||||
#include "urpMarshalToolkit.h"
|
||||
|
||||
|
||||
#include "nsIModule.h"
|
||||
|
||||
#include "bcIXPCOMStubsAndProxies.h"
|
||||
#include "bcXPCOMStubsAndProxiesCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
|
||||
class urpAllocator : public bcIAllocator { //nb make is smarter. It should deallocate allocated memory.
|
||||
class threadHashKey : public nsHashKey {
|
||||
public:
|
||||
urpAllocator(nsIAllocator *_allocator) {
|
||||
allocator = _allocator;
|
||||
}
|
||||
virtual ~urpAllocator() {}
|
||||
virtual void * Alloc(size_t size) {
|
||||
return allocator->Alloc(size);
|
||||
}
|
||||
virtual void Free(void *ptr) {
|
||||
allocator->Free(ptr);
|
||||
}
|
||||
virtual void * Realloc(void* ptr, size_t size) {
|
||||
return allocator->Realloc(ptr,size);
|
||||
}
|
||||
threadHashKey(bcTID thrdID) : threadID(thrdID) {}
|
||||
|
||||
virtual PRUint32 HashCode(void) const
|
||||
{
|
||||
return PRUint32(threadID);
|
||||
}
|
||||
|
||||
virtual PRBool Equals(const nsHashKey *aKey) const
|
||||
{
|
||||
return ((threadHashKey*)aKey)->threadID == threadID;
|
||||
}
|
||||
|
||||
virtual nsHashKey *Clone(void) const
|
||||
{
|
||||
return new threadHashKey(threadID);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAllocator> allocator;
|
||||
bcTID threadID;
|
||||
};
|
||||
|
||||
urpManager::urpManager(urpTransport* trans) {
|
||||
broker = NULL;
|
||||
connection = NULL;
|
||||
transport = trans;
|
||||
nsresult r;
|
||||
struct localThreadArg {
|
||||
urpManager *mgr;
|
||||
urpConnection *conn;
|
||||
PRBool isClnt;
|
||||
localThreadArg( urpManager *mgr, urpConnection *conn, PRBool ic ) {
|
||||
this->mgr = mgr;
|
||||
this->conn = conn;
|
||||
this->isClnt = ic;
|
||||
}
|
||||
};
|
||||
|
||||
void thread_start( void *arg )
|
||||
{
|
||||
urpManager *manager = ((localThreadArg *)arg)->mgr;
|
||||
urpConnection *connection = ((localThreadArg *)arg)->conn;
|
||||
PRBool ic = ((localThreadArg *)arg)->isClnt;
|
||||
nsresult rv = manager->ReadMessage( connection, ic );
|
||||
}
|
||||
|
||||
urpManager::urpManager(urpTransport* trans, bcIORB *orb) {
|
||||
urpManager::urpManager(PRBool IsClient, bcIORB *orb, urpConnection* conn) {
|
||||
broker = orb;
|
||||
connection = NULL;
|
||||
transport = trans;
|
||||
connection = conn;
|
||||
connTable = nsnull;
|
||||
if(IsClient) {
|
||||
//then
|
||||
localThreadArg *arg = new localThreadArg( this, conn, PR_TRUE );
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start,
|
||||
arg,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
if(thr == nsnull) {
|
||||
printf("Error couldn't run listener\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
urpManager::~urpManager() {
|
||||
if(connTable)
|
||||
delete connTable;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,10 +109,13 @@ urpManager::~urpManager() {
|
||||
void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
|
||||
PRUint16 methodIndex,
|
||||
nsIInterfaceInfo* interfaceInfo,
|
||||
bcICall *call, nsXPTCVariant* params,
|
||||
bcICall *call,
|
||||
PRUint32 paramCount, const nsXPTMethodInfo* info) {
|
||||
printf("this is method sendUrpRequest and mid is %x\n",methodIndex);
|
||||
connection = transport->GetConnection();
|
||||
if(connection == nsnull) {
|
||||
printf("Connection is NULL in SendUrpRequest\n");
|
||||
exit(-1);
|
||||
}
|
||||
long size = 0;
|
||||
long messagesCount = 0;
|
||||
urpPacket* message = new urpPacket();
|
||||
@@ -122,520 +156,95 @@ void urpManager::SendUrpRequest(bcOID oid, bcIID iid,
|
||||
else
|
||||
message->WriteByte((char)methodIndex);
|
||||
}
|
||||
printf("header is written\n");
|
||||
|
||||
WriteType(iid, message);
|
||||
printf("Type is written\n");
|
||||
WriteOid(oid, message);
|
||||
printf("OID is written\n");
|
||||
WriteThreadID(1000, message);
|
||||
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_TRUE);
|
||||
mt->WriteType(iid, message);
|
||||
mt->WriteOid(oid, message);
|
||||
bcTID thrID = (bcTID)PR_GetCurrentThread();
|
||||
printf("OID is written %ld\n", thrID);
|
||||
mt->WriteThreadID(thrID, message);
|
||||
broker = call->GetORB();
|
||||
WriteParams(params, paramCount, info, interfaceInfo, message, methodIndex);
|
||||
printf("params are written\n");
|
||||
mt->WriteParams(call, paramCount, info, interfaceInfo, message, methodIndex);
|
||||
delete mt;
|
||||
connection->Write(message);
|
||||
delete message;
|
||||
printf("package is written\n");
|
||||
}
|
||||
|
||||
void urpManager::TransformMethodIDAndIID() {
|
||||
printf("this is method transformMethodIDAndIID\n");
|
||||
}
|
||||
|
||||
void
|
||||
urpManager::WriteType(bcIID iid, urpPacket* message) {
|
||||
|
||||
short cache_index;
|
||||
|
||||
char typeClass = INTERFACE;
|
||||
int found = 0;
|
||||
|
||||
if(0) //here should be checking on whether class is simple or not
|
||||
printf("class is simple\n");
|
||||
else {
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
message->WriteByte((char)typeClass | (found ? 0x0 : 0x80));
|
||||
printf("write type is %x\n",(char)typeClass | (found ? 0x0 : 0x80));
|
||||
message->WriteShort(cache_index);
|
||||
printf("write type is %x\n",cache_index);
|
||||
|
||||
if(!found) {
|
||||
char* iidStr = iid.ToString();
|
||||
message->WriteString(iidStr, strlen(iidStr));
|
||||
PR_Free(iidStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bcIID
|
||||
urpManager::ReadType(urpPacket* message) {
|
||||
|
||||
char byte = (char)message->ReadByte();
|
||||
char typeClassValue = byte & 0xff;
|
||||
|
||||
short cache_index = message->ReadShort();
|
||||
|
||||
int& size = 0;
|
||||
nsIID iid;
|
||||
char* name = message->ReadString(size);
|
||||
iid.Parse(name);
|
||||
PR_Free(name);
|
||||
return iid;
|
||||
}
|
||||
|
||||
void
|
||||
urpManager::WriteOid(bcOID oid, urpPacket* message) {
|
||||
short cache_index;
|
||||
int found = 0;
|
||||
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
char* str = (char*)calloc(100, sizeof(char));
|
||||
sprintf(str,"%ld",oid);
|
||||
message->WriteString(str, strlen(str));
|
||||
free(str);
|
||||
message->WriteShort(cache_index);
|
||||
}
|
||||
|
||||
bcOID
|
||||
urpManager::ReadOid(urpPacket* message) {
|
||||
int& size = 0;
|
||||
bcOID result;
|
||||
|
||||
char* str = message->ReadString(size);
|
||||
short cache_index = message->ReadShort();
|
||||
result = (bcOID)atol(str);
|
||||
PR_Free(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
urpManager::WriteThreadID(bcTID tid, urpPacket* message) {
|
||||
short cache_index;
|
||||
int found = 0;
|
||||
|
||||
char realTID[5] = {0x54, 0x14, 0x78, 0x71, 0x27};
|
||||
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
message->WriteOctetStream(realTID, 5);
|
||||
message->WriteShort(cache_index);
|
||||
}
|
||||
|
||||
bcTID
|
||||
urpManager::ReadThreadID(urpPacket* message) {
|
||||
int& size = 0;
|
||||
bcTID result;
|
||||
char* array = message->ReadOctetStream(size);
|
||||
short cache_index = message->ReadShort();
|
||||
result= (bcTID)array[0];
|
||||
PR_Free(array);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::MarshalElement(void *data, nsXPTParamInfo * param, uint8 type, uint8 ind,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, const nsXPTMethodInfo *info,
|
||||
nsXPTCVariant* params) {
|
||||
nsresult r = NS_OK;
|
||||
switch(type) {
|
||||
case nsXPTType::T_IID :
|
||||
printf("Marshalim T_IID\n");
|
||||
data = *(char**)data;
|
||||
message->WriteString((char*)data, strlen((char*)data));
|
||||
break;
|
||||
case nsXPTType::T_I8 :
|
||||
message->WriteByte(*(char*)data);
|
||||
break;
|
||||
case nsXPTType::T_I16 :
|
||||
message->WriteShort(*(short*)data);
|
||||
break;
|
||||
case nsXPTType::T_I32 :
|
||||
message->WriteInt(*(int*)data);
|
||||
break;
|
||||
case nsXPTType::T_I64 :
|
||||
message->WriteLong(*(long*)data);
|
||||
break;
|
||||
case nsXPTType::T_U8 :
|
||||
message->WriteByte(*(char*)data);
|
||||
break;
|
||||
case nsXPTType::T_U16 :
|
||||
message->WriteShort(*(short*)data);
|
||||
break;
|
||||
case nsXPTType::T_U32 :
|
||||
message->WriteInt(*(int*)data);
|
||||
break;
|
||||
case nsXPTType::T_U64 :
|
||||
message->WriteLong(*(long*)data);
|
||||
break;
|
||||
case nsXPTType::T_FLOAT :
|
||||
message->WriteFloat(*(float*)data);
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE :
|
||||
message->WriteDouble(*(double*)data);
|
||||
break;
|
||||
case nsXPTType::T_CHAR_STR :
|
||||
case nsXPTType::T_WCHAR_STR :
|
||||
{
|
||||
data = *(char **)data;
|
||||
size_t length = 0;
|
||||
if (type == nsXPTType::T_WCHAR_STR) {
|
||||
length = nsCRT::strlen((const PRUnichar*)data);
|
||||
length *= 2;
|
||||
length +=2;
|
||||
for (int i = 0; i < length && type == nsXPTType::T_WCHAR_STR; i++) {
|
||||
char c = ((char*)data)[i];
|
||||
}
|
||||
} else {
|
||||
length = nsCRT::strlen((const char*)data);
|
||||
length+=1;
|
||||
}
|
||||
message->WriteString((char*)data,length);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_INTERFACE :
|
||||
case nsXPTType::T_INTERFACE_IS :
|
||||
{
|
||||
nsIID *iid;
|
||||
if (type == nsXPTType::T_INTERFACE) {
|
||||
if(NS_FAILED(r = interfaceInfo->GetIIDForParam(methodIndex, param, &iid))) {
|
||||
return r;
|
||||
}
|
||||
} else {
|
||||
uint8 argnum;
|
||||
if (NS_FAILED(r = interfaceInfo->GetInterfaceIsArgNumberForParam(methodIndex, param, &argnum))) {
|
||||
return r;
|
||||
}
|
||||
const nsXPTParamInfo& arg_param = info->GetParam(argnum);
|
||||
const nsXPTType& arg_type = arg_param.GetType();
|
||||
if(arg_type.IsPointer() &&
|
||||
arg_type.TagPart() == nsXPTType::T_IID) {
|
||||
if(arg_param.IsOut())
|
||||
iid =*((nsID**)params[argnum].val.p);
|
||||
else
|
||||
iid = (nsID*)params[argnum].val.p;
|
||||
}
|
||||
}
|
||||
bcOID oid = 0;
|
||||
if (*(char**)data != NULL) {
|
||||
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
|
||||
return r;
|
||||
}
|
||||
xpcomStubsAndProxies->GetOID(*(nsISupports**)data, broker,&oid);
|
||||
}
|
||||
WriteOid(oid, message);
|
||||
bcIID biid = *(iid);
|
||||
WriteType(biid, message);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_PSTRING_SIZE_IS:
|
||||
case nsXPTType::T_PWSTRING_SIZE_IS:
|
||||
case nsXPTType::T_ARRAY: //nb array of interfaces [to do]
|
||||
{
|
||||
PRUint32 arraySize;
|
||||
if (!GetArraySizeFromParam(interfaceInfo,info, *param,methodIndex,
|
||||
ind,params,GET_LENGTH, &arraySize)) {
|
||||
return r;
|
||||
}
|
||||
if (type == nsXPTType::T_ARRAY) {
|
||||
nsXPTType datumType;
|
||||
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
|
||||
return r;
|
||||
}
|
||||
message->WriteInt(arraySize);
|
||||
PRInt16 elemSize = GetSimpleSize(datumType);
|
||||
char *current = *(char**)data;
|
||||
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize)
|
||||
{
|
||||
r = MarshalElement(current,param,datumType.TagPart(),0,
|
||||
interfaceInfo, message, methodIndex, info, params);
|
||||
if(NS_FAILED(r)) return r;
|
||||
}
|
||||
} else {
|
||||
size_t length = 0;
|
||||
if (type == nsXPTType::T_PWSTRING_SIZE_IS) {
|
||||
length = arraySize * sizeof(PRUnichar);
|
||||
} else {
|
||||
length = arraySize;
|
||||
}
|
||||
message->WriteString((char*)data, length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::WriteParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo* interfaceInfo, urpPacket* message, PRUint16 methodIndex) {
|
||||
int i;
|
||||
nsresult rv = NS_OK;
|
||||
for(i=0;i<paramCount;i++) {
|
||||
short cache_index;
|
||||
nsXPTParamInfo param = info->GetParam(i);
|
||||
PRBool isOut = param.IsOut();
|
||||
if ((transport->IsClient() && !param.IsIn()) ||
|
||||
(transport->IsServer() && !param.IsOut())) {
|
||||
continue;
|
||||
}
|
||||
nsXPTCVariant *value = & params[i];
|
||||
void *data;
|
||||
data = (isOut) ? value->val.p : value;
|
||||
rv = MarshalElement(data, ¶m,param.GetType().TagPart(), i, interfaceInfo, message, methodIndex, info, params);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
/*
|
||||
if(0) //here should be checking on whether class is simple or not
|
||||
printf("class is simple\n");
|
||||
else {
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
message->writeByte((char)typeClass | (found ? 0x0 : 0x80));
|
||||
message->writeShort(cache_index);
|
||||
|
||||
if(!found)
|
||||
message->writeString("com.sun.star.uno.XNamingService", 31);
|
||||
}
|
||||
*/
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::UnMarshal(void *data, nsXPTParamInfo * param, uint8 type,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, bcIAllocator * allocator) {
|
||||
nsresult r = NS_OK;
|
||||
switch(type) {
|
||||
case nsXPTType::T_IID :
|
||||
{
|
||||
printf("Unmarsahalim T_IID\n");
|
||||
/*
|
||||
*(char**)data = (char*)new nsIID();
|
||||
data = *(char**)data;
|
||||
*/
|
||||
int& size = 0;
|
||||
*(char**)data = message->ReadString(size);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_I8 :
|
||||
*(char*)data = message->ReadByte();
|
||||
break;
|
||||
case nsXPTType::T_I16 :
|
||||
*(short*)data = message->ReadShort();
|
||||
break;
|
||||
case nsXPTType::T_I32 :
|
||||
*(int*)data = message->ReadInt();
|
||||
break;
|
||||
case nsXPTType::T_I64 :
|
||||
*(long*)data = message->ReadLong();
|
||||
break;
|
||||
case nsXPTType::T_U8 :
|
||||
*(char*)data = message->ReadByte();
|
||||
break;
|
||||
case nsXPTType::T_U16 :
|
||||
*(short*)data = message->ReadShort();
|
||||
break;
|
||||
case nsXPTType::T_U32 :
|
||||
*(int*)data = message->ReadInt();
|
||||
break;
|
||||
case nsXPTType::T_U64 :
|
||||
*(long*)data = message->ReadLong();
|
||||
break;
|
||||
case nsXPTType::T_FLOAT :
|
||||
*(float*)data = message->ReadFloat();
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE :
|
||||
*(double*)data = message->ReadDouble();
|
||||
break;
|
||||
case nsXPTType::T_PSTRING_SIZE_IS:
|
||||
case nsXPTType::T_PWSTRING_SIZE_IS:
|
||||
case nsXPTType::T_CHAR_STR :
|
||||
case nsXPTType::T_WCHAR_STR :
|
||||
{
|
||||
int& size = 0;
|
||||
*(char**)data = message->ReadString(size);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_INTERFACE :
|
||||
case nsXPTType::T_INTERFACE_IS :
|
||||
{
|
||||
bcOID oid = ReadOid(message);
|
||||
nsIID iid = ReadType(message);
|
||||
nsISupports *proxy = NULL;
|
||||
if (oid != 0) {
|
||||
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies,
|
||||
kXPCOMStubsAndProxies, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xp failed\n");
|
||||
return r;
|
||||
}
|
||||
xpcomStubsAndProxies->GetProxy(oid, iid, broker,&proxy);
|
||||
}
|
||||
*(nsISupports**)data = proxy;
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_ARRAY:
|
||||
{
|
||||
nsXPTType datumType;
|
||||
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
|
||||
return r;
|
||||
}
|
||||
PRUint32 arraySize;
|
||||
PRInt16 elemSize = GetSimpleSize(datumType);
|
||||
arraySize = message->ReadInt();
|
||||
|
||||
char * current;
|
||||
*(char**)data = current = (char *) allocator->Alloc(elemSize*arraySize);
|
||||
//nb what about arraySize=0?
|
||||
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize) {
|
||||
r = UnMarshal(current, param, datumType.TagPart(), interfaceInfo, message, methodIndex, allocator);
|
||||
if(NS_FAILED(r)) return r;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::ReadParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
|
||||
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
|
||||
int i;
|
||||
nsresult rv = NS_OK;
|
||||
for(i=0;i<paramCount;i++) {
|
||||
short cache_index;
|
||||
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;
|
||||
if (transport->IsServer() && param.IsOut()) {
|
||||
value->val.p = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is good
|
||||
params[i].Init(*value,param.GetType(),0);
|
||||
params[i].ptr = params[i].val.p = value->val.p;
|
||||
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
|
||||
}
|
||||
|
||||
if ((transport->IsServer() && !param.IsIn()) ||
|
||||
(transport->IsClient() && !param.IsOut())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
void *data;
|
||||
data = (isOut) ? value->val.p : value;
|
||||
rv = UnMarshal(data, ¶m, param.GetType().TagPart(), interfaceInfo,
|
||||
message, methodIndex, allocator);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
params[i].Init(*value,param.GetType(),0);
|
||||
|
||||
/*
|
||||
if(0) //here should be checking on whether class is simple or not
|
||||
printf("class is simple\n");
|
||||
else {
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
message->writeByte((char)typeClass | (found ? 0x0 : 0x80));
|
||||
message->writeShort(cache_index);
|
||||
|
||||
if(!found)
|
||||
message->writeString("com.sun.star.uno.XNamingService", 31);
|
||||
}
|
||||
*/
|
||||
}
|
||||
delete allocator;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::ReadReply(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
|
||||
nsresult rv = NS_OK;
|
||||
printf("this is method readReply\n");
|
||||
urpPacket* message = connection->Read();
|
||||
char header = message->ReadByte();
|
||||
printf("header in reply is %x %x %x\n",header, BIG_HEADER, header & BIG_HEADER);
|
||||
if((header & BIG_HEADER) != 0) { // full header?
|
||||
if((header & REQUEST) != 0) // a request ?
|
||||
printf("long request\n");
|
||||
else // reply
|
||||
rv = ParseReply(message, header, params, paramCount,
|
||||
info, interfaceInfo, methodIndex);
|
||||
}
|
||||
else
|
||||
printf("short request header\n");
|
||||
delete connection;
|
||||
delete message;
|
||||
// transport->close();
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::ParseReply(urpPacket* message, char header,
|
||||
nsXPTCVariant* params, PRUint32 paramCount,
|
||||
urpManager::ReadReply(urpPacket* message, char header,
|
||||
bcICall* call, PRUint32 paramCount,
|
||||
const nsXPTMethodInfo *info,
|
||||
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 = ReadThreadID(message);
|
||||
bcTID tid = mt->ReadThreadID(message);
|
||||
}
|
||||
else
|
||||
printf("old threadID\n");
|
||||
rv = ReadParams(params, paramCount, info, message, interfaceInfo, methodIndex);
|
||||
rv = mt->ReadParams(paramCount, info, message, interfaceInfo, methodIndex, call, broker, connection);
|
||||
delete mt;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::HandleRequest(urpConnection* conn) {
|
||||
printf("method handleRequest\n");
|
||||
connection = conn;
|
||||
urpPacket* message = connection->Read();
|
||||
urpManager::ReadMessage(urpConnection* conn, PRBool isClient) {
|
||||
nsresult rv = NS_OK;
|
||||
char header = message->ReadByte();
|
||||
bcTID tid;
|
||||
if((header & BIG_HEADER) != 0) { // full header?
|
||||
if((header & REQUEST) != 0) // a request ?
|
||||
rv = ReadLongRequest(header, message);
|
||||
else // a reply
|
||||
printf("Error: here should be request\n");
|
||||
}
|
||||
else // only a short request header
|
||||
rv = ReadShortRequest(header, message);
|
||||
delete message;
|
||||
if(!isClient) {
|
||||
if(connTable == nsnull)
|
||||
connTable = new nsHashtable(20);
|
||||
bcTID thrID = (bcTID)PR_GetCurrentThread();
|
||||
threadHashKey thrHK(thrID);
|
||||
connTable->Put(&thrHK, conn);
|
||||
}
|
||||
while(conn->GetStatus() == urpSuccess) {
|
||||
urpPacket* message = conn->Read();
|
||||
char header = message->ReadByte();
|
||||
bcTID tid;
|
||||
if((header & BIG_HEADER) != 0) { // full header?
|
||||
if((header & REQUEST) != 0) // a request ?
|
||||
rv = ReadLongRequest(header, message);
|
||||
else { // a reply
|
||||
bcIID iid; bcOID oid; bcMID mid;
|
||||
call->GetParams(&iid, &oid, &mid);
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
printf("Error in ReadMessage\n");
|
||||
return NS_ERROR_FAILURE; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
printf("Error in ReadMessage in second place\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
else // only a short request header
|
||||
rv = ReadShortRequest(header, message);
|
||||
delete message;
|
||||
}
|
||||
if(!isClient) {
|
||||
bcTID thrID = (bcTID)PR_GetCurrentThread();
|
||||
threadHashKey thrHK(thrID);
|
||||
connTable->Remove(&thrHK);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -648,7 +257,7 @@ urpManager::ReadShortRequest(char header, urpPacket* message) {
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpManager::SendReply(bcTID tid, nsXPTCVariant *params, PRUint32 paramCount,
|
||||
urpManager::SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
|
||||
const nsXPTMethodInfo* info,
|
||||
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex) {
|
||||
nsresult rv = NS_OK;
|
||||
@@ -656,13 +265,19 @@ urpManager::SendReply(bcTID tid, nsXPTCVariant *params, PRUint32 paramCount,
|
||||
header |= NEWTID;
|
||||
urpPacket* message = new urpPacket();
|
||||
message->WriteByte(header);
|
||||
WriteThreadID(tid, message);
|
||||
rv = WriteParams(params, paramCount, info, interfaceInfo, message,
|
||||
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_FALSE);
|
||||
mt->WriteThreadID(tid, message);
|
||||
rv = mt->WriteParams(call, paramCount, info, interfaceInfo, message,
|
||||
methodIndex);
|
||||
delete mt;
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
if(connTable) {
|
||||
bcTID thrID = (bcTID)PR_GetCurrentThread();
|
||||
threadHashKey thrHK(thrID);
|
||||
connection = (urpConnection*)connTable->Get(&thrHK);
|
||||
}
|
||||
connection->Write(message);
|
||||
delete message;
|
||||
delete connection;
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -679,16 +294,17 @@ urpManager::ReadLongRequest(char header, urpPacket* message) {
|
||||
else
|
||||
methodId = message->ReadByte();
|
||||
|
||||
urpMarshalToolkit* mt = new urpMarshalToolkit(PR_FALSE);
|
||||
if((header & NEWTYPE) != 0)
|
||||
iid = ReadType(message);
|
||||
iid = mt->ReadType(message);
|
||||
|
||||
if((header & NEWOID) != 0) // new oid?
|
||||
oid = ReadOid(message);
|
||||
oid = mt->ReadOid(message);
|
||||
|
||||
if((header & NEWTID) != 0) // new thread id ?
|
||||
tid = ReadThreadID(message);
|
||||
tid = mt->ReadThreadID(message);
|
||||
|
||||
printf("method readLongRequest: tid %ld\n",tid);
|
||||
printf("method readLongRequest: tid %ld %ld\n",tid,oid);
|
||||
char ignore_cache = ((header & IGNORECACHE) != 0); // do not use cache for this request?
|
||||
|
||||
char mustReply;
|
||||
@@ -706,116 +322,32 @@ printf("method readLongRequest: tid %ld\n",tid);
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
printf("here oblomalis\n");
|
||||
delete mt;
|
||||
return NS_ERROR_FAILURE; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
printf("zdesia oblom\n");
|
||||
delete mt;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
char* name;
|
||||
interfaceInfo->GetName(&name);
|
||||
printf("in handleRequest interface name is %s\n",name);
|
||||
nsXPTCVariant *params;
|
||||
nsXPTMethodInfo* info;
|
||||
interfaceInfo->GetMethodInfo(methodId,(const nsXPTMethodInfo **)&info);
|
||||
PRUint32 paramCount = info->GetParamCount();
|
||||
if (paramCount > 0) {
|
||||
params = (nsXPTCVariant *) PR_Malloc(sizeof(nsXPTCVariant)*paramCount);
|
||||
}
|
||||
ReadParams(params, paramCount, info, message, interfaceInfo, methodId);
|
||||
nsXPTCMiniVariant* tempVari = (nsXPTCMiniVariant *) PR_Malloc(sizeof(nsXPTCMiniVariant)*paramCount);
|
||||
for(int ii =0; ii<paramCount;ii++)
|
||||
tempVari[ii] = params[ii];
|
||||
//nb return value; excepion handling
|
||||
// XPTC_InvokeByIndex(object, methodId, paramCount, params);
|
||||
bcICall *call = broker->CreateCall(&iid, &oid, methodId);
|
||||
bcIMarshaler *marshaler = call->GetMarshaler();
|
||||
bcXPCOMMarshalToolkit * mt = new bcXPCOMMarshalToolkit(methodId, interfaceInfo, tempVari,broker);
|
||||
mt->Marshal(marshaler);
|
||||
mt->ReadParams(paramCount, info, message, interfaceInfo, methodId, call, broker, connection);
|
||||
delete mt;
|
||||
//nb return value; excepion handling
|
||||
broker->SendReceive(call);
|
||||
bcIUnMarshaler * unmarshaler = call->GetUnMarshaler();
|
||||
mt->UnMarshal(unmarshaler);
|
||||
delete call; delete marshaler; delete unmarshaler; delete mt;
|
||||
rv = SendReply(tid, params, paramCount, info, interfaceInfo, methodId);
|
||||
PR_Free(tempVari);
|
||||
PR_Free(params);
|
||||
rv = SendReply(tid, call, paramCount, info, interfaceInfo, methodId);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult urpManager::GetArraySizeFromParam( nsIInterfaceInfo *_interfaceInfo,
|
||||
const nsXPTMethodInfo* method,
|
||||
const nsXPTParamInfo& param,
|
||||
uint16 _methodIndex,
|
||||
uint8 paramIndex,
|
||||
nsXPTCVariant* 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, ¶m, 0, &argnum);
|
||||
} else {
|
||||
rv = _interfaceInfo->GetLengthIsArgNumberForParam(_methodIndex, ¶m, 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;
|
||||
nsresult
|
||||
urpManager::SetCall(bcICall* call, PRMonitor *m) {
|
||||
this->call = call;
|
||||
this->mon = m;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRInt16 urpManager::GetSimpleSize(uint8 type) {
|
||||
PRInt16 size = -1;
|
||||
switch(type) {
|
||||
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:
|
||||
size = sizeof(void*);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "xptinfo.h"
|
||||
#include "bcDefs.h"
|
||||
#include "urpTransport.h"
|
||||
#include "bcXPCOMMarshalToolkit.h"
|
||||
#include "bcIORB.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#define BIG_HEADER 0x80
|
||||
#define REQUEST 0x40
|
||||
@@ -29,54 +31,34 @@
|
||||
class urpManager {
|
||||
|
||||
public:
|
||||
urpManager(urpTransport* trans);
|
||||
urpManager(urpTransport* trans, bcIORB *orb);
|
||||
urpManager(PRBool IsClient, bcIORB *orb, urpConnection* connection);
|
||||
~urpManager();
|
||||
nsresult HandleRequest(urpConnection* conn);
|
||||
void SendUrpRequest(bcOID oid, bcIID iid,
|
||||
PRUint16 methodIndex,
|
||||
nsIInterfaceInfo* interfaceInfo,
|
||||
bcICall *call, nsXPTCVariant* params,
|
||||
bcICall *call,
|
||||
PRUint32 paramCount, const nsXPTMethodInfo* info);
|
||||
nsresult ReadReply(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
|
||||
nsresult ReadMessage(urpConnection* conn, PRBool ic);
|
||||
nsresult SetCall(bcICall* call, PRMonitor *m);
|
||||
private:
|
||||
nsHashtable* connTable;
|
||||
bcIORB *broker;
|
||||
enum SizeMode { GET_SIZE, GET_LENGTH };
|
||||
urpConnection* connection;
|
||||
urpTransport* transport;
|
||||
PRMonitor *mon;
|
||||
/* for ReadReply */
|
||||
bcICall* call;
|
||||
PRUint32 paramCount;
|
||||
nsXPTMethodInfo* info;
|
||||
bcMID mid;
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
void TransformMethodIDAndIID();
|
||||
void WriteType(bcIID iid, urpPacket* message);
|
||||
bcIID ReadType(urpPacket* message);
|
||||
void WriteOid(bcOID oid, urpPacket* message);
|
||||
bcOID ReadOid(urpPacket* message);
|
||||
void WriteThreadID(long tid, urpPacket* message);
|
||||
bcTID ReadThreadID(urpPacket* message);
|
||||
nsresult WriteParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo * info, nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex);
|
||||
nsresult ReadParams(nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
|
||||
nsresult ParseReply(urpPacket* message, char header,
|
||||
nsXPTCVariant* params, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
|
||||
nsresult ReadReply(urpPacket* message, char header,
|
||||
bcICall* call, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
|
||||
nsresult ReadLongRequest(char header, urpPacket* message);
|
||||
nsresult ReadShortRequest(char header, urpPacket* message);
|
||||
nsresult SendReply(bcTID tid, nsXPTCVariant *params, PRUint32 paramCount,
|
||||
nsresult SendReply(bcTID tid, bcICall* call, PRUint32 paramCount,
|
||||
const nsXPTMethodInfo* info,
|
||||
nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex);
|
||||
nsresult MarshalElement(void *data, nsXPTParamInfo * param, uint8 type, uint8 ind,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, const nsXPTMethodInfo* info,
|
||||
nsXPTCVariant* params);
|
||||
nsresult GetArraySizeFromParam( nsIInterfaceInfo *interfaceInfo,
|
||||
const nsXPTMethodInfo* method,
|
||||
const nsXPTParamInfo& param,
|
||||
uint16 methodIndex,
|
||||
uint8 paramIndex,
|
||||
nsXPTCVariant* nativeParams,
|
||||
SizeMode mode,
|
||||
PRUint32* result);
|
||||
PRInt16 GetSimpleSize(uint8 type);
|
||||
nsresult UnMarshal(void *data, nsXPTParamInfo * param, uint8 type,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, bcIAllocator * allocator);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
597
mozilla/java/xpcom/urp/src/urpMarshalToolkit.cpp
Normal file
597
mozilla/java/xpcom/urp/src/urpMarshalToolkit.cpp
Normal file
@@ -0,0 +1,597 @@
|
||||
/* -*- 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):
|
||||
* Sergey Lunegov <lsv@sparc.spb.su>
|
||||
*/
|
||||
|
||||
#include "prmem.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "xptcall.h"
|
||||
#include "nsCRT.h"
|
||||
#include "urpMarshalToolkit.h"
|
||||
#include <unistd.h>
|
||||
#include "urpStub.h"
|
||||
|
||||
|
||||
#include "nsIModule.h"
|
||||
|
||||
|
||||
class urpAllocator : public bcIAllocator { //nb make is smarter. It should deallocate allocated memory.
|
||||
public:
|
||||
urpAllocator(nsIAllocator *_allocator) {
|
||||
allocator = _allocator;
|
||||
}
|
||||
virtual ~urpAllocator() {}
|
||||
virtual void * Alloc(size_t size) {
|
||||
return allocator->Alloc(size);
|
||||
}
|
||||
virtual void Free(void *ptr) {
|
||||
allocator->Free(ptr);
|
||||
}
|
||||
virtual void * Realloc(void* ptr, size_t size) {
|
||||
return allocator->Realloc(ptr,size);
|
||||
}
|
||||
private:
|
||||
nsCOMPtr<nsIAllocator> allocator;
|
||||
};
|
||||
|
||||
|
||||
urpMarshalToolkit::urpMarshalToolkit(PRBool isclnt) {
|
||||
isClient = isclnt;
|
||||
}
|
||||
|
||||
|
||||
urpMarshalToolkit::~urpMarshalToolkit() {
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpMarshalToolkit::WriteElement(bcIUnMarshaler *um, nsXPTParamInfo * param, uint8 type, uint8 ind,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, const nsXPTMethodInfo *info,
|
||||
bcIAllocator * allocator) {
|
||||
void* data = allocator->Alloc(sizeof(void*));
|
||||
nsresult r = NS_OK;
|
||||
switch(type) {
|
||||
case nsXPTType::T_IID :
|
||||
data = (char*)new nsIID();
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteString((char*)data, strlen((char*)data));
|
||||
break;
|
||||
case nsXPTType::T_I8 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteByte(*(char*)data);
|
||||
break;
|
||||
case nsXPTType::T_I16 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteShort(*(short*)data);
|
||||
break;
|
||||
case nsXPTType::T_I32 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteInt(*(int*)data);
|
||||
break;
|
||||
case nsXPTType::T_I64 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteLong(*(long*)data);
|
||||
break;
|
||||
case nsXPTType::T_U8 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteByte(*(char*)data);
|
||||
break;
|
||||
case nsXPTType::T_U16 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteShort(*(short*)data);
|
||||
break;
|
||||
case nsXPTType::T_U32 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteInt(*(int*)data);
|
||||
break;
|
||||
case nsXPTType::T_U64 :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteLong(*(long*)data);
|
||||
break;
|
||||
case nsXPTType::T_FLOAT :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteFloat(*(float*)data);
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteDouble(*(double*)data);
|
||||
break;
|
||||
case nsXPTType::T_CHAR :
|
||||
case nsXPTType::T_WCHAR :
|
||||
um->ReadSimple(data,XPTType2bcXPType(type));
|
||||
message->WriteByte(*(char*)data);
|
||||
break;
|
||||
case nsXPTType::T_CHAR_STR :
|
||||
case nsXPTType::T_WCHAR_STR :
|
||||
{
|
||||
size_t size;
|
||||
um->ReadString(data,&size,allocator);
|
||||
{
|
||||
char *str = *(char**)data;
|
||||
for (int i = 0; i < size && type == nsXPTType::T_WCHAR_STR; i++) {
|
||||
char c = str[i];
|
||||
}
|
||||
}
|
||||
data = *(char **)data;
|
||||
size_t length = 0;
|
||||
if (type == nsXPTType::T_WCHAR_STR) {
|
||||
length = nsCRT::strlen((const PRUnichar*)data);
|
||||
length *= 2;
|
||||
length +=2;
|
||||
for (int i = 0; i < length && type == nsXPTType::T_WCHAR_STR; i++) {
|
||||
char c = ((char*)data)[i];
|
||||
}
|
||||
} else {
|
||||
length = nsCRT::strlen((const char*)data);
|
||||
length+=1;
|
||||
}
|
||||
message->WriteString((char*)data,length);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_INTERFACE :
|
||||
case nsXPTType::T_INTERFACE_IS :
|
||||
{
|
||||
nsIID iid;
|
||||
bcOID oid;
|
||||
um->ReadSimple(&oid,XPTType2bcXPType(type));
|
||||
um->ReadSimple(&iid,bc_T_IID);
|
||||
WriteOid(oid, message);
|
||||
WriteType(iid, message);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_PSTRING_SIZE_IS:
|
||||
case nsXPTType::T_PWSTRING_SIZE_IS:
|
||||
case nsXPTType::T_ARRAY: //nb array of interfaces [to do]
|
||||
{
|
||||
size_t size;
|
||||
nsXPTType datumType;
|
||||
if(type != nsXPTType::T_ARRAY) {
|
||||
um->ReadString(data,&size,allocator);
|
||||
{
|
||||
char *str = *(char**)data;
|
||||
for (int i = 0; i < size && type == nsXPTType::T_WCHAR_STR; i++) {
|
||||
char c = str[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
|
||||
allocator->Free(data);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
PRUint32 arraySize;
|
||||
PRInt16 elemSize = GetSimpleSize(datumType);
|
||||
um->ReadSimple(&arraySize,bc_T_U32);
|
||||
message->WriteInt(arraySize);
|
||||
for (unsigned int i = 0; i < arraySize; i++) {
|
||||
r = WriteElement(um,param,datumType.TagPart(),0,
|
||||
interfaceInfo, message, methodIndex, info, allocator);
|
||||
if(NS_FAILED(r)) {
|
||||
allocator->Free(data);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type != nsXPTType::T_ARRAY) {
|
||||
size_t length = 0;
|
||||
if (type == nsXPTType::T_PWSTRING_SIZE_IS) {
|
||||
length = size * sizeof(PRUnichar);
|
||||
} else {
|
||||
length = size;
|
||||
}
|
||||
message->WriteString((char*)data, length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
allocator->Free(data);
|
||||
return r;
|
||||
}
|
||||
allocator->Free(data);
|
||||
return r;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpMarshalToolkit::WriteParams(bcICall *call, PRUint32 paramCount, const nsXPTMethodInfo *info, nsIInterfaceInfo* interfaceInfo, urpPacket* message, PRUint16 methodIndex) {
|
||||
int i;
|
||||
nsresult rv = NS_OK;
|
||||
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
|
||||
bcIUnMarshaler *um = call->GetUnMarshaler();
|
||||
for(i=0;i<paramCount;i++) {
|
||||
short cache_index;
|
||||
nsXPTParamInfo param = info->GetParam(i);
|
||||
PRBool isOut = param.IsOut();
|
||||
if ((isClient && !param.IsIn()) ||
|
||||
(!isClient && !param.IsOut())) {
|
||||
continue;
|
||||
}
|
||||
rv = WriteElement(um, ¶m,param.GetType().TagPart(), i, interfaceInfo, message, methodIndex, info, allocator);
|
||||
if(NS_FAILED(rv)) {
|
||||
delete allocator;
|
||||
delete um;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
delete allocator;
|
||||
delete um;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpMarshalToolkit::ReadElement(nsXPTParamInfo * param, uint8 type,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, bcIAllocator* allocator,
|
||||
bcIMarshaler* m, bcIORB *broker, urpConnection* conn) {
|
||||
void* data = allocator->Alloc(sizeof(void*));
|
||||
nsresult r = NS_OK;
|
||||
switch(type) {
|
||||
case nsXPTType::T_IID :
|
||||
{
|
||||
int& size = 0;
|
||||
data = message->ReadString(size);
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_I8 :
|
||||
*(char*)data = message->ReadByte();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_I16 :
|
||||
*(short*)data = message->ReadShort();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_I32 :
|
||||
*(int*)data = message->ReadInt();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_I64 :
|
||||
*(long*)data = message->ReadLong();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_U8 :
|
||||
*(char*)data = message->ReadByte();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_U16 :
|
||||
*(short*)data = message->ReadShort();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_U32 :
|
||||
*(int*)data = message->ReadInt();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_U64 :
|
||||
*(long*)data = message->ReadLong();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_FLOAT :
|
||||
*(float*)data = message->ReadFloat();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE :
|
||||
*(double*)data = message->ReadDouble();
|
||||
m->WriteSimple(data, XPTType2bcXPType(type));
|
||||
break;
|
||||
case nsXPTType::T_CHAR_STR :
|
||||
case nsXPTType::T_WCHAR_STR :
|
||||
{
|
||||
int& size = 0;
|
||||
*(char**)data = message->ReadString(size);
|
||||
data = *(char **)data;
|
||||
size_t length = 0;
|
||||
if (type == nsXPTType::T_WCHAR_STR) {
|
||||
length = nsCRT::strlen((const PRUnichar*)data);
|
||||
length *= 2;
|
||||
length +=2;
|
||||
for (int i = 0; i < length && type == nsXPTType::T_WCHAR_STR; i++) {
|
||||
char c = ((char*)data)[i];
|
||||
}
|
||||
} else {
|
||||
length = nsCRT::strlen((const char*)data);
|
||||
length+=1;
|
||||
}
|
||||
m->WriteString(data,length);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_INTERFACE :
|
||||
case nsXPTType::T_INTERFACE_IS :
|
||||
{
|
||||
bcOID oid = ReadOid(message);
|
||||
nsIID iid = ReadType(message);
|
||||
nsISupports *proxy = NULL;
|
||||
if (oid != 0) {
|
||||
urpStub* stub = new urpStub(conn);
|
||||
broker->RegisterStubWithOID(stub, &oid);
|
||||
}
|
||||
m->WriteSimple(&oid, XPTType2bcXPType(type));
|
||||
m->WriteSimple(&iid,bc_T_IID);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_PSTRING_SIZE_IS:
|
||||
case nsXPTType::T_PWSTRING_SIZE_IS:
|
||||
case nsXPTType::T_ARRAY:
|
||||
{
|
||||
nsXPTType datumType;
|
||||
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
|
||||
allocator->Free(data);
|
||||
return r;
|
||||
}
|
||||
PRUint32 arraySize;
|
||||
PRInt16 elemSize = GetSimpleSize(datumType);
|
||||
arraySize = message->ReadInt();
|
||||
|
||||
if(type == nsXPTType::T_ARRAY) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
size_t length = 0;
|
||||
if (type == nsXPTType::T_PWSTRING_SIZE_IS) {
|
||||
length = arraySize * sizeof(PRUnichar);
|
||||
} else {
|
||||
length = arraySize;
|
||||
}
|
||||
m->WriteString(data, length);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
allocator->Free(data);
|
||||
return r;
|
||||
}
|
||||
allocator->Free(data);
|
||||
return r;
|
||||
}
|
||||
|
||||
nsresult
|
||||
urpMarshalToolkit::ReadParams(PRUint32 paramCount, const nsXPTMethodInfo *info, urpPacket* message, nsIInterfaceInfo *interfaceInfo, PRUint16 methodIndex, bcICall* call, bcIORB *orb, urpConnection* conn) {
|
||||
bcIAllocator * allocator = new urpAllocator(nsAllocator::GetGlobalAllocator());
|
||||
bcIMarshaler* m = call->GetMarshaler();
|
||||
int i;
|
||||
nsresult rv = NS_OK;
|
||||
for(i=0;i<paramCount;i++) {
|
||||
short cache_index;
|
||||
nsXPTParamInfo param = info->GetParam(i);
|
||||
PRBool isOut = param.IsOut();
|
||||
|
||||
if ((!isClient && !param.IsIn()) ||
|
||||
(isClient && !param.IsOut())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rv = ReadElement(¶m, param.GetType().TagPart(), interfaceInfo,
|
||||
message, methodIndex, allocator, m, orb, conn);
|
||||
if(NS_FAILED(rv)) {
|
||||
delete allocator;
|
||||
delete m;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
delete allocator;
|
||||
delete m;
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt16 urpMarshalToolkit::GetSimpleSize(uint8 type) {
|
||||
PRInt16 size = -1;
|
||||
switch(type) {
|
||||
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:
|
||||
size = sizeof(void*);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
bcXPType urpMarshalToolkit::XPTType2bcXPType(uint8 type) {
|
||||
switch(type) {
|
||||
case nsXPTType::T_I8 :
|
||||
return bc_T_I8;
|
||||
case nsXPTType::T_U8 :
|
||||
return bc_T_U8;
|
||||
case nsXPTType::T_I16 :
|
||||
return bc_T_I16;
|
||||
case nsXPTType::T_U16 :
|
||||
return bc_T_U16;
|
||||
case nsXPTType::T_I32 :
|
||||
return bc_T_I32;
|
||||
case nsXPTType::T_U32 :
|
||||
return bc_T_U32;
|
||||
case nsXPTType::T_I64 :
|
||||
return bc_T_I64;
|
||||
case nsXPTType::T_U64 :
|
||||
return bc_T_U64;
|
||||
case nsXPTType::T_FLOAT :
|
||||
return bc_T_FLOAT;
|
||||
case nsXPTType::T_DOUBLE :
|
||||
return bc_T_DOUBLE;
|
||||
case nsXPTType::T_BOOL :
|
||||
return bc_T_BOOL;
|
||||
case nsXPTType::T_CHAR :
|
||||
return bc_T_CHAR;
|
||||
case nsXPTType::T_WCHAR :
|
||||
return bc_T_WCHAR;
|
||||
case nsXPTType::T_IID :
|
||||
return bc_T_IID;
|
||||
case nsXPTType::T_CHAR_STR :
|
||||
case nsXPTType::T_PSTRING_SIZE_IS:
|
||||
return bc_T_CHAR_STR;
|
||||
case nsXPTType::T_WCHAR_STR :
|
||||
case nsXPTType::T_PWSTRING_SIZE_IS:
|
||||
return bc_T_WCHAR_STR;
|
||||
case nsXPTType::T_INTERFACE :
|
||||
case nsXPTType::T_INTERFACE_IS :
|
||||
return bc_T_INTERFACE;
|
||||
case nsXPTType::T_ARRAY:
|
||||
return bc_T_ARRAY;
|
||||
default:
|
||||
return bc_T_UNDEFINED;
|
||||
|
||||
}
|
||||
}
|
||||
void
|
||||
urpMarshalToolkit::WriteType(bcIID iid, urpPacket* message) {
|
||||
|
||||
short cache_index;
|
||||
|
||||
char typeClass = INTERFACE;
|
||||
int found = 0;
|
||||
|
||||
if(0) //here should be checking on whether class is simple or not
|
||||
printf("class is simple\n");
|
||||
else {
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
message->WriteByte((char)typeClass | (found ? 0x0 : 0x80));
|
||||
printf("write type is %x\n",(char)typeClass | (found ? 0x0 : 0x80));
|
||||
message->WriteShort(cache_index);
|
||||
printf("write type is %x\n",cache_index);
|
||||
|
||||
if(!found) {
|
||||
char* iidStr = iid.ToString();
|
||||
message->WriteString(iidStr, strlen(iidStr));
|
||||
PR_Free(iidStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bcIID
|
||||
urpMarshalToolkit::ReadType(urpPacket* message) {
|
||||
|
||||
char byte = (char)message->ReadByte();
|
||||
char typeClassValue = byte & 0xff;
|
||||
|
||||
short cache_index = message->ReadShort();
|
||||
|
||||
int& size = 0;
|
||||
nsIID iid;
|
||||
char* name = message->ReadString(size);
|
||||
iid.Parse(name);
|
||||
PR_Free(name);
|
||||
return iid;
|
||||
}
|
||||
|
||||
void
|
||||
urpMarshalToolkit::WriteOid(bcOID oid, urpPacket* message) {
|
||||
short cache_index;
|
||||
int found = 0;
|
||||
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
char* str = (char*)calloc(100, sizeof(char));
|
||||
sprintf(str,"%ld",oid);
|
||||
message->WriteString(str, strlen(str));
|
||||
free(str);
|
||||
message->WriteShort(cache_index);
|
||||
}
|
||||
|
||||
bcOID
|
||||
urpMarshalToolkit::ReadOid(urpPacket* message) {
|
||||
int& size = 0;
|
||||
bcOID result;
|
||||
|
||||
char* str = message->ReadString(size);
|
||||
short cache_index = message->ReadShort();
|
||||
result = (bcOID)atol(str);
|
||||
PR_Free(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
urpMarshalToolkit::WriteThreadID(bcTID tid, urpPacket* message) {
|
||||
short cache_index;
|
||||
int found = 0;
|
||||
|
||||
char realTID[4]; /* this is hack: I know that bcTID is PRUint32
|
||||
so it is represented by four bytes */
|
||||
realTID[0] = tid>>24 & 0xff;
|
||||
realTID[1] = (tid>>16) & 0xff;
|
||||
realTID[2] = (tid>>8) & 0xff;
|
||||
realTID[3] = tid & 0xff;
|
||||
|
||||
if(0) { // here should be checking on whether cache is used
|
||||
printf("cache is used\n");
|
||||
cache_index = 0x0;
|
||||
}
|
||||
else
|
||||
cache_index = (short)0xffff;
|
||||
|
||||
message->WriteOctetStream(realTID, 4);
|
||||
message->WriteShort(cache_index);
|
||||
}
|
||||
|
||||
bcTID
|
||||
urpMarshalToolkit::ReadThreadID(urpPacket* message) {
|
||||
int& size = 0;
|
||||
bcTID result;
|
||||
char* array = message->ReadOctetStream(size);
|
||||
short cache_index = message->ReadShort();
|
||||
result = ((unsigned char)array[0]<<24) + ((unsigned char)array[1]<<16) + ((unsigned char)array[2]<<8) + ((unsigned char)array[3]&0xff);
|
||||
PR_Free(array);
|
||||
return result;
|
||||
}
|
||||
61
mozilla/java/xpcom/urp/src/urpMarshalToolkit.h
Normal file
61
mozilla/java/xpcom/urp/src/urpMarshalToolkit.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef URP_MARSHALTOOLKIT
|
||||
#define URP_MARSHALTOOLKIT
|
||||
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "xptinfo.h"
|
||||
#include "bcDefs.h"
|
||||
#include "urpTransport.h"
|
||||
#include "bcIORB.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#define BIG_HEADER 0x80
|
||||
#define REQUEST 0x40
|
||||
#define NEWTYPE 0x20
|
||||
#define NEWOID 0x10
|
||||
#define NEWTID 0x08
|
||||
#define LONGMETHODID 0x04
|
||||
#define IGNORECACHE 0x02
|
||||
#define MOREFLAGS 0x01
|
||||
|
||||
#define MUSTREPLY 0x80
|
||||
#define SYNCHRONOUSE 0x40
|
||||
|
||||
#define DIR_MID 0x40
|
||||
#define EXCEPTION 0x20
|
||||
|
||||
#define INTERFACE 22
|
||||
#define INTERFACE_STRING "com.sun.star.uno.XInterface"
|
||||
|
||||
|
||||
class urpMarshalToolkit {
|
||||
|
||||
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 WriteParams(bcICall *call, PRUint32 paramCount, const nsXPTMethodInfo * info, nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex);
|
||||
void WriteType(bcIID iid, urpPacket* message);
|
||||
bcIID ReadType(urpPacket* message);
|
||||
void WriteOid(bcOID oid, urpPacket* message);
|
||||
bcOID ReadOid(urpPacket* message);
|
||||
void WriteThreadID(long tid, urpPacket* message);
|
||||
bcTID ReadThreadID(urpPacket* message);
|
||||
|
||||
private:
|
||||
PRBool isClient;
|
||||
nsresult WriteElement(bcIUnMarshaler * um, nsXPTParamInfo * param, uint8 type, uint8 ind,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, const nsXPTMethodInfo* info,
|
||||
bcIAllocator * allocator);
|
||||
PRInt16 GetSimpleSize(uint8 type);
|
||||
nsresult ReadElement(nsXPTParamInfo * param, uint8 type,
|
||||
nsIInterfaceInfo* interfaceInfo, urpPacket* message,
|
||||
PRUint16 methodIndex, bcIAllocator * allocator,
|
||||
bcIMarshaler* m, bcIORB *orb, urpConnection* conn);
|
||||
bcXPType XPTType2bcXPType(uint8 type);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -29,22 +29,14 @@
|
||||
|
||||
#include "urpManager.h"
|
||||
|
||||
urpStub::urpStub(char* conStr) {
|
||||
transport = new urpConnector();
|
||||
PRStatus status = transport->Open(conStr);
|
||||
if(status != NS_OK) {
|
||||
fprintf(stderr,"Error in opening of remote server on client side\n");
|
||||
exit(-1);
|
||||
}
|
||||
manager = new urpManager(transport);
|
||||
|
||||
urpStub::urpStub(urpConnection* conn) {
|
||||
manager = new urpManager(PR_TRUE, nsnull, conn);
|
||||
//here zavodim condWait i peredaem v urpManager
|
||||
}
|
||||
|
||||
|
||||
urpStub::~urpStub() {
|
||||
if(transport) {
|
||||
transport->Close();
|
||||
delete transport;
|
||||
}
|
||||
if(manager)
|
||||
delete manager;
|
||||
}
|
||||
@@ -72,25 +64,17 @@ void urpStub::Dispatch(bcICall *call) {
|
||||
interfaceInfo->GetMethodInfo(mid, (const nsXPTMethodInfo **)&info);
|
||||
PRUint32 paramCount = info->GetParamCount();
|
||||
printf("ThreadID is written %d\n",paramCount);
|
||||
nsXPTCVariant* params;
|
||||
bcXPCOMMarshalToolkit* mt = NULL;
|
||||
if (paramCount > 0) {
|
||||
params = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
|
||||
mt = new bcXPCOMMarshalToolkit(mid, interfaceInfo, params, call->GetORB());
|
||||
bcIUnMarshaler * um = call->GetUnMarshaler();
|
||||
mt->UnMarshal(um);
|
||||
if (params == nsnull) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
manager->SendUrpRequest(oid, iid, mid, interfaceInfo, call, params, paramCount,
|
||||
PRMonitor* mon = PR_NewMonitor();
|
||||
PR_EnterMonitor(mon);
|
||||
manager->SetCall(call, mon);
|
||||
manager->SendUrpRequest(oid, iid, mid, interfaceInfo, call, paramCount,
|
||||
info);
|
||||
manager->ReadReply(params, paramCount, info, interfaceInfo, mid);
|
||||
if (mt != NULL) { //nb to do what about nsresult ?
|
||||
bcIMarshaler * m = call->GetMarshaler();
|
||||
mt->Marshal(m);
|
||||
}
|
||||
if(NS_FAILED(PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT))) {
|
||||
printf("Can't wait on cond var\n");
|
||||
exit(-1);
|
||||
}
|
||||
PR_ExitMonitor(mon);
|
||||
PR_DestroyMonitor(mon);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,11 +30,10 @@
|
||||
|
||||
class urpStub : public bcIStub {
|
||||
public:
|
||||
urpStub(char* cStr);
|
||||
urpStub(urpConnection* conn);
|
||||
virtual ~urpStub();
|
||||
virtual void Dispatch(bcICall *call) ;
|
||||
private:
|
||||
urpTransport* transport;
|
||||
urpManager* manager;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user