JNI側で実行できます。
long Java_mypackage_com_createSingleton(JNIEnv* env)
{
return MySingleton::getInstance();
}
bool Java_mypackage_com_useSingletonSomehow(long singleton)
{
return (MySingleton*)singleton->someFunc();
}
シングルトンクラスの場合:
MySingleton* getInstance()
{
if(instance_ == NULL)
{
instance_ = new MySingleton();
}
return instance_;
}
Java側:
package mypackage.com;
class SingletonUser
{
private long mSingletonInstance;
public SingletonUser() {
mSingleton = createSingleton();
}
public boolean someFunc() {
return useSingletonSomehow(mSingletonInstance);
}
private native boolean useSingletonSomehow(long instance);
private native long createSingleton();
}