mirror of https://github.com/axmolengine/axmol.git
fixed #2155 : Resolve the bug of callback methods in plugin.
This commit is contained in:
parent
5a9db1a8da
commit
79bd3c990e
|
@ -119,10 +119,10 @@ JNIEnv* PluginUtils::getEnv()
|
|||
}
|
||||
|
||||
std::map<PluginProtocol*, PluginJavaData*> s_PluginObjMap;
|
||||
std::map<jobject, PluginProtocol*> s_JObjPluginMap;
|
||||
std::map<std::string, PluginProtocol*> s_JObjPluginMap;
|
||||
|
||||
typedef std::map<PluginProtocol*, PluginJavaData*>::iterator ObjMapIter;
|
||||
typedef std::map<jobject, PluginProtocol*>::iterator JObjPluginMapIter;
|
||||
typedef std::map<std::string, PluginProtocol*>::iterator JObjPluginMapIter;
|
||||
|
||||
PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj)
|
||||
{
|
||||
|
@ -135,10 +135,10 @@ PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj)
|
|||
return ret;
|
||||
}
|
||||
|
||||
PluginProtocol* PluginUtils::getPluginPtr(jobject jobj)
|
||||
PluginProtocol* PluginUtils::getPluginPtr(std::string className)
|
||||
{
|
||||
PluginProtocol* ret = NULL;
|
||||
JObjPluginMapIter it = s_JObjPluginMap.find(jobj);
|
||||
JObjPluginMapIter it = s_JObjPluginMap.find(className);
|
||||
if (it != s_JObjPluginMap.end()) {
|
||||
ret = it->second;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ void PluginUtils::setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pDa
|
|||
{
|
||||
erasePluginJavaData(pKeyObj);
|
||||
s_PluginObjMap.insert(std::pair<PluginProtocol*, PluginJavaData*>(pKeyObj, pData));
|
||||
s_JObjPluginMap.insert(std::pair<jobject, PluginProtocol*>(pData->jobj, pKeyObj));
|
||||
s_JObjPluginMap.insert(std::pair<std::string, PluginProtocol*>(pData->jclassName, pKeyObj));
|
||||
}
|
||||
|
||||
void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj)
|
||||
|
@ -162,7 +162,7 @@ void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj)
|
|||
{
|
||||
jobject jobj = pData->jobj;
|
||||
|
||||
JObjPluginMapIter pluginIt = s_JObjPluginMap.find(jobj);
|
||||
JObjPluginMapIter pluginIt = s_JObjPluginMap.find(pData->jclassName);
|
||||
if (pluginIt != s_JObjPluginMap.end())
|
||||
{
|
||||
s_JObjPluginMap.erase(pluginIt);
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
static void setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData);
|
||||
static void erasePluginJavaData(PluginProtocol* pKeyObj);
|
||||
|
||||
static PluginProtocol* getPluginPtr(jobject jobj);
|
||||
static PluginProtocol* getPluginPtr(std::string className);
|
||||
|
||||
template <typename T>
|
||||
static void callJavaFunctionWithName_oneBaseType(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
|
||||
|
|
|
@ -37,9 +37,10 @@ THE SOFTWARE.
|
|||
namespace cocos2d { namespace plugin {
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg) {
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) {
|
||||
std::string strMsg = PluginJniHelper::jstring2string(msg);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
|
||||
std::string strClassName = PluginJniHelper::jstring2string(className);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
|
||||
LOGD("nativeOnAdsResult(), Get plugin ptr : %p", pPlugin);
|
||||
if (pPlugin != NULL)
|
||||
{
|
||||
|
@ -52,8 +53,9 @@ extern "C" {
|
|||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jobject obj, jint points) {
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) {
|
||||
std::string strClassName = PluginJniHelper::jstring2string(className);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
|
||||
LOGD("nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin);
|
||||
if (pPlugin != NULL)
|
||||
{
|
||||
|
|
|
@ -37,10 +37,11 @@ THE SOFTWARE.
|
|||
namespace cocos2d { namespace plugin {
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg)
|
||||
{
|
||||
std::string strMsg = PluginJniHelper::jstring2string(msg);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
|
||||
std::string strClassName = PluginJniHelper::jstring2string(className);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
|
||||
LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
|
||||
if (pPlugin != NULL)
|
||||
{
|
||||
|
|
|
@ -37,10 +37,11 @@ THE SOFTWARE.
|
|||
namespace cocos2d { namespace plugin {
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg)
|
||||
{
|
||||
std::string strMsg = PluginJniHelper::jstring2string(msg);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
|
||||
std::string strClassName = PluginJniHelper::jstring2string(className);
|
||||
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
|
||||
LOGD("nativeOnShareResult(), Get plugin ptr : %p", pPlugin);
|
||||
if (pPlugin != NULL)
|
||||
{
|
||||
|
|
|
@ -101,11 +101,13 @@ public class InterfaceAds {
|
|||
PluginWrapper.runOnGLThread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
InterfaceAds.nativeOnAdsResult(curObj, curCode, curMsg);
|
||||
String name = curObj.getClass().getName();
|
||||
name = name.replace('.', '/');
|
||||
InterfaceAds.nativeOnAdsResult(name, curCode, curMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
private native static void nativeOnAdsResult(Object obj, int code, String msg);
|
||||
private native static void nativeOnAdsResult(String className, int code, String msg);
|
||||
|
||||
public static void onPlayerGetPoints(AdsAdapter adapter, int points) {
|
||||
final int curPoints = points;
|
||||
|
@ -113,9 +115,11 @@ public class InterfaceAds {
|
|||
PluginWrapper.runOnGLThread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
InterfaceAds.nativeOnPlayerGetPoints(curAdapter, curPoints);
|
||||
String name = curAdapter.getClass().getName();
|
||||
name = name.replace('.', '/');
|
||||
InterfaceAds.nativeOnPlayerGetPoints(name, curPoints);
|
||||
}
|
||||
});
|
||||
}
|
||||
private native static void nativeOnPlayerGetPoints(Object obj, int points);
|
||||
private native static void nativeOnPlayerGetPoints(String className, int points);
|
||||
}
|
||||
|
|
|
@ -45,9 +45,11 @@ public class InterfaceIAP {
|
|||
PluginWrapper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnPayResult(curObj, curRet, curMsg);
|
||||
String name = curObj.getClass().getName();
|
||||
name = name.replace('.', '/');
|
||||
nativeOnPayResult(name, curRet, curMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
private static native void nativeOnPayResult(Object obj, int ret, String msg);
|
||||
private static native void nativeOnPayResult(String className, int ret, String msg);
|
||||
}
|
||||
|
|
|
@ -45,9 +45,11 @@ public class InterfaceSocial {
|
|||
PluginWrapper.runOnGLThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeOnShareResult(curAdapter, curRet, curMsg);
|
||||
String name = curAdapter.getClass().getName();
|
||||
name = name.replace('.', '/');
|
||||
nativeOnShareResult(name, curRet, curMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
private static native void nativeOnShareResult(Object obj, int ret, String msg);
|
||||
private static native void nativeOnShareResult(String className, int ret, String msg);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue