示例#1
0
文件: common.cpp 项目: pelya/Osmand
jclass findClass(const char* className, bool mustHave/* = true*/)
{
	jclass javaClass = getGlobalJniEnv()->FindClass(className);
	if(!javaClass && mustHave)
		throwNewException((std::string("Failed to find class ") + className).c_str());
	return (jclass)newGlobalRef(javaClass);
}
示例#2
0
文件: List.cpp 项目: msavva/pigraphs
  template <> inline JFieldProxy< ::jace::proxy::java::util::List >::JFieldProxy(jfieldID _fieldID, jvalue value, jclass _parentClass): 
    ::jace::proxy::java::util::List(value), fieldID(_fieldID)
  {
    JNIEnv* env = attach();

    parent = 0;
    parentClass = static_cast<jclass>(newGlobalRef(env, _parentClass));
  }
示例#3
0
  template <> inline JFieldProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >::JFieldProxy(jfieldID _fieldID, jvalue value, jclass _parentClass): 
    ::jace::proxy::edu::stanford::graphics::wekautils::Common(value), fieldID(_fieldID)
  {
    JNIEnv* env = attach();

    parent = 0;
    parentClass = static_cast<jclass>(newGlobalRef(env, _parentClass));
  }
示例#4
0
void JavaObject::attach(jobject javaObject)
{
	UPDATE_STATS(0, -1);

	handle_.MakeWeak(this, DetachCallback);

	javaObject_ = javaObject;
	newGlobalRef();
}
示例#5
0
文件: List.cpp 项目: msavva/pigraphs
  template <> inline JFieldProxy< ::jace::proxy::java::util::List >::JFieldProxy(const JFieldProxy< ::jace::proxy::java::util::List >& object): 
    ::jace::proxy::java::util::List(object)
  {
    fieldID = object.fieldID; 

    if (object.parent)
    {
      JNIEnv* env = attach();
      parent = newGlobalRef(env, object.parent);
    }
    else
      parent = 0;

    if (object.parentClass)
    {
      JNIEnv* env = attach();
      parentClass = static_cast<jclass>(newGlobalRef(env, object.parentClass));
    }
    else
      parentClass = 0;
  }
示例#6
0
文件: List.cpp 项目: msavva/pigraphs
  template <> inline JFieldProxy< ::jace::proxy::java::util::List >::JFieldProxy(jfieldID _fieldID, jvalue value, jobject _parent): 
    ::jace::proxy::java::util::List(value), fieldID(_fieldID)
  {
    JNIEnv* env = attach();

    if (_parent)
      parent = newGlobalRef(env, _parent);
    else
      parent = _parent;

    parentClass = 0;
  }
示例#7
0
  template <> inline JFieldProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >::JFieldProxy(const JFieldProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >& object): 
    ::jace::proxy::edu::stanford::graphics::wekautils::Common(object)
  {
    fieldID = object.fieldID; 

    if (object.parent)
    {
      JNIEnv* env = attach();
      parent = newGlobalRef(env, object.parent);
    }
    else
      parent = 0;

    if (object.parentClass)
    {
      JNIEnv* env = attach();
      parentClass = static_cast<jclass>(newGlobalRef(env, object.parentClass));
    }
    else
      parentClass = 0;
  }
示例#8
0
  template <> inline JFieldProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >::JFieldProxy(jfieldID _fieldID, jvalue value, jobject _parent): 
    ::jace::proxy::edu::stanford::graphics::wekautils::Common(value), fieldID(_fieldID)
  {
    JNIEnv* env = attach();

    if (_parent)
      parent = newGlobalRef(env, _parent);
    else
      parent = _parent;

    parentClass = 0;
  }
void JavaObject::attach(jobject javaObject)
{
	ASSERT((javaObject && javaObject_ == NULL) || javaObject == NULL);
	UPDATE_STATS(0, -1);

	handle_.MakeWeak(this, DetachCallback);

	if (javaObject) {
		javaObject_ = javaObject;
	}
	newGlobalRef();
}
// Attaches the Java object to this native wrapper.
// This wrapper will create a global reference to the
// Java object and keep it from becoming collected by Dalvik
// until it is detached or made weak (weakGlobalRef()).
void JavaObject::attach(jobject javaObject)
{
	ASSERT((javaObject && javaObject_ == NULL) || javaObject == NULL);
	UPDATE_STATS(0, -1);

	if (javaObject) {
		javaObject_ = javaObject;
	}
	// make strong ref to Java object in JVM
	newGlobalRef();

	// So let's mark this JS object as independent and weak so V8 can tell us
	// when the JS object is ready to be GCed, which is first step in it's death
	persistent().SetWeak(this, DetachCallback);
	persistent().MarkIndependent();
}
示例#11
0
void setClassLoader(jobject classLoader) {

    JNIEnv* env = attach();
    jobject oldRef = getClassLoader();

#ifdef SUPPORTS_PTHREADS
    int rc;
#elif _WIN32
    BOOL rc;
#endif

    // Set the new value
    if ( classLoader != 0 ) {
        classLoader = static_cast<jobject> ( newGlobalRef( env, classLoader ) );
    }
#ifdef SUPPORTS_PTHREADS
    rc = pthread_setspecific( CLASSLOADER_KEY, classLoader );
    if ( rc != 0 ) {
        std::string msg = "JNIHelper::setClassLoader()\n"
                "pthread_setspecific() returned " + std::to_string( rc ) + ".";
        throw JNIException( msg );
    }
#elif _WIN32
    rc = TlsSetValue( CLASSLOADER_KEY, classLoader );
    if ( !rc ) {
        std::string msg = "JNIHelper::setClassLoader()\n"
                "TlsSetValue() returned " + std::to_string( GetLastError() ) + ".";
        throw JNIException( msg );
    }
#endif

    // Delete the old value if necessary
    if ( oldRef != 0 ) {
        classLoaderDestructor( oldRef );
    }
}
示例#12
0
文件: List.cpp 项目: msavva/pigraphs
 template <> inline ElementProxy< ::jace::proxy::java::util::List >::ElementProxy(const jace::ElementProxy< ::jace::proxy::java::util::List >& proxy): 
   ::jace::proxy::java::util::List(proxy), index(proxy.index)
 {
   JNIEnv* env = attach();
   parent = static_cast<jarray>(newGlobalRef(env, proxy.parent));
 }
示例#13
0
文件: List.cpp 项目: msavva/pigraphs
 template <> inline ElementProxy< ::jace::proxy::java::util::List >::ElementProxy(jarray array, jvalue element, int _index): 
   ::jace::proxy::java::util::List(element), index(_index)
 {
   JNIEnv* env = attach();
   parent = static_cast<jarray>(newGlobalRef(env, array));
 }
示例#14
0
 template <> inline ElementProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >::ElementProxy(jarray array, jvalue element, int _index): 
   ::jace::proxy::edu::stanford::graphics::wekautils::Common(element), index(_index)
 {
   JNIEnv* env = attach();
   parent = static_cast<jarray>(newGlobalRef(env, array));
 }
示例#15
0
 template <> inline ElementProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >::ElementProxy(const jace::ElementProxy< ::jace::proxy::edu::stanford::graphics::wekautils::Common >& proxy): 
   ::jace::proxy::edu::stanford::graphics::wekautils::Common(proxy), index(proxy.index)
 {
   JNIEnv* env = attach();
   parent = static_cast<jarray>(newGlobalRef(env, proxy.parent));
 }