JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jobject obj, jint points) { PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj); LOGD("nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { LOGD("nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin); if (pAds != NULL) { pAds->onPlayerGetPoints(points); } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj); LOGD("nativeOnAdsResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { LOGD("nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin); if (pAds != NULL) { pAds->onAdsResult((AdsResultCode) ret, strMsg.c_str()); } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnRequestProductsResult (JNIEnv* env, jobject thiz, jstring className, jint ret, jobjectArray stringArray) { std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolIAP", "onRequestProductsResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolIAP", "onRequestProductsResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin); if (pIAP != NULL) { TProductList tplist; if(stringArray != NULL) { int stringCount = env->GetArrayLength(stringArray); for (int i=0; i<stringCount; i++) { jstring string = (jstring) env->GetObjectArrayElement(stringArray, i); auto map = PluginJniHelper::jsonString2Map(string); tplist.push_back(*map); env->DeleteLocalRef(string); } } pIAP->onRequestProductsResult((IAPProductRequest)ret, tplist); } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnRequestOwnedProductsResult (JNIEnv* env, jobject thiz, jstring className, jint ret, jobjectArray plist) { std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolIAP", "onRequestOwnedProductsResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolIAP", "onRequestOwnedProductsResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin); if (pIAP != NULL) { std::vector<std::string> pplist; if(plist != NULL) { int stringCount = env->GetArrayLength(plist); for (int i=0; i<stringCount; i++) { jstring string = (jstring) env->GetObjectArrayElement(plist, i); const char* chars = env->GetStringUTFChars(string, NULL); pplist.push_back(chars); env->ReleaseStringUTFChars(string, chars); env->DeleteLocalRef(string); } } pIAP->onRequestOwnedProductsResult((IAPProductRequest)ret, pplist); } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_ShareWrapper_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolShare", "nativeOnShareResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolShare", "nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolShare* pShare = dynamic_cast<ProtocolShare*>(pPlugin); if (pShare != NULL) { ShareResultListener* listener = pShare->getResultListener(); ProtocolShare::ProtocolShareCallback callback = pShare->getListener(); if (NULL != listener) { ShareResultCode cRet = (ShareResultCode) ret; listener->onShareResult(cRet, strMsg.c_str()); }else if(callback){ callback(ret, strMsg); }else { PluginUtils::outputLog("ProtocolShare", "Can't find the listener of plugin %s", pPlugin->getPluginName()); } } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsWrapper_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin); if (pAds != NULL) { AdsListener* listener = pAds->getAdsListener(); if (listener) { listener->onAdsResult((AdsResultCode) ret, strMsg.c_str()); } else { ProtocolAds::ProtocolAdsCallback callback = pAds->getCallback(); if(callback) { callback(ret, strMsg); } } } } }
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); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { LOGD("nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin); if (pIAP != NULL) { pIAP->onPayResult((PayResultCode) ret, strMsg.c_str()); } } }
JNIEXPORT jobject JNICALL Java_com_opensdk_framework_NativeInvoker_nativeGetLoginInfo(JNIEnv* env, jobject thiz, jstring pluginKey) { std::string strPluginKey = PluginJniHelper::jstring2string(pluginKey); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strPluginKey); PluginUtils::outputLog("ProtocolUser", "nativeOnActionResult(), Get plugin ptr : %p", pPlugin); UserObject* userObject = dynamic_cast<UserObject*>(pPlugin); jobject loginInfo; if (userObject != NULL) { loginInfo=PluginUtils::createJavaMapObject(userObject->getLoginInfo()); }else{ PluginUtils::outputLog("ProtocolUser", "plugin %s is null", pPlugin->getPluginName()); loginInfo=PluginUtils::createJavaMapObject(NULL); } return loginInfo; }
static int tolua_anysdk_PluginProtocol_callFuncWithParam(lua_State* tolua_S) { if (NULL == tolua_S) return 0; int argc = 0; PluginProtocol* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ccanysdk.PluginProtocol",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast<PluginProtocol*>(tolua_tousertype(tolua_S,1,0)); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { tolua_error(tolua_S,"invalid 'self' in function 'tolua_anysdk_PluginProtocol_callFuncWithParam'\n", NULL); return 0; } #endif argc = lua_gettop(tolua_S) - 1; if (argc < 7) { const char* funName = lua_tostring(tolua_S, 2); std::vector<PluginParam*> vecParam; luavals_to_stdvector(tolua_S, argc + 1, &vecParam); self->callFuncWithParam(funName, vecParam); releaseVecContent(&vecParam); return 0; } CCLOG("'callFuncWithParam' function of PluginProtocol has wrong number of arguments: %d, max %d\n", argc, 5); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'callFuncWithParam'.",&tolua_err); return 0; #endif }
JNIEXPORT void JNICALL Java_com_opensdk_framework_NativeInvoker_nativeOnActionResult(JNIEnv* env, jobject thiz, jstring pluginKey, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strPluginKey = PluginJniHelper::jstring2string(pluginKey); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strPluginKey); PluginUtils::outputLog("ProtocolUser", "nativeOnActionResult(), Get plugin ptr : %p", pPlugin); UserObject* userObject = dynamic_cast<UserObject*>(pPlugin); if (userObject != NULL) { PluginUtils::outputLog("ProtocolUser", "nativeOnActionResult(), Get plugin name : %s", pPlugin->getPluginName()); UserActionListener* listener = userObject->getActionListener(); if (NULL != listener) { listener->onActionResult(userObject, (UserActionResultCode) ret, strMsg.c_str()); } else { UserActionResult result={ (UserActionResultCode)ret, strMsg, strPluginKey }; UserObject::pushActionResult(result); PluginUtils::outputLog("ProtocolUser","Listener of plugin %s not set correctly", pPlugin->getPluginName()); } }else{ UserActionResult result={ (UserActionResultCode)ret, strMsg, strPluginKey }; UserObject::pushActionResult(result); PluginUtils::outputLog("ProtocolUser", "plugin %s is null", pPlugin->getPluginName()); } }
JNIEXPORT void JNICALL Java_com_opensdk_framework_NativeInvoker_nativeOnSocialResult(JNIEnv* env, jobject thiz, jstring pluginKey, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strPluginKey = PluginJniHelper::jstring2string(pluginKey); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strPluginKey); PluginUtils::outputLog("ProtocolSocial", "nativeOnSocialResult(), Get plugin ptr : %p", pPlugin); SocialObject* socialObject = dynamic_cast<SocialObject*>(pPlugin); if (socialObject != NULL) { PluginUtils::outputLog("ProtocolSocial", "nativeOnSocialResult(), Get plugin name : %s", pPlugin->getPluginName()); SocialListener* pListener = socialObject->getListener(); if (NULL != pListener) { pListener->onSocialResult((SocialRetCode) ret, strMsg.c_str()); } else { SocialActionResult result={ (SocialRetCode)ret, strMsg, strPluginKey }; SocialObject::pushActionResult(result); PluginUtils::outputLog("ProtocolSocial", "Can't find the nativeOnSocialResult listener of plugin %s", pPlugin->getPluginName()); } }else{ SocialActionResult result={ (SocialRetCode)ret, strMsg, strPluginKey }; SocialObject::pushActionResult(result); PluginUtils::outputLog("ProtocolSocial", "plugin %s is null", pPlugin->getPluginName()); } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsWrapper_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) { std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin); if (pAds != NULL) { pAds->onPlayerGetPoints(points); } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnPayResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin); if (pIAP != NULL) { pIAP->onPayResult((PayResultCode) ret, strMsg.c_str()); } else { ProtocolIAP::ProtocolIAPCallback callback = pIAP->getCallback(); if(callback) callback(ret, strMsg); } } }
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsAdColonyWrapper_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jstring zoneID, jboolean success, jstring name, jint points) { std::string strClassName = PluginJniHelper::jstring2string(className); std::string strZoneIds = PluginJniHelper::jstring2string(zoneID); std::string strName = PluginJniHelper::jstring2string(name); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin); if (pAds != NULL) { AdColonyAdsIntenelListener* listener = (AdColonyAdsIntenelListener*)pAds->getAdsListener(); if (listener) { listener->onPlayerGetPoints(pAds, strZoneIds.c_str(), success, strName.c_str(), points); } } } }
/** create the plugin by name */ PluginProtocol* PluginFactory::createPlugin(const char* name) { PluginProtocol* pRet = NULL; do { if (name == NULL || strlen(name) == 0) break; std::string jClassName = ANDROID_PLUGIN_PACKAGE_PREFIX; jClassName.append(name); PluginUtils::outputLog("PluginFactory", "Java class name of plugin %s is : %s", name, jClassName.c_str()); PluginJniMethodInfo t; if (! PluginJniHelper::getStaticMethodInfo(t , "org/cocos2dx/plugin/PluginWrapper" , "initPlugin" , "(Ljava/lang/String;)Ljava/lang/Object;")) { PluginUtils::outputLog("PluginFactory", "Can't find method initPlugin in class org.cocos2dx.plugin.PluginWrapper"); break; } jstring clsName = t.env->NewStringUTF(jClassName.c_str()); jobject jObj = t.env->CallStaticObjectMethod(t.classID, t.methodID, clsName); t.env->DeleteLocalRef(clsName); t.env->DeleteLocalRef(t.classID); if (jObj == NULL) { PluginUtils::outputLog("PluginFactory", "Can't find java class %s", jClassName.c_str()); break; } if (! PluginJniHelper::getStaticMethodInfo(t , "org/cocos2dx/plugin/PluginWrapper" , "getPluginType" , "(Ljava/lang/Object;)I")) { PluginUtils::outputLog("PluginFactory", "Can't find method getPluginType in class org.cocos2dx.plugin.PluginWrapper"); break; } int curType = t.env->CallStaticIntMethod(t.classID, t.methodID, jObj); t.env->DeleteLocalRef(t.classID); PluginUtils::outputLog("PluginFactory", "The type of plugin %s is : %d", name, curType); switch (curType) { case kPluginAds: pRet = new ProtocolAds(); break; case kPluginAnalytics: pRet = new ProtocolAnalytics(); break; case kPluginIAP: pRet = new ProtocolIAP(); break; case kPluginShare: pRet = new ProtocolShare(); break; case kPluginUser: pRet = new ProtocolUser(); break; case kPluginSocial: pRet = new ProtocolSocial(); break; case kPluginData: pRet = new ProtocolData(); break; case kPluginBaaS: pRet = new ProtocolBaaS(); break; default: break; } if (pRet != NULL) { pRet->setPluginName(name); PluginUtils::initJavaPlugin(pRet, jObj, jClassName.c_str()); } } while(0); return pRet; }