Compare commits
1 Commits
tags/start
...
tags/BLACK
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
654a71e314 |
File diff suppressed because it is too large
Load Diff
@@ -1,282 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
#############################################################################
|
||||
# $Id: BB_main.pl,v 1.1.1.1 2000-10-23 20:08:03 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_main.pl
|
||||
#
|
||||
# This is the main control program for the Burst Billing process
|
||||
# It:
|
||||
# 1) Checks the directory setup and permissions.
|
||||
# 2) Archives the log file for the current project.
|
||||
# 3) Launches the Burst Billing program
|
||||
# 4) Runs the monitor program.
|
||||
#
|
||||
# I broke the burst billing and monitor programs out into seperate programs.
|
||||
# This is to handle the event where the burst billing program die's, aborts,
|
||||
# crashes, or whatever - so the main program can run the monitor program afterwards.
|
||||
# Yeah yeah, the main program might crash too, but what can I do...
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
use strict;
|
||||
|
||||
BEGIN {require '../inc/BB_include.pl';}
|
||||
require "$INC_DIR/BB_lib.pl";
|
||||
|
||||
|
||||
##############
|
||||
# Begin Code #
|
||||
##############
|
||||
|
||||
&init_program();
|
||||
|
||||
&run_burst_billing();
|
||||
|
||||
&run_monitor();
|
||||
|
||||
&cleanup_program();
|
||||
|
||||
|
||||
|
||||
###################
|
||||
# Local Functions #
|
||||
###################
|
||||
|
||||
########################################
|
||||
# init_program
|
||||
#
|
||||
# Does program initializations, such as:
|
||||
# - Checking directory permissions
|
||||
# - Archiving the log file
|
||||
# - Opening the new log file
|
||||
########################################
|
||||
sub init_program
|
||||
{
|
||||
&check_if_running();
|
||||
|
||||
&check_directories();
|
||||
|
||||
&check_files();
|
||||
|
||||
&archive_log_file();
|
||||
|
||||
&open_log_file();
|
||||
|
||||
&write_log_file($START_STAMP, "BB_main.pl started");
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# check_if_running
|
||||
#
|
||||
# Checks to see if another copy of the program is running. This is
|
||||
# indicated by the presence of the $IN_PROGRESS_FILE
|
||||
# If it is, the program aborts.
|
||||
#
|
||||
# If it isn't:
|
||||
# 1) The $IN_PROGRESS_FILE is created.
|
||||
# 2) An END routine which removes the $IN_PROGRESS_FILE is evaled. I need
|
||||
# to eval this AFTER the check for the file, otherwise I will remove
|
||||
# the $IN_PROGRESS_FILE for the other program!
|
||||
# Note that this function is not used for contention issues - I'm
|
||||
# fully of aware of the test-and-set race condition.
|
||||
##########################################################################
|
||||
sub check_if_running
|
||||
{
|
||||
my ($ip_fh);
|
||||
|
||||
if ( -f $IN_PROGRESS_FILE )
|
||||
{
|
||||
print STDERR "Another copy of BB_main.pl is currently running\n",
|
||||
"If this is not the case, please remove the ",
|
||||
"$IN_PROGRESS_FILE file and rerun the program.\n",
|
||||
"Aboring program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
|
||||
$ip_fh = new IO::File ">$IN_PROGRESS_FILE";
|
||||
$ip_fh->close();
|
||||
|
||||
eval 'END { &remove_running_file(); }';
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
# check_directories
|
||||
#
|
||||
# Basic sanity check, to make sure all the directories exist and
|
||||
# are writable by this process
|
||||
################################################################
|
||||
sub check_directories
|
||||
{
|
||||
my ($directory);
|
||||
|
||||
foreach $directory ( $BILLING_HOME, $REPORT_HOME, $LOG_DIR, $LOG_ARCHIVE_DIR,
|
||||
$RRD_DIR, $BIN_DIR, $INC_DIR )
|
||||
{
|
||||
if ( ! -d $directory )
|
||||
{
|
||||
print STDERR "ERROR: $directory is not a directory\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
foreach $directory ( $BILLING_HOME, $REPORT_HOME, $LOG_DIR,
|
||||
$LOG_ARCHIVE_DIR )
|
||||
{
|
||||
if ( ! -w $directory )
|
||||
{
|
||||
print STDERR "ERROR: $directory is not writable\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
# check_files
|
||||
#
|
||||
# Basic sanity check, to make sure all the programs and files exist
|
||||
# before launching sub-process
|
||||
################################################################
|
||||
sub check_files
|
||||
{
|
||||
my ($file);
|
||||
|
||||
foreach $file ( $BURST_ACCOUNTS_FILE )
|
||||
{
|
||||
if ( ! -e $file )
|
||||
{
|
||||
print STDERR "ERROR: $file does not exist\n.",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
elsif ( ! -r $file )
|
||||
{
|
||||
print STDERR "ERROR: $file is not readable.\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
foreach $file ( $BILLING_MODULE, $MONITOR_MODULE )
|
||||
{
|
||||
if ( ! -e "$BIN_DIR/$file" )
|
||||
{
|
||||
print STDERR "ERROR: $BIN_DIR/$file does not exist.\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
if ( (! -r "$BIN_DIR/$file") || (! -x "$BIN_DIR/$file") )
|
||||
{
|
||||
print STDERR "ERROR: $BIN_DIR/$file is not runnable.\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##############################################################
|
||||
# archive_log_file
|
||||
#
|
||||
# This copies the previous log file into the archive directory
|
||||
# and then cleans up the archive directory.
|
||||
##############################################################
|
||||
sub archive_log_file
|
||||
{
|
||||
if ( &archive_file($LOG_DIR, $LOG_FILE, $LOG_ARCHIVE_DIR, $LOG_FILE, 0) != $OKAY )
|
||||
{
|
||||
print STDERR "Error archiving log file\n";
|
||||
}
|
||||
|
||||
&purge_old_archives($LOG_ARCHIVE_DIR, $MAX_LOG_ARCHIVE_FILES, $LOG_FILE);
|
||||
}
|
||||
|
||||
|
||||
#####################################################################
|
||||
# run_boss_loader
|
||||
#
|
||||
# This function executes the burst_billing program
|
||||
# programs, checks the return codes, and handles errors.
|
||||
#####################################################################
|
||||
sub run_burst_billing
|
||||
{
|
||||
my ($retcode);
|
||||
|
||||
&write_log_file($LOG_INFO, "BB_main.pl starting to run $BILLING_MODULE");
|
||||
&close_log_file();
|
||||
|
||||
$retcode = system("$BIN_DIR/$BILLING_MODULE");
|
||||
$retcode >>= 8;
|
||||
|
||||
&open_log_file();
|
||||
&write_log_file($LOG_INFO, "$BILLING_MODULE returned exit code $retcode");
|
||||
|
||||
if ( ($retcode != $OKAY) &&
|
||||
($retcode != $ERROR_WARNING) )
|
||||
{
|
||||
&write_log_file($LOG_ERROR, "$BILLING_MODULE had some sort of error");
|
||||
}
|
||||
|
||||
return($retcode);
|
||||
}
|
||||
|
||||
|
||||
#########################################################################
|
||||
# run_monitor
|
||||
#
|
||||
# Runs the monitor module.
|
||||
#########################################################################
|
||||
sub run_monitor
|
||||
{
|
||||
my ($retcode);
|
||||
|
||||
&write_log_file($LOG_INFO, "BB_main.pl starting to run $MONITOR_MODULE");
|
||||
&close_log_file();
|
||||
|
||||
$retcode = system("$BIN_DIR/$MONITOR_MODULE");
|
||||
$retcode >>= 8;
|
||||
|
||||
&open_log_file();
|
||||
&write_log_file($LOG_INFO, "$MONITOR_MODULE returned exit code $retcode");
|
||||
|
||||
if ( ($retcode != $OKAY) &&
|
||||
($retcode != $ERROR_WARNING) )
|
||||
{
|
||||
&write_log_file($LOG_ERROR, "$MONITOR_MODULE had some sort of error");
|
||||
}
|
||||
|
||||
return($retcode);
|
||||
}
|
||||
|
||||
|
||||
#####################################################
|
||||
# cleanup_program
|
||||
#
|
||||
# Perform final cleanup before the program terminates
|
||||
#####################################################
|
||||
sub cleanup_program
|
||||
{
|
||||
&write_log_file($END_STAMP, "BOSS_main.pl ended");
|
||||
|
||||
&close_log_file();
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# remove_running_file
|
||||
#
|
||||
# Removes the $IN_PROGRESS_FILE, just before the program exits. Note that
|
||||
# this function is called by the END{} routine, which runs just as the
|
||||
# perl interpreter exits. In this way, I don't have to worry about
|
||||
# something die()ing and not cleaning up this file.
|
||||
##########################################################################
|
||||
sub remove_running_file
|
||||
{
|
||||
unlink $IN_PROGRESS_FILE;
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#############################################################################
|
||||
# $Id: BB_monitor.pl,v 1.1.1.1 2000-10-23 20:08:03 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_monitor.pl
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
#
|
||||
# Not using strict so I can play namespace games
|
||||
# Not using warnings because the Mail and Net modules suck.
|
||||
#
|
||||
|
||||
use IO::File;
|
||||
#
|
||||
# I'm not using Mail::Send becuase the current implementation has a bug
|
||||
# with multiple recipients - sent a patch to Graham.
|
||||
#
|
||||
use Mail::Mailer;
|
||||
#
|
||||
# Have to 'use' this here so I can overwrite the
|
||||
# $Net::SMTP::NetConfig{'smtp_hosts'} = [$MAIL_HOST];
|
||||
#
|
||||
use Net::SMTP;
|
||||
|
||||
BEGIN {require '../inc/BB_include.pl';}
|
||||
require "$INC_DIR/BB_lib.pl";
|
||||
|
||||
|
||||
###########
|
||||
# Globals #
|
||||
###########
|
||||
my $errors = 0;
|
||||
my $warnings = 0;
|
||||
|
||||
|
||||
##############
|
||||
# Begin Code #
|
||||
##############
|
||||
|
||||
&init_program();
|
||||
|
||||
&scan_log_file();
|
||||
|
||||
# if ( $errors || $warnings )
|
||||
&send_email();
|
||||
|
||||
exit($OKAY);
|
||||
|
||||
|
||||
###################
|
||||
# Local Functions #
|
||||
###################
|
||||
|
||||
|
||||
#####################################################################
|
||||
# init_program
|
||||
#
|
||||
# Sets the smtp server to use and the mail from address.
|
||||
# Closes STDOUT and STDERR to prevent junk messages from STMP modules
|
||||
#####################################################################
|
||||
sub init_program
|
||||
{
|
||||
#
|
||||
# Set the SMTP server to use.
|
||||
# This is cheating, but it works.
|
||||
#
|
||||
$Net::SMTP::NetConfig{'smtp_hosts'} = $MAIL_HOSTS;
|
||||
|
||||
#
|
||||
# Set the from address
|
||||
#
|
||||
$ENV{'MAILADDRESS'} = $MAIL_FROM;
|
||||
|
||||
#
|
||||
# Unfortunately, the SMTP modules are noisy in the case of errors.
|
||||
#
|
||||
close(STDOUT);
|
||||
close(STDERR);
|
||||
}
|
||||
|
||||
|
||||
###########################################################
|
||||
# scan_log_file
|
||||
#
|
||||
# Records the number of errors and warnings in the log file
|
||||
###########################################################
|
||||
sub scan_log_file
|
||||
{
|
||||
my ($log_fh, $log_line);
|
||||
|
||||
$log_fh = new IO::File "<$LOG_DIR/$LOG_FILE";
|
||||
return if ( ! $log_fh );
|
||||
|
||||
while ( defined($log_line = <$log_fh>) )
|
||||
{
|
||||
$errors++ if ( $log_line =~ /^\s*$LOG_ERROR/o );
|
||||
$warnings++ if ( $log_line =~ /^\s*$LOG_WARNING/o );
|
||||
}
|
||||
|
||||
$log_fh->close();
|
||||
}
|
||||
|
||||
|
||||
#############################
|
||||
# send_email
|
||||
#
|
||||
# Sends out the summary email
|
||||
#############################
|
||||
sub send_email
|
||||
{
|
||||
my ($mailer, $timestamp);
|
||||
my ($log_fh, $log_line);
|
||||
|
||||
$timestamp = &get_time_stamp();
|
||||
|
||||
$mailer = new Mail::Mailer('smtp');
|
||||
if ( ! $mailer )
|
||||
{
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
|
||||
eval {$mailer->open({
|
||||
'To' => $ERROR_MAIL_TO,
|
||||
'Subject' => "Burst Billing summary for $timestamp",
|
||||
});
|
||||
};
|
||||
if ( $@ )
|
||||
{
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
|
||||
print $mailer "Burst Billing summary for $timestamp\n\n";
|
||||
print $mailer "ERRORS: $errors\n";
|
||||
print $mailer "WARNINGS: $warnings\n";
|
||||
|
||||
print $mailer "Contents of log file:\n\n";
|
||||
|
||||
$log_fh = new IO::File "<$LOG_DIR/$LOG_FILE";
|
||||
if ( $log_fh )
|
||||
{
|
||||
while ( defined($log_line = <$log_fh>) )
|
||||
{
|
||||
if ( ($log_line =~ /^\s*$START_STAMP/o) ||
|
||||
($log_line =~ /^\s*$END_STAMP/o) ||
|
||||
($log_line =~ /^\s*$LOG_INFO/o) ||
|
||||
($log_line =~ /^\s*$LOG_WARNING/o) ||
|
||||
($log_line =~ /^\s*$LOG_ERROR/o) ||
|
||||
($log_line eq "\n") )
|
||||
{
|
||||
print $mailer $log_line;
|
||||
}
|
||||
}
|
||||
$log_fh->close();
|
||||
}
|
||||
|
||||
$mailer->close();
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
###########################################################################
|
||||
# $Id: BB_include.pl,v 1.1.1.1 2000-10-23 20:08:18 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_include.pl
|
||||
#
|
||||
# This include file contains global variables used across programs.
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
###########################################################################
|
||||
|
||||
use strict;
|
||||
|
||||
|
||||
######################################################################
|
||||
# Set this variable to 1 only if the failsafe triggers, to temporarily
|
||||
# override it.
|
||||
# TODO: command line switch to over-ride.
|
||||
######################################################################
|
||||
use vars qw{$FAILSAFE_OVERRIDE};
|
||||
$FAILSAFE_OVERRIDE = 0;
|
||||
# $FAILSAFE_OVERRIDE = 1;
|
||||
|
||||
#####################################################################
|
||||
# This controls the maximum number of days we will attempt to recover
|
||||
# data for.
|
||||
#####################################################################
|
||||
use vars qw($MAX_RECOVER_DAYS);
|
||||
$MAX_RECOVER_DAYS = 500;
|
||||
|
||||
|
||||
###############
|
||||
# Directories #
|
||||
###############
|
||||
use vars qw{$BILLING_HOME $RRD_DIR $REPORT_HOME $LOG_DIR $LOG_ARCHIVE_DIR
|
||||
$BIN_DIR $INC_DIR};
|
||||
|
||||
#$BILLING_HOME = "/usr/local/root/apache/cgi-bin/Burstable";
|
||||
$BILLING_HOME = "/home/kevinmc/excite/burst_billing/code";
|
||||
|
||||
$RRD_DIR = "/usr/local/nme/polling/www";
|
||||
|
||||
$REPORT_HOME = "$BILLING_HOME/data";
|
||||
|
||||
$LOG_DIR = "$BILLING_HOME/log";
|
||||
$LOG_ARCHIVE_DIR = "$LOG_DIR/archive";
|
||||
|
||||
$BIN_DIR = "$BILLING_HOME/bin";
|
||||
|
||||
$INC_DIR = "$BILLING_HOME/inc";
|
||||
|
||||
|
||||
##############
|
||||
# File Names #
|
||||
##############
|
||||
use vars qw{$BURST_ACCOUNTS_FILE $LOG_FILE $LAST_RUN_FILE $IN_DATA_FILE $OUT_DATA_FILE
|
||||
$CIRCUIT_HEADER_FILE $IN_PROGRESS_FILE $REPORT_FILE};
|
||||
$BURST_ACCOUNTS_FILE = "$INC_DIR/burst_accounts.txt";
|
||||
|
||||
$LOG_FILE = "log";
|
||||
|
||||
$LAST_RUN_FILE = "lastrun.txt";
|
||||
|
||||
#
|
||||
# Network data is dumped to these files
|
||||
#
|
||||
$IN_DATA_FILE = "in.log";
|
||||
$OUT_DATA_FILE = "out.log";
|
||||
|
||||
#
|
||||
# This contains information about the circuit
|
||||
#
|
||||
$CIRCUIT_HEADER_FILE = "header.txt";
|
||||
|
||||
#
|
||||
# This file is used to mark when this program is running. We don't
|
||||
# want to allow to loads to take place at the same time
|
||||
#
|
||||
$IN_PROGRESS_FILE = "$BILLING_HOME/.running";
|
||||
|
||||
#
|
||||
# The monthly 95/5 report
|
||||
#
|
||||
$REPORT_FILE = "95_5_report.xls";
|
||||
|
||||
|
||||
############
|
||||
# Programs #
|
||||
############
|
||||
use vars qw{$BILLING_MODULE $MONITOR_MODULE};
|
||||
$BILLING_MODULE = "BB_billing.pl";
|
||||
$MONITOR_MODULE = "BB_monitor.pl";
|
||||
|
||||
|
||||
##################
|
||||
# Log File Codes #
|
||||
##################
|
||||
use vars qw{$START_STAMP $END_STAMP $LOG_NOTE $LOG_INFO $LOG_WARNING
|
||||
$LOG_ERROR};
|
||||
$START_STAMP = "START_STAMP";
|
||||
$END_STAMP = "END_STAMP";
|
||||
$LOG_NOTE = "NOTE";
|
||||
#
|
||||
# Info error messages get included in the monitor email. Note messages don't
|
||||
#
|
||||
$LOG_INFO = "INFO";
|
||||
$LOG_WARNING = "WARNING";
|
||||
$LOG_ERROR = "ERROR";
|
||||
|
||||
|
||||
#################################################
|
||||
# Number of archives to keep for each directory #
|
||||
#################################################
|
||||
use vars qw{$MAX_LOG_ARCHIVE_FILES};
|
||||
$MAX_LOG_ARCHIVE_FILES = 10000;
|
||||
|
||||
|
||||
###############
|
||||
# Error Codes #
|
||||
###############
|
||||
use vars qw{$OKAY $ERROR_WARNING $ERROR_CRITICAL};
|
||||
$OKAY = 0;
|
||||
$ERROR_WARNING = 1;
|
||||
$ERROR_CRITICAL = 2;
|
||||
|
||||
|
||||
#################
|
||||
# Email Setting #
|
||||
#################
|
||||
use vars qw{$MAIL_HOSTS $MAIL_FROM $ERROR_MAIL_TO $REPORT_MAIL_TO};
|
||||
$MAIL_HOSTS = ['localhost',
|
||||
'mail.excitehome.net'];
|
||||
$MAIL_FROM = 'burstbilling@excitehome.net';
|
||||
$ERROR_MAIL_TO = ['mccarthy@excitehome.net',
|
||||
'tunacat@yahoo.com',
|
||||
# 'michael@excitehome.net',
|
||||
];
|
||||
|
||||
# $REPORT_MAIL_TO = 'burstbilling@excitehome.net';
|
||||
$REPORT_MAIL_TO = 'mccarthy@excitehome.net';
|
||||
|
||||
|
||||
#####################
|
||||
# Data Error Checking
|
||||
#####################
|
||||
use vars qw{$MAX_ZERO_DATA_PERCENT $MAX_NAN_DATA_PERCENT $MIN_RRD_STEP_SIZE};
|
||||
#
|
||||
# Maximum percentage of 0's to put up with in the data before I log an error
|
||||
# Use values from 0 - 100
|
||||
#
|
||||
$MAX_ZERO_DATA_PERCENT = 50;
|
||||
|
||||
#
|
||||
# Maximum percentage of NaN's to put up with in the data before I log an error
|
||||
# Use values from 0 - 100
|
||||
#
|
||||
$MAX_NAN_DATA_PERCENT = 0;
|
||||
|
||||
#
|
||||
# This is the smallest step size returned by the RRDs - equal to a 5 minute
|
||||
# granularity.
|
||||
#
|
||||
$MIN_RRD_STEP_SIZE = 300;
|
||||
|
||||
|
||||
###############################
|
||||
# Monitor Time List Hash Keys #
|
||||
###############################
|
||||
use vars qw{$MTL_START_EPOCH $MTL_END_EPOCH $MTL_FIRST_OF_MONTH
|
||||
$MTL_YEAR $MTL_MONTH $MTL_MDAY};
|
||||
$MTL_START_EPOCH = 'MTL_START_EPOCH';
|
||||
$MTL_END_EPOCH = 'MTL_END_EPOCH';
|
||||
$MTL_FIRST_OF_MONTH = 'MTL_FIRST_OF_MONTH';
|
||||
$MTL_YEAR = 'MTL_YEAR';
|
||||
$MTL_MONTH = 'MTL_MONTH';
|
||||
$MTL_MDAY = 'MTL_MDAY';
|
||||
|
||||
|
||||
###########################
|
||||
# Circuit Entry Hash Keys #
|
||||
###########################
|
||||
use vars qw{$CIRCUIT_COMPANY_NAME $CIRCUIT_IP_ADDRESS
|
||||
$CIRCUIT_PORT_NAME $CIRCUIT_ID};
|
||||
$CIRCUIT_COMPANY_NAME = 'CIRCUIT_COMPANY_NAME';
|
||||
$CIRCUIT_IP_ADDRESS = 'CIRCUIT_IP_ADDRESS';
|
||||
$CIRCUIT_PORT_NAME = 'CIRCUIT_PORT_NAME';
|
||||
$CIRCUIT_ID = 'CIRCUIT_ID';
|
||||
@@ -1,213 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
#####################################################################
|
||||
# $Id: BB_lib.pl,v 1.1.1.1 2000-10-23 20:08:17 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_lib.pl
|
||||
#
|
||||
# This file contains functions shared amongst the programs
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
#####################################################################
|
||||
|
||||
use strict;
|
||||
|
||||
use DirHandle;
|
||||
use IO::File;
|
||||
use File::Copy;
|
||||
|
||||
BEGIN {require '../inc/BB_include.pl';}
|
||||
|
||||
|
||||
###########
|
||||
# Globals #
|
||||
###########
|
||||
my $LOG_FH;
|
||||
|
||||
|
||||
##################################################################
|
||||
# get_time_stamp
|
||||
#
|
||||
# This returns the current timestamp, in the logfile format.
|
||||
##################################################################
|
||||
sub get_time_stamp
|
||||
{
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
|
||||
|
||||
$mon += 1;
|
||||
$year += 1900;
|
||||
|
||||
$mon = "0" . $mon if ( $mon < 10 );
|
||||
$mday = "0" . $mday if ( $mday < 10 );
|
||||
$hour = "0" . $hour if ( $hour < 10 );
|
||||
$min = "0" . $min if ( $min < 10 );
|
||||
$sec = "0" . $sec if ( $sec < 10 );
|
||||
|
||||
return "$year$mon$mday-$hour$min$sec";
|
||||
}
|
||||
|
||||
|
||||
######################################################
|
||||
# get_file_timestamp
|
||||
#
|
||||
# This returns the 'modification' timestamp of a file,
|
||||
# used for file archving.
|
||||
######################################################
|
||||
sub get_file_timestamp
|
||||
{
|
||||
my ($filename) = @_;
|
||||
|
||||
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size);
|
||||
my ($atime, $mtime, $ctime, $blksize, $blocks);
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
|
||||
|
||||
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
|
||||
$atime, $mtime, $ctime, $blksize, $blocks) = stat $filename;
|
||||
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
|
||||
|
||||
$mon += 1;
|
||||
$year += 1900;
|
||||
|
||||
$mon = "0" . $mon if ( $mon < 10 );
|
||||
$mday = "0" . $mday if ( $mday < 10 );
|
||||
$hour = "0" . $hour if ( $hour < 10 );
|
||||
$min = "0" . $min if ( $min < 10 );
|
||||
$sec = "0" . $sec if ( $sec < 10 );
|
||||
|
||||
return "$year$mon$mday-$hour$min$sec";
|
||||
}
|
||||
|
||||
|
||||
###############################################################
|
||||
# archive_file
|
||||
#
|
||||
# This routine moves a file into a backup directory.
|
||||
#
|
||||
# Arguments:
|
||||
# $dir => source directory to archive from
|
||||
# $filename => file to archive
|
||||
# $archive_dir => destination directory to archive to
|
||||
# $archive_filename => destination filename (wihout datestamp -
|
||||
# that is appended automatically)
|
||||
# $copy => optional parameter. If == 1 then the files
|
||||
# are copied, not moved to $archive_dir.
|
||||
# Returns: $OKAY on success
|
||||
###############################################################
|
||||
sub archive_file
|
||||
{
|
||||
my ($dir, $filename, $archive_dir, $archive_filename, $copy) = @_;
|
||||
|
||||
my ($full_filename, $timestamp, $full_archive_filename);
|
||||
|
||||
|
||||
$full_filename = "$dir/$filename";
|
||||
## $timestamp = &get_time_stamp();
|
||||
$timestamp = &get_file_timestamp($full_filename);
|
||||
|
||||
$full_archive_filename = "$archive_dir/$archive_filename.$timestamp";
|
||||
|
||||
if ( -f $full_filename )
|
||||
{
|
||||
if ( defined($copy) && $copy )
|
||||
{
|
||||
if ( ! copy($full_filename, $full_archive_filename) )
|
||||
{
|
||||
return($ERROR_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! move($full_filename, $full_archive_filename) )
|
||||
{
|
||||
return($ERROR_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return($OKAY);
|
||||
}
|
||||
|
||||
|
||||
###########################################################################
|
||||
# purge_old_archives
|
||||
#
|
||||
# This routine deletes old archive files - it sorts the files in the
|
||||
# directory and deletes the oldest files until there are at most $max_files
|
||||
# in the directory
|
||||
###########################################################################
|
||||
sub purge_old_archives
|
||||
{
|
||||
my ($archive_dir, $max_files, $prefix) = @_;
|
||||
|
||||
my ($dirhandle, @allfiles, @delfiles);
|
||||
local($_);
|
||||
|
||||
$dirhandle = new DirHandle $archive_dir;
|
||||
if ( ! $dirhandle )
|
||||
{
|
||||
return ($ERROR_WARNING);
|
||||
}
|
||||
|
||||
@allfiles = grep /^\Q$prefix\E/,
|
||||
reverse sort $dirhandle->read();
|
||||
$dirhandle->close();
|
||||
|
||||
@delfiles = splice @allfiles, $max_files;
|
||||
unlink map {"$archive_dir/$_"} @delfiles;
|
||||
}
|
||||
|
||||
|
||||
###############################
|
||||
# open_log_file
|
||||
#
|
||||
# Opens the log file for append
|
||||
###############################
|
||||
sub open_log_file
|
||||
{
|
||||
$LOG_FH = new IO::File ">>$LOG_DIR/$LOG_FILE";
|
||||
if ( ! $LOG_FH )
|
||||
{
|
||||
print STDERR "Error opening log file\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
################
|
||||
# close_log_file
|
||||
################
|
||||
sub close_log_file
|
||||
{
|
||||
$LOG_FH->close();
|
||||
}
|
||||
|
||||
|
||||
##################################
|
||||
# write_log_file
|
||||
#
|
||||
# Writes a message to the log file
|
||||
##################################
|
||||
sub write_log_file
|
||||
{
|
||||
my ($code, $desc) = @_;
|
||||
|
||||
my ($timestamp);
|
||||
|
||||
$timestamp = &get_time_stamp();
|
||||
|
||||
if ( $code eq $START_STAMP )
|
||||
{
|
||||
print $LOG_FH "\n$code<$timestamp>: $desc\n";
|
||||
}
|
||||
elsif ( $code eq $END_STAMP )
|
||||
{
|
||||
print $LOG_FH "$code<$timestamp>: $desc\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print $LOG_FH "\t$code<$timestamp>: $desc\n";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -1,71 +0,0 @@
|
||||
Comcast_Online_Towson:209.19.8.1:r1.twsn1.md.home.net:45233
|
||||
Cox_AV:209.218.23.21:w4.rdc2.occa.home.net:44204
|
||||
Cox_AZ:10.252.40.193:w1.rdc1.az.home.net:43195
|
||||
Cox_NE:10.252.136.17:w1.rdc1.ne.home.net:45621
|
||||
Cox_SD:10.252.20.97:w2.rdc1.sdca.home.net:44118
|
||||
Cox_VA:10.252.60.5:w1.rdc1.va.home.net:43711
|
||||
Cox_Fibernet:10.252.64.5:w1.rdc1.ok.home.net:44119
|
||||
Befirst:216.217.177.69:w1.pop1.fl.home.net:46820
|
||||
Internap:216.217.218.129:wbb1.rdc1.wa.home.net:48891
|
||||
Merril_Lynch:10.252.172.1:w1.pop1.nj.home.net:47549
|
||||
Siebel:10.252.9.113:w4.rdc1.sfba.home.net:46653
|
||||
Vertex:10.252.140.1:w1.pop1.ca.home.net:44176
|
||||
COX_COMM:10.252.96.17:w1.pop1.la.home.net:42782
|
||||
FUSION_NETWORKS:10.252.148.53:w1.pop1.fl.home.net:40378
|
||||
ISP_ALLIANCE:10.252.168.17:w1.pop1.ga.home.net:42968
|
||||
Akamai:64.232.139.5:wbb1.pop1.va.home.net:44435
|
||||
MICROCAST:24.7.70.65:c1.cmbrma1.home.net:44698
|
||||
MICROCAST:24.7.70.81:c1.sttlwa1.home.net:44699
|
||||
MICROCAST:24.7.70.77:c1.snfcca1.home.net:44700
|
||||
MICROCAST:24.7.70.69:c2.chcgil1.home.net:44704
|
||||
MICROCAST:24.7.70.85:c2.washdc1.home.net:44702
|
||||
MICROCAST:24.7.70.73:c1.dllstx1.home.net:44703
|
||||
STREAMING_MEDIA:10.253.0.1:wbb1.pop1.va.home.net:45382
|
||||
INTELLISPACE_INTELLIGENT_INTERNET:10.252.156.33:w1.pop1.ny.home.net:44449
|
||||
Speedera:209.219.187.1:wbb1.pop2.ca.home.net:46034
|
||||
Speedera:64.232.139.1:wbb1.pop1.va.home.net:46035
|
||||
IBeam:10.253.64.49:wbb1.pop2.ca.home.net:43891
|
||||
COX_COMM:10.252.168.21:w1.pop1.ga.home.net:44619
|
||||
Apptus:10.253.0.33:wbb1.pop1.va.home.net:46080
|
||||
SADDLEBACK_COLLEGE:10.252.25.109:w1.rdc2.occa.home.net:37266
|
||||
Cox_VA:10.252.60.1:w1.rdc1.va.home.net:37085
|
||||
Cox_AV:209.218.23.21:wbb1.rdc2.occa.home.net:36842
|
||||
SEGASOFT:209.19.34.33:w4.rdc1.sfba.home.net:36658
|
||||
AT&T_NCS_ITS:10.252.1.25:w5.rdc1.nj.home.net:35004
|
||||
LUCENT_TECHNOLOGIES:10.252.0.117:w1.rdc1.nj.home.net:38002
|
||||
BROADCOM:10.252.24.9:w1.rdc2.occa.home.net:38442
|
||||
NETWORK_PLUS:10.252.49.73:w2.pop1.ma.home.net:38786
|
||||
GLOBAL_MUSIC_OUTLET:10.252.27.9:w2.rdc2.occa.home.net:34780
|
||||
SIMPLE_NETWORK_COMM:10.252.144.1:w1.sndgca1.home.net:35837
|
||||
TELEBEAM:209.125.212.9:w1.pop1.pa.home.net:34908
|
||||
INTERTAINER:10.252.24.209:w1.rdc2.occa.home.net:39622
|
||||
INTEL_CORP:10.252.160.9:w1.pop1.or.home.net:38387
|
||||
AT&T_MEDIA_SERVICES:10.252.84.161:w4.rdc1.sfba.home.net:39715
|
||||
NET_CARRIER:209.125.212.13:w1.pop1.pa.home.net:36901
|
||||
COMCAST_ONLINE:216.217.0.1:w3.rdc1.nj.home.net:40728
|
||||
REAL_NETWORKS:216.216.93.5:wbb1.rdc1.wa.home.net:40961
|
||||
INTEL_CORP:10.252.41.13:w2.pop1.az.home.net:38798
|
||||
IDEAL:10.252.56.5:wbb1.pop1.mi.home.net:40235
|
||||
IMALL:10.252.180.17:w1.pop2.ut.home.net:39762
|
||||
PRIME:10.252.25.189:w2.rdc2.occa.home.net:41036
|
||||
ETRACKS.COM:10.252.11.73:w4.rdc1.sfba.home.net:39479
|
||||
NEW_JERSEY_LINKED:10.252.172.5:w1.pop1.nj.home.net:40679
|
||||
AT&T_FIBER_WHOLESALE:10.252.84.245:w4.rdc1.sfba.home.net:39998
|
||||
NORTHPOINT_PVC_IRVINE:10.252.32.165:w3.rdc2.occa.home.net:43108
|
||||
NORTHPOINT_PVC_CHICAGO:10.252.14.149:w3.rdc1.il.home.net:43102
|
||||
NORTHPOINT_PVC_WASHINGTON:10.252.88.21:w1.pop1.dc.home.net:43103
|
||||
NORTHPOINT_PVC_ATLANTA:10.252.168.13:w1.pop1.ga.home.net:43097
|
||||
NORTHPOINT_PVC_NEW_JERSEY:10.252.80.125:w4.rdc1.nj.home.net:43105
|
||||
NORTHPOINT_PVC_FT_LAUD:10.252.148.33:w1.pop1.fl.home.net:43101
|
||||
AIRPOWER_COMM:216.216.30.213:wbb1.rdc2.occa.home.net:42072
|
||||
REAL_NETWORKS:10.252.116.53:w1.pop1.or.home.net:42946
|
||||
AKAMAI:10.253.112.33:wbb1.pop1.il.home.net:44426
|
||||
AKAMAI:10.253.132.33:wbb1.pop1.ny.home.net:44434
|
||||
AKAMAI:10.253.80.33:wbb1.pop2.wa.home.net:44427
|
||||
AKAMAI:10.253.96.33:wbb1.pop1.ca.home.net:44429
|
||||
AKAMAI:10.253.64.37:wbb1.pop2.ca.home.net:44423
|
||||
COX_COMM:10.252.168.9:w1.pop1.ga.home.net:41756
|
||||
STREAMING_MEDIA:10.253.64.33:wbb1.pop2.ca.home.net:45381
|
||||
INTUIT:216.216.48.141:w1.sndgca1.home.net:46576
|
||||
AT&T_UGN_KANSAS:10.252.152.33:w1.pop1.il.home.net:43861
|
||||
WEBUSENET:10.253.64.45:wbb1.pop2.ca.home.net:45791
|
||||
37
mozilla/java/xpcom/Makefile
Normal file
37
mozilla/java/xpcom/Makefile
Normal file
@@ -0,0 +1,37 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
DEPTH = ../..
|
||||
topsrcdir = ../..
|
||||
VPATH = .
|
||||
srcdir = .
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS= \
|
||||
connect \
|
||||
xpcom \
|
||||
java \
|
||||
xpcom/test/ \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
37
mozilla/java/xpcom/Makefile.in
Normal file
37
mozilla/java/xpcom/Makefile.in
Normal file
@@ -0,0 +1,37 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS= \
|
||||
connect \
|
||||
xpcom \
|
||||
java \
|
||||
xpcom/test/ \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
78
mozilla/java/xpcom/README
Normal file
78
mozilla/java/xpcom/README
Normal 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)
|
||||
|
||||
34
mozilla/java/xpcom/connect/Makefile.in
Normal file
34
mozilla/java/xpcom/connect/Makefile.in
Normal 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
|
||||
33
mozilla/java/xpcom/connect/makefile.win
Normal file
33
mozilla/java/xpcom/connect/makefile.win
Normal 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>
|
||||
|
||||
|
||||
80
mozilla/java/xpcom/connect/public/bcDefs.h
Normal file
80
mozilla/java/xpcom/connect/public/bcDefs.h
Normal 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
35
mozilla/java/xpcom/connect/public/bcIAllocator.h
Normal file
35
mozilla/java/xpcom/connect/public/bcIAllocator.h
Normal 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
|
||||
|
||||
48
mozilla/java/xpcom/connect/public/bcICall.h
Normal file
48
mozilla/java/xpcom/connect/public/bcICall.h
Normal 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 __bcICall_h
|
||||
#define __bcICall_h
|
||||
#include "bcIMarshaler.h"
|
||||
#include "bcIUnMarshaler.h"
|
||||
|
||||
class bcIORB;
|
||||
|
||||
class bcICall {
|
||||
public:
|
||||
virtual int GetParams(bcIID *, bcOID *, bcMID *) = 0;
|
||||
virtual bcIMarshaler * GetMarshaler() = 0;
|
||||
virtual bcIUnMarshaler * GetUnMarshaler() = 0;
|
||||
virtual bcIORB * GetORB() = 0;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
mozilla/java/xpcom/connect/public/bcIMarshaler.h
Normal file
39
mozilla/java/xpcom/connect/public/bcIMarshaler.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
mozilla/java/xpcom/connect/public/bcIORB.h
Normal file
38
mozilla/java/xpcom/connect/public/bcIORB.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
#ifndef __bcIORB_h
|
||||
#define __bcIORB_h
|
||||
#include "bcICall.h"
|
||||
#include "bcDefs.h"
|
||||
#include "bcIStub.h"
|
||||
|
||||
|
||||
class bcIORB {
|
||||
public:
|
||||
virtual bcOID RegisterStub(bcIStub *stub) = 0;
|
||||
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID) = 0;
|
||||
virtual int SendReceive(bcICall *) = 0;
|
||||
//virtual IThread * GetThread(TID) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
31
mozilla/java/xpcom/connect/public/bcIStub.h
Normal file
31
mozilla/java/xpcom/connect/public/bcIStub.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
#ifndef __bcIStub_h
|
||||
#define __bcIStub_h
|
||||
#include "bcICall.h"
|
||||
|
||||
class bcIStub {
|
||||
public:
|
||||
virtual void Dispatch(bcICall *call) = 0;
|
||||
//nb shortcut
|
||||
};
|
||||
#endif
|
||||
29
mozilla/java/xpcom/connect/public/bcIThread.h
Normal file
29
mozilla/java/xpcom/connect/public/bcIThread.h
Normal 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
|
||||
35
mozilla/java/xpcom/connect/public/bcIUnMarshaler.h
Normal file
35
mozilla/java/xpcom/connect/public/bcIUnMarshaler.h
Normal 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
|
||||
|
||||
|
||||
46
mozilla/java/xpcom/connect/src/Allocator.cpp
Normal file
46
mozilla/java/xpcom/connect/src/Allocator.cpp
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
35
mozilla/java/xpcom/connect/src/Allocator.h
Normal file
35
mozilla/java/xpcom/connect/src/Allocator.h
Normal 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
|
||||
78
mozilla/java/xpcom/connect/src/Call.cpp
Normal file
78
mozilla/java/xpcom/connect/src/Call.cpp
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
51
mozilla/java/xpcom/connect/src/Call.h
Normal file
51
mozilla/java/xpcom/connect/src/Call.h
Normal 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
|
||||
52
mozilla/java/xpcom/connect/src/Marshaler.cpp
Normal file
52
mozilla/java/xpcom/connect/src/Marshaler.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
#include <string.h>
|
||||
#include "Marshaler.h"
|
||||
#include "util.h"
|
||||
|
||||
Marshaler::Marshaler(ostream *_out) {
|
||||
out = _out;
|
||||
}
|
||||
|
||||
Marshaler::~Marshaler() {
|
||||
}
|
||||
|
||||
int Marshaler::WriteSimple(void *ptr, bcXPType type) {
|
||||
out->write((const char*)ptr, type2size(type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Marshaler::WriteString(void *ptr, size_t size) {
|
||||
if (!size
|
||||
&& ptr) {
|
||||
size = 1;
|
||||
}
|
||||
out->write((const char*)&size, sizeof(size_t));
|
||||
if (size) {
|
||||
out->write((const char*)ptr,type2size(bc_T_CHAR)*size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
41
mozilla/java/xpcom/connect/src/Marshaler.h
Normal file
41
mozilla/java/xpcom/connect/src/Marshaler.h
Normal 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
|
||||
|
||||
|
||||
65
mozilla/java/xpcom/connect/src/ORB.cpp
Normal file
65
mozilla/java/xpcom/connect/src/ORB.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
#include "ORB.h"
|
||||
#include "Call.h"
|
||||
|
||||
ORB::ORB() {
|
||||
currentID = 1;
|
||||
for (int i = 0; i < STUBS_COUNT; i++) {
|
||||
stubs[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ORB::~ORB() {
|
||||
}
|
||||
|
||||
bcOID ORB::RegisterStub(bcIStub *stub) {
|
||||
stubs[currentID] = stub;
|
||||
return currentID++;
|
||||
}
|
||||
|
||||
bcICall * ORB::CreateCall(bcIID *iid, bcOID *oid, bcMID mid) {
|
||||
return new Call(iid, oid, mid,this);
|
||||
}
|
||||
|
||||
int ORB::SendReceive(bcICall *call) {
|
||||
bcIID iid;
|
||||
bcOID oid;
|
||||
bcMID mid;
|
||||
call->GetParams(&iid,&oid,&mid);
|
||||
bcIStub *stub = GetStub(&oid);
|
||||
if (stub) {
|
||||
stub->Dispatch(call);
|
||||
return 0;
|
||||
} else {
|
||||
return 1; //nb need to think about error values
|
||||
}
|
||||
}
|
||||
|
||||
bcIStub * ORB::GetStub(bcOID *oid) {
|
||||
return stubs[*oid];
|
||||
}
|
||||
|
||||
|
||||
|
||||
40
mozilla/java/xpcom/connect/src/ORB.h
Normal file
40
mozilla/java/xpcom/connect/src/ORB.h
Normal 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 __ORB_h
|
||||
#define __ORB_h
|
||||
#include "bcIORB.h"
|
||||
|
||||
#define STUBS_COUNT (100)
|
||||
class ORB : public bcIORB {
|
||||
public:
|
||||
ORB();
|
||||
virtual ~ORB();
|
||||
virtual bcOID RegisterStub(bcIStub *stub);
|
||||
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID);
|
||||
virtual int SendReceive(bcICall *);
|
||||
private:
|
||||
bcIStub * GetStub(bcOID *);
|
||||
bcIStub * stubs[STUBS_COUNT]; //nb :) it's jast for now. (Mon Mar 13 16:53:03 PST 2000)
|
||||
int currentID;
|
||||
};
|
||||
#endif
|
||||
53
mozilla/java/xpcom/connect/src/UnMarshaler.cpp
Normal file
53
mozilla/java/xpcom/connect/src/UnMarshaler.cpp
Normal 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;
|
||||
in->read((char*)size,sizeof(size_t));
|
||||
*(char**)ptr = (char *)allocator->Alloc(*size * type2size(bc_T_CHAR));
|
||||
if (*size) {
|
||||
in->read(*(char**)ptr,*size * type2size(bc_T_CHAR));
|
||||
}
|
||||
|
||||
if (*size == 1) {
|
||||
if (!(*(char**)ptr)[0]) {
|
||||
*size = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
38
mozilla/java/xpcom/connect/src/UnMarshaler.h
Normal file
38
mozilla/java/xpcom/connect/src/UnMarshaler.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
62
mozilla/java/xpcom/connect/src/makefile.win
Normal file
62
mozilla/java/xpcom/connect/src/makefile.win
Normal 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
|
||||
72
mozilla/java/xpcom/connect/src/util.cpp
Normal file
72
mozilla/java/xpcom/connect/src/util.cpp
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
27
mozilla/java/xpcom/connect/src/util.h
Normal file
27
mozilla/java/xpcom/connect/src/util.h
Normal 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
|
||||
65
mozilla/java/xpcom/connect/xpcom/Makefile.in
Normal file
65
mozilla/java/xpcom/connect/xpcom/Makefile.in
Normal 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) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
DEPTH=../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = bcorb
|
||||
MODULE = bcorb
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
bcORB.cpp \
|
||||
../src/Allocator.cpp \
|
||||
../src/Call.cpp \
|
||||
../src/Marshaler.cpp \
|
||||
../src/ORB.cpp \
|
||||
../src/UnMarshaler.cpp \
|
||||
../src/util.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
bcORB.h \
|
||||
../public/bcIORB.h \
|
||||
../public/bcDefs.h \
|
||||
../public/bcICall.h \
|
||||
../public/bcIUnMarshaler.h \
|
||||
../public/bcIAllocator.h \
|
||||
../public/bcIMarshaler.h \
|
||||
../public/bcIStub.h \
|
||||
../public/bcIThread.h
|
||||
|
||||
|
||||
CXXFLAGS += -I../public -I../src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
|
||||
|
||||
76
mozilla/java/xpcom/connect/xpcom/bcORB.cpp
Normal file
76
mozilla/java/xpcom/connect/xpcom/bcORB.cpp
Normal 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 "bcORB.h"
|
||||
#include "../src/ORB.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(bcORB);
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{
|
||||
"Black Connect ORB",
|
||||
BC_ORB_CID,
|
||||
BC_ORB_PROGID,
|
||||
bcORBConstructor
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("BlackConnectORB",components);
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(bcORB,NS_GET_IID(bcORB));
|
||||
|
||||
bcORB::bcORB() :
|
||||
orb(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
bcORB::~bcORB() {
|
||||
if (orb) {
|
||||
delete orb; //nb should we destroy it?
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcORB::GetORB(bcIORB **_orb) {
|
||||
if (!_orb) {
|
||||
printf("--bcORB::GetORB\n");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (!orb) {
|
||||
orb = new ORB();
|
||||
}
|
||||
*_orb = orb;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
54
mozilla/java/xpcom/connect/xpcom/bcORB.h
Normal file
54
mozilla/java/xpcom/connect/xpcom/bcORB.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
#ifndef _bcORB_h
|
||||
#define _bcORB_h
|
||||
#include "nsISupports.h"
|
||||
#include "bcIORB.h"
|
||||
|
||||
|
||||
/*29bde10c-1dd2-11b2-ab23-ebe06c6baec5*/
|
||||
#define BC_ORB_IID \
|
||||
{ 0x29bde10c, 0x1dd2, 0x11b2, \
|
||||
{0xab, 0x23, 0xeb, 0xe0, 0x6c, 0x6b, 0xae, 0xc5}}
|
||||
|
||||
|
||||
#define BC_ORB_PROGID "component://netscape/blackwood/blackconnect/orb"
|
||||
|
||||
/*ffa0d768-1dd1-11b2-8bf2-ab56f26ea844*/
|
||||
#define BC_ORB_CID \
|
||||
{ 0xffa0d768, 0x1dd1, 0x11b2, \
|
||||
{0x8b, 0xf2, 0xab, 0x56, 0xf2, 0x6e, 0xa8, 0x44 }}
|
||||
|
||||
|
||||
class bcORB : public nsISupports {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(BC_ORB_IID)
|
||||
NS_IMETHOD GetORB(bcIORB **orb);
|
||||
bcORB();
|
||||
virtual ~bcORB();
|
||||
private:
|
||||
bcIORB *orb;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
47
mozilla/java/xpcom/connect/xpcom/makefile.win
Normal file
47
mozilla/java/xpcom/connect/xpcom/makefile.win
Normal file
@@ -0,0 +1,47 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are
|
||||
# Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
MODULE=bcorb
|
||||
COMPONENT = 1
|
||||
DLLNAME = bcorb
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\bcORB.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
bcORB.h \
|
||||
$(NULL)
|
||||
|
||||
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib $(DIST)\lib\bcorbcore.lib
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\components\$(DLLNAME).dll
|
||||
32
mozilla/java/xpcom/java/Makefile.in
Normal file
32
mozilla/java/xpcom/java/Makefile.in
Normal 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= src loader classes test
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
43
mozilla/java/xpcom/java/classes/Makefile.in
Normal file
43
mozilla/java/xpcom/java/classes/Makefile.in
Normal 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
|
||||
|
||||
39
mozilla/java/xpcom/java/classes/makefile.win
Normal file
39
mozilla/java/xpcom/java/classes/makefile.win
Normal 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 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>
|
||||
@@ -0,0 +1,62 @@
|
||||
/* -*- 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;
|
||||
}
|
||||
Object object = loader.loadClass(componentClassName).newInstance();
|
||||
return object;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
58
mozilla/java/xpcom/java/classes/org/mozilla/xpcom/IID.java
Normal file
58
mozilla/java/xpcom/java/classes/org/mozilla/xpcom/IID.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
public class IID {
|
||||
public IID(String iid) {
|
||||
this.iid = (iid == null) ? "" : iid;
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof IID)) {
|
||||
return false;
|
||||
}
|
||||
boolean res = iid.equals(((IID)obj).iid);
|
||||
return res;
|
||||
}
|
||||
public String toString() {
|
||||
return "org.mozilla.xpcom.IID@"+iid;
|
||||
}
|
||||
public int hashCode() {
|
||||
int h = iid.hashCode();
|
||||
return h;
|
||||
}
|
||||
public String getString() {
|
||||
return iid;
|
||||
}
|
||||
private String iid;
|
||||
public static Class TYPE;
|
||||
static {
|
||||
try {
|
||||
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
|
||||
} catch (Exception e) { //it could not happen
|
||||
TYPE = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ProxyClass { //nb it should not be public
|
||||
public ProxyClass(IID _iid, Method[] _methods) { //nb it should not be public
|
||||
iid = _iid;
|
||||
methods = _methods;
|
||||
if (classes == null) {
|
||||
classes = new Hashtable();
|
||||
}
|
||||
classes.put(iid, this);
|
||||
}
|
||||
Method getMethodByIndex(int mid) { //first method has index equal to 'offset'
|
||||
System.out.println("--[java]ProxyClass.GetMehodByIndex "+mid);
|
||||
Method result = null;
|
||||
try {
|
||||
result = methods[mid-offset];
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int getIndexByMethod(Method method) {
|
||||
int result = 0;
|
||||
if (method == null
|
||||
||methods == null) {
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (method.equals(methods[i])) {
|
||||
result = i + offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static ProxyClass getProxyClass(IID iid) {
|
||||
ProxyClass result = null;
|
||||
Object obj = null;
|
||||
if (classes != null) {
|
||||
obj = classes.get(iid);
|
||||
if (obj != null
|
||||
&& (obj instanceof ProxyClass)) {
|
||||
result = (ProxyClass)obj;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private IID iid;
|
||||
private Method[] methods;
|
||||
private final int offset = 0; //from xpcom
|
||||
static Hashtable classes = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.ref.*;
|
||||
|
||||
class ProxyKey {
|
||||
ProxyKey(long _oid, IID _iid) {
|
||||
oid = new Long(_oid);
|
||||
iid = _iid;
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof ProxyKey)) {
|
||||
return false;
|
||||
}
|
||||
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
|
||||
}
|
||||
public int hashCode() {
|
||||
return oid.hashCode();
|
||||
}
|
||||
public String toString() {
|
||||
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
|
||||
}
|
||||
Long oid;
|
||||
IID iid;
|
||||
}
|
||||
|
||||
public class ProxyFactory {
|
||||
public static void registerInterfaceForIID(Class inter, IID iid) {
|
||||
System.out.println("--[java] ProxyFactory.registerInterfaceForIID "+iid);
|
||||
if (interfaces == null) {
|
||||
interfaces = new Hashtable();
|
||||
}
|
||||
interfaces.put(iid, inter); //nb who is gonna remove object from cache?
|
||||
}
|
||||
public static Class getInterface(IID iid) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface "+iid);
|
||||
Object obj = null;
|
||||
if (interfaces != null) {
|
||||
obj = interfaces.get(iid);
|
||||
if (obj == null) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface interface== null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!(obj instanceof Class)) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface !(obj instanceof Class"+obj);
|
||||
return null;
|
||||
}
|
||||
return (Class)obj;
|
||||
}
|
||||
|
||||
public static Object getProxy(long oid, IID iid, long orb) {
|
||||
try {
|
||||
System.out.println("--[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) {
|
||||
System.out.println("--[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);
|
||||
}
|
||||
System.out.println("--[java] ProxyFactory.getProxy we got proxy "+result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
System.out.println("--[java] ProxyFactory.getProxy we got exception "+e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected static Hashtable proxies = null;
|
||||
private static Hashtable interfaces = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
class ProxyHandler implements InvocationHandler {
|
||||
ProxyHandler(long _oid, IID _iid, long _orb) {
|
||||
oid = _oid;
|
||||
iid = _iid;
|
||||
orb = _orb;
|
||||
}
|
||||
public Object invoke(Object proxy,
|
||||
Method method,
|
||||
Object[] args) throws Throwable {
|
||||
System.out.println("--[java]ProxyHandler.invoke "+method);
|
||||
if ("toString".equals(method.getName())) {
|
||||
return "ProxyObject@{oid = "+oid+" iid = "+iid+"}";
|
||||
}
|
||||
return Utilities.callMethod(oid, method, iid, orb, args);
|
||||
}
|
||||
private long oid;
|
||||
private IID iid;
|
||||
private long orb;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/* -*- 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 Object callMethodByIndex(Object obj, IID iid, int mid, Object[] args) {
|
||||
System.out.println("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
System.out.println("--[java]callMethodByIndex args["+i+"] = "+args[i]);
|
||||
}
|
||||
Method method = getMethodByIndex(mid,iid);
|
||||
System.out.println("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method);
|
||||
try {
|
||||
if (method != null) {
|
||||
method.invoke(obj,args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("--callMethodByIndex method finished"+method);
|
||||
return null; //nb for testing
|
||||
}
|
||||
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
|
||||
System.out.println("--[java]Utilities.callMethod "+method);
|
||||
int mid = getIndexByMethod(method, iid);
|
||||
if (mid <= 0) {
|
||||
System.out.println("--[java]Utilities.callMethod we do not have implementation for "+method);
|
||||
return null;
|
||||
}
|
||||
System.out.println("--[java]Utilities.callMethod "+mid);
|
||||
return callMethodByIndex(oid,mid,iid.getString(), orb, args);
|
||||
}
|
||||
|
||||
private static Method getMethodByIndex(int index, IID iid) {
|
||||
Method result = null;
|
||||
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
|
||||
if (proxyClass != null) {
|
||||
result = proxyClass.getMethodByIndex(index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private static int getIndexByMethod(Method method, IID iid) {
|
||||
int result = 0;
|
||||
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
|
||||
if (proxyClass != null) {
|
||||
result = proxyClass.getIndexByMethod(method);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private static native Object callMethodByIndex(long oid, int index, String iid, long orb, Object[] args);
|
||||
static {
|
||||
System.loadLibrary("bcjavastubs");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
49
mozilla/java/xpcom/java/loader/Makefile.in
Normal file
49
mozilla/java/xpcom/java/loader/Makefile.in
Normal file
@@ -0,0 +1,49 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are
|
||||
# Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
MODULE = javaloader
|
||||
LIBRARY_NAME = javaloader
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
bcJavaComponentLoader.cpp \
|
||||
bcJavaModule.cpp \
|
||||
bcJavaComponentFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
CXXFLAGS += -I$(JDKHOME)/include -I$(JDKHOME)/include/linux $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
-L$(DIST)/bin/components/ \
|
||||
-lbcorb -lbcxpcomstubs -lbcjavastubs \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
90
mozilla/java/xpcom/java/loader/bcJavaComponentFactory.cpp
Normal file
90
mozilla/java/xpcom/java/loader/bcJavaComponentFactory.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCRT.h"
|
||||
#include "bcJavaComponentFactory.h"
|
||||
#include "bcJavaStubsAndProxies.h"
|
||||
#include "bcXPCOMStubsAndProxies.h"
|
||||
#include "bcORB.h"
|
||||
|
||||
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
static NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS1(bcJavaComponentFactory, nsIFactory)
|
||||
|
||||
|
||||
bcJavaComponentFactory::bcJavaComponentFactory(const char *_location) {
|
||||
NS_INIT_ISUPPORTS();
|
||||
location = nsCRT::strdup(_location);
|
||||
}
|
||||
|
||||
bcJavaComponentFactory::~bcJavaComponentFactory() {
|
||||
nsCRT::free((char*)location);
|
||||
}
|
||||
|
||||
/* void CreateInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result);
|
||||
*/
|
||||
NS_IMETHODIMP bcJavaComponentFactory::CreateInstance(nsISupports *aOuter, const nsIID & iid, void * *result) {
|
||||
printf("--bcJavaComponentFactory::CreateInstance\n");
|
||||
nsresult r;
|
||||
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--bcJavaComponentFactory::CreateInstance javaStubsAndProxies failed \n");
|
||||
return r;
|
||||
}
|
||||
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--bcJavaComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
|
||||
return r;
|
||||
}
|
||||
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
printf("--bcJavaComponentFactory::CreateInstance bcORB failed \n");
|
||||
return r;
|
||||
}
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
bcOID oid;
|
||||
r = javaStubsAndProxies->GetOID(location, &oid);
|
||||
printf("--bcJavaComponentFactory::CreateInstance after GetOID");
|
||||
nsISupports *proxy;
|
||||
printf("--[c++]bcJavaComponentFactory::CreateInstance iid:%s\n",iid.ToString());
|
||||
xpcomStubsAndProxies->GetProxy(oid, iid, orb, &proxy);
|
||||
*result = proxy;
|
||||
printf("--bcJavaComponentFactory::CreateInstance end");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void LockFactory (in PRBool lock); */
|
||||
NS_IMETHODIMP bcJavaComponentFactory::LockFactory(PRBool lock)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
mozilla/java/xpcom/java/loader/bcJavaComponentFactory.h
Normal file
39
mozilla/java/xpcom/java/loader/bcJavaComponentFactory.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* 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
|
||||
|
||||
|
||||
466
mozilla/java/xpcom/java/loader/bcJavaComponentLoader.cpp
Normal file
466
mozilla/java/xpcom/java/loader/bcJavaComponentLoader.cpp
Normal file
@@ -0,0 +1,466 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
A bunch of stuff was copied from mozJSComponentLoader.cpp
|
||||
*/
|
||||
#include "nsICategoryManager.h"
|
||||
#include "bcJavaComponentLoader.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "bcJavaModule.h"
|
||||
|
||||
|
||||
|
||||
const char javaComponentTypeName[] = JAVACOMPONENTTYPENAME;
|
||||
|
||||
/* XXX export properly from libxpcom, for now this will let Mac build */
|
||||
#ifdef RHAPSODY
|
||||
extern const char fileSizeValueName[]; // = "FileSize";
|
||||
extern const char lastModValueName[]; // = "LastModTimeStamp";
|
||||
extern const char xpcomKeyName[]; // = "Software/Mozilla/XPCOM";
|
||||
#else
|
||||
const char fileSizeValueName[] = "FileSize";
|
||||
const char lastModValueName[] = "LastModTimeStamp";
|
||||
const char xpcomKeyName[] = "software/mozilla/XPCOM/components";
|
||||
#endif
|
||||
|
||||
NS_IMPL_ISUPPORTS(bcJavaComponentLoader,NS_GET_IID(nsIComponentLoader));
|
||||
|
||||
bcJavaComponentLoader::bcJavaComponentLoader()
|
||||
: mCompMgr(NULL),
|
||||
|
||||
mXPCOMKey(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
printf("--bcJavaComponentLoader::bcJavaComponentLoader \n");
|
||||
}
|
||||
|
||||
bcJavaComponentLoader::~bcJavaComponentLoader() { //nb
|
||||
printf("--bcJavaComponentLoader::~bcJavaComponentLoader \n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the factory for a given component.
|
||||
*/
|
||||
/* nsIFactory getFactory (in nsIIDRef aCID, in string aLocation, in string aType); */
|
||||
NS_IMETHODIMP bcJavaComponentLoader::GetFactory(const nsIID & aCID, const char *aLocation, const char *aType, nsIFactory **_retval) {
|
||||
printf("--bcJavaComponentLoader::GetFactory \n");
|
||||
if (!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
#ifdef DEBUG
|
||||
char *cidString = aCID.ToString();
|
||||
fprintf(stderr, "--bcJavaComponentLoader::GetFactory(%s,%s,%s)\n", cidString, aLocation, aType);
|
||||
delete [] cidString;
|
||||
#endif
|
||||
nsIModule * module = ModuleForLocation(aLocation, 0);
|
||||
if (!module) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "ERROR: couldn't get module for %s\n", aLocation);
|
||||
#endif
|
||||
return NS_ERROR_FACTORY_NOT_LOADED;
|
||||
}
|
||||
|
||||
nsresult rv = module->GetClassObject(mCompMgr, aCID,
|
||||
NS_GET_IID(nsIFactory),
|
||||
(void **)_retval);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "GetClassObject %s\n", NS_FAILED(rv) ? "FAILED" : "ok");
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the loader.
|
||||
*
|
||||
* We use nsISupports here because nsIRegistry isn't IDLized yet.
|
||||
*/
|
||||
/* void init (in nsIComponentManager aCompMgr, in nsISupports aRegistry); */
|
||||
NS_IMETHODIMP bcJavaComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) {
|
||||
printf("--bcJavaComponentLoader::Init \n");
|
||||
nsresult rv;
|
||||
mCompMgr = aCompMgr;
|
||||
mRegistry = do_QueryInterface(aReg, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mRegistry->GetSubtree(nsIRegistry::Common, xpcomKeyName,
|
||||
&mXPCOMKey);
|
||||
if (NS_FAILED(rv))
|
||||
/* if we can't get the XPCOM key, just skip all registry ops */
|
||||
mRegistry = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a component of the appropriate type is registered,
|
||||
* to give the component loader an opportunity to do things like
|
||||
* annotate the registry and such.
|
||||
*/
|
||||
/* void onRegister (in nsIIDRef aCID, in string aType, in string aClassName, in string aProgID, in string aLocation, in boolean aReplace, in boolean aPersist); */
|
||||
NS_IMETHODIMP bcJavaComponentLoader::OnRegister(const nsIID & aCID, const char *aType, const char *aClassName, const char *aProgID, 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, ®istered);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(dirEntry);
|
||||
}
|
||||
rv = dirIterator->HasMoreElements(&more);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* AutoRegister the given component.
|
||||
*
|
||||
* Returns true if the component was registered, false if it couldn't
|
||||
* attempt to register the component (wrong type) and ``throws'' an
|
||||
* NS_FAILED code if there was an error during registration.
|
||||
*/
|
||||
/* boolean autoRegisterComponent (in long aWhen, in nsIFile aComponent); */
|
||||
|
||||
/* copied from mozJSComponentLoader.cpp */
|
||||
NS_IMETHODIMP 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, ®Time)))
|
||||
return PR_TRUE;
|
||||
|
||||
if (NS_FAILED(component->GetLastModificationDate(&lastTime)) || LL_NE(lastTime, regTime))
|
||||
return PR_TRUE;
|
||||
|
||||
/* check file size */
|
||||
PRInt64 regSize;
|
||||
if (NS_FAILED(mRegistry->GetLongLong(key, fileSizeValueName, ®Size)))
|
||||
return PR_TRUE;
|
||||
PRInt64 size;
|
||||
if (NS_FAILED(component->GetFileSize(&size)) || LL_NE(size,regSize) )
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsIModule * bcJavaComponentLoader::ModuleForLocation(const char *registryLocation, nsIFile *component) {
|
||||
nsStringKey key(registryLocation);
|
||||
nsIModule *res = NULL;
|
||||
res = (nsIModule*)mModules.Get(&key);
|
||||
PRBool needRelease = PR_FALSE;
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
if (!component) {
|
||||
if (NS_FAILED(mCompMgr->SpecForRegistryLocation(registryLocation, &component)))
|
||||
return NULL;
|
||||
needRelease = PR_TRUE;
|
||||
}
|
||||
res = new bcJavaModule(registryLocation, component);
|
||||
if (needRelease) {
|
||||
NS_IF_RELEASE(component);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
mModules.Put(&key,res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Register any deferred (NS_ERROR_FACTORY_REGISTER_AGAIN) components.
|
||||
* Return registered-any-components?
|
||||
*/
|
||||
/* boolean registerDeferredComponents (in long aWhen); */
|
||||
NS_IMETHODIMP bcJavaComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, PRBool *aRegistered) {
|
||||
printf("--bcJavaComponentLoader::RegisterDeferredComponents \n");
|
||||
nsresult rv;
|
||||
*aRegistered = PR_FALSE;
|
||||
PRUint32 count;
|
||||
rv = mDeferredComponents.Count(&count);
|
||||
printf("mJCL: registering deferred (%d)\n", count);
|
||||
if (NS_FAILED(rv) || !count)
|
||||
return NS_OK;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
nsCOMPtr<nsIFile> component;
|
||||
|
||||
rv = mDeferredComponents.GetElementAt(i, getter_AddRefs(supports));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
component = do_QueryInterface(supports, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
rv = AttemptRegistration(component, PR_TRUE /* deferred */);
|
||||
if (rv != NS_ERROR_FACTORY_REGISTER_AGAIN) {
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*aRegistered = PR_TRUE;
|
||||
mDeferredComponents.RemoveElementAt(i);
|
||||
}
|
||||
}
|
||||
rv = mDeferredComponents.Count(&count);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (*aRegistered)
|
||||
printf("mJCL: registered deferred, %d left\n", count);
|
||||
else
|
||||
printf("mJCL: didn't register any components, %d left\n", count);
|
||||
}
|
||||
/* are there any fatal errors? */
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unload all components that are willing.
|
||||
*/
|
||||
/* void unloadAll (in long aWhen); */
|
||||
NS_IMETHODIMP bcJavaComponentLoader::UnloadAll(PRInt32 aWhen) { //nb
|
||||
printf("--bcJavaComponentLoader::UnloadAll \n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
/* XXX this should all be data-driven, via NS_IMPL_GETMODULE_WITH_CATEGORIES */
|
||||
static NS_METHOD
|
||||
RegisterJavaLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
const char *registryLocation, const char *componentType)
|
||||
{
|
||||
printf("--JavaLoader got registered\n");
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString previous;
|
||||
return catman->AddCategoryEntry("component-loader", javaComponentTypeName,
|
||||
BC_JAVACOMPONENTLOADER_PROGID,
|
||||
PR_TRUE, PR_TRUE, getter_Copies(previous));
|
||||
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
UnregisterJavaLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
const char *registryLocation)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_PROGID, &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_PROGID)) {
|
||||
return catman->DeleteCategoryEntry("component-loader",
|
||||
javaComponentTypeName, PR_TRUE,
|
||||
getter_Copies(javaLoader));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaComponentLoader);
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Java component loader", BC_JAVACOMPONENTLOADER_CID,
|
||||
BC_JAVACOMPONENTLOADER_PROGID,
|
||||
bcJavaComponentLoaderConstructor,
|
||||
RegisterJavaLoader, UnregisterJavaLoader }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("Java component loader", components);
|
||||
|
||||
|
||||
|
||||
67
mozilla/java/xpcom/java/loader/bcJavaComponentLoader.h
Normal file
67
mozilla/java/xpcom/java/loader/bcJavaComponentLoader.h
Normal 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_PROGID \
|
||||
"component://netscape/blackwood/blackconnect/java-component-loader"
|
||||
|
||||
/* 0d6b5198-1dd2-11b2-b2f0-ed49ba755db8 */
|
||||
#define BC_JAVACOMPONENTLOADER_CID \
|
||||
{ 0x0d6b5198, 0x1dd2, 0x11b2, \
|
||||
{0xb2, 0xf0, 0xed, 0x49, 0xba, 0x75, 0x5d, 0xb8 }}
|
||||
|
||||
#define JAVACOMPONENTTYPENAME "text/java"
|
||||
|
||||
class bcJavaComponentLoader : public nsIComponentLoader {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOMPONENTLOADER
|
||||
|
||||
bcJavaComponentLoader();
|
||||
virtual ~bcJavaComponentLoader();
|
||||
protected:
|
||||
nsHashtable mModules;
|
||||
nsCOMPtr<nsIRegistry> mRegistry;
|
||||
nsIComponentManager* mCompMgr; // weak ref, should make it strong?
|
||||
nsRegistryKey mXPCOMKey;
|
||||
nsSupportsArray mDeferredComponents;
|
||||
|
||||
nsresult RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
|
||||
nsresult AttemptRegistration(nsIFile *component, PRBool deferred);
|
||||
nsIModule * ModuleForLocation(const char *registryLocation, nsIFile *component);
|
||||
PRBool HasChanged(const char *registryLocation, nsIFile *component);
|
||||
nsresult SetRegistryInfo(const char *registryLocation, nsIFile *component);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
88
mozilla/java/xpcom/java/loader/bcJavaModule.cpp
Normal file
88
mozilla/java/xpcom/java/loader/bcJavaModule.cpp
Normal 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], progid[1000], desc[1000];
|
||||
in.getline(cidStr,1000);
|
||||
in.getline(progid,1000);
|
||||
in.getline(desc,1000);
|
||||
printf("%s %s %s", cidStr, progid, desc);
|
||||
nsCID cid;
|
||||
cid.Parse((const char *)cidStr);
|
||||
aCompMgr->RegisterComponentWithType(cid, desc, progid, _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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
35
mozilla/java/xpcom/java/loader/bcJavaModule.h
Normal file
35
mozilla/java/xpcom/java/loader/bcJavaModule.h
Normal 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
|
||||
48
mozilla/java/xpcom/java/loader/makefile.win
Normal file
48
mozilla/java/xpcom/java/loader/makefile.win
Normal 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
|
||||
35
mozilla/java/xpcom/java/makefile.win
Normal file
35
mozilla/java/xpcom/java/makefile.win
Normal file
@@ -0,0 +1,35 @@
|
||||
#!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= \
|
||||
loader \
|
||||
src \
|
||||
classes \
|
||||
test \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
|
||||
81
mozilla/java/xpcom/java/src/Makefile.in
Normal file
81
mozilla/java/xpcom/java/src/Makefile.in
Normal file
@@ -0,0 +1,81 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
|
||||
DEPTH =../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = bcjavastubs
|
||||
MODULE = bcjavastubs
|
||||
IS_COMPONENT = 1
|
||||
|
||||
EXPORTS = \
|
||||
bcJavaStubsAndProxies.h
|
||||
|
||||
CPPSRCS = \
|
||||
bcJavaMarshalToolkit.cpp \
|
||||
bcJavaStub.cpp \
|
||||
bcJavaGlobal.cpp \
|
||||
bcJavaStubsAndProxies.cpp \
|
||||
bcIIDJava.cpp \
|
||||
org_mozilla_xpcom_Utilities.cpp \
|
||||
$(NULL)
|
||||
|
||||
CXXFLAGS += -I$(JDKHOME)/include -I$(JDKHOME)/include/linux $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
|
||||
|
||||
|
||||
DSO_LDOPTS += \
|
||||
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/ \
|
||||
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/classic \
|
||||
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/native_threads \
|
||||
-ljvm -lhpi -ljava\
|
||||
$(NULL)
|
||||
|
||||
#DSO_LDOPTS += \
|
||||
# -L$(JDKHOME)/jre/bin \
|
||||
# -L$(JDKHOME)/jre/bin/classic \
|
||||
# -ljvm \
|
||||
# $(NULL)
|
||||
|
||||
ifneq ($(OS_ARCH), Linux)
|
||||
DSO_LDOPTS += \
|
||||
-lthread -lXm -lX11 -lXt -lm
|
||||
endif
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
-L$(DIST)/bin/components/ \
|
||||
-lbcorb \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
|
||||
|
||||
99
mozilla/java/xpcom/java/src/bcIIDJava.cpp
Normal file
99
mozilla/java/xpcom/java/src/bcIIDJava.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
#include "bcIIDJava.h"
|
||||
#include "bcJavaGlobal.h"
|
||||
|
||||
jclass bcIIDJava::iidClass = NULL;
|
||||
jmethodID bcIIDJava::iidInitMID = NULL;
|
||||
jmethodID bcIIDJava::getStringMID = NULL;
|
||||
|
||||
|
||||
void bcIIDJava::Init(void) {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
if (env) {
|
||||
if (!(iidClass = env->FindClass("org/mozilla/xpcom/IID"))
|
||||
|| !(iidClass = (jclass) env->NewGlobalRef(iidClass))) {
|
||||
env->ExceptionDescribe();
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
if (!(iidInitMID = env->GetMethodID(iidClass,"<init>","(Ljava/lang/String;)V"))) {
|
||||
env->ExceptionDescribe();
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
if (!(getStringMID = env->GetMethodID(iidClass,"getString","()Ljava/lang/String;"))) {
|
||||
env->ExceptionDescribe();
|
||||
Destroy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void bcIIDJava::Destroy() {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
if (env) {
|
||||
if (iidClass) {
|
||||
env->DeleteGlobalRef(iidClass);
|
||||
iidClass = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jobject bcIIDJava::GetObject(nsIID *iid) {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
if (!iid
|
||||
|| !env ) {
|
||||
return NULL;
|
||||
}
|
||||
if (!iidClass) {
|
||||
Init();
|
||||
}
|
||||
char *str = iid->ToString(); //nb free ?
|
||||
jstring jstr = NULL;
|
||||
if (str) {
|
||||
char *siid = str+1; //we do need to have it. The format is {_xxx-xxx-xxx_}
|
||||
siid[strlen(siid)-1] = 0;
|
||||
jstr = env->NewStringUTF((const char *)siid);
|
||||
}
|
||||
return env->NewObject(iidClass,iidInitMID,jstr);
|
||||
}
|
||||
|
||||
jclass bcIIDJava::GetClass() {
|
||||
return iidClass;
|
||||
}
|
||||
|
||||
nsIID bcIIDJava::GetIID(jobject obj) {
|
||||
nsIID iid;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
if (env) {
|
||||
if (!iidClass) {
|
||||
Init();
|
||||
}
|
||||
jstring jstr = (jstring)env->CallObjectMethod(obj, getStringMID);
|
||||
const char * str = NULL;
|
||||
str = env->GetStringUTFChars(jstr,NULL);
|
||||
iid.Parse(str);
|
||||
env->ReleaseStringUTFChars(jstr,str);
|
||||
|
||||
}
|
||||
return iid;
|
||||
}
|
||||
41
mozilla/java/xpcom/java/src/bcIIDJava.h
Normal file
41
mozilla/java/xpcom/java/src/bcIIDJava.h
Normal 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
|
||||
113
mozilla/java/xpcom/java/src/bcJavaGlobal.cpp
Normal file
113
mozilla/java/xpcom/java/src/bcJavaGlobal.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/* -*- 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;
|
||||
|
||||
#ifdef XP_PC
|
||||
#define PATH_SEPARATOR ';'
|
||||
#else
|
||||
#define PATH_SEPARATOR ':'
|
||||
#endif
|
||||
|
||||
#ifdef JRI_MD_H //we are using jni.h from netscape
|
||||
#define JNIENV
|
||||
#else
|
||||
#define JNIENV (void**)
|
||||
#endif
|
||||
|
||||
JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
|
||||
JNIEnv * env;
|
||||
int res;
|
||||
if (!jvm) {
|
||||
StartJVM();
|
||||
}
|
||||
if (jvm) {
|
||||
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
|
||||
void bcJavaGlobal::StartJVM() {
|
||||
printf("--bcJavaGlobal::StartJVM begin\n");
|
||||
JNIEnv *env = NULL;
|
||||
jint res;
|
||||
jsize jvmCount;
|
||||
JNI_GetCreatedJavaVMs(&jvm, 1, &jvmCount);
|
||||
printf("--bcJavaGlobal::StartJVM after GetCreatedJavaVMs\n");
|
||||
if (jvmCount) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
JDK1_1InitArgs vm_args;
|
||||
char classpath[1024];
|
||||
JNI_GetDefaultJavaVMInitArgs(&vm_args);
|
||||
printf("--[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"));
|
||||
printf("--[c++] classpath %s\n",classpath);
|
||||
char **props = new char*[2];
|
||||
props[0]="java.compiler=NONE";
|
||||
props[1]=0;
|
||||
vm_args.properties = props;
|
||||
vm_args.classpath = classpath;
|
||||
/* Create the Java VM */
|
||||
res = JNI_CreateJavaVM(&jvm, JNIENV &env, &vm_args);
|
||||
#else
|
||||
char classpath[1024];
|
||||
JavaVMInitArgs vm_args;
|
||||
JavaVMOption options[2];
|
||||
sprintf(classpath, "-Djava.class.path=%s",PR_GetEnv("CLASSPATH"));
|
||||
printf("--[c++] classpath %s\n",classpath);
|
||||
options[0].optionString = classpath;
|
||||
options[1].optionString=""; //-Djava.compiler=NONE";
|
||||
vm_args.version = 0x00010002;
|
||||
vm_args.options = options;
|
||||
vm_args.nOptions = 2;
|
||||
vm_args.ignoreUnrecognized = JNI_TRUE;
|
||||
/* Create the Java VM */
|
||||
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
|
||||
#endif
|
||||
printf("--bcJavaGlobal::StartJVM jvm started res %d\n",res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
34
mozilla/java/xpcom/java/src/bcJavaGlobal.h
Normal file
34
mozilla/java/xpcom/java/src/bcJavaGlobal.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* -*- 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"
|
||||
|
||||
class bcJavaGlobal {
|
||||
public:
|
||||
static JNIEnv * GetJNIEnv(void);
|
||||
private:
|
||||
static JavaVM *jvm;
|
||||
static void StartJVM(void);
|
||||
};
|
||||
#endif
|
||||
787
mozilla/java/xpcom/java/src/bcJavaMarshalToolkit.cpp
Normal file
787
mozilla/java/xpcom/java/src/bcJavaMarshalToolkit.cpp
Normal file
@@ -0,0 +1,787 @@
|
||||
/* -*- 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"
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
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;
|
||||
}
|
||||
jobject object = env->GetObjectArrayElement(args,i);
|
||||
r = MarshalElement(m, object, param.IsOut(), ¶m, XPTType2bcXPType(param.GetType().TagPart()), i);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
nsresult bcJavaMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
|
||||
printf("--nsresult bcJavaMarshalToolkit::UnMarshal\n");
|
||||
bcIAllocator * allocator = new javaAllocator(nsAllocator::GetGlobalAllocator());
|
||||
PRUint32 paramCount = info->GetParamCount();
|
||||
jobject value;
|
||||
for (unsigned int i = 0; i < paramCount; i++) {
|
||||
nsXPTParamInfo param = info->GetParam(i);
|
||||
PRBool isOut = param.IsOut();
|
||||
nsXPTType type = param.GetType();
|
||||
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, ¶m, XPTType2bcXPType(type.TagPart()),allocator);
|
||||
env->SetObjectArrayElement(args,i,value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
UnMarshalElement(&value, i, um, isOut, ¶m, XPTType2bcXPType(type.TagPart()),allocator);
|
||||
env->SetObjectArrayElement(args,i,value);
|
||||
}
|
||||
delete allocator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define MARSHAL_SIMPLE_ELEMENT(_type_,_Type_) \
|
||||
do { \
|
||||
int indexInArray; \
|
||||
j##_type_ data; \
|
||||
if (! isOut \
|
||||
&& (modifier == none)) { \
|
||||
data = env->Call##_Type_##Method(value,_type_##ValueMID); \
|
||||
} 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); \
|
||||
} \
|
||||
m->WriteSimple(&data,type); \
|
||||
} while (0)
|
||||
|
||||
nsresult
|
||||
bcJavaMarshalToolkit::MarshalElement(bcIMarshaler *m, jobject value, PRBool isOut, nsXPTParamInfo * param,
|
||||
bcXPType type, uint8 ind, ArrayModifier modifier) {
|
||||
nsresult r = NS_OK;
|
||||
|
||||
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);
|
||||
}
|
||||
char * str = NULL;
|
||||
if (data) {
|
||||
str = (char*)env->GetStringUTFChars((jstring)data,NULL);
|
||||
m->WriteString(str,strlen(str)+1);
|
||||
env->ReleaseStringUTFChars(data,str);
|
||||
} 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);
|
||||
}
|
||||
nsIID iid = bcIIDJava::GetIID(data);
|
||||
m->WriteSimple(&iid, type);
|
||||
break;
|
||||
}
|
||||
|
||||
case bc_T_INTERFACE:
|
||||
{
|
||||
int indexInArray;
|
||||
jobject data = NULL;
|
||||
printf("--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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
if (m != NULL) {
|
||||
PRUint32 arraySize = (arrayValue == NULL) ? 0 : env->GetArrayLength((jarray)arrayValue);
|
||||
m->WriteSimple(&arraySize,bc_T_U32);
|
||||
for (PRUint32 i = 0; i < arraySize; i++) {
|
||||
MarshalElement(m,arrayValue,PR_FALSE,param,type,i,arrayElement);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("--it should not happend\n");
|
||||
;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#define UNMARSHAL_SIMPLE_ELEMENT(_type_,_Type_) \
|
||||
do { \
|
||||
int indexInArray; \
|
||||
j##_type_ data; \
|
||||
if (um) { \
|
||||
um->ReadSimple(&data,type); \
|
||||
} \
|
||||
if ( ! isOut \
|
||||
&& (modifier == none) ) { \
|
||||
*value = env->NewObject(_type_##Class,_type_##InitMID,data); \
|
||||
} else if (isOut && (modifier == array)) { \
|
||||
*value = env->NewObjectArray(1, _type_##ArrayClass, NULL); \
|
||||
} else if (isOut \
|
||||
|| (modifier == array)) { \
|
||||
int arraySize; \
|
||||
arraySize = (modifier == array) ? ind : 1; \
|
||||
*value = env->New##_Type_##Array(arraySize); \
|
||||
} \
|
||||
if (modifier == arrayElement \
|
||||
|| (isOut && (modifier == none)) \
|
||||
) { \
|
||||
indexInArray = (modifier == arrayElement) ? ind : 0; \
|
||||
env->Set##_Type_##ArrayRegion((j##_type_##Array)*value, indexInArray, 1, &data); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
nsresult
|
||||
bcJavaMarshalToolkit::UnMarshalElement(jobject *value, uint8 ind, bcIUnMarshaler *um, int isOut, nsXPTParamInfo * param,
|
||||
bcXPType type, bcIAllocator *allocator, ArrayModifier modifier) {
|
||||
switch(type) {
|
||||
case bc_T_I8:
|
||||
case bc_T_U8:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(byte,Byte);
|
||||
break;
|
||||
}
|
||||
case bc_T_I16:
|
||||
case bc_T_U16:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(short,Short);
|
||||
break;
|
||||
};
|
||||
case bc_T_I32:
|
||||
case bc_T_U32:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(int,Int);
|
||||
break;
|
||||
}
|
||||
case bc_T_I64:
|
||||
case bc_T_U64:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(long,Long);
|
||||
break;
|
||||
}
|
||||
case bc_T_FLOAT:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(float,Float);
|
||||
break;
|
||||
}
|
||||
|
||||
case bc_T_DOUBLE:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(double,Double);
|
||||
break;
|
||||
}
|
||||
case bc_T_BOOL:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(boolean,Boolean);
|
||||
break;
|
||||
}
|
||||
case bc_T_CHAR:
|
||||
case bc_T_WCHAR:
|
||||
{
|
||||
UNMARSHAL_SIMPLE_ELEMENT(char,Char);
|
||||
break;
|
||||
}
|
||||
case bc_T_CHAR_STR:
|
||||
case bc_T_WCHAR_STR: //nb not sure about this
|
||||
{
|
||||
int indexInArray;
|
||||
size_t size;
|
||||
jstring data = NULL;
|
||||
if (um) {
|
||||
um->ReadString(&data,&size,allocator);
|
||||
data = env->NewStringUTF((const char*)data);
|
||||
}
|
||||
if ( ! isOut
|
||||
&& (modifier == none) ) {
|
||||
*value = data;
|
||||
} else if (isOut && (modifier == array)) {
|
||||
*value = env->NewObjectArray(1, stringArrayClass, NULL);
|
||||
} else if (isOut
|
||||
|| (modifier == array)) {
|
||||
int arraySize;
|
||||
arraySize = (modifier == array) ? ind : 1;
|
||||
*value = env->NewObjectArray(arraySize,stringClass,NULL);
|
||||
}
|
||||
if (modifier == arrayElement
|
||||
|| (isOut && (modifier == none))
|
||||
) {
|
||||
indexInArray = (modifier == arrayElement) ? ind : 0;
|
||||
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
|
||||
}
|
||||
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);
|
||||
} else if (isOut
|
||||
|| (modifier == array)) {
|
||||
int arraySize;
|
||||
arraySize = (modifier == array) ? ind : 1;
|
||||
*value = env->NewObjectArray(arraySize,iidClass,NULL);
|
||||
}
|
||||
if (modifier == arrayElement
|
||||
|| (isOut && (modifier == none))
|
||||
) {
|
||||
indexInArray = (modifier == arrayElement) ? ind : 0;
|
||||
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case bc_T_INTERFACE:
|
||||
{
|
||||
printf("--[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);
|
||||
printf("%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)) { //how to create type[][] ?
|
||||
jobject arrayObject;
|
||||
arrayObject = env->NewObjectArray(1,clazz,NULL);
|
||||
jclass arrayClass = (jclass) env->CallObjectMethod(arrayObject,getClassMID); //nb how to to it better ?
|
||||
*value = env->NewObjectArray(1, arrayClass, NULL);
|
||||
} else if (isOut
|
||||
|| (modifier == array)) {
|
||||
int arraySize;
|
||||
arraySize = (modifier == array) ? ind : 1;
|
||||
*value = env->NewObjectArray(arraySize,clazz,NULL);
|
||||
}
|
||||
if (modifier == arrayElement
|
||||
|| (isOut && (modifier == none))
|
||||
) {
|
||||
indexInArray = (modifier == arrayElement) ? ind : 0;
|
||||
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
} 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("[Ljava/lang/Boolean;"))
|
||||
|| !(booleanArrayClass = (jclass) env->NewGlobalRef(clazz))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(clazz = env->FindClass("java/lang/Character"))
|
||||
|| !(charClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Character;"))
|
||||
|| !(charArrayClass = (jclass) env->NewGlobalRef(clazz))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
if (!(clazz = env->FindClass("java/lang/Byte"))
|
||||
|| !(byteClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Byte;"))
|
||||
|| !(byteArrayClass = (jclass) env->NewGlobalRef(clazz))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
if (!(clazz = env->FindClass("java/lang/Short"))
|
||||
|| !(shortClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Short;"))
|
||||
|| !(shortArrayClass = (jclass) env->NewGlobalRef(clazz))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
if (!(clazz = env->FindClass("java/lang/Integer"))
|
||||
|| !(intClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Integer;"))
|
||||
|| !(intArrayClass = (jclass) env->NewGlobalRef(clazz))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
if (!(clazz = env->FindClass("java/lang/Long"))
|
||||
|| !(longClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Long;"))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
if (!(clazz = env->FindClass("java/lang/Float"))
|
||||
|| !(floatClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Float;"))
|
||||
|| !(floatArrayClass = (jclass) env->NewGlobalRef(clazz))
|
||||
) {
|
||||
DeInitializeStatic();
|
||||
return;
|
||||
}
|
||||
if (!(clazz = env->FindClass("java/lang/Double"))
|
||||
|| !(doubleClass = (jclass) env->NewGlobalRef(clazz))
|
||||
|| !(clazz = env->FindClass("[Ljava/lang/Double;"))
|
||||
|| !(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
|
||||
printf("--[c++]void bcJavaMarshalToolkit::DeInitializeStatic() - boomer \n");
|
||||
}
|
||||
|
||||
115
mozilla/java/xpcom/java/src/bcJavaMarshalToolkit.h
Normal file
115
mozilla/java/xpcom/java/src/bcJavaMarshalToolkit.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* -*- 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 UnMarshal(bcIUnMarshaler *);
|
||||
private:
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
40
mozilla/java/xpcom/java/src/bcJavaProxy.h
Normal file
40
mozilla/java/xpcom/java/src/bcJavaProxy.h
Normal 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 __bcJavaProxy_h
|
||||
#define __bcJavaProxy_h
|
||||
#include "jni.h"
|
||||
#include "bcDefs.h"
|
||||
#include "bcIORB.h"
|
||||
|
||||
class bcJavaProxy {
|
||||
public:
|
||||
bcJavaProxy(bcOID oid, bcIID * iid, bcIORB *orb);
|
||||
virtual ~bcJavaProxy();
|
||||
jobject GetObject();
|
||||
private:
|
||||
bcIORB *orb;
|
||||
bcOID oid;
|
||||
bcIID iid;
|
||||
|
||||
};
|
||||
#endif
|
||||
116
mozilla/java/xpcom/java/src/bcJavaStub.cpp
Normal file
116
mozilla/java/xpcom/java/src/bcJavaStub.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- 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) {
|
||||
printf("--bcJavaStub::bcJavaStub \n");
|
||||
if (!obj) {
|
||||
printf("--bcJavaStub::bcJavaStub obj== 0\n");
|
||||
return;
|
||||
}
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
object = env->NewGlobalRef(obj);
|
||||
}
|
||||
|
||||
|
||||
bcJavaStub::~bcJavaStub() {
|
||||
bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object);
|
||||
}
|
||||
|
||||
void bcJavaStub::Dispatch(bcICall *call) {
|
||||
//sigsend(P_PID, getpid(),SIGINT);
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
bcIID iid; bcOID oid; bcMID mid;
|
||||
jobjectArray args;
|
||||
call->GetParams(&iid, &oid, &mid);
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
return; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (!objectClass) {
|
||||
Init();
|
||||
if (!objectClass) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
nsXPTMethodInfo* info;
|
||||
interfaceInfo->GetMethodInfo(mid,(const nsXPTMethodInfo **)&info);
|
||||
PRUint32 paramCount = info->GetParamCount();
|
||||
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);
|
||||
bcJavaGlobal::GetJNIEnv()->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args);
|
||||
//nb return value; excepion handling
|
||||
bcIMarshaler * m = call->GetMarshaler();
|
||||
mt->Marshal(m);
|
||||
//nb memory deallocation
|
||||
delete m; delete um; delete mt;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void bcJavaStub::Init() {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
objectClass = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Object"));
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
return;
|
||||
}
|
||||
|
||||
utilitiesClass = (jclass)env->NewGlobalRef(env->FindClass("org/mozilla/xpcom/Utilities"));
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
return;
|
||||
}
|
||||
callMethodByIndexMID = env->GetStaticMethodID(utilitiesClass,"callMethodByIndex","(Ljava/lang/Object;Lorg/mozilla/xpcom/IID;I[Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
41
mozilla/java/xpcom/java/src/bcJavaStub.h
Normal file
41
mozilla/java/xpcom/java/src/bcJavaStub.h
Normal 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 __bcJavaStub_h
|
||||
#define __bcJavaStub_h
|
||||
#include "bcIStub.h"
|
||||
#include "jni.h"
|
||||
|
||||
class bcJavaStub : public bcIStub {
|
||||
public:
|
||||
bcJavaStub(jobject obj);
|
||||
virtual ~bcJavaStub();
|
||||
virtual void Dispatch(bcICall *call) ;
|
||||
private:
|
||||
jobject object;
|
||||
static jclass objectClass;
|
||||
static jclass utilitiesClass;
|
||||
static jmethodID callMethodByIndexMID;
|
||||
void Init();
|
||||
};
|
||||
|
||||
#endif
|
||||
175
mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.cpp
Normal file
175
mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
#include "bcJavaStubsAndProxies.h"
|
||||
#include "bcJavaStub.h"
|
||||
#include "bcJavaGlobal.h"
|
||||
#include "bcORB.h"
|
||||
#include "bcIIDJava.h"
|
||||
|
||||
jclass bcJavaStubsAndProxies::componentLoader = 0;
|
||||
jmethodID bcJavaStubsAndProxies::loadComponentID = 0;
|
||||
|
||||
jclass bcJavaStubsAndProxies::proxyFactory = 0;
|
||||
jmethodID bcJavaStubsAndProxies::getProxyID = 0;
|
||||
jmethodID bcJavaStubsAndProxies::getInterfaceID = 0;
|
||||
|
||||
NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaStubsAndProxies);
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{
|
||||
"Black Connect Java stubs and proxies",
|
||||
BC_JAVASTUBSANDPROXIES_CID,
|
||||
BC_JAVASTUBSANDPROXIES_PROGID,
|
||||
bcJavaStubsAndProxiesConstructor
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("BlackConnect Java stubs and proxies",components);
|
||||
|
||||
NS_IMPL_ISUPPORTS(bcJavaStubsAndProxies,NS_GET_IID(bcJavaStubsAndProxies));
|
||||
|
||||
|
||||
bcJavaStubsAndProxies::bcJavaStubsAndProxies() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
bcJavaStubsAndProxies::~bcJavaStubsAndProxies() {
|
||||
}
|
||||
|
||||
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) {
|
||||
printf("--[c++] bcJavaStubsAndProxies::GetProxy\n");
|
||||
if (!componentLoader) {
|
||||
Init();
|
||||
}
|
||||
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
|
||||
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetInterface(const nsIID &iid, jclass *clazz) {
|
||||
printf("--[c++] bcJavaStubsAndProxies::GetInterface\n");
|
||||
if (!componentLoader) {
|
||||
Init();
|
||||
}
|
||||
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
|
||||
*clazz = (jclass)env->CallStaticObjectMethod(proxyFactory,getInterfaceID, jiid);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) {
|
||||
bcIStub *stub = new bcJavaStub(object);
|
||||
*oid = orb->RegisterStub(stub);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
|
||||
printf("--bcJavaStubsAndProxies::GetOID %s\n",location);
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
nsresult result;
|
||||
|
||||
if (!componentLoader) {
|
||||
Init();
|
||||
}
|
||||
//location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info
|
||||
strcpy(location + strlen(location)-4,"comp");
|
||||
jstring jstr = env->NewStringUTF(location);
|
||||
jobject object = env->CallStaticObjectMethod(componentLoader, loadComponentID, jstr);
|
||||
bcIStub *stub = new bcJavaStub(object);
|
||||
NS_WITH_SERVICE(bcORB,_orb,kORBCIID,&result);
|
||||
if (NS_FAILED(result)) {
|
||||
printf("--bcJavaStubsAndProxies::GetOID failed\n");
|
||||
return result;
|
||||
}
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
*oid = orb->RegisterStub(stub);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void bcJavaStubsAndProxies::Init(void) {
|
||||
printf("--[c++]bcJavaStubsAndProxies::Init\n");
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
componentLoader = env->FindClass("org/mozilla/xpcom/ComponentLoader");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
componentLoader = (jclass)env->NewGlobalRef(componentLoader);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
proxyFactory = (jclass)env->NewGlobalRef(proxyFactory);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
getInterfaceID = env->GetStaticMethodID(proxyFactory, "getInterface","(Lorg/mozilla/xpcom/IID;)Ljava/lang/Class;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
66
mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.h
Normal file
66
mozilla/java/xpcom/java/src/bcJavaStubsAndProxies.h
Normal 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>
|
||||
*/
|
||||
#ifndef __bcJavaStubsAndProxies_h
|
||||
#define __bcJavaStubsAndProxies_h
|
||||
#include "nsISupports.h"
|
||||
#include "jni.h"
|
||||
#include "bcDefs.h"
|
||||
#include "bcIStub.h"
|
||||
#include "bcIORB.h"
|
||||
|
||||
/* 58034ea6-1dd2-11b2-9b58-8630abb8af47 */
|
||||
|
||||
#define BC_JAVASTUBSANDPROXIES_IID \
|
||||
{0x58034ea6, 0x1dd2, 0x11b2, \
|
||||
{0x9b, 0x58, 0x86, 0x30, 0xab, 0xb8, 0xaf,0x47}}
|
||||
|
||||
#define BC_JAVASTUBSANDPROXIES_PROGID "component://netscape/blackwood/blackconnect/java-stubs-and-proxies"
|
||||
|
||||
/* 7cadf6e8-1dd2-11b2-9a6e-b1c37844e004 */
|
||||
#define BC_JAVASTUBSANDPROXIES_CID \
|
||||
{0x7cadf6e8, 0x1dd2, 0x11b2, \
|
||||
{0x9a, 0x6e, 0xb1, 0xc3, 0x78,0x44, 0xe0, 0x04}}
|
||||
|
||||
class bcJavaStubsAndProxies : public nsISupports {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(BC_JAVASTUBSANDPROXIES_IID)
|
||||
NS_IMETHOD GetStub(jobject obj, bcIStub **stub);
|
||||
NS_IMETHOD GetOID(char *location, bcOID *); //load component by location
|
||||
NS_IMETHOD GetOID(jobject object, bcIORB *orb, bcOID *oid);
|
||||
NS_IMETHOD GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy);
|
||||
NS_IMETHOD GetInterface(const nsIID &iid, jclass *clazz);
|
||||
bcJavaStubsAndProxies();
|
||||
virtual ~bcJavaStubsAndProxies();
|
||||
protected:
|
||||
void Init(void);
|
||||
static jclass componentLoader;
|
||||
static jmethodID loadComponentID;
|
||||
static jclass proxyFactory;
|
||||
static jmethodID getProxyID;
|
||||
static jmethodID getInterfaceID;
|
||||
};
|
||||
|
||||
#endif /* __bcJavaStubsAndProxies_h */
|
||||
|
||||
|
||||
|
||||
|
||||
54
mozilla/java/xpcom/java/src/makefile.win
Normal file
54
mozilla/java/xpcom/java/src/makefile.win
Normal file
@@ -0,0 +1,54 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
MODULE=bcjavastubs
|
||||
COMPONENT = 1
|
||||
DLLNAME = bcjavastubs
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
EXPORTS = \
|
||||
bcJavaStubsAndProxies.h
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\bcJavaMarshalToolkit.obj \
|
||||
.\$(OBJDIR)\bcJavaStub.obj \
|
||||
.\$(OBJDIR)\bcJavaGlobal.obj \
|
||||
.\$(OBJDIR)\bcJavaStubsAndProxies.obj \
|
||||
.\$(OBJDIR)\bcIIDJava.obj \
|
||||
.\$(OBJDIR)\org_mozilla_xpcom_Utilities.obj \
|
||||
$(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
|
||||
71
mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.cpp
Normal file
71
mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- 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 "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"
|
||||
|
||||
/*
|
||||
* 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;
|
||||
printf("--[c++] jni Java_org_mozilla_xpcom_Utilities_callMethodByIndex %d\n",(int)mid);
|
||||
const char * str = NULL;
|
||||
str = env->GetStringUTFChars(jiid,NULL);
|
||||
iid.Parse(str);
|
||||
env->ReleaseStringUTFChars(jiid,str);
|
||||
bcICall *call = orb->CreateCall(&iid, &oid, mid);
|
||||
|
||||
/*****/
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if( (iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
return NULL; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
/*****/
|
||||
bcIMarshaler * m = call->GetMarshaler();
|
||||
bcJavaMarshalToolkit * mt = new bcJavaMarshalToolkit((unsigned)mid, interfaceInfo, args, env, 0, orb);
|
||||
mt->Marshal(m);
|
||||
orb->SendReceive(call);
|
||||
bcIUnMarshaler * um = call->GetUnMarshaler();
|
||||
mt->UnMarshal(um);
|
||||
delete m; delete um; delete mt;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
21
mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.h
Normal file
21
mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
52
mozilla/java/xpcom/java/test/Makefile.in
Normal file
52
mozilla/java/xpcom/java/test/Makefile.in
Normal 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 Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = ../../../..
|
||||
srcdir = .
|
||||
VPATH = .
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = javaSample
|
||||
LIBRARY_NAME = javaSample
|
||||
IS_COMPONENT = 1
|
||||
XPIDL_MODULE = javaSample
|
||||
XPIDLSRCS = bcIJavaSample.idl
|
||||
CPPSRCS = bcJavaSample.cpp
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
|
||||
$(JDKHOME)/bin/jar cvfm bcJavaSample.jar.comp manifest *.class
|
||||
.java.class:
|
||||
$(JDKHOME)/bin/javac -classpath .:../classes $<
|
||||
install-component: bcJavaSample.jar.comp bcJavaSample.jar.info
|
||||
cp bcJavaSample.jar.comp bcJavaSample.jar.info $(DEPTH)/dist/bin/components/
|
||||
|
||||
clobber-java:
|
||||
rm -f *.class *.jar
|
||||
clobber:: clobber-java
|
||||
clobber_all:: clobber-java
|
||||
install:: install-component
|
||||
|
||||
12
mozilla/java/xpcom/java/test/bcIJavaSample.idl
Normal file
12
mozilla/java/xpcom/java/test/bcIJavaSample.idl
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(ca1e2656-1dd1-11b2-9c4e-f49ea557abde)]
|
||||
interface bcIJavaSample : nsISupports
|
||||
{
|
||||
void test0();
|
||||
void test1(in long l);
|
||||
void test2(in bcIJavaSample o);
|
||||
void test3(in PRUint32 count,[array, size_is(count)] in long valueArray);
|
||||
void test4(in PRUint32 count,[array, size_is(count)] inout string valueArray);
|
||||
|
||||
};
|
||||
19
mozilla/java/xpcom/java/test/bcIJavaSample.java
Normal file
19
mozilla/java/xpcom/java/test/bcIJavaSample.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Interface nsISample
|
||||
*
|
||||
* IID: 0xca1e2656-1dd1-11b2-9c4e-f49ea557abde
|
||||
*/
|
||||
|
||||
import org.mozilla.xpcom.*;
|
||||
|
||||
public interface bcIJavaSample
|
||||
{
|
||||
public static final String BC_IJAVASAMPLE_IID_STRING =
|
||||
"ca1e2656-1dd1-11b2-9c4e-f49ea557abde";
|
||||
void queryInterface(IID iid, Object[] result);
|
||||
void test0();
|
||||
void test1(int l);
|
||||
void test2(bcIJavaSample o);
|
||||
void test3(int count, int[] valueArray);
|
||||
void test4(int count, String[][] valueArray);
|
||||
}
|
||||
151
mozilla/java/xpcom/java/test/bcJavaSample.cpp
Normal file
151
mozilla/java/xpcom/java/test/bcJavaSample.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
/* -*- 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 "stdlib.h"
|
||||
|
||||
#define BC_JAVA_SAMPLE_CID \
|
||||
{0x072fa586, 0x1dd2, 0x11b2, \
|
||||
{ 0xb2, 0x3a, 0x81, 0xe8, 0x16, 0x49, 0xe8, 0x8b }}
|
||||
|
||||
#define BC_JAVA_SAMPLE_PROGID "javaSample.cpp"
|
||||
|
||||
|
||||
|
||||
class bcJavaSample : public bcIJavaSample {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_BCIJAVASAMPLE
|
||||
bcJavaSample();
|
||||
virtual ~bcJavaSample();
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(bcJavaSample, bcIJavaSample)
|
||||
|
||||
bcJavaSample::bcJavaSample()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
bcJavaSample::~bcJavaSample()
|
||||
{
|
||||
/* destructor code */
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaSample::Test0()
|
||||
{ printf("--[c++] bcJavaSample::Test0() \n");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void test1 (in long l); */
|
||||
NS_IMETHODIMP bcJavaSample::Test1(PRInt32 l)
|
||||
{
|
||||
printf("--[c++] bcJavaSample.test1 l=%d\n",l);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void test2 (in bcIJavaSample o); */
|
||||
NS_IMETHODIMP bcJavaSample::Test2(bcIJavaSample *o)
|
||||
{
|
||||
printf("--[c++] bcJavaSample.test2\n");
|
||||
o->Test0();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* void test3 (in PRUint32 count, [array, size_is (count)] in long valueArray); */
|
||||
NS_IMETHODIMP bcJavaSample::Test3(PRUint32 count, PRInt32 *valueArray) {
|
||||
printf("--[c++] bcJavaSample.test3 coutn %d\n",count);
|
||||
for(unsigned int i = 0; i < count; i++) {
|
||||
printf("--[c++] valueArray[%d]=%d\n",i,valueArray[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void test4 (in PRUint32 count, [array, size_is (count)] inout string valueArray); */
|
||||
NS_IMETHODIMP bcJavaSample::Test4(PRUint32 count, char ***valueArray) {
|
||||
printf("--[c++] bcJavaSample.test4 coutn %d\n",count);
|
||||
for(unsigned int i = 0; i < count; i++) {
|
||||
printf("--[c++] valueArray[%d]=%s\n",i,(*valueArray)[i]);
|
||||
}
|
||||
char ** array = (char **)malloc(sizeof(char*)*4);
|
||||
array[0] = "1";
|
||||
array[1] = "2";
|
||||
array[2] = "hello";
|
||||
array[3] = "world";
|
||||
*valueArray = array;
|
||||
return NS_OK;
|
||||
}
|
||||
void 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);
|
||||
//sigsend(P_PID, getpid(),SIGINT);
|
||||
//test->Test1(2000);
|
||||
#if 0
|
||||
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);
|
||||
#endif
|
||||
{
|
||||
char ** valueArray = (char **)malloc(sizeof(char*)*4);
|
||||
valueArray[0] = "hi";
|
||||
valueArray[1] = "there";
|
||||
valueArray[2] = "a";
|
||||
valueArray[3] = "b";
|
||||
char *** valueArray2 = &valueArray;
|
||||
test->Test4(4,valueArray2);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("valueArray2[%d]=%s\n",i,(*valueArray2)[i]);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
3
mozilla/java/xpcom/java/test/bcJavaSample.jar.info
Normal file
3
mozilla/java/xpcom/java/test/bcJavaSample.jar.info
Normal file
@@ -0,0 +1,3 @@
|
||||
6b701852-1dd2-11b2-91bd-d3ab05f89834
|
||||
bcJavaSample
|
||||
bcJavaSample
|
||||
102
mozilla/java/xpcom/java/test/bcJavaSample.java
Normal file
102
mozilla/java/xpcom/java/test/bcJavaSample.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
import org.mozilla.xpcom.*;
|
||||
import java.lang.reflect.*;
|
||||
public class bcJavaSample implements bcIJavaSample {
|
||||
public bcJavaSample() {
|
||||
System.out.println("--[java]bcJavaSample constructor");
|
||||
}
|
||||
public void queryInterface(IID iid, Object[] result) {
|
||||
System.out.println("--[java]bcJavaSample::queryInterface iid="+iid);
|
||||
if ( iid.equals(nsISupportsIID)
|
||||
|| iid.equals(bcIJavaSampleIID)) {
|
||||
result[0] = this;
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
public void test0() {
|
||||
System.out.println("--[java]bcJavaSample.test0 ");
|
||||
}
|
||||
public void test1(int l) {
|
||||
System.out.println("--[java]bcJavaSample.test1 "+l+"\n");
|
||||
}
|
||||
public void test2(bcIJavaSample o) {
|
||||
System.out.println("--[java]bcJavaSample.test2");
|
||||
System.out.println("--[java]bcJavaSample.test2 :)))) Hi there");
|
||||
if (o != null) {
|
||||
System.out.println("--[java]bcJavaSample.test2 o!= null");
|
||||
o.test0();
|
||||
o.test1(1000);
|
||||
o.test2(this);
|
||||
int[] array={3,2,1};
|
||||
o.test3(3,array);
|
||||
} 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]callMethodByIndex args["+i+"] = "+array[i]);
|
||||
}
|
||||
String[] returnArray = {"4","3","2","1"};
|
||||
valueArray[0] = returnArray;
|
||||
}
|
||||
static IID bcIJavaSampleIID;
|
||||
static IID nsISupportsIID;
|
||||
static {
|
||||
try {
|
||||
Method[] methods = null;
|
||||
Class bcIJavaSampleClass = Class.forName("bcIJavaSample");
|
||||
Class IIDClass = Class.forName("org.mozilla.xpcom.IID");
|
||||
methods = new Method[100];
|
||||
Class ObjectArrayClass = (new Object[1]).getClass();
|
||||
Class IntArrayClass = (new int[1]).getClass();
|
||||
Class StringArrayArrayClass = (new String[1][1]).getClass();
|
||||
methods[0] = bcIJavaSampleClass.getDeclaredMethod("queryInterface",new Class[]{IIDClass,ObjectArrayClass});
|
||||
methods[3] = bcIJavaSampleClass.getDeclaredMethod("test0",new Class[]{});
|
||||
methods[4] = bcIJavaSampleClass.getDeclaredMethod("test1",new Class[]{Integer.TYPE});
|
||||
methods[5] = bcIJavaSampleClass.getDeclaredMethod("test2",new Class[]{bcIJavaSampleClass});
|
||||
methods[6] = bcIJavaSampleClass.getDeclaredMethod("test3",new Class[]{Integer.TYPE,IntArrayClass});
|
||||
methods[7] = bcIJavaSampleClass.getDeclaredMethod("test4",new Class[]{Integer.TYPE,StringArrayArrayClass});
|
||||
System.out.println(methods[0]+" "+methods[3]+" "+methods[4]+" "+methods[5]+" "+methods[6]+" "+methods[7]);
|
||||
bcIJavaSampleIID = new IID(bcIJavaSample.BC_IJAVASAMPLE_IID_STRING);
|
||||
nsISupportsIID = new IID("00000000-0000-0000-c000-000000000046");
|
||||
ProxyFactory.registerInterfaceForIID(bcIJavaSampleClass,bcIJavaSampleIID);
|
||||
new ProxyClass(bcIJavaSampleIID, methods);
|
||||
//new ProxyClass(nsISupportsIID, methods);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
63
mozilla/java/xpcom/java/test/makefile.win
Normal file
63
mozilla/java/xpcom/java/test/makefile.win
Normal file
@@ -0,0 +1,63 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
|
||||
DEPTH = ..\..\..\..
|
||||
topsrcdir = ..\..\..\..
|
||||
srcdir = .
|
||||
VPATH = .
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
MODULE=javaSample
|
||||
COMPONENT=1
|
||||
DLLNAME=$(MODULE)
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\bcIJavaSample.idl \
|
||||
$(NULL)
|
||||
|
||||
OBJS = .\$(OBJDIR)\bcJavaSample.obj
|
||||
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
|
||||
$(JDKHOME)\bin\jar cvfm bcJavaSample.jar.comp manifest *.class
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath .;..\classes $<
|
||||
|
||||
install-component: bcJavaSample.jar.comp bcJavaSample.jar.info $(DLL)
|
||||
copy bcJavaSample.jar* $(DIST)\bin\components
|
||||
copy $(DLL) $(DIST)\bin\components
|
||||
|
||||
clobber-java:
|
||||
-del *.class *.jar.comp
|
||||
clobber:: clobber-java
|
||||
rm $(DIST)\bin\components\$(DLLNAME).dll
|
||||
rm $(DIST)\bin\components\bcJavaSample.jar.*
|
||||
clobber_all:: clobber-java
|
||||
install:: install-component
|
||||
1
mozilla/java/xpcom/java/test/manifest
Normal file
1
mozilla/java/xpcom/java/test/manifest
Normal file
@@ -0,0 +1 @@
|
||||
Component-Class: bcJavaSample
|
||||
34
mozilla/java/xpcom/makefile.win
Normal file
34
mozilla/java/xpcom/makefile.win
Normal file
@@ -0,0 +1,34 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Sun Microsystems,
|
||||
# Inc. Portions created by Sun are
|
||||
# Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
DEPTH = ..\..
|
||||
|
||||
DIRS= \
|
||||
connect \
|
||||
xpcom \
|
||||
java \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
|
||||
34
mozilla/java/xpcom/old/Makefile.in
Normal file
34
mozilla/java/xpcom/old/Makefile.in
Normal 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):
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS= classes \
|
||||
src \
|
||||
tools \
|
||||
$(NULL)
|
||||
# test \
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
155
mozilla/java/xpcom/old/README
Normal file
155
mozilla/java/xpcom/old/README
Normal file
@@ -0,0 +1,155 @@
|
||||
Java Bridge to XPCOM
|
||||
====================
|
||||
|
||||
This directory contains the beginnings of the Java Bridge to XPCOM.
|
||||
For now it is disconnected from the main Mozilla build, because as yet
|
||||
it is good for no more than a few demo and test programs, and because
|
||||
Java compilation on Unix and Linux doesn't work quite right (as of
|
||||
Aug 13, 1999).
|
||||
|
||||
The source is divided into four directories
|
||||
|
||||
classes
|
||||
Java source files
|
||||
src
|
||||
Native code (C++/C) for Java classes and stub support
|
||||
test
|
||||
Test code, including a dummy XPCOM component
|
||||
tools
|
||||
Support tools:
|
||||
|
||||
genproxy -- Generates Java source for a proxy class
|
||||
to an XPCOM object. (Eventually will
|
||||
generate bytecodes and interfaces.)
|
||||
|
||||
|
||||
Build
|
||||
-----
|
||||
|
||||
Currently only UNIX/Linux builds are supported (mainly because it's my
|
||||
platform of choice). Windows builds should not be too much more
|
||||
difficult, and
|
||||
|
||||
1. Make sure MOZILLA_FIVE_HOME is set to <mozilla-source-dir>/dist/bin,
|
||||
and that JDKHOME indicates a valid JDK 1.2 installation.
|
||||
|
||||
*IMPORTANT*: remove the jni.h, jni_md.h, and jri.h in mozilla/dist/bin,
|
||||
before compiling native code. Otherwise, the header
|
||||
mismatch will cause crashes in JNI code.
|
||||
|
||||
2. Insure that the following are in your LD_LIBRARY_PATH:
|
||||
|
||||
$MOZILLA_FIVE_HOME
|
||||
$MOZILLA_FIVE_HOME/../lib
|
||||
mozilla/java/xpcom/test (or "." if you run in that directory)
|
||||
mozilla/java/xpcom/src (or "../src" if you run in "test")
|
||||
|
||||
3. In mozilla/java/xpcom, execute
|
||||
|
||||
../../build/autoconf/update-makefile.sh
|
||||
|
||||
if necessary, to generate a Makefile, and then
|
||||
|
||||
gmake JAVAC="javac -g -d $MOZILLA_FIVE_HOME/../classes"
|
||||
|
||||
This is to get around bugs in Java compilation.
|
||||
|
||||
4. Change directories to mozilla/java/xpcom/test
|
||||
|
||||
5. Execute
|
||||
|
||||
gmake -f Makefile.test
|
||||
|
||||
This has the side effect of creating JSISample.xpt in the main
|
||||
Mozilla components directory; all other libraries, executables, and
|
||||
Java class files reside in the test directory.
|
||||
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
||||
Both tests use the JSSample component, whose methods do nothing more
|
||||
than print out the in and out arguments, and perhaps perform a simple
|
||||
operation.
|
||||
|
||||
xptest
|
||||
|
||||
This program takes the name of a JSSample method and a number
|
||||
of "in" parameters (coerced from strings to the expected
|
||||
data types), executes the method, and returns. It is mainly
|
||||
useful to test whether the "xpjava" native functions still
|
||||
work correctly, independently of the JVM.
|
||||
|
||||
Sample invocation:
|
||||
|
||||
./xptest AddTwoInts 1 1
|
||||
|
||||
Output:
|
||||
Starting ...
|
||||
Initializing XPCOM
|
||||
<some debugging messages>
|
||||
Registering Allocator
|
||||
Getting InterfaceInfoManager
|
||||
Registering Sample Factory
|
||||
AddTwoInts:
|
||||
0: type = 2, in
|
||||
1: type = 2, in
|
||||
2: type = 2, out, retval
|
||||
Consuming 1
|
||||
Consuming 1
|
||||
Arguments are:
|
||||
0) 1 : type 2, ptr=(nil)
|
||||
1) 1 : type 2, ptr=(nil)
|
||||
2) 7566446 : type 2, ptr=0x804fae8, data
|
||||
Calling XPTC_InvokeByIndex( 0x80932d0, 23, 3, 0x804fac8)
|
||||
Results are:
|
||||
0) 1 : type 2, ptr=(nil)
|
||||
1) 1 : type 2, ptr=(nil)
|
||||
2) 2 : type 2, ptr=0x804fae8, data
|
||||
|
||||
|
||||
XPCTest.main()
|
||||
|
||||
This is a Java version of xptest. Unlike xptest, each
|
||||
non-String argument to the method must be preceded by a flag
|
||||
indicating its type, out parameters require a "placeholder
|
||||
flag":
|
||||
|
||||
-c: char
|
||||
-b: byte
|
||||
-s: short
|
||||
-i: int
|
||||
-j, -l: long
|
||||
-f: float
|
||||
-d: double
|
||||
-z: boolean
|
||||
-r: placeholder for retval
|
||||
-0: placeholder for out param (equiv. to -r)
|
||||
|
||||
If the "command" argument is a number, XPCTest invokes the
|
||||
XPCOM method with that offset.
|
||||
|
||||
Sample invocation:
|
||||
|
||||
java -native XPCTest AddTwoInts -i 1 -i 1 -r
|
||||
|
||||
Output:
|
||||
|
||||
Initializing XPCOM
|
||||
Registering Allocator
|
||||
Getting InterfaceInfoManager
|
||||
Command: AddTwoInts, arguments: [1, 1, null]
|
||||
Results: [1, 1, 2]
|
||||
|
||||
Notes:
|
||||
|
||||
1. You must run native threads; Mozilla loads the native
|
||||
thread library, and the JVM will panic if it has to
|
||||
load both native and green threads.
|
||||
|
||||
2. Because of the way the JDK links shared libraries,
|
||||
you must have a valid mozilla/dist/bin/component.reg;
|
||||
otherwise, XPCOM will not bootstrap correctly.
|
||||
Note that "apprunner" and "xptest" will create one.
|
||||
Future versions will fix this limitation.
|
||||
|
||||
92
mozilla/java/xpcom/old/TODO
Normal file
92
mozilla/java/xpcom/old/TODO
Normal file
@@ -0,0 +1,92 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
(By no means complete ...)
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
-- *GET XPCTest WORKING*. For some reason, the JDK 1.2 JVM on Solaris
|
||||
won't load libxpcom.so correctly, even if it's on LD_LIBRARY_PATH. I
|
||||
have yet to confirm whether this is a problem on Linux or NT.
|
||||
[Done 13 Aug 1999]
|
||||
|
||||
-- Make Java compilation work correctly on Unix/Linux.
|
||||
|
||||
-- Better integration with Mozilla makefile/autoconf system.
|
||||
|
||||
-- Move XPCOM startup code to test programs.
|
||||
|
||||
-- Integrate into Java Plugin and test.
|
||||
|
||||
-- File and function renaming, to prevent conflicts and increase modularity.
|
||||
|
||||
|
||||
Registration and Activation
|
||||
---------------------------
|
||||
|
||||
-- Insure JNI libraries load and unload, even within JNI plugin
|
||||
|
||||
-- Derive proxy class from IID, and vice-versa
|
||||
|
||||
-- Generate static proxies (using genproxy)
|
||||
|
||||
-- Generate and load "on-the-fly" bytecode for proxy classes.
|
||||
|
||||
|
||||
Marshalling
|
||||
-----------
|
||||
|
||||
-- Verify nsID parameters are marshalled correctly.
|
||||
|
||||
-- Unwrap proxies used as "in" parameters.
|
||||
|
||||
-- Wrap "out" XPCOM objects in correct wrapper class. [dep: Proxy Generation]
|
||||
|
||||
-- Build C++ stubs for Java-implemented XPCOM objects. [big task?]
|
||||
|
||||
-- [Future] Allow mapping from native concrete type to Java types
|
||||
|
||||
-- [Future] Efficient handling of attributes and 0- or 1-arg methods.
|
||||
|
||||
-- [Future] Reflection API (if Java's is insufficient)
|
||||
|
||||
|
||||
NSRESULTs
|
||||
---------
|
||||
|
||||
-- Throw exceptions for error codes
|
||||
|
||||
-- Design and implement "success code mechanism", for single-threaded case
|
||||
|
||||
-- Store success codes per thread, and retrieve for current threads.
|
||||
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
-- Write proxy for ns[I]ComponentManager, by hand. (For performance,
|
||||
and because of the overloaded methods and lack of XPT.)
|
||||
|
||||
-- Write proxy for ns[I]ServiceManager, similar to above.
|
||||
|
||||
-- Throw exceptions for unknown or missing proxy classes (and other errors).
|
||||
|
||||
-- Implement XPCOM identity rules
|
||||
|
||||
-- Document (including Javadoc)
|
||||
|
||||
|
||||
Memory Management
|
||||
-----------------
|
||||
|
||||
-- Insure that temporary heap memory (esp. strings and nsIDs) is
|
||||
recycled.
|
||||
|
||||
-- Insure reference-counting rules aren't violated.
|
||||
|
||||
-- Cache previously allocated wrapper objects, to prevent unnecessary
|
||||
allocation.
|
||||
|
||||
-- Thread-safe object release
|
||||
|
||||
50
mozilla/java/xpcom/old/classes/Makefile.in
Normal file
50
mozilla/java/xpcom/old/classes/Makefile.in
Normal file
@@ -0,0 +1,50 @@
|
||||
#!gmake
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
# PENDING(frankm): find out where these should really be defined
|
||||
IGNORE_MANIFEST=1
|
||||
JAVA_OR_NSJVM=1
|
||||
NO_CAFE=1
|
||||
|
||||
# PENDING(frankm): find out how to define this for UNIX/SunOS
|
||||
JAVAC=$(JDKHOME)/bin/javac
|
||||
JAVALIB=$(JDKHOME)/lib
|
||||
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
|
||||
JAR_XPCOM_CLASSES = org/mozilla/xpcom \
|
||||
$(NULL)
|
||||
|
||||
ifdef JAVA_OR_NSJVM
|
||||
JDIRS = $(JAR_XPCOM_CLASSES)
|
||||
endif
|
||||
|
||||
# PENDING(frankm): find out how to define this for UNIX/SunOS
|
||||
JAVAC=$(JDKHOME)/bin/javac
|
||||
JAVALIB=$(JDKHOME)/lib
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
public class ComObject extends Object {
|
||||
// the XPCOM object pointer, stored as a long (for 64 bit compatibility)
|
||||
long objptr;
|
||||
|
||||
// package-private constructors
|
||||
ComObject() {
|
||||
}
|
||||
|
||||
ComObject(long p) {
|
||||
this.objptr = p;
|
||||
XPComUtilities.AddRef(objptr);
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
XPComUtilities.Release(objptr);
|
||||
}
|
||||
|
||||
protected void __invokeByIndex(nsID iid, int index, Object[] args) {
|
||||
XPComUtilities.InvokeMethodByIndex(iid, this.objptr, index, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
public final class XPCMethod extends Object {
|
||||
// PENDING: symbolic names for type codes
|
||||
|
||||
// PENDING: use an nsID equivalent
|
||||
nsID iid;
|
||||
String methodName;
|
||||
|
||||
// Pointer to XPCOM MethodInfo ptr
|
||||
long infoptr;
|
||||
// Pointer to C++ argument array template
|
||||
long frameptr;
|
||||
// Vtable offset
|
||||
int offset;
|
||||
// Number of parameters
|
||||
int count;
|
||||
|
||||
// PENDING: Add lookup by name
|
||||
// PENDING: Add metadata (in, out, retval, types)
|
||||
public // PENDING: make nonpublic ASAP
|
||||
XPCMethod(String iidString, String methodName)
|
||||
throws XPCOMException {
|
||||
this.iid = new nsID(iidString);
|
||||
this.methodName = methodName;
|
||||
offset = this.init(this.iid, this.methodName);
|
||||
}
|
||||
|
||||
public // PENDING: make nonpublic ASAP
|
||||
XPCMethod(nsID iid, String methodName)
|
||||
throws XPCOMException {
|
||||
this.iid = iid;
|
||||
this.methodName = methodName;
|
||||
offset = this.init(this.iid, methodName);
|
||||
}
|
||||
|
||||
private native int init(nsID iid, String methodName)
|
||||
throws XPCOMException;
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
infoptr = 0;
|
||||
destroyPeer(frameptr);
|
||||
frameptr = 0;
|
||||
}
|
||||
|
||||
private native void destroyPeer(long ptr) throws XPCOMException;
|
||||
|
||||
public int getNumberOfParameters() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public native int getParameterType(int index)
|
||||
throws IndexOutOfBoundsException, XPCOMException;
|
||||
|
||||
public native int getParameterClass(int index)
|
||||
throws IndexOutOfBoundsException, XPCOMException;
|
||||
|
||||
public native void invoke(ComObject target, Object[] params)
|
||||
throws XPCOMException;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
public class XPCOMException extends RuntimeException {
|
||||
public XPCOMException(String message, int xpcomCode) {
|
||||
super(message + " [nsresult=" + xpcomCode + "]");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
public class XPComUtilities {
|
||||
private static boolean didInit = false;
|
||||
|
||||
static {
|
||||
initXPCOM();
|
||||
}
|
||||
|
||||
static void initXPCOM() {
|
||||
if (didInit) return;
|
||||
|
||||
didInit = true;
|
||||
System.loadLibrary("xpjava");
|
||||
if (!initialize()) {
|
||||
System.out.println("Initialization failed!!");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private static native boolean initialize();
|
||||
|
||||
// public static native nsIComponentManager GetGlobalComponentManager();
|
||||
|
||||
public static native nsISupports CreateInstance(nsID classID,
|
||||
nsISupports aDelegate,
|
||||
nsID interfaceID);
|
||||
|
||||
/*
|
||||
public static native Object CreateInstance(String progID,
|
||||
nsISupports aDelegate,
|
||||
nsID interfaceID);
|
||||
|
||||
public static native void RegisterFactory(nsID classID,
|
||||
String className,
|
||||
String progID,
|
||||
nsIFactory aFactory,
|
||||
boolean replace);
|
||||
*/
|
||||
|
||||
public static native void RegisterComponent(nsID classID,
|
||||
String className,
|
||||
String progID,
|
||||
String libraryName,
|
||||
boolean replace,
|
||||
boolean persist);
|
||||
|
||||
//public static native nsIInterfaceInfoManager GetInterfaceInfoManager();
|
||||
|
||||
static native void AddRef(long ref);
|
||||
static native void Release(long ref);
|
||||
|
||||
static native void InvokeMethodByIndex(nsID iid,
|
||||
long ref,
|
||||
int index,
|
||||
Object[] args);
|
||||
|
||||
// TEMPORARY: remove ASAP
|
||||
public static void InvokeMethodByIndex(nsID iid,
|
||||
ComObject object,
|
||||
int index,
|
||||
Object[] args) {
|
||||
object.__invokeByIndex(iid, index, args);
|
||||
}
|
||||
}
|
||||
82
mozilla/java/xpcom/old/classes/org/mozilla/xpcom/nsID.java
Normal file
82
mozilla/java/xpcom/old/classes/org/mozilla/xpcom/nsID.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
public final class nsID {
|
||||
// ptr to a C++ nsID
|
||||
long nsidptr;
|
||||
|
||||
static {
|
||||
XPComUtilities.initXPCOM();
|
||||
}
|
||||
|
||||
/** DO NOT USE: only for creating nsIDs in native code */
|
||||
nsID() {
|
||||
nsidptr = 0x0;
|
||||
}
|
||||
|
||||
public nsID(int m0, short m1, short m2,
|
||||
byte m30, byte m31, byte m32, byte m33,
|
||||
byte m34, byte m35, byte m36, byte m37) {
|
||||
// What fun
|
||||
this.NewIDPtr(m0, m1, m2, m30, m31, m32, m33, m34, m35, m36, m37);
|
||||
}
|
||||
|
||||
private native void NewIDPtr(int m0, short m1, short m2,
|
||||
byte m30, byte m31, byte m32, byte m33,
|
||||
byte m34, byte m35, byte m36, byte m37);
|
||||
|
||||
public nsID(String idstring) throws NumberFormatException {
|
||||
this.NewIDPtr(idstring);
|
||||
if (this.nsidptr == 0) {
|
||||
throw new NumberFormatException("Can't convert '" +
|
||||
idstring
|
||||
+ "' to an nsID");
|
||||
}
|
||||
}
|
||||
|
||||
private native void NewIDPtr(String idstring);
|
||||
|
||||
protected native void finalize() throws Throwable;
|
||||
|
||||
public native boolean equals(Object other);
|
||||
|
||||
public native String toString();
|
||||
|
||||
public native int hashCode();
|
||||
|
||||
public static void main(String[] argv) {
|
||||
System.loadLibrary("xpjava");
|
||||
|
||||
nsID iid1 = new nsID("57ecad90-ae1a-11d1-b66c-00805f8a2676");
|
||||
nsID iid2 = new nsID((int)0x57ecad90, (short)0xae1a, (short)0x11d1,
|
||||
(byte)0xb6, (byte)0x6c, (byte)0x00, (byte)0x80,
|
||||
(byte)0x5f, (byte)0x8a, (byte)0x26, (byte)0x76);
|
||||
|
||||
System.out.println(iid1);
|
||||
System.out.println(iid2);
|
||||
|
||||
System.out.println(iid1.equals(iid2));
|
||||
System.out.println(iid1.equals(null));
|
||||
System.out.println(iid1.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
/*
|
||||
* ************* DO NOT EDIT THIS FILE ***********
|
||||
*
|
||||
* This file was automatically generated from /home/frankm/mozilla/dist/idl/nsISupports.idl.
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import org.mozilla.xpcom.nsID;
|
||||
|
||||
/**
|
||||
* Interface nsISupports
|
||||
*
|
||||
* IID: 0x00000000-0000-0000-c000-000000000046
|
||||
*/
|
||||
|
||||
public interface nsISupports
|
||||
{
|
||||
public static final String NS_ISUPPORTS_IID_STRING =
|
||||
"00000000-0000-0000-c000-000000000046";
|
||||
|
||||
public static final nsID NS_ISUPPORTS_IID =
|
||||
new nsID(NS_ISUPPORTS_IID_STRING);
|
||||
|
||||
|
||||
/* void QueryInterface (in nsIIDRef uuid, [iid_is (uuid), retval] out nsQIResult result); */
|
||||
public Object QueryInterface(nsID uuid);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* end
|
||||
*/
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
class nsISupports__Proxy extends ComObject implements nsISupports {
|
||||
|
||||
public Object QueryInterface(nsID uuid) {
|
||||
Object[] args = new Object[2];
|
||||
args[0] = uuid;
|
||||
args[1] = null;
|
||||
XPComUtilities.InvokeMethodByIndex(NS_ISUPPORTS_IID, objptr, 0, args);
|
||||
return args[1];
|
||||
}
|
||||
|
||||
// PENDING: should reimplement identity, hash, etc.
|
||||
}
|
||||
66
mozilla/java/xpcom/old/src/Makefile.in
Normal file
66
mozilla/java/xpcom/old/src/Makefile.in
Normal file
@@ -0,0 +1,66 @@
|
||||
#!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):
|
||||
|
||||
DEPTH=../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = xpjava
|
||||
|
||||
#MODULE = xpcom
|
||||
#XPIDL_MODULE = xpcom_base
|
||||
|
||||
CPPSRCS = \
|
||||
xpjava.cpp \
|
||||
xpj_proxy.cpp \
|
||||
xpj_XPCMethod.cpp \
|
||||
xpj_ComUtilities.cpp \
|
||||
xpj_nsID.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
# EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
REQUIRES = xpcom
|
||||
|
||||
# XXX: fix this to substitute correct OS name
|
||||
|
||||
INCLUDES += -I$(JDKHOME)/include \
|
||||
-I$(JDKHOME)/include/solaris \
|
||||
-I$(JDKHOME)/include/linux \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
-L$(topsrcdir)/dist/lib \
|
||||
-lxpcom \
|
||||
-lplc3 \
|
||||
-lplds3 \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
203
mozilla/java/xpcom/old/src/xpj_ComUtilities.cpp
Normal file
203
mozilla/java/xpcom/old/src/xpj_ComUtilities.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <iostream.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <jni.h>
|
||||
#include "nscore.h"
|
||||
#include "nsID.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "xpjava.h"
|
||||
|
||||
#ifdef INCLUDE_JNI_HEADER
|
||||
#include "org_mozilla_xpcom_XPComUtilities.h"
|
||||
#endif
|
||||
|
||||
/* ---------- CLASS METHODS ------------ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_mozilla_xpcom_XPComUtilities_initialize(JNIEnv *env, jclass cls)
|
||||
{
|
||||
nsresult res = xpj_InitXPCOM();
|
||||
if (NS_FAILED(res)) return JNI_FALSE;
|
||||
|
||||
return xpjd_InitJavaCaches(env); // XXX: remove; do in dispatch
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPComUtilities
|
||||
* Method: CreateInstance
|
||||
* Signature: (LID;LnsISupports;LID;)Ljava/lang/Object;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_XPComUtilities_CreateInstance
|
||||
(JNIEnv *env, jclass clazz,
|
||||
jobject jcid, jobject jdelegate, jobject jiid)
|
||||
{
|
||||
jobject result;
|
||||
nsISupports *xpcobj = NULL;
|
||||
nsresult res;
|
||||
nsID *classID = ID_GetNative(env, jcid);
|
||||
nsID *interfaceID = ID_GetNative(env, jiid);
|
||||
nsISupports *delegate = NULL;
|
||||
|
||||
if (jdelegate != NULL) {
|
||||
xpjp_QueryInterfaceToXPCOM(env,
|
||||
jdelegate,
|
||||
NS_GET_IID(nsISupports),
|
||||
(void **)&delegate);
|
||||
}
|
||||
|
||||
assert(classID != NULL && interfaceID != NULL);
|
||||
|
||||
// Create Instance
|
||||
//cerr << "Creating Sample Instance" << endl;
|
||||
|
||||
nsIComponentManager *manager;
|
||||
|
||||
res = NS_GetGlobalComponentManager(&manager);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to get component manager" << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = manager->CreateInstance(*classID,
|
||||
delegate,
|
||||
*interfaceID,
|
||||
(void **) &xpcobj);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to create instance" << endl;
|
||||
return NULL;
|
||||
}
|
||||
// cerr << "Wrapping " << sample << " in new ComObject" << endl;
|
||||
|
||||
// Wrap it in an ComObject
|
||||
result = xpjp_QueryInterfaceToJava(env, xpcobj, *interfaceID);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPComUtilities
|
||||
* Method: RegisterComponent
|
||||
* Signature: (LID;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_RegisterComponent
|
||||
(JNIEnv *env, jclass clazz,
|
||||
jobject cid, jstring className, jstring progID, jstring libraryName,
|
||||
jboolean replace, jboolean persist)
|
||||
{
|
||||
nsresult res;
|
||||
const nsID *aClass = ID_GetNative(env, cid);
|
||||
|
||||
const char *c_className =
|
||||
(const char *)env->GetStringUTFChars(className, NULL);
|
||||
|
||||
const char *c_progID =
|
||||
(const char *)env->GetStringUTFChars(progID, NULL);
|
||||
|
||||
// PENDING: convert from library-independent to library-dependent?
|
||||
const char *c_libraryName =
|
||||
(const char *)env->GetStringUTFChars(libraryName, NULL);
|
||||
|
||||
res = nsComponentManager::RegisterComponent(*aClass,
|
||||
c_className,
|
||||
c_progID,
|
||||
c_libraryName,
|
||||
(PRBool)replace,
|
||||
(PRBool)persist);
|
||||
|
||||
env->ReleaseStringUTFChars(className, c_className);
|
||||
|
||||
env->ReleaseStringUTFChars(progID, c_progID);
|
||||
|
||||
env->ReleaseStringUTFChars(libraryName, c_libraryName);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to register factory" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPComUtilities
|
||||
* Method: AddRef
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_AddRef
|
||||
(JNIEnv *env, jclass cls, jlong ref)
|
||||
{
|
||||
xpjp_SafeAddRefProxyID(ref);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPComUtilities
|
||||
* Method: Release
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPComUtilities_Release
|
||||
(JNIEnv *env, jclass cls, jlong ref)
|
||||
{
|
||||
xpjp_SafeReleaseProxyID(ref);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPComUtilities
|
||||
* Method: InvokeMethodByIndex
|
||||
* Signature: (LID;IJ[Ljava/lang/Object;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_mozilla_xpcom_XPComUtilities_InvokeMethodByIndex(JNIEnv *env,
|
||||
jclass cls,
|
||||
jobject iid,
|
||||
jlong ref,
|
||||
jint index,
|
||||
jobjectArray args) {
|
||||
nsIInterfaceInfo *info = nsnull;
|
||||
nsISupports *target;
|
||||
|
||||
// XXX: check for success
|
||||
xpjd_GetInterfaceInfo(env, iid, &info);
|
||||
|
||||
// XXX: s.b. just |xpjp_UnwrapProxy(env, self);|
|
||||
nsIID *nativeIID = ID_GetNative(env, iid);
|
||||
xpjp_QueryInterfaceForProxyID(ref, *nativeIID, (void**)&target);
|
||||
|
||||
xpjd_InvokeMethod(env, target, info, index, args);
|
||||
|
||||
// XXX: remove when ref not QueryInterface'd
|
||||
xpjp_SafeReleaseProxyID(ref);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
297
mozilla/java/xpcom/old/src/xpj_XPCMethod.cpp
Normal file
297
mozilla/java/xpcom/old/src/xpj_XPCMethod.cpp
Normal file
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <iostream.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <jni.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "xptinfo.h"
|
||||
#include "xptcall.h"
|
||||
#include "xpt_struct.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "xpjava.h"
|
||||
|
||||
#ifdef INCLUDE_JNI_HEADER
|
||||
#include "org_mozilla_xpcom_XPCMethod.h"
|
||||
#endif
|
||||
|
||||
static jfieldID XPCMethod_infoptr_ID = NULL;
|
||||
static jfieldID XPCMethod_frameptr_ID = NULL;
|
||||
static jfieldID XPCMethod_offset_ID = NULL;
|
||||
static jfieldID XPCMethod_count_ID = NULL;
|
||||
|
||||
jclass classXPCMethod = NULL;
|
||||
|
||||
#undef USE_PARAM_TEMPLATE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Because not all platforms convert jlong to "long long"
|
||||
*
|
||||
* NOTE: this code was cut&pasted to other places, with tweaks.
|
||||
* Normally I wouldn't do this, but my reasons are:
|
||||
*
|
||||
* 1. My alternatives were to put it in xpjava.h or xpjava.cpp
|
||||
* I'd like to take stuff *out* of xpjava.h, and putting it
|
||||
* in xpjava.cpp would preclude inlining.
|
||||
*
|
||||
* 2. How we represent methods in Java is an implementation
|
||||
* detail, which may change in the future; this entire class
|
||||
* may disappear in favor of normal Java reflection, or change
|
||||
* drastically. Thus ToPtr/ToJLong is only of interest to those
|
||||
* objects that encode pointers as jlongs, which is kind of a
|
||||
* kludge to begin with.
|
||||
*
|
||||
* -- frankm, 99.09.09
|
||||
*/
|
||||
static inline jlong ToJLong(const void *p) {
|
||||
jlong result;
|
||||
jlong_I2L(result, (int)p);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void* ToPtr(jlong l) {
|
||||
int result;
|
||||
jlong_L2I(result, l);
|
||||
return (void *)result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPCMethod
|
||||
* Method: init
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_mozilla_xpcom_XPCMethod_init(JNIEnv *env, jobject self,
|
||||
jobject iid, jstring methodName) {
|
||||
int offset;
|
||||
const nsXPTMethodInfo *mi;
|
||||
nsID *iidPtr = ID_GetNative(env, iid);
|
||||
const char *tmpstr;
|
||||
nsresult res;
|
||||
|
||||
// Get interface info
|
||||
nsIInterfaceInfo *info = nsnull;
|
||||
|
||||
res = (XPTI_GetInterfaceInfoManager())->GetInfoForIID(iidPtr, &info);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to find info for " << iidPtr->ToString() << endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
tmpstr = env->GetStringUTFChars(methodName, NULL);
|
||||
res = xpj_GetMethodInfoByName(iidPtr, tmpstr, PR_FALSE, &mi, &offset);
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Cannot find method for: " << (char *)tmpstr << endl;
|
||||
return -1;
|
||||
}
|
||||
env->ReleaseStringUTFChars(methodName, tmpstr);
|
||||
|
||||
// Store argptr
|
||||
// PENDING: add iid as an argument
|
||||
|
||||
if (XPCMethod_infoptr_ID == NULL) {
|
||||
classXPCMethod = env->GetObjectClass(self);
|
||||
|
||||
classXPCMethod = (jclass)env->NewGlobalRef(classXPCMethod);
|
||||
if (classXPCMethod == NULL) return -1;
|
||||
|
||||
XPCMethod_infoptr_ID = env->GetFieldID(classXPCMethod,
|
||||
"infoptr",
|
||||
"J");
|
||||
|
||||
if (XPCMethod_infoptr_ID == NULL) {
|
||||
cerr << "Field id for infoptr not found" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
XPCMethod_frameptr_ID = env->GetFieldID(classXPCMethod,
|
||||
"frameptr",
|
||||
"J");
|
||||
|
||||
if (XPCMethod_frameptr_ID == NULL) {
|
||||
cerr << "Field id for frameptr not found" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
XPCMethod_count_ID = env->GetFieldID(classXPCMethod,
|
||||
"count",
|
||||
"I");
|
||||
|
||||
if (XPCMethod_count_ID == NULL) {
|
||||
cerr << "Field id for count not found" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
XPCMethod_offset_ID = env->GetFieldID(classXPCMethod,
|
||||
"offset",
|
||||
"I");
|
||||
|
||||
if (XPCMethod_offset_ID == NULL) {
|
||||
cerr << "Field id for offset not found" << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
env->SetLongField(self,
|
||||
XPCMethod_infoptr_ID,
|
||||
ToJLong(info));
|
||||
|
||||
env->SetIntField(self,
|
||||
XPCMethod_count_ID,
|
||||
(jint)mi->GetParamCount());
|
||||
|
||||
#ifdef USE_PARAM_TEMPLATE
|
||||
// Build parameter array
|
||||
nsXPTCVariant *variantPtr = NULL;
|
||||
xpjd_BuildParamsForOffset(info, offset, 0, &variantPtr);
|
||||
|
||||
env->SetLongField(self,
|
||||
XPCMethod_frameptr_ID,
|
||||
ToJLong(variantPtr));
|
||||
#else
|
||||
env->SetLongField(self,
|
||||
XPCMethod_frameptr_ID,
|
||||
ToJLong(NULL));
|
||||
#endif
|
||||
|
||||
// Return offset
|
||||
return offset;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPCMethod
|
||||
* Method: destroyPeer
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_mozilla_xpcom_XPCMethod_destroyPeer(JNIEnv *env,
|
||||
jobject self, jlong peer) {
|
||||
|
||||
nsXPTCVariant *variantPtr = (nsXPTCVariant *)ToPtr(peer);
|
||||
if (variantPtr != NULL) {
|
||||
nsAllocator::Free(variantPtr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPCMethod
|
||||
* Method: getParameterType
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_mozilla_xpcom_XPCMethod_getParameterType
|
||||
(JNIEnv *env, jobject self, jint index) {
|
||||
|
||||
jint paramcount = env->GetIntField(self, XPCMethod_count_ID);
|
||||
|
||||
if (index >= paramcount || index < 0) {
|
||||
cerr << "Out of range: " << index << endl;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
jint offset = env->GetIntField(self, XPCMethod_offset_ID);
|
||||
jlong ptrval = env->GetLongField(self, XPCMethod_infoptr_ID);
|
||||
|
||||
const nsXPTMethodInfo *mi;
|
||||
nsIInterfaceInfo *info = (nsIInterfaceInfo *)ToPtr(ptrval);
|
||||
|
||||
info->GetMethodInfo(offset, &mi);
|
||||
return mi->GetParam(index).GetType().TagPart();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPCMethod
|
||||
* Method: getParameterClass
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_mozilla_xpcom_XPCMethod_getParameterClass
|
||||
(JNIEnv *env, jobject self, jint index) {
|
||||
cerr << "Unimplemented call" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: XPCMethod
|
||||
* Method: invoke
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_XPCMethod_invoke
|
||||
(JNIEnv *env, jobject self, jobject target, jobjectArray params) {
|
||||
nsresult res;
|
||||
|
||||
if (XPCMethod_infoptr_ID == NULL) {
|
||||
cerr << "Field id for infoptr not initialized" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
jint offset = env->GetIntField(self, XPCMethod_offset_ID);
|
||||
|
||||
jlong infoptr = env->GetLongField(self, XPCMethod_infoptr_ID);
|
||||
nsIInterfaceInfo *info =
|
||||
(nsIInterfaceInfo *)ToPtr(infoptr);
|
||||
|
||||
#ifdef USE_PARAM_TEMPLATE
|
||||
jint paramcount = env->GetIntField(self, XPCMethod_count_ID);
|
||||
|
||||
nsXPTCVariant *paramTemplate =
|
||||
(nsXPTCVariant *)ToPtr(env->GetLongField(self, XPCMethod_frameptr_ID));
|
||||
|
||||
nsXPTCVariant variantArray[paramcount];
|
||||
|
||||
memcpy(variantArray, paramTemplate, paramcount * sizeof(nsXPTCVariant));
|
||||
// Fix pointers
|
||||
for (int i = 0; i < paramcount; i++) {
|
||||
nsXPTCVariant *current = &(variantArray[i]);
|
||||
if (current->flags == nsXPTCVariant::PTR_IS_DATA) {
|
||||
current->ptr = ¤t->val;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
nsIID* iid = nsnull;
|
||||
nsISupports *true_target = nsnull;
|
||||
|
||||
// XXX: check for success
|
||||
info->GetIID(&iid);
|
||||
|
||||
// XXX: check for success
|
||||
xpjp_QueryInterfaceToXPCOM(env, target, *iid, (void**)&true_target);
|
||||
|
||||
xpjd_InvokeMethod(env, true_target, info, offset, params);
|
||||
|
||||
xpjp_SafeRelease(true_target);
|
||||
nsAllocator::Free(iid);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
103
mozilla/java/xpcom/old/src/xpj_dispatch.h
Normal file
103
mozilla/java/xpcom/old/src/xpj_dispatch.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <jni.h>
|
||||
#include "nsISupports.h"
|
||||
#include "xptcall.h"
|
||||
#include "xptinfo.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize caches for often-used Java classes (all in java.lang).
|
||||
* Will return JNI_FALSE if those classes, or their fields
|
||||
* and methods, aren't found.
|
||||
* @deprecated
|
||||
*/
|
||||
/* XXX: should be hidden in first call to xpjd_InvokeMethod */
|
||||
jboolean xpjd_InitJavaCaches(JNIEnv *env);
|
||||
|
||||
/**
|
||||
* Uncaches often-used Java classes (e.g. during unload).
|
||||
*/
|
||||
/* XXX: should be part of general unloading mechanism */
|
||||
void xpjd_FlushJavaCaches(JNIEnv *env);
|
||||
|
||||
/**
|
||||
* Convenience method to get the nsIInterfaceInfo for an
|
||||
* interface denoted by the Java IID object `iid'.
|
||||
* Will return JNI_FALSE if `iid' isn't a org.mozilla.xpcom.nsID
|
||||
* or no info object exists.
|
||||
*/
|
||||
jboolean xpjd_GetInterfaceInfo(JNIEnv *env,
|
||||
jobject iid,
|
||||
nsIInterfaceInfo **info);
|
||||
|
||||
/**
|
||||
* Convenience method to get the nsIInterfaceInfo for an
|
||||
* interface denoted by the C++ struct `iid'.
|
||||
* Will return JNI_FALSE if `iid' isn't a org.mozilla.xpcom.nsID
|
||||
* or no info object exists.
|
||||
*/
|
||||
jboolean xpjd_GetInterfaceInfoNative(REFNSIID iid,
|
||||
nsIInterfaceInfo **info);
|
||||
|
||||
/**
|
||||
* Invoke a method on 'target' indicated by the 'methodIndex'-th
|
||||
* method in `info', with arguments `args'.
|
||||
* Throws a Java exception if `target' can't receive the method,
|
||||
* `methodIndex' is out of bounds, `args' contains too few arguments,
|
||||
* or any of the pointer arguments is NULL.
|
||||
*/
|
||||
void xpjd_InvokeMethod(JNIEnv *env,
|
||||
nsISupports *target,
|
||||
nsIInterfaceInfo *info,
|
||||
jint methodIndex,
|
||||
jobjectArray args);
|
||||
|
||||
#if 0 /* not implemented yet */
|
||||
|
||||
/**
|
||||
* Optimized version of `xpjd_InvokeMethod' to get attributes, or
|
||||
* methods with only one in parameter and no outs or inouts.
|
||||
*/
|
||||
jobject xpjd_GetAttribute(JNIEnv *env,
|
||||
nsISupports *target,
|
||||
nsIInterfaceInfo *info,
|
||||
jint getMethodIndex);
|
||||
|
||||
/**
|
||||
* Optimized version of `xpjd_InvokeMethod' to set attributes, or
|
||||
* methods with only one out parameter and no ins or inouts.
|
||||
*/
|
||||
void xpjd_SetAttribute(JNIEnv *env,
|
||||
nsISupports *target,
|
||||
nsIInterfaceInfo *info,
|
||||
jint setMethodIndex,
|
||||
jobject value);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
298
mozilla/java/xpcom/old/src/xpj_nsID.cpp
Normal file
298
mozilla/java/xpcom/old/src/xpj_nsID.cpp
Normal file
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <iostream.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <jni.h>
|
||||
#include "nscore.h"
|
||||
#include "nsID.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
#include "xpjava.h"
|
||||
|
||||
#ifdef INCLUDE_JNI_HEADER
|
||||
#include "org_mozilla_xpcom_nsID.h"
|
||||
#endif
|
||||
|
||||
#define ID_CLASS_NAME "org/mozilla/xpcom/nsID"
|
||||
#define ID_FIELD_NAME "nsidptr"
|
||||
#define ID_FIELD_TYPE "J"
|
||||
|
||||
/* Because not all platforms convert jlong to "long long"
|
||||
*
|
||||
* NOTE: this code was cut&pasted from xpj_XPCMethod.cpp, with tweaks.
|
||||
* Normally I wouldn't do this, but my reasons are:
|
||||
*
|
||||
* 1. My alternatives were to put it in xpjava.h or xpjava.cpp
|
||||
* I'd like to take stuff *out* of xpjava.h, and putting it
|
||||
* in xpjava.cpp would preclude inlining.
|
||||
*
|
||||
* 2. How we represent nsIDs in Java is an implementation
|
||||
* detail, which may change in the future (e.g. placing the
|
||||
* whole value in the Java obj, not just a pointer to heap
|
||||
* memory). Thus ToPtr/ToJLong is only of interest to those
|
||||
* objects that stuff pointers into jlongs.
|
||||
*
|
||||
* -- frankm, 99.09.09
|
||||
*/
|
||||
static inline jlong ToJLong(const void *p) {
|
||||
jlong result;
|
||||
jlong_I2L(result, (int)p);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void* ToPtr(jlong l) {
|
||||
int result;
|
||||
jlong_L2I(result, l);
|
||||
return (void *)result;
|
||||
}
|
||||
|
||||
#undef DEBUG_GETSET_ID
|
||||
|
||||
#ifdef DEBUG_GETSET_ID
|
||||
static void GetClassName(char *namebuf, JNIEnv *env, jobject self, int len) {
|
||||
jclass clazz = env->GetObjectClass(self);
|
||||
jclass clazz_clazz = env->GetObjectClass(clazz);
|
||||
jmethodID nameID = env->GetMethodID(clazz_clazz, "getName", "()Ljava/lang/String;");
|
||||
jstring string = (jstring)env->CallObjectMethod(clazz, nameID);
|
||||
|
||||
jsize jstrlen = env->GetStringUTFLength(string);
|
||||
const char *utf = env->GetStringUTFChars(string, NULL);
|
||||
|
||||
if (jstrlen >= len) {
|
||||
jstrlen = len;
|
||||
}
|
||||
strncpy(namebuf, utf, jstrlen);
|
||||
namebuf[jstrlen] = '\0';
|
||||
|
||||
env->ReleaseStringUTFChars(string, utf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************** ID **************************/
|
||||
|
||||
jobject ID_NewJavaID(JNIEnv *env, const nsIID* iid) {
|
||||
jclass clazz = env->FindClass(ID_CLASS_NAME);
|
||||
jmethodID initID = env->GetMethodID(clazz, "<init>", "()V");
|
||||
|
||||
jobject result = env->NewObject(clazz, initID);
|
||||
nsID *idptr = (nsID *)nsAllocator::Alloc(sizeof(nsID));
|
||||
|
||||
memcpy(idptr, iid, sizeof(nsID));
|
||||
ID_SetNative(env, result, idptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsID *ID_GetNative(JNIEnv *env, jobject self) {
|
||||
jclass clazz = env->FindClass(ID_CLASS_NAME);
|
||||
jfieldID nsidptrID = env->GetFieldID(clazz, ID_FIELD_NAME, ID_FIELD_TYPE);
|
||||
|
||||
#ifdef DEBUG_GETSET_ID
|
||||
char classname[128];
|
||||
|
||||
GetClassName(classname, env, self, sizeof(classname));
|
||||
fprintf(stderr, "ID_GetNative: self instanceof %s\n", classname);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
assert(env->IsInstanceOf(self, clazz));
|
||||
|
||||
jlong nsidptr = env->GetLongField(self, nsidptrID);
|
||||
|
||||
return (nsID *)ToPtr(nsidptr);
|
||||
}
|
||||
|
||||
void ID_SetNative(JNIEnv *env, jobject self, nsID *id) {
|
||||
jclass clazz = env->FindClass(ID_CLASS_NAME);
|
||||
jfieldID nsidptrID = env->GetFieldID(clazz, ID_FIELD_NAME, ID_FIELD_TYPE);
|
||||
|
||||
#ifdef DEBUG_GETSET_ID
|
||||
char classname[128];
|
||||
|
||||
GetClassName(classname, env, self, sizeof(classname));
|
||||
fprintf(stderr, "ID_SetNative: self instanceof %s\n", classname);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
assert(env->IsInstanceOf(self, clazz));
|
||||
|
||||
jlong nsidptr = ToJLong(id);
|
||||
|
||||
env->SetLongField(self, nsidptrID, nsidptr);
|
||||
}
|
||||
|
||||
jboolean ID_IsEqual(JNIEnv *env, jobject self, jobject other) {
|
||||
jboolean result = JNI_FALSE;
|
||||
jclass clazz = env->FindClass(ID_CLASS_NAME);
|
||||
jfieldID nsidptrID = env->GetFieldID(clazz, ID_FIELD_NAME, ID_FIELD_TYPE);
|
||||
|
||||
#ifdef DEBUG_GETSET_ID
|
||||
char classname[128];
|
||||
|
||||
GetClassName(classname, env, self, sizeof(classname));
|
||||
fprintf(stderr, "ID_IsEqual: self instanceof %s\n", classname);
|
||||
|
||||
GetClassName(classname, env, other, sizeof(classname));
|
||||
fprintf(stderr, "ID_IsEqual: other instanceof %s\n", classname);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
assert(env->IsInstanceOf(self, clazz));
|
||||
|
||||
if (other != NULL && env->IsInstanceOf(other, clazz)) {
|
||||
nsID *selfid = (nsID *)ToPtr(env->GetLongField(self, nsidptrID));
|
||||
nsID *otherid = (nsID *)ToPtr(env->GetLongField(other, nsidptrID));
|
||||
|
||||
if (selfid != NULL && otherid != NULL) {
|
||||
result = selfid->Equals(*otherid);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: ID
|
||||
* Method: NewIDPtr
|
||||
* Signature: (ISSBBBBBBBB)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_nsID_NewIDPtr__ISSBBBBBBBB
|
||||
(JNIEnv *env, jobject self, jint m0, jshort m1, jshort m2,
|
||||
jbyte m30, jbyte m31, jbyte m32, jbyte m33,
|
||||
jbyte m34, jbyte m35, jbyte m36, jbyte m37) {
|
||||
|
||||
nsID *idptr = (nsID *)nsAllocator::Alloc(sizeof(nsID));
|
||||
idptr->m0 = m0;
|
||||
idptr->m1 = m1;
|
||||
idptr->m2 = m2;
|
||||
idptr->m3[0] = m30;
|
||||
idptr->m3[1] = m31;
|
||||
idptr->m3[2] = m32;
|
||||
idptr->m3[3] = m33;
|
||||
idptr->m3[4] = m34;
|
||||
idptr->m3[5] = m35;
|
||||
idptr->m3[6] = m36;
|
||||
idptr->m3[7] = m37;
|
||||
|
||||
ID_SetNative(env, self, idptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ID
|
||||
* Method: NewIDPtr
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_nsID_NewIDPtr__Ljava_lang_String_2
|
||||
(JNIEnv *env, jobject self, jstring string) {
|
||||
|
||||
nsID *idptr = (nsID *)nsAllocator::Alloc(sizeof(nsID));
|
||||
|
||||
jboolean isCopy;
|
||||
const char *utf = env->GetStringUTFChars(string, &isCopy);
|
||||
char *aIDStr;
|
||||
|
||||
if (isCopy) {
|
||||
aIDStr = (char *)utf;
|
||||
}
|
||||
else {
|
||||
jsize len = env->GetStringUTFLength(string);
|
||||
aIDStr = (char *)nsAllocator::Alloc(len * sizeof(char));
|
||||
strncpy(aIDStr, utf, len);
|
||||
aIDStr[len - 1] = 0;
|
||||
}
|
||||
|
||||
if (!(idptr->Parse(aIDStr))) {
|
||||
nsAllocator::Free(idptr);
|
||||
idptr = NULL;
|
||||
}
|
||||
|
||||
ID_SetNative(env, self, idptr);
|
||||
|
||||
if (!isCopy) {
|
||||
nsAllocator::Free(aIDStr);
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(string, utf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ID
|
||||
* Method: finalize
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_xpcom_nsID_finalize(JNIEnv *env, jobject self) {
|
||||
nsID *idptr = ID_GetNative(env, self);
|
||||
|
||||
nsAllocator::Free(idptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ID
|
||||
* Method: equals
|
||||
* Signature: (Ljava/lang/Object;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_mozilla_xpcom_nsID_equals(JNIEnv *env, jobject self, jobject other) {
|
||||
return ID_IsEqual(env, self, other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ID
|
||||
* Method: toString
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_mozilla_xpcom_nsID_toString(JNIEnv *env, jobject self) {
|
||||
|
||||
nsID *idptr = ID_GetNative(env, self);
|
||||
|
||||
char *idstr = idptr->ToString();
|
||||
|
||||
jstring result = env->NewStringUTF(idstr);
|
||||
|
||||
delete [] idstr;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ID
|
||||
* Method: hashCode
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_mozilla_xpcom_nsID_hashCode(JNIEnv *env, jobject self) {
|
||||
jint result;
|
||||
|
||||
PRUint32 *intptr = (PRUint32 *)ID_GetNative(env, self);
|
||||
|
||||
result = intptr[0] ^ intptr[1] ^ intptr[2] ^ intptr[3];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
243
mozilla/java/xpcom/old/src/xpj_proxy.cpp
Normal file
243
mozilla/java/xpcom/old/src/xpj_proxy.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include "xpjava.h"
|
||||
|
||||
#define JAVA_XPCOBJECT_CLASS "org/mozilla/xpcom/ComObject"
|
||||
|
||||
static jclass classComObject = NULL;
|
||||
static jfieldID ComObject_objptr_ID = NULL;
|
||||
|
||||
/* --------- SUPPORT FUNCTIONS ------------- */
|
||||
|
||||
/* Because not all platforms convert jlong to "long long"
|
||||
*
|
||||
* NOTE: this code was cut&pasted from xpj_XPCMethod.cpp, with tweaks.
|
||||
* Normally I wouldn't do this, but my reasons are:
|
||||
*
|
||||
* 1. My alternatives were to put it in xpjava.h or xpjava.cpp
|
||||
* I'd like to take stuff *out* of xpjava.h, and putting it
|
||||
* in xpjava.cpp would preclude inlining.
|
||||
*
|
||||
* 2. How we map proxies to XPCOM objects is an implementation
|
||||
* detail, which may change in the future (e.g. an index
|
||||
* into a proxy table). Thus ToPtr/ToJLong is only of
|
||||
* interest to those objects that stuff pointers into jlongs.
|
||||
*
|
||||
* 3. This allows adaptations to each implementation, for
|
||||
* type safety (e.g. taking and returning nsISupports*).
|
||||
*
|
||||
* -- frankm, 99.09.09
|
||||
*/
|
||||
static inline jlong ToJLong(nsISupports *p) {
|
||||
jlong result;
|
||||
jlong_I2L(result, (int)p);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline nsISupports* ToPtr(jlong l) {
|
||||
int result;
|
||||
jlong_L2I(result, l);
|
||||
return (nsISupports *)result;
|
||||
}
|
||||
|
||||
static inline jboolean xpjp_QueryInterface(nsISupports *object,
|
||||
REFNSIID iid,
|
||||
void **instance) {
|
||||
assert(object != NULL && instance != NULL);
|
||||
|
||||
if (NS_SUCCEEDED(object->QueryInterface(iid, instance))) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
static jboolean xpjp_InitJavaCaches(JNIEnv *env) {
|
||||
if (ComObject_objptr_ID == NULL) {
|
||||
classComObject = env->FindClass(JAVA_XPCOBJECT_CLASS);
|
||||
if (classComObject == NULL) return JNI_FALSE;
|
||||
|
||||
classComObject = (jclass)env->NewGlobalRef(classComObject);
|
||||
if (classComObject == NULL) return JNI_FALSE;
|
||||
|
||||
ComObject_objptr_ID = env->GetFieldID(classComObject, "objptr", "J");
|
||||
if (ComObject_objptr_ID == NULL) return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static jclass xpjp_ClassForInterface(JNIEnv *env, REFNSIID iid) {
|
||||
#if 0
|
||||
// Get info
|
||||
jclass result = classComObject; // null?
|
||||
nsIInterfaceInfo *info = nsnull;
|
||||
char *interface_name;
|
||||
char *name_space;
|
||||
char *full_classname;
|
||||
char *ch;
|
||||
nsresult res;
|
||||
|
||||
res = interfaceInfoManager->GetInfoForIID(&iid, &info);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to find info for " << iid.ToString() << endl;
|
||||
goto end;
|
||||
}
|
||||
|
||||
// XXX: PENDING: find name_space somehow
|
||||
name_space = "org.mozilla.xpcom";
|
||||
|
||||
res = info->GetName(&interface_name);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to find name for " << iid.ToString() << endl;
|
||||
goto end;
|
||||
}
|
||||
|
||||
// Construct class name
|
||||
full_classname =
|
||||
(char*)nsAllocator::Alloc(strlen(interface_name) + strlen(name_space) + 2);
|
||||
|
||||
strcpy(full_classname, name_space);
|
||||
ch = full_classname;
|
||||
while (ch != '\0') {
|
||||
if (*ch == '.') {
|
||||
*ch = '/';
|
||||
}
|
||||
ch++;
|
||||
}
|
||||
strcat(full_classname, "/");
|
||||
strcat(full_classname, interface_name);
|
||||
|
||||
cerr << "Looking for " << full_classname << endl;
|
||||
|
||||
result = env->FindClass(full_classname);
|
||||
// XXX: PENDING: If no such class found, make it
|
||||
|
||||
// XXX: PENDING: Cache result
|
||||
end:
|
||||
// Cleanup
|
||||
nsAllocator::Free(interface_name);
|
||||
nsAllocator::Free(full_classname);
|
||||
//nsAllocator::Free(name_space);
|
||||
|
||||
return result;
|
||||
#else
|
||||
return classComObject;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------- PROXY API FUNCTIONS ------------- */
|
||||
|
||||
jobject xpjp_QueryInterfaceToJava(JNIEnv *env,
|
||||
nsISupports *obj,
|
||||
REFNSIID iid) {
|
||||
if (!xpjp_InitJavaCaches(env)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// XXX: Bad implementation; returns a new proxy every time
|
||||
jobject result = 0;
|
||||
jmethodID initID = 0;
|
||||
jclass proxyClass = xpjp_ClassForInterface(env, iid);
|
||||
jobject jiid = ID_NewJavaID(env, &iid);
|
||||
|
||||
assert(proxyClass != 0);
|
||||
|
||||
initID = env->GetMethodID(proxyClass, "<init>", "(J)V");
|
||||
|
||||
if (initID != NULL) {
|
||||
result = env->NewObject(proxyClass, initID, ToJLong(obj), jiid);
|
||||
}
|
||||
else {
|
||||
initID = env->GetMethodID(proxyClass, "<init>", "()V");
|
||||
|
||||
result = env->NewObject(proxyClass, initID);
|
||||
env->SetLongField(result, ComObject_objptr_ID, ToJLong(obj));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
jboolean xpjp_QueryInterfaceToXPCOM(JNIEnv *env,
|
||||
jobject proxy,
|
||||
REFNSIID iid,
|
||||
void **instance) {
|
||||
nsISupports* xpcobj = xpjp_UnwrapProxy(env, proxy);
|
||||
if (xpcobj != NULL) {
|
||||
return xpjp_QueryInterface(xpcobj, iid, instance);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsISupports* xpjp_UnwrapProxy(JNIEnv *env, jobject proxy) {
|
||||
if (!xpjp_InitJavaCaches(env)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return ToPtr(env->GetLongField(proxy, ComObject_objptr_ID));
|
||||
}
|
||||
|
||||
void xpjp_SafeAddRef(nsISupports *object) {
|
||||
/* XXX: NOT "SAFE" */
|
||||
NS_ADDREF(object);
|
||||
}
|
||||
|
||||
void xpjp_SafeRelease(nsISupports *object) {
|
||||
/* XXX: NOT "SAFE" */
|
||||
NS_RELEASE(object);
|
||||
}
|
||||
|
||||
void xpjp_SafeAddRefProxy(JNIEnv *env, jobject proxy) {
|
||||
nsISupports* xpcobj = xpjp_UnwrapProxy(env, proxy);
|
||||
if (xpcobj != NULL) {
|
||||
xpjp_SafeAddRef(xpcobj);
|
||||
}
|
||||
}
|
||||
|
||||
void xpjp_SafeReleaseProxy(JNIEnv *env, jobject proxy) {
|
||||
nsISupports* xpcobj = xpjp_UnwrapProxy(env, proxy);
|
||||
if (xpcobj != NULL) {
|
||||
xpjp_SafeRelease(xpcobj);
|
||||
}
|
||||
}
|
||||
|
||||
/* deprecated */
|
||||
jboolean xpjp_QueryInterfaceForProxyID(jlong ref,
|
||||
REFNSIID iid,
|
||||
void **instance) {
|
||||
nsISupports *xpcobj = ToPtr(ref);
|
||||
|
||||
if (xpcobj != NULL) {
|
||||
return xpjp_QueryInterface(xpcobj, iid, instance);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/* deprecated */
|
||||
void xpjp_SafeReleaseProxyID(jlong ref) {
|
||||
xpjp_SafeRelease(ToPtr(ref));
|
||||
}
|
||||
|
||||
/* deprecated */
|
||||
void xpjp_SafeAddRefProxyID(jlong ref) {
|
||||
xpjp_SafeAddRef(ToPtr(ref));
|
||||
}
|
||||
103
mozilla/java/xpcom/old/src/xpj_proxy.h
Normal file
103
mozilla/java/xpcom/old/src/xpj_proxy.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <jni.h>
|
||||
#include "nsISupports.h"
|
||||
#include "xptcall.h"
|
||||
#include "xptinfo.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns a jobject implementing the interface indicated by `iid',
|
||||
* or NULL if `ptr' does not implement that interface.
|
||||
* The function wraps the XPCOM object in a Java proxy, unless it
|
||||
* is itself a proxy to a Java object; in that case, it unwraps the
|
||||
* proxy before testing.
|
||||
* The refcount of `ptr' will be incremented if it is wrapped.
|
||||
*/
|
||||
/* XXX: should we skip actual QueryInterface if not a proxy? */
|
||||
jobject xpjp_QueryInterfaceToJava(JNIEnv *env,
|
||||
nsISupports *ptr,
|
||||
REFNSIID iid);
|
||||
|
||||
/**
|
||||
* Sets `instance' to an instance of the interface indicated by `iid'.
|
||||
* If the Java object is a proxy, the function unwraps it and performs
|
||||
* QueryInterface(); otherwise, it performs QueryInterface() on
|
||||
* `object' and, if that succeeds, wraps it in a C++ proxy.
|
||||
* The refcount of `object' will be incremented if it is unwrapped.
|
||||
*/
|
||||
jboolean xpjp_QueryInterfaceToXPCOM(JNIEnv *env,
|
||||
jobject object,
|
||||
REFNSIID iid,
|
||||
void **instance);
|
||||
|
||||
/**
|
||||
* If `proxy' is a proxy to a nsISupports, returns the
|
||||
* contained pointer and returns true; otherwise, return NULL.
|
||||
* Used mainly for proxy implementation; others should
|
||||
* use QueryInterfaceToXPCOM().
|
||||
* The refcount of the return value is unchanged.
|
||||
*/
|
||||
nsISupports* xpjp_UnwrapProxy(JNIEnv *env, jobject proxy);
|
||||
|
||||
/**
|
||||
* Perform ptr->AddRef() in a thread-safe manner.
|
||||
*/
|
||||
void xpjp_SafeAddRef(nsISupports *ptr);
|
||||
|
||||
/**
|
||||
* Perform ptr->Release() in a thread-safe manner.
|
||||
*/
|
||||
void xpjp_SafeRelease(nsISupports *ptr);
|
||||
|
||||
/**
|
||||
* Perform AddRef() on `proxy''s underlying object in a
|
||||
* thread-safe manner.
|
||||
* Has no effect if proxy is not a proxy to a ref-counted object.
|
||||
*/
|
||||
void xpjp_SafeAddRefProxy(JNIEnv *env, jobject proxy);
|
||||
|
||||
/**
|
||||
* Perform Release() on `proxy''s underlying object in a
|
||||
* thread-safe manner.
|
||||
* Has no effect if proxy is not a proxy to a ref-counted object.
|
||||
*/
|
||||
void xpjp_SafeReleaseProxy(JNIEnv *env, jobject proxy);
|
||||
|
||||
|
||||
/* deprecated API */
|
||||
|
||||
jboolean xpjp_QueryInterfaceForProxyID(jlong ref,
|
||||
REFNSIID iid,
|
||||
void **instance);
|
||||
|
||||
void xpjp_SafeAddRefProxyID(jlong ref);
|
||||
|
||||
void xpjp_SafeReleaseProxyID(jlong ref);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
76
mozilla/java/xpcom/old/src/xpj_utils.h
Normal file
76
mozilla/java/xpcom/old/src/xpj_utils.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <jni.h>
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "xptinfo.h"
|
||||
|
||||
/*
|
||||
* Macros defined in some, but not all, jni_md.h, for
|
||||
* compilers that don't have 64 bit ints.
|
||||
*/
|
||||
#ifndef jlong_L2I
|
||||
# define jlong_L2I(_i, _l) ((_i) = (_l))
|
||||
# define jlong_I2L(_l, _i) ((_l) = (_i))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start up XPCOM
|
||||
* @deprecated
|
||||
*/
|
||||
/* XXX: should move into test directory */
|
||||
nsresult xpj_InitXPCOM();
|
||||
|
||||
/**
|
||||
* Find the method info for method or attribute `methodname'.
|
||||
* If an attribute, do not prefix with "get" or "set"; set
|
||||
* `wantsSetter' to select the getter or setter.
|
||||
* The contents of `indexPtr' are set to the method's index.
|
||||
*/
|
||||
nsresult xpj_GetMethodInfoByName(const nsID *iid,
|
||||
const char *methodname,
|
||||
PRBool wantSetter,
|
||||
const nsXPTMethodInfo **miptr,
|
||||
int *indexPtr);
|
||||
|
||||
/* Defined in xpj_nsID.cpp */
|
||||
|
||||
/** Create a new Java wrapper for `id' */
|
||||
jobject ID_NewJavaID(JNIEnv *env, const nsID* id);
|
||||
|
||||
/** Unwrap an nsID; returns the internal struct, *not a copy* */
|
||||
nsID* ID_GetNative(JNIEnv *env, jobject self);
|
||||
|
||||
/** Copies `id' to a Java wrapper */
|
||||
void ID_SetNative(JNIEnv *env, jobject self, nsID* id);
|
||||
|
||||
/** Compares two Java wrappers for an nsID */
|
||||
jboolean ID_IsEqual(JNIEnv *env, jobject self, jobject other);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
819
mozilla/java/xpcom/old/src/xpjava.cpp
Normal file
819
mozilla/java/xpcom/old/src/xpjava.cpp
Normal file
@@ -0,0 +1,819 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
#include <iostream.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "xptinfo.h"
|
||||
#include "xptcall.h"
|
||||
#include "xpt_struct.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#include "xpjava.h"
|
||||
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
#define SAMPLE_DLL "sampl32.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#define XPCOM_DLL "XPCOM_DLL"
|
||||
#define SAMPLE_DLL "SAMPL_DLL"
|
||||
#else
|
||||
#define XPCOM_DLL "libxpcom.so"
|
||||
#define SAMPLE_DLL "libsample.so"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Global references to frequently used classes and objects */
|
||||
static jclass classString;
|
||||
static jclass classByte;
|
||||
static jclass classShort;
|
||||
static jclass classInteger;
|
||||
static jclass classLong;
|
||||
static jclass classFloat;
|
||||
static jclass classDouble;
|
||||
static jclass classBoolean;
|
||||
static jclass classCharacter;
|
||||
|
||||
/* Cached field and method IDs */
|
||||
static jfieldID Byte_value_ID;
|
||||
static jfieldID Short_value_ID;
|
||||
static jfieldID Integer_value_ID;
|
||||
static jfieldID Long_value_ID;
|
||||
static jfieldID Float_value_ID;
|
||||
static jfieldID Double_value_ID;
|
||||
static jfieldID Boolean_value_ID;
|
||||
static jfieldID Character_value_ID;
|
||||
|
||||
static jmethodID Byte_init_ID;
|
||||
static jmethodID Short_init_ID;
|
||||
static jmethodID Integer_init_ID;
|
||||
static jmethodID Long_init_ID;
|
||||
static jmethodID Float_init_ID;
|
||||
static jmethodID Double_init_ID;
|
||||
static jmethodID Boolean_init_ID;
|
||||
static jmethodID Character_init_ID;
|
||||
|
||||
/* Global references to frequently used XPCOM objects */
|
||||
static nsIInterfaceInfoManager *interfaceInfoManager;
|
||||
|
||||
/* Flag to indicate caches filled */
|
||||
static jboolean cache_initialized = JNI_FALSE;
|
||||
|
||||
|
||||
/* ---------- GENERAL API FUNCTIONS ------------ */
|
||||
|
||||
nsresult xpj_InitXPCOM() {
|
||||
nsresult res;
|
||||
|
||||
#ifdef DEBUG_frankm
|
||||
cerr << "Initializing XPCOM" << endl;
|
||||
#endif
|
||||
|
||||
// Autoregistration magic. Boogeda boogeda.
|
||||
res = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup,
|
||||
nsnull);
|
||||
|
||||
#ifdef DEBUG_frankm
|
||||
cerr << "XPCOM Initialized" << endl;
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult xpj_GetMethodInfoByName(const nsID *iid,
|
||||
const char *methodname,
|
||||
PRBool wantSetter,
|
||||
const nsXPTMethodInfo **miptr,
|
||||
int *_retval) {
|
||||
nsresult res;
|
||||
|
||||
// Get info
|
||||
nsIInterfaceInfo *info = nsnull;
|
||||
|
||||
res = interfaceInfoManager->GetInfoForIID(iid, &info);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to find info for " << iid->ToString() << endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
// Find info for command
|
||||
uint16 methodcount;
|
||||
|
||||
info->GetMethodCount(&methodcount);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < methodcount; i++) {
|
||||
const nsXPTMethodInfo *mi;
|
||||
|
||||
info->GetMethodInfo(i, &mi);
|
||||
// PENDING(frankm): match against name, get/set, *AND* param types
|
||||
if (strcmp(methodname, mi->GetName()) == 0) {
|
||||
PRBool setter = mi->IsSetter();
|
||||
PRBool getter = mi->IsGetter();
|
||||
if ((!getter && !setter)
|
||||
|| (setter && wantSetter)
|
||||
|| (getter && !wantSetter)) {
|
||||
*miptr = mi;
|
||||
*_retval = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i >= methodcount) {
|
||||
cerr << "Failed to find " << methodname << endl;
|
||||
*miptr = NULL;
|
||||
*_retval = -1;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ---------- DISPATCH SUPPORT FUNCTIONS ------------ */
|
||||
|
||||
static
|
||||
int xpjd_BuildParamsForOffset(nsIInterfaceInfo *info,
|
||||
jint offset,
|
||||
jint arraysize,
|
||||
nsXPTCVariant **_retval) {
|
||||
const nsXPTMethodInfo *mi;
|
||||
nsresult res;
|
||||
|
||||
// Find info for command
|
||||
uint16 methodcount;
|
||||
|
||||
info->GetMethodCount(&methodcount);
|
||||
|
||||
if (offset < methodcount) {
|
||||
info->GetMethodInfo(offset, &mi);
|
||||
}
|
||||
else {
|
||||
cerr << "Offset " << offset << " should be < " << methodcount << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Make sure the array is large enough, and alloc more if
|
||||
// necessary.
|
||||
int paramcount = mi->GetParamCount();
|
||||
|
||||
if (paramcount > arraysize || *_retval == NULL) {
|
||||
*_retval = (nsXPTCVariant *)
|
||||
nsAllocator::Alloc(sizeof(nsXPTCVariant) * paramcount);
|
||||
}
|
||||
|
||||
// Set flags, pointers, and types for array elements
|
||||
nsXPTCVariant *current = *_retval;
|
||||
|
||||
for (int i = 0; i < paramcount; i++) {
|
||||
nsXPTParamInfo param = mi->GetParam(i);
|
||||
nsXPTType type = param.GetType();
|
||||
|
||||
current->type = type.TagPart();
|
||||
current->flags = 0;
|
||||
|
||||
if (!param.IsOut()) {
|
||||
current->flags = 0;
|
||||
current->ptr = 0;
|
||||
}
|
||||
else {
|
||||
// PTR_IS_DATA: ptr points to 'real' data in val
|
||||
current->flags = nsXPTCVariant::PTR_IS_DATA;
|
||||
|
||||
if (type.IsPointer()) {
|
||||
current->val.p = NULL;
|
||||
current->ptr = ¤t->val.p;
|
||||
// PENDING: does this routine also alloc memory?
|
||||
// Or do we treat pointers to basic types like "out"
|
||||
// parameters?
|
||||
// What about an out parameter that is a
|
||||
}
|
||||
else {
|
||||
// PENDING: Will this work on all platforms?
|
||||
current->ptr = ¤t->val;
|
||||
}
|
||||
}
|
||||
current++;
|
||||
}
|
||||
return paramcount;
|
||||
}
|
||||
|
||||
static jboolean JObjectToVariant(JNIEnv *env,
|
||||
nsXPTCVariant *current,
|
||||
const jobject elem,
|
||||
REFNSIID iid) {
|
||||
jboolean result = JNI_FALSE;
|
||||
/*
|
||||
* Match:
|
||||
* T_BOOL : Boolean
|
||||
* T_I8: Byte
|
||||
* T_I16: Short
|
||||
* T_I32: Integer
|
||||
* T_I64: Long
|
||||
* -- we may want to support widening casts
|
||||
* T_U<n>: T_I<n> type
|
||||
* T_FLOAT: Float
|
||||
* T_DOUBLE: Double (or Float?)
|
||||
* T_CHAR: Character if value is an ASCII value
|
||||
* T_WCHAR: Character
|
||||
* T_CHAR_STRING: String as UTF-8 chars
|
||||
* T_WCHAR_STRING: String as Unicode chars
|
||||
* T_BSTR: String as UTF-8 chars
|
||||
* T_INTERFACE(_IS): XPCOM pointer for an ComObject, if nsID matches
|
||||
*/
|
||||
|
||||
// Integer code assumes that current->val.i# == current->val.u#
|
||||
// for assignment purposes
|
||||
switch(current->type) {
|
||||
case nsXPTType::T_I8:
|
||||
case nsXPTType::T_U8:
|
||||
if (env->IsInstanceOf(elem, classByte)) {
|
||||
current->val.i8 =
|
||||
env->GetByteField(elem, Byte_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_I16:
|
||||
case nsXPTType::T_U16:
|
||||
if (env->IsInstanceOf(elem, classShort)) {
|
||||
current->val.i16 =
|
||||
env->GetShortField(elem, Short_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_I32:
|
||||
case nsXPTType::T_U32:
|
||||
if (env->IsInstanceOf(elem, classInteger)) {
|
||||
current->val.i32 =
|
||||
env->GetShortField(elem, Integer_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_I64:
|
||||
case nsXPTType::T_U64:
|
||||
if (env->IsInstanceOf(elem, classLong)) {
|
||||
current->val.i64 =
|
||||
env->GetShortField(elem, Long_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_FLOAT:
|
||||
if (env->IsInstanceOf(elem, classFloat)) {
|
||||
current->val.f =
|
||||
env->GetFloatField(elem, Float_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE:
|
||||
if (env->IsInstanceOf(elem, classDouble)) {
|
||||
current->val.d =
|
||||
env->GetDoubleField(elem, Double_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_BOOL:
|
||||
if (env->IsInstanceOf(elem, classBoolean)) {
|
||||
current->val.b =
|
||||
env->GetBooleanField(elem, Boolean_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_CHAR:
|
||||
if (env->IsInstanceOf(elem, classCharacter)) {
|
||||
current->val.c =
|
||||
(char)env->GetCharField(elem, Character_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_WCHAR:
|
||||
if (env->IsInstanceOf(elem, classCharacter)) {
|
||||
current->val.wc =
|
||||
env->GetCharField(elem, Character_value_ID);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_CHAR_STR:
|
||||
if (env->IsInstanceOf(elem, classString)) {
|
||||
jstring string = (jstring)elem;
|
||||
jsize jstrlen = env->GetStringUTFLength(string);
|
||||
const char *utf = env->GetStringUTFChars(string, NULL);
|
||||
|
||||
// PENDING: copying every time is wasteful, but
|
||||
// we need to release `utf' before invocation loses it.
|
||||
char *tmpstr = new char[jstrlen + 1];
|
||||
strncpy(tmpstr, utf, jstrlen);
|
||||
tmpstr[jstrlen] = '\0';
|
||||
|
||||
current->val.p = tmpstr;
|
||||
current->flags |= nsXPTCVariant::VAL_IS_OWNED;
|
||||
|
||||
env->ReleaseStringUTFChars(string, utf);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_WCHAR_STR:
|
||||
if (env->IsInstanceOf(elem, classString)) {
|
||||
jstring string = (jstring)elem;
|
||||
jsize jstrlen = env->GetStringLength(string);
|
||||
const jchar *wstr = env->GetStringChars(string, NULL);
|
||||
|
||||
// PENDING: copying every time is wasteful, but
|
||||
// we need to release `wstr' before invocation loses it.
|
||||
PRUnichar *tmpstr = new PRUnichar[jstrlen + 1];
|
||||
memcpy(tmpstr, wstr, jstrlen * sizeof(PRUnichar));
|
||||
tmpstr[jstrlen] = '\0';
|
||||
|
||||
current->val.p = tmpstr;
|
||||
|
||||
env->ReleaseStringChars(string, wstr);
|
||||
result = JNI_TRUE;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_VOID:
|
||||
// PENDING: handle void ptrs
|
||||
break;
|
||||
case nsXPTType::T_IID:
|
||||
// PENDING: unwrap the ID
|
||||
break;
|
||||
case nsXPTType::T_INTERFACE:
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
if (elem == NULL) {
|
||||
current->val.p = NULL;
|
||||
}
|
||||
else {
|
||||
xpjp_QueryInterfaceToXPCOM(env, elem, iid, &(current->val.p));
|
||||
}
|
||||
current->flags |= nsXPTCVariant::VAL_IS_IFACE;
|
||||
break;
|
||||
case nsXPTType::T_BSTR:
|
||||
// Ignore for now
|
||||
break;
|
||||
}
|
||||
// VAL_IS_OWNED: val.p holds alloc'd ptr that must be freed
|
||||
// VAL_IS_IFACE: val.p holds interface ptr that must be released
|
||||
return result;
|
||||
}
|
||||
|
||||
static nsresult JArrayToVariant(JNIEnv *env,
|
||||
int paramcount,
|
||||
nsXPTCVariant *params,
|
||||
const jobjectArray theJarray) {
|
||||
nsXPTCVariant *current = params;
|
||||
|
||||
for (jsize i = 0; i < paramcount; i++, current++) {
|
||||
jobject elem = env->GetObjectArrayElement(theJarray, i);
|
||||
nsIID iid = NS_GET_IID(nsISupports);
|
||||
// PENDING: get the iid of the object
|
||||
|
||||
if (elem == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (JObjectToVariant(env, current, elem, iid) == JNI_FALSE) {
|
||||
// PENDING: throw an exception
|
||||
cerr << "Argument " << i << " is not of the correct type" << endl;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static jobject VariantToJObject(JNIEnv *env, const nsXPTCVariant *current) {
|
||||
jobject result = NULL;
|
||||
|
||||
// Integer code assumes that current->val.i# == current->val.u#
|
||||
// for assignment purposes
|
||||
switch(current->type) {
|
||||
case nsXPTType::T_I8:
|
||||
case nsXPTType::T_U8:
|
||||
result =
|
||||
env->NewObject(classByte,
|
||||
Byte_init_ID,
|
||||
(jbyte)current->val.i16);
|
||||
break;
|
||||
case nsXPTType::T_I16:
|
||||
case nsXPTType::T_U16:
|
||||
result =
|
||||
env->NewObject(classShort,
|
||||
Short_init_ID,
|
||||
(jshort)current->val.i16);
|
||||
break;
|
||||
case nsXPTType::T_I32:
|
||||
case nsXPTType::T_U32:
|
||||
result =
|
||||
env->NewObject(classInteger,
|
||||
Integer_init_ID,
|
||||
(jint)current->val.i32);
|
||||
break;
|
||||
case nsXPTType::T_I64:
|
||||
result =
|
||||
env->NewObject(classLong,
|
||||
Long_init_ID,
|
||||
(jlong)current->val.i64);
|
||||
break;
|
||||
case nsXPTType::T_FLOAT:
|
||||
result =
|
||||
env->NewObject(classFloat,
|
||||
Float_init_ID,
|
||||
(jfloat)current->val.f);
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE:
|
||||
result =
|
||||
env->NewObject(classDouble,
|
||||
Double_init_ID,
|
||||
(jdouble)current->val.d);
|
||||
break;
|
||||
case nsXPTType::T_BOOL:
|
||||
result =
|
||||
env->NewObject(classBoolean,
|
||||
Boolean_init_ID,
|
||||
(jboolean)current->val.b);
|
||||
break;
|
||||
case nsXPTType::T_CHAR:
|
||||
result =
|
||||
env->NewObject(classCharacter,
|
||||
Character_init_ID,
|
||||
(jchar)current->val.c);
|
||||
break;
|
||||
case nsXPTType::T_WCHAR:
|
||||
result =
|
||||
env->NewObject(classCharacter,
|
||||
Character_init_ID,
|
||||
(jchar)current->val.wc);
|
||||
break;
|
||||
case nsXPTType::T_CHAR_STR:
|
||||
if (current->val.p != NULL) {
|
||||
result = env->NewStringUTF((const char *)current->val.p);
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_WCHAR_STR:
|
||||
if (current->val.p != NULL) {
|
||||
jsize len = 0;
|
||||
const jchar *wstr = (const jchar *)current->val.p;
|
||||
// PENDING: is this right?
|
||||
while (wstr[len] != 0) len++;
|
||||
result = env->NewString(wstr, len);
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_VOID:
|
||||
// Ignore for now
|
||||
break;
|
||||
case nsXPTType::T_IID:
|
||||
// Ignore for now
|
||||
if (current->val.p != NULL) {
|
||||
result = ID_NewJavaID(env, (const nsID *)current->val.p);
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_BSTR:
|
||||
// Ignore for now
|
||||
break;
|
||||
case nsXPTType::T_INTERFACE:
|
||||
// Ignore for now
|
||||
break;
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
// Ignore for now
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static nsresult VariantToJArray(JNIEnv *env,
|
||||
jobjectArray theJarray,
|
||||
int paramcount,
|
||||
nsXPTCVariant *params) {
|
||||
nsXPTCVariant *current = params;
|
||||
|
||||
for (jsize i = 0; i < paramcount; i++, current++) {
|
||||
jobject elem = NULL; // env->GetObjectArrayElement(theJarray, i);
|
||||
jboolean isequal = JNI_FALSE;
|
||||
nsXPTCVariant currValue;
|
||||
|
||||
if (!(current->flags & nsXPTCVariant::PTR_IS_DATA)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (elem != NULL) {
|
||||
nsIID iid = NS_GET_IID(nsISupports);
|
||||
// PENDING: get the iid of the object
|
||||
|
||||
memcpy(&currValue, current, sizeof(nsXPTCVariant));
|
||||
if (JObjectToVariant(env, &currValue, elem, iid) != JNI_FALSE) {
|
||||
isequal =
|
||||
(memcmp(&currValue, current, sizeof(nsXPTCVariant)) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (isequal) {
|
||||
// PENDING: what about casting to more specific interfaces?
|
||||
continue;
|
||||
}
|
||||
|
||||
elem = VariantToJObject(env, current);
|
||||
|
||||
env->SetObjectArrayElement(theJarray, i, elem);
|
||||
|
||||
if (current->flags & nsXPTCVariant::VAL_IS_IFACE) {
|
||||
xpjp_SafeRelease((nsISupports*)current->val.p);
|
||||
}
|
||||
|
||||
if (current->flags & nsXPTCVariant::VAL_IS_OWNED) {
|
||||
delete [] current->val.p;
|
||||
current->val.p = 0; // for cleanliness sake
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* ---------- DISPATCH API FUNCTIONS ------------ */
|
||||
|
||||
jboolean xpjd_InitJavaCaches(JNIEnv *env) {
|
||||
|
||||
if (cache_initialized) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
// For basic types
|
||||
|
||||
classString = env->FindClass("java/lang/String");
|
||||
if (classString == NULL) return JNI_FALSE;
|
||||
classString = (jclass)env->NewGlobalRef(classString);
|
||||
if (classString == NULL) return JNI_FALSE;
|
||||
|
||||
classByte = env->FindClass("java/lang/Byte");
|
||||
if (classByte == NULL) return JNI_FALSE;
|
||||
classByte = (jclass)env->NewGlobalRef(classByte);
|
||||
if (classByte == NULL) return JNI_FALSE;
|
||||
|
||||
classShort = env->FindClass("java/lang/Short");
|
||||
if (classShort == NULL) return JNI_FALSE;
|
||||
classShort = (jclass)env->NewGlobalRef(classShort);
|
||||
if (classShort == NULL) return JNI_FALSE;
|
||||
|
||||
classInteger = env->FindClass("java/lang/Integer");
|
||||
if (classInteger == NULL) return JNI_FALSE;
|
||||
classInteger = (jclass)env->NewGlobalRef(classInteger);
|
||||
if (classInteger == NULL) return JNI_FALSE;
|
||||
|
||||
classLong = env->FindClass("java/lang/Long");
|
||||
if (classLong == NULL) return JNI_FALSE;
|
||||
classLong = (jclass)env->NewGlobalRef(classLong);
|
||||
if (classLong == NULL) return JNI_FALSE;
|
||||
|
||||
classFloat = env->FindClass("java/lang/Float");
|
||||
if (classFloat == NULL) return JNI_FALSE;
|
||||
classFloat = (jclass)env->NewGlobalRef(classFloat);
|
||||
if (classFloat == NULL) return JNI_FALSE;
|
||||
|
||||
classDouble = env->FindClass("java/lang/Double");
|
||||
if (classDouble == NULL) return JNI_FALSE;
|
||||
classDouble = (jclass)env->NewGlobalRef(classDouble);
|
||||
if (classDouble == NULL) return JNI_FALSE;
|
||||
|
||||
classBoolean = env->FindClass("java/lang/Boolean");
|
||||
if (classBoolean == NULL) return JNI_FALSE;
|
||||
classBoolean = (jclass)env->NewGlobalRef(classBoolean);
|
||||
if (classBoolean == NULL) return JNI_FALSE;
|
||||
|
||||
classCharacter = env->FindClass("java/lang/Character");
|
||||
if (classCharacter == NULL) return JNI_FALSE;
|
||||
classCharacter = (jclass)env->NewGlobalRef(classCharacter);
|
||||
if (classCharacter == NULL) return JNI_FALSE;
|
||||
|
||||
Byte_init_ID = env->GetMethodID(classByte, "<init>", "(B)V");
|
||||
if (Byte_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Byte_value_ID = env->GetFieldID(classByte, "value", "B");
|
||||
if (Byte_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Short_init_ID = env->GetMethodID(classShort, "<init>", "(S)V");
|
||||
if (Short_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Short_value_ID = env->GetFieldID(classShort, "value", "S");
|
||||
if (Short_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Integer_init_ID = env->GetMethodID(classInteger, "<init>", "(I)V");
|
||||
if (Integer_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Integer_value_ID = env->GetFieldID(classInteger, "value", "I");
|
||||
if (Integer_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Long_init_ID = env->GetMethodID(classLong, "<init>", "(J)V");
|
||||
if (Long_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Long_value_ID = env->GetFieldID(classLong, "value", "J");
|
||||
if (Long_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Float_init_ID = env->GetMethodID(classFloat, "<init>", "(F)V");
|
||||
if (Float_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Float_value_ID = env->GetFieldID(classFloat, "value", "F");
|
||||
if (Float_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Double_init_ID = env->GetMethodID(classDouble, "<init>", "(D)V");
|
||||
if (Double_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Double_value_ID = env->GetFieldID(classDouble, "value", "D");
|
||||
if (Double_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Boolean_init_ID = env->GetMethodID(classBoolean, "<init>", "(Z)V");
|
||||
if (Boolean_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Boolean_value_ID = env->GetFieldID(classBoolean, "value", "Z");
|
||||
if (Boolean_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Character_init_ID = env->GetMethodID(classCharacter, "<init>", "(C)V");
|
||||
if (Integer_init_ID == NULL) return JNI_FALSE;
|
||||
|
||||
Character_value_ID = env->GetFieldID(classCharacter, "value", "C");
|
||||
if (Character_value_ID == NULL) return JNI_FALSE;
|
||||
|
||||
// Get InterfaceInfoManager
|
||||
|
||||
#ifdef DEBUG_frankm
|
||||
cerr << "Getting InterfaceInfoManager" << endl;
|
||||
#endif
|
||||
|
||||
interfaceInfoManager = XPTI_GetInterfaceInfoManager();
|
||||
|
||||
if (!interfaceInfoManager) {
|
||||
// XXX: throw exception or something
|
||||
cerr << "Failed to find InterfaceInfoManager" << endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_frankm
|
||||
cerr << "InterfaceInfoManager found!" << endl;
|
||||
#endif
|
||||
|
||||
cache_initialized = JNI_TRUE;
|
||||
|
||||
return cache_initialized;
|
||||
}
|
||||
|
||||
void xpjd_FlushJavaCaches(JNIEnv *env) {
|
||||
|
||||
cache_initialized = JNI_FALSE;
|
||||
|
||||
// For basic types
|
||||
|
||||
env->DeleteGlobalRef(classString);
|
||||
classString = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classByte);
|
||||
classByte = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classShort);
|
||||
classShort = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classInteger);
|
||||
classInteger = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classLong);
|
||||
classLong = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classFloat);
|
||||
classFloat = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classDouble);
|
||||
classDouble = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classBoolean);
|
||||
classBoolean = NULL;
|
||||
|
||||
env->DeleteGlobalRef(classCharacter);
|
||||
classCharacter = NULL;
|
||||
|
||||
Byte_init_ID = NULL;
|
||||
Byte_value_ID = NULL;
|
||||
Short_init_ID = NULL;
|
||||
Short_value_ID = NULL;
|
||||
Integer_init_ID = NULL;
|
||||
Integer_value_ID = NULL;
|
||||
Long_init_ID = NULL;
|
||||
Long_value_ID = NULL;
|
||||
Float_init_ID = NULL;
|
||||
Float_value_ID = NULL;
|
||||
Double_init_ID = NULL;
|
||||
Double_value_ID = NULL;
|
||||
Boolean_init_ID = NULL;
|
||||
Boolean_value_ID = NULL;
|
||||
Character_init_ID = NULL;
|
||||
Character_value_ID = NULL;
|
||||
}
|
||||
|
||||
jboolean xpjd_GetInterfaceInfo(JNIEnv *env,
|
||||
jobject iid,
|
||||
nsIInterfaceInfo **info) {
|
||||
nsID *nativeIID = ID_GetNative(env, iid);
|
||||
|
||||
return xpjd_GetInterfaceInfoNative(*nativeIID, info);
|
||||
}
|
||||
|
||||
jboolean xpjd_GetInterfaceInfoNative(REFNSIID iid,
|
||||
nsIInterfaceInfo **info) {
|
||||
nsresult res;
|
||||
|
||||
// Get info
|
||||
*info = nsnull;
|
||||
|
||||
res = interfaceInfoManager->GetInfoForIID(&iid, info);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
cerr << "Failed to find info for " << iid.ToString() << endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
void xpjd_InvokeMethod(JNIEnv *env,
|
||||
nsISupports *target,
|
||||
nsIInterfaceInfo *info,
|
||||
jint methodIndex,
|
||||
jobjectArray jargs) {
|
||||
|
||||
nsresult res = NS_OK;
|
||||
nsXPTCVariant paramArray[32];
|
||||
nsXPTCVariant *params = paramArray;
|
||||
int nparams = 0;
|
||||
const int capacity = sizeof(paramArray)/sizeof(paramArray[0]);
|
||||
|
||||
// XXX: check info != NULL, target != null, jargs != null, env != null
|
||||
|
||||
// XXX: check bounds of methodIndex
|
||||
|
||||
nparams = xpjd_BuildParamsForOffset(info,
|
||||
methodIndex,
|
||||
capacity,
|
||||
¶ms);
|
||||
if (nparams < 0) {
|
||||
// PENDING: throw an exception
|
||||
cerr << "Couldn't initialize parameter array" << endl;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
res = JArrayToVariant(env, nparams, params, jargs);
|
||||
if (NS_FAILED(res)) {
|
||||
// PENDING: throw an exception
|
||||
cerr << "Array and parameter list mismatch" << endl;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
//xpjp_SafeAddRef(target);
|
||||
|
||||
res = XPTC_InvokeByIndex(target, methodIndex, nparams, params);
|
||||
|
||||
//xpjp_SafeRelease(target);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
// PENDING: throw an exception
|
||||
cerr << "Invocation failed, status: " << res << endl;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
res = VariantToJArray(env, jargs, nparams, params);
|
||||
if (NS_FAILED(res)) {
|
||||
// PENDING: throw an exception
|
||||
cerr << "Array and parameter list mismatch" << endl;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
finally:
|
||||
if (params != paramArray) {
|
||||
nsAllocator::Free(params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
mozilla/java/xpcom/old/src/xpjava.h
Normal file
25
mozilla/java/xpcom/old/src/xpjava.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
|
||||
#include "xpj_dispatch.h"
|
||||
#include "xpj_proxy.h"
|
||||
#include "xpj_utils.h"
|
||||
73
mozilla/java/xpcom/old/test/JSISample.idl
Normal file
73
mozilla/java/xpcom/old/test/JSISample.idl
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 Frank
|
||||
* Mitchell. Portions created by Frank Mitchell are
|
||||
* Copyright (C) 1999 Frank Mitchell. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Frank Mitchell (frank.mitchell@sun.com)
|
||||
*/
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* blah blah blah.
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface JSIComplex;
|
||||
|
||||
[object, uuid(57ecad90-ae1a-11d1-b66c-00805f8a2676)]
|
||||
interface JSISample : nsISupports {
|
||||
|
||||
// basic method
|
||||
void PrintStats();
|
||||
|
||||
// attributes
|
||||
attribute long someInt;
|
||||
attribute boolean someBool;
|
||||
readonly attribute long roInt;
|
||||
attribute double someDouble;
|
||||
attribute string someName;
|
||||
readonly attribute string roString;
|
||||
|
||||
// methods
|
||||
void TakeInt(in long anInt);
|
||||
long GiveInt();
|
||||
long GiveAndTake(inout long anInt);
|
||||
|
||||
string TooManyArgs(in short oneInt,
|
||||
in short twoInt,
|
||||
inout long redInt,
|
||||
out short blueInt,
|
||||
in double orNothing,
|
||||
in long long johnSilver,
|
||||
in boolean algebra);
|
||||
|
||||
string CatStrings(in string str1, in string str2);
|
||||
void AppendString(inout string str1, in string str2);
|
||||
|
||||
JSIComplex NewComplex(in long aReal, in long anImaginary);
|
||||
JSIComplex AddComplex(in JSIComplex complex1, in JSIComplex complex2);
|
||||
void AddInPlace(inout JSIComplex complex1, in JSIComplex complex2);
|
||||
|
||||
long AddTwoInts(in long int1, in long int2);
|
||||
};
|
||||
|
||||
[object, uuid(57ecad91-ae1a-11d1-b66c-00805f8a2676)]
|
||||
interface JSIComplex : nsISupports {
|
||||
// attributes
|
||||
attribute long real;
|
||||
attribute long imaginary;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user