Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
d0fa033729 This commit was manufactured by cvs2svn to create tag 'BLACKCONNECT-M4'.
git-svn-id: svn://10.0.0.236/tags/BLACKCONNECT-M4@98776 18797224-902f-48f8-a5cc-f745e15eee43
2001-07-06 02:56:42 +00:00
347 changed files with 29108 additions and 281 deletions

View File

@@ -0,0 +1,39 @@
#!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= \
java/xpidl \
connect \
xpcom \
wrappers \
java \
# xpcom/test/ \
$(NULL)
include $(topsrcdir)/config/rules.mk

78
mozilla/java/xpcom/README Normal file
View File

@@ -0,0 +1,78 @@
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

@@ -0,0 +1,34 @@
#!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

@@ -0,0 +1,33 @@
#!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

@@ -0,0 +1,80 @@
/* -*- 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

@@ -0,0 +1,35 @@
/* -*- 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

@@ -0,0 +1,70 @@
/* -*- 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;
};
#define INVOKE_ADDREF(oid,iid,orb) \
do { \
bcICall * call; \
call = GET_ADDREF_CALL((oid),(iid),(orb)); \
(orb)->SendReceive(call); \
delete call; \
} while(0)
#define INVOKE_RELEASE(oid,iid,orb) \
do { \
bcICall * call; \
call = GET_RELEASE_CALL((oid),(iid),(orb)); \
(orb)->SendReceive(call); \
delete call; \
} while(0)
#define GET_ADDREF_CALL(oid,iid,orb) \
(orb)->CreateCall((iid),(oid),1)
#define GET_RELEASE_CALL(oid,iid,orb) \
(orb)->CreateCall((iid),(oid),2)
#endif

View File

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

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

View File

@@ -0,0 +1,32 @@
/* -*- 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;
virtual void SetORB(bcIORB *orb) = 0;
virtual void SetOID(bcOID oid) = 0;
};
#endif

View File

@@ -0,0 +1,29 @@
/* -*- 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

@@ -0,0 +1,35 @@
/* -*- 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

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

@@ -0,0 +1,35 @@
/* -*- 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

@@ -0,0 +1,78 @@
/* -*- 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

@@ -0,0 +1,51 @@
/* -*- 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

@@ -0,0 +1,55 @@
/* -*- 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;
}
if (!ptr) {
size = 0;
}
out->write((const char*)&size, sizeof(size_t));
if (size) {
out->write((const char*)ptr,type2size(bc_T_CHAR)*size);
}
return 0;
}

View File

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

@@ -0,0 +1,120 @@
/* -*- 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"
#include "nsHashtable.h"
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);
}
};
ORB::ORB() {
currentID = 1;
stubs = new nsHashtable(256,PR_TRUE);
}
ORB::~ORB() {
delete stubs;
}
bcOID ORB::RegisterStub(bcIStub *stub) {
bcOID oid = GenerateOID();
RegisterStubWithOID(stub,&oid);
return oid;
}
void ORB::RegisterStubWithOID(bcIStub *stub, bcOID *oid) {
stubs->Put(new bcOIDKey(*oid),stub);
stub->SetORB(this);
stub->SetOID(*oid);
return;
}
void ORB::UnregisterStub(bcOID oid) {
bcOIDKey *oidKey = new bcOIDKey(oid);
stubs->Remove(oidKey);
delete oidKey;
return;
}
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) {
bcOIDKey *key = new bcOIDKey(*oid);
void *tmp = stubs->Get(key);
delete key;
return (bcIStub*)tmp;
}
struct bcOIDstruct {
PRUint16 high;
PRUint16 low;
};
bcOID ORB::GenerateOID() {
bcOID oid;
bcOIDstruct oidStruct;
oidStruct.low = currentID++;
oidStruct.high = ((PRUint32)this);
oid = *(bcOID*)&oidStruct;
return oid;
}

View File

@@ -0,0 +1,43 @@
/* -*- 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"
class nsHashtable;
class ORB : public bcIORB {
public:
ORB();
virtual ~ORB();
virtual bcOID RegisterStub(bcIStub *stub);
virtual void RegisterStubWithOID(bcIStub *stub, bcOID *oid);
virtual void UnregisterStub(bcOID oid);
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID);
virtual int SendReceive(bcICall *);
private:
bcIStub * GetStub(bcOID *);
bcOID GenerateOID();
nsHashtable *stubs;
unsigned int currentID;
};
#endif

View File

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

View File

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

@@ -0,0 +1,62 @@
#!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

@@ -0,0 +1,72 @@
/* -*- 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

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

View File

@@ -0,0 +1,76 @@
#!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 = \
bcORBComponent.cpp \
../src/Allocator.cpp \
../src/Call.cpp \
../src/Marshaler.cpp \
../src/ORB.cpp \
../src/UnMarshaler.cpp \
../src/util.cpp \
$(NULL)
EXPORTS = \
bcIORBComponent.h \
bcORBComponentCID.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
ifeq ($(CCC),CC)
CXXFLAGS += -library=iostream
endif
DSO_LDOPTS += \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

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

View File

@@ -0,0 +1,76 @@
/* -*- 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 "bcORBComponent.h"
#include "../src/ORB.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(bcORBComponent);
static nsModuleComponentInfo components[] =
{
{
"Black Connect ORB Component",
BC_ORBCOMPONENT_CID,
BC_ORBCOMPONENT_ContractID,
bcORBComponentConstructor
}
};
NS_IMPL_NSGETMODULE("BlackConnectORB component",components);
NS_IMPL_THREADSAFE_ISUPPORTS(bcORBComponent,NS_GET_IID(bcORBComponent));
bcORBComponent::bcORBComponent() :
orb(0)
{
NS_INIT_REFCNT();
}
bcORBComponent::~bcORBComponent() {
if (orb) {
delete orb; //nb should we destroy it?
}
}
NS_IMETHODIMP bcORBComponent::GetORB(bcIORB **_orb) {
if (!_orb) {
printf("--bcORBComponent::GetORB\n");
return NS_ERROR_NULL_POINTER;
}
if (!orb) {
orb = new ORB();
}
*_orb = orb;
return NS_OK;
}

View File

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

View File

@@ -0,0 +1,35 @@
/* -*- 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 __bcORBComponentCID_h__
#define __bcORBComponentCID_h__
#define BC_ORBCOMPONENT_ContractID "@mozilla.org/blackwood/blackconnect/orbcomponent;1"
/*ffa0d768-1dd1-11b2-8bf2-ab56f26ea844*/
#define BC_ORBCOMPONENT_CID \
{ 0xffa0d768, 0x1dd1, 0x11b2, \
{0x8b, 0xf2, 0xab, 0x56, 0xf2, 0x6e, 0xa8, 0x44 }}
#endif

View File

@@ -0,0 +1,48 @@
#!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)\bcORBComponent.obj \
$(NULL)
EXPORTS = \
bcIORBComponent.h \
bcORBComponentCID.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"

8
mozilla/java/xpcom/env.bat Executable file
View File

@@ -0,0 +1,8 @@
rem * set JDKHOME to your jdk directory
set JDKHOME=c:\java\jdk1.3
rem * set DIST to your mozilla binaries
set DIST=c:\ws\mozilla\mozilla\dist\win32_d.obj
set PATH=%path%;%jdkhome%\jre\bin;%jdkhome%\jre\bin\classic;%dist%\bin\components
set CLASSPATH=%claspath%;%dist%\..\classes;.

View File

@@ -0,0 +1,32 @@
#!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 jni loader import classes components
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,43 @@
#!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

@@ -0,0 +1,40 @@
#
# 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

@@ -0,0 +1,42 @@
/* -*- 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 CID extends ID {
public CID(String cid) {
super(cid);
}
public boolean equals(Object obj) {
if (! (obj instanceof CID)) {
return false;
}
boolean res = id.equals(((CID)obj).id);
return res;
}
protected String getPrefixForToString() {
return "org.mozilla.xpcom.CID@";
}
}

View File

@@ -0,0 +1,64 @@
/* -*- 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

@@ -0,0 +1,46 @@
/* -*- 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;
}
public static nsIXPIDLServiceManager getServiceManager() {
return serviceMgr;
}
public static void setServiceManager(nsIXPIDLServiceManager mgr) {
serviceMgr = mgr;
}
public static native void initXPCOM();
private static nsIComponentManager componentMgr = null;
private static nsIXPIDLServiceManager serviceMgr = null;
static {
System.loadLibrary("blackconnectjni");
}
};

View File

@@ -0,0 +1,28 @@
/* -*- 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

@@ -0,0 +1,53 @@
/* -*- 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 ID {
public ID(String id) {
this.id = ((id == null) ? "" : id).toLowerCase();;
}
public boolean equals(Object obj) {
if (! (obj instanceof IID)) {
return false;
}
boolean res = id.equals(((ID)obj).id);
return res;
}
public String toString() {
return getPrefixForToString()+id;
}
public int hashCode() {
int h = id.hashCode();
return h;
}
public String getString() {
return id;
}
protected String id;
protected String getPrefixForToString() {
return "org.mozilla.xpcom.ID@";
}
}

View File

@@ -0,0 +1,42 @@
/* -*- 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 extends ID {
public IID(String iid) {
super(iid);
}
public boolean equals(Object obj) {
if (! (obj instanceof IID)) {
return false;
}
boolean res = id.equals(((IID)obj).id);
return res;
}
protected String getPrefixForToString() {
return "org.mozilla.xpcom.IID@";
}
}

View File

@@ -0,0 +1,244 @@
/* -*- 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 iidTmp = cl.getField(IID_STRING).get(cl);
if (iidTmp instanceof IID) {
IID iid = (IID)iidTmp;
// if this iface hasn't been registered, yet
if (interfaces.get(iid) == null) {
String[] methodNames = Utilities.getInterfaceMethodNames(iid.getString());
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

@@ -0,0 +1,92 @@
/* -*- 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.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

@@ -0,0 +1,70 @@
/* -*- 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;
Utilities.callMethod(oid, null, iid, orb, null); //it is hack method = null means addref
}
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")) {
Utilities.callMethod(oid, method, iid, orb, args);
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

@@ -0,0 +1,98 @@
/* -*- 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+" object "+obj);
try {
if (method != null) {
Class[] parameterTypes = method.getParameterTypes();
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) {
if (!objectArrayClass.equals(parameterTypes[i])
&& parameterTypes[i].isArray()) {
Class componentType = parameterTypes[i].getComponentType();
args[i] = java.lang.reflect.Array.newInstance(componentType,1);
}
}
/* another hack. Some IIDs are CIDs. We can not get this data from typelib. Here we can.
*/
if (args[i] instanceof IID
&& !parameterTypes[i].equals(IID.class)) {
IID iidTmp = (IID)args[i];
CID cidTmp = new CID(iidTmp.getString());
args[i] = cidTmp;
}
}
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;
if (method == null) {
mid = 1; //it is hack method = null means addref
} else if ("finalize".equals(method.getName())) {
mid = 2;
} else {
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

@@ -0,0 +1,29 @@
/* -*- 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 XPCOMException extends RuntimeException {
public XPCOMException(int xpcomCode) {
super(" [nsresult=" + xpcomCode + "]");
}
}

View File

@@ -0,0 +1,62 @@
#!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
include ../config/rules.mk
COMPONENT=bcBlackConnectInit
CLASSES=bcIBlackConnectInit.class bcBlackConnectInit.class
DSO_LDOPTS += \
$(XPCOM_LIBS) \
$(NULL)
$(COMPONENT).jar.comp: manifest $(CLASSES)
$(JDKHOME)/bin/jar cvfm $(COMPONENT).jar.comp manifest *.class
.java.class:
$(JDKHOME)/bin/javac -classpath .:../classes:$(DIST)/classes $<
bcIBlackConnectInit.java : bcIBlackConnectInit.idl
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

@@ -0,0 +1,67 @@
/* -*- 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"
#include "nsIXPIDLServiceManager.h"
#include "bcIXPCOMWrappers.h"
#include "bcXPCOMWrappersCID.h"
NS_DEFINE_CID(kXPCOMWrappers,BC_XPCOMWRAPPERS_CID);
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr,
nsIFile *location,
nsIModule** result) //I am using it for initialization only
{
static int counter = 0; //we do not need to call it on unload time;
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;
nsIXPIDLServiceManager *sm;
r = NS_GetGlobalComponentManager(&cm);
if (NS_SUCCEEDED(r)) {
blackConnectInit->InitComponentManager(cm);
}
NS_WITH_SERVICE(bcIXPCOMWrappers,xpcomWrappers,kXPCOMWrappers,&r);
nsIID * wrapperIID;
if (NS_SUCCEEDED(r)) {
r = xpcomWrappers->GetWrapper((nsISupports*)NULL,NS_GET_IID(nsIServiceManager),&wrapperIID, (nsISupports**)&sm);
if (NS_SUCCEEDED(r)) {
printf("--[c++]about to call blackConnectInit->InitServiceManager(sm)\n");
blackConnectInit->InitServiceManager(sm);
}
}
}
}
return NS_ERROR_FAILURE;
}

View File

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

View File

@@ -0,0 +1,52 @@
/* -*- 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 ( nsISupports.IID.equals(iid)
|| bcIBlackConnectInit.IID.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);");
}
/* void initServiceManager (in nsIXPIDLServiceManager sm); */
public void initServiceManager(nsIXPIDLServiceManager sm) {
Components.setServiceManager(sm);
Debug.log("Components.setServiceManager(sm);");
}
static {
InterfaceRegistry.register(nsIComponentManager.class);
InterfaceRegistry.register(nsIXPIDLServiceManager.class);
}
}

View File

@@ -0,0 +1,39 @@
/* -*- Mode: IDL; 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 "nsISupports.idl"
#include "nsIComponentManager.idl"
#include "nsIXPIDLServiceManager.idl"
#pragma prefix
[scriptable, uuid(d4867a7e-1dd1-11b2-a009-b111ab5d7639)]
interface bcIBlackConnectInit : nsISupports
{
void initComponentManager(in nsIComponentManager cm);
void initServiceManager(in nsIXPIDLServiceManager sm);
};

View File

@@ -0,0 +1,69 @@
#!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=bcBlackConnectInit
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>
include ..\config\rules.mak
COMPONENT=bcBlackConnectInit
CLASSES=bcIBlackConnectInit.class bcBlackConnectInit.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;$(DEPTH)\dist\classes $<
bcIBlackConnectInit.java : bcIBlackConnectInit.idl
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 -f "$(DIST)\bin\components\$(DLLNAME).dll"
rm -f "$(DIST)\bin\components\$(COMPONENT).jar.*"
clobber_all:: clobber-java
install:: install-component

View File

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

View File

@@ -0,0 +1,30 @@
#!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>
#
XPIDL_PROG=$(DIST)\bin\xpidl
.SUFFIXES: .java .idl
XPIDL_JAVA=$(JAVAXPIDLSRCS:.idl=.java)
idl2java: $(XPIDL_JAVA)
.idl.java:
$(XPIDL_PROG) -m java -w $(XPIDL_INCLUDES) -I$(DEPTH)\dist\idl\ $<

View File

@@ -0,0 +1,29 @@
#!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>
#
.SUFFIXES: .java .idl
XPIDL_JAVA=$(JAVAXPIDLSRCS:.idl=.java)
XPIDL_PROG=$(DIST)/bin/xpidl
idl2java: $(XPIDL_JAVA)
.idl.java:
$(XPIDL_PROG) -m java -w $(XPIDL_INCLUDES) -I$(DEPTH)/dist/idl/ $<

View File

@@ -0,0 +1,57 @@
#!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 = ../../../..
JAVAXPIDLSRCS = nsISupports.idl \
nsIFile.idl \
nsIEnumerator.idl \
nsIComponentManager.idl \
nsIFactory.idl \
nsISupportsPrimitives.idl \
nsIXPIDLServiceManager.idl \
$(NULL)
include $(DEPTH)/config/rules.mk
include ../config/rules.mk
.SUFFIXES: .idl .java
import: $(JAVAXPIDLSRCS)
$(JAVAXPIDLSRCS) :
cp $(DEPTH)/dist/idl/$(@F) .
#we have to exclude some files from here
#xpidl compiler does not suport typedefs, yet.
#we do not have typedefs in java
#what is the best solution?
#idk@eng.sun.com (04/02/2001)
exclude: idl2java
rm -f nsISupportsPRTime.java
java2class: idl2java
mkdir -p $(DEPTH)/dist/classes
$(JDKHOME)/bin/javac -classpath ".:../classes/:$(CLASSPATH)" -d $(DEPTH)/dist/classes *.java
export:: import idl2java exclude java2class

View File

@@ -0,0 +1,58 @@
#!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 = ..\..\..\..
JAVAXPIDLSRCS = nsISupports.idl \
nsIFile.idl \
nsIEnumerator.idl \
nsIComponentManager.idl \
nsIFactory.idl \
nsISupportsPrimitives.idl \
nsIXPIDLServiceManager.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>
include ..\config\rules.mak
.SUFFIXES: .idl .java
import: $(XPIDLSRCS)
$(JAVAXPIDLSRCS) :
copy $(DEPTH)\dist\idl\$(@F) .
#we have to exclude some files from here
#xpidl compiler does not suport typedefs, yet.
#we do not have typedefs in java
#what is the best solution?
#idk@eng.sun.com (04/02/2001)
exclude:
del nsISupportsPRTime.java
java2class:
if not exist $(DEPTH)\dist\classes mkdir $(DEPTH)\dist\classes
$(JDKHOME)\bin\javac -classpath ".;..\classes\;$(CLASSPATH)" -d $(DEPTH)\dist\classes *.java
export:: import idl2java exclude java2class

View File

@@ -0,0 +1,53 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# 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 = blackconnectjni
CPPSRCS = \
org_mozilla_xpcom_Components.cpp \
$(NULL)
DSO_LDOPTS += \
$(XPCOM_LIBS) \
$(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) $(CXXFLAGS)
include $(topsrcdir)/config/rules.mk
CCC += $(CXXFLAGS) # I want to have $(JDKHOME)/include before $(DIST) include

View File

@@ -0,0 +1,39 @@
#
# 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 Kushnriskiy <idk@eng.sun.com>
MODULE = blackconnectjni
LIBRARY_NAME = blackconnectjni
DEPTH= ..\..\..\..
OBJS = \
.\$(OBJDIR)\org_mozilla_xpcom_Components.obj \
$(NULL)
MAKE_OBJ_TYPE = DLL
DLL = .\$(OBJDIR)\$(LIBRARY_NAME).dll
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
include <$(DEPTH)/config/rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\

View File

@@ -0,0 +1,66 @@
/* -*- 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_Components.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
/*
* Class: org_mozilla_xpcom_Components
* Method: initXPCOM
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_Components_initXPCOM
(JNIEnv *, jclass) {
static int initCounter = 0;
/*
mozilla/embedding/base/nsEmbedAPI.cpp NS_InitEmbedding was used as
prototype
*/
initCounter++;
if (initCounter > 1) {
return;
}
nsresult rv;
nsIServiceManager* servMgr;
rv = NS_InitXPCOM(&servMgr, NULL);
if (NS_FAILED(rv)) {
#ifdef DEBUG_idk
printf("--Components::initXPCOM failed \n");
#endif
return;
}
rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup,
NULL /* default */);
if (NS_FAILED(rv)) {
#ifdef DEBUG_idk
printf("--Components::initXPCOM failed \n");
#endif
return;
}
}

View File

@@ -0,0 +1,23 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_mozilla_xpcom_Components */
#ifndef _Included_org_mozilla_xpcom_Components
#define _Included_org_mozilla_xpcom_Components
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: componentMgr */
/* Inaccessible static: serviceMgr */
/*
* Class: org_mozilla_xpcom_Components
* Method: initXPCOM
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_Components_initXPCOM
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,52 @@
#!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)
DSO_LDOPTS += \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \
$(NULL)
CXXFLAGS += -I$(JDKHOME)/include -I$(JDKHOME)/include/linux $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
ifeq ($(CCC),CC)
CXXFLAGS += -library=iostream
endif
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,99 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIServiceManager.h"
#include "nsCRT.h"
#include "bcJavaComponentFactory.h"
#include "bcIJavaStubsAndProxies.h"
#include "bcJavaStubsAndProxiesCID.h"
#include "bcIXPCOMStubsAndProxies.h"
#include "bcXPCOMStubsAndProxiesCID.h"
#include "bcIORBComponent.h"
#include "bcORBComponentCID.h"
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBComponent,BC_ORBCOMPONENT_CID);
NS_IMPL_THREADSAFE_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(bcIJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance javaStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcIORBComponent, _orb, kORBComponent, &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);
if (NS_FAILED(r)) {
return r;
}
printf("--bcJavaComponentFactory::CreateInstance after GetOID");
nsISupports *proxy;
printf("--[c++]bcJavaComponentFactory::CreateInstance iid:%s\n",iid.ToString());
xpcomStubsAndProxies->GetProxy(oid, iid, orb, &proxy);
if (NS_FAILED(r)) {
return r;
}
*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

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

@@ -0,0 +1,465 @@
/* -*- 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_THREADSAFE_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, const nsModuleComponentInfo *info)
{
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, const nsModuleComponentInfo *info)
{
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_loader[] = {
{ "Java component loader", BC_JAVACOMPONENTLOADER_CID,
BC_JAVACOMPONENTLOADER_ContractID,
bcJavaComponentLoaderConstructor,
RegisterJavaLoader, UnregisterJavaLoader },
};
NS_IMPL_NSGETMODULE("Java component loader", components_loader);

View File

@@ -0,0 +1,67 @@
/* -*- 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;1"
/* 0d6b5198-1dd2-11b2-b2f0-ed49ba755db8 */
#define BC_JAVACOMPONENTLOADER_CID \
{ 0x0d6b5198, 0x1dd2, 0x11b2, \
{0xb2, 0xf0, 0xed, 0x49, 0xba, 0x75, 0x5d, 0xb8 }}
#define JAVACOMPONENTTYPENAME "application/java"
class bcJavaComponentLoader : public nsIComponentLoader {
NS_DECL_ISUPPORTS
NS_DECL_NSICOMPONENTLOADER
bcJavaComponentLoader();
virtual ~bcJavaComponentLoader();
protected:
nsHashtable mModules;
nsCOMPtr<nsIRegistry> mRegistry;
nsCOMPtr<nsIComponentManager> mCompMgr;
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

@@ -0,0 +1,88 @@
/* -*- 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

@@ -0,0 +1,35 @@
/* -*- 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

@@ -0,0 +1,48 @@
#!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

@@ -0,0 +1,39 @@
#!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 \
jni \
import \
classes \
# test \
components \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,108 @@
#!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 = \
bcIJavaStubsAndProxies.h \
bcJavaStubsAndProxiesCID.h \
$(NULL)
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
archExpr = case "`uname -m`" in \
i[3-6]86) \
echo i386 \
;; \
sparc*) \
echo sparc \
;; \
*) \
uname -m \
;; \
esac
endif
ifeq ($(OS_ARCH), SunOS)
JDKINCLUDE += -I$(JDKHOME)/include/solaris
archExpr = uname -p
endif
HOSTTYPE = $(shell $(archExpr))
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)/client \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/native_threads \
-ljvm -lhpi -ljava -lawt \
$(NULL)
DSO_LDOPTS += \
$(XPCOM_LIBS) \
$(NSPR_LIBS) \
$(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
include $(topsrcdir)/config/rules.mk
CCC += $(CXXFLAGS) # I want to have $(JDKHOME)/include before $(DIST) include

View File

@@ -0,0 +1,130 @@
/* -*- 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;
static nsID nullID = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
void bcIIDJava::Init(void) {
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
if (env) {
if (!(iidClass = env->FindClass("org/mozilla/xpcom/IID"))
|| !(iidClass = (jclass) env->NewGlobalRef(iidClass))) {
env->ExceptionDescribe();
Destroy();
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
if (!(iidInitMID = env->GetMethodID(iidClass,"<init>","(Ljava/lang/String;)V"))) {
env->ExceptionDescribe();
Destroy();
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
if (!(getStringMID = env->GetMethodID(iidClass,"getString","()Ljava/lang/String;"))) {
env->ExceptionDescribe();
Destroy();
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
}
}
void bcIIDJava::Destroy() {
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
if (env) {
if (iidClass) {
env->DeleteGlobalRef(iidClass);
iidClass = NULL;
}
}
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
}
jobject bcIIDJava::GetObject(nsIID *iid) {
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
if (!iid
|| !env
|| nullID.Equals(*iid)) {
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
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);
}
jobject ret = env->NewObject(iidClass,iidInitMID,jstr);
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return ret;
}
jclass bcIIDJava::GetClass() {
return iidClass;
}
nsIID bcIIDJava::GetIID(jobject obj) {
nsIID iid;
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
if (env) {
if (!iidClass) {
Init();
}
if (obj != NULL) {
jstring jstr = (jstring)env->CallObjectMethod(obj, getStringMID);
const char * str = NULL;
str = env->GetStringUTFChars(jstr,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jstr,str);
} else {
iid = nullID;
}
}
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return iid;
}

View File

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

@@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIJavaStubsAndProxies_h
#define __bcIJavaStubsAndProxies_h
#include "nsISupports.h"
#include "jni.h"
#include "bcDefs.h"
/* 58034ea6-1dd2-11b2-9b58-8630abb8af47 */
#define BC_JAVASTUBSANDPROXIES_IID \
{0x58034ea6, 0x1dd2, 0x11b2, \
{0x9b, 0x58, 0x86, 0x30, 0xab, 0xb8, 0xaf,0x47}}
class bcIORB;
class bcIStub;
class bcIJavaStubsAndProxies : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(BC_JAVASTUBSANDPROXIES_IID)
NS_IMETHOD GetStub(jobject obj, bcIStub **stub) = 0;
NS_IMETHOD GetOID(char *location, bcOID *) = 0; //load component by location
NS_IMETHOD GetOID(jobject object, bcIORB *orb, bcOID *oid) = 0;
NS_IMETHOD GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy) = 0;
NS_IMETHOD GetInterface(const nsIID &iid, jclass *clazz) = 0;
};
#endif

View File

@@ -0,0 +1,148 @@
/* -*- 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
static int counter = 0;
JNIEnv * bcJavaGlobal::GetJNIEnv(int *detachRequired) {
JNIEnv * env;
int res;
*detachRequired = 1;
if (!jvm) {
StartJVM();
}
if (jvm) {
res = jvm->GetEnv(JNIENV &env, JNI_VERSION_1_2);
if (res == JNI_OK) {
*detachRequired = 0;
} else {
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
#ifdef DEBUG_idk
printf("--bcJavaGlobal::GetJNIEnv ++counter %d\n",++counter);
#endif
}
}
return env;
}
void bcJavaGlobal::ReleaseJNIEnv() {
int res;
if (jvm) {
res = jvm->DetachCurrentThread();
#ifdef DEBUG_idk
printf("--bcJavaGlobal::ReleaseJNIEnv --counter %d\n",--counter);
#endif
}
}
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];
char * classpathEnv = PR_GetEnv("CLASSPATH");
if (classpathEnv != NULL) {
sprintf(classpath, "-Djava.class.path=%s",classpathEnv);
PR_LOG(l,PR_LOG_DEBUG,("--[c++] classpath %s\n",classpath));
options[0].optionString = classpath;
options[1].optionString=""; //-Djava.compiler=NONE";
vm_args.options = options;
vm_args.nOptions = 2;
} else {
vm_args.nOptions = 0;
}
vm_args.version = 0x00010002;
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

@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* 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(int *detachRequired);
static void ReleaseJNIEnv();
static PRLogModuleInfo * GetLog();
private:
static PRLogModuleInfo* log;
static JavaVM *jvm;
static void StartJVM(void);
};
#endif

View File

@@ -0,0 +1,911 @@
/* -*- 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) {
char *str;
um->ReadString(&str,&size,allocator);
if (str != NULL) {
{
for (int i = 0; i < size && type == bc_T_WCHAR_STR; i++) {
char c = str[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*)str);
} else {
size-=2; size/=2;
data = env->NewString((const jchar*)str,size);
}
allocator->Free(str);
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

@@ -0,0 +1,118 @@
/* -*- 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

@@ -0,0 +1,197 @@
/* -*- 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) : orb(NULL) {
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;
}
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
object = env->NewGlobalRef(obj);
refCounter = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
}
bcJavaStub::~bcJavaStub() {
int detachRequired;
JNIEnv *env = bcJavaGlobal::GetJNIEnv(&detachRequired);
env->DeleteGlobalRef(object);
if (orb != NULL) {
orb->UnregisterStub(oid);
}
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
}
void bcJavaStub::SetORB(bcIORB *_orb) {
orb = _orb;
}
void bcJavaStub::SetOID(bcOID _oid) {
oid = _oid;
}
void bcJavaStub::Dispatch(bcICall *call) {
//sigsend(P_PID, getpid(),SIGINT);
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
bcIID iid; bcOID oid; bcMID mid;
jobjectArray args;
call->GetParams(&iid, &oid, &mid);
if (mid == 1) { //AddRef
refCounter++;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
} else if (mid == 2) { //Release
refCounter--;
printf("-java mid==2\n");
if (refCounter <= 0) {
printf("-java delete\n");
delete this;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
}
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
if (!objectClass) {
Init();
if (!objectClass) {
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
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 = env->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args);
nsresult result = NS_OK;
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
result = NS_ERROR_FAILURE;
}
bcIMarshaler * m = call->GetMarshaler();
m->WriteSimple(&result, bc_T_U32);
if (NS_SUCCEEDED(result)) {
mt->Marshal(m, retval);
}
delete m; delete um; delete mt;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
void bcJavaStub::Init() {
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
objectClass = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Object"));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
utilitiesClass = (jclass)env->NewGlobalRef(env->FindClass("org/mozilla/xpcom/Utilities"));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
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();
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
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

@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
* 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) ;
virtual void SetORB(bcIORB *orb);
virtual void SetOID(bcOID oid);
private:
bcIORB *orb;
bcOID oid;
jobject object;
PRUint32 refCounter;
static jclass objectClass;
static jclass utilitiesClass;
static jmethodID callMethodByIndexMID;
void Init();
PRBool HasRetval(PRUint32 paramCount, nsXPTMethodInfo *info);
};
#endif

View File

@@ -0,0 +1,354 @@
/* -*- 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 "bcIORBComponent.h"
#include "bcORBComponentCID.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(kORBComponent,BC_ORBCOMPONENT_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaStubsAndProxies);
static nsModuleComponentInfo components[] =
{
{
"Black Connect Java stubs and proxies",
BC_JAVASTUBSANDPROXIES_CID,
BC_JAVASTUBSANDPROXIES_ContractID,
bcJavaStubsAndProxiesConstructor
}
};
NS_IMPL_NSGETMODULE("BlackConnect Java stubs and proxies",components);
NS_IMPL_THREADSAFE_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();
PR_LOG(bcJavaGlobal::GetLog(),PR_LOG_DEBUG,
("--[c++] bcJavaStubsAndProxies::bcJavaStubsAndProxies\n"));
oid2objectMap = new nsHashtable(256,PR_TRUE);
}
bcJavaStubsAndProxies::~bcJavaStubsAndProxies() {
PR_LOG(bcJavaGlobal::GetLog(),PR_LOG_DEBUG,
("--[c++] bcJavaStubsAndProxies::~bcJavaStubsAndProxies\n"));
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();
}
if (!componentLoader) {
return NS_ERROR_FAILURE;
}
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 {
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
EXCEPTION_CHECKING(env);
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
}
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();
}
if (!componentLoader) {
return NS_ERROR_FAILURE;
}
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
*clazz = (jclass)env->CallStaticObjectMethod(proxyFactory,getInterfaceID, jiid);
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
nsresult rv = NS_OK;
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
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));
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return rv;
}
}
bcIStub *stub = new bcJavaStub(object);
*oid = orb->RegisterStub(stub);
oid2objectMap->Put(new bcOIDKey(*oid),object);
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
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));
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
nsresult result;
if (!componentLoader) {
Init();
}
if (!componentLoader) {
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return NS_ERROR_FAILURE;
}
//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(bcIORBComponent,_orb,kORBComponent,&result);
if (NS_FAILED(result)) {
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID failed\n"));
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return result;
}
bcIORB *orb;
_orb->GetORB(&orb);
*oid = orb->RegisterStub(stub);
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return NS_OK;
}
void bcJavaStubsAndProxies::Init(void) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log, PR_LOG_DEBUG,("--[c++]bcJavaStubsAndProxies::Init\n"));
int detachRequired;
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
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"));
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
componentLoader = (jclass)env->NewGlobalRef(componentLoader);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
proxyFactory = (jclass)env->NewGlobalRef(proxyFactory);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
getInterfaceID = env->GetStaticMethodID(proxyFactory, "getInterface","(Lorg/mozilla/xpcom/IID;)Ljava/lang/Class;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
java_lang_reflect_Proxy = env->FindClass("java/lang/reflect/Proxy");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
getInvocationHandlerID =
env->GetStaticMethodID(java_lang_reflect_Proxy, "getInvocationHandler",
"(Ljava/lang/Object;)Ljava/lang/reflect/InvocationHandler;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
java_lang_reflect_Proxy = (jclass)env->NewGlobalRef(java_lang_reflect_Proxy);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
org_mozilla_xpcom_ProxyHandler = env->FindClass("org/mozilla/xpcom/ProxyHandler");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
org_mozilla_xpcom_ProxyHandler = (jclass)env->NewGlobalRef(org_mozilla_xpcom_ProxyHandler);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
getOIDID = env->GetMethodID(org_mozilla_xpcom_ProxyHandler, "getOID","()J");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
if (detachRequired) {
bcJavaGlobal::ReleaseJNIEnv();
}
return;
}
}

View File

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

@@ -0,0 +1,33 @@
/* -*- 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 __bcJavaStubsAndProxiesCID_h__
#define __bcJavaStubsAndProxiesCID_h__
/* 7cadf6e8-1dd2-11b2-9a6e-b1c37844e004 */
#define BC_JAVASTUBSANDPROXIES_CID \
{0x7cadf6e8, 0x1dd2, 0x11b2, \
{0x9a, 0x6e, 0xb1, 0xc3, 0x78,0x44, 0xe0, 0x04}}
#define BC_JAVASTUBSANDPROXIES_ContractID "@mozilla.org/blackwood/blackconnect/java-stubs-and-proxies;1"
#endif

View File

@@ -0,0 +1,57 @@
#!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 = \
bcIJavaStubsAndProxies.h \
bcJavaStubsAndProxiesCID.h \
$(NULL)
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

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

@@ -0,0 +1,21 @@
/* 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

@@ -0,0 +1,158 @@
/* -*- 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"
static jclass XPCOMExceptionClass = NULL;
static jmethodID XPCOMExceptionInitMID = NULL;
/*
* 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);
if (mid == 2) {
INVOKE_RELEASE(&oid,&iid,orb);
return NULL;
} else if (mid == 1) {
INVOKE_ADDREF(&oid,&iid,orb);
return NULL;
}
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();
nsresult result;
jobject retval;
um->ReadSimple(&result, bc_T_U32);
if (NS_SUCCEEDED(result)) {
mt->UnMarshal(um, &retval);
} else {
if (XPCOMExceptionClass == NULL) {
XPCOMExceptionClass = (jclass) env->FindClass("org/mozilla/xpcom/XPCOMException");
if (!env->ExceptionOccurred()) { // if there is an exception it will be catched in java
XPCOMExceptionClass = (jclass)env->NewGlobalRef(XPCOMExceptionClass);
if (!env->ExceptionOccurred()) {
XPCOMExceptionInitMID = env->GetMethodID(XPCOMExceptionClass,"<init>","(I)V");
if (env->ExceptionOccurred()) {
XPCOMExceptionClass = NULL;
}
}
}
}
if (!env->ExceptionOccurred()) {
jthrowable exception = (jthrowable) env->NewObject(XPCOMExceptionClass, XPCOMExceptionInitMID,(jint)result);
env->Throw(exception);
}
}
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

@@ -0,0 +1,29 @@
/* 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

@@ -0,0 +1,60 @@
#!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
include ../config/rules.mk
DSO_LDOPTS += \
$(XPCOM_LIBS) \
$(NULL)
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
$(JDKHOME)/bin/jar cvfm bcJavaSample.jar.comp manifest *.class
.java.class:
$(JDKHOME)/bin/javac -classpath .:../classes:$(DIST)/classes $<
bcIJavaSample.java : bcIJavaSample.idl
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

@@ -0,0 +1,18 @@
#include "nsISupports.idl"
#include "nsIComponentManager.idl"
#pragma prefix
[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);
void test8(in nsCIDRef cid);
void test9(out nsIIDPtr po);
};

View File

@@ -0,0 +1,279 @@
/* -*- 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"
#include "prthread.h"
#include "prmon.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++) {
char *str = (*valueArray)[i];
printf("--[c++] valueArray[%d]=%s\n",i,(str == NULL) ? "null" : str);
}
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 test8 (in nsCIDRef cid); */
NS_IMETHODIMP bcJavaSample::Test8(const nsCID & cid) {
printf("--[c++]bcJavaSample::Test8 %s\n",cid.ToString());
return NS_OK;
}
/* void test9 (out nsIIDPtr po); */
NS_IMETHODIMP bcJavaSample::Test9(nsIID * *po) {
if (po != NULL) {
printf("--[c++]bcJavaSample::Test9 %s\n", (*po)->ToString());
} else {
printf("--[c++]bcJavaSample::Test9 %s\n", "null");
}
return NS_OK;
}
static bcIJavaSample * javaSample = NULL;
void thread_start( void *arg ) {
printf("--thread_start currentThread=%p\n",PR_GetCurrentThread());
if (javaSample == NULL) {
nsresult r;
r = nsComponentManager::CreateInstance("bcJavaSample",
nsnull,
NS_GET_IID(bcIJavaSample),
(void**)&javaSample);
// } else {
bcIJavaSample *t;
javaSample->Test1((int)PR_GetCurrentThread());
printf("--thread_start after first invocation \n");
javaSample->Test1((int)PR_GetCurrentThread());
printf("--thread_start after second invocation \n");
}
}
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);
#if 1
{
for (int i = 0; i < 1; i++) {
printf("\n--we are creating threads i=%d\n",i);
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
thread_start,
test,
PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD,
PR_JOINABLE_THREAD,
0);
PR_JoinThread(thr);
}
}
return;
#endif
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++) {
char *str = (*valueArray2)[i];
printf("--[c++] valueArray2[%d]=%s\n",i,(str == NULL) ? "null" : str);
}
}
#if 1
{
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";
valueArray[3] = NULL;
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("--[c++]about to test8\n");
test->Test8(NS_GET_IID(bcIJavaSample));
printf("--[c++]end of test8\n");
}
{
nsCID cid = NS_GET_IID(bcIJavaSample);
nsCID *cidParam = &cid;
printf("--[c++]about to test9\n");
test->Test9(&cidParam);
printf("--[c++]end of test9\n");
}
#endif
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

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

View File

@@ -0,0 +1,182 @@
/* -*- 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.*;
import java.lang.reflect.*;
public class bcJavaSample implements bcIJavaSample {
bcIJavaSample object;
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(nsISupports.IID)
|| iid.equals(bcIJavaSample.IID)) {
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");
nsIXPIDLServiceManager sm = Components.getServiceManager();
nsISupports service = sm.getService(new CID("f0032af2-1dd1-11b2-bb75-c242dcb4f47a"), new IID("1f29f516-1dd2-11b2-9751-f129d72134d0"));
System.out.println("--[java]bcJavaSample.test0 current thread "+Thread.currentThread()+"\n");
Thread.dumpStack();
}
public void test1(int l) {
System.out.println("--[java]bcJavaSample.test1 "+l+"\n");
try {
Thread.currentThread().sleep(1000);
} catch (java.lang.InterruptedException e) {
};
}
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);
}
System.out.println("--[java]bcJavaSample.test2 doing threads test\n");
System.out.println("--[java]bcJavaSample.test2 current thread "+Thread.currentThread()+"\n");
Thread.dumpStack();
o.test2(this);
object = o;
new Thread( new Runnable() {
public void run() {
System.out.println("--[java]bcJavaSample.test2 current thread "+Thread.currentThread()+"\n");
object.test2(bcJavaSample.this);
}
}).start();
} 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",null};
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(nsISupportsString.IID);
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;
}
/* void test8 (in nsCIDRef cid); */
public void test8(CID cid) {
System.out.println("--[java]bcJavaSample.test8 "+cid);
}
/* void test9 (out nsIIDPtr po); */
public void test9(IID[] po) {
System.out.println("--[java]bcJavaSample::Test9 "+po[0]);
}
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

@@ -0,0 +1,65 @@
#!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>
include ..\config\rules.mak
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
$(JDKHOME)\bin\jar cvfm bcJavaSample.jar.comp manifest *.class
.java.class:
$(JDKHOME)\bin\javac -classpath .;..\classes;$(DEPTH)\dist\classes $<
bcIJavaSample.java : bcIJavaSample.idl
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 -f "$(DIST)\bin\components\$(DLLNAME).dll"
rm -f "$(DIST)\bin\components\bcJavaSample.jar.*"
clobber_all:: clobber-java
install:: install-component

View File

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

View File

@@ -0,0 +1,74 @@
#
# 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

@@ -0,0 +1,74 @@
#
# 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

@@ -0,0 +1,68 @@
#!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

@@ -0,0 +1,198 @@
/* -*- 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

@@ -0,0 +1,746 @@
/* -*- 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);
}

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