Skip to content

Commit

Permalink
Add Registry class for storing information about java-c++
Browse files Browse the repository at this point in the history
objects binding
  • Loading branch information
idk%eng.sun.com committed Sep 25, 1999
1 parent 0e1d8c6 commit dd3ecbe
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 5 deletions.
45 changes: 45 additions & 0 deletions java/plugins/classes/org/mozilla/pluglet/Registry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* -*- 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.0 (the "License"); you 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 Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
* Inc. All Rights Reserved.
*/
package org.mozilla.pluglet;

import java.util.*;

public class Registry {
static Hashtable table = null;
public static void setPeer(Object key,long peer) {
if (table == null) {
table = new Hashtable(10);
}
table.put(key, new Long(peer));
}
public static long getPeer(Object key) {
if (table == null) {
return 0;
}
Object obj = table.get(key);
if (obj == null) {
return 0;
} else {
return ((Long)obj).longValue();
}
}
public static void remove(Object key) {
if (table != null) {
table.remove(key);
}
}

}
2 changes: 1 addition & 1 deletion java/plugins/src/Pluglet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ nsresult Pluglet::CreatePluginInstance(const char* aPluginMIMEType, void **aResu
nsresult Pluglet::Initialize(void) {
JNIEnv *env = PlugletEngine::GetJNIEnv();
if(!env) {
return NS_ERROR_FAILURE;
return NS_ERROR_FAILURE;
}
if (!initializeMID) {
jclass clazz = env->FindClass("org/mozilla/pluglet/Pluglet");
Expand Down
6 changes: 4 additions & 2 deletions java/plugins/src/PlugletInstance.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/* -*- 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.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
Expand All @@ -17,7 +17,7 @@
#include "PlugletEngine.h"
#include "PlugletStreamListener.h"
#include "PlugletInstancePeer.h"

#include "Registry.h"

jmethodID PlugletInstance::initializeMID = NULL;
jmethodID PlugletInstance::startMID = NULL;
Expand All @@ -37,9 +37,11 @@ PlugletInstance::PlugletInstance(jobject object) {
//nb check for null
peer = NULL;
view = new PlugletInstanceView();
Registry::SetPeer(jthis,(jlong)this);
}

PlugletInstance::~PlugletInstance() {
Registry::Remove(jthis);
PlugletEngine::GetJNIEnv()->DeleteGlobalRef(jthis);
NS_RELEASE(peer);
}
Expand Down
2 changes: 1 addition & 1 deletion java/plugins/src/PlugletInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
#ifndef __PlugletInstance_h__
#define __PlugletInstance_h__
#include "jni.h"
#include "nsplugin.h"
#include "jni.h"
#include "PlugletInstanceView.h"

class PlugletInstance : public nsIPluginInstance {
Expand Down
87 changes: 87 additions & 0 deletions java/plugins/src/Registry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* -*- 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.0 (the "License"); you 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 Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
* Inc. All Rights Reserved.
*/

#include "PlugletEngine.h"
#include "Registry.h"

jclass Registry::clazz = NULL;
jmethodID Registry::setPeerMID = NULL;
jmethodID Registry::removeMID = NULL;

void Registry::SetPeer(jobject key, jlong peer) {
if (!clazz) {
Initialize();
if(!clazz) {
return;
}
}
JNIEnv *env = PlugletEngine::GetJNIEnv();
env->CallStaticVoidMethod(clazz,setPeerMID,key,peer);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
}

void Registry::Remove(jobject key) {
if (!clazz) { // it is impossible
Initialize();
if(!clazz) {
return;
}
}
JNIEnv *env = PlugletEngine::GetJNIEnv();
env->CallStaticVoidMethod(clazz,removeMID,key);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
}

void Registry::Initialize() {
JNIEnv *env = PlugletEngine::GetJNIEnv();
if(!env) {
return;
}
clazz = env->FindClass("org/mozilla/pluglet/Registry");
if(!clazz) {
env->ExceptionDescribe();
return;
}
setPeerMID = env->GetStaticMethodID(clazz,"setPeer","(Ljava/lang/Object;J)V");
if (!setPeerMID) {
env->ExceptionDescribe();
clazz = NULL;
return;
}
removeMID = env->GetStaticMethodID(clazz,"remove","(Ljava/lang/Object;)V");
if (!removeMID) {
env->ExceptionDescribe();
clazz = NULL;
return;
}
}











33 changes: 33 additions & 0 deletions java/plugins/src/Registry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you 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 Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
* Inc. All Rights Reserved.
*/
#ifndef __Registry_h__
#define __Registry_h__
#include "jni.h"
class Registry {
public:
static void SetPeer(jobject key, jlong peer);
static void Remove(jobject key);
private:
static void Initialize();
static jclass clazz;
static jmethodID setPeerMID;
static jmethodID removeMID;
};
#endif /* __Registry_h__ */




3 changes: 2 additions & 1 deletion java/plugins/src/makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ OBJS = \
.\$(OBJDIR)\PlugletInstancePeer.obj \
.\$(OBJDIR)\PlugletManager.obj \
.\$(OBJDIR)\PlugletInputStream.obj \
.\$(OBJDIR)\PlugletInstanceView.obj
.\$(OBJDIR)\PlugletInstanceView.obj \
.\$(OBJDIR)\Registry.obj

MAKE_OBJ_TYPE = DLL

Expand Down

0 comments on commit dd3ecbe

Please sign in to comment.