Compare commits

..

2 Commits

Author SHA1 Message Date
heikki%netscape.com
a637f81f7f new project started
git-svn-id: svn://10.0.0.236/branches/mozilla@91184 18797224-902f-48f8-a5cc-f745e15eee43
2001-04-03 22:13:38 +00:00
(no author)
6cfadae5d1 This commit was manufactured by cvs2svn to create branch 'mozilla'.
git-svn-id: svn://10.0.0.236/branches/mozilla@8534 18797224-902f-48f8-a5cc-f745e15eee43
1998-08-26 18:36:10 +00:00
116 changed files with 102 additions and 10898 deletions

View File

@@ -1,37 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../..
topsrcdir = ../..
VPATH = .
srcdir = .
include $(DEPTH)/config/autoconf.mk
DIRS= \
connect \
xpcom \
java \
# xpcom/test/ \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -1,37 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS= \
connect \
xpcom \
java \
# xpcom/test/ \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -1,78 +0,0 @@
Black Connect
================================
This directory contains the Black Connect
The sources is divided into three directories
connect
public headers.
ORB implementation.
xpcom
XPCOM stubs and proxy implementation
java
JAVA stubs and proxy implementation
Java component loader
===============================================
Solaris directions
===============================================
Requirements:
* current mozilla built tree
* JDK1.3
* Perl 5 must be in your path
How To Build:
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie export JDKHOME=/usr/local/jdk1.3
* Add following directories to to your LD_LIBRARY_PATH:
$MOZILLA_FIVE_HOME:$JDKHOME/jre/lib/$HOSTTYPE/native_threads:$JDKHOME/jre/lib/$HOSTTYPE/classic:
$JDKHOME/jre/lib/$HOSTTYPE/:
* type "gmake"
==============================================
Linux directions
===============================================
Requirements:
* mozilla m16 build tree
* JDK1.3 from IBM
* Perl 5 must be in your path
How To Build:
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie export JDKHOME=/usr/local/jdk1.3
* Add following directories to to your LD_LIBRARY_PATH:
$MOZILLA_FIVE_HOME:$JDKHOME/jre/bin:$JDKHOME/jre/bin/classic:
* remove jni* jri* from MOZILLA_FIVE_HOME/dist/include
* type "gmake"
==============================================
How to run test java component
===============================================
* cd java/test
* gmake
* add $MOZILLA_FIVE_HOME/dist/classes to your CLASSPATH
Test component would be placed in dist/bin/componets and loaded on mozilla
sturtup (or you can use regxpcom for testing)

View File

@@ -1,34 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS= \
xpcom \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -1,33 +0,0 @@
#!nmake
#
# 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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ..\..\..
DIRS= \
src \
xpcom \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,80 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcDefs_h
#define __bcDefs_h
#include "prtypes.h"
#include "nsID.h"
enum bcXPType {
bc_T_I8 = 1, bc_T_U8, bc_T_I16, bc_T_U16,
bc_T_I32, bc_T_U32, bc_T_I64, bc_T_U64,
bc_T_FLOAT, bc_T_DOUBLE, bc_T_BOOL,
bc_T_CHAR, bc_T_WCHAR,
bc_T_IID ,
bc_T_CHAR_STR, bc_T_WCHAR_STR,
bc_T_ARRAY,
bc_T_INTERFACE,
bc_T_UNDEFINED
};
typedef long bcOID;
typedef nsID bcIID;
typedef long bcTID ;
typedef unsigned int bcMID;
typedef unsigned int size_t;
#endif

View File

@@ -1,35 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIAllocator_h
#define __bcIAllocator_h
#include "bcDefs.h"
class bcIAllocator {
public:
virtual void * Alloc(size_t size) = 0;
virtual void Free(void *ptr) = 0;
virtual void * Realloc(void* ptr, size_t size) = 0;
};
#endif

View File

@@ -1,48 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcICall_h
#define __bcICall_h
#include "bcIMarshaler.h"
#include "bcIUnMarshaler.h"
class bcIORB;
class bcICall {
public:
virtual int GetParams(bcIID *, bcOID *, bcMID *) = 0;
virtual bcIMarshaler * GetMarshaler() = 0;
virtual bcIUnMarshaler * GetUnMarshaler() = 0;
virtual bcIORB * GetORB() = 0;
};
#endif

View File

@@ -1,39 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIMarshaler_h
#define __bcIMarshaler_h
#include "bcIAllocator.h"
#include "bcDefs.h"
class bcIMarshaler {
public:
virtual int WriteSimple(void *ptr, bcXPType type) = 0;
virtual int WriteString(void *ptr, size_t size) = 0;
};
#endif

View File

@@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIORB_h
#define __bcIORB_h
#include "bcICall.h"
#include "bcDefs.h"
#include "bcIStub.h"
class bcIORB {
public:
virtual bcOID RegisterStub(bcIStub *stub) = 0;
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID) = 0;
virtual int SendReceive(bcICall *) = 0;
//virtual IThread * GetThread(TID) = 0;
};
#endif

View File

@@ -1,31 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIStub_h
#define __bcIStub_h
#include "bcICall.h"
class bcIStub {
public:
virtual void Dispatch(bcICall *call) = 0;
//nb shortcut
};
#endif

View File

@@ -1,29 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIThread_h
#define __bcIThread_h
class bcIThread {
public:
virtual AttachCall(bcICall *, short isAsync) = 0;
};
#endif

View File

@@ -1,35 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIUnMarshaler_h
#define __bcIUnMarshaler_h
#include "bcIAllocator.h"
#include "bcDefs.h"
class bcIUnMarshaler {
public:
virtual int ReadSimple(void *ptr, bcXPType type) = 0;
virtual int ReadString(void *ptr, size_t *size, bcIAllocator * allocator = 0) = 0;
};
#endif

View File

@@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include <stdlib.h>
#include "Allocator.h"
#include <iostream.h>
Allocator::Allocator() {
}
Allocator::~Allocator() {
}
void * Allocator::Alloc(size_t size) {
cout<<"Allocator::Alloc("<<size<<")\n";
return malloc(size);
}
void Allocator::Free(void *ptr) {
free(ptr);
}
void * Allocator::Realloc(void *ptr, size_t size) {
return realloc(ptr,size);
}

View File

@@ -1,35 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __Allocator_h
#define __Allocator_h
#include "bcIAllocator.h"
class Allocator : public bcIAllocator {
public:
Allocator();
virtual ~Allocator();
virtual void * Alloc(size_t size);
virtual void Free(void *ptr);
virtual void * Realloc(void* ptr, size_t size);
};
#endif

View File

@@ -1,78 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "Call.h"
#include "Marshaler.h"
#include "UnMarshaler.h"
Call::Call() {
}
Call::Call(bcIID *_iid, bcOID *_oid, bcMID _mid, bcIORB *_orb):out(0),in(0) {
iid = *_iid;
oid = *_oid;
mid = _mid;
orb = _orb;
}
Call::~Call() {
if (out)
delete out;
if (in)
delete in;
}
int Call::GetParams(bcIID *_iid, bcOID *_oid, bcMID *_mid) {
*_iid = iid;
*_oid = oid;
*_mid = mid;
return 0;
}
bcIMarshaler * Call::GetMarshaler() {
out = new ostrstream();
return new Marshaler(out);
}
bcIUnMarshaler * Call::GetUnMarshaler() {
if (!out) {
return NULL;
}
char *buf = out->str();
// cout<<"Call::GetUnMarshaler "<<out->pcount()<<"\n";
#if 0
cout<<"Call::GetUnMarshaler buf:\n";
for (int i = 0; i < out->pcount(); i++) {
cout<<" buf["<<i<<"]"<<(unsigned)buf[i]<<"\n";
}
#endif
if (out->pcount()) {
in = new istrstream(buf,out->pcount());
}
return new UnMarshaler(in);
}
bcIORB * Call::GetORB() {
return orb;
}

View File

@@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __Call_h
#define __Call_h
#ifdef WIN32
#include <strstrea.h>
#else
#include <strstream.h>
#endif
#include "bcICall.h"
class Call : public bcICall {
public:
Call();
Call(bcIID *, bcOID *, bcMID, bcIORB *orb);
virtual ~Call();
virtual int GetParams(bcIID *, bcOID *, bcMID*);
virtual bcIORB * GetORB();
virtual bcIMarshaler * GetMarshaler();
virtual bcIUnMarshaler * GetUnMarshaler();
private :
ostrstream *out;
istrstream *in;
bcIID iid;
bcOID oid;
bcMID mid;
bcIORB *orb;
};
#endif

View File

@@ -1,52 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include <iostream.h>
#include <string.h>
#include "Marshaler.h"
#include "util.h"
Marshaler::Marshaler(ostream *_out) {
out = _out;
}
Marshaler::~Marshaler() {
}
int Marshaler::WriteSimple(void *ptr, bcXPType type) {
out->write((const char*)ptr, type2size(type));
return 0;
}
int Marshaler::WriteString(void *ptr, size_t size) {
if (!size
&& ptr) {
size = 1;
}
out->write((const char*)&size, sizeof(size_t));
if (size) {
out->write((const char*)ptr,type2size(bc_T_CHAR)*size);
}
return 0;
}

View File

@@ -1,41 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __Marshaler_h
#define __Marshaler_h
#include <iostream.h>
#include "bcIMarshaler.h"
class Marshaler : public bcIMarshaler {
public:
Marshaler(ostream *out);
virtual ~Marshaler();
virtual int WriteSimple(void *ptr, bcXPType type);
virtual int WriteString(void *ptr, size_t size);
private:
ostream * out;
};
#endif

View File

@@ -1,65 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "ORB.h"
#include "Call.h"
ORB::ORB() {
currentID = 1;
for (int i = 0; i < STUBS_COUNT; i++) {
stubs[i] = 0;
}
}
ORB::~ORB() {
}
bcOID ORB::RegisterStub(bcIStub *stub) {
stubs[currentID] = stub;
return currentID++;
}
bcICall * ORB::CreateCall(bcIID *iid, bcOID *oid, bcMID mid) {
return new Call(iid, oid, mid,this);
}
int ORB::SendReceive(bcICall *call) {
bcIID iid;
bcOID oid;
bcMID mid;
call->GetParams(&iid,&oid,&mid);
bcIStub *stub = GetStub(&oid);
if (stub) {
stub->Dispatch(call);
return 0;
} else {
return 1; //nb need to think about error values
}
}
bcIStub * ORB::GetStub(bcOID *oid) {
return stubs[*oid];
}

View File

@@ -1,40 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __ORB_h
#define __ORB_h
#include "bcIORB.h"
#define STUBS_COUNT (50000)
class ORB : public bcIORB {
public:
ORB();
virtual ~ORB();
virtual bcOID RegisterStub(bcIStub *stub);
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID);
virtual int SendReceive(bcICall *);
private:
bcIStub * GetStub(bcOID *);
bcIStub * stubs[STUBS_COUNT]; //nb :) it's jast for now. (Mon Mar 13 16:53:03 PST 2000)
int currentID;
};
#endif

View File

@@ -1,53 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "UnMarshaler.h"
#include "util.h"
UnMarshaler::UnMarshaler(istream *_in) {
in = _in;
}
UnMarshaler::~UnMarshaler() {
}
int UnMarshaler::ReadSimple(void *ptr, bcXPType type) {
char *p = (char *)ptr;
int size = type2size(type);
in->read(p,size );
return 0;
}
int UnMarshaler::ReadString(void *ptr, size_t *size, bcIAllocator * allocator) {
size_t length;
in->read((char*)size,sizeof(size_t));
*(char**)ptr = (char *)allocator->Alloc(*size * type2size(bc_T_CHAR));
if (*size) {
in->read(*(char**)ptr,*size * type2size(bc_T_CHAR));
}
if (*size == 1) {
if (!(*(char**)ptr)[0]) {
*size = 0;
}
}
return 0;
}

View File

@@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __UnMarshaler_h
#define __UnMarshaler_h
#include <iostream.h>
#include "bcIUnMarshaler.h"
class UnMarshaler : public bcIUnMarshaler {
public:
UnMarshaler(istream *in);
virtual ~UnMarshaler();
virtual int ReadSimple(void *ptr, bcXPType type);
virtual int ReadString(void *ptr, size_t *size, bcIAllocator * allocator);
private:
istream *in;
};
#endif

View File

@@ -1,62 +0,0 @@
#!nmake
#
# 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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = lib
LIBRARY_NAME = bcorbcore
LIB=.\$(OBJDIR)\bcorbcore.lib
OBJS= \
.\$(OBJDIR)\Allocator.obj \
.\$(OBJDIR)\Call.obj \
.\$(OBJDIR)\Marshaler.obj \
.\$(OBJDIR)\ORB.obj \
.\$(OBJDIR)\UnMarshaler.obj \
.\$(OBJDIR)\util.obj \
$(NULL)
EXPORTS = \
..\public\bcIORB.h \
..\public\bcDefs.h \
..\public\bcICall.h \
..\public\bcIUnMarshaler.h \
..\public\bcIAllocator.h \
..\public\bcIMarshaler.h \
..\public\bcIStub.h \
..\public\bcIThread.h
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
INCS = \
-I..\public -I..\src \
$(INCS) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIB)
$(MAKE_INSTALL) $(LIB) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "util.h"
#include "bcDefs.h"
size_t type2size(bcXPType type) {
size_t res = 0;
switch (type) {
case bc_T_CHAR :
res = sizeof(char);
break;
case bc_T_WCHAR:
res = 2; //nb
break;
case bc_T_I8:
case bc_T_U8:
res = sizeof(PRInt8);
break;
case bc_T_I16:
case bc_T_U16:
res = sizeof(PRInt16);
break;
case bc_T_I32:
case bc_T_U32:
res = sizeof(PRInt32);
break;
case bc_T_I64:
case bc_T_U64:
res = sizeof(PRInt64);
break;
case bc_T_FLOAT:
res = sizeof(float);
break;
case bc_T_DOUBLE:
res = sizeof(double);
break;
case bc_T_BOOL:
res = sizeof(PRBool);
break;
case bc_T_IID:
res = sizeof(nsID);
break;
case bc_T_INTERFACE:
res = sizeof(bcOID);
break;
default:
res = 0;
}
return res;
}

View File

@@ -1,27 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __util_h
#define __util_h
#include "bcDefs.h"
size_t type2size(bcXPType type);
#endif

View File

@@ -1,65 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = bcorb
MODULE = bcorb
IS_COMPONENT = 1
CPPSRCS = \
bcORB.cpp \
../src/Allocator.cpp \
../src/Call.cpp \
../src/Marshaler.cpp \
../src/ORB.cpp \
../src/UnMarshaler.cpp \
../src/util.cpp \
$(NULL)
EXPORTS = \
bcORB.h \
../public/bcIORB.h \
../public/bcDefs.h \
../public/bcICall.h \
../public/bcIUnMarshaler.h \
../public/bcIAllocator.h \
../public/bcIMarshaler.h \
../public/bcIStub.h \
../public/bcIThread.h
CXXFLAGS += -I../public -I../src
include $(topsrcdir)/config/rules.mk

View File

@@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcORB.h"
#include "../src/ORB.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(bcORB);
static nsModuleComponentInfo components[] =
{
{
"Black Connect ORB",
BC_ORB_CID,
BC_ORB_PROGID,
bcORBConstructor
}
};
NS_IMPL_NSGETMODULE("BlackConnectORB",components);
NS_IMPL_ISUPPORTS(bcORB,NS_GET_IID(bcORB));
bcORB::bcORB() :
orb(0)
{
NS_INIT_REFCNT();
}
bcORB::~bcORB() {
if (orb) {
delete orb; //nb should we destroy it?
}
}
NS_IMETHODIMP bcORB::GetORB(bcIORB **_orb) {
if (!_orb) {
printf("--bcORB::GetORB\n");
return NS_ERROR_NULL_POINTER;
}
if (!orb) {
orb = new ORB();
}
*_orb = orb;
return NS_OK;
}

View File

@@ -1,54 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef _bcORB_h
#define _bcORB_h
#include "nsISupports.h"
#include "bcIORB.h"
/*29bde10c-1dd2-11b2-ab23-ebe06c6baec5*/
#define BC_ORB_IID \
{ 0x29bde10c, 0x1dd2, 0x11b2, \
{0xab, 0x23, 0xeb, 0xe0, 0x6c, 0x6b, 0xae, 0xc5}}
#define BC_ORB_PROGID "component://netscape/blackwood/blackconnect/orb"
/*ffa0d768-1dd1-11b2-8bf2-ab56f26ea844*/
#define BC_ORB_CID \
{ 0xffa0d768, 0x1dd1, 0x11b2, \
{0x8b, 0xf2, 0xab, 0x56, 0xf2, 0x6e, 0xa8, 0x44 }}
class bcORB : public nsISupports {
NS_DECL_ISUPPORTS
NS_DEFINE_STATIC_IID_ACCESSOR(BC_ORB_IID)
NS_IMETHOD GetORB(bcIORB **orb);
bcORB();
virtual ~bcORB();
private:
bcIORB *orb;
};
#endif

View File

@@ -1,47 +0,0 @@
#!nmake
#
# 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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = DLL
MODULE=bcorb
COMPONENT = 1
DLLNAME = bcorb
DLL=.\$(OBJDIR)\$(DLLNAME).dll
OBJS= \
.\$(OBJDIR)\bcORB.obj \
$(NULL)
EXPORTS = \
bcORB.h \
$(NULL)
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib $(DIST)\lib\bcorbcore.lib
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
clobber::
rm -f $(DIST)\bin\components\$(DLLNAME).dll

View File

@@ -1,32 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS= xpidl src loader classes components
include $(topsrcdir)/config/rules.mk

View File

@@ -1,43 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
JAVA_OR_NSJVM=1
include $(DEPTH)/config/autoconf.mk
JAR_PLUGLET_CLASSES = \
org/mozilla/xpcom \
$(NULL)
JDIRS = $(JAR_PLUGLET_CLASSES)
include $(topsrcdir)/config/rules.mk
JAVAC=$(JDKHOME)/bin/javac -classpath .:$(CLASSPATH) -d $(DIST)/classes

View File

@@ -1,40 +0,0 @@
#
# 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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
IGNORE_MANIFEST=1
DEPTH = ..\..\..\..
JAVA_OR_NSJVM=1
NO_CAFE=1
include <$(DEPTH)\config\config.mak>
JAR_PLUGLET_CLASSES = \
org\mozilla\xpcom \
$(NULL)
JDIRS = $(JAR_PLUGLET_CLASSES)
JAVAC_PROG=$(JDKHOME)\bin\javac
JAVAC_FLAGS=-classpath "$(CLASSPATH);$(JAVA_DESTPATH)" -d "$(JAVA_DESTPATH)"
include <$(DEPTH)\config\rules.mak>
include <$(DEPTH)\config\javarules.mak>

View File

@@ -1,64 +0,0 @@
/* -*- Mode: java; 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
import java.net.URLClassLoader;
import java.net.URL;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.io.InputStream;
import java.io.File;
public class ComponentLoader {
// path to jar file. Name of main class sould to be in MANIFEST.
public static Object loadComponent(String location) {
try {
File file = (new File(location)).getCanonicalFile(); //To avoid spelling diffs, e.g c: and C:
location = file.getAbsolutePath();
if (File.separatorChar != '/') {
location = location.replace(File.separatorChar,'/');
}
if (!location.startsWith("/")) {
location = "/" + location;
}
URL url = new URL("file:"+location);
URLClassLoader loader = URLClassLoader.newInstance(new URL[]{url});
URL manifestURL = new URL("jar:file:"+location+"!/META-INF/MANIFEST.MF");
InputStream inputStream = manifestURL.openStream();
Manifest manifest = new Manifest(inputStream);
Attributes attr = manifest.getMainAttributes();
String componentClassName = attr.getValue("Component-Class");
if (componentClassName == null) {
//nb
return null;
}
Class component = loader.loadClass(componentClassName);
InterfaceRegistry.register(component);
Object object = component.newInstance();
return object;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@@ -1,33 +0,0 @@
/* -*- Mode: java; 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
public class Components {
public static nsIComponentManager getComponentManager() {
return componentMgr;
}
public static void setComponentManager(nsIComponentManager mgr) {
componentMgr = mgr;
}
private static nsIComponentManager componentMgr = null;
};

View File

@@ -1,28 +0,0 @@
/* -*- Mode: Java; 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):
*
* Igor Kushnirskiy <idk@eng.sun.com>
*
*/
package org.mozilla.xpcom;
public class Debug {
public static native void log(String str);
}

View File

@@ -1,58 +0,0 @@
/* -*- Mode: java; 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
public class IID {
public IID(String iid) {
this.iid = ((iid == null) ? "" : iid).toLowerCase();;
}
public boolean equals(Object obj) {
if (! (obj instanceof IID)) {
return false;
}
boolean res = iid.equals(((IID)obj).iid);
return res;
}
public String toString() {
return "org.mozilla.xpcom.IID@"+iid;
}
public int hashCode() {
int h = iid.hashCode();
return h;
}
public String getString() {
return iid;
}
private String iid;
public static Class TYPE;
static {
try {
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
} catch (Exception e) { //it could not happen
TYPE = null;
}
}
}

View File

@@ -1,244 +0,0 @@
/* -*- Mode: Java; 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):
* Denis Sharypov <sdv@sparc.spb.su>
*/
package org.mozilla.xpcom;
import java.util.HashSet;
import java.util.Hashtable;
import java.lang.reflect.*;
public class InterfaceRegistry {
private static String IID_STRING = "IID";
private static Hashtable interfaces = null;
private static Hashtable iMethods = null;
private static HashSet keywords = null;
private static boolean debug = true;
private InterfaceRegistry() {
}
public static void register(nsISupports obj) {
if (obj == null) {
return;
}
Class cl = obj.getClass();
register(cl);
}
public static void register(String name) {
try {
register(Class.forName(name));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void register(Class cl) {
if (cl == null) {
return;
}
if (interfaces == null) {
interfaces = new Hashtable();
}
if (iMethods == null) {
iMethods = new Hashtable();
}
if (keywords == null) {
keywords = new HashSet(javaKeywords.length);
for (int i = 0; i < javaKeywords.length; i++) {
keywords.add(javaKeywords[i]);
}
}
if (!cl.isInterface()) {
Class[] ifaces = cl.getInterfaces();
for (int i = 0; i < ifaces.length; i++) {
registerInterfaces(ifaces[i]);
}
} else {
registerInterfaces(cl);
}
}
public static void unregister(IID iid) {
interfaces.remove(iid);
iMethods.remove(iid);
}
private static Hashtable registerInterfaces(Class cl) {
try {
Object iidStr = cl.getField(IID_STRING).get(cl);
if (iidStr instanceof String) {
IID iid = new IID((String)iidStr);
// if this iface hasn't been registered, yet
if (interfaces.get(iid) == null) {
String[] methodNames = Utilities.getInterfaceMethodNames((String)iidStr);
if (methodNames != null) {
Method[] rmethods = new Method[methodNames.length];
Class[] ifaces = cl.getInterfaces();
// check for single inheritance (xpcom)
if (ifaces.length < 2) {
// recursively get all parent interface methods
Hashtable mhash = null;
Method[] methods = cl.getDeclaredMethods();
// the very super iface
if (ifaces.length == 0) {
mhash = new Hashtable(methods.length);
} else {
mhash = new Hashtable(registerInterfaces(ifaces[0]));
}
for (int i = 0; i < methods.length; i++) {
mhash.put(methods[i].getName(), methods[i]);
}
for (int j = methodNames.length - 1; j >= 0; j--) {
rmethods[j] = (Method)mhash.get(subscriptMethodName(methodNames[j]));
}
interfaces.put(iid, cl);
iMethods.put(iid, new MethodArray(rmethods, mhash));
debug(cl.getName() + ": " + iid + " ( " + cl + " )");
printMethods(rmethods);
return mhash;
}
}
// simply pass iface methods
} else {
MethodArray m = (MethodArray)iMethods.get(iid);
if (m != null) {
return m.names;
}
}
}
} catch (NoSuchFieldException e) {
// the interface doesn't define IID field
debug("no such field...");
} catch (IllegalAccessException e1) {
debug("can't access field...");
}
return new Hashtable();
}
public static Class getInterface(IID iid) {
Object obj = null;
if (interfaces != null) {
obj = interfaces.get(iid);
}
if (obj == null || !(obj instanceof Class)) {
return null;
}
return (Class)obj;
}
public static Method getMethodByIndex(int index, IID iid) {
Method result = null;
MethodArray m = (MethodArray)iMethods.get(iid);
if (m != null && m.methods !=null) {
try {
result = m.methods[index];
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
public static int getIndexByMethod(Method method, IID iid) {
int result = -1;
MethodArray m = (MethodArray)iMethods.get(iid);
if (m != null && m.methods != null) {
for (int i = 0; i < m.methods.length; i++) {
if (m.methods[i] != null && method.equals(m.methods[i])) {
result = i;
break;
}
}
}
return result;
}
private static String subscriptMethodName(String str) {
if (keywords.contains(str)) {
return str + "_";
}
return str;
}
// methods for debugging
private static void printMethods(Method[] methods) {
if (debug) {
for (int i = 0; i < methods.length; i++) {
printMethod(methods[i]);
}
}
}
private static void printMethod(Method m) {
if (m == null) {
Debug.log("<null>");
return;
}
Class retType = m.getReturnType();
Class[] paramTypes = m.getParameterTypes();
String name = m.getName();
System.out.print(Modifier.toString(m.getModifiers()));
System.out.print(" " + retType.getName() + " " + name
+ "(");
for (int j = 0; j < paramTypes.length; j++) {
if (j > 0) System.out.print(", ");
System.out.print(paramTypes[j].getName());
}
Debug.log(");");
}
private static void debug(String str) {
if (debug) {
Debug.log(str);
}
}
private static String[] javaKeywords = {
"abstract", "default", "if" , "private" , "this" ,
"boolean" , "do" , "implements", "protected" , "throw" ,
"break" , "double" , "import", "public" , "throws" ,
"byte" , "else" , "instanceof", "return" , "transient",
"case" , "extends", "int" , "short" , "try" ,
"catch" , "final" , "interface" , "static" , "void" ,
"char" , "finally", "long" , "strictfp" , "volatile" ,
"class" , "float" , "native" , "super" , "while" ,
"const" , "for" , "new" , "switch" ,
"continue", "goto" , "package" , "synchronized",
// non-final method names of Object class
"toString", "clone" , "finalize" , "hashCode" , "equals"};
}
class MethodArray {
Method[] methods;
Hashtable names;
MethodArray(Method[] _methods, Hashtable _names) {
methods = _methods;
names = _names;
}
}

View File

@@ -1,92 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
import java.util.*;
import java.lang.reflect.*;
import java.lang.ref.*;
class ProxyKey {
ProxyKey(long _oid, IID _iid) {
oid = new Long(_oid);
iid = _iid;
}
public boolean equals(Object obj) {
if (! (obj instanceof ProxyKey)) {
return false;
}
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
}
public int hashCode() {
return oid.hashCode();
}
public String toString() {
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
}
Long oid;
IID iid;
}
public class ProxyFactory {
public static Class getInterface(IID iid) {
Debug.log("--[java] ProxyFactory.getInterface "+iid);
return InterfaceRegistry.getInterface(iid);
}
public static Object getProxy(long oid, IID iid, long orb) {
try {
Debug.log("--[java] ProxyFactory.getProxy "+iid);
ProxyKey key = new ProxyKey(oid, iid);
Object obj = null;
Object result = null;
if (proxies != null) {
obj = proxies.get(key);
if (obj != null
&& (obj instanceof Reference)) {
result = ((Reference)obj).get();
}
} else {
proxies = new Hashtable();
}
if (result == null) {
Class inter = getInterface(iid);
if (inter == null) {
Debug.log("--[java] ProxyFactory.getProxy we did not find interface for iid="+iid+"returing null");
return null;
}
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
proxies.put(new WeakReference(result), key);
}
Debug.log("--[java] ProxyFactory.getProxy we got proxy "+result);
return result;
} catch (Exception e) {
Debug.log("--[java] ProxyFactory.getProxy we got exception "+e);
}
return null;
}
protected static Hashtable proxies = null;
}

View File

@@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
import java.lang.reflect.*;
class ProxyHandler implements InvocationHandler {
ProxyHandler(long _oid, IID _iid, long _orb) {
oid = _oid;
iid = _iid;
orb = _orb;
}
public Object invoke(Object proxy,
Method method,
Object[] args) throws Throwable {
Debug.log("--[java]ProxyHandler.invoke "+method);
String str = method.getName();
if (str.equals("toString")) {
return "ProxyObject@{oid = "+oid+" iid = "+iid+"}";
} else if (str.equals("clone")) {
throw new java.lang.CloneNotSupportedException();
} else if (str.equals("finalize")) {
finalize();
} else if (str.equals("equals")) {
if (args[0] instanceof ProxyHandler) {
ProxyHandler p = (ProxyHandler)args[0];
return new Boolean((oid == p.oid) &&
iid.equals(p.iid) &&
(orb == p.orb));
}
} else if (str.equals("hashCode")) {
return new Integer(hashCode());
} else {
return Utilities.callMethod(oid, method, iid, orb, args);
}
return null;
}
long getOID() {
return oid;
}
private long oid;
private IID iid;
private long orb;
}

View File

@@ -1,92 +0,0 @@
/* -*- Mode: java; 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
import java.lang.reflect.*;
public class Utilities {
static Class objectArrayClass = (new Object[1]).getClass();
static Object callMethodByIndex(Object obj, IID iid, int mid, Object[] args) {
Debug.log("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
Object retObject = null;
for (int i = 0; i < args.length; i++) {
Debug.log("--[java]callMethodByIndex args["+i+"] = "+args[i]);
}
Method method = InterfaceRegistry.getMethodByIndex(mid,iid);
Debug.log("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method);
try {
if (method != null) {
for (int i = 0 ; i < args.length; i++) {
/* this is hack. at the time we are doing holders for [out] interfaces
we might do not know the expected type and we are producing Object[] insted of
nsISupports[] for example. Here we are taking care about it.
If args[i] is Object[] of size 1 we are checking with expected type from method.
In case it is not expeceted type we are creating object[] of expected type.
*/
if (objectArrayClass.equals(args[i].getClass())
&& ((Object[])args[i]).length == 1) {
Class[] parameterTypes = method.getParameterTypes();
if (!objectArrayClass.equals(parameterTypes[i])
&& parameterTypes[i].isArray()) {
Class componentType = parameterTypes[i].getComponentType();
args[i] = java.lang.reflect.Array.newInstance(componentType,1);
}
}
}
retObject = method.invoke(obj,args);
Debug.log("--[java] Utilities.callMethodByIndex: retObject = " + retObject);
}
} catch (Exception e) {
e.printStackTrace();
}
Debug.log("--[java] Utilities.callMethodByIndex method finished"+method);
return retObject;
}
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
Debug.log("--[java]Utilities.callMethod "+method);
int mid = InterfaceRegistry.getIndexByMethod(method, iid);
if (mid < 0) {
Debug.log("--[java]Utilities.callMethod we do not have implementation for "+method);
return null;
}
Debug.log("--[java]Utilities.callMethod "+mid);
return callMethodByIndex(oid,mid,iid.getString(), orb, args);
}
private static native Object callMethodByIndex(long oid, int index, String iid, long orb, Object[] args);
static native String[] getInterfaceMethodNames(String iid);
static {
System.loadLibrary("bcjavastubs");
}
}

View File

@@ -1,330 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsIComponentManager.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsIComponentManager
*
* IID: 0x8458a740-d5dc-11d2-92fb-00e09805570f
*/
public interface nsIComponentManager extends nsISupports
{
public static final String IID =
"8458a740-d5dc-11d2-92fb-00e09805570f";
/**
* findFactory
*
* Returns the factory object that can be used to create instances of
* CID aClass
*
* @param aClass The classid of the factory that is being requested
*/
/* nsIFactory findFactory (in nsCIDRef aClass); */
public nsIFactory findFactory(IID aClass);
/**
* getClassObject
*
* @param aClass : CID of the class whose class object is requested
* @param aIID : IID of an interface that the class object is known to
* to implement. nsISupports and nsIFactory are known to
* be implemented by the class object.
*/
/**
* contractIDToClassID
*
* Get the ClassID for a given ContractID. Many ClassIDs may implement a
* ContractID. In such a situation, this returns the preferred ClassID, which
* happens to be the last registered ClassID.
*
* @param aContractID : Contractid for which ClassID is requested
* @return aClass : ClassID return
*/
/**
* classIDToContractid
*
* Get the ContractID for a given ClassID. A ClassIDs may implement multiple
* ContractIDs. This function return the last registered ContractID.
*
* @param aClass : ClassID for which ContractID is requested.
* @return aClassName : returns class name asssociated with aClass
* @return : ContractID last registered for aClass
*/
/* string CLSIDToContractID (in nsCIDRef aClass, out string aClassName); */
public String cLSIDToContractID(IID aClass, String[] aClassName);
/**
* createInstance
*
* Create an instance of the CID aClass and return the interface aIID.
*
* @param aClass : ClassID of object instance requested
* @param aDelegate : Used for aggregation
* @param aIID : IID of interface requested
*/
/**
* createInstanceByContractID
*
* Create an instance of the CID that implements aContractID and return the
* interface aIID. This is a convenience function that effectively does
* ContractIDToClassID() followed by CreateInstance().
*
* @param aContractID : aContractID of object instance requested
* @param aDelegate : Used for aggregation
* @param aIID : IID of interface requested
*/
/**
* registryLocationForSpec
*
* Given a file specification, return the registry representation of
* the filename. Files that are found relative to the components
* directory will have a registry representation
* "rel:<relative-native-path>" while filenames that are not, will have
* "abs:<full-native-path>".
*/
/* string registryLocationForSpec (in nsIFile aSpec); */
public String registryLocationForSpec(nsIFile aSpec);
/**
* specForRegistyLocation
*
* Create a file specification for the registry representation (rel:/abs:)
* got via registryLocationForSpec.
*/
/* nsIFile specForRegistryLocation (in string aLocation); */
public nsIFile specForRegistryLocation(String aLocation);
/**
* registerFactory
*
* Register a factory and ContractID associated with CID aClass
*
* @param aClass : CID of object
* @param aClassName : Class Name of CID
* @param aContractID : ContractID associated with CID aClass
* @param aFactory : Factory that will be registered for CID aClass
* @param aReplace : Boolean that indicates whether to replace a previous
* registration for the CID aClass.
*/
/* void registerFactory (in nsCIDRef aClass, in string aClassName, in string aContractID, in nsIFactory aFactory, in boolean aReplace); */
public void registerFactory(IID aClass, String aClassName, String aContractID, nsIFactory aFactory, boolean aReplace);
/**
* registerComponent
*
* Register a native dll module via its registry representation as returned
* by registryLocationForSpec() as the container of CID implemenation
* aClass and associate aContractID and aClassName to the CID aClass. Native
* dll component type is assumed.
*
* @param aClass : CID implemenation contained in module
* @param aClassName : Class name associated with CID aClass
* @param aContractID : ContractID associated with CID aClass
* @param aLocation : Location of module (dll). Format of this is the
* registry representation as returned by
* registryLocationForSpec()
* @param aReplace : Boolean that indicates whether to replace a previous
* module registration for aClass.
* @param aPersist : Remember this registration across sessions.
*/
/* void registerComponent (in nsCIDRef aClass, in string aClassName, in string aContractID, in string aLocation, in boolean aReplace, in boolean aPersist); */
public void registerComponent(IID aClass, String aClassName, String aContractID, String aLocation, boolean aReplace, boolean aPersist);
/**
* registerComponentWithType
*
* Register a module's location via its registry representation
* as returned by registryLocationForSpec() as the container of CID implemenation
* aClass of type aType and associate aContractID and aClassName to the CID aClass.
*
* @param aClass : CID implemenation contained in module
* @param aClassName : Class name associated with CID aClass
* @param aContractID : ContractID associated with CID aClass
* @param aSpec : Filename spec for module's location.
* @param aLocation : Location of module of type aType. Format of this string
* is the registry representation as returned by
* registryLocationForSpec()
* @param aReplace : Boolean that indicates whether to replace a previous
* loader registration for aClass.
* @param aPersist : Remember this registration across sessions.
* @param aType : Component Type of CID aClass.
*/
/* void registerComponentWithType (in nsCIDRef aClass, in string aClassName, in string aContractID, in nsIFile aSpec, in string aLocation, in boolean aReplace, in boolean aPersist, in string aType); */
public void registerComponentWithType(IID aClass, String aClassName, String aContractID, nsIFile aSpec, String aLocation, boolean aReplace, boolean aPersist, String aType);
/**
* registerComponentSpec
*
* Register a native dll module via its file specification as the container
* of CID implemenation aClass and associate aContractID and aClassName to the
* CID aClass. Native dll component type is assumed.
*
* @param aClass : CID implemenation contained in module
* @param aClassName : Class name associated with CID aClass
* @param aContractID : ContractID associated with CID aClass
* @param aLibrary : File specification Location of module (dll).
* @param aReplace : Boolean that indicates whether to replace a previous
* module registration for aClass.
* @param aPersist : Remember this registration across sessions.
*/
/* void registerComponentSpec (in nsCIDRef aClass, in string aClassName, in string aContractID, in nsIFile aLibrary, in boolean aReplace, in boolean aPersist); */
public void registerComponentSpec(IID aClass, String aClassName, String aContractID, nsIFile aLibrary, boolean aReplace, boolean aPersist);
/**
* registerComponentLib
*
* Register a native dll module via its dll name (not full path) as the
* container of CID implemenation aClass and associate aContractID and aClassName
* to the CID aClass. Native dll component type is assumed and the system
* services will be used to load this dll.
*
* @param aClass : CID implemenation contained in module
* @param aClassName : Class name associated with CID aClass
* @param aContractID : ContractID associated with CID aClass
* @param aDllNameLocation : Dll name of module.
* @param aReplace : Boolean that indicates whether to replace a previous
* module registration for aClass.
* @param aPersist : Remember this registration across sessions.
*/
/* void registerComponentLib (in nsCIDRef aClass, in string aClassName, in string aContractID, in string aDllName, in boolean aReplace, in boolean aPersist); */
public void registerComponentLib(IID aClass, String aClassName, String aContractID, String aDllName, boolean aReplace, boolean aPersist);
/**
* unregisterFactory
*
* Unregister a factory associated with CID aClass.
*
* @param aClass : ClassID being unregistered
* @param aFactory : Factory previously registered to create instances of
* ClassID aClass.
*/
/* void unregisterFactory (in nsCIDRef aClass, in nsIFactory aFactory); */
public void unregisterFactory(IID aClass, nsIFactory aFactory);
/**
* unregisterComponent
*
* Disassociate module aLocation represented as registry location as returned
* by registryLocationForSpec() as containing ClassID aClass.
*
* @param aClass : ClassID being unregistered
* @param aLocation : Location of module. Format of this is the registry
* representation as returned by registryLocationForSpec().
* Components of any type will be unregistered.
*/
/* void unregisterComponent (in nsCIDRef aClass, in string aLocation); */
public void unregisterComponent(IID aClass, String aLocation);
/**
* unregisterComponentSpec
*
* Disassociate module references by file specification aLibrarySpec as
* containing ClassID aClass.
*/
/* void unregisterComponentSpec (in nsCIDRef aClass, in nsIFile aLibrarySpec); */
public void unregisterComponentSpec(IID aClass, nsIFile aLibrarySpec);
/**
* freeLibraries
*
* Enumerates all loaded modules and unloads unused modules.
*/
/* void freeLibraries (); */
public void freeLibraries();
/**
* ID values for 'when'
*/
/* const long NS_Startup = 0; */
public static final int NS_Startup = 0;
/* const long NS_Script = 1; */
public static final int NS_Script = 1;
/* const long NS_Timer = 2; */
public static final int NS_Timer = 2;
/* const long NS_Shutdown = 3; */
public static final int NS_Shutdown = 3;
/**
* autoRegister
*
* Enumerates directory looking for modules of all types and registers
* modules who have changed (modtime or size) since the last time
* autoRegister() was invoked.
*
* @param when : ID values of when the call is being made.
* @param directory : Directory the will be enumerated.
*/
/* void autoRegister (in long when, in nsIFile directory); */
public void autoRegister(int when, nsIFile directory);
/**
* autoRegisterComponent
*
* Loads module using appropriate loader and gives it an opportunity to
* register its CIDs if module's modtime or size changed since the last
* time this was called.
*
* @param when : ID values of when the call is being made.
* @param aFileLocation : File specification of module.
*/
/* void autoRegisterComponent (in long when, in nsIFile aFileLocation); */
public void autoRegisterComponent(int when, nsIFile aFileLocation);
/**
* autoUnregisterComponent
*
* Loads module using approriate loader and gives it an opportunity to
* unregister its CIDs
*/
/* void autoUnregisterComponent (in long when, in nsIFile aFileLocation); */
public void autoUnregisterComponent(int when, nsIFile aFileLocation);
/**
* isRegistered
*
* Returns true if a factory or module is registered for CID aClass.
*
* @param aClass : ClassID queried for registeration
* @return : true if a factory or module is registered for CID aClass.
* false otherwise.
*/
/* boolean isRegistered (in nsCIDRef aClass); */
public boolean isRegistered(IID aClass);
/**
* enumerateCLSIDs
*
* Enumerate the list of all registered ClassIDs.
*
* @return : enumerator for ClassIDs.
*/
/* nsIEnumerator enumerateCLSIDs (); */
public nsIEnumerator enumerateCLSIDs();
/**
* enumerateContractIDs
*
* Enumerate the list of all registered ContractIDs.
*
* @return : enumerator for ContractIDs.
*/
/* nsIEnumerator enumerateContractIDs (); */
public nsIEnumerator enumerateContractIDs();
}
/*
* end
*/

View File

@@ -1,49 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsIEnumerator.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsIEnumerator
*
* IID: 0xad385286-cbc4-11d2-8cca-0060b0fc14a3
*/
public interface nsIEnumerator extends nsISupports
{
public static final String IID =
"ad385286-cbc4-11d2-8cca-0060b0fc14a3";
/** First will reset the list. will return NS_FAILED if no items
*/
/* void first (); */
public void first();
/** Next will advance the list. will return failed if already at end
*/
/* void next (); */
public void next();
/** CurrentItem will return the CurrentItem item it will fail if the
* list is empty
*/
/* nsISupports currentItem (); */
public nsISupports currentItem();
/** return if the collection is at the end. that is the beginning following
* a call to Prev and it is the end of the list following a call to next
*/
/* void isDone (); */
public void isDone();
}
/*
* end
*/

View File

@@ -1,33 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsIFactory.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsIFactory
*
* IID: 0x00000001-0000-0000-c000-000000000046
*/
public interface nsIFactory extends nsISupports
{
public static final String IID =
"00000001-0000-0000-c000-000000000046";
/* void createInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result); */
public Object createInstance(nsISupports aOuter, IID iid);
/* void lockFactory (in PRBool lock); */
public void lockFactory(boolean lock);
}
/*
* end
*/

View File

@@ -1,365 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsIFile.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsIFile
*
* IID: 0xc8c0a080-0868-11d3-915f-d9d889d48e3c
*/
public interface nsIFile extends nsISupports
{
public static final String IID =
"c8c0a080-0868-11d3-915f-d9d889d48e3c";
/**
* Create Types
*
* NORMAL_FILE_TYPE - A normal file.
* DIRECTORY_TYPE - A directory/folder.
*/
/* const unsigned long NORMAL_FILE_TYPE = 0; */
public static final int NORMAL_FILE_TYPE = 0;
/* const unsigned long DIRECTORY_TYPE = 1; */
public static final int DIRECTORY_TYPE = 1;
/**
* appendPath
*
* This function is used for constructing a descendant of the
* current nsIFile.
*
* @param relativePath
* A string which is intented to be a child node of the
* nsIFile.
*/
/* void append ([const] in string node); */
public void append(String node);
/* void appendUnicode ([const] in wstring node); */
public void appendUnicode(String node);
/**
* Normalize the pathName (e.g. removing .. and . components on Unix).
*/
/* void normalize (); */
public void normalize();
/**
* create
*
* This function will create a new file or directory in the
* file system. Any nodes that have not been created or
* resolved, will be. If the file or directory already
* exists create() will return NS_ERROR_FILE_ALREADY_EXISTS.
*
* @param type
* This specifies the type of file system object
* to be made. The only two types at this time
* are file and directory which are defined above.
* If the type is unrecongnized, we will return an
* error (NS_ERROR_FILE_UNKNOWN_TYPE).
*
* @param permissions
* The unix style octal permissions. This may
* be ignored on systems that do not need to do
* permissions.
*/
/* void create (in unsigned long type, in unsigned long permissions); */
public void create(int type, int permissions);
/**
* Accessor to the leaf name of the file itself.
*/
/* attribute string leafName; */
public String getLeafName();
public void setLeafName(String value);
/* attribute wstring unicodeLeafName; */
public String getUnicodeLeafName();
public void setUnicodeLeafName(String value);
/**
* copyTo
*
* This will copy this file to the specified newParentDir.
* If a newName is specified, the file will be renamed.
* If 'this' is not created we will return an error
* (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
*
* copyTo will NOT resolve aliases/shortcuts during the copy.
*
* @param newParentDir
* This param is the destination directory. If the
* newParentDir is null, copyTo() will use the parent
* directory of this file. If the newParentDir is not
* null and is not a directory, an error will be
* returned (NS_ERROR_FILE_DESTINATION_NOT_DIR)
*
* @param newName
* This param allows you to specify a new name for
* the file to be copied. This param may be null, in
* which case the current leaf name will be used.
*
*/
/* void copyTo (in nsIFile newParentDir, [const] in string newName); */
public void copyTo(nsIFile newParentDir, String newName);
/* void copyToUnicode (in nsIFile newParentDir, [const] in wstring newName); */
public void copyToUnicode(nsIFile newParentDir, String newName);
/**
* copyToFollowingLinks
*
* This function is identical to copyTo except it, as
* the name implies, follows symbolic links. Some OSes
* such as Unix and Linux always follow symbolic links
* when copying.
*/
/* void copyToFollowingLinks (in nsIFile newParentDir, [const] in string newName); */
public void copyToFollowingLinks(nsIFile newParentDir, String newName);
/* void copyToFollowingLinksUnicode (in nsIFile newParentDir, [const] in wstring newName); */
public void copyToFollowingLinksUnicode(nsIFile newParentDir, String newName);
/**
* moveTo
*
* This will move this file to the specified newParentDir.
* If a newName is specified, the file will be renamed.
* If 'this' is not created we will return an error
* (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
*
* moveTo will NOT resolve aliases/shortcuts during the copy.
* moveTo will do the right thing and allow copies across
* volumes.
*
* @param newParentDir
* This param is the destination directory. If the
* newParentDir is null, moveTo() will rename the file
* within its current directory. If the newParentDir is
* not null and does not name a directory, an error will
* be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR)
*
* @param newName
* This param allows you to specify a new name for
* the file to be moved. This param may be null, in
* which case the current leaf name will be used.
*
*/
/* void moveTo (in nsIFile newParentDir, [const] in string newName); */
public void moveTo(nsIFile newParentDir, String newName);
/* void moveToUnicode (in nsIFile newParentDir, [const] in wstring newName); */
public void moveToUnicode(nsIFile newParentDir, String newName);
/**
* This will try to execute this file. It will not block for
* execution. 'args' will be passed through on the command line
* if the OS supports that.
*/
/* void spawn ([array, size_is (count)] in string args, in unsigned long count); */
public void spawn(String[] args, int count);
/**
* This will try to delete this file. The 'recursive' flag
* must be PR_TRUE to delete directories which are not empty.
*
* This will not resolve any symlinks.
*/
/* void delete (in boolean recursive); */
public void delete(boolean recursive);
/**
* Attributes of nsIFile.
*/
/* attribute unsigned long permissions; */
public int getPermissions();
public void setPermissions(int value);
/* attribute unsigned long permissionsOfLink; */
public int getPermissionsOfLink();
public void setPermissionsOfLink(int value);
/**
* File Times are to be in milliseconds from
* midnight (00:00:00), January 1, 1970 Greenwich Mean
* Time (GMT).
*/
/* attribute PRInt64 lastModificationDate; */
public long getLastModificationDate();
public void setLastModificationDate(long value);
/* attribute PRInt64 lastModificationDateOfLink; */
public long getLastModificationDateOfLink();
public void setLastModificationDateOfLink(long value);
/**
* WARNING! On the Mac getting/setting the file size with nsIFile
* only deals with the size of the data fork. If you need to
* know the size of the combined data and resource forks use the
* GetFileSizeWithResFork() method defined in nsILocalFileMac.h
*/
/* attribute PRInt64 fileSize; */
public long getFileSize();
public void setFileSize(long value);
/* readonly attribute PRInt64 fileSizeOfLink; */
public long getFileSizeOfLink();
/**
* target & path
*
* Accessor to the string path. These strings are
* not guaranteed to be a usable path to pass to NSPR
* or the C stdlib. There are problems that affect
* platforms on which a path does not fully specify a
* file, because two volumes can have the same name.
* This is solved by holding "private", native data in
* the nsIFile implementation. This native data is lost
* when you convert to a string.
*
* DO NOT PASS TO USE WITH NSPR OR STDLIB.
*
* target:
* Find out what the symlink points at. Will give error
* (NS_ERROR_FILE_INVALID_PATH) if not a symlink.
*
* path:
* Find out what the nsIFile points at.
*/
/* readonly attribute string target; */
public String getTarget();
/* readonly attribute wstring unicodeTarget; */
public String getUnicodeTarget();
/* readonly attribute string path; */
public String getPath();
/* readonly attribute wstring unicodePath; */
public String getUnicodePath();
/* boolean exists (); */
public boolean exists();
/* boolean isWritable (); */
public boolean isWritable();
/* boolean isReadable (); */
public boolean isReadable();
/* boolean isExecutable (); */
public boolean isExecutable();
/* boolean isHidden (); */
public boolean isHidden();
/* boolean isDirectory (); */
public boolean isDirectory();
/* boolean isFile (); */
public boolean isFile();
/* boolean isSymlink (); */
public boolean isSymlink();
/**
* Not a regular file, not a directory, not a symlink.
*/
/* boolean isSpecial (); */
public boolean isSpecial();
/**
* createUnique
*
* This function will create a new file or directory in the
* file system. Any nodes that have not been created or
* resolved, will be. If this file already exists, we try
* variations on the leaf name "suggestedName" until we find
* one that did not already exist.
*
* If the search for nonexistent files takes too long
* (thousands of the variants already exist), we give up and
* return NS_ERROR_FILE_TOO_BIG.
*
* @param type
* This specifies the type of file system object
* to be made. The only two types at this time
* are file and directory which are defined above.
* If the type is unrecongnized, we will return an
* error (NS_ERROR_FILE_UNKNOWN_TYPE).
*
* @param permissions
* The unix style octal permissions. This may
* be ignored on systems that do not need to do
* permissions.
*/
/* void createUnique (in string suggestedName, in unsigned long type, in unsigned long permissions); */
public void createUnique(String suggestedName, int type, int permissions);
/**
* clone()
*
* This function will allocate and initialize a nsIFile object to the
* exact location of the |this| nsIFile.
*
* @param file
* A nsIFile which this object will be initialize
* with.
*
*/
/* nsIFile clone (); */
/* public nsIFile clone(); */
/**
* Will determine if the inFile equals this.
*/
/* boolean equals (in nsIFile inFile); */
public boolean equals(nsIFile inFile);
/**
* Will determine if inFile is a descendant of this file
* If |recur| is true, look in subdirectories too
*/
/* boolean contains (in nsIFile inFile, in boolean recur); */
public boolean contains(nsIFile inFile, boolean recur);
/**
* Parent will be null when this is at the top of the volume.
*/
/* readonly attribute nsIFile parent; */
public nsIFile getParent();
/**
* Returns an enumeration of the elements in a directory. Each
* element in the enumeration is an nsIFile.
*
* @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
* not specify a directory.
*/
/* readonly attribute nsISimpleEnumerator directoryEntries; */
public nsISimpleEnumerator getDirectoryEntries();
/**
* Accesses the file: url for the nsIFile. Setting this causes the path
* to be reset.
*/
/* attribute string URL; */
public String getURL();
public void setURL(String value);
}
/*
* end
*/

View File

@@ -1,33 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsIEnumerator.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsISimpleEnumerator
*
* IID: 0xD1899240-F9D2-11D2-BDD6-000064657374
*/
public interface nsISimpleEnumerator extends nsISupports
{
public static final String IID =
"D1899240-F9D2-11D2-BDD6-000064657374";
/* boolean hasMoreElements (); */
public boolean hasMoreElements();
/* nsISupports getNext (); */
public nsISupports getNext();
}
/*
* end
*/

View File

@@ -1,30 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsISupports.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsISupports
*
* IID: 0x00000000-0000-0000-c000-000000000046
*/
public interface nsISupports
{
public static final String IID =
"00000000-0000-0000-c000-000000000046";
/* void QueryInterface (in nsIIDRef uuid, [iid_is (uuid), retval] out nsQIResult result); */
public Object queryInterface(IID uuid);
}
/*
* end
*/

View File

@@ -1,37 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from nsISupportsPrimitives.idl.
*/
package org.mozilla.xpcom;
/**
* Interface nsISupportsString
*
* IID: 0xd65ff270-4a1c-11d3-9890-006008962422
*/
public interface nsISupportsString extends nsISupports
{
public static final String IID =
"d65ff270-4a1c-11d3-9890-006008962422";
/* attribute string data; */
public String getData();
public void setData(String value);
/* string toString (); */
public String toString_();
/* void setDataWithLength (in unsigned long length, [size_is (length)] in string data); */
public void setDataWithLength(int length, String data);
}
/*
* end
*/

View File

@@ -1,55 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../../..
topsrcdir = ../../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
MODULE = blackConnectInit
LIBRARY_NAME = blackConnectInit
IS_COMPONENT = 1
XPIDL_MODULE = blackConnectInit
XPIDLSRCS = bcIBlackConnectInit.idl
CPPSRCS = bcBlackConnectInit.cpp
include $(topsrcdir)/config/rules.mk
COMPONENT=bcBlackConnectInit
CLASSES=bcIBlackConnectInit.class bcBlackConnectInit.class
$(COMPONENT).jar.comp: manifest $(CLASSES)
$(JDKHOME)/bin/jar cvfm $(COMPONENT).jar.comp manifest *.class
.java.class:
$(JDKHOME)/bin/javac -classpath .:../classes $<
install-component: $(COMPONENT).jar.comp $(COMPONENT).jar.info
cp $(COMPONENT).jar.comp $(COMPONENT).jar.info $(DEPTH)/dist/bin/components/
clobber-java:
rm -f *.class *.jar
clobber:: clobber-java
clobber_all:: clobber-java
install:: install-component

View File

@@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcIBlackConnectInit.h"
#include "nsIModule.h"
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 initialization only
{
nsresult r;
if (counter == 0) {
counter ++;
bcIBlackConnectInit *blackConnectInit;
r = nsComponentManager::CreateInstance("bcBlackConnectInit",
nsnull,
NS_GET_IID(bcIBlackConnectInit),
(void**)&blackConnectInit);
if (NS_SUCCEEDED(r)) {
nsIComponentManager* cm;
r = NS_GetGlobalComponentManager(&cm);
if (NS_SUCCEEDED(r)) {
blackConnectInit->InitComponentManager(cm);
}
}
}
return NS_ERROR_FAILURE;
}

View File

@@ -1,3 +0,0 @@
d531c06c-1dd1-11b2-b98f-d65c8eec0052
bcBlackConnectInit
bcBlackConnectInit

View File

@@ -1,48 +0,0 @@
/* -*- Mode: java; 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
import org.mozilla.xpcom.*;
public class bcBlackConnectInit implements bcIBlackConnectInit {
public bcBlackConnectInit() {
}
public Object queryInterface(IID iid) {
Object result;
if ( nsISupportsIID.equals(iid)
|| bcIBlackConnectInitIID.equals(iid)) {
result = this;
} else {
result = null;
}
return result;
}
/* void initComponentManager (in nsIComponentManager cm); */
public void initComponentManager(nsIComponentManager cm) {
Components.setComponentManager(cm);
Debug.log("Components.setComponentManager(cm);");
}
static IID bcIBlackConnectInitIID = new IID(bcIBlackConnectInit.IID);
static IID nsISupportsIID = new IID(nsISupports.IID);
static {
InterfaceRegistry.register(nsIComponentManager.class);
}
}

View File

@@ -1,9 +0,0 @@
#include "nsISupports.idl"
#include "nsIComponentManager.idl"
[scriptable, uuid(d4867a7e-1dd1-11b2-a009-b111ab5d7639)]
interface bcIBlackConnectInit : nsISupports
{
void initComponentManager(in nsIComponentManager cm);
};

View File

@@ -1,30 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from bcIBlackConnectInit.idl.
*/
import org.mozilla.xpcom.*;
/**
* Interface bcIBlackConnectInit
*
* IID: 0xd4867a7e-1dd1-11b2-a009-b111ab5d7639
*/
public interface bcIBlackConnectInit extends nsISupports
{
public static final String IID =
"d4867a7e-1dd1-11b2-a009-b111ab5d7639";
/* void initComponentManager (in nsIComponentManager cm); */
public void initComponentManager(nsIComponentManager cm);
}
/*
* end
*/

View File

@@ -1,66 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ..\..\..\..
topsrcdir = ..\..\..\..
srcdir = .
VPATH = .
MAKE_OBJ_TYPE=DLL
MODULE=javaSample
COMPONENT=1
DLLNAME=$(MODULE)
DLL=.\$(OBJDIR)\$(DLLNAME).dll
XPIDLSRCS = \
.\bcIBlackConnectInit.idl \
$(NULL)
OBJS = .\$(OBJDIR)\bcBlackConnectInit.obj
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
include <$(DEPTH)\config\rules.mak>
COMPONENT=bcBlackConnectInit
CLASSES=bcIBlackConnectInit.class bcJavaSample.class
$(COMPONENT).jar.comp: manifest $(CLASSES)
$(JDKHOME)\bin\jar cvfm $(COMPONENT).jar.comp manifest *.class
.SUFFIXES: .java .class
.java.class:
$(JDKHOME)\bin\javac -classpath .;..\classes $<
install-component: $(COMPONENT).jar.comp $(COMPONENT).jar.info $(DLL)
copy $(COMPONENT).jar* $(DIST)\bin\components
copy $(DLL) $(DIST)\bin\components
clobber-java:
-del *.class *.jar.comp
clobber:: clobber-java
rm $(DIST)\bin\components\$(DLLNAME).dll
rm $(DIST)\bin\components\$(COMPONENT).jar.*
clobber_all:: clobber-java
install:: install-component

View File

@@ -1 +0,0 @@
Component-Class: bcBlackConnectInit

View File

@@ -1,49 +0,0 @@
#!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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
MODULE = javaloader
LIBRARY_NAME = javaloader
IS_COMPONENT = 1
CPPSRCS = \
bcJavaComponentLoader.cpp \
bcJavaModule.cpp \
bcJavaComponentFactory.cpp \
$(NULL)
CXXFLAGS += -I$(JDKHOME)/include -I$(JDKHOME)/include/linux $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb -lbcxpcomstubs -lbcjavastubs \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -1,90 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIServiceManager.h"
#include "nsCRT.h"
#include "bcJavaComponentFactory.h"
#include "bcJavaStubsAndProxies.h"
#include "bcXPCOMStubsAndProxies.h"
#include "bcORB.h"
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
NS_IMPL_ISUPPORTS1(bcJavaComponentFactory, nsIFactory)
bcJavaComponentFactory::bcJavaComponentFactory(const char *_location) {
NS_INIT_ISUPPORTS();
location = nsCRT::strdup(_location);
}
bcJavaComponentFactory::~bcJavaComponentFactory() {
nsCRT::free((char*)location);
}
/* void CreateInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result);
*/
NS_IMETHODIMP bcJavaComponentFactory::CreateInstance(nsISupports *aOuter, const nsIID & iid, void * *result) {
printf("--bcJavaComponentFactory::CreateInstance\n");
nsresult r;
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance javaStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance bcORB failed \n");
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcOID oid;
r = javaStubsAndProxies->GetOID(location, &oid);
printf("--bcJavaComponentFactory::CreateInstance after GetOID");
nsISupports *proxy;
printf("--[c++]bcJavaComponentFactory::CreateInstance iid:%s\n",iid.ToString());
xpcomStubsAndProxies->GetProxy(oid, iid, orb, &proxy);
*result = proxy;
printf("--bcJavaComponentFactory::CreateInstance end");
return NS_OK;
}
/* void LockFactory (in PRBool lock); */
NS_IMETHODIMP bcJavaComponentFactory::LockFactory(PRBool lock)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -1,39 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaComponentFactory_h
#define __bcJavaComponentFactory_h
#include "nsIFactory.h"
class bcJavaComponentFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
bcJavaComponentFactory(const char *location);
virtual ~bcJavaComponentFactory();
private:
char *location;
};
#endif

View File

@@ -1,466 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
/*
A bunch of stuff was copied from mozJSComponentLoader.cpp
*/
#include "nsICategoryManager.h"
#include "bcJavaComponentLoader.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "bcJavaModule.h"
const char javaComponentTypeName[] = JAVACOMPONENTTYPENAME;
/* 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_ISUPPORTS(bcJavaComponentLoader,NS_GET_IID(nsIComponentLoader));
bcJavaComponentLoader::bcJavaComponentLoader()
: mCompMgr(NULL),
mXPCOMKey(0)
{
NS_INIT_REFCNT();
printf("--bcJavaComponentLoader::bcJavaComponentLoader \n");
}
bcJavaComponentLoader::~bcJavaComponentLoader() { //nb
printf("--bcJavaComponentLoader::~bcJavaComponentLoader \n");
}
/**
* Get the factory for a given component.
*/
/* nsIFactory getFactory (in nsIIDRef aCID, in string aLocation, in string aType); */
NS_IMETHODIMP bcJavaComponentLoader::GetFactory(const nsIID & aCID, const char *aLocation, const char *aType, nsIFactory **_retval) {
printf("--bcJavaComponentLoader::GetFactory \n");
if (!_retval)
return NS_ERROR_NULL_POINTER;
#ifdef DEBUG
char *cidString = aCID.ToString();
fprintf(stderr, "--bcJavaComponentLoader::GetFactory(%s,%s,%s)\n", cidString, aLocation, aType);
delete [] cidString;
#endif
nsIModule * module = ModuleForLocation(aLocation, 0);
if (!module) {
#ifdef DEBUG
fprintf(stderr, "ERROR: couldn't get module for %s\n", aLocation);
#endif
return NS_ERROR_FACTORY_NOT_LOADED;
}
nsresult rv = module->GetClassObject(mCompMgr, aCID,
NS_GET_IID(nsIFactory),
(void **)_retval);
#ifdef DEBUG
fprintf(stderr, "GetClassObject %s\n", NS_FAILED(rv) ? "FAILED" : "ok");
#endif
return rv;
}
/**
* Initialize the loader.
*
* We use nsISupports here because nsIRegistry isn't IDLized yet.
*/
/* void init (in nsIComponentManager aCompMgr, in nsISupports aRegistry); */
NS_IMETHODIMP bcJavaComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) {
printf("--bcJavaComponentLoader::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 bcJavaComponentLoader::OnRegister(const nsIID & aCID, const char *aType, const char *aClassName, const char *aContractID, const char *aLocation, PRBool aReplace, PRBool aPersist) { //nb
printf("--bcJavaComponentLoader::OnRegister \n");
return NS_OK;
}
/**
* AutoRegister components in the given directory.
*/
NS_IMETHODIMP bcJavaComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsIFile *aDirectory) {
printf("--bcJavaComponentLoader::AutoRegisterComponents \n");
return RegisterComponentsInDir(aWhen,aDirectory);
}
NS_IMETHODIMP bcJavaComponentLoader::AutoUnregisterComponent(PRInt32 when,
nsIFile *component,
PRBool *unregistered) {
//nb need to impelement
return NS_OK;
}
nsresult bcJavaComponentLoader::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, &registered);
}
}
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 bcJavaComponentLoader::AutoRegisterComponent(PRInt32 when, nsIFile *component, PRBool *registered) {
//printf("--bcJavaComponentLoader::AutoRegisterComponent \n");
nsresult rv;
if (!registered)
return NS_ERROR_NULL_POINTER;
const char javaExtension[] = ".jar.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("--bcJavaComponentLoader: registering bcJavaComponent 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 bcJavaComponentLoader::AttemptRegistration(nsIFile *component,
PRBool deferred) {
nsXPIDLCString registryLocation;
nsresult rv;
nsIModule *module;
rv = mCompMgr->RegistryLocationForSpec(component,
getter_Copies(registryLocation));
if (NS_FAILED(rv))
return rv;
/* no need to check registry data on deferred reg */
if (deferred || HasChanged(registryLocation, component)) {
module = ModuleForLocation(registryLocation, component);
if (module) {
rv = module->RegisterSelf(mCompMgr, component, registryLocation,
javaComponentTypeName);
if (rv == NS_ERROR_FACTORY_REGISTER_AGAIN) {
mDeferredComponents.AppendElement(component);
/*
* we don't enter in the registry because we may want to
* try again on a later autoreg, in case a dependency has
* become available.
*/
return rv;
}
}
}
SetRegistryInfo(registryLocation, component);
return rv;
}
nsresult bcJavaComponentLoader::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 bcJavaComponentLoader::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, &regTime)))
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, &regSize)))
return PR_TRUE;
PRInt64 size;
if (NS_FAILED(component->GetFileSize(&size)) || LL_NE(size,regSize) )
return PR_TRUE;
return PR_FALSE;
}
nsIModule * bcJavaComponentLoader::ModuleForLocation(const char *registryLocation, nsIFile *component) {
nsStringKey key((const PRUnichar *)registryLocation); //nb can I do this?
nsIModule *res = NULL;
res = (nsIModule*)mModules.Get(&key);
PRBool needRelease = PR_FALSE;
if (res) {
return res;
}
if (!component) {
if (NS_FAILED(mCompMgr->SpecForRegistryLocation(registryLocation, &component)))
return NULL;
needRelease = PR_TRUE;
}
res = new bcJavaModule(registryLocation, component);
if (needRelease) {
NS_IF_RELEASE(component);
}
if (res) {
mModules.Put(&key,res);
}
return res;
}
/**
* Register any deferred (NS_ERROR_FACTORY_REGISTER_AGAIN) components.
* Return registered-any-components?
*/
/* boolean registerDeferredComponents (in long aWhen); */
NS_IMETHODIMP bcJavaComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, PRBool *aRegistered) {
printf("--bcJavaComponentLoader::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 bcJavaComponentLoader::UnloadAll(PRInt32 aWhen) { //nb
printf("--bcJavaComponentLoader::UnloadAll \n");
return NS_OK;
}
//---------------------------------------------------------------------------------------------------
/* XXX this should all be data-driven, via NS_IMPL_GETMODULE_WITH_CATEGORIES */
static NS_METHOD
RegisterJavaLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const char *componentType)
{
printf("--JavaLoader got registered\n");
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString previous;
return catman->AddCategoryEntry("component-loader", javaComponentTypeName,
BC_JAVACOMPONENTLOADER_ContractID,
PR_TRUE, PR_TRUE, getter_Copies(previous));
}
static NS_METHOD
UnregisterJavaLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString javaLoader;
rv = catman->GetCategoryEntry("component-loader", javaComponentTypeName,
getter_Copies(javaLoader));
if (NS_FAILED(rv)) return rv;
// only unregister if we're the current JS component loader
if (!strcmp(javaLoader, BC_JAVACOMPONENTLOADER_ContractID)) {
return catman->DeleteCategoryEntry("component-loader",
javaComponentTypeName, PR_TRUE,
getter_Copies(javaLoader));
}
return NS_OK;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaComponentLoader);
static nsModuleComponentInfo components[] = {
{ "Java component loader", BC_JAVACOMPONENTLOADER_CID,
BC_JAVACOMPONENTLOADER_ContractID,
bcJavaComponentLoaderConstructor,
RegisterJavaLoader, UnregisterJavaLoader }
};
NS_IMPL_NSGETMODULE("Java component loader", components);

View File

@@ -1,67 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef _bcJavaComponentLoader_h
#define _bcJavaComponentLoader_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 BC_JAVACOMPONENTLOADER_ContractID \
"@mozilla.org/blackwood/blackconnect/java-component-loader"
/* 0d6b5198-1dd2-11b2-b2f0-ed49ba755db8 */
#define BC_JAVACOMPONENTLOADER_CID \
{ 0x0d6b5198, 0x1dd2, 0x11b2, \
{0xb2, 0xf0, 0xed, 0x49, 0xba, 0x75, 0x5d, 0xb8 }}
#define JAVACOMPONENTTYPENAME "text/java"
class bcJavaComponentLoader : public nsIComponentLoader {
NS_DECL_ISUPPORTS
NS_DECL_NSICOMPONENTLOADER
bcJavaComponentLoader();
virtual ~bcJavaComponentLoader();
protected:
nsHashtable mModules;
nsCOMPtr<nsIRegistry> mRegistry;
nsIComponentManager* mCompMgr; // weak ref, should make it strong?
nsRegistryKey mXPCOMKey;
nsSupportsArray mDeferredComponents;
nsresult RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
nsresult AttemptRegistration(nsIFile *component, PRBool deferred);
nsIModule * ModuleForLocation(const char *registryLocation, nsIFile *component);
PRBool HasChanged(const char *registryLocation, nsIFile *component);
nsresult SetRegistryInfo(const char *registryLocation, nsIFile *component);
};
#endif

View File

@@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include <fstream.h>
#include "nsCRT.h"
#include "nsIAllocator.h"
#include "nsXPIDLString.h"
#include "nsCOMPtr.h"
#include "bcJavaModule.h"
#include "bcJavaComponentFactory.h"
NS_IMPL_ISUPPORTS(bcJavaModule,NS_GET_IID(nsIModule));
bcJavaModule::bcJavaModule(const char *registryLocation, nsIFile *component)
: location(NULL) {
NS_INIT_REFCNT();
nsXPIDLCString str;
component->GetPath(getter_Copies(str));
location = nsCRT::strdup(str);
printf("--JavaModule::JavaModule %s\n",(const char*)str);
}
bcJavaModule::~bcJavaModule() {
if (location) {
nsCRT::free((char*)location);
}
}
/* void getClassObject (in nsIComponentManager aCompMgr, in nsCIDRef aClass, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */
NS_IMETHODIMP bcJavaModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass, const nsIID & aIID, void * *result) {
printf("--JavaModule::GetClassObject\n");
nsIFactory *f;
f = new bcJavaComponentFactory(location);
NS_ADDREF(f);
*result = f;
return NS_OK;
}
/* void registerSelf (in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation, in string componentType); */
NS_IMETHODIMP bcJavaModule::RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *_location, const char *registryLocation, const char *componentType) {
nsresult result = NS_OK;
printf("--JavaModule::RegisterSelf\n");
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);
aCompMgr->RegisterComponentWithType(cid, desc, contractid, _location, registryLocation, PR_TRUE, PR_TRUE, componentType);
return result;
}
/* void unregisterSelf (in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation); */
NS_IMETHODIMP bcJavaModule::UnregisterSelf(nsIComponentManager *aCompMgr, nsIFile *_location, const char *registryLocation) { //nb
return NS_OK;
}
/* boolean canUnload (in nsIComponentManager aCompMgr); */
NS_IMETHODIMP bcJavaModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *_retval) {
if (!_retval) {
return NS_ERROR_NULL_POINTER;
}
*_retval = PR_TRUE;
return NS_OK;
}

View File

@@ -1,35 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef _bcJavaModule_h
#define _bcJavaModule_h
#include "nsIModule.h"
class bcJavaModule : public nsIModule {
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
bcJavaModule(const char *registryLocation, nsIFile *component);
virtual ~bcJavaModule();
protected:
const char *location;
};
#endif

View File

@@ -1,48 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = DLL
MODULE=bcjavaloader
COMPONENT = 1
DLLNAME = bcjavaloader
DLL=.\$(OBJDIR)\$(DLLNAME).dll
OBJS= \
.\$(OBJDIR)\bcJavaComponentLoader.obj \
.\$(OBJDIR)\bcJavaModule.obj \
.\$(OBJDIR)\bcJavaComponentFactory.obj \
$(NULL)
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
LINCS=-I$(JDKHOME)\include -I$(JDKHOME)\include\win32
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
clobber::
rm -f $(DIST)\bin\components\$(DLLNAME).dll

View File

@@ -1,37 +0,0 @@
#!nmake
#
# 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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ..\..\..
DIRS= \
xpidl \
loader \
src \
classes \
# test \
components \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,91 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH =../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = bcjavastubs
MODULE = bcjavastubs
IS_COMPONENT = 1
EXPORTS = \
bcJavaStubsAndProxies.h
CPPSRCS = \
bcJavaMarshalToolkit.cpp \
bcJavaStub.cpp \
bcJavaGlobal.cpp \
bcJavaStubsAndProxies.cpp \
bcIIDJava.cpp \
org_mozilla_xpcom_Utilities.cpp \
org_mozilla_xpcom_Debug.cpp \
$(NULL)
JDKINCLUDE= -I$(JDKHOME)/include
ifeq ($(OS_ARCH), Linux)
JDKINCLUDE += -I$(JDKHOME)/include/linux
endif
ifeq ($(OS_ARCH), SunOS)
JDKINCLUDE += -I$(JDKHOME)/include/solaris
endif
CXXFLAGS := $(JDKINCLUDE) $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public $(CXXFLAGS)
DSO_LDOPTS += \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/ \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/classic \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/native_threads \
-ljvm -lhpi -ljava -lawt\
$(NULL)
#DSO_LDOPTS += \
# -L$(JDKHOME)/jre/bin \
# -L$(JDKHOME)/jre/bin/classic \
# -ljvm \
# $(NULL)
ifneq ($(OS_ARCH), Linux)
DSO_LDOPTS += \
-lthread -lXm -lX11 -lXt -lm
endif
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb \
$(NULL)
include $(topsrcdir)/config/rules.mk
CCC += $(CXXFLAGS) # I want to have $(JDKHOME)/include before $(DIST) include
test:
echo $(OS_ARCH)

View File

@@ -1,99 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcIIDJava.h"
#include "bcJavaGlobal.h"
jclass bcIIDJava::iidClass = NULL;
jmethodID bcIIDJava::iidInitMID = NULL;
jmethodID bcIIDJava::getStringMID = NULL;
void bcIIDJava::Init(void) {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env) {
if (!(iidClass = env->FindClass("org/mozilla/xpcom/IID"))
|| !(iidClass = (jclass) env->NewGlobalRef(iidClass))) {
env->ExceptionDescribe();
Destroy();
return;
}
if (!(iidInitMID = env->GetMethodID(iidClass,"<init>","(Ljava/lang/String;)V"))) {
env->ExceptionDescribe();
Destroy();
return;
}
if (!(getStringMID = env->GetMethodID(iidClass,"getString","()Ljava/lang/String;"))) {
env->ExceptionDescribe();
Destroy();
return;
}
}
}
void bcIIDJava::Destroy() {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env) {
if (iidClass) {
env->DeleteGlobalRef(iidClass);
iidClass = NULL;
}
}
}
jobject bcIIDJava::GetObject(nsIID *iid) {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (!iid
|| !env ) {
return NULL;
}
if (!iidClass) {
Init();
}
char *str = iid->ToString(); //nb free ?
jstring jstr = NULL;
if (str) {
char *siid = str+1; //we do need to have it. The format is {_xxx-xxx-xxx_}
siid[strlen(siid)-1] = 0;
jstr = env->NewStringUTF((const char *)siid);
}
return env->NewObject(iidClass,iidInitMID,jstr);
}
jclass bcIIDJava::GetClass() {
return iidClass;
}
nsIID bcIIDJava::GetIID(jobject obj) {
nsIID iid;
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env) {
if (!iidClass) {
Init();
}
jstring jstr = (jstring)env->CallObjectMethod(obj, getStringMID);
const char * str = NULL;
str = env->GetStringUTFChars(jstr,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jstr,str);
}
return iid;
}

View File

@@ -1,41 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIIDJava_H
#define __bcIIDJava_H
#include "nsIID.h"
#include "jni.h"
class bcIIDJava {
public:
static jobject GetObject(nsIID * iid);
static nsIID GetIID(jobject obj);
static jclass GetClass();
private:
static jclass iidClass;
static jmethodID iidInitMID;
static jmethodID getStringMID;
static void Init(void);
static void Destroy(void);
};
#endif

View File

@@ -1,122 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcJavaGlobal.h"
#include "prenv.h"
JavaVM *bcJavaGlobal::jvm = NULL;
PRLogModuleInfo* bcJavaGlobal::log = NULL;
#ifdef XP_PC
#define PATH_SEPARATOR ';'
#else
#define PATH_SEPARATOR ':'
#endif
#ifdef JRI_MD_H //we are using jni.h from netscape
#define JNIENV
#else
#define JNIENV (void**)
#endif
JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
JNIEnv * env;
int res;
if (!jvm) {
StartJVM();
}
if (jvm) {
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
}
return env;
}
void bcJavaGlobal::StartJVM() {
PRLogModuleInfo * l = GetLog();
PR_LOG(l,PR_LOG_DEBUG,("--bcJavaGlobal::StartJVM begin\n"));
JNIEnv *env = NULL;
jint res;
jsize jvmCount;
JNI_GetCreatedJavaVMs(&jvm, 1, &jvmCount);
PR_LOG(l,PR_LOG_DEBUG,("--bcJavaGlobal::StartJVM after GetCreatedJavaVMs\n"));
if (jvmCount) {
return;
}
#if 0
JDK1_1InitArgs vm_args;
char classpath[1024];
JNI_GetDefaultJavaVMInitArgs(&vm_args);
PR_LOG(l,PR_LOG_DEBUG,("--[c++] version %d",(int)vm_args.version));
vm_args.version = 0x00010001;
/* Append USER_CLASSPATH to the default system class path */
sprintf(classpath, "%s%c%s",
vm_args.classpath, PATH_SEPARATOR, PR_GetEnv("CLASSPATH"));
PR_LOG(l,PR_LOG_DEBUG,("--[c++] classpath %s\n",classpath));
char **props = new char*[2];
props[0]="java.compiler=NONE";
props[1]=0;
vm_args.properties = props;
vm_args.classpath = classpath;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, JNIENV &env, &vm_args);
#else
char classpath[1024];
JavaVMInitArgs vm_args;
JavaVMOption options[2];
sprintf(classpath, "-Djava.class.path=%s",PR_GetEnv("CLASSPATH"));
PR_LOG(l,PR_LOG_DEBUG,("--[c++] classpath %s\n",classpath));
options[0].optionString = classpath;
options[1].optionString=""; //-Djava.compiler=NONE";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
#endif
PR_LOG(l,PR_LOG_DEBUG,("--bcJavaGlobal::StartJVM jvm started res %d\n",res));
}
PRLogModuleInfo* bcJavaGlobal::GetLog() {
if (log == NULL) {
log = PR_NewLogModule(LOG_MODULE);
}
return log;
}

View File

@@ -1,47 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaGlobal_h_
#define __bcJavaGlobal_h_
#include "nscore.h"
#include "jni.h"
#include "prlog.h"
#define LOG_MODULE "blackConnect"
#define EXCEPTION_CHECKING(env) \
do { \
if ((env)->ExceptionOccurred()) { \
(env)->ExceptionDescribe(); \
} \
} while (0);
class bcJavaGlobal {
public:
static JNIEnv * GetJNIEnv(void);
static PRLogModuleInfo * GetLog();
private:
static PRLogModuleInfo* log;
static JavaVM *jvm;
static void StartJVM(void);
};
#endif

View File

@@ -1,907 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIAllocator.h"
#include "nsCOMPtr.h"
#include "bcJavaMarshalToolkit.h"
#include "bcIIDJava.h"
#include "bcJavaStubsAndProxies.h"
#include "nsIServiceManager.h"
#include "bcJavaGlobal.h"
#include <string.h>
jclass bcJavaMarshalToolkit::objectClass = NULL;
jclass bcJavaMarshalToolkit::objectArrayClass = NULL;
jclass bcJavaMarshalToolkit::booleanClass = NULL;
jclass bcJavaMarshalToolkit::booleanArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::booleanInitMID = NULL;
jmethodID bcJavaMarshalToolkit::booleanValueMID = NULL;
jclass bcJavaMarshalToolkit::charClass = NULL;
jclass bcJavaMarshalToolkit::charArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::charInitMID = NULL;
jmethodID bcJavaMarshalToolkit::charValueMID = NULL;
jclass bcJavaMarshalToolkit::byteClass = NULL;
jclass bcJavaMarshalToolkit::byteArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::byteInitMID = NULL;
jmethodID bcJavaMarshalToolkit::byteValueMID = NULL;
jclass bcJavaMarshalToolkit::shortClass = NULL;
jclass bcJavaMarshalToolkit::shortArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::shortInitMID = NULL;
jmethodID bcJavaMarshalToolkit::shortValueMID = NULL;
jclass bcJavaMarshalToolkit::intClass = NULL;
jclass bcJavaMarshalToolkit::intArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::intInitMID = NULL;
jmethodID bcJavaMarshalToolkit::intValueMID = NULL;
jclass bcJavaMarshalToolkit::longClass = NULL;
jclass bcJavaMarshalToolkit::longArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::longInitMID = NULL;
jmethodID bcJavaMarshalToolkit::longValueMID = NULL;
jclass bcJavaMarshalToolkit::floatClass = NULL;
jclass bcJavaMarshalToolkit::floatArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::floatInitMID = NULL;
jmethodID bcJavaMarshalToolkit::floatValueMID = NULL;
jclass bcJavaMarshalToolkit::doubleClass = NULL;
jclass bcJavaMarshalToolkit::doubleArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::doubleInitMID = NULL;
jmethodID bcJavaMarshalToolkit::doubleValueMID = NULL;
jclass bcJavaMarshalToolkit::stringClass = NULL;
jclass bcJavaMarshalToolkit::stringArrayClass = NULL;
jclass bcJavaMarshalToolkit::iidClass = NULL;
jclass bcJavaMarshalToolkit::iidArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::getClassMID = NULL;
//maping from java types to *connect types
#define boolean_map PRBool
#define byte_map PRInt8
#define short_map PRInt16
#define int_map PRInt32
#define long_map PRInt64
#define float_map float
#define double_map double
#define char_map PRInt16
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
bcJavaMarshalToolkit::bcJavaMarshalToolkit(PRUint16 _methodIndex,
nsIInterfaceInfo *_interfaceInfo, jobjectArray _args, JNIEnv *_env, int isOnServer, bcIORB *_orb) {
env = _env;
callSide = (isOnServer) ? onServer : onClient;
methodIndex = _methodIndex;
interfaceInfo = _interfaceInfo;
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo **)&info); // These do *not* make copies ***explicit bending of XPCOM rules***
args = _args;
if(!objectClass) {
InitializeStatic();
if(!objectClass) {
//nb ? we do not have java classes. What could we do?
}
}
orb = _orb;
}
bcJavaMarshalToolkit::~bcJavaMarshalToolkit() {
}
class javaAllocator : public bcIAllocator {
public:
javaAllocator(nsIAllocator *_allocator) {
allocator = _allocator;
}
virtual ~javaAllocator() {}
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;
};
nsresult bcJavaMarshalToolkit::Marshal(bcIMarshaler *m, jobject retval) {
retV = retval;
return Marshal(m);
}
nsresult bcJavaMarshalToolkit::Marshal(bcIMarshaler *m) {
PRUint32 paramCount = info->GetParamCount();
nsresult r = NS_OK;
for (unsigned int i = 0; (i < paramCount) && NS_SUCCEEDED(r); i++) {
nsXPTParamInfo param = info->GetParam(i);
if ((callSide == onClient && !param.IsIn())
|| (callSide == onServer && !param.IsOut())) {
continue;
} else if (param.IsRetval() && callSide == onServer) {
r = MarshalElement(m, retV, PR_FALSE, &param, XPTType2bcXPType(param.GetType().TagPart()), i);
} else {
jobject object = env->GetObjectArrayElement(args,i);
EXCEPTION_CHECKING(env);
r = MarshalElement(m, object, param.IsOut(), &param, XPTType2bcXPType(param.GetType().TagPart()), i);
}
}
return r;
}
nsresult bcJavaMarshalToolkit::UnMarshal(bcIUnMarshaler *um, jobject *retval) {
nsresult r = UnMarshal(um);
*retval = retV;
return r;
}
nsresult bcJavaMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
PRLogModuleInfo * log = bcJavaGlobal::GetLog();
PR_LOG(log, PR_LOG_DEBUG,("--nsresult bcJavaMarshalToolkit::UnMarshal\n"));
bcIAllocator * allocator = new javaAllocator(nsAllocator::GetGlobalAllocator());
PRUint32 paramCount = info->GetParamCount();
retV = NULL;
jobject value;
for (unsigned int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
nsXPTType type = param.GetType();
if (param.IsRetval() && callSide == onServer) {
PR_LOG(log,PR_LOG_DEBUG,("** bcJavaMarshalToolkit::UnMarshal skipping retval\n"));
PR_LOG(log,PR_LOG_DEBUG,("**unmarshall: call side: %d\n", callSide));
continue;
}
if ( (callSide == onServer && !param.IsIn()
|| (callSide == onClient && !param.IsOut()))){
if (callSide == onServer
&& isOut) { //we need to allocate memory for out parametr
UnMarshalElement(&value, i, NULL, 1, &param, XPTType2bcXPType(type.TagPart()),allocator);
env->SetObjectArrayElement(args,i,value);
EXCEPTION_CHECKING(env);
}
continue;
}
if (param.IsRetval()) {
UnMarshalElement(&value, i, um, PR_FALSE, &param, XPTType2bcXPType(type.TagPart()),allocator);
retV = value;
} else {
if (isOut) {
value = env->GetObjectArrayElement(args,i);
EXCEPTION_CHECKING(env);
}
UnMarshalElement(&value, i, um, isOut, &param, XPTType2bcXPType(type.TagPart()),allocator);
env->SetObjectArrayElement(args,i,value);
EXCEPTION_CHECKING(env);
}
}
delete allocator;
return NS_OK;
}
/*
*JNIEnv *env; jobject value; PRBool isOut; ArrayModifier modifier; bcIMarshaler *m;
* should be defined before calling this mavro
*
*/
#define MARSHAL_SIMPLE_ELEMENT(_type_,_Type_) \
do { \
int indexInArray; \
j##_type_ data; \
if (! isOut \
&& (modifier == none)) { \
data = env->Call##_Type_##Method(value,_type_##ValueMID); \
EXCEPTION_CHECKING(env); \
} else if (isOut && (modifier == array)) { \
/* could not happend. We take care about it in T_ARRAY case */ \
} else if (modifier == arrayElement \
|| (isOut && (modifier == none))) { \
indexInArray = (modifier == arrayElement) ? ind : 0; \
env->Get##_Type_##ArrayRegion((j##_type_##Array)value, indexInArray, 1, &data); \
EXCEPTION_CHECKING(env); \
} \
_type_##_map tmpData = data; \
m->WriteSimple(&tmpData,type); \
} while (0)
nsresult
bcJavaMarshalToolkit::MarshalElement(bcIMarshaler *m, jobject value, PRBool isOut, nsXPTParamInfo * param,
bcXPType type, uint8 ind, ArrayModifier modifier) {
nsresult r = NS_OK;
PRLogModuleInfo * log = bcJavaGlobal::GetLog();
switch(type) {
case bc_T_I8:
case bc_T_U8:
{
MARSHAL_SIMPLE_ELEMENT(byte,Byte);
break;
}
case bc_T_I16:
case bc_T_U16:
{
MARSHAL_SIMPLE_ELEMENT(short,Short);
break;
};
case bc_T_I32:
case bc_T_U32:
{
MARSHAL_SIMPLE_ELEMENT(int,Int);
break;
}
case bc_T_I64:
case bc_T_U64:
{
MARSHAL_SIMPLE_ELEMENT(long,Long);
break;
}
case bc_T_FLOAT:
{
MARSHAL_SIMPLE_ELEMENT(float,Float);
break;
}
case bc_T_DOUBLE:
{
MARSHAL_SIMPLE_ELEMENT(double,Double);
break;
}
case bc_T_BOOL:
{
MARSHAL_SIMPLE_ELEMENT(boolean,Boolean);
break;
}
case bc_T_CHAR:
case bc_T_WCHAR:
{
MARSHAL_SIMPLE_ELEMENT(char,Char);
break;
}
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR: //nb not sure about this
{
int indexInArray;
jstring data = NULL;
if (! isOut
&& (modifier == none)) {
data = (jstring)value;
} else if (modifier == arrayElement
|| (isOut && (modifier == none))) {
indexInArray = (modifier == arrayElement) ? ind : 0;
data = (jstring)env->GetObjectArrayElement((jobjectArray)value,indexInArray);
EXCEPTION_CHECKING(env);
}
char * str = NULL;
char * tmpStr = NULL;
if (data) {
size_t length = 0;
if (type == bc_T_CHAR_STR) {
str = (char*)env->GetStringUTFChars((jstring)data,NULL);
length = strlen(str)+1;
tmpStr = str;
} else {
str = (char*)env->GetStringChars((jstring)data,NULL);
length = env->GetStringLength((jstring)data);
length *= 2; //nb
length += 2;
tmpStr = new char[length];
memcpy(tmpStr,str,length-2);
tmpStr[length-1] = tmpStr[length-2] = 0;
{
for (int i = 0; i < length && type == bc_T_WCHAR_STR; i++) {
char c = tmpStr[i];
PR_LOG(log,PR_LOG_DEBUG,("--[c++] bcJavaMarshalToolkit::MarshalElement T_WCHAR_STR [%d] = %d %c\n",i,c,c));
}
}
}
EXCEPTION_CHECKING(env);
m->WriteString(tmpStr,length);
if (type == bc_T_CHAR_STR) {
env->ReleaseStringUTFChars(data,str);
} else {
env->ReleaseStringChars(data,(const jchar*)str);
delete[] tmpStr;
}
EXCEPTION_CHECKING(env);
} else {
m->WriteString(str,0);
}
break;
}
case bc_T_IID:
{
int indexInArray;
jobject data = NULL;
if (! isOut
&& (modifier == none)) {
data = value;
} else if (modifier == arrayElement
|| (isOut && (modifier == none))) {
indexInArray = (modifier == arrayElement) ? ind : 0;
data = (jstring)env->GetObjectArrayElement((jobjectArray)value,indexInArray);
EXCEPTION_CHECKING(env);
}
nsIID iid = bcIIDJava::GetIID(data);
m->WriteSimple(&iid, type);
break;
}
case bc_T_INTERFACE:
{
int indexInArray;
jobject data = NULL;
PR_LOG(log,PR_LOG_DEBUG,("--marshalElement we got interface\n"));
bcOID oid = 0;
nsIID *iid;
if (! isOut
&& (modifier == none)) {
data = value;
} else if (modifier == arrayElement
|| (isOut && (modifier == none))) {
indexInArray = (modifier == arrayElement) ? ind : 0;
data = env->GetObjectArrayElement((jobjectArray)value,indexInArray);
EXCEPTION_CHECKING(env);
}
if (data != NULL) {
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
return NS_ERROR_FAILURE;
}
javaStubsAndProxies->GetOID(data, orb, &oid);
}
m->WriteSimple(&oid,type);
if (param->GetType().TagPart() == nsXPTType::T_INTERFACE) {
if(NS_FAILED(r = interfaceInfo->
GetIIDForParam(methodIndex, param, &iid))) {
return r;
}
m->WriteSimple(iid,bc_T_IID);
} else {
uint8 argnum;
if (NS_FAILED(r = interfaceInfo->GetInterfaceIsArgNumberForParam(methodIndex,
param, &argnum))) {
return r;
}
const nsXPTParamInfo& arg_param = info->GetParam(argnum);
jobject object = env->GetObjectArrayElement(args,argnum);
EXCEPTION_CHECKING(env);
r = MarshalElement(m, object, arg_param.IsOut(),(nsXPTParamInfo*)&arg_param,
XPTType2bcXPType(arg_param.GetType().TagPart()), (uint8)0);
}
break;
}
case bc_T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
bcXPType type = XPTType2bcXPType(datumType.TagPart());
jobject arrayValue = value;
if (isOut) {
arrayValue = env->GetObjectArrayElement((jobjectArray)value,0);
EXCEPTION_CHECKING(env);
}
if (m != NULL) {
PRUint32 arraySize = (arrayValue == NULL) ? 0 : env->GetArrayLength((jarray)arrayValue);
EXCEPTION_CHECKING(env);
m->WriteSimple(&arraySize,bc_T_U32);
for (PRUint32 i = 0; i < arraySize; i++) {
MarshalElement(m,arrayValue,PR_FALSE,param,type,i,arrayElement);
}
}
break;
}
default:
PR_LOG(log,PR_LOG_DEBUG,("--it should not happend\n"));
;
}
return r;
}
#define UNMARSHAL_SIMPLE_ELEMENT(_type_,_Type_) \
do { \
int indexInArray; \
j##_type_ data; \
_type_##_map tmpData; \
if (um) { \
um->ReadSimple(&tmpData,type); \
data = tmpData; \
} \
if ( ! isOut \
&& (modifier == none) ) { \
*value = env->NewObject(_type_##Class,_type_##InitMID,data); \
EXCEPTION_CHECKING(env); \
} else if (isOut && (modifier == array)) { \
*value = env->NewObjectArray(1, _type_##ArrayClass, NULL); \
} else if ( (isOut && callSide == onServer) \
|| (modifier == array)) { \
int arraySize; \
arraySize = (modifier == array) ? ind : 1; \
*value = env->New##_Type_##Array(arraySize); \
EXCEPTION_CHECKING(env); \
} \
if (modifier == arrayElement \
|| (isOut && (modifier == none)) \
) { \
indexInArray = (modifier == arrayElement) ? ind : 0; \
env->Set##_Type_##ArrayRegion((j##_type_##Array)*value, indexInArray, 1, &data); \
EXCEPTION_CHECKING(env); \
} \
} while(0)
nsresult
bcJavaMarshalToolkit::UnMarshalElement(jobject *value, uint8 ind, bcIUnMarshaler *um, int isOut, nsXPTParamInfo * param,
bcXPType type, bcIAllocator *allocator, ArrayModifier modifier) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
switch(type) {
case bc_T_I8:
case bc_T_U8:
{
UNMARSHAL_SIMPLE_ELEMENT(byte,Byte);
break;
}
case bc_T_I16:
case bc_T_U16:
{
UNMARSHAL_SIMPLE_ELEMENT(short,Short);
break;
};
case bc_T_I32:
case bc_T_U32:
{
UNMARSHAL_SIMPLE_ELEMENT(int,Int);
break;
}
case bc_T_I64:
case bc_T_U64:
{
UNMARSHAL_SIMPLE_ELEMENT(long,Long);
break;
}
case bc_T_FLOAT:
{
UNMARSHAL_SIMPLE_ELEMENT(float,Float);
break;
}
case bc_T_DOUBLE:
{
UNMARSHAL_SIMPLE_ELEMENT(double,Double);
break;
}
case bc_T_BOOL:
{
UNMARSHAL_SIMPLE_ELEMENT(boolean,Boolean);
break;
}
case bc_T_CHAR:
case bc_T_WCHAR:
{
UNMARSHAL_SIMPLE_ELEMENT(char,Char);
break;
}
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR: //nb not sure about this
{
int indexInArray;
size_t size;
jstring data = NULL;
if (um) {
um->ReadString(&data,&size,allocator);
{
for (int i = 0; i < size && type == bc_T_WCHAR_STR; i++) {
char c = ((char*)data)[i];
PR_LOG(log, PR_LOG_DEBUG,("--[c++] bcJavaMarshalToolkit::UnMarshalElement T_WCHAR_STR [%d] = %d %c\n",i,c,c));
}
}
if (type == bc_T_CHAR_STR) {
data = env->NewStringUTF((const char*)data);
} else {
size-=2; size/=2;
data = env->NewString((const jchar*)data,size);
}
EXCEPTION_CHECKING(env);
}
if ( ! isOut
&& (modifier == none) ) {
*value = data;
} else if (isOut && (modifier == array)) {
*value = env->NewObjectArray(1, stringArrayClass, NULL);
EXCEPTION_CHECKING(env);
} else if ( (isOut && callSide == onServer)
|| (modifier == array)) {
int arraySize;
arraySize = (modifier == array) ? ind : 1;
*value = env->NewObjectArray(arraySize,stringClass,NULL);
EXCEPTION_CHECKING(env);
}
if (modifier == arrayElement
|| (isOut && (modifier == none))
) {
indexInArray = (modifier == arrayElement) ? ind : 0;
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
EXCEPTION_CHECKING(env);
}
break;
}
case bc_T_IID:
{
int indexInArray = 0;
jobject data = NULL;
if (um) {
nsIID iid;
um->ReadSimple(&iid,type);
data = bcIIDJava::GetObject(&iid);
}
if ( ! isOut
&& (modifier == none) ) {
*value = data;
} else if (isOut && (modifier == array)) {
*value = env->NewObjectArray(1, iidArrayClass, NULL);
EXCEPTION_CHECKING(env);
} else if ( (isOut && callSide == onServer)
|| (modifier == array)) {
int arraySize;
arraySize = (modifier == array) ? ind : 1;
*value = env->NewObjectArray(arraySize,iidClass,NULL);
EXCEPTION_CHECKING(env);
}
if (modifier == arrayElement
|| (isOut && (modifier == none))
) {
indexInArray = (modifier == arrayElement) ? ind : 0;
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
EXCEPTION_CHECKING(env);
}
break;
}
case bc_T_INTERFACE:
{
PR_LOG(log, PR_LOG_DEBUG,("--[c++] bcJavaMarshalToolkit::UnMarshalElement we have an interface\n"));
int indexInArray = 0;
jobject data = NULL;
bcOID oid = 0;
nsIID iid;
nsresult r;
jclass clazz = objectClass;
if (um) {
um->ReadSimple(&oid,type);
um->ReadSimple(&iid,bc_T_IID);
PR_LOG(log,PR_LOG_DEBUG,("%d oid\n",(int) oid));
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
return NS_ERROR_FAILURE;
}
if (oid != 0) {
javaStubsAndProxies->GetProxy(oid, iid, orb, &data);
}
javaStubsAndProxies->GetInterface(iid,&clazz);
}
if ( ! isOut
&& (modifier == none) ) {
*value = data;
} else if ( isOut && (modifier == array)) { //we are creating type[][]
jobject arrayObject;
arrayObject = env->NewObjectArray(1,clazz,NULL);
EXCEPTION_CHECKING(env);
jclass arrayClass = (jclass) env->CallObjectMethod(arrayObject,getClassMID); //nb how to to it better ?
EXCEPTION_CHECKING(env);
*value = env->NewObjectArray(1, arrayClass, NULL);
EXCEPTION_CHECKING(env);
} else if ( (isOut && callSide == onServer)
|| (modifier == array)) {
int arraySize;
arraySize = (modifier == array) ? ind : 1;
*value = env->NewObjectArray(arraySize,clazz,NULL);
EXCEPTION_CHECKING(env);
}
if (modifier == arrayElement
|| (isOut && (modifier == none))
) {
indexInArray = (modifier == arrayElement) ? ind : 0;
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
EXCEPTION_CHECKING(env);
}
break;
}
case bc_T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
bcXPType type = XPTType2bcXPType(datumType.TagPart());
if (isOut && callSide == onServer) {
UnMarshalElement(value,ind,NULL,isOut,param,type,allocator,array);
}
if (um != NULL) {
PRUint32 arraySize;
um->ReadSimple(&arraySize,bc_T_U32);
jobject arrayValue = NULL;
UnMarshalElement(&arrayValue,arraySize,NULL,0,param,type,allocator,array);
if (isOut) {
env->SetObjectArrayElement((jobjectArray)*value,0,arrayValue);
EXCEPTION_CHECKING(env);
} else {
*value = arrayValue;
}
for (PRUint32 i = 0; i < arraySize; i++) {
UnMarshalElement(&arrayValue,i,um,0,param,type,allocator,arrayElement);
}
}
break;
}
default:
;
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}
bcXPType bcJavaMarshalToolkit::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 bcJavaMarshalToolkit::InitializeStatic() {
jclass clazz;
if (!(clazz = env->FindClass("java/lang/Object"))
|| !(objectClass = (jclass) env->NewGlobalRef(clazz))
) {
return;
}
if (!(clazz = env->FindClass("java/lang/Boolean"))
|| !(booleanClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Z"))
|| !(booleanArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Character"))
|| !(charClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[C"))
|| !(charArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Byte"))
|| !(byteClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[B"))
|| !(byteArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Short"))
|| !(shortClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[[S"))
|| !(shortArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Integer"))
|| !(intClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[I"))
|| !(intArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Long"))
|| !(longClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[J"))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Float"))
|| !(floatClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[F"))
|| !(floatArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Double"))
|| !(doubleClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[D"))
|| !(doubleArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/String"))
|| !(stringClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/String;"))
|| !(stringArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("org/mozilla/xpcom/IID"))
|| !(iidClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Lorg/mozilla/xpcom/IID;"))
|| !(iidArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(booleanInitMID = env->GetMethodID(booleanClass,"<init>","(Z)V"))) {
DeInitializeStatic();
return;
}
if (!(booleanValueMID = env->GetMethodID(booleanClass,"booleanValue","()Z"))) {
DeInitializeStatic();
return;
}
if (!(charInitMID = env->GetMethodID(charClass,"<init>","(C)V"))) {
DeInitializeStatic();
return;
}
if (!(charValueMID = env->GetMethodID(charClass,"charValue","()C"))) {
DeInitializeStatic();
return;
}
if (!(byteInitMID = env->GetMethodID(byteClass,"<init>","(B)V"))) {
DeInitializeStatic();
return;
}
if (!(byteValueMID = env->GetMethodID(byteClass,"byteValue","()B"))) {
DeInitializeStatic();
return;
}
if (!(shortInitMID = env->GetMethodID(shortClass,"<init>","(S)V"))) {
DeInitializeStatic();
return;
}
if (!(shortValueMID = env->GetMethodID(shortClass,"shortValue","()S"))) {
DeInitializeStatic();
return;
}
if (!(intInitMID = env->GetMethodID(intClass,"<init>","(I)V"))) {
DeInitializeStatic();
return;
}
if (!(intValueMID = env->GetMethodID(intClass,"intValue","()I"))) {
DeInitializeStatic();
return;
}
if (!(longInitMID = env->GetMethodID(longClass,"<init>","(J)V"))) {
DeInitializeStatic();
return;
}
if (!(longValueMID = env->GetMethodID(longClass,"longValue","()J"))) {
DeInitializeStatic();
return;
}
if (!(floatInitMID = env->GetMethodID(floatClass,"<init>","(F)V"))) {
DeInitializeStatic();
return;
}
if (!(floatValueMID = env->GetMethodID(floatClass,"floatValue","()F"))) {
DeInitializeStatic();
return;
}
if (!(doubleInitMID = env->GetMethodID(doubleClass,"<init>","(D)V"))) {
DeInitializeStatic();
return;
}
if (!(doubleValueMID = env->GetMethodID(doubleClass,"doubleValue","()D"))) {
DeInitializeStatic();
return;
}
if (!(getClassMID = env->GetMethodID(objectClass,"getClass","()Ljava/lang/Class;"))) {
DeInitializeStatic();
return;
}
}
void bcJavaMarshalToolkit::DeInitializeStatic() { //nb need to do
PRLogModuleInfo * log = bcJavaGlobal::GetLog();
PR_LOG(log, PR_LOG_DEBUG,("--[c++]void bcJavaMarshalToolkit::DeInitializeStatic() - boomer \n"));
}

View File

@@ -1,118 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef _bcJavaMarshalToolkit_h
#define _bcJavaMarshalToolkit_h
#include "nscore.h"
#include "xptcall.h"
#include "nsISupports.h"
#include "jni.h"
#include "bcIMarshaler.h"
#include "bcIUnMarshaler.h"
#include "bcIORB.h"
class bcJavaMarshalToolkit {
public:
bcJavaMarshalToolkit(PRUint16 methodIndex,
nsIInterfaceInfo *interfaceInfo, jobjectArray args,
JNIEnv *env, int isOnServer, bcIORB *orb) ;
virtual ~bcJavaMarshalToolkit();
nsresult Marshal(bcIMarshaler *);
nsresult Marshal(bcIMarshaler *, jobject);
nsresult UnMarshal(bcIUnMarshaler *);
nsresult UnMarshal(bcIUnMarshaler *, jobject*);
private:
jobject retV;
enum ArrayModifier { none, arrayElement, array};
enum { unDefined, onServer, onClient } callSide;
JNIEnv *env;
PRUint16 methodIndex;
nsXPTMethodInfo *info;
nsIInterfaceInfo * interfaceInfo;
bcIORB *orb;
jobjectArray args;
static jclass objectClass;
static jclass objectArrayClass;
static jclass booleanClass;
static jclass booleanArrayClass;
static jmethodID booleanInitMID;
static jmethodID booleanValueMID;
static jclass charClass;
static jclass charArrayClass;
static jmethodID charInitMID;
static jmethodID charValueMID;
static jclass byteClass;
static jclass byteArrayClass;
static jmethodID byteInitMID;
static jmethodID byteValueMID;
static jclass shortClass;
static jclass shortArrayClass;
static jmethodID shortInitMID;
static jmethodID shortValueMID;
static jclass intClass;
static jclass intArrayClass;
static jmethodID intInitMID;
static jmethodID intValueMID;
static jclass longClass;
static jclass longArrayClass;
static jmethodID longInitMID;
static jmethodID longValueMID;
static jclass floatClass;
static jclass floatArrayClass;
static jmethodID floatInitMID;
static jmethodID floatValueMID;
static jclass doubleClass;
static jclass doubleArrayClass;
static jmethodID doubleInitMID;
static jmethodID doubleValueMID;
static jclass stringClass;
static jclass stringArrayClass;
static jclass iidClass;
static jclass iidArrayClass;
static jmethodID getClassMID;
void InitializeStatic();
void DeInitializeStatic();
bcXPType XPTType2bcXPType(uint8 type);
// nsresult MarshalElement(bcIMarshaler *m, jobject array, nsXPTParamInfo * param, bcXPType type,
// uint8 ind, ArrayModifier modifier = none);
nsresult
MarshalElement(bcIMarshaler *m, jobject value, PRBool isOut, nsXPTParamInfo * param,
bcXPType type, uint8 ind, ArrayModifier modifier = none);
nsresult
UnMarshalElement(jobject *value, uint8 ind, bcIUnMarshaler *um, PRBool isOut , nsXPTParamInfo * param,
bcXPType type, bcIAllocator *allocator, ArrayModifier modifier = none);
};
#endif

View File

@@ -1,126 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nscore.h"
#include "xptcall.h"
#include "bcJavaStub.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "bcJavaMarshalToolkit.h"
#include "bcJavaGlobal.h"
#include "bcIIDJava.h"
jclass bcJavaStub::objectClass = NULL;
jclass bcJavaStub::utilitiesClass = NULL;
jmethodID bcJavaStub::callMethodByIndexMID = NULL;
bcJavaStub::bcJavaStub(jobject obj) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStub::bcJavaStub \n"));
if (!obj) {
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStub::bcJavaStub obj== 0\n"));
return;
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
object = env->NewGlobalRef(obj);
}
bcJavaStub::~bcJavaStub() {
bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object);
}
void bcJavaStub::Dispatch(bcICall *call) {
//sigsend(P_PID, getpid(),SIGINT);
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
bcIID iid; bcOID oid; bcMID mid;
jobjectArray args;
call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
return;
}
if (!objectClass) {
Init();
if (!objectClass) {
return;
}
}
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid,(const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
PR_LOG(log, PR_LOG_DEBUG,("\n**[c++]hasRetval: %d\n", HasRetval(paramCount, info)));
if (HasRetval(paramCount, info))
// do not pass retval param
paramCount--;
args = env->NewObjectArray(paramCount, objectClass,NULL);
bcJavaMarshalToolkit * mt = new bcJavaMarshalToolkit(mid, interfaceInfo, args, env,1, call->GetORB());
bcIUnMarshaler * um = call->GetUnMarshaler();
mt->UnMarshal(um);
jobject jiid = bcIIDJava::GetObject(&iid);
jobject retval = bcJavaGlobal::GetJNIEnv()->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args);
//nb return value; excepion handling
bcIMarshaler * m = call->GetMarshaler();
mt->Marshal(m, retval);
//nb memory deallocation
delete m; delete um; delete mt;
return;
}
void bcJavaStub::Init() {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
objectClass = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Object"));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
utilitiesClass = (jclass)env->NewGlobalRef(env->FindClass("org/mozilla/xpcom/Utilities"));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
callMethodByIndexMID = env->GetStaticMethodID(utilitiesClass,"callMethodByIndex","(Ljava/lang/Object;Lorg/mozilla/xpcom/IID;I[Ljava/lang/Object;)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
}
PRBool bcJavaStub::HasRetval(PRUint32 paramCount, nsXPTMethodInfo *info)
{
for (unsigned int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
if (param.IsRetval())
return PR_TRUE;
}
return PR_FALSE;
}

View File

@@ -1,43 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaStub_h
#define __bcJavaStub_h
#include "bcIStub.h"
#include "jni.h"
#include "xptinfo.h"
class bcJavaStub : public bcIStub {
public:
bcJavaStub(jobject obj);
virtual ~bcJavaStub();
virtual void Dispatch(bcICall *call) ;
private:
jobject object;
static jclass objectClass;
static jclass utilitiesClass;
static jmethodID callMethodByIndexMID;
void Init();
PRBool HasRetval(PRUint32 paramCount, nsXPTMethodInfo *info);
};
#endif

View File

@@ -1,275 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "bcJavaStubsAndProxies.h"
#include "bcJavaStub.h"
#include "bcJavaGlobal.h"
#include "bcORB.h"
#include "bcIIDJava.h"
#include "nsHashtable.h"
jclass bcJavaStubsAndProxies::componentLoader = 0;
jmethodID bcJavaStubsAndProxies::loadComponentID = 0;
jclass bcJavaStubsAndProxies::proxyFactory = 0;
jmethodID bcJavaStubsAndProxies::getProxyID = 0;
jmethodID bcJavaStubsAndProxies::getInterfaceID = 0;
jclass bcJavaStubsAndProxies::java_lang_reflect_Proxy = 0;
jmethodID bcJavaStubsAndProxies::getInvocationHandlerID = 0;
jclass bcJavaStubsAndProxies::org_mozilla_xpcom_ProxyHandler = 0;
jmethodID bcJavaStubsAndProxies::getOIDID = 0;
NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaStubsAndProxies);
static nsModuleComponentInfo components[] =
{
{
"Black Connect Java stubs and proxies",
BC_JAVASTUBSANDPROXIES_CID,
BC_JAVASTUBSANDPROXIES_PROGID,
bcJavaStubsAndProxiesConstructor
}
};
NS_IMPL_NSGETMODULE("BlackConnect Java stubs and proxies",components);
NS_IMPL_ISUPPORTS(bcJavaStubsAndProxies,NS_GET_IID(bcJavaStubsAndProxies));
class bcOIDKey : public nsHashKey {
protected:
bcOID key;
public:
bcOIDKey(bcOID oid) {
key = oid;
}
virtual ~bcOIDKey() {
}
PRUint32 HashCode(void) const {
return (PRUint32)key;
}
PRBool Equals(const nsHashKey *aKey) const {
return (key == ((const bcOIDKey *) aKey)->key);
}
nsHashKey *Clone() const {
return new bcOIDKey(key);
}
};
bcJavaStubsAndProxies::bcJavaStubsAndProxies() {
NS_INIT_REFCNT();
oid2objectMap = new nsHashtable(256,PR_TRUE);
}
bcJavaStubsAndProxies::~bcJavaStubsAndProxies() {
delete oid2objectMap;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetStub(jobject obj, bcIStub **stub) {
if (!stub) {
return NS_ERROR_NULL_POINTER;
}
*stub = new bcJavaStub(obj);
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--[c++] bcJavaStubsAndProxies::GetProxy\n"));
if (!componentLoader) {
Init();
}
bcOIDKey *key = new bcOIDKey(oid);
void *tmp = oid2objectMap->Get(key);
delete key;
if (tmp != NULL) { //we have shortcut
*proxy = (jobject)tmp;
PR_LOG(log, PR_LOG_DEBUG, ("\n--bcJavaStubsAndProxies::GetProxy we have shortcut for oid=%d\n",oid));
} else {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
EXCEPTION_CHECKING(env);
}
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetInterface(const nsIID &iid, jclass *clazz) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--[c++] bcJavaStubsAndProxies::GetInterface\n"));
if (!componentLoader) {
Init();
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
*clazz = (jclass)env->CallStaticObjectMethod(proxyFactory,getInterfaceID, jiid);
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
nsresult rv = NS_OK;
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env->IsInstanceOf(object,java_lang_reflect_Proxy)) {
EXCEPTION_CHECKING(env);
jobject handler = env->CallStaticObjectMethod(java_lang_reflect_Proxy,getInvocationHandlerID,object);
EXCEPTION_CHECKING(env);
if (handler != NULL
&& env->IsInstanceOf(handler,org_mozilla_xpcom_ProxyHandler)) {
EXCEPTION_CHECKING(env);
*oid = env->CallLongMethod(handler,getOIDID);
PR_LOG(log, PR_LOG_DEBUG, ("--bcJavaStubsAndProxies::GetOID we are using old oid %d\n",*oid));
return rv;
}
}
bcIStub *stub = new bcJavaStub(object);
*oid = orb->RegisterStub(stub);
oid2objectMap->Put(new bcOIDKey(*oid),object);
return rv;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID %s\n",location));
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
nsresult result;
if (!componentLoader) {
Init();
}
//location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info
strcpy(location + strlen(location)-4,"comp");
jstring jstr = env->NewStringUTF(location);
jobject object = env->CallStaticObjectMethod(componentLoader, loadComponentID, jstr);
bcIStub *stub = new bcJavaStub(object);
NS_WITH_SERVICE(bcORB,_orb,kORBCIID,&result);
if (NS_FAILED(result)) {
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID failed\n"));
return result;
}
bcIORB *orb;
_orb->GetORB(&orb);
*oid = orb->RegisterStub(stub);
return NS_OK;
}
void bcJavaStubsAndProxies::Init(void) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log, PR_LOG_DEBUG,("--[c++]bcJavaStubsAndProxies::Init\n"));
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
componentLoader = env->FindClass("org/mozilla/xpcom/ComponentLoader");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
PR_LOG(log,PR_LOG_ALWAYS,("--Did you set CLASSPATH correctly\n"));
return;
}
componentLoader = (jclass)env->NewGlobalRef(componentLoader);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
proxyFactory = (jclass)env->NewGlobalRef(proxyFactory);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getInterfaceID = env->GetStaticMethodID(proxyFactory, "getInterface","(Lorg/mozilla/xpcom/IID;)Ljava/lang/Class;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
java_lang_reflect_Proxy = env->FindClass("java/lang/reflect/Proxy");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getInvocationHandlerID =
env->GetStaticMethodID(java_lang_reflect_Proxy, "getInvocationHandler",
"(Ljava/lang/Object;)Ljava/lang/reflect/InvocationHandler;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
java_lang_reflect_Proxy = (jclass)env->NewGlobalRef(java_lang_reflect_Proxy);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
org_mozilla_xpcom_ProxyHandler = env->FindClass("org/mozilla/xpcom/ProxyHandler");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
org_mozilla_xpcom_ProxyHandler = (jclass)env->NewGlobalRef(org_mozilla_xpcom_ProxyHandler);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getOIDID = env->GetMethodID(org_mozilla_xpcom_ProxyHandler, "getOID","()J");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
}

View File

@@ -1,74 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaStubsAndProxies_h
#define __bcJavaStubsAndProxies_h
#include "nsISupports.h"
#include "jni.h"
#include "bcDefs.h"
#include "bcIStub.h"
#include "bcIORB.h"
/* 58034ea6-1dd2-11b2-9b58-8630abb8af47 */
#define BC_JAVASTUBSANDPROXIES_IID \
{0x58034ea6, 0x1dd2, 0x11b2, \
{0x9b, 0x58, 0x86, 0x30, 0xab, 0xb8, 0xaf,0x47}}
#define BC_JAVASTUBSANDPROXIES_PROGID "component://netscape/blackwood/blackconnect/java-stubs-and-proxies"
/* 7cadf6e8-1dd2-11b2-9a6e-b1c37844e004 */
#define BC_JAVASTUBSANDPROXIES_CID \
{0x7cadf6e8, 0x1dd2, 0x11b2, \
{0x9a, 0x6e, 0xb1, 0xc3, 0x78,0x44, 0xe0, 0x04}}
class nsHashtable;
class bcJavaStubsAndProxies : public nsISupports {
NS_DECL_ISUPPORTS
NS_DEFINE_STATIC_IID_ACCESSOR(BC_JAVASTUBSANDPROXIES_IID)
NS_IMETHOD GetStub(jobject obj, bcIStub **stub);
NS_IMETHOD GetOID(char *location, bcOID *); //load component by location
NS_IMETHOD GetOID(jobject object, bcIORB *orb, bcOID *oid);
NS_IMETHOD GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy);
NS_IMETHOD GetInterface(const nsIID &iid, jclass *clazz);
bcJavaStubsAndProxies();
virtual ~bcJavaStubsAndProxies();
protected:
void Init(void);
static jclass componentLoader;
static jmethodID loadComponentID;
static jclass proxyFactory;
static jmethodID getProxyID;
static jmethodID getInterfaceID;
static jclass java_lang_reflect_Proxy;
static jmethodID getInvocationHandlerID;
static jclass org_mozilla_xpcom_ProxyHandler;
static jmethodID getOIDID;
nsHashtable * oid2objectMap;
};
#endif /* __bcJavaStubsAndProxies_h */

View File

@@ -1,55 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = DLL
MODULE=bcjavastubs
COMPONENT = 1
DLLNAME = bcjavastubs
DLL=.\$(OBJDIR)\$(DLLNAME).dll
EXPORTS = \
bcJavaStubsAndProxies.h
OBJS= \
.\$(OBJDIR)\bcJavaMarshalToolkit.obj \
.\$(OBJDIR)\bcJavaStub.obj \
.\$(OBJDIR)\bcJavaGlobal.obj \
.\$(OBJDIR)\bcJavaStubsAndProxies.obj \
.\$(OBJDIR)\bcIIDJava.obj \
.\$(OBJDIR)\org_mozilla_xpcom_Utilities.obj \
.\$(OBJDIR)\org_mozilla_xpcom_Debug.obj \
$(NULL)
LINCS=-I$(JDKHOME)\include -I$(JDKHOME)\include\win32
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib $(JDKHOME)\lib\jvm.lib
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
clobber::
rm -f $(DIST)\bin\components\$(DLLNAME).dll

View File

@@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "org_mozilla_xpcom_Debug.h"
#include "bcJavaGlobal.h"
/*
* Class: org_mozilla_xpcom_Debug
* Method: log
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_Debug_log
(JNIEnv *env, jclass, jstring jstr) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
char * str = NULL;
str = (char*)env->GetStringUTFChars(jstr,NULL);
PR_LOG(log, PR_LOG_DEBUG, ("%s\n",str));
env->ReleaseStringUTFChars(jstr,str);
}

View File

@@ -1,21 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_mozilla_xpcom_Debug */
#ifndef _Included_org_mozilla_xpcom_Debug
#define _Included_org_mozilla_xpcom_Debug
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_mozilla_xpcom_Debug
* Method: log
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_Debug_log
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,127 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
* Denis Sharypov <sdv@sparc.spb.su>
*/
#include "nsISupports.h"
#include "org_mozilla_xpcom_Utilities.h"
#include "bcIORB.h"
#include "bcICall.h"
#include "bcDefs.h"
#include "xptcall.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "bcJavaMarshalToolkit.h"
#include "ctype.h"
#include "bcJavaGlobal.h"
/*
* Class: org_mozilla_xpcom_Utilities
* Method: callMethodByIndex
* Signature: (JILjava/lang/String;J[Ljava/lang/Object;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
(JNIEnv *env, jclass clazz, jlong _oid, jint mid, jstring jiid, jlong _orb, jobjectArray args) {
bcIORB * orb = (bcIORB*) _orb;
bcOID oid = (bcOID)_oid;
nsIID iid;
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] jni Java_org_mozilla_xpcom_Utilities_callMethodByIndex %d\n",(int)mid));
const char * str = NULL;
str = env->GetStringUTFChars(jiid,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jiid,str);
bcICall *call = orb->CreateCall(&iid, &oid, mid);
/*****/
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if( (iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return NULL; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
return NULL;
}
/*****/
bcIMarshaler * m = call->GetMarshaler();
bcJavaMarshalToolkit * mt = new bcJavaMarshalToolkit((unsigned)mid, interfaceInfo, args, env, 0, orb);
mt->Marshal(m);
orb->SendReceive(call);
bcIUnMarshaler * um = call->GetUnMarshaler();
jobject retval;
mt->UnMarshal(um, &retval);
delete call; delete m; delete um; delete mt;
return retval;
}
/*
* Class: org_mozilla_xpcom_Utilities
* Method: getInterfaceMethodNames
* Signature: (Ljava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_org_mozilla_xpcom_Utilities_getInterfaceMethodNames
(JNIEnv *env, jclass clazz, jstring jiid) {
if (!jiid) {
return NULL;
}
nsIID iid;
const char * str = NULL;
str = env->GetStringUTFChars(jiid, NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jiid,str);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return NULL; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
return NULL;
}
PRUint16 num;
interfaceInfo->GetMethodCount(&num);
jobjectArray names;
jclass stringClass = env->GetObjectClass(jiid);
names = env->NewObjectArray(num, stringClass, NULL);
nsXPTMethodInfo* info;
char buf[256];
for (int i = 0; i < num; i++) {
interfaceInfo->GetMethodInfo(i, (const nsXPTMethodInfo **)&info);
const char* name = info->GetName();
if (info->IsGetter()) {
sprintf(buf, "get%c%s", toupper(*name), name+1);
} else if (info->IsSetter()) {
sprintf(buf, "set%c%s", toupper(*name), name+1);
} else {
// first letter of the method name is in lowercase in java
sprintf(buf, "%c%s", tolower(*name), name + 1);
}
env->SetObjectArrayElement(names, i, env->NewStringUTF(buf));
}
return names;
}

View File

@@ -1,29 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_mozilla_xpcom_Utilities */
#ifndef _Included_org_mozilla_xpcom_Utilities
#define _Included_org_mozilla_xpcom_Utilities
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_mozilla_xpcom_Utilities
* Method: callMethodByIndex
* Signature: (JILjava/lang/String;J[Ljava/lang/Object;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
(JNIEnv *, jclass, jlong, jint, jstring, jlong, jobjectArray);
/*
* Class: org_mozilla_xpcom_Utilities
* Method: getInterfaceMethodNames
* Signature: (Ljava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_org_mozilla_xpcom_Utilities_getInterfaceMethodNames
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,52 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../../..
topsrcdir = ../../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
MODULE = javaSample
LIBRARY_NAME = javaSample
IS_COMPONENT = 1
XPIDL_MODULE = javaSample
XPIDLSRCS = bcIJavaSample.idl
CPPSRCS = bcJavaSample.cpp
include $(topsrcdir)/config/rules.mk
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
$(JDKHOME)/bin/jar cvfm bcJavaSample.jar.comp manifest *.class
.java.class:
$(JDKHOME)/bin/javac -classpath .:../classes $<
install-component: bcJavaSample.jar.comp bcJavaSample.jar.info
cp bcJavaSample.jar.comp bcJavaSample.jar.info $(DEPTH)/dist/bin/components/
clobber-java:
rm -f *.class *.jar
clobber:: clobber-java
clobber_all:: clobber-java
install:: install-component

View File

@@ -1,15 +0,0 @@
#include "nsISupports.idl"
#include "nsIComponentManager.idl"
[scriptable, uuid(ca1e2656-1dd1-11b2-9c4e-f49ea557abde)]
interface bcIJavaSample : nsISupports
{
void test0();
void test1(in long l);
void test2(in bcIJavaSample o);
void test3(in PRUint32 count,[array, size_is(count)] in long valueArray);
void test4(in PRUint32 count,[array, size_is(count)] inout string valueArray);
void test5(in nsIComponentManager cm);
void test6(in PRUint32 count,[array, size_is(count)] in string valueArray);
void test7(out PRUint32 count,[array, size_is(count)] out char valueArray);
};

View File

@@ -1,51 +0,0 @@
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from bcIJavaSample.idl.
*/
import org.mozilla.xpcom.*;
/**
* Interface bcIJavaSample
*
* IID: 0xca1e2656-1dd1-11b2-9c4e-f49ea557abde
*/
public interface bcIJavaSample extends nsISupports
{
public static final String IID =
"ca1e2656-1dd1-11b2-9c4e-f49ea557abde";
/* void test0 (); */
public void test0();
/* void test1 (in long l); */
public void test1(int l);
/* void test2 (in bcIJavaSample o); */
public void test2(bcIJavaSample o);
/* void test3 (in PRUint32 count, [array, size_is (count)] in long valueArray); */
public void test3(int count, int[] valueArray);
/* void test4 (in PRUint32 count, [array, size_is (count)] inout string valueArray); */
public void test4(int count, String[][] valueArray);
/* void test5 (in nsIComponentManager cm); */
public void test5(nsIComponentManager cm);
/* void test6 (in PRUint32 count, [array, size_is (count)] in string valueArray); */
public void test6(int count, String[] valueArray);
/* void test7 (out PRUint32 count, [array, size_is (count)] out char valueArray); */
public void test7(int[] count, char[][] valueArray);
}
/*
* end
*/

View File

@@ -1,202 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcIJavaSample.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsIEnumerator.h"
#include "stdlib.h"
#define BC_JAVA_SAMPLE_CID \
{0x072fa586, 0x1dd2, 0x11b2, \
{ 0xb2, 0x3a, 0x81, 0xe8, 0x16, 0x49, 0xe8, 0x8b }}
class bcJavaSample : public bcIJavaSample {
NS_DECL_ISUPPORTS
NS_DECL_BCIJAVASAMPLE
bcJavaSample();
virtual ~bcJavaSample();
};
NS_IMPL_ISUPPORTS1(bcJavaSample, bcIJavaSample)
bcJavaSample::bcJavaSample()
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
}
bcJavaSample::~bcJavaSample()
{
/* destructor code */
}
NS_IMETHODIMP bcJavaSample::Test0()
{ printf("--[c++] bcJavaSample::Test0() \n");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void test1 (in long l); */
NS_IMETHODIMP bcJavaSample::Test1(PRInt32 l)
{
printf("--[c++] bcJavaSample.test1 l=%d\n",l);
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void test2 (in bcIJavaSample o); */
NS_IMETHODIMP bcJavaSample::Test2(bcIJavaSample *o)
{
printf("--[c++] bcJavaSample.test2\n");
o->Test0();
return NS_OK;
}
/* void test3 (in PRUint32 count, [array, size_is (count)] in long valueArray); */
NS_IMETHODIMP bcJavaSample::Test3(PRUint32 count, PRInt32 *valueArray) {
printf("--[c++] bcJavaSample.test3 coutn %d\n",count);
for(unsigned int i = 0; i < count; i++) {
printf("--[c++] valueArray[%d]=%d\n",i,valueArray[i]);
}
return NS_OK;
}
/* void test4 (in PRUint32 count, [array, size_is (count)] inout string valueArray); */
NS_IMETHODIMP bcJavaSample::Test4(PRUint32 count, char ***valueArray) {
printf("--[c++] bcJavaSample.test4 coutn %d\n",count);
for(unsigned int i = 0; i < count; i++) {
printf("--[c++] valueArray[%d]=%s\n",i,(*valueArray)[i]);
}
char ** array = (char **)malloc(sizeof(char*)*4);
array[0] = "1";
array[1] = "2";
array[2] = "hello";
array[3] = "world";
*valueArray = array;
return NS_OK;
}
/* void test5 (in nsIComponentManager cm); */
NS_IMETHODIMP bcJavaSample::Test5(nsIComponentManager *cm) {
return NS_OK;
}
/* void test6 (in PRUint32 count, [array, size_is (count)] in string valueArray); */
NS_IMETHODIMP bcJavaSample::Test6(PRUint32 count, const char **valueArray) {
printf("--[c++] bcJavaSample.test6 coutn %d\n",count);
for(unsigned int i = 0; i < count; i++) {
printf("--[c++] valueArray[%d]=%s\n",i,valueArray[i]);
}
return NS_OK;
}
/* void test7 (in PRUint32 count, [array, size_is (count)] out char valueArray); */
NS_IMETHODIMP bcJavaSample::Test7(PRUint32 *count, char **valueArray) {
return NS_OK;
}
void test() {
printf("--BlackConnect test start\n");
nsresult r;
bcIJavaSample *test;
bcIJavaSample *a = new bcJavaSample();
r = nsComponentManager::CreateInstance("bcJavaSample",
nsnull,
NS_GET_IID(bcIJavaSample),
(void**)&test);
if (NS_FAILED(r)) {
printf("--[debug] can not load bcJavaSample\n");
return;
}
//sigsend(P_PID, getpid(),SIGINT);
//test->Test1(2000);
test->Test1(1000);
bcIJavaSample *test1;
if (NS_FAILED(r)) {
printf("failed to get component. try to restart test\n");
} else {
test->Test2(a);
}
test->QueryInterface(NS_GET_IID(bcIJavaSample),(void**)&test1);
int intArray[] = {1,2,3};
test->Test3(3, intArray);
{
char ** valueArray = (char **)malloc(sizeof(char*)*4);
valueArray[0] = "hi";
valueArray[1] = "there";
valueArray[2] = "a";
valueArray[3] = "b";
char *** valueArray2 = &valueArray;
test->Test4(4,valueArray2);
for (int i = 0; i < 4; i++) {
printf("valueArray2[%d]=%s\n",i,(*valueArray2)[i]);
}
}
{
nsIComponentManager* cm;
nsresult rv = NS_GetGlobalComponentManager(&cm);
printf("--[c++] bcJavaSample before test->Test5(cm)\n");
test->Test5(cm);
nsIEnumerator *enumerator;
rv = cm->EnumerateCLSIDs(&enumerator);
if (NS_FAILED(rv)) {
printf("--[c++] can get enumerator\n");
}
printf("--[c++] bcJavaSample after test->Test5(cm)\n");
}
{
const char ** valueArray = (const char **)malloc(sizeof(char*)*4);
valueArray[0] = "hi";
valueArray[1] = "there";
valueArray[2] = "a";
valueArray[3] = "b";
test->Test6(4,valueArray);
}
{
printf("--[c++]about to test7\n");
PRUint32 count;
char *charArray;
test->Test7(&count,&charArray);
for (int i = 0; i < count; i++) {
printf("--[c++] charArray[%d]=%c\n",i,charArray[i]);
}
printf("--[c++]end of test7\n");
}
printf("--BlackConnect test end\n");
}
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 ++;
printf("--bcJavaSample before test\n");
test();
printf("--bcJavaSample after test\n");
}
return NS_ERROR_FAILURE;
}

View File

@@ -1,3 +0,0 @@
6b701852-1dd2-11b2-91bd-d3ab05f89834
bcJavaSample
bcJavaSample

View File

@@ -1,154 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
import org.mozilla.xpcom.*;
import java.lang.reflect.*;
public class bcJavaSample implements bcIJavaSample {
public bcJavaSample() {
System.out.println("--[java]bcJavaSample constructor");
}
public Object queryInterface(IID iid) {
System.out.println("--[java]bcJavaSample::queryInterface iid="+iid);
Object result;
if ( iid.equals(nsISupportsIID)
|| iid.equals(bcIJavaSampleIID)) {
result = this;
} else {
result = null;
}
System.out.println("--[java]bcJavaSample::queryInterface result=null "+(result==null));
return result;
}
public void test0() {
System.out.println("--[java]bcJavaSample.test0 ");
}
public void test1(int l) {
System.out.println("--[java]bcJavaSample.test1 "+l+"\n");
}
public void test2(bcIJavaSample o) {
System.out.println("--[java]bcJavaSample.test2");
System.out.println("--[java]bcJavaSample.test2 :)))) Hi there");
if (o != null) {
System.out.println("--[java]bcJavaSample.test2 o!= null");
o.test0();
o.test1(1000);
o.test2(this);
int[] array={3,2,1};
o.test3(3,array);
{
String[] strings = {"4","3","2","1"};
o.test6(4, strings);
}
} else {
System.out.println("--[java]bcJavaSample.test2 o = null");
}
}
public void test3(int count, int[] valueArray) {
System.out.println("--[java]bcJavaSample.test3");
System.out.println(valueArray.length);
for (int i = 0; i < valueArray.length; i++) {
System.out.println("--[java]callMethodByIndex args["+i+"] = "+valueArray[i]);
}
}
public void test4(int count, String[][] valueArray) {
System.out.println("--[java]bcJavaSample.test4");
String[] array = valueArray[0];
for (int i = 0; i < array.length; i++) {
System.out.println("--[java]bcJavaSample.test4 valueArray["+i+"] = "+array[i]);
}
String[] returnArray = {"4","3","2","1"};
valueArray[0] = returnArray;
}
/* void test5 (in nsIComponentManager cm); */
public void test5(nsIComponentManager cm) {
System.out.println("--[java]bcJavaSample.test5");
try {
nsIEnumerator retval;
nsIEnumerator enumerator = cm.enumerateContractIDs();
System.out.println("--[java] before calling enumerator.firts() "+
"enumerator==null "+(enumerator==null));
enumerator.first();
int counter = 0;
nsISupports obj;
String str;
nsISupportsString strObj;
while (true) {
obj = enumerator.currentItem();
if (obj == null
|| counter > 300) {
break;
}
strObj = (nsISupportsString) obj.queryInterface(nsISupportsStringIID);
str = strObj.getData();
System.out.println("--[java] bcJavaSample.Test5 string "+str);
enumerator.next(); counter++;
}
} catch (Exception e) {
System.out.println(e);
}
}
public void test6(int count, String[] valueArray) {
System.out.println("--[java]bcJavaSample.test6");
String[] array = valueArray;
for (int i = 0; i < array.length; i++) {
System.out.println("--[java]bcJavaSample.test6 valueArray["+i+"] = "+array[i]);
}
}
/* void test7 (out PRUint32 count, [array, size_is (count)] out char valueArray); */
public void test7(int[] count, char[][] valueArray) {
System.out.println("--[java]bcJavaSample.test7");
char [] retValue = {'1','b','c','d'};
count[0] = retValue.length;
valueArray[0] = retValue;
}
static IID bcIJavaSampleIID = new IID(bcIJavaSample.IID);
static IID nsISupportsIID = new IID(nsISupports.IID);
static IID nsIComponenstManagerIID = new IID(nsIComponentManager.IID);
static IID nsISupportsStringIID = new IID(nsISupportsString.IID);
static {
try {
Class nsIComponentManagerClass =
Class.forName("org.mozilla.xpcom.nsIComponentManager");
Class nsIEnumeratorClass =
Class.forName("org.mozilla.xpcom.nsIEnumerator");
Class nsISupportsStringClass =
Class.forName("org.mozilla.xpcom.nsISupportsString");
InterfaceRegistry.register(nsIComponentManagerClass);
InterfaceRegistry.register(nsIEnumeratorClass);
InterfaceRegistry.register(nsISupportsStringClass);
} catch (Exception e) {
System.out.println(e);
}
}
};

View File

@@ -1,63 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ..\..\..\..
topsrcdir = ..\..\..\..
srcdir = .
VPATH = .
MAKE_OBJ_TYPE=DLL
MODULE=javaSample
COMPONENT=1
DLLNAME=$(MODULE)
DLL=.\$(OBJDIR)\$(DLLNAME).dll
XPIDLSRCS = \
.\bcIJavaSample.idl \
$(NULL)
OBJS = .\$(OBJDIR)\bcJavaSample.obj
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
include <$(DEPTH)\config\rules.mak>
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
$(JDKHOME)\bin\jar cvfm bcJavaSample.jar.comp manifest *.class
.SUFFIXES: .java .class
.java.class:
$(JDKHOME)\bin\javac -classpath .;..\classes $<
install-component: bcJavaSample.jar.comp bcJavaSample.jar.info $(DLL)
copy bcJavaSample.jar* $(DIST)\bin\components
copy $(DLL) $(DIST)\bin\components
clobber-java:
-del *.class *.jar.comp
clobber:: clobber-java
rm $(DIST)\bin\components\$(DLLNAME).dll
rm $(DIST)\bin\components\bcJavaSample.jar.*
clobber_all:: clobber-java
install:: install-component

View File

@@ -1 +0,0 @@
Component-Class: bcJavaSample

View File

@@ -1,74 +0,0 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = ../../../..
srcdir = .
VPATH = .
XPIDLDIR = $(DEPTH)/xpcom/typelib/xpidl
include $(DEPTH)/config/autoconf.mk
include $(DEPTH)/config/config.mk
PROGRAM = xpidl$(BIN_SUFFIX)
INTERNAL_TOOLS = 1
CSRCS = \
xpidl.c \
xpidl_idl.c \
$(XPIDLDIR)/xpidl_util.c \
$(XPIDLDIR)/xpidl_header.c \
$(XPIDLDIR)/xpidl_typelib.c \
$(XPIDLDIR)/xpidl_doc.c \
xpidl_java.c \
$(NULL)
CFLAGS += $(LIBIDL_CFLAGS) -I$(XPIDLDIR)
ifdef CROSS_COMPILE
HOST_PROGRAM = host_xpidl
HOST_CSRCS = $(CSRCS)
endif
include $(topsrcdir)/config/rules.mk
# Compile directly against the static lib, so we can use xpidl during the build
# without the shared library path being set.
LIBS = $(DIST)/lib/libxpt.$(LIB_SUFFIX) $(LIBIDL_LIBS)
# Tell the $(PROGRAM) target that we need to be recompiled when libxpt changes.
EXTRA_DEPS = $(wildcard $(DIST)/lib/libxpt.*)
ifdef CROSS_COMPILE
HOST_CFLAGS += $(HOST_LIBIDL_CFLAGS)
HOST_LIBS = $(DIST)/host/lib/libhostxpt.$(LIB_SUFFIX) $(HOST_LIBIDL_LIBS)
HOST_EXTRA_DEPS = $(wildcard $(DIST)/host/lib/libhostxpt.*)
ifdef HOST_NSPR_MDCPUCFG
HOST_CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
endif
endif
export:: install

View File

@@ -1,74 +0,0 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
XPIDLDIR = $(DEPTH)/xpcom/typelib/xpidl
include $(DEPTH)/config/autoconf.mk
include $(DEPTH)/config/config.mk
PROGRAM = xpidl$(BIN_SUFFIX)
INTERNAL_TOOLS = 1
CSRCS = \
xpidl.c \
xpidl_idl.c \
$(XPIDLDIR)/xpidl_util.c \
$(XPIDLDIR)/xpidl_header.c \
$(XPIDLDIR)/xpidl_typelib.c \
$(XPIDLDIR)/xpidl_doc.c \
xpidl_java.c \
$(NULL)
CFLAGS += $(LIBIDL_CFLAGS) -I$(XPIDLDIR)
ifdef CROSS_COMPILE
HOST_PROGRAM = host_xpidl
HOST_CSRCS = $(CSRCS)
endif
include $(topsrcdir)/config/rules.mk
# Compile directly against the static lib, so we can use xpidl during the build
# without the shared library path being set.
LIBS = $(DIST)/lib/libxpt.$(LIB_SUFFIX) $(LIBIDL_LIBS)
# Tell the $(PROGRAM) target that we need to be recompiled when libxpt changes.
EXTRA_DEPS = $(wildcard $(DIST)/lib/libxpt.*)
ifdef CROSS_COMPILE
HOST_CFLAGS += $(HOST_LIBIDL_CFLAGS)
HOST_LIBS = $(DIST)/host/lib/libhostxpt.$(LIB_SUFFIX) $(HOST_LIBIDL_LIBS)
HOST_EXTRA_DEPS = $(wildcard $(DIST)/host/lib/libhostxpt.*)
ifdef HOST_NSPR_MDCPUCFG
HOST_CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
endif
endif
export:: install

View File

@@ -1,68 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = EXE
PROGRAM = .\$(OBJDIR)\xpidl.exe
#RESFILE = xpidl.res
# glib and libIDL link against the non-debug msvcrt
MOZ_NO_DEBUG_RTL=1
XPIDLDIR = $(DEPTH)\xpcom\typelib\xpidl
OBJS = \
.\$(OBJDIR)\xpidl.obj \
.\$(OBJDIR)\xpidl_idl.obj \
$(XPIDLDIR)\$(OBJDIR)\xpidl_util.obj \
$(XPIDLDIR)\$(OBJDIR)\xpidl_header.obj \
$(XPIDLDIR)\$(OBJDIR)\xpidl_typelib.obj \
$(XPIDLDIR)\$(OBJDIR)\xpidl_doc.obj \
.\$(OBJDIR)\xpidl_java.obj \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom \
-I$(MOZ_TOOLS)\include \
-I$(XPIDLDIR) \
$(NULL)
LCFLAGS = -DEXPORT_XPT_API
MYDIR=C:\USR\LOCAL
LLIBS= \
$(DIST)\lib\xpcomxpt_s.lib \
$(MOZ_TOOLS)\lib\glib-1.2.lib \
$(MOZ_TOOLS)\lib\libidl-0.6.lib \
$(NULL)
LLFLAGS= $(LLFLAGS) -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRTD
include <$(DEPTH)\config\rules.mak>
export:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\xpidl.exe
$(PROGRAM):: $(OBJS) $(MYLIBS)

View File

@@ -1,198 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* Main xpidl program entry point.
*/
#include "xpidl.h"
static ModeData modes[] = {
{"header", "Generate C++ header", "h", xpidl_header_dispatch},
{"typelib", "Generate XPConnect typelib", "xpt", xpidl_typelib_dispatch},
{"doc", "Generate HTML documentation", "html", xpidl_doc_dispatch},
{"java", "Generate Java interface", "java", xpidl_java_dispatch},
{0, 0, 0, 0}
};
static ModeData *
FindMode(char *mode)
{
int i;
for (i = 0; modes[i].mode; i++) {
if (!strcmp(modes[i].mode, mode))
return &modes[i];
}
return NULL;
}
gboolean enable_debug = FALSE;
gboolean enable_warnings = FALSE;
gboolean verbose_mode = FALSE;
gboolean emit_typelib_annotations = FALSE;
static char xpidl_usage_str[] =
"Usage: %s [-m mode] [-w] [-v] [-I path] [-o basename] filename.idl\n"
" -a emit annotaions to typelib\n"
" -w turn on warnings (recommended)\n"
" -v verbose mode (NYI)\n"
" -I add entry to start of include path for ``#include \"nsIThing.idl\"''\n"
" -o use basename (e.g. ``/tmp/nsIThing'') for output\n"
" -m specify output mode:\n";
static void
xpidl_usage(int argc, char *argv[])
{
int i;
fprintf(stderr, xpidl_usage_str, argv[0]);
for (i = 0; modes[i].mode; i++) {
fprintf(stderr, " %-12s %-30s (.%s)\n", modes[i].mode,
modes[i].modeInfo, modes[i].suffix);
}
}
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
#define main xpidl_main
int xpidl_main(int argc, char *argv[]);
#endif
int main(int argc, char *argv[])
{
int i;
IncludePathEntry *inc, *inc_head, **inc_tail;
char *file_basename = NULL;
ModeData *mode = NULL;
/* turn this on for extra checking of our code */
/* IDL_check_cast_enable(TRUE); */
inc_head = xpidl_malloc(sizeof *inc);
#ifndef XP_MAC
inc_head->directory = ".";
#else
inc_head->directory = "";
#endif
inc_head->next = NULL;
inc_tail = &inc_head->next;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
switch (argv[i][1]) {
case '-':
argc++; /* pretend we didn't see this */
/* fall through */
case 0: /* - is a legal input filename (stdin) */
goto done_options;
case 'a':
emit_typelib_annotations = TRUE;
break;
case 'w':
enable_warnings = TRUE;
break;
case 'v':
verbose_mode = TRUE;
break;
case 'I':
if (argv[i][2] == '\0' && i == argc) {
fputs("ERROR: missing path after -I\n", stderr);
xpidl_usage(argc, argv);
return 1;
}
inc = xpidl_malloc(sizeof *inc);
if (argv[i][2] == '\0') {
/* is it the -I foo form? */
inc->directory = argv[++i];
} else {
/* must be the -Ifoo form. Don't preincrement i. */
inc->directory = argv[i] + 2;
}
#ifdef DEBUG_shaver_includes
fprintf(stderr, "adding %s to include path\n", inc->directory);
#endif
inc->next = NULL;
*inc_tail = inc;
inc_tail = &inc->next;
break;
case 'o':
if (i == argc) {
fprintf(stderr, "ERROR: missing basename after -o\n");
xpidl_usage(argc, argv);
return 1;
}
file_basename = argv[i + 1];
i++;
break;
case 'm':
if (i == argc) {
fprintf(stderr, "ERROR: missing modename after -m\n");
xpidl_usage(argc, argv);
return 1;
}
if (mode) {
fprintf(stderr,
"ERROR: must specify exactly one mode "
"(first \"%s\", now \"%s\")\n", mode->mode,
argv[i + 1]);
xpidl_usage(argc, argv);
return 1;
}
mode = FindMode(argv[++i]);
if (!mode) {
fprintf(stderr, "ERROR: unknown mode \"%s\"\n", argv[i]);
xpidl_usage(argc, argv);
return 1;
}
break;
default:
fprintf(stderr, "unknown option %s\n", argv[i]);
xpidl_usage(argc, argv);
return 1;
}
}
done_options:
if (!mode) {
fprintf(stderr, "ERROR: must specify output mode\n");
xpidl_usage(argc, argv);
return 1;
}
if (argc != i + 1) {
fprintf(stderr, "ERROR: extra arguments after input file\n");
}
if (!strcmp(mode->mode, "java") && file_basename) {
fprintf(stderr, "ERROR: you can't specify -o basename in -m java mode.\n"
"Java filename can't differ from the java interface name.\n"
"Omit -o option. Each java interface will be generated in a single file.\n");
return 1;
}
/*
* Don't try to process multiple files, given that we don't handle -o
* multiply.
*/
if (xpidl_process_idl(argv[i], inc_head, file_basename, mode))
return 0;
return 1;
}

View File

@@ -1,746 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* Common IDL-processing code.
*/
#include "xpidl.h"
/*
* The bulk of the generation happens here.
*/
gboolean
xpidl_process_node(TreeState *state)
{
gint type;
nodeHandler *dispatch, handler;
assert(state->tree);
type = IDL_NODE_TYPE(state->tree);
if ((dispatch = state->dispatch) && (handler = dispatch[type]))
return handler(state);
return TRUE;
}
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
extern void mac_warning(const char* warning_message);
#endif
static int
msg_callback(int level, int num, int line, const char *file,
const char *message)
{
char *warning_message;
if (!file)
file = "<unknown file>";
warning_message = g_strdup_printf("%s:%d: %s\n", file, line, message);
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
mac_warning(warning_message);
#else
fputs(warning_message, stderr);
#endif
free(warning_message);
return 1;
}
/*
* To keep track of the state associated with a given input file. The 'next'
* field lets us maintain a stack of input files.
*/
typedef struct input_data {
char *filename; /* where did I come from? */
unsigned int lineno; /* last lineno processed */
char *buf; /* contents of file */
char *point; /* next char to feed to libIDL */
char *max; /* 1 past last char in buf */
struct input_data *next; /* file from which we were included */
} input_data;
/*
* Passed to us by libIDL. Holds global information and the current stack of
* include files.
*/
typedef struct input_callback_state {
struct input_data *input_stack; /* linked list of input_data */
GHashTable *already_included; /* to prevent redundant includes */
IncludePathEntry *include_path; /* search path for included files */
GSList *base_includes; /* to accumulate #includes from *first* file;
* for passing thru TreeState to
* xpidl_header backend. */
} input_callback_state;
static FILE *
fopen_from_includes(const char *filename, const char *mode,
IncludePathEntry *include_path)
{
IncludePathEntry *current_path = include_path;
char *pathname;
FILE *inputfile;
if (!strcmp(filename, "-"))
return stdin;
if (filename[0] != '/') {
while (current_path) {
pathname = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
current_path->directory, filename);
if (!pathname)
return NULL;
inputfile = fopen(pathname, mode);
free(pathname);
if (inputfile)
return inputfile;
current_path = current_path->next;
}
} else {
inputfile = fopen(filename, mode);
if (inputfile)
return inputfile;
}
return NULL;
}
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
extern FILE* mac_fopen(const char* filename, const char *mode);
#endif
static input_data *
new_input_data(const char *filename, IncludePathEntry *include_path)
{
input_data *new_data;
FILE *inputfile;
char *buffer = NULL;
size_t offset = 0;
size_t buffer_size;
#ifdef XP_MAC
size_t i;
#endif
#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
// on Mac, fopen knows how to find files.
inputfile = fopen(filename, "r");
#else
inputfile = fopen_from_includes(filename, "r", include_path);
#endif
if (!inputfile)
return NULL;
/*
* Rather than try to keep track of many different varieties of state
* around the boundaries of a circular buffer, we just read in the entire
* file.
*
* We iteratively grow the buffer here; an alternative would be to use
* stat to find the exact buffer size we need, as xpt_dump does.
*/
for (buffer_size = 8191; ; buffer_size *= 2) {
size_t just_read;
buffer = realloc(buffer, buffer_size + 1); /* +1 for trailing nul */
just_read = fread(buffer + offset, 1, buffer_size - offset, inputfile);
if (ferror(inputfile))
return NULL;
if (just_read < buffer_size - offset || just_read == 0) {
/* Done reading. */
offset += just_read;
break;
}
offset += just_read;
}
fclose(inputfile);
#ifdef XP_MAC
/*
* libIDL doesn't speak '\r' properly - always make sure lines end with
* '\n'.
*/
for (i = 0; i < offset; i++) {
if (buffer[i] == '\r')
buffer[i] = '\n';
}
#endif
new_data = xpidl_malloc(sizeof (struct input_data));
new_data->point = new_data->buf = buffer;
new_data->max = buffer + offset;
*new_data->max = '\0';
new_data->filename = xpidl_strdup(filename);
/* libIDL expects the line number to be that of the *next* line */
new_data->lineno = 2;
new_data->next = NULL;
return new_data;
}
/* process pending raw section */
static int
NextIsRaw(input_data *data, char **startp, int *lenp)
{
char *end, *start;
/*
* XXXmccabe still needed: an in_raw flag to handle the case where we're in
* a raw block, but haven't managed to copy it all to xpidl. This will
* happen when we have a raw block larger than
* IDL_input_data->fill.max_size (currently 8192.)
*/
if (!(data->point[0] == '%' && data->point[1] == '{'))
return 0;
start = *startp = data->point;
end = NULL;
while (start < data->max && (end = strstr(start, "%}"))) {
if (end[-1] == '\r' ||
end[-1] == '\n')
break;
start = end + 1;
}
if (end && start < data->max) {
*lenp = end - data->point + 2;
return 1;
} else {
const char *filename;
int lineno;
IDL_file_get(&filename, &lineno);
msg_callback(IDL_ERROR, 0, lineno, filename,
"unterminated %{ block");
return -1;
}
}
/* process pending comment */
static int
NextIsComment(input_data *data, char **startp, int *lenp)
{
char *end;
if (!(data->point[0] == '/' && data->point[1] == '*'))
return 0;
end = strstr(data->point, "*/");
*lenp = 0;
if (end) {
int skippedLines = 0;
char *tempPoint;
/* get current lineno */
IDL_file_get(NULL,(int *)&data->lineno);
/* get line count */
for (tempPoint = data->point; tempPoint < end; tempPoint++) {
if (*tempPoint == '\n')
skippedLines++;
}
data->lineno += skippedLines;
IDL_file_set(data->filename, (int)data->lineno);
*startp = end + 2;
/* If it's a ** comment, tell libIDL about it. */
if (data->point[2] == '*') {
/* hack termination. +2 to get past '*' '/' */
char t = *(end + 2);
*(end + 2) = '\0';
IDL_queue_new_ident_comment(data->point);
*(end + 2) = t;
}
data->point = *startp; /* XXXmccabe move this out of function? */
return 1;
} else {
const char *filename;
int lineno;
IDL_file_get(&filename, &lineno);
msg_callback(IDL_ERROR, 0, lineno, filename,
"unterminated comment");
return -1;
}
}
static int
NextIsInclude(input_callback_state *callback_state, char **startp,
int *lenp)
{
input_data *data = callback_state->input_stack;
input_data *new_data;
char *filename, *start, *end;
const char *scratch;
/* process the #include that we're in now */
if (strncmp(data->point, "#include \"", 10)) {
return 0;
}
filename = data->point + 10; /* skip #include " */
assert(filename < data->max);
end = filename;
while (end < data->max) {
if (*end == '\"' || *end == '\n' || *end == '\r')
break;
end++;
}
if (*end != '\"') {
/*
* Didn't find end of include file. Scan 'til next whitespace to find
* some reasonable approximation of the filename, and use it to report
* an error.
*/
end = filename;
while (end < data->max) {
if (*end == ' ' || *end == '\n' || *end == '\r' || *end == '\t')
break;
end++;
}
*end = '\0';
/* make sure we have accurate line info */
IDL_file_get(&scratch, (int *)&data->lineno);
fprintf(stderr,
"%s:%d: didn't find end of quoted include name \"%s\n",
scratch, data->lineno, filename);
return -1;
}
*end = '\0';
*startp = end + 1;
if (data->next == NULL) {
/*
* If we're in the initial file, add this filename to the list
* of filenames to be turned into #include "filename.h"
* directives in xpidl_header.c. We do it here rather than in the
* block below so it still gets added to the list even if it's
* already been recursively included from some other file.
*/
char *filename_cp = xpidl_strdup(filename);
/* note that g_slist_append accepts and likes null as list-start. */
callback_state->base_includes =
g_slist_append(callback_state->base_includes, filename_cp);
}
/* store offset for when we pop, or if we skip this one */
data->point = *startp;
if (!g_hash_table_lookup(callback_state->already_included, filename)) {
filename = xpidl_strdup(filename);
g_hash_table_insert(callback_state->already_included,
filename, (void *)TRUE);
new_data = new_input_data(filename, callback_state->include_path);
if (!new_data) {
char *error_message;
IDL_file_get(&scratch, (int *)&data->lineno);
error_message =
g_strdup_printf("can't open included file %s for reading\n",
filename);
msg_callback(IDL_ERROR, 0,
data->lineno, scratch, error_message);
free(error_message);
return -1;
}
new_data->next = data;
/* tell libIDL to exclude this IDL from the toplevel tree */
IDL_inhibit_push();
IDL_file_get(&scratch, (int *)&data->lineno);
callback_state->input_stack = new_data;
IDL_file_set(new_data->filename, (int)new_data->lineno);
}
*lenp = 0; /* this is magic, see the comment below */
return 1;
}
static void
FindSpecial(input_data *data, char **startp, int *lenp)
{
char *point = data->point;
/* magic sequences are:
* "%{" raw block
* "/\*" comment
* "#include \"" include
* The first and last want a newline [\r\n] before, or the start of the
* file.
*/
#define LINE_START(data, point) (point == data->buf || \
(point > data->point && \
(point[-1] == '\r' || point[-1] == '\n')))
while (point < data->max) {
if (point[0] == '/' && point[1] == '*')
break;
if (LINE_START(data, point)) {
if (point[0] == '%' && point[1] == '{')
break;
if (point[0] == '#' && !strncmp(point + 1, "include \"", 9))
break;
}
point++;
}
#undef LINE_START
*startp = data->point;
*lenp = point - data->point;
}
/* set this with a debugger to see exactly what libIDL sees */
static FILE *tracefile;
static int
input_callback(IDL_input_reason reason, union IDL_input_data *cb_data,
gpointer user_data)
{
input_callback_state *callback_state = user_data;
input_data *data = callback_state->input_stack;
input_data *new_data = NULL;
unsigned int len, copy;
int rv;
char *start;
switch(reason) {
case IDL_INPUT_REASON_INIT:
if (data == NULL || data->next == NULL) {
/*
* This is the first file being processed. As it's the target
* file, we only look for it in the first entry in the include
* path, which we assume to be the current directory.
*/
/* XXXmccabe proper assumption? Do we handle files in other
directories? */
IncludePathEntry first_entry;
first_entry.directory = callback_state->include_path->directory;
first_entry.next = NULL;
new_data = new_input_data(cb_data->init.filename,
&first_entry);
} else {
new_data = new_input_data(cb_data->init.filename,
callback_state->include_path);
}
if (!new_data)
return -1;
IDL_file_set(new_data->filename, (int)new_data->lineno);
callback_state->input_stack = new_data;
return 0;
case IDL_INPUT_REASON_FILL:
start = NULL;
len = 0;
while (data->point >= data->max) {
if (!data->next)
return 0;
/* Current file is done; revert to including file */
callback_state->input_stack = data->next;
free(data->filename);
free(data->buf);
free(data);
data = callback_state->input_stack;
IDL_file_set(data->filename, (int)data->lineno);
IDL_inhibit_pop();
}
/*
* Now we scan for sequences which require special attention:
* \n#include begins an include statement
* \n%{ begins a raw-source block
* /\* begins a comment
*
* We used to be fancier here, so make sure that we sent the most
* data possible at any given time. To that end, we skipped over
* \n%{ raw \n%} blocks and then _continued_ the search for special
* sequences like \n#include or /\* comments .
*
* It was really ugly, though -- liberal use of goto! lots of implicit
* state! what fun! -- so now we just do this:
*
* if (special at start) {
* process that special -
* - raw: send it to libIDL, and don't look inside for specials
* - comments: adjust point and start over
* - includes: push new input_data struct for included file, and
* start over
* } else {
* scan for next special
* send data up to that special to libIDL
* }
*
* If len is set to zero, it is a sentinel value indicating we a comment
* or include was found, and parsing should start over.
*
* XXX const string foo = "/\*" will just screw us horribly.
* Hm but. We could treat strings as we treat raw blocks, eh?
*/
/*
* Order is important, so that you can have /\* comments and
* #includes within raw sections, and so that you can comment out
* #includes.
*/
rv = NextIsRaw(data, &start, (int *)&len);
if (rv == -1) return -1;
if (!rv) {
/*
* When NextIsComment succeeds, it returns a 0 len (requesting a
* restart) and adjusts data->point to pick up after the comment.
*/
rv = NextIsComment(data, &start, (int *)&len);
if (rv == -1) return -1;
if (!rv) {
/*
* NextIsInclude might push a new input_data struct; if so, it
* will return a 0 len, letting the callback pick up the new
* file the next time around.
*/
rv = NextIsInclude(callback_state, &start, (int *)&len);
if (rv == -1) return -1;
if (!rv)
FindSpecial(data, &start, (int *)&len);
}
}
if (len == 0) {
/*
* len == 0 is a sentinel value that means we found a comment or
* include. If we found a comment, point has been adjusted to
* point past the comment. If we found an include, a new input_data
* has been pushed. In both cases, calling the input_callback again
* will pick up the new state.
*/
return input_callback(reason, cb_data, user_data);
}
copy = MIN(len, (unsigned int) cb_data->fill.max_size);
memcpy(cb_data->fill.buffer, start, copy);
data->point = start + copy;
if (tracefile)
fwrite(cb_data->fill.buffer, copy, 1, tracefile);
return copy;
case IDL_INPUT_REASON_ABORT:
case IDL_INPUT_REASON_FINISH:
while (data != NULL) {
input_data *next;
next = data->next;
free(data->filename);
free(data->buf);
free(data);
data = next;
}
return 0;
default:
g_error("unknown input reason %d!", reason);
return -1;
}
}
static void
free_ghash_key(gpointer key, gpointer value, gpointer user_data)
{
/* We're only storing TRUE in the value... */
free(key);
}
static void
free_gslist_data(gpointer data, gpointer user_data)
{
free(data);
}
/* Pick up unlink. */
#ifdef XP_UNIX
#include <unistd.h>
#elif XP_WIN
/* We get it from stdio.h. */
#endif
int
xpidl_process_idl(char *filename, IncludePathEntry *include_path,
char *file_basename, ModeData *mode)
{
char *tmp, *outname, *mode_outname = NULL;
IDL_tree top;
TreeState state;
int rv;
input_callback_state callback_state;
gboolean ok;
backend *emitter;
callback_state.input_stack = NULL;
callback_state.base_includes = NULL;
callback_state.include_path = include_path;
callback_state.already_included = g_hash_table_new(g_str_hash, g_str_equal);
if (!callback_state.already_included) {
fprintf(stderr, "failed to create hashtable. out of memory?\n");
return 0;
}
state.basename = xpidl_strdup(filename);
/* if basename has an .extension, truncate it. */
tmp = strrchr(state.basename, '.');
if (tmp)
*tmp = '\0';
if (!file_basename)
outname = xpidl_strdup(state.basename);
else
outname = xpidl_strdup(file_basename);
/* so we don't include it again! */
g_hash_table_insert(callback_state.already_included,
xpidl_strdup(filename), (void *)TRUE);
rv = IDL_parse_filename_with_input(filename, input_callback, &callback_state,
msg_callback, &top,
&state.ns,
IDLF_IGNORE_FORWARDS |
IDLF_XPIDL,
enable_warnings ? IDL_WARNING1 :
IDL_ERROR);
if (rv != IDL_SUCCESS) {
if (rv == -1) {
g_warning("Parse of %s failed: %s", filename, g_strerror(errno));
} else {
g_warning("Parse of %s failed", filename);
}
return 0;
}
state.basename = xpidl_strdup(filename);
tmp = strrchr(state.basename, '.');
if (tmp)
*tmp = '\0';
/* so xpidl_header.c can use it to generate a list of #include directives */
state.base_includes = callback_state.base_includes;
emitter = mode->factory();
state.dispatch = emitter->dispatch_table;
if (strcmp(outname, "-")) {
// don't open file if the mode is "java"
if (strcmp(mode->mode, "java")) {
const char *fopen_mode;
mode_outname = g_strdup_printf("%s.%s", outname, mode->suffix);
/* Use binary write for typelib mode */
fopen_mode = (strcmp(mode->mode, "typelib")) ? "w" : "wb";
state.file = fopen(mode_outname, fopen_mode);
if (!state.file) {
perror("error opening output file");
return 0;
}
} else {
state.file = NULL;
}
} else {
state.file = stdout;
}
state.tree = top;
if (emitter->emit_prolog)
emitter->emit_prolog(&state);
ok = xpidl_process_node(&state);
if (emitter->emit_epilog)
emitter->emit_epilog(&state);
if (state.file && state.file != stdout)
fclose(state.file);
free(state.basename);
free(outname);
g_hash_table_foreach(callback_state.already_included, free_ghash_key, NULL);
g_hash_table_destroy(callback_state.already_included);
g_slist_foreach(callback_state.base_includes, free_gslist_data, NULL);
IDL_ns_free(state.ns);
IDL_tree_free(top);
if (mode_outname != NULL) {
/*
* Delete partial output file on failure. (Mac does this in the plugin
* driver code, if the compiler returns failure.)
*/
#if defined(XP_UNIX) || defined(XP_WIN)
if (!ok)
unlink(mode_outname);
#endif
free(mode_outname);
}
return ok;
}
/*
* Our own version of IDL_tree_warning, which we use when IDL_tree_warning
* would crash on us.
*/
void
xpidl_tree_warning(IDL_tree p, int level, const char *fmt, ...)
{
va_list ap;
char *msg, *file;
int lineno;
/* XXX need to check against __IDL_max_msg_level, no accessor */
va_start(ap, fmt);
msg = g_strdup_vprintf(fmt, ap);
if (p) {
file = p->_file;
lineno = p->_line;
} else {
file = NULL;
lineno = 0;
}
/* call our message callback, like IDL_tree_warning would */
msg_callback(level, 0, lineno, file, msg);
va_end(ap);
}

View File

@@ -1,926 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Michael Allen (michael.allen@sun.com)
* Frank Mitchell (frank.mitchell@sun.com)
*/
/*
* Generate Java interfaces from XPIDL.
*/
#include "xpidl.h"
#include <ctype.h>
#include <glib.h>
/*
* Write a one-line comment containing IDL
* source decompiled from state->tree.
*/
void write_comment(TreeState *state);
char* subscriptIdentifier(TreeState *state, char *str);
char* subscriptMethodName(TreeState *state, char *str);
struct java_priv_data {
GHashTable *typedefTable;
GHashTable *keywords;
FILE *file;
};
char* javaKeywords[] = {
"abstract", "default", "if" , "private" , "this" ,
"boolean" , "do" , "implements", "protected" , "throw" ,
"break" , "double" , "import", "public" , "throws" ,
"byte" , "else" , "instanceof", "return" , "transient",
"case" , "extends", "int" , "short" , "try" ,
"catch" , "final" , "interface" , "static" , "void" ,
"char" , "finally", "long" , "strictfp" , "volatile" ,
"class" , "float" , "native" , "super" , "while" ,
"const" , "for" , "new" , "switch" ,
"continue", "goto" , "package" , "synchronized"};
#define TYPEDEFS(state) (((struct java_priv_data *)state->priv)->typedefTable)
#define KEYWORDS(state) (((struct java_priv_data *)state->priv)->keywords)
#define FILENAME(state) (((struct java_priv_data *)state->priv)->file)
static gboolean
write_classname_iid_define(FILE *file, const char *className)
{
const char *iidName;
if (className[0] == 'n' && className[1] == 's') {
/* backcompat naming styles */
fputs("NS_", file);
iidName = className + 2;
} else {
iidName = className;
}
while (*iidName) {
fputc(toupper(*iidName++), file);
}
fputs("_IID", file);
return TRUE;
}
static gboolean
java_prolog(TreeState *state)
{
int len, i;
state->priv = calloc(1, sizeof(struct java_priv_data));
if (!state->priv)
return FALSE;
TYPEDEFS(state) = 0;
TYPEDEFS(state) = g_hash_table_new(g_str_hash, g_str_equal);
if (!TYPEDEFS(state)) {
/* XXX report error */
free(state->priv);
return FALSE;
}
KEYWORDS(state) = 0;
KEYWORDS(state) = g_hash_table_new(g_str_hash, g_str_equal);
if (!KEYWORDS(state)) {
g_hash_table_destroy(TYPEDEFS(state));
free(state->priv);
return FALSE;
}
len = sizeof(javaKeywords)/sizeof(*javaKeywords);
for (i = 0; i < len; i++) {
g_hash_table_insert(KEYWORDS(state),
javaKeywords[i],
javaKeywords[i]);
}
return TRUE;
}
static gboolean
java_epilog(TreeState *state)
{
/* points to other elements of the tree, so just destroy the table */
g_hash_table_destroy(TYPEDEFS(state));
g_hash_table_destroy(KEYWORDS(state));
free(state->priv);
state->priv = NULL;
return TRUE;
}
static gboolean
forward_declaration(TreeState *state)
{
/*
* Java doesn't need forward declarations unless the declared
* class resides in a different package.
*/
#if 0
IDL_tree iface = state->tree;
const char *className = IDL_IDENT(IDL_FORWARD_DCL(iface).ident).str;
const char *pkgName = "org.mozilla.xpcom";
if (!className)
return FALSE;
/* XXX: Get package name and compare */
fprintf(FILENAME(state), "import %s.%s;\n", pkgName, className);
#endif
return TRUE;
}
static gboolean
interface_declaration(TreeState *state)
{
char *outname;
IDL_tree interface = state->tree;
IDL_tree iterator = NULL;
char *interface_name =
subscriptIdentifier(state, IDL_IDENT(IDL_INTERFACE(interface).ident).str);
const char *iid = NULL;
GSList *doc_comments = IDL_IDENT(IDL_INTERFACE(interface).ident).comments;
char *prefix = IDL_GENTREE(IDL_NS(state->ns).current)._cur_prefix;
/*
* Each interface decl is a single file
*/
outname = g_strdup_printf("%s.%s", interface_name, "java");
FILENAME(state) = fopen(outname, "w");
if (!FILENAME(state)) {
perror("error opening output file");
return FALSE;
}
fputs("/*\n * ************* DO NOT EDIT THIS FILE ***********\n",
FILENAME(state));
fprintf(FILENAME(state),
" *\n * This file was automatically generated from %s.idl.\n",
state->basename);
fputs(" */\n\n", FILENAME(state));
if (prefix) {
if (strlen(prefix))
fprintf(FILENAME(state), "\npackage %s;\n\n", prefix);
fputs("import org.mozilla.xpcom.*;\n\n", FILENAME(state));
} else {
fputs("\npackage org.mozilla.xpcom;\n\n", FILENAME(state));
}
/*
* Write out JavaDoc comment
*/
fprintf(FILENAME(state), "\n/**\n * Interface %s\n", interface_name);
#ifndef LIBIDL_MAJOR_VERSION
iid = IDL_tree_property_get(interface, "uuid");
#else
iid = IDL_tree_property_get(IDL_INTERFACE(interface).ident, "uuid");
#endif
if (iid != NULL) {
fprintf(FILENAME(state), " *\n * IID: 0x%s\n */\n\n", iid);
} else {
fputs(" */\n\n", FILENAME(state));
}
if (doc_comments != NULL)
printlist(FILENAME(state), doc_comments);
/*
* Write "public interface <foo>"
*/
fprintf(FILENAME(state), "public interface %s ", interface_name);
/*
* Check for inheritence, and iterator over the inherited names,
* if any.
*/
if ((iterator = IDL_INTERFACE(interface).inheritance_spec)) {
fputs("extends ", FILENAME(state));
do {
fprintf(FILENAME(state), "%s",
IDL_IDENT(IDL_LIST(iterator).data).str);
if (IDL_LIST(iterator).next) {
fputs(", ", FILENAME(state));
}
} while ((iterator = IDL_LIST(iterator).next));
}
fputs("\n{\n", FILENAME(state));
if (iid) {
/*
* Write interface constants for IID
*/
/* fputs(" public static final String ", FILENAME(state)); */
/* XXX s.b just "IID" ? */
/* if (!write_classname_iid_define(FILENAME(state), interface_name)) { */
/* return FALSE; */
/* } */
/* fprintf(FILENAME(state), "_STRING =\n \"%s\";\n\n", iid); */
/* fputs(" public static final nsID ", FILENAME(state)); */
/* XXX s.b just "IID" ? */
/* if (!write_classname_iid_define(FILENAME(state), interface_name)) { */
/* return FALSE; */
/* } */
/* fprintf(FILENAME(state), " =\n new nsID(\"%s\");\n\n", iid); */
fprintf(FILENAME(state), " public static final String IID =\n \"%s\";\n\n", iid);
}
/*
* Advance the state of the tree, go on to process more
*/
state->tree = IDL_INTERFACE(interface).body;
if (state->tree && !xpidl_process_node(state)) {
return FALSE;
}
fputs("\n}\n", FILENAME(state));
fprintf(FILENAME(state), "\n/*\n * end\n */\n");
fclose(FILENAME(state));
free(outname);
return TRUE;
}
static gboolean
process_list(TreeState *state)
{
IDL_tree iter;
gint type;
for (iter = state->tree; iter; iter = IDL_LIST(iter).next) {
state->tree = IDL_LIST(iter).data;
type = IDL_NODE_TYPE(state->tree);
if (!xpidl_process_node(state))
return FALSE;
}
return TRUE;
}
static gboolean
xpcom_to_java_type (TreeState *state)
{
if (!state->tree) {
fputs("Object", FILENAME(state));
return TRUE;
}
switch(IDL_NODE_TYPE(state->tree)) {
case IDLN_TYPE_INTEGER: {
switch(IDL_TYPE_INTEGER(state->tree).f_type) {
case IDL_INTEGER_TYPE_SHORT:
fputs("short", FILENAME(state));
break;
case IDL_INTEGER_TYPE_LONG:
fputs("int", FILENAME(state));
break;
case IDL_INTEGER_TYPE_LONGLONG:
fputs("long", FILENAME(state));
break;
default:
g_error(" Unknown integer type: %d\n",
IDL_TYPE_INTEGER(state->tree).f_type);
return FALSE;
}
break;
}
case IDLN_TYPE_CHAR:
case IDLN_TYPE_WIDE_CHAR:
fputs("char", FILENAME(state));
break;
case IDLN_TYPE_WIDE_STRING:
case IDLN_TYPE_STRING:
fputs("String", FILENAME(state));
break;
case IDLN_TYPE_BOOLEAN:
fputs("boolean", FILENAME(state));
break;
case IDLN_TYPE_OCTET:
fputs("byte", FILENAME(state));
break;
case IDLN_TYPE_FLOAT:
switch(IDL_TYPE_FLOAT(state->tree).f_type) {
case IDL_FLOAT_TYPE_FLOAT:
fputs("float", FILENAME(state));
break;
case IDL_FLOAT_TYPE_DOUBLE:
fputs("double", FILENAME(state));
break;
default:
g_error(" Unknown floating point typ: %d\n",
IDL_NODE_TYPE(state->tree));
break;
}
break;
case IDLN_IDENT:
if (IDL_NODE_UP(state->tree) &&
IDL_NODE_TYPE(IDL_NODE_UP(state->tree)) == IDLN_NATIVE) {
const char *user_type = IDL_NATIVE(IDL_NODE_UP(state->tree)).user_type;
const char *ident_str = IDL_IDENT(IDL_NATIVE(IDL_NODE_UP(state->tree)).ident).str;
if (strcmp(user_type, "void") == 0) {
fputs("Object", FILENAME(state));
}
else if (strcmp(user_type, "nsID") == 0 ||
strcmp(user_type, "nsIID") == 0 ||
strcmp(user_type, "nsCID") == 0) {
/* XXX: s.b test for "iid" attribute */
/* XXX: special class for nsIDs */
fputs("IID", FILENAME(state));
}
else {
/* XXX: special class for opaque types */
fputs("OpaqueValue", FILENAME(state));
}
} else {
const char *ident_str = IDL_IDENT(state->tree).str;
/* XXX: big kludge; s.b. way to match to typedefs */
if (strcmp(ident_str, "PRInt8") == 0 ||
strcmp(ident_str, "PRUint8") == 0) {
fputs("byte", FILENAME(state));
}
else if (strcmp(ident_str, "PRInt16") == 0 ||
strcmp(ident_str, "PRUint16") == 0) {
fputs("short", FILENAME(state));
}
else if (strcmp(ident_str, "PRInt32") == 0 ||
strcmp(ident_str, "PRUint32") == 0) {
fputs("int", FILENAME(state));
}
else if (strcmp(ident_str, "PRInt64") == 0 ||
strcmp(ident_str, "PRUint64") == 0) {
fputs("long", FILENAME(state));
}
else if (strcmp(ident_str, "PRBool") == 0) {
fputs("boolean", FILENAME(state));
}
else if (strcmp(ident_str, "nsrefcnt") == 0) {
fputs("int", FILENAME(state));
}
else {
IDL_tree real_type =
g_hash_table_lookup(TYPEDEFS(state), ident_str);
if (real_type) {
IDL_tree orig_tree = state->tree;
state->tree = real_type;
xpcom_to_java_type(state);
state->tree = orig_tree;
}
else {
fputs(subscriptIdentifier(state, ident_str), FILENAME(state));
}
}
}
break;
case IDLN_TYPE_ENUM:
case IDLN_TYPE_OBJECT:
default:
g_error(" Unknown type: %d\n",
IDL_TYPE_FLOAT(state->tree).f_type);
break;
}
return TRUE;
}
static gboolean
xpcom_to_java_param(TreeState *state)
{
IDL_tree param = state->tree;
state->tree = IDL_PARAM_DCL(param).param_type_spec;
/*
* Put in type of parameter
*/
if (!xpcom_to_java_type(state)) {
return FALSE;
}
/*
* If the parameter is out or inout, make it a Java array of the
* appropriate type
*/
if (IDL_PARAM_DCL(param).attr != IDL_PARAM_IN) {
fputs("[]", FILENAME(state));
}
/*
* If the parameter is an array make it a Java array
*/
if (IDL_tree_property_get(IDL_PARAM_DCL(param).simple_declarator, "array"))
fputs("[]", FILENAME(state));
/*
* Put in name of parameter
*/
fputc(' ', FILENAME(state));
fputs(subscriptIdentifier(state,
IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str),
FILENAME(state));
return TRUE;
}
static gboolean
type_declaration(TreeState *state)
{
/*
* Unlike C, Java has no type declaration directive.
* Instead, we record the mapping, and look up the actual type
* when needed.
*/
IDL_tree type = IDL_TYPE_DCL(state->tree).type_spec;
IDL_tree dcls = IDL_TYPE_DCL(state->tree).dcls;
/* XXX: check for illegal types */
g_hash_table_insert(TYPEDEFS(state),
IDL_IDENT(IDL_LIST(dcls).data).str,
type);
return TRUE;
}
static gboolean
method_declaration(TreeState *state)
{
/* IDL_tree method_tree = state->tree; */
const char* array = NULL;
GSList *doc_comments = IDL_IDENT(IDL_OP_DCL(state->tree).ident).comments;
struct _IDL_OP_DCL *method = &IDL_OP_DCL(state->tree);
gboolean method_notxpcom =
(IDL_tree_property_get(method->ident, "notxpcom") != NULL);
gboolean method_noscript =
(IDL_tree_property_get(method->ident, "noscript") != NULL);
IDL_tree iterator = NULL;
IDL_tree retval_param = NULL;
char *method_name =
g_strdup_printf("%c%s",
tolower(IDL_IDENT(method->ident).str[0]),
IDL_IDENT(method->ident).str + 1);
if (doc_comments != NULL) {
fputs(" ", FILENAME(state));
printlist(FILENAME(state), doc_comments);
}
if (method_notxpcom || method_noscript)
return TRUE;
if (!verify_method_declaration(state->tree))
return FALSE;
fputc('\n', FILENAME(state));
write_comment(state);
/*
* Write beginning of method declaration
*/
fputs(" ", FILENAME(state));
if (!method_noscript) {
/* Nonscriptable methods become package-protected */
fputs("public ", FILENAME(state));
}
/*
* Write return type
* Unlike C++ headers, Java interfaces return the declared
* return value; an exception indicates XPCOM method failure.
*/
if (method_notxpcom || method->op_type_spec) {
state->tree = method->op_type_spec;
if (!xpcom_to_java_type(state)) {
return FALSE;
}
} else {
/* Check for retval attribute */
for (iterator = method->parameter_dcls; iterator != NULL;
iterator = IDL_LIST(iterator).next) {
IDL_tree original_tree = state->tree;
state->tree = IDL_LIST(iterator).data;
if (IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
"retval")) {
retval_param = iterator;
array =
IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
"array");
state->tree = IDL_PARAM_DCL(state->tree).param_type_spec;
/*
* Put in type of parameter
*/
if (!xpcom_to_java_type(state)) {
return FALSE;
}
if (array)
fputs("[]", FILENAME(state));
}
state->tree = original_tree;
}
if (retval_param == NULL) {
fputs("void", FILENAME(state));
}
}
/*
* Write method name
*/
fprintf(FILENAME(state), " %s(", subscriptMethodName(state, method_name));
free(method_name);
/*
* Write parameters
*/
for (iterator = method->parameter_dcls; iterator != NULL;
iterator = IDL_LIST(iterator).next) {
/* Skip "retval" */
if (iterator == retval_param) {
continue;
}
if (iterator != method->parameter_dcls) {
fputs(", ", FILENAME(state));
}
state->tree = IDL_LIST(iterator).data;
if (!xpcom_to_java_param(state)) {
return FALSE;
}
}
fputs(")", FILENAME(state));
if (method->raises_expr) {
IDL_tree iter = method->raises_expr;
IDL_tree dataNode = IDL_LIST(iter).data;
fputs(" throws ", FILENAME(state));
fputs(IDL_IDENT(dataNode).str, FILENAME(state));
iter = IDL_LIST(iter).next;
while (iter) {
dataNode = IDL_LIST(iter).data;
fprintf(FILENAME(state), ", %s", IDL_IDENT(dataNode).str);
iter = IDL_LIST(iter).next;
}
}
fputs(";\n", FILENAME(state));
return TRUE;
}
static gboolean
constant_declaration(TreeState *state)
{
/*
* The C++ header XPIDL module only allows for shorts and longs (ints)
* to be constants, so we will follow the same convention
*/
struct _IDL_CONST_DCL *declaration = &IDL_CONST_DCL(state->tree);
const char *name = IDL_IDENT(declaration->ident).str;
gboolean success;
gboolean isshort = FALSE;
GSList *doc_comments = IDL_IDENT(declaration->ident).comments;
/*
* Consts must be in an interface
*/
if (!IDL_NODE_UP(IDL_NODE_UP(state->tree)) ||
IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(state->tree))) !=
IDLN_INTERFACE) {
XPIDL_WARNING((state->tree, IDL_WARNING1,
"A constant \"%s\" was declared outside an interface."
" It was ignored.", name));
return TRUE;
}
/*
* Make sure this is a numeric short or long constant.
*/
success = (IDLN_TYPE_INTEGER == IDL_NODE_TYPE(declaration->const_type));
if (success) {
/*
* We aren't successful yet, we know it's an integer, but what *kind*
* of integer?
*/
switch(IDL_TYPE_INTEGER(declaration->const_type).f_type) {
case IDL_INTEGER_TYPE_SHORT:
/*
* We're OK
*/
isshort = TRUE;
break;
case IDL_INTEGER_TYPE_LONG:
/*
* We're OK
*/
break;
default:
/*
* Whoops, it's some other kind of number
*/
success = FALSE;
}
} else {
IDL_tree_error(state->tree,
"const declaration \'%s\' must be of type short or long",
name);
return FALSE;
}
if (doc_comments != NULL) {
fputs(" ", FILENAME(state));
printlist(FILENAME(state), doc_comments);
}
if (success) {
fputc('\n', FILENAME(state));
write_comment(state);
fprintf(FILENAME(state), " public static final %s %s = %d;\n",
(isshort ? "short" : "int"),
subscriptIdentifier(state, name),
(int) IDL_INTEGER(declaration->const_exp).value);
} else {
XPIDL_WARNING((state->tree, IDL_WARNING1,
"A constant \"%s\" was not of type short or long."
" It was ignored.", name));
}
return TRUE;
}
#define ATTR_IDENT(tree) (IDL_IDENT(IDL_LIST(IDL_ATTR_DCL((tree)).simple_declarations).data))
#define ATTR_PROPS(tree) (IDL_LIST(IDL_ATTR_DCL((tree)).simple_declarations).data)
#define ATTR_TYPE_DECL(tree) (IDL_ATTR_DCL((tree)).param_type_spec)
static gboolean
attribute_declaration(TreeState *state)
{
gboolean read_only = IDL_ATTR_DCL(state->tree).f_readonly;
char *attribute_name = ATTR_IDENT(state->tree).str;
gboolean method_noscript =
(IDL_tree_property_get(ATTR_PROPS(state->tree), "noscript") != NULL);
GSList *doc_comments =
IDL_IDENT(IDL_LIST(IDL_ATTR_DCL
(state->tree).simple_declarations).data).comments;
if (doc_comments != NULL) {
fputs(" ", FILENAME(state));
printlist(FILENAME(state), doc_comments);
}
#if 0
/*
* Disabled here because I can't verify this check against possible
* users of the java xpidl backend.
*/
if (!verify_attribute_declaration(state->tree))
return FALSE;
#endif
/* Comment */
fputc('\n', FILENAME(state));
write_comment(state);
state->tree = ATTR_TYPE_DECL(state->tree);
/*
* Write access permission ("public" unless nonscriptable)
*/
fputs(" ", FILENAME(state));
if (!method_noscript) {
fputs("public ", FILENAME(state));
}
/*
* Write the proper Java return value for the get operation
*/
if (!xpcom_to_java_type(state)) {
return FALSE;
}
/*
* Write the name of the accessor ("get") method.
*/
fprintf(FILENAME(state), " get%c%s();\n",
toupper(attribute_name[0]), attribute_name + 1);
if (!read_only) {
/* Nonscriptable methods become package-protected */
fputs(" ", FILENAME(state));
if (!method_noscript) {
fputs("public ", FILENAME(state));
}
/*
* Write attribute access method name and return type
*/
fprintf(FILENAME(state), "void set%c%s(",
toupper(attribute_name[0]),
attribute_name+1);
/*
* Write the proper Java type for the set operation
*/
if (!xpcom_to_java_type(state)) {
return FALSE;
}
/*
* Write the name of the formal parameter.
*/
fputs(" value);\n", FILENAME(state));
}
return TRUE;
}
static gboolean
enum_declaration(TreeState *state)
{
XPIDL_WARNING((state->tree, IDL_WARNING1,
"enums not supported, enum \'%s\' ignored",
IDL_IDENT(IDL_TYPE_ENUM(state->tree).ident).str));
return TRUE;
}
static gboolean
module_declaration(TreeState *state)
{
// do not use modules yet
#if 0
IDL_tree scope =
IDL_tree_get_scope(state->tree);
char *module_name = IDL_IDENT(IDL_MODULE(state->tree).ident).str;
printf("\n\n I've go a module declared!!! \n name: %s \n\n",
module_name);
fprintf(FILENAME(state), "package %s;\n", module_name);
state->tree = IDL_MODULE(state->tree).definition_list;
type = IDL_NODE_TYPE(state->tree);
printf("\n type: %d\n\n", type);
return process_list(state);
#endif
return TRUE;
}
backend *
xpidl_java_dispatch(void)
{
static backend result;
static nodeHandler table[IDLN_LAST];
static gboolean initialized = FALSE;
result.emit_prolog = java_prolog;
result.emit_epilog = java_epilog;
if (!initialized) {
table[IDLN_INTERFACE] = interface_declaration;
table[IDLN_LIST] = process_list;
table[IDLN_OP_DCL] = method_declaration;
table[IDLN_ATTR_DCL] = attribute_declaration;
table[IDLN_CONST_DCL] = constant_declaration;
table[IDLN_TYPE_DCL] = type_declaration;
/* table[IDLN_FORWARD_DCL] = forward_declaration;*/
table[IDLN_TYPE_ENUM] = enum_declaration;
/* table[IDLN_MODULE] = module_declaration;*/
initialized = TRUE;
}
result.dispatch_table = table;
return &result;
}
void write_comment(TreeState *state)
{
fprintf(FILENAME(state), " /* ");
IDL_tree_to_IDL(state->tree, state->ns, FILENAME(state),
IDLF_OUTPUT_NO_NEWLINES |
IDLF_OUTPUT_NO_QUALIFY_IDENTS |
IDLF_OUTPUT_PROPERTIES);
fputs(" */\n", FILENAME(state));
}
char* subscriptMethodName(TreeState *state, char *str)
{
char *sstr = NULL;
if (strcmp(str, "toString") &&
strcmp(str, "clone") &&
strcmp(str, "finalize") &&
strcmp(str, "equals") &&
strcmp(str, "hashCode")) {
return subscriptIdentifier(state, str);
}
sstr = g_strdup_printf("%s_", str);
return sstr;
}
char* subscriptIdentifier(TreeState *state, char *str)
{
char *sstr = NULL;
char *keyword = g_hash_table_lookup(KEYWORDS(state), str);
if (keyword) {
sstr = g_strdup_printf("%s_", keyword);
return sstr;
}
return str;
}

View File

@@ -1,34 +0,0 @@
#!nmake
#
# 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):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ..\..
DIRS= \
connect \
xpcom \
java \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,64 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH = ../../../
topsrcdir = $(DEPTH)
srcdir = .
VPATH = .
LIBRARY_NAME = bcxpcomstubs
MODULE = bcxpcomstubs
IS_COMPONENT = 1
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
CXXFLAGS += -I$(CONNECT_SRC)/public
CPPSRCS = \
bcXPCOMProxy.cpp \
bcXPCOMStub.cpp \
bcXPCOMMarshalToolkit.cpp \
bcXPCOMStubsAndProxies.cpp \
bcXPCOMLog.cpp \
$(NULL)
EXPORTS = \
bcXPCOMStubsAndProxies.h
LIBS = \
-lxpcom \
-lxptinfo \
$(NSPR_LIBS) \
$(NULL)
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -1,32 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcXPCOMLog.h"
PRLogModuleInfo * bcXPCOMLog::log = NULL;
PRLogModuleInfo * bcXPCOMLog::GetLog() {
if (log == NULL) {
log = PR_NewLogModule(LOG_MODULE);
}
return log;
}

View File

@@ -1,31 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "prlog.h"
#define LOG_MODULE "blackConnect"
class bcXPCOMLog {
public:
static PRLogModuleInfo *GetLog();
private:
static PRLogModuleInfo *log;
};

View File

@@ -1,478 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIAllocator.h"
#include "nsCOMPtr.h"
#include "bcXPCOMMarshalToolkit.h"
#include "nsIServiceManager.h"
#include "bcORB.h"
#include "bcXPCOMStubsAndProxies.h"
#include "nsCRT.h"
#include "bcXPCOMLog.h"
static NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterfaceInfo *_interfaceInfo,
nsXPTCMiniVariant* _params, bcIORB *_orb) {
callSide = onClient;
orb = _orb;
methodIndex = _methodIndex;
interfaceInfo = _interfaceInfo;
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo**) &info); // These do *not* make copies ***explicit bending of XPCOM rules***
PRUint32 paramCount = info->GetParamCount();
if (paramCount > 0) {
params = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
if (params == nsnull) {
return;
}
for (unsigned int i = 0; i < paramCount; i++) {
(params)[i].Init(_params[i], info->GetParam(i).GetType(),0);
if (info->GetParam(i).IsOut()) {
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
params[i].ptr = params[i].val.p = _params[i].val.p;
}
}
}
}
bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterfaceInfo *_interfaceInfo,
nsXPTCVariant* _params, bcIORB *_orb) {
callSide = onServer;
orb = _orb;
methodIndex = _methodIndex;
interfaceInfo = _interfaceInfo;
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo **)&info); // These do *not* make copies ***explicit bending of XPCOM rules***
params = _params;
}
bcXPCOMMarshalToolkit::~bcXPCOMMarshalToolkit() {
//nb
}
class xpAllocator : public bcIAllocator { //nb make is smarter. It should deallocate allocated memory.
public:
xpAllocator(nsIAllocator *_allocator) {
allocator = _allocator;
}
virtual ~xpAllocator() {}
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;
};
nsresult bcXPCOMMarshalToolkit::Marshal(bcIMarshaler *m) {
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--bcXPCOMMarshalToolkit::Marshal\n"));
nsresult r = NS_OK;
PRUint32 paramCount = info->GetParamCount();
for (unsigned int i = 0; (i < paramCount) && NS_SUCCEEDED(r); i++) {
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
if ((callSide == onClient && !param.IsIn())
|| (callSide == onServer && !param.IsOut())) {
continue;
}
nsXPTCVariant *value = & params[i];
void *data;
data = (isOut) ? value->val.p : value;
r = MarshalElement(m,data,&param,param.GetType().TagPart(),i);
}
return r;
}
nsresult bcXPCOMMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
bcIAllocator * allocator = new xpAllocator(nsAllocator::GetGlobalAllocator());
PRUint32 paramCount = info->GetParamCount();
for (unsigned int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
nsXPTCMiniVariant tmpValue = params[i]; //we need to set value for client side
nsXPTCMiniVariant * value;
value = &tmpValue;
nsXPTType type = param.GetType();
if (callSide == onServer
&& param.IsOut()) { //we need to allocate memory for out parametr
value->val.p = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is good
params[i].Init(*value,type,0);
params[i].ptr = params[i].val.p = value->val.p;
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
}
#if 0
if (callSide == onClient
&& param.GetType().IsPointer()
&& ! param.GetType().IsReference()
) {
allocator->Free(params[i].val.p);
}
#endif
if ( (callSide == onServer && !param.IsIn()
|| (callSide == onClient && !param.IsOut()))){
continue;
}
void *data = (isOut) ? value->val.p : value;
UnMarshalElement(data, um, &param, param.GetType().TagPart(),allocator);
params[i].Init(*value,type,0);
}
return NS_OK;
}
nsresult bcXPCOMMarshalToolkit::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, &param, 0, &argnum);
} else {
rv = _interfaceInfo->GetLengthIsArgNumberForParam(_methodIndex, &param, 0, &argnum);
}
if(NS_FAILED(rv)) {
return PR_FALSE;
}
const nsXPTParamInfo& arg_param = method->GetParam(argnum);
const nsXPTType& arg_type = arg_param.GetType();
// XXX require PRUint32 here - need to require in compiler too!
if(arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_U32)
return PR_FALSE;
if(arg_param.IsOut())
*result = *(PRUint32*)nativeParams[argnum].val.p;
else
*result = nativeParams[argnum].val.u32;
return PR_TRUE;
}
bcXPType bcXPCOMMarshalToolkit::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;
}
}
nsresult bcXPCOMMarshalToolkit::MarshalElement(bcIMarshaler *m, void *data, nsXPTParamInfo * param,
uint8 type, uint8 ind) {
PRLogModuleInfo * log = bcXPCOMLog::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--bcXPCOMMarshalToolkit::MarshalElement ind=%d\n",ind));
nsresult r = NS_OK;
switch(type) {
case nsXPTType::T_IID :
data = *(char**)data;
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
m->WriteSimple(data, XPTType2bcXPType(type));
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);
PR_LOG(log, PR_LOG_DEBUG,("--[c++] bcXPCOMMarshalToolkit::MarshalElement T_WCHAR_STR length=%d\n",length));
length *= 2;
length +=2;
for (int i = 0; i < length && type == nsXPTType::T_WCHAR_STR; i++) {
char c = ((char*)data)[i];
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] bcXPCOMMarshalToolkit::MarshalElement T_WCHAR_STR [%d] = %d %c\n",i,c,c));
}
} else {
length = nsCRT::strlen((const char*)data);
length+=1;
}
m->WriteString(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;
}
}
PR_LOG(log, PR_LOG_DEBUG, ("--[c++]XPCOMMarshallToolkit INTERFACE iid=%s\n",iid->ToString()));
bcOID oid = 0;
if (*(char**)data != NULL) {
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
return r;
}
xpcomStubsAndProxies->GetOID(*(nsISupports**)data, orb,&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: //nb array of interfaces [to do]
{
PRUint32 arraySize;
if (!GetArraySizeFromParam(interfaceInfo,info, *param,methodIndex,
ind,params,GET_LENGTH, &arraySize)) {
return NS_ERROR_FAILURE;
}
if (type == nsXPTType::T_ARRAY) {
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
m->WriteSimple(&arraySize,bc_T_U32);
PRInt16 elemSize = GetSimpleSize(datumType);
char *current = *(char**)data;
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize) {
MarshalElement(m,current,param,datumType.TagPart(),0);
}
} 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:
return NS_ERROR_FAILURE;
}
return r;
}
nsresult
bcXPCOMMarshalToolkit::UnMarshalElement(void *data, bcIUnMarshaler *um, nsXPTParamInfo * param, uint8 type, bcIAllocator * allocator) {
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
nsresult r = NS_OK;
switch(type) {
case nsXPTType::T_IID :
*(char**)data = (char*)new nsIID(); //nb memory leak. how are we going to release it
data = *(char**)data;
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
um->ReadSimple(data,XPTType2bcXPType(type));
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] bcXPCOMMarshalToolkit::UnMarshalElement %c\n",*(char*)data));
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
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];
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] bcXPCOMMarshalToolkit::UnMarshalElement T_WCHAR_STR [%d] = %d %c\n",i,(int)c,c));
}
}
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] we have an interface\n"));
bcOID oid;
um->ReadSimple(&oid,XPTType2bcXPType(type));
PR_LOG(log, PR_LOG_DEBUG, ("%d oid\n",(int) oid));
nsIID iid;
um->ReadSimple(&iid,bc_T_IID);
nsISupports *proxy = NULL;
if (oid != 0) {
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
return r; //nb am I sure about that?
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies,
kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
xpcomStubsAndProxies->GetProxy(oid, iid, orb,&proxy);
}
*(nsISupports**)data = proxy;
break;
}
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
PRUint32 arraySize;
PRInt16 elemSize = GetSimpleSize(datumType);
um->ReadSimple(&arraySize,bc_T_U32);
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) {
UnMarshalElement(current, um, param, datumType.TagPart(), allocator);
}
break;
}
default:
return NS_ERROR_FAILURE;
}
return r;
}
PRInt16 bcXPCOMMarshalToolkit::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;
}

Some files were not shown because too many files have changed in this diff Show More