From 514f7fe5d595b949a55f5ea4da5c490218ff34d5 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 23 May 2013 17:57:55 +0800 Subject: [PATCH 01/18] Add reflection in plugin on android. --- .../src/org/cocos2dx/plugin/IAPNd91.java | 2 +- plugin/protocols/PluginParam.cpp | 59 ++++++++++++ plugin/protocols/include/PluginParam.h | 89 ++++++++++++++++++ plugin/protocols/include/PluginProtocol.h | 3 + .../platform/android/PluginProtocol.cpp | 75 +++++++++++++++ .../platform/android/PluginUtils.cpp | 93 +++++++++++++++++-- .../protocols/platform/android/PluginUtils.h | 11 ++- .../platform/android/ProtocolAds.cpp | 6 +- .../platform/android/ProtocolAnalytics.cpp | 6 +- .../platform/android/ProtocolIAP.cpp | 2 +- .../platform/android/ProtocolSocial.cpp | 2 +- plugin/protocols/proj.android/jni/Android.mk | 1 + 12 files changed, 327 insertions(+), 22 deletions(-) create mode 100644 plugin/protocols/PluginParam.cpp create mode 100644 plugin/protocols/include/PluginParam.h create mode 100644 plugin/protocols/platform/android/PluginProtocol.cpp diff --git a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java index aa2a8335af..80e9ff5c5f 100644 --- a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java +++ b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java @@ -230,7 +230,7 @@ public class IAPNd91 implements IAPAdapter { IAPNd91.LogD("finishPayProcess code : " + code); switch(code){ case NdErrorCode.ND_COM_PLATFORM_SUCCESS: - IAPNd91.payResult(InterfaceIAP.PAYRESULT_SUCCESS, "购买成功"); + IAPNd91.payResult(InterfaceIAP.PAYRESULT_SUCCESS, "购买成功"); break; case NdErrorCode.ND_COM_PLATFORM_ERROR_PAY_FAILURE: IAPNd91.payResult(InterfaceIAP.PAYRESULT_FAIL, "购买失败"); break; case NdErrorCode.ND_COM_PLATFORM_ERROR_PAY_CANCEL: diff --git a/plugin/protocols/PluginParam.cpp b/plugin/protocols/PluginParam.cpp new file mode 100644 index 0000000000..2891ffd80e --- /dev/null +++ b/plugin/protocols/PluginParam.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "PluginParam.h" + +namespace cocos2d { namespace plugin { + +PluginParam::PluginParam(int nValue) +: m_nValue(nValue) +{ + m_type = kParamTypeInt; +} + +PluginParam::PluginParam(float fValue) +: m_fValue(fValue) +{ + m_type = kParamTypeFloat; +} + +PluginParam::PluginParam(bool bValue) +: m_bValue(bValue) +{ + m_type = kParamTypeBool; +} + +PluginParam::PluginParam(const char* strValue) +: m_strValue(strValue) +{ + m_type = kParamTypeString; +} + +PluginParam::PluginParam(std::map mapValue) +: m_mapValue(mapValue) +{ + m_type = kParamTypeMap; +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/include/PluginParam.h b/plugin/protocols/include/PluginParam.h new file mode 100644 index 0000000000..fbf29498d2 --- /dev/null +++ b/plugin/protocols/include/PluginParam.h @@ -0,0 +1,89 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __CCX_PLUGIN_PARAM_H__ +#define __CCX_PLUGIN_PARAM_H__ + +#include +#include + +namespace cocos2d { namespace plugin { + +class PluginParam +{ +public: + PluginParam(int nValue); + PluginParam(float fValue); + PluginParam(bool bValue); + PluginParam(const char* strValue); + PluginParam(std::map mapValue); + + typedef enum{ + kParamTypeNull = 0, + kParamTypeInt, + kParamTypeFloat, + kParamTypeBool, + kParamTypeString, + kParamTypeMap + } ParamType; + + inline ParamType getCurrentType() { + return m_type; + } + + inline int getIntValue() { + return m_nValue; + } + + inline float getFloatValue() { + return m_fValue; + } + + inline bool getBoolValue() { + return m_bValue; + } + + inline const char* getStringValue() { + return m_strValue.c_str(); + } + + inline std::map getMapValue() { + return m_mapValue; + } + +private: + PluginParam(); + +private: + ParamType m_type; + + int m_nValue; + float m_fValue; + bool m_bValue; + std::string m_strValue; + std::map m_mapValue; +}; + +}} //namespace cocos2d { namespace plugin { + +#endif /* __CCX_PLUGIN_PARAM_H__ */ diff --git a/plugin/protocols/include/PluginProtocol.h b/plugin/protocols/include/PluginProtocol.h index f59917e082..6a6103f944 100644 --- a/plugin/protocols/include/PluginProtocol.h +++ b/plugin/protocols/include/PluginProtocol.h @@ -25,6 +25,7 @@ THE SOFTWARE. #define __CCX_IPLUGIN_H__ #include "RegisterPlugin.h" +#include "PluginParam.h" namespace cocos2d { namespace plugin { @@ -40,6 +41,8 @@ public: void setUserData(void* userData) { m_pUserData = userData; } void* getUserData() { return m_pUserData; } + void callFuncWithParam(const char* funcName, PluginParam* param); + /** @brief plug-in info methods(name, version, SDK version) */ diff --git a/plugin/protocols/platform/android/PluginProtocol.cpp b/plugin/protocols/platform/android/PluginProtocol.cpp new file mode 100644 index 0000000000..946be3ee6d --- /dev/null +++ b/plugin/protocols/platform/android/PluginProtocol.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "PluginProtocol.h" +#include "PluginUtils.h" + +namespace cocos2d { namespace plugin { + +void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) +{ + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + if (NULL == pData) { + PluginUtils::outputLog("PluginProtocol", "Can't find java data for plugin : %s", this->getPluginName()); + return; + } + + if (NULL == param) + { + PluginUtils::callJavaFunctionWithName(this, funcName); + } else + { + switch(param->getCurrentType()) + { + case PluginParam::kParamTypeInt: + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(I)V", param->getIntValue()); + break; + case PluginParam::kParamTypeFloat: + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(F)V", param->getFloatValue()); + break; + case PluginParam::kParamTypeBool: + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Z)V", param->getBoolValue()); + break; + case PluginParam::kParamTypeString: + { + jstring jstr = PluginUtils::getEnv()->NewStringUTF(param->getStringValue()); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Ljava/lang/String;)V", jstr); + PluginUtils::getEnv()->DeleteLocalRef(jstr); + } + break; + case PluginParam::kParamTypeMap: + { + jobject jMap = PluginUtils::getJObjFromParam(param); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Lorg/json/JSONObject;)V", jMap); + PluginUtils::getEnv()->DeleteLocalRef(jMap); + } + break; + default: + break; + } + } +} + +}} //namespace cocos2d { namespace plugin { + +#endif /* __CCX_IPLUGIN_H__ */ diff --git a/plugin/protocols/platform/android/PluginUtils.cpp b/plugin/protocols/platform/android/PluginUtils.cpp index 4f6b6ff99e..e78ad5cf66 100644 --- a/plugin/protocols/platform/android/PluginUtils.cpp +++ b/plugin/protocols/platform/android/PluginUtils.cpp @@ -25,17 +25,12 @@ THE SOFTWARE. #include #include +#define MAX_LOG_LEN 256 + namespace cocos2d { namespace plugin { #define JAVAVM cocos2d::PluginJniHelper::getJavaVM() -#if 1 -#define LOG_TAG "PluginUtils" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - static cocos2d::plugin::PluginProtocol* s_pPluginInstance = NULL; extern "C" { @@ -98,13 +93,13 @@ JNIEnv* PluginUtils::getEnv() { if (JAVAVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) { - LOGD("Failed to get the environment using GetEnv()"); + outputLog("PluginUtils", "Failed to get the environment using GetEnv()"); break; } if (JAVAVM->AttachCurrentThread(&env, 0) < 0) { - LOGD("Failed to get the environment using AttachCurrentThread()"); + outputLog("PluginUtils", "Failed to get the environment using AttachCurrentThread()"); break; } @@ -169,7 +164,7 @@ void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj) } JNIEnv* pEnv = getEnv(); - LOGD("Delete global reference."); + outputLog("PluginUtils", "Delete global reference."); pEnv->DeleteGlobalRef(jobj); delete pData; } @@ -177,4 +172,82 @@ void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj) } } +void PluginUtils::outputLog(const char* logTag, const char* pFormat, ...) +{ + char buf[MAX_LOG_LEN + 1]; + + va_list args; + va_start(args, pFormat); + vsnprintf(buf, MAX_LOG_LEN, pFormat, args); + va_end(args); + + __android_log_print(ANDROID_LOG_DEBUG, logTag, buf); +} + +jobject PluginUtils::getJObjFromParam(PluginParam* param) +{ + if (NULL == param) + { + return NULL; + } + + jobject obj = NULL; + PluginJniMethodInfo t; + JNIEnv* env = PluginUtils::getEnv(); + + switch(param->getCurrentType()) + { + case PluginParam::kParamTypeInt: + if (PluginJniHelper::getStaticMethodInfo(t, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;")) + { + obj = t.env->CallStaticObjectMethod(t.classID, t.methodID, param->getIntValue()); + } + break; + case PluginParam::kParamTypeFloat: + if (PluginJniHelper::getStaticMethodInfo(t, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;")) + { + obj = t.env->CallStaticObjectMethod(t.classID, t.methodID, param->getFloatValue()); + } + break; + case PluginParam::kParamTypeBool: + if (PluginJniHelper::getStaticMethodInfo(t, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;")) + { + obj = t.env->CallStaticObjectMethod(t.classID, t.methodID, param->getBoolValue()); + } + break; + case PluginParam::kParamTypeString: + obj = env->NewStringUTF(param->getStringValue()); + break; + case PluginParam::kParamTypeMap: + { + jclass cls = env->FindClass("org/json/JSONObject"); + jmethodID mid = env->GetMethodID(cls,"","()V"); + obj = env->NewObject(cls,mid); + + std::map::iterator it; + std::map mapParam = param->getMapValue(); + for (it = mapParam.begin(); it != mapParam.end(); it++) + { + PluginJniMethodInfo tInfo; + if (PluginJniHelper::getMethodInfo(tInfo, "org/json/JSONObject", "put", "(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;")) + { + jstring strKey = env->NewStringUTF(it->first.c_str()); + jobject objValue = PluginUtils::getJObjFromParam(it->second); + + tInfo.env->CallObjectMethod(obj, tInfo.methodID, strKey, objValue); + tInfo.env->DeleteLocalRef(tInfo.classID); + + PluginUtils::getEnv()->DeleteLocalRef(strKey); + PluginUtils::getEnv()->DeleteLocalRef(objValue); + } + } + } + break; + default: + break; + } + + return obj; +} + }}// namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/android/PluginUtils.h b/plugin/protocols/platform/android/PluginUtils.h index 37de6cd58a..aeee154561 100644 --- a/plugin/protocols/platform/android/PluginUtils.h +++ b/plugin/protocols/platform/android/PluginUtils.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include "PluginJavaData.h" #include "PluginProtocol.h" #include +#include "PluginParam.h" namespace cocos2d { namespace plugin { @@ -48,13 +49,15 @@ public: static PluginProtocol* getPluginPtr(std::string className); + static jobject getJObjFromParam(PluginParam* param); + template - static void callJavaFunctionWithName_oneBaseType(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) + static void callJavaFunctionWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) { return_if_fails(funcName != NULL && strlen(funcName) > 0); return_if_fails(paramCode != NULL && strlen(paramCode) > 0); PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); - PluginJniMethodInfo t; + PluginJniMethodInfo t; if (PluginJniHelper::getMethodInfo(t , pData->jclassName.c_str() , funcName @@ -64,7 +67,7 @@ public: t.env->DeleteLocalRef(t.classID); } } - + static void callJavaFunctionWithName(PluginProtocol* thiz, const char* funcName) { return_if_fails(funcName != NULL && strlen(funcName) > 0); @@ -79,6 +82,8 @@ public: t.env->DeleteLocalRef(t.classID); } } + + static void outputLog(const char* logTag, const char* pFormat, ...); }; }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/android/ProtocolAds.cpp b/plugin/protocols/platform/android/ProtocolAds.cpp index 4e4ba6a87d..5ebe6e884d 100644 --- a/plugin/protocols/platform/android/ProtocolAds.cpp +++ b/plugin/protocols/platform/android/ProtocolAds.cpp @@ -129,12 +129,12 @@ void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos) void ProtocolAds::hideAds(AdsType type) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "hideAds", "(I)V", type); + PluginUtils::callJavaFunctionWithName_oneParam(this, "hideAds", "(I)V", type); } void ProtocolAds::spendPoints(int points) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "spendPoints", "(I)V", points); + PluginUtils::callJavaFunctionWithName_oneParam(this, "spendPoints", "(I)V", points); } const char* ProtocolAds::getSDKVersion() @@ -156,7 +156,7 @@ const char* ProtocolAds::getSDKVersion() void ProtocolAds::setDebugMode(bool debug) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setDebugMode", "(Z)V", debug); + PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug); } void ProtocolAds::setAdsListener(AdsListener* pListener) diff --git a/plugin/protocols/platform/android/ProtocolAnalytics.cpp b/plugin/protocols/platform/android/ProtocolAnalytics.cpp index edeb4b19b9..efa239f41a 100644 --- a/plugin/protocols/platform/android/ProtocolAnalytics.cpp +++ b/plugin/protocols/platform/android/ProtocolAnalytics.cpp @@ -109,17 +109,17 @@ void ProtocolAnalytics::stopSession() void ProtocolAnalytics::setSessionContinueMillis(long millis) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setSessionContinueMillis", "(I)V", millis); + PluginUtils::callJavaFunctionWithName_oneParam(this, "setSessionContinueMillis", "(I)V", millis); } void ProtocolAnalytics::setCaptureUncaughtException(bool isEnabled) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setCaptureUncaughtException", "(Z)V", isEnabled); + PluginUtils::callJavaFunctionWithName_oneParam(this, "setCaptureUncaughtException", "(Z)V", isEnabled); } void ProtocolAnalytics::setDebugMode(bool isDebugMode) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setDebugMode", "(Z)V", isDebugMode); + PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", isDebugMode); } void ProtocolAnalytics::logError(const char* errorId, const char* message) diff --git a/plugin/protocols/platform/android/ProtocolIAP.cpp b/plugin/protocols/platform/android/ProtocolIAP.cpp index 86ba7136ef..22a2a71040 100644 --- a/plugin/protocols/platform/android/ProtocolIAP.cpp +++ b/plugin/protocols/platform/android/ProtocolIAP.cpp @@ -178,7 +178,7 @@ const char* ProtocolIAP::getSDKVersion() void ProtocolIAP::setDebugMode(bool debug) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setDebugMode", "(Z)V", debug); + PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug); } }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp index c2a225e1a7..82fb6c01ad 100755 --- a/plugin/protocols/platform/android/ProtocolSocial.cpp +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -165,7 +165,7 @@ const char* ProtocolSocial::getSDKVersion() void ProtocolSocial::setDebugMode(bool debug) { - PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setDebugMode", "(Z)V", debug); + PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug); } }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/proj.android/jni/Android.mk b/plugin/protocols/proj.android/jni/Android.mk index 5e82597a05..dfba8cc95b 100755 --- a/plugin/protocols/proj.android/jni/Android.mk +++ b/plugin/protocols/proj.android/jni/Android.mk @@ -17,6 +17,7 @@ $(addprefix ../../platform/android/, \ ) \ ../../PluginManager.cpp \ ../../RegisterPlugin.cpp \ +../../PluginParam.cpp LOCAL_CFLAGS := -Wno-psabi LOCAL_EXPORT_CFLAGS := -Wno-psabi From c89bf0f1a8a0a3e68010d07f94931a4789d90724 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Fri, 24 May 2013 17:34:01 +0800 Subject: [PATCH 02/18] Refactor the implementation of plugin protocols on android. --- plugin/protocols/PluginManager.cpp | 64 +++----- .../PluginFactory.h} | 27 +++- plugin/protocols/include/PluginManager.h | 7 +- plugin/protocols/include/PluginProtocol.h | 30 ++-- plugin/protocols/include/ProtocolAds.h | 30 +--- plugin/protocols/include/ProtocolAnalytics.h | 41 ++---- plugin/protocols/include/ProtocolIAP.h | 26 +--- plugin/protocols/include/ProtocolSocial.h | 27 +--- .../platform/android/PluginFactory.cpp | 138 ++++++++++++++++++ .../platform/android/PluginProtocol.cpp | 44 ++++++ .../platform/android/PluginUtils.cpp | 39 +---- .../protocols/platform/android/PluginUtils.h | 3 +- .../platform/android/ProtocolAds.cpp | 51 +------ .../platform/android/ProtocolAnalytics.cpp | 35 ----- .../platform/android/ProtocolIAP.cpp | 49 +------ .../platform/android/ProtocolSocial.cpp | 47 +----- plugin/protocols/proj.android/jni/Android.mk | 2 +- .../src/org/cocos2dx/plugin/AdsWrapper.java | 116 +++++++++++++++ .../src/org/cocos2dx/plugin/IAPWrapper.java} | 58 +++----- .../src/org/cocos2dx/plugin/InterfaceAds.java | 104 ++----------- .../cocos2dx/plugin/InterfaceAnalytics.java | 3 + .../src/org/cocos2dx/plugin/InterfaceIAP.java | 33 +---- .../org/cocos2dx/plugin/InterfaceSocial.java | 33 +---- .../org/cocos2dx/plugin/PluginWrapper.java | 22 ++- .../org/cocos2dx/plugin/SocialWrapper.java | 48 ++++++ 25 files changed, 523 insertions(+), 554 deletions(-) rename plugin/protocols/{RegisterPlugin.cpp => include/PluginFactory.h} (69%) create mode 100644 plugin/protocols/platform/android/PluginFactory.cpp create mode 100644 plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java rename plugin/protocols/{include/RegisterPlugin.h => proj.android/src/org/cocos2dx/plugin/IAPWrapper.java} (51%) create mode 100755 plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java diff --git a/plugin/protocols/PluginManager.cpp b/plugin/protocols/PluginManager.cpp index 64a3e3170d..b4d79d8edd 100644 --- a/plugin/protocols/PluginManager.cpp +++ b/plugin/protocols/PluginManager.cpp @@ -22,20 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #include "PluginManager.h" -#include -#include +#include "PluginFactory.h" + namespace cocos2d { namespace plugin { -typedef struct tagPluginInfo -{ - PluginCreator pfnCreator; - PluginProtocol* pInstance; -}PluginInfo; - -typedef std::map PluginCreatorMap; -typedef std::pair PluginCreatorPair; - -static PluginCreatorMap* s_pCreatorMap = NULL; static PluginManager* s_pPluginManager = NULL; PluginManager::PluginManager(void) @@ -44,14 +34,15 @@ PluginManager::PluginManager(void) PluginManager::~PluginManager() { - PluginCreatorMap::iterator it = s_pCreatorMap->begin(); - for (;it != s_pCreatorMap->end();++it) + std::map::iterator it = m_pluginsMap.begin(); + for (;it != m_pluginsMap.end();++it) { - if (it->second.pInstance != NULL) { - delete it->second.pInstance; - it->second.pInstance = NULL; + if (it->second != NULL) { + delete it->second; + it->second = NULL; } } + m_pluginsMap.clear(); } PluginManager* PluginManager::getInstance() @@ -70,6 +61,8 @@ void PluginManager::end() delete s_pPluginManager; s_pPluginManager = NULL; } + + PluginFactory::purgeFactory(); } PluginProtocol* PluginManager::loadPlugin(const char* name) @@ -77,18 +70,16 @@ PluginProtocol* PluginManager::loadPlugin(const char* name) PluginProtocol* pRet = NULL; do { if (name == NULL || strlen(name) == 0) break; - PluginCreatorMap::iterator it = s_pCreatorMap->find(name); - if (it != s_pCreatorMap->end()) + std::map::iterator it = m_pluginsMap.find(name); + if (it != m_pluginsMap.end()) { - if (it->second.pInstance == NULL) { - it->second.pInstance = it->second.pfnCreator(); + if (it->second == NULL) { + it->second = PluginFactory::getInstance()->createPlugin(name); } - else { - // LOGD("The plugin has been loaded, return the loaded instance directly."); - } - pRet = it->second.pInstance; + pRet = it->second; } } while (false); + return pRet; } @@ -96,28 +87,15 @@ void PluginManager::unloadPlugin(const char* name) { do { if (name == NULL || strlen(name) == 0) break; - PluginCreatorMap::iterator it = s_pCreatorMap->find(name); - if (it != s_pCreatorMap->end()) + std::map::iterator it = m_pluginsMap.find(name); + if (it != m_pluginsMap.end()) { - if (it->second.pInstance != NULL) { - delete it->second.pInstance; - it->second.pInstance = NULL; + if (it->second != NULL) { + delete it->second; + it->second = NULL; } } } while (false); } -bool PluginManager::registerPlugin(const char* name, PluginCreator pfnCreator) -{ - if (s_pCreatorMap == NULL) { - static PluginCreatorMap s_CreatorMap; - s_pCreatorMap = &s_CreatorMap; - } - PluginInfo info; - info.pfnCreator = pfnCreator; - info.pInstance = NULL; - s_pCreatorMap->insert(PluginCreatorPair(name, info)); - return true; -} - }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/RegisterPlugin.cpp b/plugin/protocols/include/PluginFactory.h similarity index 69% rename from plugin/protocols/RegisterPlugin.cpp rename to plugin/protocols/include/PluginFactory.h index 7d5f3229c2..c331eb87f3 100644 --- a/plugin/protocols/RegisterPlugin.cpp +++ b/plugin/protocols/include/PluginFactory.h @@ -21,14 +21,31 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "RegisterPlugin.h" -#include "PluginManager.h" +#ifndef __CCX_PLUGIN_FACTORY_H__ +#define __CCX_PLUGIN_FACTORY_H__ namespace cocos2d { namespace plugin { -RegisterPlugin::RegisterPlugin(const char* name, PluginCreator pfnCreator) +class PluginProtocol; +class PluginManager; +class PluginFactory { - PluginManager::getInstance()->registerPlugin(name, pfnCreator); -} +public: + virtual ~PluginFactory(); + /** Get singleton of PluginFactory */ + static PluginFactory* getInstance(); + + /** Destory the instance of PluginFactory */ + static void purgeFactory(); + +private: + friend class PluginManager; + PluginFactory(void); + + /** create the plugin by name */ + PluginProtocol* createPlugin(const char* name); +}; }} //namespace cocos2d { namespace plugin { + +#endif /* __CCX_PLUGIN_FACTORY_H__ */ diff --git a/plugin/protocols/include/PluginManager.h b/plugin/protocols/include/PluginManager.h index f618625086..8800487f78 100644 --- a/plugin/protocols/include/PluginManager.h +++ b/plugin/protocols/include/PluginManager.h @@ -25,7 +25,8 @@ THE SOFTWARE. #define __CCX_PLUGINMANAGER_H__ #include "PluginProtocol.h" -#include "RegisterPlugin.h" +#include +#include namespace cocos2d { namespace plugin { @@ -42,10 +43,10 @@ public: PluginProtocol* loadPlugin(const char* name); /** unload the plugin by name */ void unloadPlugin(const char* name); + private: - friend class RegisterPlugin; - bool registerPlugin(const char* name, PluginCreator pfnCreator); PluginManager(void); + std::map m_pluginsMap; }; }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/include/PluginProtocol.h b/plugin/protocols/include/PluginProtocol.h index 6a6103f944..c3d97f08f4 100644 --- a/plugin/protocols/include/PluginProtocol.h +++ b/plugin/protocols/include/PluginProtocol.h @@ -24,7 +24,6 @@ THE SOFTWARE. #ifndef __CCX_IPLUGIN_H__ #define __CCX_IPLUGIN_H__ -#include "RegisterPlugin.h" #include "PluginParam.h" namespace cocos2d { namespace plugin { @@ -32,31 +31,38 @@ namespace cocos2d { namespace plugin { /** The super class for all plugins. */ - +class PluginFactory; class PluginProtocol { public: - virtual ~PluginProtocol() {} - virtual bool init() { return true; } - void setUserData(void* userData) { m_pUserData = userData; } - void* getUserData() { return m_pUserData; } - - void callFuncWithParam(const char* funcName, PluginParam* param); + virtual ~PluginProtocol(); /** @brief plug-in info methods(name, version, SDK version) */ - virtual const char* getPluginName() = 0; - virtual const char* getPluginVersion() = 0; + inline const char* getPluginName() { return m_pPluginName; } + const char* getPluginVersion(); + const char* getSDKVersion(); /** @brief switch debug plug-in on/off */ - virtual void setDebugMode(bool bDebug) {} + void setDebugMode(bool bDebug); + + /** + * @brief methods for reflections + */ + void callFuncWithParam(const char* funcName, PluginParam* param); protected: PluginProtocol() {} - void* m_pUserData; + +private: + friend class PluginFactory; + inline void setPluginName(const char* name) { + m_pPluginName = name; + } + const char* m_pPluginName; }; }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/include/ProtocolAds.h b/plugin/protocols/include/ProtocolAds.h index 97e347f8e0..4ca675cf1d 100644 --- a/plugin/protocols/include/ProtocolAds.h +++ b/plugin/protocols/include/ProtocolAds.h @@ -66,6 +66,8 @@ public: class ProtocolAds : public PluginProtocol { public: + ProtocolAds(); + virtual ~ProtocolAds(); typedef enum { kBannerAd = 0, @@ -82,11 +84,6 @@ public: kPosBottomRight, } AdsPos; - /** - @brief plugin initialization - */ - virtual bool init(); - /** @brief config the application info @param devInfo This parameter is the info of aplication, @@ -94,7 +91,7 @@ public: @warning Must invoke this interface before other interfaces. And invoked only once. */ - virtual void configDeveloperInfo(TAdsDeveloperInfo devInfo); + void configDeveloperInfo(TAdsDeveloperInfo devInfo); /** @brief show adview @@ -106,26 +103,20 @@ public: @param pos The position where the adview be shown. (only used when type is kBannerAd) */ - virtual void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter); + void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter); /** @brief Hide the adview @param type The adview type need to hide. */ - virtual void hideAds(AdsType type); + void hideAds(AdsType type); /** @brief Spend the points. Use this method to notify server spend points. @param points Need spend number of points */ - virtual void spendPoints(int points); - - /** - @brief Set whether needs to output logs to console. - @param debug If true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); + void spendPoints(int points); /** @brief set the Ads listener @@ -136,15 +127,6 @@ public: void onAdsResult(AdsResultCode code, const char* msg); void onPlayerGetPoints(int points); - virtual const char* getPluginVersion() { return "ProtocolAds, v0.1.01 , subclass should override this interface!"; }; - virtual const char* getSDKVersion(); - virtual const char* getPluginName() = 0; - -protected: - ProtocolAds(); -public: - virtual ~ProtocolAds(); - protected: AdsListener* m_pListener; }; diff --git a/plugin/protocols/include/ProtocolAnalytics.h b/plugin/protocols/include/ProtocolAnalytics.h index 17a7ce7809..9360c9eb69 100644 --- a/plugin/protocols/include/ProtocolAnalytics.h +++ b/plugin/protocols/include/ProtocolAnalytics.h @@ -36,78 +36,59 @@ typedef std::map< std::string, std::string > LogEventParamMap; class ProtocolAnalytics : public PluginProtocol { public: + ProtocolAnalytics(); + virtual ~ProtocolAnalytics(); - /** - @brief plugin initialization - */ - virtual bool init(); - /** @brief Start a new session. @param appKey The identity of the application. */ - virtual void startSession(const char* appKey); + void startSession(const char* appKey); /** @brief Stop a session. @warning This interface only worked on android */ - virtual void stopSession(); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - @note It must be invoked before calling startSession. - */ - virtual void setDebugMode(bool debug); - + void stopSession(); + /** @brief Set the timeout for expiring a session. @param millis In milliseconds as the unit of time. @note It must be invoked before calling startSession. */ - virtual void setSessionContinueMillis(long millis); + void setSessionContinueMillis(long millis); /** @brief log an error @param errorId The identity of error @param message Extern message for the error */ - virtual void logError(const char* errorId, const char* message); + void logError(const char* errorId, const char* message); /** @brief log an event. @param eventId The identity of event @param paramMap Extern parameters of the event, use NULL if not needed. */ - virtual void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL); + void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL); /** @brief Track an event begin. @param eventId The identity of event */ - virtual void logTimedEventBegin(const char* eventId); + void logTimedEventBegin(const char* eventId); /** @brief Track an event end. @param eventId The identity of event */ - virtual void logTimedEventEnd(const char* eventId); + void logTimedEventEnd(const char* eventId); /** @brief Whether to catch uncaught exceptions to server. @warning This interface only worked on android. */ - virtual void setCaptureUncaughtException(bool enabled); - - virtual const char* getPluginVersion() { return "ProtocolAnalytics, v0.1.01 , subclass should override this interface!"; }; - virtual const char* getSDKVersion(); - virtual const char* getPluginName() = 0; - -protected: - ProtocolAnalytics(); -public: - virtual ~ProtocolAnalytics(); + void setCaptureUncaughtException(bool enabled); }; }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/include/ProtocolIAP.h b/plugin/protocols/include/ProtocolIAP.h index 73c501c282..f2d4c8df69 100644 --- a/plugin/protocols/include/ProtocolIAP.h +++ b/plugin/protocols/include/ProtocolIAP.h @@ -50,11 +50,8 @@ public: class ProtocolIAP : public PluginProtocol { public: - - /** - @brief plugin initialization - */ - virtual bool init(); + ProtocolIAP(); + virtual ~ProtocolIAP(); /** @brief config the developer info @@ -63,7 +60,7 @@ public: @warning Must invoke this interface before other interfaces. And invoked only once. */ - virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo); + void configDeveloperInfo(TIAPDeveloperInfo devInfo); /** @brief pay for product @@ -74,13 +71,7 @@ public: @warning For different plugin, the parameter should have other keys to pay. Look at the manual of plugins. */ - virtual void payForProduct(TProductInfo info); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); + void payForProduct(TProductInfo info); /** @breif set the result listener @@ -94,15 +85,6 @@ public: */ void onPayResult(PayResultCode ret, const char* msg); - virtual const char* getPluginVersion() { return "ProtocolIAP, v0.1.01 , subclass should override this interface!"; }; - virtual const char* getSDKVersion(); - virtual const char* getPluginName() = 0; - -protected: - ProtocolIAP(); -public: - virtual ~ProtocolIAP(); - protected: static bool m_bPaying; diff --git a/plugin/protocols/include/ProtocolSocial.h b/plugin/protocols/include/ProtocolSocial.h index c6fe7434c2..e0423c551d 100755 --- a/plugin/protocols/include/ProtocolSocial.h +++ b/plugin/protocols/include/ProtocolSocial.h @@ -50,11 +50,8 @@ public: class ProtocolSocial : public PluginProtocol { public: - - /** - @brief plugin initialization - */ - virtual bool init(); + ProtocolSocial(); + virtual ~ProtocolSocial(); /** @brief config the social developer info @@ -63,7 +60,7 @@ public: @warning Must invoke this interface before other interfaces. And invoked only once. */ - virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo); + void configDeveloperInfo(TSocialDeveloperInfo devInfo); /** @brief share information @@ -73,13 +70,7 @@ public: @warning For different plugin, the parameter should have other keys to share. Look at the manual of plugins. */ - virtual void share(TShareInfo info); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); + void share(TShareInfo info); /** @breif set the result listener @@ -93,14 +84,8 @@ public: */ void onShareResult(ShareResultCode ret, const char* msg); - virtual const char* getPluginVersion() { return "ProtocolSocial, v0.1.0, subclass should override this interface!"; }; - virtual const char* getSDKVersion(); - virtual const char* getPluginName() = 0; - -protected: - ProtocolSocial(); -public: - virtual ~ProtocolSocial(); + const char* getPluginVersion() { return "ProtocolSocial, v0.1.0, subclass should override this interface!"; }; + const char* getSDKVersion(); protected: ShareResultListener* m_pListener; diff --git a/plugin/protocols/platform/android/PluginFactory.cpp b/plugin/protocols/platform/android/PluginFactory.cpp new file mode 100644 index 0000000000..09029f1fa9 --- /dev/null +++ b/plugin/protocols/platform/android/PluginFactory.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "PluginFactory.h" +#include "PluginUtils.h" +#include "PluginJniHelper.h" +#include "ProtocolAds.h" +#include "ProtocolAnalytics.h" +#include "ProtocolIAP.h" +#include "ProtocolSocial.h" + +namespace cocos2d { namespace plugin { + +enum { + kPluginAds = 1, + kPluginAnalytics, + kPluginIAP, + kPluginSocial, +}; + +#define ANDROID_PLUGIN_TYPE_FIELD "PluginType" +#define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugins/" +#define BREAK_IF(cond) if(cond) break + +static PluginFactory* s_pFactory = NULL; + +PluginFactory::PluginFactory() +{ + +} + +PluginFactory::~PluginFactory() +{ + +} + +PluginFactory* PluginFactory::getInstance() +{ + if (NULL == s_pFactory) + { + s_pFactory = new PluginFactory(); + } + + return s_pFactory; +} + +void PluginFactory::purgeFactory() +{ + if (NULL != s_pFactory) + { + delete s_pFactory; + s_pFactory = NULL; + } +} + +/** 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;")) + { + 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); + BREAK_IF(jObj == NULL); + + jclass jcls = t.env->FindClass(jClassName.c_str()); + jfieldID fid_Type = t.env->GetFieldID(jcls, ANDROID_PLUGIN_TYPE_FIELD, "I"); + BREAK_IF(fid_Type == NULL); + + int curType = t.env->GetIntField(jObj, fid_Type); + 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 kPluginSocial: + pRet = new ProtocolSocial(); + break; + default: + break; + } + + if (pRet != NULL) + { + pRet->setPluginName(name); + PluginUtils::initJavaPlugin(pRet, jObj, jClassName.c_str()); + } + } while(0); + + return pRet; +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/android/PluginProtocol.cpp b/plugin/protocols/platform/android/PluginProtocol.cpp index 946be3ee6d..e049e30df8 100644 --- a/plugin/protocols/platform/android/PluginProtocol.cpp +++ b/plugin/protocols/platform/android/PluginProtocol.cpp @@ -26,6 +26,50 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { +PluginProtocol::~PluginProtocol() +{ + PluginUtils::erasePluginJavaData(this); +} + +const char* PluginProtocol::getPluginVersion() +{ + std::string verName; + + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "getPluginVersion" + , "()Ljava/lang/String;")) + { + jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); + verName = PluginJniHelper::jstring2string(ret); + } + return verName.c_str(); +} + +const char* PluginProtocol::getSDKVersion() +{ + std::string verName; + + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "getSDKVersion" + , "()Ljava/lang/String;")) + { + jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); + verName = PluginJniHelper::jstring2string(ret); + } + return verName.c_str(); +} + +void PluginProtocol::setDebugMode(bool isDebugMode) +{ + PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", isDebugMode); +} + void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) { PluginJavaData* pData = PluginUtils::getPluginJavaData(this); diff --git a/plugin/protocols/platform/android/PluginUtils.cpp b/plugin/protocols/platform/android/PluginUtils.cpp index e78ad5cf66..64068b0a9a 100644 --- a/plugin/protocols/platform/android/PluginUtils.cpp +++ b/plugin/protocols/platform/android/PluginUtils.cpp @@ -31,23 +31,6 @@ namespace cocos2d { namespace plugin { #define JAVAVM cocos2d::PluginJniHelper::getJavaVM() -static cocos2d::plugin::PluginProtocol* s_pPluginInstance = NULL; - -extern "C" { - -JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_PluginWrapper_nativeInitPlugin(JNIEnv* env, jobject thiz, jobject obj, jstring className) -{ - if (s_pPluginInstance != NULL) { - cocos2d::plugin::PluginJavaData* pUserData = new cocos2d::plugin::PluginJavaData(); - pUserData->jobj = env->NewGlobalRef(obj); - pUserData->jclassName = cocos2d::PluginJniHelper::jstring2string(className); - cocos2d::plugin::PluginUtils::setPluginJavaData(s_pPluginInstance, pUserData); - s_pPluginInstance = NULL; - } -} - -} - jobject PluginUtils::createJavaMapObject(PluginJniMethodInfo&t, std::map* paramMap) { jclass class_Hashtable = t.env->FindClass("java/util/Hashtable"); @@ -65,24 +48,12 @@ jobject PluginUtils::createJavaMapObject(PluginJniMethodInfo&t, std::map 0, false); - bool bRet = false; - PluginJniMethodInfo t; - s_pPluginInstance = pPlugin; - if (PluginJniHelper::getStaticMethodInfo(t - , "org/cocos2dx/plugin/PluginWrapper" - , "initPlugin" - , "(Ljava/lang/String;)Z")) - { - jstring jclassName = t.env->NewStringUTF(className); - bRet = (bool)t.env->CallStaticBooleanMethod(t.classID, t.methodID, jclassName); - t.env->DeleteLocalRef(jclassName); - t.env->DeleteLocalRef(t.classID); - } - - return bRet; + cocos2d::plugin::PluginJavaData* pUserData = new cocos2d::plugin::PluginJavaData(); + pUserData->jobj = PluginUtils::getEnv()->NewGlobalRef(jObj); + pUserData->jclassName = className; + cocos2d::plugin::PluginUtils::setPluginJavaData(pPlugin, pUserData); } JNIEnv* PluginUtils::getEnv() diff --git a/plugin/protocols/platform/android/PluginUtils.h b/plugin/protocols/platform/android/PluginUtils.h index aeee154561..9f6d97ec4a 100644 --- a/plugin/protocols/platform/android/PluginUtils.h +++ b/plugin/protocols/platform/android/PluginUtils.h @@ -25,7 +25,6 @@ THE SOFTWARE. #define __PLUGIN_UTILS_H__ #include "PluginJniHelper.h" -#include #include "PluginJavaData.h" #include "PluginProtocol.h" #include @@ -40,7 +39,7 @@ class PluginUtils { public: static jobject createJavaMapObject(PluginJniMethodInfo&t, std::map* paramMap); - static bool initJavaPlugin(PluginProtocol* pPlugin, const char* className); + static void initJavaPlugin(PluginProtocol* pPlugin, jobject jObj, const char* className); static JNIEnv* getEnv(); static PluginJavaData* getPluginJavaData(PluginProtocol* pKeyObj); diff --git a/plugin/protocols/platform/android/ProtocolAds.cpp b/plugin/protocols/platform/android/ProtocolAds.cpp index 5ebe6e884d..2e03bd444f 100644 --- a/plugin/protocols/platform/android/ProtocolAds.cpp +++ b/plugin/protocols/platform/android/ProtocolAds.cpp @@ -27,13 +27,6 @@ THE SOFTWARE. #include "PluginUtils.h" #include "PluginJavaData.h" -#if 1 -#define LOG_TAG "ProtocolAds" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - namespace cocos2d { namespace plugin { extern "C" { @@ -41,10 +34,10 @@ extern "C" { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); - LOGD("nativeOnAdsResult(), Get plugin ptr : %p", pPlugin); + PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { - LOGD("nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName()); + PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast(pPlugin); if (pAds != NULL) { @@ -56,10 +49,10 @@ extern "C" { 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); + PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { - LOGD("nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName()); + PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolAds* pAds = dynamic_cast(pPlugin); if (pAds != NULL) { @@ -76,19 +69,13 @@ ProtocolAds::ProtocolAds() ProtocolAds::~ProtocolAds() { - PluginUtils::erasePluginJavaData(this); -} - -bool ProtocolAds::init() -{ - return true; } void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo) { if (devInfo.empty()) { - LOGD("The application info is empty!"); + PluginUtils::outputLog("ProtocolAds", "The application info is empty!"); return; } else @@ -116,7 +103,7 @@ void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos) PluginJavaData* pData = PluginUtils::getPluginJavaData(this); PluginJniMethodInfo t; - LOGD("Class name : %s", pData->jclassName.c_str()); + PluginUtils::outputLog("ProtocolAds", "Class name : %s", pData->jclassName.c_str()); if (PluginJniHelper::getMethodInfo(t , pData->jclassName.c_str() , "showAds" @@ -137,28 +124,6 @@ void ProtocolAds::spendPoints(int points) PluginUtils::callJavaFunctionWithName_oneParam(this, "spendPoints", "(I)V", points); } -const char* ProtocolAds::getSDKVersion() -{ - std::string verName; - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getSDKVersion" - , "()Ljava/lang/String;")) - { - jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); - verName = PluginJniHelper::jstring2string(ret); - } - return verName.c_str(); -} - -void ProtocolAds::setDebugMode(bool debug) -{ - PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug); -} - void ProtocolAds::setAdsListener(AdsListener* pListener) { m_pListener = pListener; @@ -166,7 +131,7 @@ void ProtocolAds::setAdsListener(AdsListener* pListener) void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg) { - LOGD("ProtocolAds::adsResult invoked!"); + PluginUtils::outputLog("ProtocolAds", "ProtocolAds::adsResult invoked!"); if (m_pListener != NULL) { m_pListener->onAdsResult(code, msg); @@ -175,7 +140,7 @@ void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg) void ProtocolAds::onPlayerGetPoints(int points) { - LOGD("ProtocolAds::onPlayerGetPoints invoked!"); + PluginUtils::outputLog("ProtocolAds", "ProtocolAds::onPlayerGetPoints invoked!"); if (m_pListener != NULL) { m_pListener->onPlayerGetPoints(this, points); diff --git a/plugin/protocols/platform/android/ProtocolAnalytics.cpp b/plugin/protocols/platform/android/ProtocolAnalytics.cpp index efa239f41a..20174d08ea 100644 --- a/plugin/protocols/platform/android/ProtocolAnalytics.cpp +++ b/plugin/protocols/platform/android/ProtocolAnalytics.cpp @@ -27,13 +27,6 @@ THE SOFTWARE. #include "PluginUtils.h" #include "PluginJavaData.h" -#if 1 -#define LOG_TAG "ProtocolAnalytics" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - namespace cocos2d { namespace plugin { static void callJavaFunctionWithName_string_map(ProtocolAnalytics* thiz, const char* funcName, const char* keyParam, LogEventParamMap* paramMap) @@ -80,12 +73,6 @@ ProtocolAnalytics::ProtocolAnalytics() ProtocolAnalytics::~ProtocolAnalytics() { - PluginUtils::erasePluginJavaData(this); -} - -bool ProtocolAnalytics::init() -{ - return true; } void ProtocolAnalytics::startSession(const char* appKey) @@ -117,11 +104,6 @@ void ProtocolAnalytics::setCaptureUncaughtException(bool isEnabled) PluginUtils::callJavaFunctionWithName_oneParam(this, "setCaptureUncaughtException", "(Z)V", isEnabled); } -void ProtocolAnalytics::setDebugMode(bool isDebugMode) -{ - PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", isDebugMode); -} - void ProtocolAnalytics::logError(const char* errorId, const char* message) { return_if_fails(errorId != NULL && strlen(errorId) > 0); @@ -144,23 +126,6 @@ void ProtocolAnalytics::logError(const char* errorId, const char* message) } } -const char* ProtocolAnalytics::getSDKVersion() -{ - std::string verName; - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getSDKVersion" - , "()Ljava/lang/String;")) - { - jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); - verName = PluginJniHelper::jstring2string(ret); - } - return verName.c_str(); -} - void ProtocolAnalytics::logEvent(const char* eventId, LogEventParamMap* pParams/* = NULL */) { callJavaFunctionWithName_string_map(this, "logEvent", eventId, pParams); diff --git a/plugin/protocols/platform/android/ProtocolIAP.cpp b/plugin/protocols/platform/android/ProtocolIAP.cpp index 22a2a71040..fd19cde31a 100644 --- a/plugin/protocols/platform/android/ProtocolIAP.cpp +++ b/plugin/protocols/platform/android/ProtocolIAP.cpp @@ -27,13 +27,6 @@ THE SOFTWARE. #include "PluginUtils.h" #include "PluginJavaData.h" -#if 1 -#define LOG_TAG "ProtocolIAP" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - namespace cocos2d { namespace plugin { extern "C" { @@ -42,10 +35,10 @@ extern "C" { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); - LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin); + PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { - LOGD("nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName()); + PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolIAP* pIAP = dynamic_cast(pPlugin); if (pIAP != NULL) { @@ -64,19 +57,13 @@ ProtocolIAP::ProtocolIAP() ProtocolIAP::~ProtocolIAP() { - PluginUtils::erasePluginJavaData(this); -} - -bool ProtocolIAP::init() -{ - return true; } void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo) { if (devInfo.empty()) { - LOGD("The developer info is empty!"); + PluginUtils::outputLog("ProtocolIAP", "The developer info is empty!"); return; } else @@ -103,7 +90,7 @@ void ProtocolIAP::payForProduct(TProductInfo info) { if (m_bPaying) { - LOGD("Now is paying"); + PluginUtils::outputLog("ProtocolIAP", "Now is paying"); return; } @@ -113,7 +100,7 @@ void ProtocolIAP::payForProduct(TProductInfo info) { onPayResult(kPayFail, "Product info error"); } - LOGD("The product info is empty!"); + PluginUtils::outputLog("ProtocolIAP", "The product info is empty!"); return; } else @@ -153,32 +140,10 @@ void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg) } else { - LOGD("Result listener is null!"); + PluginUtils::outputLog("ProtocolIAP", "Result listener is null!"); } m_curInfo.clear(); - LOGD("Pay result is : %d(%s)", (int) ret, msg); -} - -const char* ProtocolIAP::getSDKVersion() -{ - std::string verName; - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getSDKVersion" - , "()Ljava/lang/String;")) - { - jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); - verName = PluginJniHelper::jstring2string(ret); - } - return verName.c_str(); -} - -void ProtocolIAP::setDebugMode(bool debug) -{ - PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug); + PluginUtils::outputLog("ProtocolIAP", "Pay result is : %d(%s)", (int) ret, msg); } }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp index 82fb6c01ad..08e3bdd6c6 100755 --- a/plugin/protocols/platform/android/ProtocolSocial.cpp +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -27,13 +27,6 @@ THE SOFTWARE. #include "PluginUtils.h" #include "PluginJavaData.h" -#if 1 -#define LOG_TAG "ProtocolSocial" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - namespace cocos2d { namespace plugin { extern "C" { @@ -42,10 +35,10 @@ extern "C" { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); - LOGD("nativeOnShareResult(), Get plugin ptr : %p", pPlugin); + PluginUtils::outputLog("ProtocolSocial", "nativeOnShareResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { - LOGD("nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName()); + PluginUtils::outputLog("ProtocolSocial", "nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName()); ProtocolSocial* pSocial = dynamic_cast(pPlugin); if (pSocial != NULL) { @@ -62,19 +55,13 @@ ProtocolSocial::ProtocolSocial() ProtocolSocial::~ProtocolSocial() { - PluginUtils::erasePluginJavaData(this); -} - -bool ProtocolSocial::init() -{ - return true; } void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo) { if (devInfo.empty()) { - LOGD("The developer info is empty!"); + PluginUtils::outputLog("ProtocolSocial", "The developer info is empty!"); return; } else @@ -105,7 +92,7 @@ void ProtocolSocial::share(TShareInfo info) { onShareResult(kShareFail, "Share info error"); } - LOGD("The Share info is empty!"); + PluginUtils::outputLog("ProtocolSocial", "The Share info is empty!"); return; } else @@ -141,31 +128,9 @@ void ProtocolSocial::onShareResult(ShareResultCode ret, const char* msg) } else { - LOGD("Result listener is null!"); + PluginUtils::outputLog("ProtocolSocial", "Result listener is null!"); } - LOGD("Share result is : %d(%s)", (int) ret, msg); -} - -const char* ProtocolSocial::getSDKVersion() -{ - std::string verName; - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getSDKVersion" - , "()Ljava/lang/String;")) - { - jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); - verName = PluginJniHelper::jstring2string(ret); - } - return verName.c_str(); -} - -void ProtocolSocial::setDebugMode(bool debug) -{ - PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug); + PluginUtils::outputLog("ProtocolSocial", "Share result is : %d(%s)", (int) ret, msg); } }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/proj.android/jni/Android.mk b/plugin/protocols/proj.android/jni/Android.mk index dfba8cc95b..c503f7dc55 100755 --- a/plugin/protocols/proj.android/jni/Android.mk +++ b/plugin/protocols/proj.android/jni/Android.mk @@ -8,6 +8,7 @@ LOCAL_MODULE_FILENAME := libPluginProtocolStatic LOCAL_SRC_FILES :=\ $(addprefix ../../platform/android/, \ + PluginFactory.cpp \ PluginJniHelper.cpp \ PluginUtils.cpp \ ProtocolAnalytics.cpp \ @@ -16,7 +17,6 @@ $(addprefix ../../platform/android/, \ ProtocolSocial.cpp \ ) \ ../../PluginManager.cpp \ -../../RegisterPlugin.cpp \ ../../PluginParam.cpp LOCAL_CFLAGS := -Wno-psabi diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java new file mode 100644 index 0000000000..65499853d6 --- /dev/null +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java @@ -0,0 +1,116 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.plugin; + +import java.util.Hashtable; + +import android.view.Gravity; +import android.view.View; +import android.view.WindowManager; + +public class AdsWrapper { + + public static final int RESULT_CODE_AdsReceived = 0; // The ad is received + public static final int RESULT_CODE_FullScreenViewShown = 1; // The full screen advertisement shown + public static final int RESULT_CODE_FullScreenViewDismissed = 2; // The full screen advertisement dismissed + public static final int RESULT_CODE_PointsSpendSucceed = 3; // The points spend succeed + public static final int RESULT_CODE_PointsSpendFailed = 4; // The points spend failed + public static final int RESULT_CODE_NetworkError = 5; // Network error + public static final int RESULT_CODE_UnknownError = 6; // Unknown error + + public static final int ADS_TYPE_BANNER = 0; + public static final int ADS_TYPE_FULL_SCREEN = 1; + + public static final int POS_CENTER = 0; + public static final int POS_TOP = 1; + public static final int POS_TOP_LEFT = 2; + public static final int POS_TOP_RIGHT = 3; + public static final int POS_BOTTOM = 4; + public static final int POS_BOTTOM_LEFT = 5; + public static final int POS_BOTTOM_RIGHT = 6; + + public static void addAdView(WindowManager mWm, View adView, int pos) { + WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(); + mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; + mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; + mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; + mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + + switch (pos) { + case POS_CENTER: + mLayoutParams.gravity = Gravity.CENTER; + break; + case POS_TOP: + mLayoutParams.gravity = Gravity.TOP; + break; + case POS_TOP_LEFT: + mLayoutParams.gravity = Gravity.TOP | Gravity.LEFT; + break; + case POS_TOP_RIGHT: + mLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT; + break; + case POS_BOTTOM: + mLayoutParams.gravity = Gravity.BOTTOM; + break; + case POS_BOTTOM_LEFT: + mLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; + break; + case POS_BOTTOM_RIGHT: + mLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; + break; + default: + break; + } + mWm.addView(adView, mLayoutParams); + } + + public static void onAdsResult(InterfaceAds adapter, int code, String msg) { + final int curCode = code; + final String curMsg = msg; + final InterfaceAds curObj = adapter; + PluginWrapper.runOnGLThread(new Runnable(){ + @Override + public void run() { + String name = curObj.getClass().getName(); + name = name.replace('.', '/'); + AdsWrapper.nativeOnAdsResult(name, curCode, curMsg); + } + }); + } + private native static void nativeOnAdsResult(String className, int code, String msg); + + public static void onPlayerGetPoints(InterfaceAds adapter, int points) { + final int curPoints = points; + final InterfaceAds curAdapter = adapter; + PluginWrapper.runOnGLThread(new Runnable(){ + @Override + public void run() { + String name = curAdapter.getClass().getName(); + name = name.replace('.', '/'); + AdsWrapper.nativeOnPlayerGetPoints(name, curPoints); + } + }); + } + private native static void nativeOnPlayerGetPoints(String className, int points); +} diff --git a/plugin/protocols/include/RegisterPlugin.h b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java similarity index 51% rename from plugin/protocols/include/RegisterPlugin.h rename to plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java index ea59063e37..5e00194ef9 100644 --- a/plugin/protocols/include/RegisterPlugin.h +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java @@ -21,44 +21,28 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#ifndef __CCX_REGISTERPLUGIN_H__ -#define __CCX_REGISTERPLUGIN_H__ +package org.cocos2dx.plugin; -namespace cocos2d { namespace plugin { +import java.util.Hashtable; -class PluginProtocol; +public class IAPWrapper { + public static final int PAYRESULT_SUCCESS = 0; + public static final int PAYRESULT_FAIL = 1; + public static final int PAYRESULT_CANCEL = 2; + public static final int PAYRESULT_TIMEOUT = 3; -typedef PluginProtocol* (*PluginCreator)(); - -/** - @brief RegisterPlugin class is only for associating plugin name with plugin creator. - Plugin developers don't need to use this class directly. - Using the macros 'PLUGIN_REGISTER_DECL' and 'PLUGIN_REGISTER_IMPL' instead. -*/ -class RegisterPlugin -{ -public: - RegisterPlugin(const char* name, PluginCreator pfnCreator); -}; - -#define PLUGIN_REGISTER_DECL(type) \ - private: type() {} \ - static RegisterPlugin s_registerPlugin; \ - public: static PluginProtocol* createPlugin(); \ - virtual const char* getPluginName() { return #type; }; - -#define PLUGIN_REGISTER_IMPL(type) \ -RegisterPlugin type::s_registerPlugin(#type, type::createPlugin); \ -PluginProtocol* type::createPlugin() { \ - type* pRet = new type(); \ - if (pRet) { \ - if (!pRet->init()) { \ - delete pRet; pRet = NULL; \ - } \ - } \ - return pRet; \ + public static void onPayResult(InterfaceIAP obj, int ret, String msg) { + final int curRet = ret; + final String curMsg = msg; + final InterfaceIAP curObj = obj; + PluginWrapper.runOnGLThread(new Runnable() { + @Override + public void run() { + String name = curObj.getClass().getName(); + name = name.replace('.', '/'); + nativeOnPayResult(name, curRet, curMsg); + } + }); + } + private static native void nativeOnPayResult(String className, int ret, String msg); } - -}} //namespace cocos2d { namespace plugin { - -#endif /* __CCX_REGISTERPLUGIN_H__ */ diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java index 3842c6311f..6d7f85f1f9 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java @@ -25,101 +25,15 @@ package org.cocos2dx.plugin; import java.util.Hashtable; -import android.view.Gravity; -import android.view.View; -import android.view.WindowManager; +public interface InterfaceAds { -public class InterfaceAds { + public final int PluginType = 1; - public static final int RESULT_CODE_AdsReceived = 0; // The ad is received - public static final int RESULT_CODE_FullScreenViewShown = 1; // The full screen advertisement shown - public static final int RESULT_CODE_FullScreenViewDismissed = 2; // The full screen advertisement dismissed - public static final int RESULT_CODE_PointsSpendSucceed = 3; // The points spend succeed - public static final int RESULT_CODE_PointsSpendFailed = 4; // The points spend failed - public static final int RESULT_CODE_NetworkError = 5; // Network error - public static final int RESULT_CODE_UnknownError = 6; // Unknown error - - public static final int ADS_TYPE_BANNER = 0; - public static final int ADS_TYPE_FULL_SCREEN = 1; - - public static final int POS_CENTER = 0; - public static final int POS_TOP = 1; - public static final int POS_TOP_LEFT = 2; - public static final int POS_TOP_RIGHT = 3; - public static final int POS_BOTTOM = 4; - public static final int POS_BOTTOM_LEFT = 5; - public static final int POS_BOTTOM_RIGHT = 6; - - public interface AdsAdapter { - public void configDeveloperInfo(Hashtable devInfo); - public void showAds(int type, int sizeEnum, int pos); - public void hideAds(int type); - public void spendPoints(int points); - public void setDebugMode(boolean debug); - public String getSDKVersion(); - } - - public static void addAdView(WindowManager mWm, View adView, int pos) { - WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(); - mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; - mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; - mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; - mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - - switch (pos) { - case POS_CENTER: - mLayoutParams.gravity = Gravity.CENTER; - break; - case POS_TOP: - mLayoutParams.gravity = Gravity.TOP; - break; - case POS_TOP_LEFT: - mLayoutParams.gravity = Gravity.TOP | Gravity.LEFT; - break; - case POS_TOP_RIGHT: - mLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT; - break; - case POS_BOTTOM: - mLayoutParams.gravity = Gravity.BOTTOM; - break; - case POS_BOTTOM_LEFT: - mLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; - break; - case POS_BOTTOM_RIGHT: - mLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; - break; - default: - break; - } - mWm.addView(adView, mLayoutParams); - } - - public static void onAdsResult(AdsAdapter adapter, int code, String msg) { - final int curCode = code; - final String curMsg = msg; - final AdsAdapter curObj = adapter; - PluginWrapper.runOnGLThread(new Runnable(){ - @Override - public void run() { - String name = curObj.getClass().getName(); - name = name.replace('.', '/'); - InterfaceAds.nativeOnAdsResult(name, curCode, curMsg); - } - }); - } - private native static void nativeOnAdsResult(String className, int code, String msg); - - public static void onPlayerGetPoints(AdsAdapter adapter, int points) { - final int curPoints = points; - final AdsAdapter curAdapter = adapter; - PluginWrapper.runOnGLThread(new Runnable(){ - @Override - public void run() { - String name = curAdapter.getClass().getName(); - name = name.replace('.', '/'); - InterfaceAds.nativeOnPlayerGetPoints(name, curPoints); - } - }); - } - private native static void nativeOnPlayerGetPoints(String className, int points); + public void configDeveloperInfo(Hashtable devInfo); + public void showAds(int type, int sizeEnum, int pos); + public void hideAds(int type); + public void spendPoints(int points); + public void setDebugMode(boolean debug); + public String getSDKVersion(); + public String getPluginVersion(); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java index 9135cd8519..84aa078449 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java @@ -27,6 +27,8 @@ import java.util.Hashtable; public interface InterfaceAnalytics { + public final int PluginType = 2; + public void startSession(String appKey); public void stopSession(); public void setSessionContinueMillis(int millis); @@ -38,4 +40,5 @@ public interface InterfaceAnalytics { public void logTimedEventBegin(String eventId); public void logTimedEventEnd(String eventId); public String getSDKVersion(); + public String getPluginVersion(); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java index 340abdc74c..d576287cf2 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java @@ -25,31 +25,12 @@ package org.cocos2dx.plugin; import java.util.Hashtable; -public class InterfaceIAP { - public static final int PAYRESULT_SUCCESS = 0; - public static final int PAYRESULT_FAIL = 1; - public static final int PAYRESULT_CANCEL = 2; - public static final int PAYRESULT_TIMEOUT = 3; +public interface InterfaceIAP { + public final int PluginType = 3; - public interface IAPAdapter { - public void configDeveloperInfo(Hashtable cpInfo); - public void payForProduct(Hashtable cpInfo); - public void setDebugMode(boolean debug); - public String getSDKVersion(); - } - - public static void onPayResult(IAPAdapter obj, int ret, String msg) { - final int curRet = ret; - final String curMsg = msg; - final IAPAdapter curObj = obj; - PluginWrapper.runOnGLThread(new Runnable() { - @Override - public void run() { - String name = curObj.getClass().getName(); - name = name.replace('.', '/'); - nativeOnPayResult(name, curRet, curMsg); - } - }); - } - private static native void nativeOnPayResult(String className, int ret, String msg); + public void configDeveloperInfo(Hashtable cpInfo); + public void payForProduct(Hashtable cpInfo); + public void setDebugMode(boolean debug); + public String getSDKVersion(); + public String getPluginVersion(); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java index 90147ffc6d..4066a0be9e 100755 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java @@ -25,31 +25,12 @@ package org.cocos2dx.plugin; import java.util.Hashtable; -public class InterfaceSocial { - public static final int SHARERESULT_SUCCESS = 0; - public static final int SHARERESULT_FAIL = 1; - public static final int SHARERESULT_CANCEL = 2; - public static final int SHARERESULT_TIMEOUT = 3; +public interface InterfaceSocial { + public final int PluginType = 4; - public interface ShareAdapter { - public void configDeveloperInfo(Hashtable cpInfo); - public void share(Hashtable cpInfo); - public void setDebugMode(boolean debug); - public String getSDKVersion(); - } - - public static void onShareResult(ShareAdapter obj, int ret, String msg) { - final int curRet = ret; - final String curMsg = msg; - final ShareAdapter curAdapter = obj; - PluginWrapper.runOnGLThread(new Runnable() { - @Override - public void run() { - String name = curAdapter.getClass().getName(); - name = name.replace('.', '/'); - nativeOnShareResult(name, curRet, curMsg); - } - }); - } - private static native void nativeOnShareResult(String className, int ret, String msg); + public void configDeveloperInfo(Hashtable cpInfo); + public void share(Hashtable cpInfo); + public void setDebugMode(boolean debug); + public String getSDKVersion(); + public String getPluginVersion(); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java index 3583870a19..749b41b282 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java @@ -30,9 +30,7 @@ import android.util.Log; public class PluginWrapper { - - public static native void nativeInitPlugin(Object instance, String className); - + protected static Context sContext = null; protected static GLSurfaceView sGLSurfaceView = null; protected static Handler sMainThreadHandler = null; @@ -50,33 +48,33 @@ public class PluginWrapper { sGLSurfaceView = value; } - protected static boolean initPlugin(String classFullName) + protected static Object initPlugin(String classFullName) { Log.i(TAG, "class name : ----" + classFullName + "----"); Class c = null; - try { - c = Class.forName(classFullName); + try { + String fullName = classFullName.replace('/', '.'); + c = Class.forName(fullName); } catch (ClassNotFoundException e) { Log.e(TAG, "Class " + classFullName + " not found."); e.printStackTrace(); - return false; - } + return null; + } try { Context ctx = getContext(); if (ctx != null) { Object o = c.getDeclaredConstructor(Context.class).newInstance(ctx); - PluginWrapper.nativeInitPlugin(o, classFullName.replace('.', '/')); - return true; + return o; } else { Log.e(TAG, "Plugin " + classFullName + " wasn't initialized."); } } catch (Exception e) { e.printStackTrace(); } - return false; + return null; } - + public static Context getContext() { return sContext; } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java new file mode 100755 index 0000000000..c6ab687524 --- /dev/null +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java @@ -0,0 +1,48 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.plugin; + +import java.util.Hashtable; + +public class SocialWrapper { + public static final int SHARERESULT_SUCCESS = 0; + public static final int SHARERESULT_FAIL = 1; + public static final int SHARERESULT_CANCEL = 2; + public static final int SHARERESULT_TIMEOUT = 3; + + public static void onShareResult(InterfaceSocial obj, int ret, String msg) { + final int curRet = ret; + final String curMsg = msg; + final InterfaceSocial curAdapter = obj; + PluginWrapper.runOnGLThread(new Runnable() { + @Override + public void run() { + String name = curAdapter.getClass().getName(); + name = name.replace('.', '/'); + nativeOnShareResult(name, curRet, curMsg); + } + }); + } + private static native void nativeOnShareResult(String className, int ret, String msg); +} From 9f61f920179c91830f242552e2a339638960df04 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Mon, 27 May 2013 13:58:31 +0800 Subject: [PATCH 03/18] issue #2224 : Modify the implementation of plugin twitter & weibo on android for the new framework of plugin. --- .../plugins/twitter/include/SocialTwitter.h | 76 ------------------ plugin/plugins/twitter/jsb_twitter.ini | 60 -------------- .../platform/android/SocialTwitter.cpp | 78 ------------------- .../twitter/proj.android/build_native.sh | 20 ----- .../twitter/proj.android/jni/Android.mk | 29 ------- .../twitter/proj.android/jni/Application.mk | 7 -- .../org/cocos2dx/plugin/SocialTwitter.java | 22 +++--- plugin/plugins/weibo/include/SocialWeibo.h | 74 ------------------ plugin/plugins/weibo/jsb_weibo.ini | 60 -------------- .../weibo/platform/android/SocialWeibo.cpp | 77 ------------------ .../weibo/proj.android/build_native.sh | 20 ----- .../plugins/weibo/proj.android/jni/Android.mk | 29 ------- .../weibo/proj.android/jni/Application.mk | 7 -- .../src/org/cocos2dx/plugin/SocialWeibo.java | 28 ++++--- plugin/protocols/PluginManager.cpp | 4 + .../platform/android/PluginFactory.cpp | 26 ++++--- .../platform/android/PluginProtocol.cpp | 2 - .../platform/android/PluginUtils.cpp | 4 + .../protocols/platform/android/PluginUtils.h | 4 + .../platform/android/ProtocolAds.cpp | 4 +- .../platform/android/ProtocolIAP.cpp | 2 +- .../platform/android/ProtocolSocial.cpp | 2 +- plugin/protocols/proj.android/jni/Android.mk | 1 + .../src/org/cocos2dx/plugin/AdsWrapper.java | 2 - .../src/org/cocos2dx/plugin/IAPWrapper.java | 2 - .../org/cocos2dx/plugin/PluginWrapper.java | 16 ++++ .../org/cocos2dx/plugin/SocialWrapper.java | 2 - .../HelloSocial/Classes/MySocialManager.cpp | 60 +++++++------- .../HelloSocial/Classes/MySocialManager.h | 7 +- .../HelloSocial/proj.android/jni/Android.mk | 6 +- plugin/tools/publish.sh | 2 +- plugin/tools/toolsForPublish/publishPlugin.sh | 53 +++++++------ 32 files changed, 147 insertions(+), 639 deletions(-) delete mode 100755 plugin/plugins/twitter/include/SocialTwitter.h delete mode 100644 plugin/plugins/twitter/jsb_twitter.ini delete mode 100755 plugin/plugins/twitter/platform/android/SocialTwitter.cpp delete mode 100755 plugin/plugins/twitter/proj.android/build_native.sh delete mode 100755 plugin/plugins/twitter/proj.android/jni/Android.mk delete mode 100755 plugin/plugins/twitter/proj.android/jni/Application.mk delete mode 100755 plugin/plugins/weibo/include/SocialWeibo.h delete mode 100644 plugin/plugins/weibo/jsb_weibo.ini delete mode 100755 plugin/plugins/weibo/platform/android/SocialWeibo.cpp delete mode 100755 plugin/plugins/weibo/proj.android/build_native.sh delete mode 100755 plugin/plugins/weibo/proj.android/jni/Android.mk delete mode 100755 plugin/plugins/weibo/proj.android/jni/Application.mk diff --git a/plugin/plugins/twitter/include/SocialTwitter.h b/plugin/plugins/twitter/include/SocialTwitter.h deleted file mode 100755 index 6487741d0c..0000000000 --- a/plugin/plugins/twitter/include/SocialTwitter.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_SOCIAL_TWITTER_H__ -#define __CCX_SOCIAL_TWITTER_H__ - -#include "ProtocolSocial.h" -#include -#include - -namespace cocos2d { namespace plugin { - -class SocialTwitter : public ProtocolSocial -{ - PLUGIN_REGISTER_DECL(SocialTwitter) -public: - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief config the developer info - @param devInfo This parameter is the info of developer, must contains key: - TwitterKey The consumerkey of twitter account - TwitterSecret The consumersecret of twitter account - @warning Must invoke this interface before other interfaces. - And invoked only once. - */ - virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo); - - /** - @brief pay for product - @param info The info of product, can contains key: - SharedText The text need to share - SharedImagePath The full path of image file need to share (optinal) - @warning For different plugin, the parameter should have other keys to pay. - Look at the manual of plugins. - */ - virtual void share(TShareInfo info); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - virtual ~SocialTwitter(); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_SOCIAL_TWITTER_H__ */ diff --git a/plugin/plugins/twitter/jsb_twitter.ini b/plugin/plugins/twitter/jsb_twitter.ini deleted file mode 100644 index 01d3058c96..0000000000 --- a/plugin/plugins/twitter/jsb_twitter.ini +++ /dev/null @@ -1,60 +0,0 @@ -[twitter] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_twitter - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/twitter/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/twitter/include/SocialTwitter.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = SocialTwitter - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = SocialTwitter - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes - diff --git a/plugin/plugins/twitter/platform/android/SocialTwitter.cpp b/plugin/plugins/twitter/platform/android/SocialTwitter.cpp deleted file mode 100755 index 7d7bfafa0d..0000000000 --- a/plugin/plugins/twitter/platform/android/SocialTwitter.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "SocialTwitter.h" -#include "PluginUtils.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(SocialTwitter) - -SocialTwitter::~SocialTwitter() -{ -} - -/** -@brief plugin initialization -*/ -bool SocialTwitter::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.SocialTwitter"); -} - -/** -@brief config the developer info -@param devInfo This parameter is the info of developer, must contains key: - TwitterKey The consumerkey of twitter account - TwitterSecret The consumersecret of twitter account - More: https://dev.twitter.com -@warning Must invoke this interface before other interfaces. - And invoked only once. -*/ -void SocialTwitter::configDeveloperInfo(TSocialDeveloperInfo devInfo) -{ - ProtocolSocial::configDeveloperInfo(devInfo); -} - -/** -@brief pay for product -@param info The info of product, must contains key: - SharedText The text need to share - SharedImagePath The full path of image file need to share (optinal) -*/ -void SocialTwitter::share(TShareInfo info) -{ - ProtocolSocial::share(info); -} - -const char* SocialTwitter::getSDKVersion() -{ - return ProtocolSocial::getSDKVersion(); -} - -void SocialTwitter::setDebugMode(bool debug) -{ - ProtocolSocial::setDebugMode(debug); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/twitter/proj.android/build_native.sh b/plugin/plugins/twitter/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/twitter/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/twitter/proj.android/jni/Android.mk b/plugin/plugins/twitter/proj.android/jni/Android.mk deleted file mode 100755 index e4c920eb4c..0000000000 --- a/plugin/plugins/twitter/proj.android/jni/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginTwitterStatic - -LOCAL_MODULE_FILENAME := libPluginTwitterStatic - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - SocialTwitter.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) diff --git a/plugin/plugins/twitter/proj.android/jni/Application.mk b/plugin/plugins/twitter/proj.android/jni/Application.mk deleted file mode 100755 index e4935028c3..0000000000 --- a/plugin/plugins/twitter/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginTwitterStatic -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java index d539e6f016..b799bbd151 100755 --- a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java +++ b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java @@ -25,7 +25,6 @@ package org.cocos2dx.plugin; import java.util.Hashtable; -import org.cocos2dx.plugin.InterfaceSocial.ShareAdapter; import org.cocos2dx.plugin.TwitterApp.TwDialogListener; import android.app.Activity; @@ -34,11 +33,11 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; -public class SocialTwitter implements ShareAdapter { +public class SocialTwitter implements InterfaceSocial { private static final String LOG_TAG = "SocialTwitter"; private static Activity mContext = null; - private static ShareAdapter mSocialAdapter = null; + private static InterfaceSocial mSocialAdapter = null; protected static boolean bDebug = false; private static String CONSUMER_KEY=""; private static String CONSUMER_SECRET=""; @@ -98,12 +97,12 @@ public class SocialTwitter implements ShareAdapter { LogD("share invoked " + info.toString()); mShareInfo = info; if (! networkReachable()) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, "Network error!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "Network error!"); return; } if (! isInitialized) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, "Initialize failed!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "Initialize failed!"); return; } @@ -153,7 +152,7 @@ public class SocialTwitter implements ShareAdapter { } private static void shareResult(int ret, String msg) { - InterfaceSocial.onShareResult(mSocialAdapter, ret, msg); + SocialWrapper.onShareResult(mSocialAdapter, ret, msg); LogD("SocialTwitter result : " + ret + " msg : " + msg); } @@ -162,7 +161,7 @@ public class SocialTwitter implements ShareAdapter { @Override public void onError(int flag, String value) { LogD("Twitter connection failed!"); - shareResult(InterfaceSocial.SHARERESULT_FAIL, value); + shareResult(SocialWrapper.SHARERESULT_FAIL, value); } @Override @@ -181,11 +180,16 @@ public class SocialTwitter implements ShareAdapter { mTwitter.updateStatus(text); } LogD("Posted to Twitter!"); - shareResult(InterfaceSocial.SHARERESULT_SUCCESS, "Share succeed!"); + shareResult(SocialWrapper.SHARERESULT_SUCCESS, "Share succeed!"); } catch (Exception e) { LogD("Post to Twitter failed!"); - shareResult(InterfaceSocial.SHARERESULT_FAIL, "Unknown error!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "Unknown error!"); e.printStackTrace(); } } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/plugins/weibo/include/SocialWeibo.h b/plugin/plugins/weibo/include/SocialWeibo.h deleted file mode 100755 index 394a257285..0000000000 --- a/plugin/plugins/weibo/include/SocialWeibo.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_SOCIAL_WEIBO_H__ -#define __CCX_SOCIAL_WEIBO_H__ - -#include "ProtocolSocial.h" - -namespace cocos2d { namespace plugin { - -class SocialWeibo : public ProtocolSocial -{ - PLUGIN_REGISTER_DECL(SocialWeibo) -public: - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief config the developer info - @param devInfo This parameter is the info of developer, must contains key: - WeiboAppKey The app key of weibo account - WeiboRedirectUrl The redirect url of weibo account - @warning Must invoke this interface before other interfaces. - And invoked only once. - */ - virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo); - - /** - @brief pay for product - @param info The info of product, can contains key: - SharedText The text need to share - SharedImagePath The full path of image file need to share (optinal) - @warning For different plugin, the parameter should have other keys to pay. - Look at the manual of plugins. - */ - virtual void share(TShareInfo info); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - virtual ~SocialWeibo(); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_SOCIAL_WEIBO_H__ */ diff --git a/plugin/plugins/weibo/jsb_weibo.ini b/plugin/plugins/weibo/jsb_weibo.ini deleted file mode 100644 index f6ef4983ec..0000000000 --- a/plugin/plugins/weibo/jsb_weibo.ini +++ /dev/null @@ -1,60 +0,0 @@ -[weibo] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_weibo - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/weibo/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/weibo/include/SocialWeibo.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = SocialWeibo - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = SocialWeibo - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes - diff --git a/plugin/plugins/weibo/platform/android/SocialWeibo.cpp b/plugin/plugins/weibo/platform/android/SocialWeibo.cpp deleted file mode 100755 index f311270bb3..0000000000 --- a/plugin/plugins/weibo/platform/android/SocialWeibo.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "SocialWeibo.h" -#include "PluginUtils.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(SocialWeibo) - -SocialWeibo::~SocialWeibo() -{ -} - -/** -@brief plugin initialization -*/ -bool SocialWeibo::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.SocialWeibo"); -} - -/** -@brief config the developer info -@param devInfo This parameter is the info of developer, must contains key: - WeiboAppKey The app key of weibo account - WeiboRedirectUrl The redirect url of weibo account -@warning Must invoke this interface before other interfaces. - And invoked only once. -*/ -void SocialWeibo::configDeveloperInfo(TSocialDeveloperInfo devInfo) -{ - ProtocolSocial::configDeveloperInfo(devInfo); -} - -/** -@brief pay for product -@param info The info of product, must contains key: - SharedText The text need to share - SharedImagePath The full path of image file need to share (optinal) -*/ -void SocialWeibo::share(TShareInfo info) -{ - ProtocolSocial::share(info); -} - -const char* SocialWeibo::getSDKVersion() -{ - return ProtocolSocial::getSDKVersion(); -} - -void SocialWeibo::setDebugMode(bool debug) -{ - ProtocolSocial::setDebugMode(debug); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/weibo/proj.android/build_native.sh b/plugin/plugins/weibo/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/weibo/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/weibo/proj.android/jni/Android.mk b/plugin/plugins/weibo/proj.android/jni/Android.mk deleted file mode 100755 index 695a6a352d..0000000000 --- a/plugin/plugins/weibo/proj.android/jni/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginWeiboStatic - -LOCAL_MODULE_FILENAME := libPluginWeiboStatic - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - SocialWeibo.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) diff --git a/plugin/plugins/weibo/proj.android/jni/Application.mk b/plugin/plugins/weibo/proj.android/jni/Application.mk deleted file mode 100755 index 68e59b0ee9..0000000000 --- a/plugin/plugins/weibo/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginWeiboStatic -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/weibo/proj.android/src/org/cocos2dx/plugin/SocialWeibo.java b/plugin/plugins/weibo/proj.android/src/org/cocos2dx/plugin/SocialWeibo.java index 6a9e074440..8a50d5f5ad 100755 --- a/plugin/plugins/weibo/proj.android/src/org/cocos2dx/plugin/SocialWeibo.java +++ b/plugin/plugins/weibo/proj.android/src/org/cocos2dx/plugin/SocialWeibo.java @@ -26,7 +26,6 @@ package org.cocos2dx.plugin; import java.io.IOException; import java.util.Hashtable; -import org.cocos2dx.plugin.InterfaceSocial.ShareAdapter; import com.weibo.sdk.android.Oauth2AccessToken; import com.weibo.sdk.android.Weibo; @@ -43,7 +42,7 @@ import android.net.NetworkInfo; import android.os.Bundle; import android.util.Log; -public class SocialWeibo implements ShareAdapter { +public class SocialWeibo implements InterfaceSocial { private static final String LOG_TAG = "SocialWeibo"; private static Activity mContext = null; @@ -109,12 +108,12 @@ public class SocialWeibo implements ShareAdapter { LogD("share invoked " + info.toString()); mShareInfo = info; if (! networkReachable()) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, "Network error!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "Network error!"); return; } if (! isInitialized) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, "Initialize failed!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "Initialize failed!"); return; } @@ -154,7 +153,7 @@ public class SocialWeibo implements ShareAdapter { } public static void shareResult(int ret, String msg) { - InterfaceSocial.onShareResult(mSocialAdapter, ret, msg); + SocialWrapper.onShareResult(mSocialAdapter, ret, msg); LogD("SocialWeibo result : " + ret + " msg : " + msg); } @@ -170,24 +169,24 @@ public class SocialWeibo implements ShareAdapter { mSocialAdapter.shareToWeibo(); } catch (Exception e) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, "认证失败!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "认证失败!"); LogE("anthorize failed", e); } } @Override public void onError(WeiboDialogError e) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, e.getMessage()); + shareResult(SocialWrapper.SHARERESULT_FAIL, e.getMessage()); } @Override public void onCancel() { - shareResult(InterfaceSocial.SHARERESULT_FAIL, "取消认证!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "取消认证!"); } @Override public void onWeiboException(WeiboException e) { - shareResult(InterfaceSocial.SHARERESULT_FAIL, e.getMessage()); + shareResult(SocialWrapper.SHARERESULT_FAIL, e.getMessage()); } } @@ -206,19 +205,24 @@ public class SocialWeibo implements ShareAdapter { @Override public void onComplete(String arg0) { - shareResult(InterfaceSocial.SHARERESULT_SUCCESS, "分享成功!"); + shareResult(SocialWrapper.SHARERESULT_SUCCESS, "分享成功!"); } @Override public void onError(WeiboException arg0) { LogE("Share onError", arg0); - shareResult(InterfaceSocial.SHARERESULT_FAIL, "分享失败!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "分享失败!"); } @Override public void onIOException(IOException arg0) { LogE("Share onIOException", arg0); - shareResult(InterfaceSocial.SHARERESULT_FAIL, "分享失败!"); + shareResult(SocialWrapper.SHARERESULT_FAIL, "分享失败!"); } } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/protocols/PluginManager.cpp b/plugin/protocols/PluginManager.cpp index b4d79d8edd..f39a893ca2 100644 --- a/plugin/protocols/PluginManager.cpp +++ b/plugin/protocols/PluginManager.cpp @@ -77,6 +77,10 @@ PluginProtocol* PluginManager::loadPlugin(const char* name) it->second = PluginFactory::getInstance()->createPlugin(name); } pRet = it->second; + } else + { + pRet = PluginFactory::getInstance()->createPlugin(name); + m_pluginsMap["name"] = pRet; } } while (false); diff --git a/plugin/protocols/platform/android/PluginFactory.cpp b/plugin/protocols/platform/android/PluginFactory.cpp index 09029f1fa9..6b4ba4a89b 100644 --- a/plugin/protocols/platform/android/PluginFactory.cpp +++ b/plugin/protocols/platform/android/PluginFactory.cpp @@ -38,9 +38,7 @@ enum { kPluginSocial, }; -#define ANDROID_PLUGIN_TYPE_FIELD "PluginType" -#define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugins/" -#define BREAK_IF(cond) if(cond) break +#define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugin/" static PluginFactory* s_pFactory = NULL; @@ -91,6 +89,7 @@ PluginProtocol* PluginFactory::createPlugin(const char* name) , "initPlugin" , "(Ljava/lang/String;)Ljava/lang/Object;")) { + PluginUtils::outputLog("PluginFactory", "Can't find method initPlugin in class org.cocos2dx.plugin.PluginWrapper"); break; } @@ -98,13 +97,22 @@ PluginProtocol* PluginFactory::createPlugin(const char* name) jobject jObj = t.env->CallStaticObjectMethod(t.classID, t.methodID, clsName); t.env->DeleteLocalRef(clsName); t.env->DeleteLocalRef(t.classID); - BREAK_IF(jObj == NULL); + if (jObj == NULL) + { + PluginUtils::outputLog("PluginFactory", "Can't find java class %s", jClassName.c_str()); + break; + } - jclass jcls = t.env->FindClass(jClassName.c_str()); - jfieldID fid_Type = t.env->GetFieldID(jcls, ANDROID_PLUGIN_TYPE_FIELD, "I"); - BREAK_IF(fid_Type == NULL); - - int curType = t.env->GetIntField(jObj, fid_Type); + 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) diff --git a/plugin/protocols/platform/android/PluginProtocol.cpp b/plugin/protocols/platform/android/PluginProtocol.cpp index e049e30df8..52983f9f9c 100644 --- a/plugin/protocols/platform/android/PluginProtocol.cpp +++ b/plugin/protocols/platform/android/PluginProtocol.cpp @@ -115,5 +115,3 @@ void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) } }} //namespace cocos2d { namespace plugin { - -#endif /* __CCX_IPLUGIN_H__ */ diff --git a/plugin/protocols/platform/android/PluginUtils.cpp b/plugin/protocols/platform/android/PluginUtils.cpp index 64068b0a9a..6437e9ff01 100644 --- a/plugin/protocols/platform/android/PluginUtils.cpp +++ b/plugin/protocols/platform/android/PluginUtils.cpp @@ -98,6 +98,10 @@ PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj) ret = it->second; } + if (NULL != ret) + { + outputLog("PluginUtils", "get plugin java data : %s, %p", ret->jclassName.c_str(), ret->jobj); + } return ret; } diff --git a/plugin/protocols/platform/android/PluginUtils.h b/plugin/protocols/platform/android/PluginUtils.h index 9f6d97ec4a..db9c9ebf99 100644 --- a/plugin/protocols/platform/android/PluginUtils.h +++ b/plugin/protocols/platform/android/PluginUtils.h @@ -56,6 +56,8 @@ public: return_if_fails(funcName != NULL && strlen(funcName) > 0); return_if_fails(paramCode != NULL && strlen(paramCode) > 0); PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); + return_if_fails(pData != NULL); + PluginJniMethodInfo t; if (PluginJniHelper::getMethodInfo(t , pData->jclassName.c_str() @@ -71,6 +73,8 @@ public: { return_if_fails(funcName != NULL && strlen(funcName) > 0); PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); + return_if_fails(pData != NULL); + PluginJniMethodInfo t; if (PluginJniHelper::getMethodInfo(t , pData->jclassName.c_str() diff --git a/plugin/protocols/platform/android/ProtocolAds.cpp b/plugin/protocols/platform/android/ProtocolAds.cpp index 2e03bd444f..65b859852c 100644 --- a/plugin/protocols/platform/android/ProtocolAds.cpp +++ b/plugin/protocols/platform/android/ProtocolAds.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { + 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); @@ -46,7 +46,7 @@ extern "C" { } } - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) { + 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); diff --git a/plugin/protocols/platform/android/ProtocolIAP.cpp b/plugin/protocols/platform/android/ProtocolIAP.cpp index fd19cde31a..b12fb1e9c3 100644 --- a/plugin/protocols/platform/android/ProtocolIAP.cpp +++ b/plugin/protocols/platform/android/ProtocolIAP.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) + 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); diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp index 08e3bdd6c6..fab901c89f 100755 --- a/plugin/protocols/platform/android/ProtocolSocial.cpp +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) + JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_SocialWrapper_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); std::string strClassName = PluginJniHelper::jstring2string(className); diff --git a/plugin/protocols/proj.android/jni/Android.mk b/plugin/protocols/proj.android/jni/Android.mk index c503f7dc55..4bc000a7bd 100755 --- a/plugin/protocols/proj.android/jni/Android.mk +++ b/plugin/protocols/proj.android/jni/Android.mk @@ -11,6 +11,7 @@ $(addprefix ../../platform/android/, \ PluginFactory.cpp \ PluginJniHelper.cpp \ PluginUtils.cpp \ + PluginProtocol.cpp \ ProtocolAnalytics.cpp \ ProtocolIAP.cpp \ ProtocolAds.cpp \ diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java index 65499853d6..42978cad90 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/AdsWrapper.java @@ -23,8 +23,6 @@ THE SOFTWARE. ****************************************************************************/ package org.cocos2dx.plugin; -import java.util.Hashtable; - import android.view.Gravity; import android.view.View; import android.view.WindowManager; diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java index 5e00194ef9..a26c437c18 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/IAPWrapper.java @@ -23,8 +23,6 @@ THE SOFTWARE. ****************************************************************************/ package org.cocos2dx.plugin; -import java.util.Hashtable; - public class IAPWrapper { public static final int PAYRESULT_SUCCESS = 0; public static final int PAYRESULT_FAIL = 1; diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java index 749b41b282..d736d4aeeb 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java @@ -23,6 +23,8 @@ THE SOFTWARE. ****************************************************************************/ package org.cocos2dx.plugin; +import java.lang.reflect.Field; + import android.content.Context; import android.opengl.GLSurfaceView; import android.os.Handler; @@ -75,6 +77,20 @@ public class PluginWrapper { return null; } + protected static int getPluginType(Object obj) { + int nRet = -1; + try + { + Field filedID = obj.getClass().getField("PluginType"); + Integer nObj = (Integer) filedID.get(obj); + nRet = nObj.intValue(); + } catch (Exception e) { + e.printStackTrace(); + } + + return nRet; + } + public static Context getContext() { return sContext; } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java index c6ab687524..76de053aba 100755 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/SocialWrapper.java @@ -23,8 +23,6 @@ THE SOFTWARE. ****************************************************************************/ package org.cocos2dx.plugin; -import java.util.Hashtable; - public class SocialWrapper { public static final int SHARERESULT_SUCCESS = 0; public static final int SHARERESULT_FAIL = 1; diff --git a/plugin/samples/HelloSocial/Classes/MySocialManager.cpp b/plugin/samples/HelloSocial/Classes/MySocialManager.cpp index ca138cf4fc..62bea5c815 100755 --- a/plugin/samples/HelloSocial/Classes/MySocialManager.cpp +++ b/plugin/samples/HelloSocial/Classes/MySocialManager.cpp @@ -75,40 +75,46 @@ void MySocialManager::loadSocialPlugin() { // init twitter plugin - s_pTwitter = dynamic_cast(PluginManager::getInstance()->loadPlugin("SocialTwitter")); - TSocialDeveloperInfo pTwitterInfo; - - /* Warning: must set your twiiter dev info here */ - // pTwitterInfo["TwitterKey"] = "your consumerkey"; - // pTwitterInfo["TwitterSecret"] = "your consumersecret"; - - if (pTwitterInfo.empty()) + s_pTwitter = dynamic_cast(PluginManager::getInstance()->loadPlugin("SocialTwitter")); + if (NULL != s_pTwitter) { - char msg[256] = { 0 }; - sprintf(msg, "Developer info is empty. PLZ fill your twitter info in %s(nearby line %d)", __FILE__, __LINE__); - CCMessageBox(msg, "Twitter Warning"); + TSocialDeveloperInfo pTwitterInfo; + + /* Warning: must set your twiiter dev info here */ + // pTwitterInfo["TwitterKey"] = "your consumerkey"; + // pTwitterInfo["TwitterSecret"] = "your consumersecret"; + + if (pTwitterInfo.empty()) + { + char msg[256] = { 0 }; + sprintf(msg, "Developer info is empty. PLZ fill your twitter info in %s(nearby line %d)", __FILE__, __LINE__); + CCMessageBox(msg, "Twitter Warning"); + } + s_pTwitter->setDebugMode(true); + s_pTwitter->configDeveloperInfo(pTwitterInfo); + s_pTwitter->setResultListener(s_pRetListener); } - s_pTwitter->setDebugMode(true); - s_pTwitter->configDeveloperInfo(pTwitterInfo); - s_pTwitter->setResultListener(s_pRetListener); } { - s_pWeibo = dynamic_cast(PluginManager::getInstance()->loadPlugin("SocialWeibo")); - TSocialDeveloperInfo pWeiboInfo; - // pWeiboInfo["WeiboAppKey"] = "your app key"; - // pWeiboInfo["WeiboRedirectUrl"] = "your redirect url"; - - if (pWeiboInfo.empty()) + s_pWeibo = dynamic_cast(PluginManager::getInstance()->loadPlugin("SocialWeibo")); + if (NULL != s_pWeibo) { - char msg[256] = { 0 }; - sprintf(msg, "Developer info is empty. PLZ fill your weibo info in %s(nearby line %d)", __FILE__, __LINE__); - CCMessageBox(msg, "Weibo Warning"); - } + TSocialDeveloperInfo pWeiboInfo; + // pWeiboInfo["WeiboAppKey"] = "your app key"; + // pWeiboInfo["WeiboRedirectUrl"] = "your redirect url"; - s_pWeibo->setDebugMode(true); - s_pWeibo->configDeveloperInfo(pWeiboInfo); - s_pWeibo->setResultListener(s_pRetListener); + if (pWeiboInfo.empty()) + { + char msg[256] = { 0 }; + sprintf(msg, "Developer info is empty. PLZ fill your weibo info in %s(nearby line %d)", __FILE__, __LINE__); + CCMessageBox(msg, "Weibo Warning"); + } + + s_pWeibo->setDebugMode(true); + s_pWeibo->configDeveloperInfo(pWeiboInfo); + s_pWeibo->setResultListener(s_pRetListener); + } } } diff --git a/plugin/samples/HelloSocial/Classes/MySocialManager.h b/plugin/samples/HelloSocial/Classes/MySocialManager.h index 5aa6d72f76..cc647499b3 100755 --- a/plugin/samples/HelloSocial/Classes/MySocialManager.h +++ b/plugin/samples/HelloSocial/Classes/MySocialManager.h @@ -24,8 +24,7 @@ THE SOFTWARE. #ifndef __MY_SOCIAL_MANAGER_H__ #define __MY_SOCIAL_MANAGER_H__ -#include "SocialTwitter.h" -#include "SocialWeibo.h" +#include "ProtocolSocial.h" class MyShareResult : public cocos2d::plugin::ShareResultListener { @@ -55,8 +54,8 @@ private: static MySocialManager* s_pManager; - cocos2d::plugin::SocialTwitter* s_pTwitter; - cocos2d::plugin::SocialWeibo* s_pWeibo; + cocos2d::plugin::ProtocolSocial* s_pTwitter; + cocos2d::plugin::ProtocolSocial* s_pWeibo; MyShareResult* s_pRetListener; }; diff --git a/plugin/samples/HelloSocial/proj.android/jni/Android.mk b/plugin/samples/HelloSocial/proj.android/jni/Android.mk index 820eb3ba00..cf391cb2bf 100755 --- a/plugin/samples/HelloSocial/proj.android/jni/Android.mk +++ b/plugin/samples/HelloSocial/proj.android/jni/Android.mk @@ -14,13 +14,9 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static \ - PluginTwitterStatic \ - PluginProtocolStatic \ - PluginWeiboStatic + PluginProtocolStatic include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) -$(call import-module,plugins/twitter/android) -$(call import-module,plugins/weibo/android) $(call import-module,protocols/android) diff --git a/plugin/tools/publish.sh b/plugin/tools/publish.sh index 8eb12ad8ab..f7d2c72620 100755 --- a/plugin/tools/publish.sh +++ b/plugin/tools/publish.sh @@ -29,7 +29,7 @@ echo echo echo Now publish protocols echo --------------------------------- -./toolsForPublish/publishPlugin.sh "protocols" ${TARGET_ROOT} ${PLUGIN_ROOT} +./toolsForPublish/publishPlugin.sh "protocols" ${TARGET_ROOT} ${PLUGIN_ROOT} 1 echo --------------------------------- #publish plugins diff --git a/plugin/tools/toolsForPublish/publishPlugin.sh b/plugin/tools/toolsForPublish/publishPlugin.sh index 27b0140aa4..2ec88a16e6 100755 --- a/plugin/tools/toolsForPublish/publishPlugin.sh +++ b/plugin/tools/toolsForPublish/publishPlugin.sh @@ -9,10 +9,6 @@ echo android project dir is ${ANDROID_PROJ_DIR} #create directory for plugin mkdir -p ${TARGET_DIR} -#create include directory -mkdir -p ${TARGET_DIR}/include -cp -rf ${PLUGIN_ROOT}/${plugin_name}/include/* ${TARGET_DIR}/include - ############################### # functions used ############################### @@ -84,25 +80,6 @@ if [ -d ${ANDROID_PROJ_DIR}/sdk ]; then cp -rf ${ANDROID_PROJ_DIR}/sdk/*.jar ${TARGET_DIR}/android fi -#copy android include files -ADNROID_SOURCE_DIR=${PLUGIN_ROOT}/${plugin_name}/platform/android -if [ -d ${ADNROID_SOURCE_DIR} ]; then - HAVE_HEADER_FILE=`find ${ADNROID_SOURCE_DIR} -name "*.h"` - if [ -n "${HAVE_HEADER_FILE}" ]; then - cp -rf ${ADNROID_SOURCE_DIR}/*.h "${TARGET_DIR}/android" - fi -fi - -#invoke ndk build for plugin project -if [ -f "${ANDROID_PROJ_DIR}/build_native.sh" ]; then - ./build_native.sh - LIB_FILE="$(getLibraryFileName)" - cp -rf "${ANDROID_PROJ_DIR}/obj/local/armeabi/${LIB_FILE}" "${TARGET_DIR}/android" -fi - -#generate mk file for prebuild -${PLUGIN_ROOT}/tools/toolsForPublish/genPrebuildMK.sh ${ANDROID_PROJ_DIR}/jni/Android.mk ${TARGET_DIR}/android/Android.mk - #copy android depend on project to publish directory if [ -d "${ADNROID_SOURCE_DIR}/DependProject" ]; then cp -rf "${ADNROID_SOURCE_DIR}/DependProject" "${TARGET_DIR}/android" @@ -123,4 +100,34 @@ if [ -d "${ANDROID_PROJ_DIR}/ForAssets" ]; then cp -rf "${ANDROID_PROJ_DIR}/ForAssets" "${TARGET_DIR}/android" fi +#Build C++ code +BUILD_CPLUSPLUS=$4 +if [ $BUILD_CPLUSPLUS ]; then + + echo "Build C++ code" + + #create include directory + mkdir -p ${TARGET_DIR}/include + cp -rf ${PLUGIN_ROOT}/${plugin_name}/include/* ${TARGET_DIR}/include + + #copy android include files + ADNROID_SOURCE_DIR=${PLUGIN_ROOT}/${plugin_name}/platform/android + if [ -d ${ADNROID_SOURCE_DIR} ]; then + HAVE_HEADER_FILE=`find ${ADNROID_SOURCE_DIR} -name "*.h"` + if [ -n "${HAVE_HEADER_FILE}" ]; then + cp -rf ${ADNROID_SOURCE_DIR}/*.h "${TARGET_DIR}/android" + fi + fi + + #invoke ndk build for plugin project + if [ -f "${ANDROID_PROJ_DIR}/build_native.sh" ]; then + ./build_native.sh + LIB_FILE="$(getLibraryFileName)" + cp -rf "${ANDROID_PROJ_DIR}/obj/local/armeabi/${LIB_FILE}" "${TARGET_DIR}/android" + fi + + #generate mk file for prebuild + ${PLUGIN_ROOT}/tools/toolsForPublish/genPrebuildMK.sh ${ANDROID_PROJ_DIR}/jni/Android.mk ${TARGET_DIR}/android/Android.mk +fi + popd From 35bc7a51d853e2866935787326ee84b63c51cb84 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Mon, 27 May 2013 14:19:36 +0800 Subject: [PATCH 04/18] issue #2224 : Modify the implementation of plugin alipay & nd91. --- plugin/plugins/alipay/include/IAPAlipay.h | 81 ----------------- plugin/plugins/alipay/jsb_alipay.ini | 60 ------------- .../alipay/platform/android/IAPAlipay.cpp | 84 ----------------- plugin/plugins/alipay/proj.android/.project | 12 --- .../alipay/proj.android/build_native.sh | 20 ----- .../alipay/proj.android/jni/Android.mk | 29 ------ .../alipay/proj.android/jni/Application.mk | 7 -- .../src/org/cocos2dx/plugin/IAPAlipay.java | 29 +++--- plugin/plugins/nd91/include/IAPNd91.h | 82 ----------------- plugin/plugins/nd91/jsb_nd91.ini | 59 ------------ .../.settings/org.eclipse.jdt.core.prefs | 11 --- .../plugins/nd91/platform/android/IAPNd91.cpp | 85 ------------------ plugin/plugins/nd91/proj.android/.project | 12 --- .../DependProject/.classpath | 0 .../DependProject/.project | 0 .../DependProject/AndroidManifest.xml | 0 .../DependProject/project.properties | 0 .../DependProject/res/anim/nd_flipin.xml | 0 .../res/anim/nd_flipin_reverse.xml | 0 .../DependProject/res/anim/nd_flipout.xml | 0 .../res/anim/nd_flipout_reverse.xml | 0 .../res/drawable/nd3_background_xml.xml | 0 .../DependProject/res/drawable/nd3_button.xml | 0 .../res/drawable/nd3_button_02.xml | 0 .../res/drawable/nd3_button_action.xml | 0 .../res/drawable/nd3_button_logout.xml | 0 .../res/drawable/nd3_button_old.xml | 0 .../res/drawable/nd3_button_x.xml | 0 .../res/drawable/nd3_checkbox_button.xml | 0 .../res/drawable/nd3_friend_del_button.xml | 0 .../res/drawable/nd3_image_48_bg.xml | 0 .../res/drawable/nd3_input_gray.xml | 0 .../res/drawable/nd3_message_item_1_bg.xml | 0 .../res/drawable/nd3_message_item_2_bg.xml | 0 .../res/drawable/nd3_pay_checkbox_button.xml | 0 .../res/drawable/nd3_progress_large.xml | 0 .../drawable/nd3_rank_choice_left_btn_bg.xml | 0 .../nd3_rank_choice_middle_btn_bg.xml | 0 .../drawable/nd3_rank_choice_right_btn_bg.xml | 0 .../res/drawable/nd3_regist_checked.xml | 0 .../res/drawable/nd3_round_bg.xml | 0 .../drawable/nd3_square_checkbox_button.xml | 0 .../drawable/nd3_title_bar_action_btn_xml.xml | 0 .../drawable/nd3_title_bar_return_btn_xml.xml | 0 .../res/drawable/nd3_user_item_bg.xml | 0 .../DependProject/res/drawable/nd_blue.xml | 0 .../res/drawable/nd_button_action_add.xml | 0 .../res/drawable/nd_button_action_buy.xml | 0 .../res/drawable/nd_button_action_reduce.xml | 0 .../DependProject/res/drawable/nd_c_blur.xml | 0 .../res/drawable/nd_download.xml | 0 .../DependProject/res/drawable/nd_green.xml | 0 .../drawable/nd_leaderboard_left_btn_bg.xml | 0 .../drawable/nd_leaderboard_right_btn_bg.xml | 0 .../drawable/nd_list_btn_delete_selector.xml | 0 .../drawable/nd_login_btn_land_selector.xml | 0 .../nd_login_btn_portrait_selector.xml | 0 .../nd_register_btn_portrait_selector.xml | 0 .../res/drawable/nd_slider_handle_h.xml | 0 .../drawable/nd_slider_handle_h_expand.xml | 0 .../res/drawable/nd_slider_handle_v.xml | 0 .../drawable/nd_slider_handle_v_expand.xml | 0 .../res/drawable/nd_white_btn.xml | 0 .../res/layout/nd3_account_bind_bind.xml | 0 .../res/layout/nd3_account_bind_register.xml | 0 .../res/layout/nd3_account_email_item.xml | 0 .../res/layout/nd3_account_login.xml | 0 .../res/layout/nd3_account_login_item.xml | 0 .../res/layout/nd3_account_login_land.xml | 0 .../layout/nd3_account_login_other_item.xml | 0 .../res/layout/nd3_account_login_portrait.xml | 0 .../res/layout/nd3_account_oauth_bind.xml | 0 .../res/layout/nd3_account_official.xml | 0 .../layout/nd3_account_official_landscape.xml | 0 .../layout/nd3_account_official_portrait.xml | 0 .../res/layout/nd3_account_other_login.xml | 0 .../res/layout/nd3_account_register.xml | 0 .../layout/nd3_account_register_agreement.xml | 0 .../res/layout/nd3_account_register_phone.xml | 0 .../res/layout/nd3_account_register_quick.xml | 0 .../res/layout/nd3_account_secret_find.xml | 0 .../res/layout/nd3_account_secret_set.xml | 0 .../res/layout/nd3_account_sina.xml | 0 .../res/layout/nd3_achieve_detail.xml | 0 .../layout/nd3_activity_action_template.xml | 0 .../nd3_activity_content_reg_template_1.xml | 0 .../nd3_activity_content_reg_template_2.xml | 0 ...d3_activity_content_reg_template_2_ext.xml | 0 .../nd3_activity_content_reg_template_3.xml | 0 .../nd3_activity_content_reg_template_4.xml | 0 .../res/layout/nd3_activity_detail.xml | 0 .../layout/nd3_activity_detail_plus_image.xml | 0 .../layout/nd3_activity_detail_plus_list.xml | 0 .../nd3_activity_detail_plus_list_ext.xml | 0 .../res/layout/nd3_activity_head_reg.xml | 0 .../nd3_activity_no_action_template.xml | 0 .../res/layout/nd3_app_feedback.xml | 0 .../DependProject/res/layout/nd3_app_item.xml | 0 .../res/layout/nd3_app_property.xml | 0 .../res/layout/nd3_banner_layout.xml | 0 .../res/layout/nd3_blank_listview.xml | 0 .../res/layout/nd3_bottom_bar.xml | 0 .../res/layout/nd3_category_item.xml | 0 .../layout/nd3_category_plus_image_item.xml | 0 .../res/layout/nd3_control_center.xml | 0 .../res/layout/nd3_dispatch_search_friend.xml | 0 .../res/layout/nd3_empty_listview.xml | 0 .../DependProject/res/layout/nd3_frame.xml | 0 .../res/layout/nd3_friend_home.xml | 0 .../res/layout/nd3_friend_remark_setting.xml | 0 .../res/layout/nd3_friend_section.xml | 0 .../layout/nd3_friend_section_list_item.xml | 0 .../res/layout/nd3_friend_section_panel.xml | 0 .../res/layout/nd3_game_content.xml | 0 .../res/layout/nd3_game_main.xml | 0 .../DependProject/res/layout/nd3_home.xml | 0 .../res/layout/nd3_home_land.xml | 0 .../res/layout/nd3_home_personal.xml | 0 .../res/layout/nd3_home_portrait.xml | 0 .../res/layout/nd3_invite_friend.xml | 0 .../res/layout/nd3_invite_friend_choice.xml | 0 .../res/layout/nd3_invite_friend_item.xml | 0 .../res/layout/nd3_leaderboard_category.xml | 0 .../res/layout/nd3_leaderboard_list_item.xml | 0 .../res/layout/nd3_listview_footer.xml | 0 .../res/layout/nd3_listview_footer_ext.xml | 0 .../res/layout/nd3_listview_template.xml | 0 .../nd3_listview_template_no_divider.xml | 0 .../res/layout/nd3_mesg_main.xml | 0 .../layout/nd3_message_friendmsge_list.xml | 0 .../res/layout/nd3_message_main.xml | 0 .../res/layout/nd3_message_receive_item.xml | 0 .../res/layout/nd3_message_record_item.xml | 0 .../res/layout/nd3_message_send.xml | 0 .../res/layout/nd3_message_send_item.xml | 0 .../res/layout/nd3_more_about.xml | 0 .../res/layout/nd3_more_account.xml | 0 .../res/layout/nd3_more_bean_recharge.xml | 0 .../res/layout/nd3_more_consume_detail.xml | 0 .../res/layout/nd3_more_consumes.xml | 0 .../res/layout/nd3_more_info.xml | 0 .../layout/nd3_more_info_edit_head_dialog.xml | 0 .../res/layout/nd3_more_more.xml | 0 .../res/layout/nd3_more_no_password.xml | 0 .../res/layout/nd3_more_password.xml | 0 .../res/layout/nd3_more_permission.xml | 0 .../res/layout/nd3_more_recharge_detail.xml | 0 .../res/layout/nd3_more_recharges.xml | 0 .../res/layout/nd3_more_records.xml | 0 .../res/layout/nd3_more_records_item.xml | 0 .../DependProject/res/layout/nd3_myfriend.xml | 0 .../res/layout/nd3_network_error.xml | 0 .../res/layout/nd3_normal_search.xml | 0 .../res/layout/nd3_pay_friend_item.xml | 0 .../DependProject/res/layout/nd3_pay_pass.xml | 0 .../res/layout/nd3_pay_password_check.xml | 0 .../res/layout/nd3_pay_products_item.xml | 0 .../res/layout/nd3_pay_select_friend.xml | 0 .../res/layout/nd3_pay_template.xml | 0 .../res/layout/nd3_person_info_detail.xml | 0 .../res/layout/nd3_personinfo.xml | 0 .../res/layout/nd3_progressbar.xml | 0 .../res/layout/nd3_recharge_record.xml | 0 .../res/layout/nd3_searchfriend_condition.xml | 0 .../layout/nd3_share_bind_account_item.xml | 0 .../res/layout/nd3_share_sina.xml | 0 .../layout/nd3_share_unbind_account_item.xml | 0 .../res/layout/nd3_stranger_home.xml | 0 .../layout/nd3_sysmessage_detail_action.xml | 0 .../res/layout/nd3_sysmessage_detail_app.xml | 0 .../nd3_sysmessage_detail_no_action.xml | 0 .../res/layout/nd3_sysmessage_head_reg.xml | 0 .../res/layout/nd3_thirdplatform_item.xml | 0 .../res/layout/nd3_title_bar.xml | 0 .../res/layout/nd3_user_fangle.xml | 0 .../res/layout/nd3_user_fangle_ext.xml | 0 .../res/layout/nd3_user_item.xml | 0 .../res/layout/nd3_user_item_divider.xml | 0 .../res/layout/nd3_user_message.xml | 0 .../res/layout/nd3_user_message_switcher.xml | 0 .../res/layout/nd3_version_update.xml | 0 .../res/layout/nd3_write_message.xml | 0 .../res/layout/nd_account_list_item.xml | 0 .../res/layout/nd_account_manage.xml | 0 .../res/layout/nd_bind_phone_lottery.xml | 0 .../res/layout/nd_bind_phone_number.xml | 0 .../layout/nd_bind_phone_number_result.xml | 0 .../res/layout/nd_bind_phone_number_tip.xml | 0 .../nd_bind_phone_number_unactivity_tip.xml | 0 .../res/layout/nd_check_version.xml | 0 .../res/layout/nd_find_password.xml | 0 .../res/layout/nd_goods_detail.xml | 0 .../res/layout/nd_goods_list.xml | 0 .../res/layout/nd_goods_list_item.xml | 0 .../res/layout/nd_leaderboard.xml | 0 .../res/layout/nd_leaderboard_list_header.xml | 0 .../nd_leaderboard_switcher_landscape_1.xml | 0 .../nd_leaderboard_switcher_portrait_1.xml | 0 .../res/layout/nd_login_director.xml | 0 .../res/layout/nd_set_password.xml | 0 .../res/layout/nd_softpromotion_flipitem.xml | 0 .../res/layout/nd_softpromotion_listitem.xml | 0 .../res/layout/nd_softpromotion_slider_h.xml | 0 .../layout/nd_softpromotion_slider_item.xml | 0 .../res/layout/nd_softpromotion_slider_v.xml | 0 .../res/layout/nd_softwarepromotion.xml | 0 .../res/layout/nd_unbind_phone_number.xml | 0 .../DependProject/res/raw/nd_res.zip | Bin .../DependProject/res/values/nd3_misc.xml | 0 .../res/values/nd3_sdk_error_strings.xml | 0 .../DependProject/res/values/nd3_strings.xml | 0 .../DependProject/src/.gitignore | 0 .../plugins/nd91/proj.android/build_native.sh | 20 ----- .../plugins/nd91/proj.android/jni/Android.mk | 29 ------ .../nd91/proj.android/jni/Application.mk | 7 -- .../src/org/cocos2dx/plugin/IAPNd91.java | 35 ++++---- plugin/plugins/twitter/proj.android/.project | 12 --- plugin/plugins/weibo/proj.android/.project | 12 --- .../samples/HelloIAP/Classes/MyPurchase.cpp | 4 +- plugin/samples/HelloIAP/Classes/MyPurchase.h | 7 +- .../HelloIAP/proj.android/jni/Android.mk | 4 - plugin/tools/toolsForPublish/publishPlugin.sh | 4 +- 222 files changed, 42 insertions(+), 663 deletions(-) delete mode 100644 plugin/plugins/alipay/include/IAPAlipay.h delete mode 100644 plugin/plugins/alipay/jsb_alipay.ini delete mode 100644 plugin/plugins/alipay/platform/android/IAPAlipay.cpp delete mode 100755 plugin/plugins/alipay/proj.android/build_native.sh delete mode 100644 plugin/plugins/alipay/proj.android/jni/Android.mk delete mode 100644 plugin/plugins/alipay/proj.android/jni/Application.mk delete mode 100644 plugin/plugins/nd91/include/IAPNd91.h delete mode 100644 plugin/plugins/nd91/jsb_nd91.ini delete mode 100644 plugin/plugins/nd91/platform/android/DependProject/.settings/org.eclipse.jdt.core.prefs delete mode 100644 plugin/plugins/nd91/platform/android/IAPNd91.cpp rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/.classpath (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/.project (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/AndroidManifest.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/project.properties (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/anim/nd_flipin.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/anim/nd_flipin_reverse.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/anim/nd_flipout.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/anim/nd_flipout_reverse.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_background_xml.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_button.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_button_02.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_button_action.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_button_logout.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_button_old.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_button_x.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_checkbox_button.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_friend_del_button.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_image_48_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_input_gray.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_message_item_1_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_message_item_2_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_pay_checkbox_button.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_progress_large.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_rank_choice_left_btn_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_rank_choice_middle_btn_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_rank_choice_right_btn_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_regist_checked.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_round_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_square_checkbox_button.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_title_bar_action_btn_xml.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_title_bar_return_btn_xml.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd3_user_item_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_blue.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_button_action_add.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_button_action_buy.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_button_action_reduce.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_c_blur.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_download.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_green.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_leaderboard_left_btn_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_leaderboard_right_btn_bg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_list_btn_delete_selector.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_login_btn_land_selector.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_login_btn_portrait_selector.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_register_btn_portrait_selector.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_slider_handle_h.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_slider_handle_h_expand.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_slider_handle_v.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_slider_handle_v_expand.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/drawable/nd_white_btn.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_bind_bind.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_bind_register.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_email_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_login.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_login_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_login_land.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_login_other_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_login_portrait.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_oauth_bind.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_official.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_official_landscape.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_official_portrait.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_other_login.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_register.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_register_agreement.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_register_phone.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_register_quick.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_secret_find.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_secret_set.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_account_sina.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_achieve_detail.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_action_template.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_content_reg_template_1.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_content_reg_template_2.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_content_reg_template_2_ext.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_content_reg_template_3.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_content_reg_template_4.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_detail.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_detail_plus_image.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_detail_plus_list.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_detail_plus_list_ext.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_head_reg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_activity_no_action_template.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_app_feedback.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_app_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_app_property.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_banner_layout.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_blank_listview.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_bottom_bar.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_category_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_category_plus_image_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_control_center.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_dispatch_search_friend.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_empty_listview.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_frame.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_friend_home.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_friend_remark_setting.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_friend_section.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_friend_section_list_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_friend_section_panel.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_game_content.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_game_main.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_home.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_home_land.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_home_personal.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_home_portrait.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_invite_friend.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_invite_friend_choice.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_invite_friend_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_leaderboard_category.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_leaderboard_list_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_listview_footer.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_listview_footer_ext.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_listview_template.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_listview_template_no_divider.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_mesg_main.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_message_friendmsge_list.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_message_main.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_message_receive_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_message_record_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_message_send.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_message_send_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_about.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_account.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_bean_recharge.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_consume_detail.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_consumes.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_info.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_info_edit_head_dialog.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_more.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_no_password.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_password.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_permission.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_recharge_detail.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_recharges.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_records.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_more_records_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_myfriend.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_network_error.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_normal_search.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_pay_friend_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_pay_pass.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_pay_password_check.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_pay_products_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_pay_select_friend.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_pay_template.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_person_info_detail.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_personinfo.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_progressbar.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_recharge_record.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_searchfriend_condition.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_share_bind_account_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_share_sina.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_share_unbind_account_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_stranger_home.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_sysmessage_detail_action.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_sysmessage_detail_app.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_sysmessage_detail_no_action.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_sysmessage_head_reg.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_thirdplatform_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_title_bar.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_user_fangle.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_user_fangle_ext.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_user_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_user_item_divider.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_user_message.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_user_message_switcher.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_version_update.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd3_write_message.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_account_list_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_account_manage.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_bind_phone_lottery.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_bind_phone_number.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_bind_phone_number_result.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_bind_phone_number_tip.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_bind_phone_number_unactivity_tip.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_check_version.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_find_password.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_goods_detail.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_goods_list.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_goods_list_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_leaderboard.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_leaderboard_list_header.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_leaderboard_switcher_landscape_1.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_leaderboard_switcher_portrait_1.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_login_director.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_set_password.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_softpromotion_flipitem.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_softpromotion_listitem.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_softpromotion_slider_h.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_softpromotion_slider_item.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_softpromotion_slider_v.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_softwarepromotion.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/layout/nd_unbind_phone_number.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/raw/nd_res.zip (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/values/nd3_misc.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/values/nd3_sdk_error_strings.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/res/values/nd3_strings.xml (100%) rename plugin/plugins/nd91/{platform/android => proj.android}/DependProject/src/.gitignore (100%) delete mode 100755 plugin/plugins/nd91/proj.android/build_native.sh delete mode 100644 plugin/plugins/nd91/proj.android/jni/Android.mk delete mode 100644 plugin/plugins/nd91/proj.android/jni/Application.mk diff --git a/plugin/plugins/alipay/include/IAPAlipay.h b/plugin/plugins/alipay/include/IAPAlipay.h deleted file mode 100644 index 0085e19ab3..0000000000 --- a/plugin/plugins/alipay/include/IAPAlipay.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_IAP_ALIPAY_H__ -#define __CCX_IAP_ALIPAY_H__ - -#include "ProtocolIAP.h" -#include -#include - -namespace cocos2d { namespace plugin { - -class IAPAlipay : public ProtocolIAP -{ - PLUGIN_REGISTER_DECL(IAPAlipay) -public: - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief config the developer info - @param devInfo This parameter is the info of developer, must contains key: - AlipayPartner The partner id of alipay account - AlipaySeller The seller id of alipay account - AlipayRsaPrivate The RSA private key of alipay account - AlipayPublic The public key of alipay account - AlipayNotifyUrl The notify url of developer (must not be empty) - AlipayPluginName The apk file name of Alipay (must not be empty) - @warning Must invoke this interface before other interfaces. - And invoked only once. - */ - virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo); - - /** - @brief pay for product - @param info The info of product, must contains key: - productName The name of product - productPrice The price of product(must can be parse to float) - productDesc The description of product - @warning For different plugin, the parameter should have other keys to pay. - Look at the manual of plugins. - */ - virtual void payForProduct(TProductInfo info); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - virtual ~IAPAlipay(); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_IAP_ALIPAY_H__ */ diff --git a/plugin/plugins/alipay/jsb_alipay.ini b/plugin/plugins/alipay/jsb_alipay.ini deleted file mode 100644 index 5265191fce..0000000000 --- a/plugin/plugins/alipay/jsb_alipay.ini +++ /dev/null @@ -1,60 +0,0 @@ -[alipay] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_alipay - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/alipay/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/alipay/include/IAPAlipay.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = IAPAlipay - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = IAPAlipay - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes - diff --git a/plugin/plugins/alipay/platform/android/IAPAlipay.cpp b/plugin/plugins/alipay/platform/android/IAPAlipay.cpp deleted file mode 100644 index 21657963e6..0000000000 --- a/plugin/plugins/alipay/platform/android/IAPAlipay.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "IAPAlipay.h" -#include "PluginUtils.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(IAPAlipay) - -IAPAlipay::~IAPAlipay() -{ -} - -/** -@brief plugin initialization -*/ -bool IAPAlipay::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.IAPAlipay"); -} - -/** -@brief config the developer info -@param devInfo This parameter is the info of developer, must contains key: - AlipayPartner The partner id of alipay account - AlipaySeller The seller id of alipay account - AlipayRsaPrivate The RSA private key of alipay account - AlipayPublic The public key of alipay account - AlipayNotifyUrl The notify url of developer (must not be empty) - AlipayPluginName The apk file name of Alipay (must not be empty) -@warning Must invoke this interface before other interfaces. - And invoked only once. -*/ -void IAPAlipay::configDeveloperInfo(TIAPDeveloperInfo devInfo) -{ - ProtocolIAP::configDeveloperInfo(devInfo); -} - -/** -@brief pay for product -@param info The info of product, must contains key: - productName The name of product - productPrice The price of product(must can be parse to float) - productDesc The description of product -@warning For different plugin, the parameter should have other keys to pay. - Look at the manual of plugins. -*/ -void IAPAlipay::payForProduct(TProductInfo info) -{ - ProtocolIAP::payForProduct(info); -} - -const char* IAPAlipay::getSDKVersion() -{ - return ProtocolIAP::getSDKVersion(); -} - -void IAPAlipay::setDebugMode(bool debug) -{ - ProtocolIAP::setDebugMode(debug); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/alipay/proj.android/.project b/plugin/plugins/alipay/proj.android/.project index c7bf0cc435..93e01793c8 100644 --- a/plugin/plugins/alipay/proj.android/.project +++ b/plugin/plugins/alipay/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/plugins/alipay/proj.android/build_native.sh b/plugin/plugins/alipay/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/alipay/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/alipay/proj.android/jni/Android.mk b/plugin/plugins/alipay/proj.android/jni/Android.mk deleted file mode 100644 index 20c61b7bc8..0000000000 --- a/plugin/plugins/alipay/proj.android/jni/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginAlipayStatic - -LOCAL_MODULE_FILENAME := libPluginAlipayStatic - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - IAPAlipay.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) diff --git a/plugin/plugins/alipay/proj.android/jni/Application.mk b/plugin/plugins/alipay/proj.android/jni/Application.mk deleted file mode 100644 index bc7141a7ec..0000000000 --- a/plugin/plugins/alipay/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginAlipayStatic -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java b/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java index 4d0dcade3d..3c799b7d03 100644 --- a/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java +++ b/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java @@ -28,8 +28,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Hashtable; -import org.cocos2dx.plugin.InterfaceIAP.IAPAdapter; - import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; @@ -41,7 +39,7 @@ import android.os.Message; import android.util.Log; import android.view.KeyEvent; -public class IAPAlipay implements IAPAdapter { +public class IAPAlipay implements InterfaceIAP { private static final String LOG_TAG = "IAPAlipay"; private static Activity mContext = null; @@ -97,7 +95,7 @@ public class IAPAlipay implements IAPAdapter { public void payForProduct(Hashtable info) { LogD("payForProduct invoked " + info.toString()); if (! networkReachable()) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "网络不可用"); + payResult(IAPWrapper.PAYRESULT_FAIL, "网络不可用"); return; } @@ -108,7 +106,7 @@ public class IAPAlipay implements IAPAdapter { MobileSecurePayHelper mspHelper = new MobileSecurePayHelper(mContext); boolean bInstalled = mspHelper.detectMobile_sp(); if (! bInstalled) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "未安装支付宝插件"); + payResult(IAPWrapper.PAYRESULT_FAIL, "未安装支付宝插件"); return; } @@ -138,12 +136,12 @@ public class IAPAlipay implements IAPAdapter { closeProgress(); mProgress = BaseHelper.showProgress(mContext, null, "正在支付", false, true); } else { - payResult(InterfaceIAP.PAYRESULT_FAIL, "支付失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "支付失败"); return; } } catch (Exception ex) { LogE("Remote call failed", ex); - payResult(InterfaceIAP.PAYRESULT_FAIL, "remote call failed"); + payResult(IAPWrapper.PAYRESULT_FAIL, "remote call failed"); return; } } @@ -200,21 +198,21 @@ public class IAPAlipay implements IAPAdapter { int retVal = resultChecker.checkSign(); // 返回验签结果以及交易状态 if (retVal == ResultChecker.RESULT_CHECK_SIGN_FAILED) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "签名验证失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "签名验证失败"); } else if (retVal == ResultChecker.RESULT_CHECK_SIGN_SUCCEED && resultChecker.isPayOk()) { - payResult(InterfaceIAP.PAYRESULT_SUCCESS, "支付成功"); + payResult(IAPWrapper.PAYRESULT_SUCCESS, "支付成功"); } else { - payResult(InterfaceIAP.PAYRESULT_FAIL, "支付失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "支付失败"); } } catch (Exception e) { e.printStackTrace(); - payResult(InterfaceIAP.PAYRESULT_FAIL, "结果解析失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "结果解析失败"); } } break; default: mAdapter.closeProgress(); - payResult(InterfaceIAP.PAYRESULT_FAIL, "支付失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "支付失败"); break; } @@ -335,7 +333,12 @@ public class IAPAlipay implements IAPAdapter { } private static void payResult(int ret, String msg) { - InterfaceIAP.onPayResult(mAdapter, ret, msg); + IAPWrapper.onPayResult(mAdapter, ret, msg); LogD("Alipay result : " + ret + " msg : " + msg); } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/plugins/nd91/include/IAPNd91.h b/plugin/plugins/nd91/include/IAPNd91.h deleted file mode 100644 index 2b81a65124..0000000000 --- a/plugin/plugins/nd91/include/IAPNd91.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_IAP_ND91_H__ -#define __CCX_IAP_ND91_H__ - -#include "ProtocolIAP.h" -#include -#include - -namespace cocos2d { namespace plugin { - -class IAPNd91 : public ProtocolIAP -{ - PLUGIN_REGISTER_DECL(IAPNd91) -public: - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief config the developer info - @param devInfo This parameter is the info of developer, must contains key: - Nd91AppId The app id of nd91 - Nd91AppKey The app key of nd91 - Nd91Orientation The orientation of your app(use value : portrait, landscape, auto) - default value is portrait - @warning Must invoke this interface before other interfaces. - And invoked only once. - */ - virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo); - - /** - @brief pay for product - @param info The info of product, must contains key: - productName The name of product - productPrice The price of product(must can be parse to float) - productDesc The description of product - Nd91ProductId The product id of product for nd91 - Nd91ProductCount The product number will buy(1--10000, default value 1) - Nd91OriginalPrice The original price of product(default value is same with productPrice) - @warning For different plugin, the parameter should have other keys to pay. - Look at the manual of plugins. - */ - virtual void payForProduct(TProductInfo info); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - virtual ~IAPNd91(); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_IAP_ND91_H__ */ diff --git a/plugin/plugins/nd91/jsb_nd91.ini b/plugin/plugins/nd91/jsb_nd91.ini deleted file mode 100644 index 0949203dab..0000000000 --- a/plugin/plugins/nd91/jsb_nd91.ini +++ /dev/null @@ -1,59 +0,0 @@ -[nd91] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_nd91 - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/nd91/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/nd91/include/IAPNd91.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = IAPNd91 - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = IAPNd91 - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes diff --git a/plugin/plugins/nd91/platform/android/DependProject/.settings/org.eclipse.jdt.core.prefs b/plugin/plugins/nd91/platform/android/DependProject/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 8000cd6ca6..0000000000 --- a/plugin/plugins/nd91/platform/android/DependProject/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/plugin/plugins/nd91/platform/android/IAPNd91.cpp b/plugin/plugins/nd91/platform/android/IAPNd91.cpp deleted file mode 100644 index 664a03e9ba..0000000000 --- a/plugin/plugins/nd91/platform/android/IAPNd91.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "IAPNd91.h" -#include "PluginUtils.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(IAPNd91) - -IAPNd91::~IAPNd91() -{ -} - -/** -@brief plugin initialization -*/ -bool IAPNd91::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.IAPNd91"); -} - -/** -@brief config the developer info -@param devInfo This parameter is the info of developer, must contains key: - Nd91AppId The app id of nd91 - Nd91AppKey The app key of nd91 - Nd91Orientation The orientation of your app(use value : portrait, landscape, auto) - default value is portrait -@warning Must invoke this interface before other interfaces. - And invoked only once. -*/ -void IAPNd91::configDeveloperInfo(TIAPDeveloperInfo devInfo) -{ - ProtocolIAP::configDeveloperInfo(devInfo); -} - -/** -@brief pay for product -@param info The info of product, must contains key: - productName The name of product - productPrice The price of product(must can be parse to float) - productDesc The description of product - Nd91ProductId The product id of product for nd91 - Nd91ProductCount The product number will buy(1--10000) - Nd91OriginalPrice The original price of product -@warning For different plugin, the parameter should have other keys to pay. - Look at the manual of plugins. -*/ -void IAPNd91::payForProduct(TProductInfo info) -{ - ProtocolIAP::payForProduct(info); -} - -const char* IAPNd91::getSDKVersion() -{ - return ProtocolIAP::getSDKVersion(); -} - -void IAPNd91::setDebugMode(bool debug) -{ - ProtocolIAP::setDebugMode(debug); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/nd91/proj.android/.project b/plugin/plugins/nd91/proj.android/.project index 89ad77c006..af04421e09 100644 --- a/plugin/plugins/nd91/proj.android/.project +++ b/plugin/plugins/nd91/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/plugins/nd91/platform/android/DependProject/.classpath b/plugin/plugins/nd91/proj.android/DependProject/.classpath similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/.classpath rename to plugin/plugins/nd91/proj.android/DependProject/.classpath diff --git a/plugin/plugins/nd91/platform/android/DependProject/.project b/plugin/plugins/nd91/proj.android/DependProject/.project similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/.project rename to plugin/plugins/nd91/proj.android/DependProject/.project diff --git a/plugin/plugins/nd91/platform/android/DependProject/AndroidManifest.xml b/plugin/plugins/nd91/proj.android/DependProject/AndroidManifest.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/AndroidManifest.xml rename to plugin/plugins/nd91/proj.android/DependProject/AndroidManifest.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/project.properties b/plugin/plugins/nd91/proj.android/DependProject/project.properties similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/project.properties rename to plugin/plugins/nd91/proj.android/DependProject/project.properties diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipin.xml b/plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipin.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipin.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipin.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipin_reverse.xml b/plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipin_reverse.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipin_reverse.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipin_reverse.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipout.xml b/plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipout.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipout.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipout.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipout_reverse.xml b/plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipout_reverse.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/anim/nd_flipout_reverse.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/anim/nd_flipout_reverse.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_background_xml.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_background_xml.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_background_xml.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_background_xml.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_02.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_02.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_02.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_02.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_action.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_action.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_action.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_action.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_logout.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_logout.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_logout.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_logout.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_old.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_old.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_old.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_old.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_x.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_x.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_button_x.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_button_x.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_checkbox_button.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_checkbox_button.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_checkbox_button.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_checkbox_button.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_friend_del_button.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_friend_del_button.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_friend_del_button.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_friend_del_button.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_image_48_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_image_48_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_image_48_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_image_48_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_input_gray.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_input_gray.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_input_gray.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_input_gray.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_message_item_1_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_message_item_1_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_message_item_1_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_message_item_1_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_message_item_2_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_message_item_2_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_message_item_2_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_message_item_2_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_pay_checkbox_button.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_pay_checkbox_button.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_pay_checkbox_button.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_pay_checkbox_button.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_progress_large.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_progress_large.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_progress_large.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_progress_large.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_rank_choice_left_btn_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_rank_choice_left_btn_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_rank_choice_left_btn_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_rank_choice_left_btn_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_rank_choice_middle_btn_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_rank_choice_middle_btn_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_rank_choice_middle_btn_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_rank_choice_middle_btn_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_rank_choice_right_btn_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_rank_choice_right_btn_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_rank_choice_right_btn_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_rank_choice_right_btn_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_regist_checked.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_regist_checked.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_regist_checked.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_regist_checked.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_round_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_round_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_round_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_round_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_square_checkbox_button.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_square_checkbox_button.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_square_checkbox_button.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_square_checkbox_button.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_title_bar_action_btn_xml.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_title_bar_action_btn_xml.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_title_bar_action_btn_xml.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_title_bar_action_btn_xml.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_title_bar_return_btn_xml.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_title_bar_return_btn_xml.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_title_bar_return_btn_xml.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_title_bar_return_btn_xml.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_user_item_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_user_item_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd3_user_item_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd3_user_item_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_blue.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_blue.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_blue.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_blue.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_button_action_add.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_button_action_add.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_button_action_add.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_button_action_add.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_button_action_buy.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_button_action_buy.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_button_action_buy.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_button_action_buy.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_button_action_reduce.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_button_action_reduce.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_button_action_reduce.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_button_action_reduce.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_c_blur.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_c_blur.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_c_blur.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_c_blur.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_download.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_download.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_download.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_download.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_green.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_green.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_green.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_green.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_leaderboard_left_btn_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_leaderboard_left_btn_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_leaderboard_left_btn_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_leaderboard_left_btn_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_leaderboard_right_btn_bg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_leaderboard_right_btn_bg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_leaderboard_right_btn_bg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_leaderboard_right_btn_bg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_list_btn_delete_selector.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_list_btn_delete_selector.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_list_btn_delete_selector.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_list_btn_delete_selector.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_login_btn_land_selector.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_login_btn_land_selector.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_login_btn_land_selector.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_login_btn_land_selector.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_login_btn_portrait_selector.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_login_btn_portrait_selector.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_login_btn_portrait_selector.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_login_btn_portrait_selector.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_register_btn_portrait_selector.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_register_btn_portrait_selector.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_register_btn_portrait_selector.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_register_btn_portrait_selector.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_h.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_h.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_h.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_h.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_h_expand.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_h_expand.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_h_expand.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_h_expand.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_v.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_v.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_v.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_v.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_v_expand.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_v_expand.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_slider_handle_v_expand.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_slider_handle_v_expand.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_white_btn.xml b/plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_white_btn.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/drawable/nd_white_btn.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/drawable/nd_white_btn.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_bind_bind.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_bind_bind.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_bind_bind.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_bind_bind.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_bind_register.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_bind_register.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_bind_register.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_bind_register.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_email_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_email_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_email_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_email_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_land.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_land.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_land.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_land.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_other_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_other_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_other_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_other_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_portrait.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_portrait.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_login_portrait.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_login_portrait.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_oauth_bind.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_oauth_bind.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_oauth_bind.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_oauth_bind.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_official.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_official.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_official.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_official.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_official_landscape.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_official_landscape.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_official_landscape.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_official_landscape.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_official_portrait.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_official_portrait.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_official_portrait.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_official_portrait.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_other_login.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_other_login.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_other_login.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_other_login.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register_agreement.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register_agreement.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register_agreement.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register_agreement.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register_phone.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register_phone.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register_phone.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register_phone.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register_quick.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register_quick.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_register_quick.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_register_quick.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_secret_find.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_secret_find.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_secret_find.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_secret_find.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_secret_set.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_secret_set.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_secret_set.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_secret_set.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_sina.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_sina.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_account_sina.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_account_sina.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_achieve_detail.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_achieve_detail.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_achieve_detail.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_achieve_detail.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_action_template.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_action_template.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_action_template.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_action_template.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_1.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_1.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_1.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_1.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_2.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_2.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_2.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_2.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_2_ext.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_2_ext.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_2_ext.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_2_ext.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_3.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_3.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_3.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_3.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_4.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_4.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_content_reg_template_4.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_content_reg_template_4.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail_plus_image.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail_plus_image.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail_plus_image.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail_plus_image.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail_plus_list.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail_plus_list.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail_plus_list.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail_plus_list.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail_plus_list_ext.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail_plus_list_ext.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_detail_plus_list_ext.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_detail_plus_list_ext.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_head_reg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_head_reg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_head_reg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_head_reg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_no_action_template.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_no_action_template.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_activity_no_action_template.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_activity_no_action_template.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_app_feedback.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_app_feedback.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_app_feedback.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_app_feedback.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_app_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_app_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_app_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_app_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_app_property.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_app_property.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_app_property.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_app_property.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_banner_layout.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_banner_layout.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_banner_layout.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_banner_layout.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_blank_listview.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_blank_listview.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_blank_listview.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_blank_listview.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_bottom_bar.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_bottom_bar.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_bottom_bar.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_bottom_bar.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_category_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_category_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_category_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_category_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_category_plus_image_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_category_plus_image_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_category_plus_image_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_category_plus_image_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_control_center.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_control_center.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_control_center.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_control_center.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_dispatch_search_friend.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_dispatch_search_friend.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_dispatch_search_friend.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_dispatch_search_friend.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_empty_listview.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_empty_listview.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_empty_listview.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_empty_listview.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_frame.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_frame.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_frame.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_frame.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_home.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_home.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_home.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_home.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_remark_setting.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_remark_setting.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_remark_setting.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_remark_setting.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_section.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_section.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_section.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_section.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_section_list_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_section_list_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_section_list_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_section_list_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_section_panel.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_section_panel.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_friend_section_panel.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_friend_section_panel.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_game_content.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_game_content.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_game_content.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_game_content.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_game_main.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_game_main.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_game_main.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_game_main.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home_land.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home_land.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home_land.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home_land.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home_personal.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home_personal.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home_personal.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home_personal.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home_portrait.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home_portrait.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_home_portrait.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_home_portrait.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_invite_friend.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_invite_friend.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_invite_friend.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_invite_friend.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_invite_friend_choice.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_invite_friend_choice.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_invite_friend_choice.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_invite_friend_choice.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_invite_friend_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_invite_friend_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_invite_friend_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_invite_friend_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_leaderboard_category.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_leaderboard_category.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_leaderboard_category.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_leaderboard_category.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_leaderboard_list_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_leaderboard_list_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_leaderboard_list_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_leaderboard_list_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_footer.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_footer.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_footer.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_footer.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_footer_ext.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_footer_ext.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_footer_ext.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_footer_ext.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_template.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_template.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_template.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_template.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_template_no_divider.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_template_no_divider.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_listview_template_no_divider.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_listview_template_no_divider.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_mesg_main.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_mesg_main.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_mesg_main.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_mesg_main.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_friendmsge_list.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_friendmsge_list.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_friendmsge_list.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_friendmsge_list.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_main.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_main.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_main.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_main.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_receive_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_receive_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_receive_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_receive_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_record_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_record_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_record_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_record_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_send.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_send.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_send.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_send.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_send_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_send_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_message_send_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_message_send_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_about.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_about.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_about.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_about.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_account.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_account.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_account.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_account.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_bean_recharge.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_bean_recharge.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_bean_recharge.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_bean_recharge.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_consume_detail.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_consume_detail.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_consume_detail.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_consume_detail.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_consumes.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_consumes.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_consumes.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_consumes.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_info.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_info.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_info.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_info.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_info_edit_head_dialog.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_info_edit_head_dialog.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_info_edit_head_dialog.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_info_edit_head_dialog.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_more.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_more.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_more.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_more.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_no_password.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_no_password.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_no_password.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_no_password.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_password.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_password.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_password.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_password.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_permission.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_permission.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_permission.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_permission.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_recharge_detail.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_recharge_detail.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_recharge_detail.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_recharge_detail.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_recharges.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_recharges.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_recharges.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_recharges.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_records.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_records.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_records.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_records.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_records_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_records_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_more_records_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_more_records_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_myfriend.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_myfriend.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_myfriend.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_myfriend.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_network_error.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_network_error.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_network_error.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_network_error.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_normal_search.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_normal_search.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_normal_search.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_normal_search.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_friend_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_friend_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_friend_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_friend_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_pass.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_pass.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_pass.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_pass.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_password_check.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_password_check.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_password_check.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_password_check.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_products_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_products_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_products_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_products_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_select_friend.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_select_friend.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_select_friend.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_select_friend.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_template.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_template.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_pay_template.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_pay_template.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_person_info_detail.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_person_info_detail.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_person_info_detail.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_person_info_detail.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_personinfo.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_personinfo.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_personinfo.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_personinfo.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_progressbar.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_progressbar.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_progressbar.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_progressbar.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_recharge_record.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_recharge_record.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_recharge_record.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_recharge_record.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_searchfriend_condition.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_searchfriend_condition.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_searchfriend_condition.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_searchfriend_condition.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_share_bind_account_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_share_bind_account_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_share_bind_account_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_share_bind_account_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_share_sina.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_share_sina.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_share_sina.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_share_sina.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_share_unbind_account_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_share_unbind_account_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_share_unbind_account_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_share_unbind_account_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_stranger_home.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_stranger_home.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_stranger_home.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_stranger_home.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_detail_action.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_detail_action.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_detail_action.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_detail_action.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_detail_app.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_detail_app.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_detail_app.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_detail_app.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_detail_no_action.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_detail_no_action.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_detail_no_action.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_detail_no_action.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_head_reg.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_head_reg.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_sysmessage_head_reg.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_sysmessage_head_reg.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_thirdplatform_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_thirdplatform_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_thirdplatform_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_thirdplatform_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_title_bar.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_title_bar.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_title_bar.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_title_bar.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_fangle.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_fangle.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_fangle.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_fangle.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_fangle_ext.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_fangle_ext.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_fangle_ext.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_fangle_ext.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_item_divider.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_item_divider.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_item_divider.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_item_divider.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_message.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_message.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_message.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_message.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_message_switcher.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_message_switcher.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_user_message_switcher.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_user_message_switcher.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_version_update.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_version_update.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_version_update.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_version_update.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_write_message.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_write_message.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd3_write_message.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd3_write_message.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_account_list_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_account_list_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_account_list_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_account_list_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_account_manage.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_account_manage.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_account_manage.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_account_manage.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_lottery.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_lottery.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_lottery.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_lottery.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number_result.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number_result.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number_result.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number_result.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number_tip.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number_tip.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number_tip.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number_tip.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number_unactivity_tip.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number_unactivity_tip.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_bind_phone_number_unactivity_tip.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_bind_phone_number_unactivity_tip.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_check_version.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_check_version.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_check_version.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_check_version.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_find_password.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_find_password.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_find_password.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_find_password.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_goods_detail.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_goods_detail.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_goods_detail.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_goods_detail.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_goods_list.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_goods_list.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_goods_list.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_goods_list.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_goods_list_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_goods_list_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_goods_list_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_goods_list_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard_list_header.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard_list_header.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard_list_header.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard_list_header.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard_switcher_landscape_1.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard_switcher_landscape_1.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard_switcher_landscape_1.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard_switcher_landscape_1.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard_switcher_portrait_1.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard_switcher_portrait_1.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_leaderboard_switcher_portrait_1.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_leaderboard_switcher_portrait_1.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_login_director.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_login_director.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_login_director.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_login_director.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_set_password.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_set_password.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_set_password.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_set_password.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_flipitem.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_flipitem.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_flipitem.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_flipitem.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_listitem.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_listitem.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_listitem.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_listitem.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_slider_h.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_slider_h.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_slider_h.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_slider_h.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_slider_item.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_slider_item.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_slider_item.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_slider_item.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_slider_v.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_slider_v.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softpromotion_slider_v.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softpromotion_slider_v.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softwarepromotion.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softwarepromotion.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_softwarepromotion.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_softwarepromotion.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_unbind_phone_number.xml b/plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_unbind_phone_number.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/layout/nd_unbind_phone_number.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/layout/nd_unbind_phone_number.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/raw/nd_res.zip b/plugin/plugins/nd91/proj.android/DependProject/res/raw/nd_res.zip similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/raw/nd_res.zip rename to plugin/plugins/nd91/proj.android/DependProject/res/raw/nd_res.zip diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/values/nd3_misc.xml b/plugin/plugins/nd91/proj.android/DependProject/res/values/nd3_misc.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/values/nd3_misc.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/values/nd3_misc.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/values/nd3_sdk_error_strings.xml b/plugin/plugins/nd91/proj.android/DependProject/res/values/nd3_sdk_error_strings.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/values/nd3_sdk_error_strings.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/values/nd3_sdk_error_strings.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/res/values/nd3_strings.xml b/plugin/plugins/nd91/proj.android/DependProject/res/values/nd3_strings.xml similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/res/values/nd3_strings.xml rename to plugin/plugins/nd91/proj.android/DependProject/res/values/nd3_strings.xml diff --git a/plugin/plugins/nd91/platform/android/DependProject/src/.gitignore b/plugin/plugins/nd91/proj.android/DependProject/src/.gitignore similarity index 100% rename from plugin/plugins/nd91/platform/android/DependProject/src/.gitignore rename to plugin/plugins/nd91/proj.android/DependProject/src/.gitignore diff --git a/plugin/plugins/nd91/proj.android/build_native.sh b/plugin/plugins/nd91/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/nd91/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/nd91/proj.android/jni/Android.mk b/plugin/plugins/nd91/proj.android/jni/Android.mk deleted file mode 100644 index 5f3d3ffcff..0000000000 --- a/plugin/plugins/nd91/proj.android/jni/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginNd91Static - -LOCAL_MODULE_FILENAME := libPluginNd91Static - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - IAPNd91.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) diff --git a/plugin/plugins/nd91/proj.android/jni/Application.mk b/plugin/plugins/nd91/proj.android/jni/Application.mk deleted file mode 100644 index c99caa634c..0000000000 --- a/plugin/plugins/nd91/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginNd91Static -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java index 80e9ff5c5f..c60c1e4348 100644 --- a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java +++ b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java @@ -26,8 +26,6 @@ package org.cocos2dx.plugin; import java.util.Hashtable; import java.util.UUID; -import org.cocos2dx.plugin.InterfaceIAP.IAPAdapter; - import com.nd.commplatform.NdCommplatform; import com.nd.commplatform.NdErrorCode; import com.nd.commplatform.NdMiscCallbackListener; @@ -40,7 +38,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; -public class IAPNd91 implements IAPAdapter { +public class IAPNd91 implements InterfaceIAP { private static final String LOG_TAG = "IAPNd91"; private static Activity mContext = null; @@ -104,13 +102,13 @@ public class IAPNd91 implements IAPAdapter { public void payForProduct(Hashtable info) { LogD("payForProduct invoked " + info.toString()); if (! networkReachable()) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "网络不可用"); + payResult(IAPWrapper.PAYRESULT_FAIL, "网络不可用"); return; } curProductInfo = info; if (curProductInfo == null) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "商品信息错误"); + payResult(IAPWrapper.PAYRESULT_FAIL, "商品信息错误"); return; } @@ -150,7 +148,7 @@ public class IAPNd91 implements IAPAdapter { } private static void payResult(int ret, String msg) { - InterfaceIAP.onPayResult(mNd91, ret, msg); + IAPWrapper.onPayResult(mNd91, ret, msg); LogD("Nd91 result : " + ret + " msg : " + msg); } @@ -176,14 +174,14 @@ public class IAPNd91 implements IAPAdapter { if (code == NdErrorCode.ND_COM_PLATFORM_SUCCESS) { addPayment(curProductInfo); } else if (code == NdErrorCode.ND_COM_PLATFORM_ERROR_CANCEL) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "用户取消登录"); + payResult(IAPWrapper.PAYRESULT_FAIL, "用户取消登录"); } else { - payResult(InterfaceIAP.PAYRESULT_FAIL, "用户登录失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "用户登录失败"); } } }); } catch (Exception e) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "用户登录失败"); + payResult(IAPWrapper.PAYRESULT_FAIL, "用户登录失败"); LogE("User login error", e); } } @@ -199,7 +197,7 @@ public class IAPNd91 implements IAPAdapter { String strCount = productInfo.get("Nd91ProductCount"); if (id == null || id.length() == 0) { - payResult(InterfaceIAP.PAYRESULT_FAIL, "商品信息错误"); + payResult(IAPWrapper.PAYRESULT_FAIL, "商品信息错误"); break; } @@ -230,24 +228,29 @@ public class IAPNd91 implements IAPAdapter { IAPNd91.LogD("finishPayProcess code : " + code); switch(code){ case NdErrorCode.ND_COM_PLATFORM_SUCCESS: - IAPNd91.payResult(InterfaceIAP.PAYRESULT_SUCCESS, "购买成功"); break; + IAPNd91.payResult(IAPWrapper.PAYRESULT_SUCCESS, "购买成功"); break; case NdErrorCode.ND_COM_PLATFORM_ERROR_PAY_FAILURE: - IAPNd91.payResult(InterfaceIAP.PAYRESULT_FAIL, "购买失败"); break; + IAPNd91.payResult(IAPWrapper.PAYRESULT_FAIL, "购买失败"); break; case NdErrorCode.ND_COM_PLATFORM_ERROR_PAY_CANCEL: - IAPNd91.payResult(InterfaceIAP.PAYRESULT_CANCEL, "取消购买"); break; + IAPNd91.payResult(IAPWrapper.PAYRESULT_CANCEL, "取消购买"); break; default: - IAPNd91.payResult(InterfaceIAP.PAYRESULT_FAIL, "购买失败"); break; + IAPNd91.payResult(IAPWrapper.PAYRESULT_FAIL, "购买失败"); break; } } }); if (aError != 0) { - IAPNd91.payResult(InterfaceIAP.PAYRESULT_FAIL, "您输入参数有错,无法提交购买请求"); + IAPNd91.payResult(IAPWrapper.PAYRESULT_FAIL, "您输入参数有错,无法提交购买请求"); } } while (false); } catch (Exception e) { LogE("Error during payment", e); - IAPNd91.payResult(InterfaceIAP.PAYRESULT_FAIL, "支付失败"); + IAPNd91.payResult(IAPWrapper.PAYRESULT_FAIL, "支付失败"); } } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/plugins/twitter/proj.android/.project b/plugin/plugins/twitter/proj.android/.project index 9aade58531..a46974059c 100755 --- a/plugin/plugins/twitter/proj.android/.project +++ b/plugin/plugins/twitter/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/plugins/weibo/proj.android/.project b/plugin/plugins/weibo/proj.android/.project index 345896bff7..960d21be03 100755 --- a/plugin/plugins/weibo/proj.android/.project +++ b/plugin/plugins/weibo/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/samples/HelloIAP/Classes/MyPurchase.cpp b/plugin/samples/HelloIAP/Classes/MyPurchase.cpp index 213909a207..49b7ac858d 100644 --- a/plugin/samples/HelloIAP/Classes/MyPurchase.cpp +++ b/plugin/samples/HelloIAP/Classes/MyPurchase.cpp @@ -75,7 +75,7 @@ void MyPurchase::loadIAPPlugin() { // init alipay plugin - s_pAlipay = dynamic_cast(PluginManager::getInstance()->loadPlugin("IAPAlipay")); + s_pAlipay = dynamic_cast(PluginManager::getInstance()->loadPlugin("IAPAlipay")); TIAPDeveloperInfo pAlipayInfo; if (pAlipayInfo.empty()) { @@ -98,7 +98,7 @@ void MyPurchase::loadIAPPlugin() sprintf(msg, "Developer info is empty. PLZ fill your Nd91 info in %s(nearby line %d)", __FILE__, __LINE__); CCMessageBox(msg, "Nd91 Warning"); } - s_pNd91 = dynamic_cast(PluginManager::getInstance()->loadPlugin("IAPNd91")); + s_pNd91 = dynamic_cast(PluginManager::getInstance()->loadPlugin("IAPNd91")); s_pNd91->setDebugMode(true); s_pNd91->configDeveloperInfo(pNdInfo); s_pNd91->setResultListener(s_pRetListener); diff --git a/plugin/samples/HelloIAP/Classes/MyPurchase.h b/plugin/samples/HelloIAP/Classes/MyPurchase.h index df863f009c..a5d2048864 100644 --- a/plugin/samples/HelloIAP/Classes/MyPurchase.h +++ b/plugin/samples/HelloIAP/Classes/MyPurchase.h @@ -24,8 +24,7 @@ THE SOFTWARE. #ifndef __MY_PURCHASE_H__ #define __MY_PURCHASE_H__ -#include "IAPAlipay.h" -#include "IAPNd91.h" +#include "ProtocolIAP.h" class MyPurchaseResult : public cocos2d::plugin::PayResultListener { @@ -55,8 +54,8 @@ private: static MyPurchase* s_pPurchase; - cocos2d::plugin::IAPAlipay* s_pAlipay; - cocos2d::plugin::IAPNd91* s_pNd91; + cocos2d::plugin::ProtocolIAP* s_pAlipay; + cocos2d::plugin::ProtocolIAP* s_pNd91; MyPurchaseResult* s_pRetListener; }; diff --git a/plugin/samples/HelloIAP/proj.android/jni/Android.mk b/plugin/samples/HelloIAP/proj.android/jni/Android.mk index a3eb4d3d13..a51de9683d 100644 --- a/plugin/samples/HelloIAP/proj.android/jni/Android.mk +++ b/plugin/samples/HelloIAP/proj.android/jni/Android.mk @@ -14,13 +14,9 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static \ - PluginAlipayStatic \ - PluginNd91Static \ PluginProtocolStatic include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) \ -$(call import-module,plugins/alipay/android) \ -$(call import-module,plugins/nd91/android) \ $(call import-module,protocols/android) diff --git a/plugin/tools/toolsForPublish/publishPlugin.sh b/plugin/tools/toolsForPublish/publishPlugin.sh index 2ec88a16e6..82878c9646 100755 --- a/plugin/tools/toolsForPublish/publishPlugin.sh +++ b/plugin/tools/toolsForPublish/publishPlugin.sh @@ -81,8 +81,8 @@ if [ -d ${ANDROID_PROJ_DIR}/sdk ]; then fi #copy android depend on project to publish directory -if [ -d "${ADNROID_SOURCE_DIR}/DependProject" ]; then - cp -rf "${ADNROID_SOURCE_DIR}/DependProject" "${TARGET_DIR}/android" +if [ -d "${ANDROID_PROJ_DIR}/DependProject" ]; then + cp -rf "${ANDROID_PROJ_DIR}/DependProject" "${TARGET_DIR}/android" fi #copy ForManifest.xml file to publish directory From c5965989b07e896151715227a6c3461c1937773e Mon Sep 17 00:00:00 2001 From: zhangbin Date: Mon, 27 May 2013 14:40:08 +0800 Subject: [PATCH 05/18] issue #2224 : Modify the implementation of plugin admob. --- plugin/plugins/admob/include/AdsAdmob.h | 96 ------------------- plugin/plugins/admob/jsb_admob.ini | 60 ------------ .../admob/platform/android/AdsAdmob.cpp | 81 ---------------- plugin/plugins/admob/proj.android/.project | 12 --- .../admob/proj.android/build_native.sh | 20 ---- .../plugins/admob/proj.android/jni/Android.mk | 29 ------ .../admob/proj.android/jni/Application.mk | 7 -- .../src/org/cocos2dx/plugin/AdsAdmob.java | 33 ++++--- .../HelloAds/Classes/HelloWorldScene.cpp | 4 +- .../HelloAds/Classes/HelloWorldScene.h | 4 +- .../HelloAds/proj.android/jni/Android.mk | 3 +- 11 files changed, 23 insertions(+), 326 deletions(-) delete mode 100644 plugin/plugins/admob/include/AdsAdmob.h delete mode 100644 plugin/plugins/admob/jsb_admob.ini delete mode 100644 plugin/plugins/admob/platform/android/AdsAdmob.cpp delete mode 100755 plugin/plugins/admob/proj.android/build_native.sh delete mode 100644 plugin/plugins/admob/proj.android/jni/Android.mk delete mode 100644 plugin/plugins/admob/proj.android/jni/Application.mk diff --git a/plugin/plugins/admob/include/AdsAdmob.h b/plugin/plugins/admob/include/AdsAdmob.h deleted file mode 100644 index 5f30c20d88..0000000000 --- a/plugin/plugins/admob/include/AdsAdmob.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_ADS_ADMOB_H__ -#define __CCX_ADS_ADMOB_H__ - -#include "ProtocolAds.h" -#include -#include - -namespace cocos2d { namespace plugin { - -class AdsAdmob : public ProtocolAds -{ - PLUGIN_REGISTER_DECL(AdsAdmob) -public: - - typedef enum { - kSizeBanner = 0, - kSizeIABMRect, - kSizeIABBanner, - kSizeIABLeaderboard, - } AdmobBannerSize; - - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief config the application info - @param devInfo This parameter is the info of application, must contains: - AdmobID The publisher ID of admob. - @warning Must invoke this interface before other interfaces. - And invoked only once. - */ - virtual void configDeveloperInfo(TAdsDeveloperInfo devInfo); - - /** - @brief show adview - @param type The adview type need to show. - @param sizeEnum The size of the banner view. - (only used when type is kBannerAd) - Use the enum number in AdmobBannerSize. - @param pos The position where the adview be shown. - (only used when type is kBannerAd) - */ - virtual void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter); - - /** - @brief Hide the adview - @param type The adview type need to hide. - */ - virtual void hideAds(AdsType type); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - */ - virtual void setDebugMode(bool debug); - - /** - @brief Add the test device ID - @param deviceID The device ID - */ - void addTestDevice(const char* deviceID); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - virtual ~AdsAdmob(); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_ADS_ADMOB_H__ */ diff --git a/plugin/plugins/admob/jsb_admob.ini b/plugin/plugins/admob/jsb_admob.ini deleted file mode 100644 index ab93d3da10..0000000000 --- a/plugin/plugins/admob/jsb_admob.ini +++ /dev/null @@ -1,60 +0,0 @@ -[admob] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_admob - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/admob/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/admob/include/AdsAdmob.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = AdsAdmob - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = AdsAdmob - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes - diff --git a/plugin/plugins/admob/platform/android/AdsAdmob.cpp b/plugin/plugins/admob/platform/android/AdsAdmob.cpp deleted file mode 100644 index 1cfba3f2b7..0000000000 --- a/plugin/plugins/admob/platform/android/AdsAdmob.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "AdsAdmob.h" -#include "PluginUtils.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(AdsAdmob) - -AdsAdmob::~AdsAdmob() -{ -} - -bool AdsAdmob::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.AdsAdmob"); -} - -void AdsAdmob::configDeveloperInfo(TAdsDeveloperInfo appInfo) -{ - ProtocolAds::configDeveloperInfo(appInfo); -} - -void AdsAdmob::showAds(AdsType type, int sizeEnum, AdsPos pos) -{ - ProtocolAds::showAds(type, sizeEnum, pos); -} - -void AdsAdmob::hideAds(AdsType type) -{ - ProtocolAds::hideAds(type); -} - -const char* AdsAdmob::getSDKVersion() -{ - return ProtocolAds::getSDKVersion(); -} - -void AdsAdmob::setDebugMode(bool debug) -{ - ProtocolAds::setDebugMode(debug); -} - -void AdsAdmob::addTestDevice(const char* deviceID) -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "addTestDevice" - , "(Ljava/lang/String;)V")) - { - jstring strDeviceID = t.env->NewStringUTF(deviceID); - t.env->CallVoidMethod(pData->jobj, t.methodID, strDeviceID); - t.env->DeleteLocalRef(strDeviceID); - t.env->DeleteLocalRef(t.classID); - } -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/admob/proj.android/.project b/plugin/plugins/admob/proj.android/.project index a383057831..f512fd07f5 100644 --- a/plugin/plugins/admob/proj.android/.project +++ b/plugin/plugins/admob/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/plugins/admob/proj.android/build_native.sh b/plugin/plugins/admob/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/admob/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/admob/proj.android/jni/Android.mk b/plugin/plugins/admob/proj.android/jni/Android.mk deleted file mode 100644 index d9e6ef83db..0000000000 --- a/plugin/plugins/admob/proj.android/jni/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginAdmobStatic - -LOCAL_MODULE_FILENAME := libPluginAdmobStatic - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - AdsAdmob.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) diff --git a/plugin/plugins/admob/proj.android/jni/Application.mk b/plugin/plugins/admob/proj.android/jni/Application.mk deleted file mode 100644 index 6c9133095b..0000000000 --- a/plugin/plugins/admob/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginAdmobStatic -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java b/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java index 5395002616..7d85eece30 100644 --- a/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java +++ b/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java @@ -28,8 +28,6 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Set; -import org.cocos2dx.plugin.InterfaceAds.AdsAdapter; - import com.google.ads.*; import com.google.ads.AdRequest.ErrorCode; @@ -38,7 +36,7 @@ import android.content.Context; import android.util.Log; import android.view.WindowManager; -public class AdsAdmob implements AdsAdapter { +public class AdsAdmob implements InterfaceAds { private static final String LOG_TAG = "AdsAdmob"; private static Activity mContext = null; @@ -94,10 +92,10 @@ public class AdsAdmob implements AdsAdapter { @Override public void showAds(int adsType, int sizeEnum, int pos) { switch (adsType) { - case InterfaceAds.ADS_TYPE_BANNER: + case AdsWrapper.ADS_TYPE_BANNER: showBannerAd(sizeEnum, pos); break; - case InterfaceAds.ADS_TYPE_FULL_SCREEN: + case AdsWrapper.ADS_TYPE_FULL_SCREEN: LogD("Now not support full screen view in Admob"); break; default: @@ -113,10 +111,10 @@ public class AdsAdmob implements AdsAdapter { @Override public void hideAds(int adsType) { switch (adsType) { - case InterfaceAds.ADS_TYPE_BANNER: + case AdsWrapper.ADS_TYPE_BANNER: hideBannerAd(); break; - case InterfaceAds.ADS_TYPE_FULL_SCREEN: + case AdsWrapper.ADS_TYPE_FULL_SCREEN: break; default: break; @@ -178,7 +176,7 @@ public class AdsAdmob implements AdsAdapter { if (null == mWm) { mWm = (WindowManager) mContext.getSystemService("window"); } - InterfaceAds.addAdView(mWm, adView, curPos); + AdsWrapper.addAdView(mWm, adView, curPos); } }); } @@ -211,20 +209,20 @@ public class AdsAdmob implements AdsAdapter { @Override public void onDismissScreen(Ad arg0) { LogD("onDismissScreen invoked"); - InterfaceAds.onAdsResult(mAdapter, InterfaceAds.RESULT_CODE_FullScreenViewDismissed, "Full screen ads view dismissed!"); + AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_FullScreenViewDismissed, "Full screen ads view dismissed!"); } @Override public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) { - int errorNo = InterfaceAds.RESULT_CODE_UnknownError; + int errorNo = AdsWrapper.RESULT_CODE_UnknownError; String errorMsg = "Unknow error"; switch (arg1) { case NETWORK_ERROR: - errorNo = InterfaceAds.RESULT_CODE_NetworkError; + errorNo = AdsWrapper.RESULT_CODE_NetworkError; errorMsg = "Network error"; break; case INVALID_REQUEST: - errorNo = InterfaceAds.RESULT_CODE_NetworkError; + errorNo = AdsWrapper.RESULT_CODE_NetworkError; errorMsg = "The ad request is invalid"; break; case NO_FILL: @@ -234,7 +232,7 @@ public class AdsAdmob implements AdsAdapter { break; } LogD("failed to receive ad : " + errorNo + " , " + errorMsg); - InterfaceAds.onAdsResult(mAdapter, errorNo, errorMsg); + AdsWrapper.onAdsResult(mAdapter, errorNo, errorMsg); } @Override @@ -245,13 +243,18 @@ public class AdsAdmob implements AdsAdapter { @Override public void onPresentScreen(Ad arg0) { LogD("onPresentScreen invoked"); - InterfaceAds.onAdsResult(mAdapter, InterfaceAds.RESULT_CODE_FullScreenViewShown, "Full screen ads view shown!"); + AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_FullScreenViewShown, "Full screen ads view shown!"); } @Override public void onReceiveAd(Ad arg0) { LogD("onReceiveAd invoked"); - InterfaceAds.onAdsResult(mAdapter, InterfaceAds.RESULT_CODE_AdsReceived, "Ads request received success!"); + AdsWrapper.onAdsResult(mAdapter, AdsWrapper.RESULT_CODE_AdsReceived, "Ads request received success!"); } } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp b/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp index d36d4c02c6..f622c8d36b 100644 --- a/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp @@ -71,7 +71,7 @@ bool HelloWorld::init() return false; } - m_pAdmob = dynamic_cast(PluginManager::getInstance()->loadPlugin("AdsAdmob")); + m_pAdmob = dynamic_cast(PluginManager::getInstance()->loadPlugin("AdsAdmob")); TAdsDeveloperInfo devInfo; devInfo["AdmobID"] = "a1516fb6b16b12f"; m_pAdmob->configDeveloperInfo(devInfo); @@ -168,7 +168,7 @@ void HelloWorld::testShow(CCObject* pSender) int nSize = 0; if (m_pAds == m_pAdmob) { - nSize = AdsAdmob::kSizeBanner; + nSize = 0; } if (m_pAds) diff --git a/plugin/samples/HelloAds/Classes/HelloWorldScene.h b/plugin/samples/HelloAds/Classes/HelloWorldScene.h index 4d9573712c..19a04807ff 100644 --- a/plugin/samples/HelloAds/Classes/HelloWorldScene.h +++ b/plugin/samples/HelloAds/Classes/HelloWorldScene.h @@ -25,7 +25,7 @@ THE SOFTWARE. #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" -#include "AdsAdmob.h" +#include "ProtocolAds.h" class MyAdsListener : public cocos2d::plugin::AdsListener { @@ -57,7 +57,7 @@ public: CREATE_FUNC(HelloWorld); private: - cocos2d::plugin::AdsAdmob* m_pAdmob; + cocos2d::plugin::ProtocolAds* m_pAdmob; MyAdsListener* m_pListener; cocos2d::CCMenuItemToggle* m_pCaseItem; diff --git a/plugin/samples/HelloAds/proj.android/jni/Android.mk b/plugin/samples/HelloAds/proj.android/jni/Android.mk index a10377440a..49fb10bb3c 100644 --- a/plugin/samples/HelloAds/proj.android/jni/Android.mk +++ b/plugin/samples/HelloAds/proj.android/jni/Android.mk @@ -13,10 +13,9 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static \ -PluginProtocolStatic PluginAdmobStatic +PluginProtocolStatic include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,protocols/android) -$(call import-module,plugins/admob/android) From 4022e002e81c1a9d705b210ed767d1689a9e17e1 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 28 May 2013 18:10:09 +0800 Subject: [PATCH 06/18] issue #2224 : Modify the implementation of plugin flurry & umeng. --- .../plugins/flurry/include/AnalyticsFlurry.h | 170 ------- plugin/plugins/flurry/jsb_flurry.ini | 59 --- .../platform/android/AnalyticsFlurry.cpp | 246 ---------- plugin/plugins/flurry/proj.android/.project | 12 - .../flurry/proj.android/build_native.sh | 20 - .../flurry/proj.android/jni/Android.mk | 29 -- .../flurry/proj.android/jni/Application.mk | 7 - .../org/cocos2dx/plugin/AnalyticsFlurry.java | 331 +++++++------- plugin/plugins/umeng/include/AnalyticsUmeng.h | 189 -------- plugin/plugins/umeng/jsb_umeng.ini | 59 --- .../umeng/platform/android/AnalyticsUmeng.cpp | 354 --------------- plugin/plugins/umeng/proj.android/.project | 12 - .../umeng/proj.android/build_native.sh | 20 - .../plugins/umeng/proj.android/jni/Android.mk | 30 -- .../umeng/proj.android/jni/Application.mk | 7 - .../org/cocos2dx/plugin/AnalyticsUmeng.java | 424 ++++++++++-------- plugin/protocols/PluginParam.cpp | 6 + plugin/protocols/include/PluginParam.h | 9 +- plugin/protocols/include/PluginProtocol.h | 4 + .../platform/android/PluginJniHelper.cpp | 20 +- .../platform/android/PluginJniHelper.h | 3 - .../platform/android/PluginJniMacros.h | 114 +++++ .../platform/android/PluginProtocol.cpp | 149 +++--- .../platform/android/PluginUtils.cpp | 43 +- .../protocols/platform/android/PluginUtils.h | 57 ++- .../platform/android/ProtocolAds.cpp | 2 +- .../platform/android/ProtocolAnalytics.cpp | 2 +- .../platform/android/ProtocolIAP.cpp | 4 +- .../platform/android/ProtocolSocial.cpp | 4 +- .../HelloAnalytics/Classes/AppDelegate.cpp | 41 +- .../Classes/HelloWorldScene.cpp | 121 +++-- .../HelloAnalytics/proj.android/.project | 5 + .../proj.android/jni/Android.mk | 4 +- 33 files changed, 821 insertions(+), 1736 deletions(-) delete mode 100644 plugin/plugins/flurry/include/AnalyticsFlurry.h delete mode 100644 plugin/plugins/flurry/jsb_flurry.ini delete mode 100644 plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp delete mode 100755 plugin/plugins/flurry/proj.android/build_native.sh delete mode 100644 plugin/plugins/flurry/proj.android/jni/Android.mk delete mode 100644 plugin/plugins/flurry/proj.android/jni/Application.mk delete mode 100644 plugin/plugins/umeng/include/AnalyticsUmeng.h delete mode 100644 plugin/plugins/umeng/jsb_umeng.ini delete mode 100644 plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp delete mode 100755 plugin/plugins/umeng/proj.android/build_native.sh delete mode 100644 plugin/plugins/umeng/proj.android/jni/Android.mk delete mode 100644 plugin/plugins/umeng/proj.android/jni/Application.mk create mode 100644 plugin/protocols/platform/android/PluginJniMacros.h diff --git a/plugin/plugins/flurry/include/AnalyticsFlurry.h b/plugin/plugins/flurry/include/AnalyticsFlurry.h deleted file mode 100644 index 6eb932e08d..0000000000 --- a/plugin/plugins/flurry/include/AnalyticsFlurry.h +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_ANALYTICS_FLURRY_H__ -#define __CCX_ANALYTICS_FLURRY_H__ - -#include "ProtocolAnalytics.h" - -namespace cocos2d { namespace plugin { - -class AnalyticsFlurry : public ProtocolAnalytics -{ - PLUGIN_REGISTER_DECL(AnalyticsFlurry) -public: - enum Gender{ - FEMALE = 0, - MALE = 1 - }; - - virtual ~AnalyticsFlurry(); - - /** - @par override interface of base class - */ - - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief Start a new session. - @param appKey The identity of the application. - */ - virtual void startSession(const char* appKey); - - /** - @brief Stop a session. - @warning This interface only worked on android - */ - virtual void stopSession(); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - @note It must be invoked before calling startSession. - */ - virtual void setDebugMode(bool debug); - - /** - @brief Set the timeout for expiring a session. - @param millis In milliseconds as the unit of time. - @note It must be invoked before calling startSession. - */ - virtual void setSessionContinueMillis(long millis); - - /** - @brief log an error - @param errorId The identity of error - @param message Extern message for the error - */ - virtual void logError(const char* errorId, const char* message); - - /** - @brief log an event. - @param eventId The identity of event - @param paramMap Extern parameters of the event, use NULL if not needed. - */ - virtual void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL); - - /** - @brief Track an event begin. - @param eventId The identity of event - */ - virtual void logTimedEventBegin(const char* eventId); - - /** - @brief Track an event end. - @param eventId The identity of event - */ - virtual void logTimedEventEnd(const char* eventId); - - /** - @brief Whether to catch uncaught exceptions to server. - @warning This interface only worked on android. - */ - virtual void setCaptureUncaughtException(bool enabled); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - /** - @par Unique interface of Flurry - */ - /** - @brief Sets the age of the user at the time of this session. - */ - void setAge(int age); - - /** - @brief Sets the gender of the user. - */ - void setGender(Gender gender); - - /** - @brief Sets the userId for this session. - */ - void setUserId(const char* userId); - - /** - @brief Log a page view. - */ - void logPageView(); - - /** - @brief Set the version name of the app. - @note It must be invoked before calling startSession. - */ - void setVersionName(const char* versionName); - - /** - @par interface for android - */ - /** - @brief Enable the use of HTTPS communications. - @warning This interface only worked on android - */ - void setUseHttps(bool useHttps); - - /** @brief Enable or disable detailed location reporting. - * @note It must be invoked before calling startSession. - * @warning This interface only worked on android - */ - void setReportLocation(bool enabled); - - /** - @par interface for ios - */ - /** - @brief Log a timed event with parameters. - @warning The paramMap is only worked on ios. - On android, paramMap is ignored. - */ - void logTimedEventBegin(const char* eventId, LogEventParamMap* paramMap); - void logTimedEventEnd(const char* eventId, LogEventParamMap* paramMap); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_ANALYTICS_FLURRY_H__ */ diff --git a/plugin/plugins/flurry/jsb_flurry.ini b/plugin/plugins/flurry/jsb_flurry.ini deleted file mode 100644 index 151a4ddbbf..0000000000 --- a/plugin/plugins/flurry/jsb_flurry.ini +++ /dev/null @@ -1,59 +0,0 @@ -[flurry] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_flurry - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/flurry/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/flurry/include/AnalyticsFlurry.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = AnalyticsFlurry - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = AnalyticsFlurry - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes diff --git a/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp b/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp deleted file mode 100644 index e6ce0752e8..0000000000 --- a/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "AnalyticsFlurry.h" -#include "PluginJniHelper.h" -#include -#include "PluginUtils.h" -#include "PluginJavaData.h" - -#if 1 -#define LOG_TAG "AnalyticsFlurry" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(AnalyticsFlurry) - -AnalyticsFlurry::~AnalyticsFlurry() -{ - LOGD("AnalyticsFlurry destructor"); -} - -bool AnalyticsFlurry::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.AnalyticsFlurry"); -} - -void AnalyticsFlurry::setReportLocation(bool enabled) -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setReportLocation" - , "(Z)V")) - { - t.env->CallVoidMethod(pData->jobj, t.methodID, enabled); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::logPageView() -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logPageView" - , "()V")) - { - t.env->CallVoidMethod(pData->jobj, t.methodID); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::setVersionName(const char* versionName) -{ - return_if_fails(versionName != NULL && strlen(versionName) > 0); - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setVersionName" - , "(Ljava/lang/String;)V")) - { - jstring jversionName = t.env->NewStringUTF(versionName); - t.env->CallVoidMethod(pData->jobj, t.methodID, jversionName); - t.env->DeleteLocalRef(jversionName); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::setAge(int age) -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setAge" - , "(I)V")) - { - t.env->CallVoidMethod(pData->jobj, t.methodID, age); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::setGender(Gender gender) -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setGender" - , "(B)V")) - { - t.env->CallVoidMethod(pData->jobj, t.methodID, (jbyte)gender); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::setUserId(const char* userId) -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - return_if_fails(userId != NULL && strlen(userId) > 0); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setUserId" - , "(Ljava/lang/String;)V")) - { - jstring juserId = t.env->NewStringUTF(userId); - t.env->CallVoidMethod(pData->jobj, t.methodID, juserId); - t.env->DeleteLocalRef(juserId); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::setUseHttps(bool useHttps) -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setUseHttps" - , "(Z)V")) - { - t.env->CallVoidMethod(pData->jobj, t.methodID, useHttps); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsFlurry::logTimedEventBegin(const char* eventId) -{ - ProtocolAnalytics::logTimedEventBegin(eventId); -} - -void AnalyticsFlurry::logTimedEventBegin(const char* eventId, LogEventParamMap* paramMap) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - - if (paramMap == NULL) - { - ProtocolAnalytics::logTimedEventBegin(eventId); - } - else - { - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logTimedEventBegin" - , "(Ljava/lang/String;Ljava/util/Hashtable;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jobject jparamMap= PluginUtils::createJavaMapObject(t, paramMap); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jparamMap); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jparamMap); - t.env->DeleteLocalRef(t.classID); - } - } -} - -/** override methods of base class */ -/** Start a new session. */ -void AnalyticsFlurry::startSession(const char* appKey) -{ - ProtocolAnalytics::startSession(appKey); -} - -/** Stop a session. */ -void AnalyticsFlurry::stopSession() -{ - ProtocolAnalytics::stopSession(); -} - -/** Set the timeout for expiring a session. */ -void AnalyticsFlurry::setSessionContinueMillis(long millis) -{ - ProtocolAnalytics::setSessionContinueMillis(millis); -} - -/** Whether to catch uncaught exceptions to server.*/ -void AnalyticsFlurry::setCaptureUncaughtException(bool enabled) -{ - ProtocolAnalytics::setCaptureUncaughtException(enabled); -} - -const char* AnalyticsFlurry::getSDKVersion() -{ - return ProtocolAnalytics::getSDKVersion(); -} - -/** Set whether needs to output logs to console.*/ -void AnalyticsFlurry::setDebugMode(bool debug) -{ - ProtocolAnalytics::setDebugMode(debug); -} - -/** log an error */ -void AnalyticsFlurry::logError(const char* errorId, const char* message) -{ - ProtocolAnalytics::logError(errorId, message); -} - -/** log an event. */ -void AnalyticsFlurry::logEvent(const char* eventId, LogEventParamMap* paramMap) -{ - ProtocolAnalytics::logEvent(eventId, paramMap); -} - -/** end a timed event */ -void AnalyticsFlurry::logTimedEventEnd(const char* eventId) -{ - ProtocolAnalytics::logTimedEventEnd(eventId); -} - -void AnalyticsFlurry::logTimedEventEnd(const char* eventId, LogEventParamMap* paramMap) -{ - ProtocolAnalytics::logTimedEventEnd(eventId); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/flurry/proj.android/.project b/plugin/plugins/flurry/proj.android/.project index 2c418957e0..49c5fb84c4 100644 --- a/plugin/plugins/flurry/proj.android/.project +++ b/plugin/plugins/flurry/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/plugins/flurry/proj.android/build_native.sh b/plugin/plugins/flurry/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/flurry/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/flurry/proj.android/jni/Android.mk b/plugin/plugins/flurry/proj.android/jni/Android.mk deleted file mode 100644 index a429de049f..0000000000 --- a/plugin/plugins/flurry/proj.android/jni/Android.mk +++ /dev/null @@ -1,29 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginFlurryStatic - -LOCAL_MODULE_FILENAME := libPluginFlurryStatic - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - AnalyticsFlurry.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) diff --git a/plugin/plugins/flurry/proj.android/jni/Application.mk b/plugin/plugins/flurry/proj.android/jni/Application.mk deleted file mode 100644 index 76dbd7b433..0000000000 --- a/plugin/plugins/flurry/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginFlurryStatic -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java index f738728077..d1091f2bbf 100644 --- a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java +++ b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java @@ -24,6 +24,9 @@ THE SOFTWARE. package org.cocos2dx.plugin; import java.util.Hashtable; +import java.util.Iterator; + +import org.json.JSONObject; import android.content.Context; import android.util.Log; @@ -32,170 +35,194 @@ import com.flurry.android.FlurryAgent; public class AnalyticsFlurry implements InterfaceAnalytics { - private Context mContext = null; - protected static String TAG = "AnalyticsFlurry"; - - protected static void LogE(String msg, Exception e) { - Log.e(TAG, msg, e); - e.printStackTrace(); - } + private Context mContext = null; + protected static String TAG = "AnalyticsFlurry"; - private static boolean isDebug = false; - protected static void LogD(String msg) { - if (isDebug) { - Log.d(TAG, msg); - } - } + private static final String KEY_EVENT = "FlurryEvent"; + private static final String KEY_PARAMS = "FlurryParams"; + + protected static void LogE(String msg, Exception e) { + Log.e(TAG, msg, e); + e.printStackTrace(); + } - public AnalyticsFlurry(Context context) { - mContext = context; - } - - @Override - public void startSession(String appKey) { - LogD("startSession invoked!"); - FlurryAgent.onStartSession(mContext, appKey); - } + private static boolean isDebug = false; + protected static void LogD(String msg) { + if (isDebug) { + Log.d(TAG, msg); + } + } - @Override - public void stopSession() { - LogD("stopSession invoked!"); - FlurryAgent.onEndSession(mContext); - } + public AnalyticsFlurry(Context context) { + mContext = context; + } + + @Override + public void startSession(String appKey) { + LogD("startSession invoked!"); + FlurryAgent.onStartSession(mContext, appKey); + } - @Override - public void setSessionContinueMillis(int millis) { - LogD("setSessionContinueMillis invoked!"); - FlurryAgent.setContinueSessionMillis(millis); - } + @Override + public void stopSession() { + LogD("stopSession invoked!"); + FlurryAgent.onEndSession(mContext); + } - @Override - public void setCaptureUncaughtException(boolean isEnabled) { - LogD("setCaptureUncaughtException invoked!"); - FlurryAgent.setCaptureUncaughtExceptions(isEnabled); - } + @Override + public void setSessionContinueMillis(int millis) { + LogD("setSessionContinueMillis invoked!"); + FlurryAgent.setContinueSessionMillis(millis); + } - @Override - public void setDebugMode(boolean isDebugMode) { - isDebug = isDebugMode; - FlurryAgent.setLogEnabled(isDebug); - if (isDebugMode) { - FlurryAgent.setLogLevel(Log.DEBUG); - } - } + @Override + public void setCaptureUncaughtException(boolean isEnabled) { + LogD("setCaptureUncaughtException invoked!"); + FlurryAgent.setCaptureUncaughtExceptions(isEnabled); + } - @Override - public void logError(String errorId, String message) { - LogD("logError invoked!"); - FlurryAgent.onError(errorId, message, ""); - } + @Override + public void setDebugMode(boolean isDebugMode) { + isDebug = isDebugMode; + FlurryAgent.setLogEnabled(isDebug); + if (isDebugMode) { + FlurryAgent.setLogLevel(Log.DEBUG); + } + } - @Override - public void logEvent(String eventId) { - LogD("logEvent(eventId) invoked!"); - FlurryAgent.logEvent(eventId); - } + @Override + public void logError(String errorId, String message) { + LogD("logError invoked!"); + FlurryAgent.onError(errorId, message, ""); + } - @Override - public void logEvent(String eventId, Hashtable paramMap) { - LogD("logEvent(eventId, paramMap) invoked!"); - FlurryAgent.logEvent(eventId, paramMap); - } + @Override + public void logEvent(String eventId) { + LogD("logEvent(eventId) invoked!"); + FlurryAgent.logEvent(eventId); + } - @Override - public void logTimedEventBegin(String eventId) { - LogD("logTimedEventBegin invoked!"); - FlurryAgent.logEvent(eventId, true); - } + @Override + public void logEvent(String eventId, Hashtable paramMap) { + LogD("logEvent(eventId, paramMap) invoked!"); + FlurryAgent.logEvent(eventId, paramMap); + } - @Override - public void logTimedEventEnd(String eventId) { - LogD("logTimedEventEnd invoked!"); - FlurryAgent.endTimedEvent(eventId); - } + @Override + public void logTimedEventBegin(String eventId) { + LogD("logTimedEventBegin invoked!"); + FlurryAgent.logEvent(eventId, true); + } - @Override - public String getSDKVersion() { - LogD("getSDKVersion invoked!"); - String ret = ""; - try { - int nRet = FlurryAgent.getAgentVersion(); - ret = "Flurry android ver " + nRet; - } catch(Exception e){ - LogE("Exception in getSDKVersion", e); - } - return ret; - } + @Override + public void logTimedEventEnd(String eventId) { + LogD("logTimedEventEnd invoked!"); + FlurryAgent.endTimedEvent(eventId); + } - protected void logTimedEventBegin(String eventId, Hashtable paramMap) { - LogD("logTimedEventBegin invoked!"); - try{ - FlurryAgent.logEvent(eventId, paramMap, true); - } catch(Exception e){ - LogE("Exception in logTimedEventBegin", e); - } - } - - protected void setReportLocation(boolean enabled) { - LogD("setReportLocation invoked!"); - try{ - FlurryAgent.setReportLocation(enabled); - } catch(Exception e){ - LogE("Exception in setReportLocation", e); - } - } - - protected void logPageView() { - LogD("logPageView invoked!"); - try{ - FlurryAgent.onPageView(); - } catch(Exception e){ - LogE("Exception in logPageView", e); - } - } + @Override + public String getSDKVersion() { + LogD("getSDKVersion invoked!"); + String ret = ""; + try { + int nRet = FlurryAgent.getAgentVersion(); + ret = "Flurry android ver " + nRet; + } catch(Exception e){ + LogE("Exception in getSDKVersion", e); + } + return ret; + } - protected void setVersionName(String versionName) { - LogD("setVersionName invoked!"); - try { - FlurryAgent.setVersionName(versionName); - } catch(Exception e){ - LogE("Exception in setVersionName", e); - } - } - - protected void setAge(int age) { - LogD("setAge invoked!"); - try { - FlurryAgent.setAge(age); - } catch(Exception e){ - LogE("Exception in setAge", e); - } - } - - protected void setGender(byte gender) { - LogD("setGender invoked!"); - try { - FlurryAgent.setGender(gender); - } catch(Exception e){ - LogE("Exception in setGender", e); - } - } - - protected void setUserId(String userId) { - LogD("setUserId invoked!"); - try { - FlurryAgent.setUserId(userId); - } catch(Exception e){ - LogE("Exception in setUserId", e); - } - } - - protected void setUseHttps(boolean useHttps) { - LogD("setUseHttps invoked!"); - try { - FlurryAgent.setUseHttps(useHttps); - } catch(Exception e){ - LogE("Exception in setUseHttps", e); - } - } + protected void logTimedEventBegin(JSONObject eventInfo) { + LogD("logTimedEventBegin invoked!"); + try{ + String eventId = eventInfo.getString(KEY_EVENT); + + if (eventInfo.has("FlurryParams")) + { + JSONObject params = eventInfo.getJSONObject(KEY_PARAMS); + @SuppressWarnings("rawtypes") + Iterator it = params.keys(); + Hashtable paramMap = new Hashtable(); + while (it.hasNext()) { + String key = (String) it.next(); + String value = params.getString(key); + paramMap.put(key, value); + } + FlurryAgent.logEvent(eventId, paramMap, true); + } else { + FlurryAgent.logEvent(eventId, true); + } + } catch(Exception e){ + LogE("Exception in logTimedEventBegin", e); + } + } + + protected void setReportLocation(boolean enabled) { + LogD("setReportLocation invoked!"); + try{ + FlurryAgent.setReportLocation(enabled); + } catch(Exception e){ + LogE("Exception in setReportLocation", e); + } + } + + protected void logPageView() { + LogD("logPageView invoked!"); + try{ + FlurryAgent.onPageView(); + } catch(Exception e){ + LogE("Exception in logPageView", e); + } + } + + protected void setVersionName(String versionName) { + LogD("setVersionName invoked!"); + try { + FlurryAgent.setVersionName(versionName); + } catch(Exception e){ + LogE("Exception in setVersionName", e); + } + } + + protected void setAge(int age) { + LogD("setAge invoked!"); + try { + FlurryAgent.setAge(age); + } catch(Exception e){ + LogE("Exception in setAge", e); + } + } + + protected void setGender(byte gender) { + LogD("setGender invoked!"); + try { + FlurryAgent.setGender(gender); + } catch(Exception e){ + LogE("Exception in setGender", e); + } + } + + protected void setUserId(String userId) { + LogD("setUserId invoked!"); + try { + FlurryAgent.setUserId(userId); + } catch(Exception e){ + LogE("Exception in setUserId", e); + } + } + + protected void setUseHttps(boolean useHttps) { + LogD("setUseHttps invoked!"); + try { + FlurryAgent.setUseHttps(useHttps); + } catch(Exception e){ + LogE("Exception in setUseHttps", e); + } + } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/plugins/umeng/include/AnalyticsUmeng.h b/plugin/plugins/umeng/include/AnalyticsUmeng.h deleted file mode 100644 index 187fb2c619..0000000000 --- a/plugin/plugins/umeng/include/AnalyticsUmeng.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCX_ANALYTICS_UMENG_H__ -#define __CCX_ANALYTICS_UMENG_H__ - -#include "ProtocolAnalytics.h" - -namespace cocos2d { namespace plugin { - -// Please refer to http://dev.umeng.com/doc/document_ana_android.html for the detail informations about -// how to use the interfaces of Umeng. - -class AnalyticsUmeng : public ProtocolAnalytics -{ - PLUGIN_REGISTER_DECL(AnalyticsUmeng) -public: - enum UmengReportPolicy - { - REALTIME = 0, - BATCH_AT_LAUNCH = 1, - DAILY = 4, - WIFIONLY = 5 - }; - - virtual ~AnalyticsUmeng(); - - /** - @par override interface of base class - */ - /** - @brief plugin initialization - */ - virtual bool init(); - - /** - @brief Start a new session. - @param appKey The identity of the application. - */ - virtual void startSession(const char* appKey); - - /** - @brief Stop a session. - @warning This interface only worked on android - */ - virtual void stopSession(); - - /** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - @note It must be invoked before calling startSession. - */ - virtual void setDebugMode(bool debug); - - /** - @brief Set the timeout for expiring a session. - @param millis In milliseconds as the unit of time. - @note It must be invoked before calling startSession. - @warning Only worked on android - */ - virtual void setSessionContinueMillis(long millis); - - /** - @brief log an error - @param errorId The identity of error - @param message Extern message for the error - @warning Only worked on android - */ - virtual void logError(const char* errorId, const char* message); - - /** - @brief log an event. - @param eventId The identity of event - @param paramMap Extern parameters of the event, use NULL if not needed. - */ - virtual void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL); - - /** - @brief Track an event begin. - @param eventId The identity of event - */ - virtual void logTimedEventBegin(const char* eventId); - - /** - @brief Track an event end. - @param eventId The identity of event - */ - virtual void logTimedEventEnd(const char* eventId); - - /** - @brief Whether to catch uncaught exceptions to server. - @warning This interface only worked on android. - */ - virtual void setCaptureUncaughtException(bool enabled); - - virtual const char* getPluginVersion() { return "v0.1.01"; }; - virtual const char* getSDKVersion(); - - /** - @par Unique interface of Umeng - */ - - /** - @brief Update the online configuration - */ - void updateOnlineConfig(); - - /** - @brief Get the online configuration parameters - */ - const char* getConfigParams(const char* key); - - /** - @brief Set the default policy - */ - void setDefaultReportPolicy(UmengReportPolicy policy); - - /** - @brief Log event with a label. - * @note The label param is for distinguish event that with the same id. It will not be kept in the server. - */ - void logEventWithLabel(const char* eventId, const char* label); - - /** - @brief Log event with duration and a label - * @note The label param is for distinguish event that with the same id. It will not be kept in the server. - */ - void logEventWithDuration(const char* eventId, long duration, const char* label); - - /** - @brief Log event with duration and a map which contains event parameters. - * @note The label param is for distinguish event that with the same id. It will not be kept in the server. - */ - void logEventWithDuration(const char* eventId, long duration, LogEventParamMap* paramMap = NULL); - - /** - @brief Start log a timed event with a label. - */ - void logTimedEventWithLabelBegin(const char* eventId, const char* label); - - /** - @brief Finish log a timed event with a label - */ - void logTimedEventWithLabelEnd(const char* eventId, const char* label); - - /** - @brief Start log a timed event with a label and a map which contains event parameters. - */ - void logTimedKVEventBegin(const char* eventId, const char* label, LogEventParamMap* paramMap); - - /** - @brief Finish log a timed event with a label. - */ - void logTimedKVEventEnd(const char* eventId, const char* label); - - /** - @par interface for ios - */ - /** - @brief start session with policy and channel id - @warning On android, policy & channelId are ignored. - */ - void startSession(const char* appKey, UmengReportPolicy policy, const char* channelId); - void checkUpdate(); -}; - -}} // namespace cocos2d { namespace plugin { - -#endif /* __CCX_ANALYTICS_UMENG_H__ */ diff --git a/plugin/plugins/umeng/jsb_umeng.ini b/plugin/plugins/umeng/jsb_umeng.ini deleted file mode 100644 index 0de2e13de9..0000000000 --- a/plugin/plugins/umeng/jsb_umeng.ini +++ /dev/null @@ -1,59 +0,0 @@ -[umeng] -# the prefix to be added to the generated functions. You might or might not use this in your own -# templates -prefix = pluginx_umeng - -# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) -# all classes will be embedded in that namespace -target_namespace = plugin - -android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include -android_flags = -D_SIZE_T_DEFINED_ - -clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include -clang_flags = -nostdinc -x c++ - -cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/umeng/include - -cocos_flags = -DANDROID - -cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common - -# extra arguments for clang -extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s - -# what headers to parse -headers = %(pluginxdir)s/plugins/umeng/include/AnalyticsUmeng.h - -# what classes to produce code for. You can use regular expressions here. When testing the regular -# expression, it will be enclosed in "^$", like this: "^CCMenu*$". -classes = AnalyticsUmeng - -# what should we skip? in the format ClassName::[function function] -# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also -# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just -# add a single "*" as functions. See bellow for several examples. A special class name is "*", which -# will apply to all class names. This is a convenience wildcard to be able to skip similar named -# functions from all classes. - -skip = *::[createPlugin] - -rename_functions = - -rename_classes = - -# for all class names, should we remove something when registering in the target VM? -remove_prefix = - -# classes for which there will be no "parent" lookup -classes_have_no_parents = - -# base classes which will be skipped when their sub-classes found them. -base_classes_to_skip = - -# classes that create no constructor -# CCSet is special and we will use a hand-written constructor -abstract_classes = AnalyticsUmeng - -# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes diff --git a/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp b/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp deleted file mode 100644 index 42661f095f..0000000000 --- a/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "AnalyticsUmeng.h" -#include "PluginJniHelper.h" -#include -#include "PluginUtils.h" -#include "PluginJavaData.h" -#if 1 -#define LOG_TAG "AnalyticsUmeng" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#endif - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(AnalyticsUmeng) - -AnalyticsUmeng::~AnalyticsUmeng() -{ - LOGD("AnalyticsUmeng destructor"); -} - -bool AnalyticsUmeng::init() -{ - return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.AnalyticsUmeng"); -} - -void AnalyticsUmeng::updateOnlineConfig() -{ - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - LOGD("update online 01"); - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "updateOnlineConfig" - , "()V")) - { - LOGD("update online 02"); - t.env->CallVoidMethod(pData->jobj, t.methodID); - LOGD("update online 03"); - t.env->DeleteLocalRef(t.classID); - LOGD("update online 04"); - } -} - -const char* AnalyticsUmeng::getConfigParams(const char* key) -{ - static std::string ret = ""; - return_val_if_fails(key != NULL && strlen(key) > 0, ""); - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getConfigParams" - , "(Ljava/lang/String;)Ljava/lang/String;")) - { - jstring jstrKey = t.env->NewStringUTF(key); - jstring jstr = (jstring)t.env->CallObjectMethod(pData->jobj, t.methodID, jstrKey); - ret = PluginJniHelper::jstring2string(jstr); - LOGD("ret = %s", ret.c_str()); - t.env->DeleteLocalRef(jstrKey); - t.env->DeleteLocalRef(t.classID); - } - return ret.c_str(); -} - -void AnalyticsUmeng::setDefaultReportPolicy(UmengReportPolicy ePolicy) -{ - return_if_fails(ePolicy == REALTIME - || ePolicy == BATCH_AT_LAUNCH - || ePolicy == DAILY - || ePolicy == WIFIONLY ); - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - LOGD("data : %p", pData); - LOGD("class name : %s", pData->jclassName.c_str()); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "setDefaultReportPolicy" - , "(I)V")) - { - t.env->CallVoidMethod(pData->jobj, t.methodID, (jint)ePolicy); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsUmeng::logEventWithLabel(const char* eventId, const char* label) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - return_if_fails(label != NULL && strlen(label) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logEventWithLabel" - , "(Ljava/lang/String;Ljava/lang/String;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jstring jlabel = t.env->NewStringUTF(label); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jlabel); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jlabel); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, const char* label) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - return_if_fails(label != NULL && strlen(label) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logEventWithDuration" - , "(Ljava/lang/String;ILjava/lang/String;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jstring jlabel = t.env->NewStringUTF(label); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, duration, jlabel); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jlabel); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, LogEventParamMap* paramMap /* = NULL */) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (paramMap == NULL) - { - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logEventWithDuration" - , "(Ljava/lang/String;I)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, duration); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(t.classID); - } - } - else - { - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logEventWithDuration" - , "(Ljava/lang/String;ILjava/util/Hashtable;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jobject jparamMap= PluginUtils::createJavaMapObject(t, paramMap); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, duration, jparamMap); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jparamMap); - t.env->DeleteLocalRef(t.classID); - } - } - -} - -void AnalyticsUmeng::logTimedEventWithLabelBegin(const char* eventId, const char* label) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - return_if_fails(label != NULL && strlen(label) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logTimedEventWithLabelBegin" - , "(Ljava/lang/String;Ljava/lang/String;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jstring jlabel = t.env->NewStringUTF(label); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jlabel); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jlabel); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsUmeng::logTimedEventWithLabelEnd(const char* eventId, const char* label) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - return_if_fails(label != NULL && strlen(label) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logTimedEventWithLabelEnd" - , "(Ljava/lang/String;Ljava/lang/String;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jstring jlabel = t.env->NewStringUTF(label); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jlabel); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jlabel); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsUmeng::logTimedKVEventBegin(const char* eventId, const char* label, LogEventParamMap* paramMap) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - return_if_fails(label != NULL && strlen(label) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logTimedKVEventBegin" - , "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Hashtable;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jstring jlabel = t.env->NewStringUTF(label); - jobject jparamMap= PluginUtils::createJavaMapObject(t, paramMap); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jlabel, jparamMap); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jlabel); - t.env->DeleteLocalRef(jparamMap); - t.env->DeleteLocalRef(t.classID); - } -} - -void AnalyticsUmeng::logTimedKVEventEnd(const char* eventId, const char* label) -{ - return_if_fails(eventId != NULL && strlen(eventId) > 0); - return_if_fails(label != NULL && strlen(label) > 0); - - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "logTimedKVEventEnd" - , "(Ljava/lang/String;Ljava/lang/String;)V")) - { - jstring jeventId = t.env->NewStringUTF(eventId); - jstring jlabel = t.env->NewStringUTF(label); - t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jlabel); - t.env->DeleteLocalRef(jeventId); - t.env->DeleteLocalRef(jlabel); - t.env->DeleteLocalRef(t.classID); - } -} - -/** interface for ios */ -void AnalyticsUmeng::startSession(const char* appKey, UmengReportPolicy policy, const char* channelId) -{ - startSession(appKey); -} - -void AnalyticsUmeng::checkUpdate() -{ - -} - -/** override methods of base class */ -/** Start a new session. */ -void AnalyticsUmeng::startSession(const char* appKey) -{ - ProtocolAnalytics::startSession(appKey); -} - -/** Stop a session. */ -void AnalyticsUmeng::stopSession() -{ - ProtocolAnalytics::stopSession(); -} - -/** Set the timeout for expiring a session. */ -void AnalyticsUmeng::setSessionContinueMillis(long millis) -{ - ProtocolAnalytics::setSessionContinueMillis(millis); -} - -/** Whether to catch uncaught exceptions to server.*/ -void AnalyticsUmeng::setCaptureUncaughtException(bool enabled) -{ - ProtocolAnalytics::setCaptureUncaughtException(enabled); -} - -const char* AnalyticsUmeng::getSDKVersion() -{ - return ProtocolAnalytics::getSDKVersion(); -} - -/** Set whether needs to output logs to console.*/ -void AnalyticsUmeng::setDebugMode(bool debug) -{ - ProtocolAnalytics::setDebugMode(debug); -} - -/** log an error */ -void AnalyticsUmeng::logError(const char* errorId, const char* message) -{ - ProtocolAnalytics::logError(errorId, message); -} - -/** log an event. */ -void AnalyticsUmeng::logEvent(const char* eventId, LogEventParamMap* paramMap) -{ - ProtocolAnalytics::logEvent(eventId, paramMap); -} - -/** begin to log a timed event */ -void AnalyticsUmeng::logTimedEventBegin(const char* eventId) -{ - ProtocolAnalytics::logTimedEventBegin(eventId); -} - -/** end a timed event */ -void AnalyticsUmeng::logTimedEventEnd(const char* eventId) -{ - ProtocolAnalytics::logTimedEventEnd(eventId); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/umeng/proj.android/.project b/plugin/plugins/umeng/proj.android/.project index 40d433d922..21bd34bcab 100644 --- a/plugin/plugins/umeng/proj.android/.project +++ b/plugin/plugins/umeng/proj.android/.project @@ -30,16 +30,4 @@ com.android.ide.eclipse.adt.AndroidNature org.eclipse.jdt.core.javanature - - - android - 2 - PARENT-1-PROJECT_LOC/platform/android - - - include - 2 - PARENT-1-PROJECT_LOC/include - - diff --git a/plugin/plugins/umeng/proj.android/build_native.sh b/plugin/plugins/umeng/proj.android/build_native.sh deleted file mode 100755 index 0b272b9465..0000000000 --- a/plugin/plugins/umeng/proj.android/build_native.sh +++ /dev/null @@ -1,20 +0,0 @@ -# set params -PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd) - -if [ ! "${PLUGIN_ROOT}" ]; then - PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../.. -fi - -# build -"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \ -NDK_MODULE_PATH="$PLUGIN_ROOT" - -echo -if [ "0" != "$?" ]; then - echo "Build error occoured!!!" - exit 1 -fi - -echo -echo "Native build action success." -exit 0 \ No newline at end of file diff --git a/plugin/plugins/umeng/proj.android/jni/Android.mk b/plugin/plugins/umeng/proj.android/jni/Android.mk deleted file mode 100644 index d63ee1a0e5..0000000000 --- a/plugin/plugins/umeng/proj.android/jni/Android.mk +++ /dev/null @@ -1,30 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := PluginUmengStatic - -LOCAL_MODULE_FILENAME := libPluginUmengStatic - -LOCAL_SRC_FILES := \ -$(addprefix ../../platform/android/, \ - AnalyticsUmeng.cpp \ -) \ - -LOCAL_CFLAGS := - -LOCAL_EXPORT_CFLAGS := - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include - -LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic - -LOCAL_LDLIBS := -landroid -LOCAL_LDLIBS += -llog - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module, protocols/proj.android/jni) - diff --git a/plugin/plugins/umeng/proj.android/jni/Application.mk b/plugin/plugins/umeng/proj.android/jni/Application.mk deleted file mode 100644 index 3b6a51c3fd..0000000000 --- a/plugin/plugins/umeng/proj.android/jni/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -# it is needed for ndk-r5 -APP_STL := gnustl_static -APP_CPPFLAGS += -frtti -APP_MODULES := PluginUmengStatic -APP_ABI :=armeabi -#APP_ABI :=x86 -#APP_ABI :=mips mips-r2 mips-r2-sf armeabi diff --git a/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java b/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java index 278d9e2c6b..5c5f33de9d 100644 --- a/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java +++ b/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java @@ -27,229 +27,255 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; +import org.json.JSONObject; + import android.content.Context; import android.util.Log; import com.umeng.analytics.MobclickAgent; public class AnalyticsUmeng implements InterfaceAnalytics{ - - private Context mContext = null; - - protected static String TAG = "AnalyticsUmeng"; - - protected static void LogE(String msg, Exception e) { - Log.e(TAG, msg, e); - e.printStackTrace(); - } + + private Context mContext = null; + + protected static String TAG = "AnalyticsUmeng"; - private static boolean isDebug = true; - protected static void LogD(String msg) { - if (isDebug) { - Log.d(TAG, msg); - } - } + private static final String KEY_EVENT = "UmengEvent"; + private static final String KEY_LABEL = "UmengLabel"; + private static final String KEY_PARAMS = "UmengParams"; + private static final String KEY_DURATION = "UmengDuration"; + + protected static void LogE(String msg, Exception e) { + Log.e(TAG, msg, e); + e.printStackTrace(); + } - public AnalyticsUmeng(Context context) { - mContext = context; - MobclickAgent.setWrapper("Cocos2d-x", "1.0"); - } - - public boolean isValid() { - return mContext != null; - } - @Override - public void startSession(String appKey) { - LogD("startSession invoked!"); - MobclickAgent.onResume(mContext); - } + private static boolean isDebug = true; + protected static void LogD(String msg) { + if (isDebug) { + Log.d(TAG, msg); + } + } - @Override - public void stopSession() { - LogD("stopSession invoked!"); - MobclickAgent.onPause(mContext); - } + public AnalyticsUmeng(Context context) { + mContext = context; + MobclickAgent.setWrapper("Cocos2d-x", "1.0"); + } + + public boolean isValid() { + return mContext != null; + } + @Override + public void startSession(String appKey) { + LogD("startSession invoked!"); + MobclickAgent.onResume(mContext); + } - @Override - public void setSessionContinueMillis(int millis) { - LogD("setSessionContinueMillis invoked!"); - MobclickAgent.setSessionContinueMillis(millis); - } + @Override + public void stopSession() { + LogD("stopSession invoked!"); + MobclickAgent.onPause(mContext); + } - @Override - public void setCaptureUncaughtException(boolean isEnabled) { - LogD("setCaptureUncaughtException invoked!"); - if (isEnabled) { - MobclickAgent.onError(mContext); - } - } + @Override + public void setSessionContinueMillis(int millis) { + LogD("setSessionContinueMillis invoked!"); + MobclickAgent.setSessionContinueMillis(millis); + } - @Override - public void setDebugMode(boolean isDebugMode) { - isDebug = isDebugMode; - MobclickAgent.setDebugMode(isDebugMode); - } + @Override + public void setCaptureUncaughtException(boolean isEnabled) { + LogD("setCaptureUncaughtException invoked!"); + if (isEnabled) { + MobclickAgent.onError(mContext); + } + } - @Override - public void logError(String errorId, String message) { - LogD("logError invoked!"); - MobclickAgent.reportError(mContext, message); - } + @Override + public void setDebugMode(boolean isDebugMode) { + isDebug = isDebugMode; + MobclickAgent.setDebugMode(isDebugMode); + } - @Override - public void logEvent(String eventId) { - LogD("logEvent(eventId) invoked!"); - MobclickAgent.onEvent(mContext, eventId); - } + @Override + public void logError(String errorId, String message) { + LogD("logError invoked!"); + MobclickAgent.reportError(mContext, message); + } - @Override - public void logEvent(String eventId, Hashtable paramMap) { - LogD("logEvent(eventId, paramMap) invoked!"); - HashMap curParam = changeTableToMap(paramMap); - MobclickAgent.onEvent(mContext, eventId, curParam); - } + @Override + public void logEvent(String eventId) { + LogD("logEvent(eventId) invoked!"); + MobclickAgent.onEvent(mContext, eventId); + } - @Override - public void logTimedEventBegin(String eventId) { - LogD("logTimedEventBegin invoked!"); - MobclickAgent.onEventBegin(mContext, eventId); - } + @Override + public void logEvent(String eventId, Hashtable paramMap) { + LogD("logEvent(eventId, paramMap) invoked!"); + HashMap curParam = changeTableToMap(paramMap); + MobclickAgent.onEvent(mContext, eventId, curParam); + } - @Override - public void logTimedEventEnd(String eventId) { - LogD("logTimedEventEnd invoked!"); - MobclickAgent.onEventEnd(mContext, eventId); - } + @Override + public void logTimedEventBegin(String eventId) { + LogD("logTimedEventBegin invoked!"); + MobclickAgent.onEventBegin(mContext, eventId); + } - @Override - public String getSDKVersion() { - LogD("getSDKVersion invoked!"); - return "UMeng no version info"; - } + @Override + public void logTimedEventEnd(String eventId) { + LogD("logTimedEventEnd invoked!"); + MobclickAgent.onEventEnd(mContext, eventId); + } - protected String getConfigParams(String key) { - LogD("getConfigParams invoked!"); - if (!isValid()) return null; - String ret = ""; - try{ - ret = MobclickAgent.getConfigParams(mContext, key); - } catch(Exception e){ - LogE("Exception in logTimedEventBegin", e); - } - return ret; - } - - protected void updateOnlineConfig() { - LogD("updateOnlineConfig invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.updateOnlineConfig(mContext); - } catch(Exception e){ - LogE("Exception in updateOnlineConfig", e); - } - } - - protected void setDefaultReportPolicy(int policy) { - LogD("setDefaultReportPolicy invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.setDefaultReportPolicy(mContext, policy); - } catch(Exception e){ - LogE("Exception in setDefaultReportPolicy", e); - } - } - - protected void logEventWithLabel(String eventId, String label) { - LogD("logEventWithLabel invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.onEvent(mContext, eventId, label); - } catch(Exception e){ - LogE("Exception in logEventWithLabel", e); - } - } - - protected void logEventWithDuration(String eventId, int duration) { - LogD("logEventWithDuration(eventId, duration) invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.onEventDuration(mContext, eventId, duration); - } catch(Exception e){ - LogE("Exception in logEventWithDuration, eventId, duration", e); - } - } - - protected void logEventWithDuration(String eventId, int duration, String label) { - LogD("logEventWithDuration(eventId, duration, label) invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.onEventDuration(mContext, eventId, label, duration); - } catch(Exception e){ - LogE("Exception in logEventWithDuration, eventId, label, duration", e); - } - } - - protected void logEventWithDuration(String eventId, int duration, Hashtable paramMap) { - LogD("logEventWithDuration(eventId, duration, paramMap) invoked!"); - if (!isValid()) return; - try{ - HashMap curMap = changeTableToMap(paramMap); - MobclickAgent.onEventDuration(mContext, eventId, curMap, duration); - } catch(Exception e){ - LogE("Exception in logEventWithDuration,eventId,duration,paramMap", e); - } - } - - protected void logTimedEventWithLabelBegin(String eventId, String label) { - LogD("logTimedEventWithLabelBegin invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.onEventBegin(mContext, eventId, label); - } catch(Exception e){ - LogE("Exception in logTimedEventWithLabelBegin", e); - } - } - - protected void logTimedEventWithLabelEnd(String eventId, String label) { - LogD("logTimedEventWithLabelEnd invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.onEventEnd(mContext, eventId, label); - } catch(Exception e){ - LogE("Exception in logTimedEventWithLabelEnd", e); - } - } - - protected void logTimedKVEventBegin(String eventId, String label, Hashtable paramMap) { - LogD("logTimedKVEventBegin invoked!"); - if (!isValid()) return; - try{ - HashMap curMap = changeTableToMap(paramMap); - MobclickAgent.onKVEventBegin(mContext, eventId, curMap, label); - } catch(Exception e){ - LogE("Exception in logTimedKVEventBegin", e); - } - } - - protected void logTimedKVEventEnd(String eventId, String label) { - LogD("logTimedKVEventEnd invoked!"); - if (!isValid()) return; - try{ - MobclickAgent.onKVEventEnd(mContext, eventId, label); - } catch(Exception e){ - LogE("Exception in logTimedKVEventEnd", e); - } - } + @Override + public String getSDKVersion() { + LogD("getSDKVersion invoked!"); + return "UMeng no version info"; + } - private HashMap changeTableToMap(Hashtable param) { - HashMap retParam = new HashMap(); - for(Iterator it = param.keySet().iterator(); it.hasNext(); ) { + protected String getConfigParams(String key) { + LogD("getConfigParams(" + key + ") invoked!"); + if (!isValid()) return null; + String ret = ""; + try{ + ret = MobclickAgent.getConfigParams(mContext, key); + } catch(Exception e){ + LogE("Exception in logTimedEventBegin", e); + } + LogD("get config : " + ret); + return ret; + } + + protected void updateOnlineConfig() { + LogD("updateOnlineConfig invoked!"); + if (!isValid()) return; + try{ + MobclickAgent.updateOnlineConfig(mContext); + } catch(Exception e){ + LogE("Exception in updateOnlineConfig", e); + } + } + + protected void logEventWithLabel(JSONObject eventInfo) { + LogD("logEventWithLabel invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString(KEY_EVENT); + String label = eventInfo.getString(KEY_LABEL); + MobclickAgent.onEvent(mContext, eventId, label); + } catch(Exception e){ + LogE("Exception in logEventWithLabel", e); + } + } + + protected void logEventWithDuration(JSONObject eventInfo) { + LogD("logEventWithDuration invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString(KEY_EVENT); + int duration = eventInfo.getInt(KEY_DURATION); + + if (eventInfo.has(KEY_LABEL)) { + String label = eventInfo.getString(KEY_LABEL); + MobclickAgent.onEventDuration(mContext, eventId, label, duration); + } else + if (eventInfo.has(KEY_PARAMS)) { + JSONObject params = eventInfo.getJSONObject(KEY_PARAMS); + HashMap curMap = getMapFromJson(params); + MobclickAgent.onEventDuration(mContext, eventId, curMap, duration); + } else { + MobclickAgent.onEventDuration(mContext, eventId, duration); + } + } catch(Exception e){ + LogE("Exception in logEventWithDuration, eventId, duration", e); + } + } + + protected void logTimedEventWithLabelBegin(JSONObject eventInfo) { + LogD("logTimedEventWithLabelBegin invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString(KEY_EVENT); + String label = eventInfo.getString(KEY_LABEL); + MobclickAgent.onEventBegin(mContext, eventId, label); + } catch(Exception e){ + LogE("Exception in logTimedEventWithLabelBegin", e); + } + } + + protected void logTimedEventWithLabelEnd(JSONObject eventInfo) { + LogD("logTimedEventWithLabelEnd invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString(KEY_EVENT); + String label = eventInfo.getString(KEY_LABEL); + MobclickAgent.onEventEnd(mContext, eventId, label); + } catch(Exception e){ + LogE("Exception in logTimedEventWithLabelEnd", e); + } + } + + protected void logTimedKVEventBegin(JSONObject eventInfo) { + LogD("logTimedKVEventBegin invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString(KEY_EVENT); + String label = eventInfo.getString(KEY_LABEL); + JSONObject params = eventInfo.getJSONObject(KEY_PARAMS); + + if (params != null) { + HashMap curMap = getMapFromJson(params); + MobclickAgent.onKVEventBegin(mContext, eventId, curMap, label); + } + } catch(Exception e){ + LogE("Exception in logTimedKVEventBegin", e); + } + } + + protected void logTimedKVEventEnd(JSONObject eventInfo) { + LogD("logTimedKVEventEnd invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString(KEY_EVENT); + String label = eventInfo.getString(KEY_LABEL); + MobclickAgent.onKVEventEnd(mContext, eventId, label); + } catch(Exception e){ + LogE("Exception in logTimedKVEventEnd", e); + } + } + + private HashMap changeTableToMap(Hashtable param) { + HashMap retParam = new HashMap(); + for(Iterator it = param.keySet().iterator(); it.hasNext(); ) { String key = it.next(); String value = param.get(key); retParam.put(key, value); } - return retParam; - } + return retParam; + } + + private HashMap getMapFromJson(JSONObject json) { + HashMap curMap = new HashMap(); + try { + @SuppressWarnings("rawtypes") + Iterator it = json.keys(); + while (it.hasNext()) { + String key = (String) it.next(); + String value = json.getString(key); + curMap.put(key, value); + } + } catch (Exception e) { + LogE("Error when get HashMap from JSONObject", e); + } + + return curMap; + } + + @Override + public String getPluginVersion() { + return "0.2.0"; + } } diff --git a/plugin/protocols/PluginParam.cpp b/plugin/protocols/PluginParam.cpp index 2891ffd80e..d747c7d9b0 100644 --- a/plugin/protocols/PluginParam.cpp +++ b/plugin/protocols/PluginParam.cpp @@ -56,4 +56,10 @@ PluginParam::PluginParam(std::map mapValue) m_type = kParamTypeMap; } +PluginParam::PluginParam(std::map strMapValue) +: m_strMapValue(strMapValue) +{ + m_type = kParamTypeStringMap; +} + }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/include/PluginParam.h b/plugin/protocols/include/PluginParam.h index fbf29498d2..f37d748cf4 100644 --- a/plugin/protocols/include/PluginParam.h +++ b/plugin/protocols/include/PluginParam.h @@ -37,6 +37,7 @@ public: PluginParam(bool bValue); PluginParam(const char* strValue); PluginParam(std::map mapValue); + PluginParam(std::map strMapValue); typedef enum{ kParamTypeNull = 0, @@ -44,7 +45,8 @@ public: kParamTypeFloat, kParamTypeBool, kParamTypeString, - kParamTypeMap + kParamTypeMap, + kParamTypeStringMap, } ParamType; inline ParamType getCurrentType() { @@ -71,6 +73,10 @@ public: return m_mapValue; } + inline std::map getStrMapValue() { + return m_strMapValue; + } + private: PluginParam(); @@ -82,6 +88,7 @@ private: bool m_bValue; std::string m_strValue; std::map m_mapValue; + std::map m_strMapValue; }; }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/include/PluginProtocol.h b/plugin/protocols/include/PluginProtocol.h index c3d97f08f4..9b75dfcbd8 100644 --- a/plugin/protocols/include/PluginProtocol.h +++ b/plugin/protocols/include/PluginProtocol.h @@ -53,6 +53,10 @@ public: * @brief methods for reflections */ void callFuncWithParam(const char* funcName, PluginParam* param); + const char* callStringFuncWithParam(const char* funcName, PluginParam* param); + int callIntFuncWithParam(const char* funcName, PluginParam* param); + bool callBoolFuncWithParam(const char* funcName, PluginParam* param); + float callFloatFuncWithParam(const char* funcName, PluginParam* param); protected: PluginProtocol() {} diff --git a/plugin/protocols/platform/android/PluginJniHelper.cpp b/plugin/protocols/platform/android/PluginJniHelper.cpp index d70198e2b1..8890ee74e7 100644 --- a/plugin/protocols/platform/android/PluginJniHelper.cpp +++ b/plugin/protocols/platform/android/PluginJniHelper.cpp @@ -109,6 +109,10 @@ extern "C" methodID = pEnv->GetStaticMethodID(classID, methodName, paramCode); if (! methodID) { + if(pEnv->ExceptionCheck()) + { + pEnv->ExceptionClear(); + } LOGD("Failed to find static method id of %s", methodName); break; } @@ -140,7 +144,11 @@ extern "C" methodID = pEnv->GetMethodID(classID, methodName, paramCode); if (! methodID) { - LOGD("Failed to find method id of %s", methodName); + if(pEnv->ExceptionCheck()) + { + pEnv->ExceptionClear(); + } + LOGD("Failed to find method %s in class %s", methodName, className); break; } @@ -190,16 +198,6 @@ void PluginJniHelper::setJavaVM(JavaVM *javaVM) m_psJavaVM = javaVM; } -string PluginJniHelper::m_externalAssetPath; - -const char* PluginJniHelper::getExternalAssetPath() { - return m_externalAssetPath.c_str(); -} - -void PluginJniHelper::setExternalAssetPath(const char * externalAssetPath) { - m_externalAssetPath = externalAssetPath; -} - jclass PluginJniHelper::getClassID(const char *className, JNIEnv *env) { return getClassID_(className, env); diff --git a/plugin/protocols/platform/android/PluginJniHelper.h b/plugin/protocols/platform/android/PluginJniHelper.h index 8c48c286bc..6fb3080b0d 100644 --- a/plugin/protocols/platform/android/PluginJniHelper.h +++ b/plugin/protocols/platform/android/PluginJniHelper.h @@ -41,8 +41,6 @@ class PluginJniHelper public: static JavaVM* getJavaVM(); static void setJavaVM(JavaVM *javaVM); - static const char* getExternalAssetPath(); - static void setExternalAssetPath(const char* externalAssetPath); static jclass getClassID(const char *className, JNIEnv *env=0); static bool getStaticMethodInfo(PluginJniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode); static bool getMethodInfo(PluginJniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode); @@ -50,7 +48,6 @@ public: private: static JavaVM *m_psJavaVM; - static std::string m_externalAssetPath; }; } diff --git a/plugin/protocols/platform/android/PluginJniMacros.h b/plugin/protocols/platform/android/PluginJniMacros.h new file mode 100644 index 0000000000..3716a904f1 --- /dev/null +++ b/plugin/protocols/platform/android/PluginJniMacros.h @@ -0,0 +1,114 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __PLUGIN_JNI_MACROS_H__ +#define __PLUGIN_JNI_MACROS_H__ + +#define return_if_fails(cond) if (!(cond)) return; +#define return_val_if_fails(cond, ret) if(!(cond)) return (ret); + +#define CALL_BASERET_JAVA_FUNC_WITH_PARAM(retType, paramCode, param, retCode, defaultRet) \ +retType ret = defaultRet; \ +return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret); \ +return_val_if_fails(paramCode != NULL && strlen(paramCode) > 0, ret); \ +PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); \ +return_val_if_fails(pData != NULL, ret); \ + \ +PluginJniMethodInfo t; \ +if (PluginJniHelper::getMethodInfo(t \ + , pData->jclassName.c_str() \ + , funcName \ + , paramCode)) \ +{ \ + if (NULL != param) \ + { \ + ret = t.env->Call##retCode##Method(pData->jobj, t.methodID, param); \ + } else { \ + ret = t.env->Call##retCode##Method(pData->jobj, t.methodID); \ + } \ + t.env->DeleteLocalRef(t.classID); \ +} \ +return ret; \ + + + +#define CALL_JAVA_FUNC(retType, retCode, defaultRet, jRetCode) \ +retType ret = defaultRet; \ +PluginJavaData* pData = PluginUtils::getPluginJavaData(this); \ +if (NULL == pData) { \ + PluginUtils::outputLog("PluginProtocol", "Can't find java data for plugin : %s", this->getPluginName()); \ + return ret; \ +} \ + \ +std::string paramCode; \ +if (NULL == param) \ +{ \ + paramCode = "()"; \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), NULL); \ +} else \ +{ \ + switch(param->getCurrentType()) \ + { \ + case PluginParam::kParamTypeInt: \ + paramCode = "(I)"; \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), param->getIntValue()); \ + break; \ + case PluginParam::kParamTypeFloat: \ + paramCode = "(F)"; \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), param->getFloatValue()); \ + break; \ + case PluginParam::kParamTypeBool: \ + paramCode = "(Z)"; \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), param->getBoolValue()); \ + break; \ + case PluginParam::kParamTypeString: \ + { \ + jstring jstr = PluginUtils::getEnv()->NewStringUTF(param->getStringValue()); \ + paramCode = "(Ljava/lang/String;)"; \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), jstr); \ + PluginUtils::getEnv()->DeleteLocalRef(jstr); \ + } \ + break; \ + case PluginParam::kParamTypeStringMap: \ + case PluginParam::kParamTypeMap: \ + { \ + jobject jMap = PluginUtils::getJObjFromParam(param); \ + paramCode = "(Lorg/json/JSONObject;)"; \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), jMap); \ + PluginUtils::getEnv()->DeleteLocalRef(jMap); \ + } \ + break; \ + default: \ + break; \ + } \ +} \ +return ret; \ + + +#endif // __PLUGIN_JNI_MACROS_H__ diff --git a/plugin/protocols/platform/android/PluginProtocol.cpp b/plugin/protocols/platform/android/PluginProtocol.cpp index 52983f9f9c..4f6ec87eca 100644 --- a/plugin/protocols/platform/android/PluginProtocol.cpp +++ b/plugin/protocols/platform/android/PluginProtocol.cpp @@ -28,41 +28,41 @@ namespace cocos2d { namespace plugin { PluginProtocol::~PluginProtocol() { - PluginUtils::erasePluginJavaData(this); + PluginUtils::erasePluginJavaData(this); } const char* PluginProtocol::getPluginVersion() { - std::string verName; + std::string verName; - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getPluginVersion" - , "()Ljava/lang/String;")) - { - jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); - verName = PluginJniHelper::jstring2string(ret); - } - return verName.c_str(); + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "getPluginVersion" + , "()Ljava/lang/String;")) + { + jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); + verName = PluginJniHelper::jstring2string(ret); + } + return verName.c_str(); } const char* PluginProtocol::getSDKVersion() { - std::string verName; + std::string verName; - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - PluginJniMethodInfo t; - if (PluginJniHelper::getMethodInfo(t - , pData->jclassName.c_str() - , "getSDKVersion" - , "()Ljava/lang/String;")) - { - jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); - verName = PluginJniHelper::jstring2string(ret); - } - return verName.c_str(); + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + PluginJniMethodInfo t; + if (PluginJniHelper::getMethodInfo(t + , pData->jclassName.c_str() + , "getSDKVersion" + , "()Ljava/lang/String;")) + { + jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID)); + verName = PluginJniHelper::jstring2string(ret); + } + return verName.c_str(); } void PluginProtocol::setDebugMode(bool isDebugMode) @@ -72,46 +72,67 @@ void PluginProtocol::setDebugMode(bool isDebugMode) void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) { - PluginJavaData* pData = PluginUtils::getPluginJavaData(this); - if (NULL == pData) { - PluginUtils::outputLog("PluginProtocol", "Can't find java data for plugin : %s", this->getPluginName()); - return; - } + PluginJavaData* pData = PluginUtils::getPluginJavaData(this); + if (NULL == pData) { + PluginUtils::outputLog("PluginProtocol", "Can't find java data for plugin : %s", this->getPluginName()); + return; + } - if (NULL == param) - { - PluginUtils::callJavaFunctionWithName(this, funcName); - } else - { - switch(param->getCurrentType()) - { - case PluginParam::kParamTypeInt: - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(I)V", param->getIntValue()); - break; - case PluginParam::kParamTypeFloat: - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(F)V", param->getFloatValue()); - break; - case PluginParam::kParamTypeBool: - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Z)V", param->getBoolValue()); - break; - case PluginParam::kParamTypeString: - { - jstring jstr = PluginUtils::getEnv()->NewStringUTF(param->getStringValue()); - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Ljava/lang/String;)V", jstr); - PluginUtils::getEnv()->DeleteLocalRef(jstr); - } - break; - case PluginParam::kParamTypeMap: - { - jobject jMap = PluginUtils::getJObjFromParam(param); - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Lorg/json/JSONObject;)V", jMap); - PluginUtils::getEnv()->DeleteLocalRef(jMap); - } - break; - default: - break; - } - } + if (NULL == param) + { + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "()V", NULL); + } else + { + switch(param->getCurrentType()) + { + case PluginParam::kParamTypeInt: + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(I)V", param->getIntValue()); + break; + case PluginParam::kParamTypeFloat: + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(F)V", param->getFloatValue()); + break; + case PluginParam::kParamTypeBool: + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Z)V", param->getBoolValue()); + break; + case PluginParam::kParamTypeString: + { + jstring jstr = PluginUtils::getEnv()->NewStringUTF(param->getStringValue()); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Ljava/lang/String;)V", jstr); + PluginUtils::getEnv()->DeleteLocalRef(jstr); + } + break; + case PluginParam::kParamTypeStringMap: + case PluginParam::kParamTypeMap: + { + jobject jMap = PluginUtils::getJObjFromParam(param); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Lorg/json/JSONObject;)V", jMap); + PluginUtils::getEnv()->DeleteLocalRef(jMap); + } + break; + default: + break; + } + } +} + +const char* PluginProtocol::callStringFuncWithParam(const char* funcName, PluginParam* param) +{ + CALL_JAVA_FUNC(const char*, String, "", "Ljava/lang/String;") +} + +int PluginProtocol::callIntFuncWithParam(const char* funcName, PluginParam* param) +{ + CALL_JAVA_FUNC(int, Int, 0, "I") +} + +bool PluginProtocol::callBoolFuncWithParam(const char* funcName, PluginParam* param) +{ + CALL_JAVA_FUNC(bool, Bool, false, "Z") +} + +float PluginProtocol::callFloatFuncWithParam(const char* funcName, PluginParam* param) +{ + CALL_JAVA_FUNC(float, Float, 0.0f, "F") } }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/android/PluginUtils.cpp b/plugin/protocols/platform/android/PluginUtils.cpp index 6437e9ff01..ae68b3ecb3 100644 --- a/plugin/protocols/platform/android/PluginUtils.cpp +++ b/plugin/protocols/platform/android/PluginUtils.cpp @@ -31,20 +31,21 @@ namespace cocos2d { namespace plugin { #define JAVAVM cocos2d::PluginJniHelper::getJavaVM() -jobject PluginUtils::createJavaMapObject(PluginJniMethodInfo&t, std::map* paramMap) +jobject PluginUtils::createJavaMapObject(std::map* paramMap) { - jclass class_Hashtable = t.env->FindClass("java/util/Hashtable"); - jmethodID construct_method = t.env->GetMethodID( class_Hashtable, "","()V"); - jobject obj_Map = t.env->NewObject( class_Hashtable, construct_method, ""); + JNIEnv* env = getEnv(); + jclass class_Hashtable = env->FindClass("java/util/Hashtable"); + jmethodID construct_method = env->GetMethodID( class_Hashtable, "","()V"); + jobject obj_Map = env->NewObject( class_Hashtable, construct_method, ""); if (paramMap != NULL) { - jmethodID add_method= t.env->GetMethodID( class_Hashtable,"put","(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + jmethodID add_method= env->GetMethodID( class_Hashtable,"put","(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); for (std::map::const_iterator it = paramMap->begin(); it != paramMap->end(); ++it) { - t.env->CallObjectMethod(obj_Map, add_method, t.env->NewStringUTF(it->first.c_str()), t.env->NewStringUTF(it->second.c_str())); + env->CallObjectMethod(obj_Map, add_method, env->NewStringUTF(it->first.c_str()), env->NewStringUTF(it->second.c_str())); } } - t.env->DeleteLocalRef(class_Hashtable); + env->DeleteLocalRef(class_Hashtable); return obj_Map; } @@ -193,6 +194,30 @@ jobject PluginUtils::getJObjFromParam(PluginParam* param) case PluginParam::kParamTypeString: obj = env->NewStringUTF(param->getStringValue()); break; + case PluginParam::kParamTypeStringMap: + { + jclass cls = env->FindClass("org/json/JSONObject"); + jmethodID mid = env->GetMethodID(cls,"","()V"); + obj = env->NewObject(cls,mid); + std::map::iterator it; + std::map mapParam = param->getStrMapValue(); + for (it = mapParam.begin(); it != mapParam.end(); it++) + { + PluginJniMethodInfo tInfo; + if (PluginJniHelper::getMethodInfo(tInfo, "org/json/JSONObject", "put", "(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;")) + { + jstring strKey = tInfo.env->NewStringUTF(it->first.c_str()); + jstring strValue = tInfo.env->NewStringUTF(it->second.c_str()); + + tInfo.env->CallObjectMethod(obj, tInfo.methodID, strKey, strValue); + tInfo.env->DeleteLocalRef(tInfo.classID); + + tInfo.env->DeleteLocalRef(strKey); + tInfo.env->DeleteLocalRef(strValue); + } + } + } + break; case PluginParam::kParamTypeMap: { jclass cls = env->FindClass("org/json/JSONObject"); @@ -206,13 +231,13 @@ jobject PluginUtils::getJObjFromParam(PluginParam* param) PluginJniMethodInfo tInfo; if (PluginJniHelper::getMethodInfo(tInfo, "org/json/JSONObject", "put", "(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;")) { - jstring strKey = env->NewStringUTF(it->first.c_str()); + jstring strKey = tInfo.env->NewStringUTF(it->first.c_str()); jobject objValue = PluginUtils::getJObjFromParam(it->second); tInfo.env->CallObjectMethod(obj, tInfo.methodID, strKey, objValue); tInfo.env->DeleteLocalRef(tInfo.classID); - PluginUtils::getEnv()->DeleteLocalRef(strKey); + tInfo.env->DeleteLocalRef(strKey); PluginUtils::getEnv()->DeleteLocalRef(objValue); } } diff --git a/plugin/protocols/platform/android/PluginUtils.h b/plugin/protocols/platform/android/PluginUtils.h index db9c9ebf99..8d4e1465d1 100644 --- a/plugin/protocols/platform/android/PluginUtils.h +++ b/plugin/protocols/platform/android/PluginUtils.h @@ -29,16 +29,14 @@ THE SOFTWARE. #include "PluginProtocol.h" #include #include "PluginParam.h" +#include "PluginJniMacros.h" namespace cocos2d { namespace plugin { -#define return_if_fails(cond) if (!(cond)) return; -#define return_val_if_fails(cond, ret) if(!(cond)) return (ret); - class PluginUtils { public: - static jobject createJavaMapObject(PluginJniMethodInfo&t, std::map* paramMap); + static jobject createJavaMapObject(std::map* paramMap); static void initJavaPlugin(PluginProtocol* pPlugin, jobject jObj, const char* className); static JNIEnv* getEnv(); @@ -50,6 +48,7 @@ public: static jobject getJObjFromParam(PluginParam* param); + // methods have no return value template static void callJavaFunctionWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) { @@ -64,26 +63,64 @@ public: , funcName , paramCode)) { - t.env->CallVoidMethod(pData->jobj, t.methodID, param); + if (param != NULL) + { + t.env->CallVoidMethod(pData->jobj, t.methodID, param); + } else { + t.env->CallVoidMethod(pData->jobj, t.methodID); + } t.env->DeleteLocalRef(t.classID); } } - static void callJavaFunctionWithName(PluginProtocol* thiz, const char* funcName) + // methods return value is string + template + static const char* callJavaStringFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) { - return_if_fails(funcName != NULL && strlen(funcName) > 0); + const char* ret = ""; + return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret); + return_val_if_fails(paramCode != NULL && strlen(paramCode) > 0, ret); PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz); - return_if_fails(pData != NULL); + return_val_if_fails(pData != NULL, ret); PluginJniMethodInfo t; if (PluginJniHelper::getMethodInfo(t , pData->jclassName.c_str() , funcName - , "()V")) + , paramCode)) { - t.env->CallVoidMethod(pData->jobj, t.methodID); + jstring strRet = NULL; + if (param != NULL) + { + strRet = (jstring) t.env->CallObjectMethod(pData->jobj, t.methodID, param); + } else { + strRet = (jstring) t.env->CallObjectMethod(pData->jobj, t.methodID); + } + ret = PluginJniHelper::jstring2string(strRet).c_str(); t.env->DeleteLocalRef(t.classID); } + return ret; + } + + // methods return value is int + template + static int callJavaIntFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) + { + CALL_BASERET_JAVA_FUNC_WITH_PARAM(int, paramCode, param, Int, 0) + } + + // methods return value is float + template + static float callJavaFloatFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) + { + CALL_BASERET_JAVA_FUNC_WITH_PARAM(float, paramCode, param, Float, 0.0f) + } + + // methods return value is bool + template + static bool callJavaBoolFuncWithName_oneParam(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) + { + CALL_BASERET_JAVA_FUNC_WITH_PARAM(bool, paramCode, param, Boolean, false) } static void outputLog(const char* logTag, const char* pFormat, ...); diff --git a/plugin/protocols/platform/android/ProtocolAds.cpp b/plugin/protocols/platform/android/ProtocolAds.cpp index 65b859852c..8bdc34029c 100644 --- a/plugin/protocols/platform/android/ProtocolAds.cpp +++ b/plugin/protocols/platform/android/ProtocolAds.cpp @@ -88,7 +88,7 @@ void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo) , "(Ljava/util/Hashtable;)V")) { // generate the hashtable from map - jobject obj_Map = PluginUtils::createJavaMapObject(t, &devInfo); + jobject obj_Map = PluginUtils::createJavaMapObject(&devInfo); // invoke java method t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); diff --git a/plugin/protocols/platform/android/ProtocolAnalytics.cpp b/plugin/protocols/platform/android/ProtocolAnalytics.cpp index 20174d08ea..a7cd8eca6c 100644 --- a/plugin/protocols/platform/android/ProtocolAnalytics.cpp +++ b/plugin/protocols/platform/android/ProtocolAnalytics.cpp @@ -58,7 +58,7 @@ static void callJavaFunctionWithName_string_map(ProtocolAnalytics* thiz, const c , "(Ljava/lang/String;Ljava/util/Hashtable;)V")) { jstring jeventId = t.env->NewStringUTF(keyParam); - jobject obj_Map = PluginUtils::createJavaMapObject(t, paramMap); + jobject obj_Map = PluginUtils::createJavaMapObject(paramMap); t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, obj_Map); t.env->DeleteLocalRef(jeventId); t.env->DeleteLocalRef(obj_Map); diff --git a/plugin/protocols/platform/android/ProtocolIAP.cpp b/plugin/protocols/platform/android/ProtocolIAP.cpp index b12fb1e9c3..270e8ea44f 100644 --- a/plugin/protocols/platform/android/ProtocolIAP.cpp +++ b/plugin/protocols/platform/android/ProtocolIAP.cpp @@ -76,7 +76,7 @@ void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo) , "(Ljava/util/Hashtable;)V")) { // generate the hashtable from map - jobject obj_Map = PluginUtils::createJavaMapObject(t, &devInfo); + jobject obj_Map = PluginUtils::createJavaMapObject(&devInfo); // invoke java method t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); @@ -116,7 +116,7 @@ void ProtocolIAP::payForProduct(TProductInfo info) , "(Ljava/util/Hashtable;)V")) { // generate the hashtable from map - jobject obj_Map = PluginUtils::createJavaMapObject(t, &info); + jobject obj_Map = PluginUtils::createJavaMapObject(&info); // invoke java method t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp index fab901c89f..8c933d3380 100755 --- a/plugin/protocols/platform/android/ProtocolSocial.cpp +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -74,7 +74,7 @@ void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo) , "(Ljava/util/Hashtable;)V")) { // generate the hashtable from map - jobject obj_Map = PluginUtils::createJavaMapObject(t, &devInfo); + jobject obj_Map = PluginUtils::createJavaMapObject(&devInfo); // invoke java method t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); @@ -105,7 +105,7 @@ void ProtocolSocial::share(TShareInfo info) , "(Ljava/util/Hashtable;)V")) { // generate the hashtable from map - jobject obj_Map = PluginUtils::createJavaMapObject(t, &info); + jobject obj_Map = PluginUtils::createJavaMapObject(&info); // invoke java method t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map); diff --git a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp index d964b52fc3..3aab1d92cb 100644 --- a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp +++ b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp @@ -25,8 +25,7 @@ THE SOFTWARE. #include "cocos2d.h" #include "HelloWorldScene.h" #include "PluginManager.h" -#include "AnalyticsFlurry.h" -#include "AnalyticsUmeng.h" +#include "ProtocolAnalytics.h" using namespace cocos2d::plugin; USING_NS_CC; @@ -91,25 +90,27 @@ bool AppDelegate::applicationDidFinishLaunching() const char* sdkVer = g_pAnalytics->getSDKVersion(); CCLog("SDK version : %s", sdkVer); - AnalyticsUmeng* pUmeng = dynamic_cast(g_pAnalytics); - AnalyticsFlurry* pFlurry = dynamic_cast(g_pAnalytics); - if (pUmeng != NULL) - { - pUmeng->updateOnlineConfig(); - pUmeng->setDefaultReportPolicy(AnalyticsUmeng::REALTIME); - } + g_pAnalytics->callFuncWithParam("updateOnlineConfig", NULL); - if (pFlurry != NULL) - { - pFlurry->setReportLocation(true); - pFlurry->logPageView(); - // const char* sdkVersion = pFlurry->getSDKVersion(); - pFlurry->setVersionName("1.1"); - pFlurry->setAge(20); - pFlurry->setGender(AnalyticsFlurry::MALE); - pFlurry->setUserId("123456"); - pFlurry->setUseHttps(false); - } + PluginParam pParam1(true); + g_pAnalytics->callFuncWithParam("setReportLocation", &pParam1); + + g_pAnalytics->callFuncWithParam("logPageView", NULL); + + PluginParam pParam2("1.1"); + g_pAnalytics->callFuncWithParam("setVersionName", &pParam2); + + PluginParam pParam3(20); + g_pAnalytics->callFuncWithParam("setAge", &pParam3); + + PluginParam pParam4(1); + g_pAnalytics->callFuncWithParam("setGender", &pParam4); + + PluginParam pParam5("123456"); + g_pAnalytics->callFuncWithParam("setUserId", &pParam5); + + PluginParam pParam6(false); + g_pAnalytics->callFuncWithParam("setUseHttps", &pParam6); // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); diff --git a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp index df76783ab8..e2771759b7 100644 --- a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "HelloWorldScene.h" #include "PluginManager.h" -#include "AnalyticsFlurry.h" -#include "AnalyticsUmeng.h" +#include "ProtocolAnalytics.h" #include "AppDelegate.h" using namespace cocos2d; @@ -112,7 +111,7 @@ bool HelloWorld::init() } std::string strName = g_pAnalytics->getPluginName(); - std::string strVer = g_pAnalytics->getPluginVersion(); + std::string strVer = g_pAnalytics->getSDKVersion(); char ret[256] = { 0 }; sprintf(ret, "Plugin : %s, Ver : %s", strName.c_str(), strVer.c_str()); CCLabelTTF* pLabel = CCLabelTTF::create(ret, "Arial", 18, CCSizeMake(size.width, 0), kCCTextAlignmentCenter); @@ -139,8 +138,6 @@ void HelloWorld::reloadPluginMenuCallback(CCObject* pSender) void HelloWorld::eventMenuCallback(CCObject* pSender) { CCMenuItemLabel* pMenuItem = (CCMenuItemLabel*)pSender; - AnalyticsUmeng* pUmeng = dynamic_cast(g_pAnalytics); - AnalyticsFlurry* pFlurry = dynamic_cast(g_pAnalytics); switch (pMenuItem->getTag()) { @@ -160,64 +157,100 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) break; case TAG_LOG_ONLINE_CONFIG: { - if (pUmeng != NULL) - { - CCLog("Online config = %s", pUmeng->getConfigParams("abc")); - } - else - { - CCLog("Now is not using umeng!"); - } + PluginParam param("abc"); + CCLog("Online config = %s", g_pAnalytics->callStringFuncWithParam("getConfigParams", ¶m)); } break; case TAG_LOG_EVENT_ID_DURATION: { - if (pUmeng != NULL) - { - pUmeng->logEventWithDuration("book", 12000); - pUmeng->logEventWithDuration("book", 23000, "chapter1"); - LogEventParamMap paramMap; - paramMap.insert(LogEventParamPair("type", "popular")); - paramMap.insert(LogEventParamPair("artist", "JJLin")); - pUmeng->logEventWithDuration("music", 2330000, ¶mMap); - } - else - { - CCLog("Now is not using umeng!"); - } + PluginParam event1("book"); + PluginParam dura1(12000); + std::map param1; + param1["UmengEvent"] = &event1; + param1["UmengDuration"] = &dura1; + PluginParam param1Map(param1); + g_pAnalytics->callFuncWithParam("logEventWithDuration", ¶m1Map); + + PluginParam event2("book"); + PluginParam dura2(12000); + PluginParam label("chapter1"); + std::map param2; + param2["UmengEvent"] = &event2; + param2["UmengDuration"] = &dura2; + param2["UmengLabel"] = &label; + PluginParam param2Map(param2); + g_pAnalytics->callFuncWithParam("logEventWithDuration", ¶m2Map); + + PluginParam event3("music"); + PluginParam dura3(2330000); + LogEventParamMap paramMap; + paramMap.insert(LogEventParamPair("type", "popular")); + paramMap.insert(LogEventParamPair("artist", "JJLin")); + PluginParam mapValue(paramMap); + + std::map param3; + param3["UmengEvent"] = &event3; + param3["UmengDuration"] = &dura3; + param3["UmengParams"] = &mapValue; + PluginParam param3Map(param3); + g_pAnalytics->callFuncWithParam("logEventWithDuration", ¶m3Map); } break; case TAG_LOG_EVENT_BEGIN: { g_pAnalytics->logTimedEventBegin("music"); + PluginParam event1("music"); + PluginParam label1("one"); + std::map param1; + param1["UmengEvent"] = &event1; + param1["UmengLabel"] = &label1; + PluginParam param1Map(param1); + g_pAnalytics->callFuncWithParam("logTimedEventWithLabelBegin", ¶m1Map); + + PluginParam event2("music"); + PluginParam label2("flag0"); LogEventParamMap paramMap; paramMap.insert(LogEventParamPair("type", "popular")); paramMap.insert(LogEventParamPair("artist", "JJLin")); + PluginParam mapValue(paramMap); + std::map param2; + param2["UmengEvent"] = &event2; + param2["UmengLabel"] = &label2; + param2["UmengParams"] = &mapValue; + PluginParam param2Map(param2); + g_pAnalytics->callFuncWithParam("logTimedKVEventBegin", ¶m2Map); - if (pUmeng != NULL) - { - pUmeng->logTimedEventWithLabelBegin("music", "one"); - pUmeng->logTimedKVEventBegin("music", "flag0", ¶mMap); - } - else if (pFlurry != NULL) - { - pFlurry->logTimedEventBegin("music-kv", ¶mMap); - } + PluginParam event3("music-kv"); + std::map param3; + param3["FlurryEvent"] = &event3; + param3["FlurryParams"] = &mapValue; + PluginParam param3Map(param3); + g_pAnalytics->callFuncWithParam("logTimedEventBegin", ¶m3Map); } break; case TAG_LOG_EVENT_END: { g_pAnalytics->logTimedEventEnd("music"); - if (pUmeng != NULL) - { - pUmeng->logTimedEventWithLabelEnd("music", "one"); - pUmeng->logTimedKVEventEnd("music", "flag0"); - } - else if (pFlurry != NULL) - { - pFlurry->logTimedEventEnd("music-kv"); - } + + PluginParam event1("music"); + PluginParam label1("one"); + std::map param1; + param1["UmengEvent"] = &event1; + param1["UmengLabel"] = &label1; + PluginParam param1Map(param1); + g_pAnalytics->callFuncWithParam("logTimedEventWithLabelEnd", ¶m1Map); + + PluginParam event2("music"); + PluginParam label2("flag0"); + std::map param2; + param2["UmengEvent"] = &event2; + param2["UmengLabel"] = &label2; + PluginParam param2Map(param2); + g_pAnalytics->callFuncWithParam("logTimedKVEventEnd", ¶m2Map); + + PluginParam event3("music-kv"); + g_pAnalytics->callFuncWithParam("logTimedEventEnd", &event3); } break; case TAG_MAKE_ME_CRASH: diff --git a/plugin/samples/HelloAnalytics/proj.android/.project b/plugin/samples/HelloAnalytics/proj.android/.project index f6032c3714..242b4d396f 100644 --- a/plugin/samples/HelloAnalytics/proj.android/.project +++ b/plugin/samples/HelloAnalytics/proj.android/.project @@ -31,6 +31,11 @@ org.eclipse.jdt.core.javanature + + Classes + 2 + PARENT-1-PROJECT_LOC/Classes + publish 2 diff --git a/plugin/samples/HelloAnalytics/proj.android/jni/Android.mk b/plugin/samples/HelloAnalytics/proj.android/jni/Android.mk index 25eba89294..6940ebe855 100644 --- a/plugin/samples/HelloAnalytics/proj.android/jni/Android.mk +++ b/plugin/samples/HelloAnalytics/proj.android/jni/Android.mk @@ -13,11 +13,9 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static \ - PluginFlurryStatic PluginUmengStatic PluginProtocolStatic + PluginProtocolStatic include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) \ -$(call import-module,plugins/flurry/android) \ -$(call import-module,plugins/umeng/android) \ $(call import-module,protocols/android) From a6346a80363096d5d1b34c69410ee5d7ecdcf104 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Wed, 29 May 2013 14:22:08 +0800 Subject: [PATCH 07/18] issue #2224 : Use variable argument functions in the implementation of reflection. --- .../org/cocos2dx/plugin/AnalyticsFlurry.java | 9 +-- .../org/cocos2dx/plugin/AnalyticsUmeng.java | 75 ++++++++++++------- plugin/protocols/include/PluginProtocol.h | 10 +-- .../platform/android/PluginJniMacros.h | 51 ++++++++++--- .../platform/android/PluginProtocol.cpp | 58 +++++++++++--- .../HelloAnalytics/Classes/AppDelegate.cpp | 12 +-- .../Classes/HelloWorldScene.cpp | 56 +++----------- 7 files changed, 158 insertions(+), 113 deletions(-) diff --git a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java index d1091f2bbf..4019f25192 100644 --- a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java +++ b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java @@ -38,9 +38,6 @@ public class AnalyticsFlurry implements InterfaceAnalytics { private Context mContext = null; protected static String TAG = "AnalyticsFlurry"; - private static final String KEY_EVENT = "FlurryEvent"; - private static final String KEY_PARAMS = "FlurryParams"; - protected static void LogE(String msg, Exception e) { Log.e(TAG, msg, e); e.printStackTrace(); @@ -136,11 +133,11 @@ public class AnalyticsFlurry implements InterfaceAnalytics { protected void logTimedEventBegin(JSONObject eventInfo) { LogD("logTimedEventBegin invoked!"); try{ - String eventId = eventInfo.getString(KEY_EVENT); + String eventId = eventInfo.getString("Param1"); - if (eventInfo.has("FlurryParams")) + if (eventInfo.has("Param2")) { - JSONObject params = eventInfo.getJSONObject(KEY_PARAMS); + JSONObject params = eventInfo.getJSONObject("Param2"); @SuppressWarnings("rawtypes") Iterator it = params.keys(); Hashtable paramMap = new Hashtable(); diff --git a/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java b/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java index 5c5f33de9d..108e2bedcc 100644 --- a/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java +++ b/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java @@ -40,11 +40,6 @@ public class AnalyticsUmeng implements InterfaceAnalytics{ protected static String TAG = "AnalyticsUmeng"; - private static final String KEY_EVENT = "UmengEvent"; - private static final String KEY_LABEL = "UmengLabel"; - private static final String KEY_PARAMS = "UmengParams"; - private static final String KEY_DURATION = "UmengDuration"; - protected static void LogE(String msg, Exception e) { Log.e(TAG, msg, e); e.printStackTrace(); @@ -161,34 +156,58 @@ public class AnalyticsUmeng implements InterfaceAnalytics{ LogD("logEventWithLabel invoked! event : " + eventInfo.toString()); if (!isValid()) return; try{ - String eventId = eventInfo.getString(KEY_EVENT); - String label = eventInfo.getString(KEY_LABEL); + String eventId = eventInfo.getString("Param1"); + String label = eventInfo.getString("Param2"); MobclickAgent.onEvent(mContext, eventId, label); } catch(Exception e){ LogE("Exception in logEventWithLabel", e); } } - protected void logEventWithDuration(JSONObject eventInfo) { - LogD("logEventWithDuration invoked! event : " + eventInfo.toString()); + protected void logEventWithDurationLabel(JSONObject eventInfo) { + LogD("logEventWithDurationLabel invoked! event : " + eventInfo.toString()); if (!isValid()) return; - try{ - String eventId = eventInfo.getString(KEY_EVENT); - int duration = eventInfo.getInt(KEY_DURATION); - - if (eventInfo.has(KEY_LABEL)) { - String label = eventInfo.getString(KEY_LABEL); + try { + String eventId = eventInfo.getString("Param1"); + int duration = eventInfo.getInt("Param2"); + if (eventInfo.has("Param3")) { + String label = eventInfo.getString("Param3"); MobclickAgent.onEventDuration(mContext, eventId, label, duration); - } else - if (eventInfo.has(KEY_PARAMS)) { - JSONObject params = eventInfo.getJSONObject(KEY_PARAMS); + } else { + MobclickAgent.onEventDuration(mContext, eventId, duration); + } + } catch (Exception e) { + LogE("Exception in logEventWithDurationLabel", e); + } + } + + protected void logEventWithDurationParams(JSONObject eventInfo) { + LogD("logEventWithDurationParams invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try { + String eventId = eventInfo.getString("Param1"); + int duration = eventInfo.getInt("Param2"); + if (eventInfo.has("Param3")) { + JSONObject params = eventInfo.getJSONObject("Param3"); HashMap curMap = getMapFromJson(params); MobclickAgent.onEventDuration(mContext, eventId, curMap, duration); } else { MobclickAgent.onEventDuration(mContext, eventId, duration); } + } catch (Exception e) { + LogE("Exception in logEventWithDurationParams", e); + } + } + + protected void logEventWithDuration(JSONObject eventInfo) { + LogD("logEventWithDuration invoked! event : " + eventInfo.toString()); + if (!isValid()) return; + try{ + String eventId = eventInfo.getString("Param1"); + int duration = eventInfo.getInt("Param2"); + MobclickAgent.onEventDuration(mContext, eventId, duration); } catch(Exception e){ - LogE("Exception in logEventWithDuration, eventId, duration", e); + LogE("Exception in logEventWithDuration", e); } } @@ -196,8 +215,8 @@ public class AnalyticsUmeng implements InterfaceAnalytics{ LogD("logTimedEventWithLabelBegin invoked! event : " + eventInfo.toString()); if (!isValid()) return; try{ - String eventId = eventInfo.getString(KEY_EVENT); - String label = eventInfo.getString(KEY_LABEL); + String eventId = eventInfo.getString("Param1"); + String label = eventInfo.getString("Param2"); MobclickAgent.onEventBegin(mContext, eventId, label); } catch(Exception e){ LogE("Exception in logTimedEventWithLabelBegin", e); @@ -208,8 +227,8 @@ public class AnalyticsUmeng implements InterfaceAnalytics{ LogD("logTimedEventWithLabelEnd invoked! event : " + eventInfo.toString()); if (!isValid()) return; try{ - String eventId = eventInfo.getString(KEY_EVENT); - String label = eventInfo.getString(KEY_LABEL); + String eventId = eventInfo.getString("Param1"); + String label = eventInfo.getString("Param2"); MobclickAgent.onEventEnd(mContext, eventId, label); } catch(Exception e){ LogE("Exception in logTimedEventWithLabelEnd", e); @@ -220,9 +239,9 @@ public class AnalyticsUmeng implements InterfaceAnalytics{ LogD("logTimedKVEventBegin invoked! event : " + eventInfo.toString()); if (!isValid()) return; try{ - String eventId = eventInfo.getString(KEY_EVENT); - String label = eventInfo.getString(KEY_LABEL); - JSONObject params = eventInfo.getJSONObject(KEY_PARAMS); + String eventId = eventInfo.getString("Param1"); + String label = eventInfo.getString("Param2"); + JSONObject params = eventInfo.getJSONObject("Param3"); if (params != null) { HashMap curMap = getMapFromJson(params); @@ -237,8 +256,8 @@ public class AnalyticsUmeng implements InterfaceAnalytics{ LogD("logTimedKVEventEnd invoked! event : " + eventInfo.toString()); if (!isValid()) return; try{ - String eventId = eventInfo.getString(KEY_EVENT); - String label = eventInfo.getString(KEY_LABEL); + String eventId = eventInfo.getString("Param1"); + String label = eventInfo.getString("Param2"); MobclickAgent.onKVEventEnd(mContext, eventId, label); } catch(Exception e){ LogE("Exception in logTimedKVEventEnd", e); diff --git a/plugin/protocols/include/PluginProtocol.h b/plugin/protocols/include/PluginProtocol.h index 9b75dfcbd8..d385db1ee7 100644 --- a/plugin/protocols/include/PluginProtocol.h +++ b/plugin/protocols/include/PluginProtocol.h @@ -52,11 +52,11 @@ public: /** * @brief methods for reflections */ - void callFuncWithParam(const char* funcName, PluginParam* param); - const char* callStringFuncWithParam(const char* funcName, PluginParam* param); - int callIntFuncWithParam(const char* funcName, PluginParam* param); - bool callBoolFuncWithParam(const char* funcName, PluginParam* param); - float callFloatFuncWithParam(const char* funcName, PluginParam* param); + void callFuncWithParam(const char* funcName, PluginParam* param, ...); + const char* callStringFuncWithParam(const char* funcName, PluginParam* param, ...); + int callIntFuncWithParam(const char* funcName, PluginParam* param, ...); + bool callBoolFuncWithParam(const char* funcName, PluginParam* param, ...); + float callFloatFuncWithParam(const char* funcName, PluginParam* param, ...); protected: PluginProtocol() {} diff --git a/plugin/protocols/platform/android/PluginJniMacros.h b/plugin/protocols/platform/android/PluginJniMacros.h index 3716a904f1..ef56b1e771 100644 --- a/plugin/protocols/platform/android/PluginJniMacros.h +++ b/plugin/protocols/platform/android/PluginJniMacros.h @@ -68,26 +68,57 @@ if (NULL == param) ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), NULL); \ } else \ { \ - switch(param->getCurrentType()) \ + PluginParam* pRetParam = NULL; \ + std::map allParams; \ + va_list argp; \ + int argno = 0; \ + PluginParam* pArg = NULL; \ + \ + allParams["Param1"] = param; \ + va_start( argp, param ); \ + while (1) \ + { \ + pArg = va_arg(argp, PluginParam*); \ + if (pArg == NULL) \ + { \ + break; \ + } \ + argno++; \ + char strKey[8] = { 0 }; \ + sprintf(strKey, "Param%d", argno + 1); \ + allParams[strKey] = pArg; \ + } \ + va_end(argp); \ + \ + PluginParam tempParam(allParams); \ + if (argno == 0) \ + { \ + pRetParam = param; \ + } \ + else \ + { \ + pRetParam = &tempParam; \ + } \ + switch(pRetParam->getCurrentType()) \ { \ case PluginParam::kParamTypeInt: \ paramCode = "(I)"; \ - paramCode.append(jRetCode); \ - ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), param->getIntValue()); \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), pRetParam->getIntValue()); \ break; \ case PluginParam::kParamTypeFloat: \ paramCode = "(F)"; \ - paramCode.append(jRetCode); \ - ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), param->getFloatValue()); \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), pRetParam->getFloatValue()); \ break; \ case PluginParam::kParamTypeBool: \ paramCode = "(Z)"; \ - paramCode.append(jRetCode); \ - ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), param->getBoolValue()); \ + paramCode.append(jRetCode); \ + ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), pRetParam->getBoolValue()); \ break; \ case PluginParam::kParamTypeString: \ { \ - jstring jstr = PluginUtils::getEnv()->NewStringUTF(param->getStringValue()); \ + jstring jstr = PluginUtils::getEnv()->NewStringUTF(pRetParam->getStringValue()); \ paramCode = "(Ljava/lang/String;)"; \ paramCode.append(jRetCode); \ ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), jstr); \ @@ -97,9 +128,9 @@ if (NULL == param) case PluginParam::kParamTypeStringMap: \ case PluginParam::kParamTypeMap: \ { \ - jobject jMap = PluginUtils::getJObjFromParam(param); \ + jobject jMap = PluginUtils::getJObjFromParam(pRetParam); \ paramCode = "(Lorg/json/JSONObject;)"; \ - paramCode.append(jRetCode); \ + paramCode.append(jRetCode); \ ret = PluginUtils::callJava##retCode##FuncWithName_oneParam(this, funcName, paramCode.c_str(), jMap); \ PluginUtils::getEnv()->DeleteLocalRef(jMap); \ } \ diff --git a/plugin/protocols/platform/android/PluginProtocol.cpp b/plugin/protocols/platform/android/PluginProtocol.cpp index 4f6ec87eca..82a1364448 100644 --- a/plugin/protocols/platform/android/PluginProtocol.cpp +++ b/plugin/protocols/platform/android/PluginProtocol.cpp @@ -24,6 +24,8 @@ THE SOFTWARE. #include "PluginProtocol.h" #include "PluginUtils.h" +#define LOG_TAG "PluginProtocol" + namespace cocos2d { namespace plugin { PluginProtocol::~PluginProtocol() @@ -70,11 +72,11 @@ void PluginProtocol::setDebugMode(bool isDebugMode) PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", isDebugMode); } -void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) +void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param, ...) { PluginJavaData* pData = PluginUtils::getPluginJavaData(this); if (NULL == pData) { - PluginUtils::outputLog("PluginProtocol", "Can't find java data for plugin : %s", this->getPluginName()); + PluginUtils::outputLog(LOG_TAG, "Can't find java data for plugin : %s", this->getPluginName()); return; } @@ -83,20 +85,52 @@ void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "()V", NULL); } else { - switch(param->getCurrentType()) + PluginParam* pRetParam = NULL; + std::map allParams; + va_list argp; + int argno = 0; + PluginParam* pArg = NULL; + + allParams["Param1"] = param; + va_start( argp, param ); + while (1) + { + pArg = va_arg(argp, PluginParam*); + if (pArg == NULL) + { + break; + } + argno++; + char strKey[8] = { 0 }; + sprintf(strKey, "Param%d", argno + 1); + allParams[strKey] = pArg; + } + va_end(argp); + + PluginParam tempParam(allParams); + if (argno == 0) + { + pRetParam = param; + } + else + { + pRetParam = &tempParam; + } + + switch(pRetParam->getCurrentType()) { case PluginParam::kParamTypeInt: - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(I)V", param->getIntValue()); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(I)V", pRetParam->getIntValue()); break; case PluginParam::kParamTypeFloat: - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(F)V", param->getFloatValue()); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(F)V", pRetParam->getFloatValue()); break; case PluginParam::kParamTypeBool: - PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Z)V", param->getBoolValue()); + PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Z)V", pRetParam->getBoolValue()); break; case PluginParam::kParamTypeString: { - jstring jstr = PluginUtils::getEnv()->NewStringUTF(param->getStringValue()); + jstring jstr = PluginUtils::getEnv()->NewStringUTF(pRetParam->getStringValue()); PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Ljava/lang/String;)V", jstr); PluginUtils::getEnv()->DeleteLocalRef(jstr); } @@ -104,7 +138,7 @@ void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) case PluginParam::kParamTypeStringMap: case PluginParam::kParamTypeMap: { - jobject jMap = PluginUtils::getJObjFromParam(param); + jobject jMap = PluginUtils::getJObjFromParam(pRetParam); PluginUtils::callJavaFunctionWithName_oneParam(this, funcName, "(Lorg/json/JSONObject;)V", jMap); PluginUtils::getEnv()->DeleteLocalRef(jMap); } @@ -115,22 +149,22 @@ void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param) } } -const char* PluginProtocol::callStringFuncWithParam(const char* funcName, PluginParam* param) +const char* PluginProtocol::callStringFuncWithParam(const char* funcName, PluginParam* param, ...) { CALL_JAVA_FUNC(const char*, String, "", "Ljava/lang/String;") } -int PluginProtocol::callIntFuncWithParam(const char* funcName, PluginParam* param) +int PluginProtocol::callIntFuncWithParam(const char* funcName, PluginParam* param, ...) { CALL_JAVA_FUNC(int, Int, 0, "I") } -bool PluginProtocol::callBoolFuncWithParam(const char* funcName, PluginParam* param) +bool PluginProtocol::callBoolFuncWithParam(const char* funcName, PluginParam* param, ...) { CALL_JAVA_FUNC(bool, Bool, false, "Z") } -float PluginProtocol::callFloatFuncWithParam(const char* funcName, PluginParam* param) +float PluginProtocol::callFloatFuncWithParam(const char* funcName, PluginParam* param, ...) { CALL_JAVA_FUNC(float, Float, 0.0f, "F") } diff --git a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp index 3aab1d92cb..8375de18bb 100644 --- a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp +++ b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp @@ -93,24 +93,24 @@ bool AppDelegate::applicationDidFinishLaunching() g_pAnalytics->callFuncWithParam("updateOnlineConfig", NULL); PluginParam pParam1(true); - g_pAnalytics->callFuncWithParam("setReportLocation", &pParam1); + g_pAnalytics->callFuncWithParam("setReportLocation", &pParam1, NULL); g_pAnalytics->callFuncWithParam("logPageView", NULL); PluginParam pParam2("1.1"); - g_pAnalytics->callFuncWithParam("setVersionName", &pParam2); + g_pAnalytics->callFuncWithParam("setVersionName", &pParam2, NULL); PluginParam pParam3(20); - g_pAnalytics->callFuncWithParam("setAge", &pParam3); + g_pAnalytics->callFuncWithParam("setAge", &pParam3, NULL); PluginParam pParam4(1); - g_pAnalytics->callFuncWithParam("setGender", &pParam4); + g_pAnalytics->callFuncWithParam("setGender", &pParam4, NULL); PluginParam pParam5("123456"); - g_pAnalytics->callFuncWithParam("setUserId", &pParam5); + g_pAnalytics->callFuncWithParam("setUserId", &pParam5, NULL); PluginParam pParam6(false); - g_pAnalytics->callFuncWithParam("setUseHttps", &pParam6); + g_pAnalytics->callFuncWithParam("setUseHttps", &pParam6, NULL); // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); diff --git a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp index e2771759b7..f44d597140 100644 --- a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp @@ -158,28 +158,19 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) case TAG_LOG_ONLINE_CONFIG: { PluginParam param("abc"); - CCLog("Online config = %s", g_pAnalytics->callStringFuncWithParam("getConfigParams", ¶m)); + CCLog("Online config = %s", g_pAnalytics->callStringFuncWithParam("getConfigParams", ¶m, NULL)); } break; case TAG_LOG_EVENT_ID_DURATION: { PluginParam event1("book"); PluginParam dura1(12000); - std::map param1; - param1["UmengEvent"] = &event1; - param1["UmengDuration"] = &dura1; - PluginParam param1Map(param1); - g_pAnalytics->callFuncWithParam("logEventWithDuration", ¶m1Map); + g_pAnalytics->callFuncWithParam("logEventWithDuration", &event1, &dura1, NULL); PluginParam event2("book"); PluginParam dura2(12000); PluginParam label("chapter1"); - std::map param2; - param2["UmengEvent"] = &event2; - param2["UmengDuration"] = &dura2; - param2["UmengLabel"] = &label; - PluginParam param2Map(param2); - g_pAnalytics->callFuncWithParam("logEventWithDuration", ¶m2Map); + g_pAnalytics->callFuncWithParam("logEventWithDurationLabel", &event2, &dura2, &label, NULL); PluginParam event3("music"); PluginParam dura3(2330000); @@ -187,13 +178,7 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) paramMap.insert(LogEventParamPair("type", "popular")); paramMap.insert(LogEventParamPair("artist", "JJLin")); PluginParam mapValue(paramMap); - - std::map param3; - param3["UmengEvent"] = &event3; - param3["UmengDuration"] = &dura3; - param3["UmengParams"] = &mapValue; - PluginParam param3Map(param3); - g_pAnalytics->callFuncWithParam("logEventWithDuration", ¶m3Map); + g_pAnalytics->callFuncWithParam("logEventWithDurationParams", &event3, &dura3, &mapValue, NULL); } break; case TAG_LOG_EVENT_BEGIN: @@ -202,11 +187,7 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) PluginParam event1("music"); PluginParam label1("one"); - std::map param1; - param1["UmengEvent"] = &event1; - param1["UmengLabel"] = &label1; - PluginParam param1Map(param1); - g_pAnalytics->callFuncWithParam("logTimedEventWithLabelBegin", ¶m1Map); + g_pAnalytics->callFuncWithParam("logTimedEventWithLabelBegin", &event1, &label1, NULL); PluginParam event2("music"); PluginParam label2("flag0"); @@ -214,19 +195,10 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) paramMap.insert(LogEventParamPair("type", "popular")); paramMap.insert(LogEventParamPair("artist", "JJLin")); PluginParam mapValue(paramMap); - std::map param2; - param2["UmengEvent"] = &event2; - param2["UmengLabel"] = &label2; - param2["UmengParams"] = &mapValue; - PluginParam param2Map(param2); - g_pAnalytics->callFuncWithParam("logTimedKVEventBegin", ¶m2Map); + g_pAnalytics->callFuncWithParam("logTimedKVEventBegin", &event2, &label2, &mapValue, NULL); PluginParam event3("music-kv"); - std::map param3; - param3["FlurryEvent"] = &event3; - param3["FlurryParams"] = &mapValue; - PluginParam param3Map(param3); - g_pAnalytics->callFuncWithParam("logTimedEventBegin", ¶m3Map); + g_pAnalytics->callFuncWithParam("logTimedEventBegin", &event3, &mapValue, NULL); } break; case TAG_LOG_EVENT_END: @@ -235,22 +207,14 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) PluginParam event1("music"); PluginParam label1("one"); - std::map param1; - param1["UmengEvent"] = &event1; - param1["UmengLabel"] = &label1; - PluginParam param1Map(param1); - g_pAnalytics->callFuncWithParam("logTimedEventWithLabelEnd", ¶m1Map); + g_pAnalytics->callFuncWithParam("logTimedEventWithLabelEnd", &event1, &label1, NULL); PluginParam event2("music"); PluginParam label2("flag0"); - std::map param2; - param2["UmengEvent"] = &event2; - param2["UmengLabel"] = &label2; - PluginParam param2Map(param2); - g_pAnalytics->callFuncWithParam("logTimedKVEventEnd", ¶m2Map); + g_pAnalytics->callFuncWithParam("logTimedKVEventEnd", &event2, &label2, NULL); PluginParam event3("music-kv"); - g_pAnalytics->callFuncWithParam("logTimedEventEnd", &event3); + g_pAnalytics->callFuncWithParam("logTimedEventEnd", &event3, NULL); } break; case TAG_MAKE_ME_CRASH: From 50747530e05d5e303c502db0cbf370d2847eb7f0 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 30 May 2013 14:50:21 +0800 Subject: [PATCH 08/18] issue #2224 : Implement reflection in plugin on iOS. --- plugin/protocols/platform/ios/InterfaceAds.h | 7 +- .../platform/ios/InterfaceAnalytics.h | 7 +- plugin/protocols/platform/ios/InterfaceIAP.h | 3 +- .../protocols/platform/ios/InterfaceSocial.h | 6 +- .../protocols/platform/ios/PluginFactory.mm | 107 ++++++++++ .../protocols/platform/ios/PluginOCMacros.h | 82 ++++++++ .../protocols/platform/ios/PluginProtocol.mm | 155 ++++++++++++++ .../protocols/platform/ios/PluginUtilsIOS.h | 40 +++- .../protocols/platform/ios/PluginUtilsIOS.mm | 196 +++++++++++++----- plugin/protocols/platform/ios/ProtocolAds.mm | 56 +++-- .../platform/ios/ProtocolAnalytics.mm | 139 ++++++------- plugin/protocols/platform/ios/ProtocolIAP.mm | 68 ++++-- .../protocols/platform/ios/ProtocolSocial.mm | 103 +++++++++ .../PluginProtocol.xcodeproj/project.pbxproj | 32 ++- 14 files changed, 829 insertions(+), 172 deletions(-) create mode 100644 plugin/protocols/platform/ios/PluginFactory.mm create mode 100644 plugin/protocols/platform/ios/PluginOCMacros.h create mode 100644 plugin/protocols/platform/ios/PluginProtocol.mm create mode 100755 plugin/protocols/platform/ios/ProtocolSocial.mm diff --git a/plugin/protocols/platform/ios/InterfaceAds.h b/plugin/protocols/platform/ios/InterfaceAds.h index d6e3645ef9..7fb01971ed 100644 --- a/plugin/protocols/platform/ios/InterfaceAds.h +++ b/plugin/protocols/platform/ios/InterfaceAds.h @@ -28,9 +28,10 @@ THE SOFTWARE. - (void) configDeveloperInfo: (NSMutableDictionary*) devInfo; - (void) showAds: (int) type size:(int) sizeEnum position:(int) pos; -- (void) hideAds: (NSNumber*) type; -- (void) spendPoints: (NSNumber*) points; -- (void) setDebugMode: (NSNumber*) debug; +- (void) hideAds: (int) type; +- (void) spendPoints: (int) points; +- (void) setDebugMode: (BOOL) debug; - (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; @end diff --git a/plugin/protocols/platform/ios/InterfaceAnalytics.h b/plugin/protocols/platform/ios/InterfaceAnalytics.h index 239b7f97c7..e834edd12e 100644 --- a/plugin/protocols/platform/ios/InterfaceAnalytics.h +++ b/plugin/protocols/platform/ios/InterfaceAnalytics.h @@ -28,14 +28,15 @@ THE SOFTWARE. - (void) startSession: (NSString*) appKey; - (void) stopSession; -- (void) setSessionContinueMillis: (NSNumber*) millis; -- (void) setCaptureUncaughtException: (NSNumber*) isEnabled; -- (void) setDebugMode: (NSNumber*) isDebugMode; +- (void) setSessionContinueMillis: (long) millis; +- (void) setCaptureUncaughtException: (BOOL) isEnabled; +- (void) setDebugMode: (BOOL) debug; - (void) logError: (NSString*) errorId withMsg:(NSString*) message; - (void) logEvent: (NSString*) eventId; - (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; - (void) logTimedEventBegin: (NSString*) eventId; - (void) logTimedEventEnd: (NSString*) eventId; - (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; @end diff --git a/plugin/protocols/platform/ios/InterfaceIAP.h b/plugin/protocols/platform/ios/InterfaceIAP.h index 6c1cb2da20..86af913f05 100644 --- a/plugin/protocols/platform/ios/InterfaceIAP.h +++ b/plugin/protocols/platform/ios/InterfaceIAP.h @@ -28,7 +28,8 @@ THE SOFTWARE. - (void) configDeveloperInfo: (NSMutableDictionary*) cpInfo; - (void) payForProduct: (NSMutableDictionary*) profuctInfo; -- (void) setDebugMode: (NSNumber*) debug; +- (void) setDebugMode: (BOOL) debug; - (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; @end diff --git a/plugin/protocols/platform/ios/InterfaceSocial.h b/plugin/protocols/platform/ios/InterfaceSocial.h index b98eb8827e..00033030da 100644 --- a/plugin/protocols/platform/ios/InterfaceSocial.h +++ b/plugin/protocols/platform/ios/InterfaceSocial.h @@ -24,6 +24,10 @@ THE SOFTWARE. @protocol InterfaceSocial - +- (void) configDeveloperInfo : (NSMutableDictionary*) cpInfo; +- (void) share: (NSMutableDictionary*) shareInfo; +- (void) setDebugMode: (BOOL) debug; +- (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; @end diff --git a/plugin/protocols/platform/ios/PluginFactory.mm b/plugin/protocols/platform/ios/PluginFactory.mm new file mode 100644 index 0000000000..09e6b1aba5 --- /dev/null +++ b/plugin/protocols/platform/ios/PluginFactory.mm @@ -0,0 +1,107 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "PluginFactory.h" +#include "ProtocolAds.h" +#include "ProtocolAnalytics.h" +#include "ProtocolIAP.h" +#include "ProtocolSocial.h" +#include "PluginUtilsIOS.h" + +#import +#import "InterfaceAds.h" +#import "InterfaceAnalytics.h" +#import "InterfaceIAP.h" +#import "InterfaceSocial.h" + +namespace cocos2d { namespace plugin { + +static PluginFactory* s_pFactory = NULL; + +PluginFactory::PluginFactory() +{ + +} + +PluginFactory::~PluginFactory() +{ + +} + +PluginFactory* PluginFactory::getInstance() +{ + if (NULL == s_pFactory) + { + s_pFactory = new PluginFactory(); + } + + return s_pFactory; +} + +void PluginFactory::purgeFactory() +{ + if (NULL != s_pFactory) + { + delete s_pFactory; + s_pFactory = NULL; + } +} + +/** create the plugin by name */ +PluginProtocol* PluginFactory::createPlugin(const char* name) +{ + PluginProtocol* pRet = NULL; + do + { + if (name == NULL || strlen(name) == 0) break; + + NSString* className = [NSString stringWithUTF8String:name]; + id obj = [[NSClassFromString(className) alloc] init]; + if (obj == nil) break; + + if ([obj conformsToProtocol:@protocol(InterfaceAds)]) { + pRet = new ProtocolAds(); + } else + if ([obj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + pRet = new ProtocolAnalytics(); + } else + if ([obj conformsToProtocol:@protocol(InterfaceIAP)]) { + pRet = new ProtocolIAP(); + } else + if ([obj conformsToProtocol:@protocol(InterfaceSocial)]) { + pRet = new ProtocolSocial(); + } else { + PluginUtilsIOS::outputLog("Plugin %s not implements a right protocol", name); + } + + if (pRet != NULL) + { + pRet->setPluginName(name); + PluginUtilsIOS::initOCPlugin(pRet, obj, name); + } + } while(0); + + return pRet; +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/PluginOCMacros.h b/plugin/protocols/platform/ios/PluginOCMacros.h new file mode 100644 index 0000000000..f1d3622e81 --- /dev/null +++ b/plugin/protocols/platform/ios/PluginOCMacros.h @@ -0,0 +1,82 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#ifndef __PLUGIN_OC_MACROS_H__ +#define __PLUGIN_OC_MACROS_H__ + +#define return_if_fails(cond) if (!(cond)) return; +#define return_val_if_fails(cond, ret) if(!(cond)) return (ret); + + +#define CALL_OC_FUNC(retType, defaultRet, retCode) \ +retType ret = defaultRet; \ +PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); \ +if (NULL == pData) { \ + PluginUtilsIOS::outputLog("Can't find OC data for plugin : %s", this->getPluginName()); \ + return ret; \ +} \ + \ +if (NULL == param) \ +{ \ + ret = PluginUtilsIOS::callOC##retCode##FunctionWithName_oneParam(this, funcName, NULL); \ +} else \ +{ \ + PluginParam* pRetParam = NULL; \ + std::map allParams; \ + va_list argp; \ + int argno = 0; \ + PluginParam* pArg = NULL; \ + \ + allParams["Param1"] = param; \ + va_start( argp, param ); \ + while (1) \ + { \ + pArg = va_arg(argp, PluginParam*); \ + if (pArg == NULL) \ + { \ + break; \ + } \ + argno++; \ + char strKey[8] = { 0 }; \ + sprintf(strKey, "Param%d", argno + 1); \ + allParams[strKey] = pArg; \ + } \ + va_end(argp); \ + \ + PluginParam tempParam(allParams); \ + if (argno == 0) \ + { \ + pRetParam = param; \ + } \ + else \ + { \ + pRetParam = &tempParam; \ + } \ + \ + id ocParam = PluginUtilsIOS::getOCObjFromParam(pRetParam); \ + ret = PluginUtilsIOS::callOC##retCode##FunctionWithName_oneParam(this, funcName, ocParam); \ +} \ +return ret; \ + + +#endif // __PLUGIN_OC_MACROS_H__ diff --git a/plugin/protocols/platform/ios/PluginProtocol.mm b/plugin/protocols/platform/ios/PluginProtocol.mm new file mode 100644 index 0000000000..249e9b6c5e --- /dev/null +++ b/plugin/protocols/platform/ios/PluginProtocol.mm @@ -0,0 +1,155 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "PluginProtocol.h" +#include "PluginUtilsIOS.h" +#include "PluginOCMacros.h" + +namespace cocos2d { namespace plugin { + +PluginProtocol::~PluginProtocol() +{ + PluginUtilsIOS::erasePluginOCData(this); +} + +const char* PluginProtocol::getPluginVersion() +{ + std::string verName; + + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"getPluginVersion"); + + if ([pOCObj respondsToSelector:selector]) { + NSString* strRet = (NSString*)[pOCObj performSelector:selector]; + verName = [strRet UTF8String]; + } else { + PluginUtilsIOS::outputLog("Can't find function 'getPluginVersion' in class '%s'", pData->className.c_str()); + } + } else { + PluginUtilsIOS::outputLog("Plugin %p not right initilized", this); + } + + return verName.c_str(); +} + +const char* PluginProtocol::getSDKVersion() +{ + std::string verName; + + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (pData) { + id pOCObj = pData->obj; + SEL selector = NSSelectorFromString(@"getSDKVersion"); + + if ([pOCObj respondsToSelector:selector]) { + NSString* strRet = (NSString*)[pOCObj performSelector:selector]; + verName = [strRet UTF8String]; + } else { + PluginUtilsIOS::outputLog("Can't find function 'getSDKVersion' in class '%s'", pData->className.c_str()); + } + } else { + PluginUtilsIOS::outputLog("Plugin %s not right initilized", this->getPluginName()); + } + + return verName.c_str(); +} + +void PluginProtocol::setDebugMode(bool isDebugMode) +{ + NSNumber* bDebug = [NSNumber numberWithBool:isDebugMode]; + PluginUtilsIOS::callOCFunctionWithName_oneParam(this, "setDebugMode", bDebug); +} + +void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param, ...) +{ + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + if (NULL == pData) { + PluginUtilsIOS::outputLog("Can't find OC data for plugin : %s", this->getPluginName()); + return; + } + + if (NULL == param) + { + PluginUtilsIOS::callOCFunctionWithName_oneParam(this, funcName, NULL); + } else + { + PluginParam* pRetParam = NULL; + std::map allParams; + va_list argp; + int argno = 0; + PluginParam* pArg = NULL; + + allParams["Param1"] = param; + va_start( argp, param ); + while (1) + { + pArg = va_arg(argp, PluginParam*); + if (pArg == NULL) + { + break; + } + argno++; + char strKey[8] = { 0 }; + sprintf(strKey, "Param%d", argno + 1); + allParams[strKey] = pArg; + } + va_end(argp); + + PluginParam tempParam(allParams); + if (argno == 0) + { + pRetParam = param; + } + else + { + pRetParam = &tempParam; + } + + id ocParam = PluginUtilsIOS::getOCObjFromParam(pRetParam); + PluginUtilsIOS::callOCFunctionWithName_oneParam(this, funcName, ocParam); + } +} + +const char* PluginProtocol::callStringFuncWithParam(const char* funcName, PluginParam* param, ...) +{ + CALL_OC_FUNC(const char*, "", String) +} + +int PluginProtocol::callIntFuncWithParam(const char* funcName, PluginParam* param, ...) +{ + CALL_OC_FUNC(int, 0, Int) +} + +bool PluginProtocol::callBoolFuncWithParam(const char* funcName, PluginParam* param, ...) +{ + CALL_OC_FUNC(bool, false, Bool) +} + +float PluginProtocol::callFloatFuncWithParam(const char* funcName, PluginParam* param, ...) +{ + CALL_OC_FUNC(float, 0.0f, Float) +} + +}} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/PluginUtilsIOS.h b/plugin/protocols/platform/ios/PluginUtilsIOS.h index 4933575de8..18118691b8 100644 --- a/plugin/protocols/platform/ios/PluginUtilsIOS.h +++ b/plugin/protocols/platform/ios/PluginUtilsIOS.h @@ -28,12 +28,10 @@ THE SOFTWARE. #include "PluginProtocol.h" #include #include +#include "PluginParam.h" namespace cocos2d { namespace plugin { -#define return_if_fails(cond) if (!(cond)) return; -#define return_val_if_fails(cond, ret) if(!(cond)) return (ret); - typedef struct _PluginOCData { id obj; @@ -43,7 +41,7 @@ typedef struct _PluginOCData class PluginUtilsIOS { public: - static bool initOCPlugin(PluginProtocol* pPlugin, const char* className); + static void initOCPlugin(PluginProtocol* pPlugin, id ocObj, const char* className); static PluginOCData* getPluginOCData(PluginProtocol* pKeyObj); static void setPluginOCData(PluginProtocol* pKeyObj, PluginOCData* pData); @@ -51,9 +49,39 @@ public: static PluginProtocol* getPluginPtr(id obj); + static id getOCObjFromParam(PluginParam* param); + static NSMutableDictionary* createDictFromMap(std::map* paramMap); - static void callOCFunctionWithName(PluginProtocol* pPlugin, const char* funcName); - static void callOCFunctionWithName_Object(PluginProtocol* pPlugin, const char* funcName, id obj); + + /** + @brief method don't have return value + */ + static void callOCFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param); + + /** + @brief method return int value + */ + static int callOCIntFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param); + + /** + @brief method return float value + */ + static float callOCFloatFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param); + + /** + @brief method return bool value + */ + static bool callOCBoolFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param); + + /** + @brief method return string value + */ + static const char* callOCStringFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param); + + static void outputLog(const char* pFormat, ...); + +private: + static id callRetFunction(PluginProtocol* pPlugin, const char* funcName, id param); }; }} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/PluginUtilsIOS.mm b/plugin/protocols/platform/ios/PluginUtilsIOS.mm index 2236ba1858..ca3ae7816e 100644 --- a/plugin/protocols/platform/ios/PluginUtilsIOS.mm +++ b/plugin/protocols/platform/ios/PluginUtilsIOS.mm @@ -25,28 +25,20 @@ THE SOFTWARE. #include "PluginUtilsIOS.h" #include #import +#include "PluginOCMacros.h" + +#define MAX_LOG_LEN 256 namespace cocos2d { namespace plugin { static PluginProtocol* s_pPluginInstance = NULL; -bool PluginUtilsIOS::initOCPlugin(PluginProtocol* pPlugin, const char* className) +void PluginUtilsIOS::initOCPlugin(PluginProtocol* pPlugin, id ocObj, const char* className) { - return_val_if_fails(className != NULL && strlen(className) > 0, false); - bool bRet = false; - - NSString* name = [NSString stringWithUTF8String:className]; - id obj = [[NSClassFromString(name) alloc] init]; - if (obj != nil) - { - PluginOCData* pData = new PluginOCData(); - pData->obj = obj; - pData->className = className; - PluginUtilsIOS::setPluginOCData(pPlugin, pData); - bRet = true; - } - - return bRet; + PluginOCData* pData = new PluginOCData(); + pData->obj = ocObj; + pData->className = className; + PluginUtilsIOS::setPluginOCData(pPlugin, pData); } std::map s_PluginOCObjMap; @@ -77,6 +69,54 @@ PluginProtocol* PluginUtilsIOS::getPluginPtr(id obj) return ret; } +id PluginUtilsIOS::getOCObjFromParam(PluginParam* param) +{ + if (NULL == param) + { + return nil; + } + + id obj = nil; + switch(param->getCurrentType()) + { + case PluginParam::kParamTypeInt: + obj = [NSNumber numberWithInt:param->getIntValue()]; + break; + case PluginParam::kParamTypeFloat: + obj = [NSNumber numberWithFloat:param->getFloatValue()]; + break; + case PluginParam::kParamTypeBool: + obj = [NSNumber numberWithBool:param->getBoolValue()]; + break; + case PluginParam::kParamTypeString: + obj = [NSString stringWithUTF8String:param->getStringValue()]; + break; + case PluginParam::kParamTypeStringMap: + { + std::map mapValue = param->getStrMapValue(); + obj = createDictFromMap(&mapValue); + } + break; + case PluginParam::kParamTypeMap: + { + obj = [NSMutableDictionary dictionary]; + std::map paramMap = param->getMapValue(); + std::map::const_iterator it; + for (it = paramMap.begin(); it != paramMap.end(); ++it) + { + NSString* pKey = [NSString stringWithUTF8String:it->first.c_str()]; + id objValue = PluginUtilsIOS::getOCObjFromParam(it->second); + [obj setValue:objValue forKey:pKey]; + } + } + break; + default: + break; + } + + return obj; +} + void PluginUtilsIOS::setPluginOCData(PluginProtocol* pKeyObj, PluginOCData* pData) { erasePluginOCData(pKeyObj); @@ -125,50 +165,112 @@ NSMutableDictionary* PluginUtilsIOS::createDictFromMap(std::map 0); - - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(pPlugin); - if (pData) { - id pOCObj = pData->obj; - NSString* strFuncName = [NSString stringWithUTF8String:funcName]; - SEL selector = NSSelectorFromString(strFuncName); - - const char* className = class_getName([pOCObj class]); - NSString* strClassName = [NSString stringWithUTF8String:className]; - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector]; - NSLog(@"Function '%@' in class '%@' invoked", strFuncName, strClassName); - } else { - NSLog(@"Can't find function '%@' in class '%@'", strFuncName, strClassName); - } - } else { - printf("Can't find function '%s' in plugin %p", funcName, pPlugin); - } -} - -void PluginUtilsIOS::callOCFunctionWithName_Object(PluginProtocol* pPlugin, const char* funcName, id obj) +void PluginUtilsIOS::callOCFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param) { return_if_fails(funcName != NULL && strlen(funcName) > 0); PluginOCData* pData = PluginUtilsIOS::getPluginOCData(pPlugin); if (pData) { id pOCObj = pData->obj; + NSString* strFuncName = [NSString stringWithUTF8String:funcName]; + if (param != nil) { + strFuncName = [strFuncName stringByAppendingString:@":"]; + } SEL selector = NSSelectorFromString(strFuncName); - - const char* className = class_getName([pOCObj class]); - NSString* strClassName = [NSString stringWithUTF8String:className]; if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:obj]; - NSLog(@"Function '%@' in class '%@' invoked", strFuncName, strClassName); + if (param == nil) { + [pOCObj performSelector:selector]; + } else { + [pOCObj performSelector:selector withObject:param]; + } } else { - NSLog(@"Can't find function '%@' in class '%@'", strFuncName, strClassName); + outputLog("Can't find function '%s' in class '%s'", [strFuncName UTF8String], pData->className.c_str()); } } else { - printf("Can't find function '%s' in plugin %p", funcName, pPlugin); + PluginUtilsIOS::outputLog("Plugin %s not right initilized", pPlugin->getPluginName()); } } +int PluginUtilsIOS::callOCIntFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param) +{ + int ret = (NSInteger)callRetFunction(pPlugin, funcName, param); + return ret; +} + +float PluginUtilsIOS::callOCFloatFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param) +{ + float ret = 0.0f; + NSNumber* pRet = (NSNumber*)callRetFunction(pPlugin, funcName, param); + if (nil != pRet) { + ret = [pRet floatValue]; + } + + return ret; +} + +bool PluginUtilsIOS::callOCBoolFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param) +{ + bool ret = false; + NSNumber* pRet = (NSNumber*)callRetFunction(pPlugin, funcName, param); + if (nil != pRet) { + ret = [pRet boolValue]; + } + + return ret; +} + +const char* PluginUtilsIOS::callOCStringFunctionWithName_oneParam(PluginProtocol* pPlugin, const char* funcName, id param) +{ + const char* ret = ""; + NSString* pRet = (NSString*)callRetFunction(pPlugin, funcName, param); + if (nil != pRet) { + ret = [pRet UTF8String]; + } + + return ret; +} + +id PluginUtilsIOS::callRetFunction(PluginProtocol* pPlugin, const char* funcName, id param) +{ + id ret = nil; + return_val_if_fails(funcName != NULL && strlen(funcName) > 0, ret); + + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(pPlugin); + if (pData) { + id pOCObj = pData->obj; + + NSString* strFuncName = [NSString stringWithUTF8String:funcName]; + if (param != nil) { + strFuncName = [strFuncName stringByAppendingString:@":"]; + } + SEL selector = NSSelectorFromString(strFuncName); + if ([pOCObj respondsToSelector:selector]) { + if (param == nil) { + ret = [pOCObj performSelector:selector]; + } else { + ret = [pOCObj performSelector:selector withObject:param]; + } + } else { + outputLog("Can't find function '%s' in class '%s'", [strFuncName UTF8String], pData->className.c_str()); + } + } else { + PluginUtilsIOS::outputLog("Plugin %s not right initilized", pPlugin->getPluginName()); + } + + return ret; +} + +void PluginUtilsIOS::outputLog(const char* pFormat, ...) +{ + printf("Plugin-x: "); + char szBuf[MAX_LOG_LEN+1] = {0}; + va_list ap; + va_start(ap, pFormat); + vsnprintf(szBuf, MAX_LOG_LEN, pFormat, ap); + va_end(ap); + printf("%s", szBuf); + printf("\n"); +} + }}// namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolAds.mm b/plugin/protocols/platform/ios/ProtocolAds.mm index 0e9a2cb85c..1902f0eec0 100644 --- a/plugin/protocols/platform/ios/ProtocolAds.mm +++ b/plugin/protocols/platform/ios/ProtocolAds.mm @@ -23,6 +23,7 @@ ****************************************************************************/ #include "ProtocolAds.h" +#include "PluginUtilsIOS.h" #import "InterfaceAds.h" namespace cocos2d { namespace plugin { @@ -36,29 +37,61 @@ ProtocolAds::~ProtocolAds() { } -bool ProtocolAds::init() -{ - return true; -} - void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo) { + if (devInfo.empty()) + { + PluginUtilsIOS::outputLog("The developer info is empty for %s!", this->getPluginName()); + return; + } + else + { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) { + NSObject* curObj = ocObj; + NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&devInfo); + [curObj configDeveloperInfo:pDict]; + } + } } void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos) { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) { + NSObject* curObj = ocObj; + [curObj showAds:type size:sizeEnum position:pos]; + } } void ProtocolAds::hideAds(AdsType type) { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) { + NSObject* curObj = ocObj; + [curObj hideAds:type]; + } } void ProtocolAds::spendPoints(int points) { -} - -void ProtocolAds::setDebugMode(bool debug) -{ + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAds)]) { + NSObject* curObj = ocObj; + [curObj spendPoints:points]; + } } // For the callbak methods @@ -83,9 +116,4 @@ void ProtocolAds::onPlayerGetPoints(int points) } } -const char* ProtocolAds::getSDKVersion() -{ - return "Subclass should override this interface"; -} - }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolAnalytics.mm b/plugin/protocols/platform/ios/ProtocolAnalytics.mm index ae04635971..3fb65f6b01 100644 --- a/plugin/protocols/platform/ios/ProtocolAnalytics.mm +++ b/plugin/protocols/platform/ios/ProtocolAnalytics.mm @@ -36,19 +36,21 @@ ProtocolAnalytics::~ProtocolAnalytics() PluginUtilsIOS::erasePluginOCData(this); } -bool ProtocolAnalytics::init() -{ - return true; -} - /** @brief Start a new session. @param appKey The identity of the application. */ void ProtocolAnalytics::startSession(const char* appKey) { - NSString* pStrKey = [NSString stringWithUTF8String:appKey]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "startSession:", pStrKey); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + NSString* pStrKey = [NSString stringWithUTF8String:appKey]; + [curObj startSession:pStrKey]; + } } /** @@ -57,18 +59,14 @@ void ProtocolAnalytics::startSession(const char* appKey) */ void ProtocolAnalytics::stopSession() { - PluginUtilsIOS::callOCFunctionWithName(this, "stopSession"); -} - -/** - @brief Set whether needs to output logs to console. - @param debug if true debug mode enabled, or debug mode disabled. - @note It must be invoked before calling startSession. - */ -void ProtocolAnalytics::setDebugMode(bool debug) -{ - NSNumber* bDebug = [NSNumber numberWithBool:debug]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setDebugMode:", bDebug); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + [curObj stopSession]; + } } /** @@ -78,8 +76,14 @@ void ProtocolAnalytics::setDebugMode(bool debug) */ void ProtocolAnalytics::setSessionContinueMillis(long millis) { - NSNumber* lMillis = [NSNumber numberWithLong:millis]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setSessionContinueMillis:", lMillis); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + [curObj setSessionContinueMillis:millis]; + } } /** @@ -90,18 +94,14 @@ void ProtocolAnalytics::setSessionContinueMillis(long millis) void ProtocolAnalytics::logError(const char* errorId, const char* message) { PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (! pData) { - return; - } + assert(pData != NULL); - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logError:withMsg:"); - if ([pOCObj respondsToSelector:selector]) { - - NSString* strErrID = [NSString stringWithUTF8String:errorId]; - NSString* strMsg = [NSString stringWithUTF8String:message]; - [pOCObj logError:strErrID withMsg:strMsg]; - NSLog(@"logError withMsg in OC class invoked!"); + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + NSString* pError = [NSString stringWithUTF8String:errorId]; + NSString* pMsg = [NSString stringWithUTF8String:message]; + [curObj logError:pError withMsg:pMsg]; } } @@ -113,24 +113,14 @@ void ProtocolAnalytics::logError(const char* errorId, const char* message) void ProtocolAnalytics::logEvent(const char* eventId, LogEventParamMap* paramMap) { PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (! pData) { - return; - } + assert(pData != NULL); - id pOCObj = pData->obj; - NSString* strEventID = [NSString stringWithUTF8String:eventId]; - - if (paramMap == NULL) { - PluginUtilsIOS::callOCFunctionWithName_Object(this, "logEvent:", strEventID); - NSLog(@"logEvent(no paramsters) in OC class invoked!"); - } else { - SEL selector = NSSelectorFromString(@"logEvent:withParam:"); - if ([pOCObj respondsToSelector:selector]) { - - NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); - [pOCObj logEvent:strEventID withParam:dict]; - NSLog(@"logEvent(with parameters) in OC class invoked!"); - } + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + NSString* pId = [NSString stringWithUTF8String:eventId]; + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); + [curObj logEvent:pId withParam:dict]; } } @@ -140,8 +130,15 @@ void ProtocolAnalytics::logEvent(const char* eventId, LogEventParamMap* paramMap */ void ProtocolAnalytics::logTimedEventBegin(const char* eventId) { - NSString* pStrID = [NSString stringWithUTF8String:eventId]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "logTimedEventBegin:", pStrID); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + NSString* pEvent = [NSString stringWithUTF8String:eventId]; + [curObj logTimedEventBegin:pEvent]; + } } /** @@ -150,8 +147,15 @@ void ProtocolAnalytics::logTimedEventBegin(const char* eventId) */ void ProtocolAnalytics::logTimedEventEnd(const char* eventId) { - NSString* pStrID = [NSString stringWithUTF8String:eventId]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "logTimedEventEnd:", pStrID); + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + NSString* pEvent = [NSString stringWithUTF8String:eventId]; + [curObj logTimedEventEnd:pEvent]; + } } /** @@ -160,27 +164,14 @@ void ProtocolAnalytics::logTimedEventEnd(const char* eventId) */ void ProtocolAnalytics::setCaptureUncaughtException(bool enabled) { - NSNumber* bEnable = [NSNumber numberWithBool:enabled]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setCaptureUncaughtException:", bEnable); -} - -const char* ProtocolAnalytics::getSDKVersion() -{ - const char* pRet = ""; - - do { - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (! pData) break; - - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"getSDKVersion"); - if ([pOCObj respondsToSelector:selector]) { - NSString* strRet = [pOCObj performSelector:selector]; - pRet = [strRet UTF8String]; - } - } while (0); - - return pRet; + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceAnalytics)]) { + NSObject* curObj = ocObj; + [curObj setCaptureUncaughtException:enabled]; + } } }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolIAP.mm b/plugin/protocols/platform/ios/ProtocolIAP.mm index d142c880c0..e3680b273d 100644 --- a/plugin/protocols/platform/ios/ProtocolIAP.mm +++ b/plugin/protocols/platform/ios/ProtocolIAP.mm @@ -26,7 +26,7 @@ #import "InterfaceIAP.h" namespace cocos2d { namespace plugin { - + bool ProtocolIAP::m_bPaying = false; ProtocolIAP::ProtocolIAP() @@ -39,17 +39,59 @@ ProtocolIAP::~ProtocolIAP() PluginUtilsIOS::erasePluginOCData(this); } -bool ProtocolIAP::init() -{ - return true; -} - void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo) { + if (devInfo.empty()) + { + PluginUtilsIOS::outputLog("The developer info is empty for %s!", this->getPluginName()); + return; + } + else + { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceIAP)]) { + NSObject* curObj = ocObj; + NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&devInfo); + [curObj configDeveloperInfo:pDict]; + } + } } void ProtocolIAP::payForProduct(TProductInfo info) { + if (m_bPaying) + { + PluginUtilsIOS::outputLog("Now is paying"); + return; + } + + if (info.empty()) + { + if (NULL != m_pListener) + { + onPayResult(kPayFail, "Product info error"); + } + PluginUtilsIOS::outputLog("The product info is empty for %s!", this->getPluginName()); + return; + } + else + { + m_bPaying = true; + m_curInfo = info; + + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceIAP)]) { + NSObject* curObj = ocObj; + NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(&info); + [curObj payForProduct:dict]; + } + } } void ProtocolIAP::setResultListener(PayResultListener* pListener) @@ -64,17 +106,13 @@ void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg) { m_pListener->onPayResult(ret, msg, m_curInfo); } + else + { + PluginUtilsIOS::outputLog("Pay result listener of %s is null!", this->getPluginName()); + } m_curInfo.clear(); -} - -const char* ProtocolIAP::getSDKVersion() -{ - return "Subclass should override this interface"; -} - -void ProtocolIAP::setDebugMode(bool debug) -{ + PluginUtilsIOS::outputLog("Pay result of %s is : %d(%s)", this->getPluginName(), (int) ret, msg); } }} //namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/platform/ios/ProtocolSocial.mm b/plugin/protocols/platform/ios/ProtocolSocial.mm new file mode 100755 index 0000000000..0c5d559d4f --- /dev/null +++ b/plugin/protocols/platform/ios/ProtocolSocial.mm @@ -0,0 +1,103 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#include "ProtocolSocial.h" +#include "PluginUtilsIOS.h" +#import "InterfaceSocial.h" + +namespace cocos2d { namespace plugin { + +ProtocolSocial::ProtocolSocial() +: m_pListener(NULL) +{ +} + +ProtocolSocial::~ProtocolSocial() +{ +} + +void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo) +{ + if (devInfo.empty()) + { + PluginUtilsIOS::outputLog("The developer info is empty for %s!", this->getPluginName()); + return; + } + else + { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceSocial)]) { + NSObject* curObj = ocObj; + NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&devInfo); + [curObj configDeveloperInfo:pDict]; + } + } +} + +void ProtocolSocial::share(TShareInfo info) +{ + if (info.empty()) + { + if (NULL != m_pListener) + { + onShareResult(kShareFail, "Share info error"); + } + PluginUtilsIOS::outputLog("The Share info of %s is empty!", this->getPluginName()); + return; + } + else + { + PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); + assert(pData != NULL); + + id ocObj = pData->obj; + if ([ocObj conformsToProtocol:@protocol(InterfaceSocial)]) { + NSObject* curObj = ocObj; + NSMutableDictionary* pDict = PluginUtilsIOS::createDictFromMap(&info); + [curObj share:pDict]; + } + } +} + +void ProtocolSocial::setResultListener(ShareResultListener* pListener) +{ + m_pListener = pListener; +} + +void ProtocolSocial::onShareResult(ShareResultCode ret, const char* msg) +{ + if (m_pListener) + { + m_pListener->onShareResult(ret, msg); + } + else + { + PluginUtilsIOS::outputLog("Share result listener of %s is null!", this->getPluginName()); + } + PluginUtilsIOS::outputLog("Share result of %s is : %d(%s)", this->getPluginName(), (int) ret, msg); +} + +}} // namespace cocos2d { namespace plugin { diff --git a/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj b/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj index 289b40e67c..1a124f8ca6 100644 --- a/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj +++ b/plugin/protocols/proj.ios/PluginProtocol.xcodeproj/project.pbxproj @@ -9,12 +9,15 @@ /* Begin PBXBuildFile section */ FA09A325168ADBC2008C1C7B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA09A324168ADBC2008C1C7B /* Foundation.framework */; }; FA09A33E168ADC1F008C1C7B /* PluginManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA09A33C168ADC1F008C1C7B /* PluginManager.cpp */; }; - FA09A33F168ADC1F008C1C7B /* RegisterPlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA09A33D168ADC1F008C1C7B /* RegisterPlugin.cpp */; }; FA8CC1E6173754CF00464206 /* PluginUtilsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC1E5173754CF00464206 /* PluginUtilsIOS.mm */; }; FA8CC2041737A3CE00464206 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA8CC2031737A3CE00464206 /* CoreFoundation.framework */; }; FA8CC208173894F000464206 /* ProtocolAds.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC205173894F000464206 /* ProtocolAds.mm */; }; FA8CC209173894F000464206 /* ProtocolAnalytics.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC206173894F000464206 /* ProtocolAnalytics.mm */; }; FA8CC20A173894F000464206 /* ProtocolIAP.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC207173894F000464206 /* ProtocolIAP.mm */; }; + FAB6DF961755D7E500C90D89 /* PluginParam.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAB6DF951755D7E500C90D89 /* PluginParam.cpp */; }; + FAB6DF981755D82F00C90D89 /* PluginFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAB6DF971755D82F00C90D89 /* PluginFactory.mm */; }; + FAB6DF9A1755D93600C90D89 /* PluginProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAB6DF991755D93600C90D89 /* PluginProtocol.mm */; }; + FAB6DFD31756EA4D00C90D89 /* ProtocolSocial.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAB6DFD21756EA4D00C90D89 /* ProtocolSocial.mm */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -36,9 +39,7 @@ FA09A338168ADC05008C1C7B /* PluginProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginProtocol.h; sourceTree = ""; }; FA09A339168ADC05008C1C7B /* ProtocolAnalytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolAnalytics.h; sourceTree = ""; }; FA09A33A168ADC05008C1C7B /* ProtocolIAP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolIAP.h; sourceTree = ""; }; - FA09A33B168ADC05008C1C7B /* RegisterPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterPlugin.h; sourceTree = ""; }; FA09A33C168ADC1F008C1C7B /* PluginManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PluginManager.cpp; path = ../PluginManager.cpp; sourceTree = ""; }; - FA09A33D168ADC1F008C1C7B /* RegisterPlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegisterPlugin.cpp; path = ../RegisterPlugin.cpp; sourceTree = ""; }; FA4E3033172BD02800A3E673 /* ProtocolSocial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolSocial.h; sourceTree = ""; }; FA7C6C971724E4DD008A0ECC /* ProtocolAds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolAds.h; sourceTree = ""; }; FA8CC1E4173754CF00464206 /* PluginUtilsIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginUtilsIOS.h; sourceTree = ""; }; @@ -51,6 +52,13 @@ FA8CC21C1739E86E00464206 /* InterfaceAnalytics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceAnalytics.h; sourceTree = ""; }; FA8CC21D1739E86E00464206 /* InterfaceIAP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceIAP.h; sourceTree = ""; }; FA8CC21E1739E86E00464206 /* InterfaceSocial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterfaceSocial.h; sourceTree = ""; }; + FAB6DF931755D7D100C90D89 /* PluginFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginFactory.h; sourceTree = ""; }; + FAB6DF941755D7D100C90D89 /* PluginParam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginParam.h; sourceTree = ""; }; + FAB6DF951755D7E500C90D89 /* PluginParam.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PluginParam.cpp; path = ../PluginParam.cpp; sourceTree = ""; }; + FAB6DF971755D82F00C90D89 /* PluginFactory.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginFactory.mm; sourceTree = ""; }; + FAB6DF991755D93600C90D89 /* PluginProtocol.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginProtocol.mm; sourceTree = ""; }; + FAB6DFCD1755EF8E00C90D89 /* PluginOCMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginOCMacros.h; sourceTree = ""; }; + FAB6DFD21756EA4D00C90D89 /* ProtocolSocial.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProtocolSocial.mm; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,10 +77,10 @@ FA09A316168ADBC2008C1C7B = { isa = PBXGroup; children = ( + FAB6DF951755D7E500C90D89 /* PluginParam.cpp */, FA8CC2031737A3CE00464206 /* CoreFoundation.framework */, FA0CB8B5168D3CC200E36B11 /* ios */, FA09A33C168ADC1F008C1C7B /* PluginManager.cpp */, - FA09A33D168ADC1F008C1C7B /* RegisterPlugin.cpp */, FA09A336168ADC05008C1C7B /* include */, FA09A323168ADBC2008C1C7B /* Frameworks */, FA09A322168ADBC2008C1C7B /* Products */, @@ -98,13 +106,14 @@ FA09A336168ADC05008C1C7B /* include */ = { isa = PBXGroup; children = ( - FA4E3033172BD02800A3E673 /* ProtocolSocial.h */, - FA7C6C971724E4DD008A0ECC /* ProtocolAds.h */, + FAB6DF931755D7D100C90D89 /* PluginFactory.h */, + FAB6DF941755D7D100C90D89 /* PluginParam.h */, FA09A337168ADC05008C1C7B /* PluginManager.h */, FA09A338168ADC05008C1C7B /* PluginProtocol.h */, + FA7C6C971724E4DD008A0ECC /* ProtocolAds.h */, FA09A339168ADC05008C1C7B /* ProtocolAnalytics.h */, FA09A33A168ADC05008C1C7B /* ProtocolIAP.h */, - FA09A33B168ADC05008C1C7B /* RegisterPlugin.h */, + FA4E3033172BD02800A3E673 /* ProtocolSocial.h */, ); name = include; path = ../include; @@ -113,6 +122,9 @@ FA0CB8B5168D3CC200E36B11 /* ios */ = { isa = PBXGroup; children = ( + FAB6DFCD1755EF8E00C90D89 /* PluginOCMacros.h */, + FAB6DF991755D93600C90D89 /* PluginProtocol.mm */, + FAB6DF971755D82F00C90D89 /* PluginFactory.mm */, FA8CC21B1739E86E00464206 /* InterfaceAds.h */, FA8CC21C1739E86E00464206 /* InterfaceAnalytics.h */, FA8CC21D1739E86E00464206 /* InterfaceIAP.h */, @@ -120,6 +132,7 @@ FA8CC205173894F000464206 /* ProtocolAds.mm */, FA8CC206173894F000464206 /* ProtocolAnalytics.mm */, FA8CC207173894F000464206 /* ProtocolIAP.mm */, + FAB6DFD21756EA4D00C90D89 /* ProtocolSocial.mm */, FA8CC1E4173754CF00464206 /* PluginUtilsIOS.h */, FA8CC1E5173754CF00464206 /* PluginUtilsIOS.mm */, ); @@ -179,11 +192,14 @@ buildActionMask = 2147483647; files = ( FA09A33E168ADC1F008C1C7B /* PluginManager.cpp in Sources */, - FA09A33F168ADC1F008C1C7B /* RegisterPlugin.cpp in Sources */, FA8CC1E6173754CF00464206 /* PluginUtilsIOS.mm in Sources */, FA8CC208173894F000464206 /* ProtocolAds.mm in Sources */, FA8CC209173894F000464206 /* ProtocolAnalytics.mm in Sources */, FA8CC20A173894F000464206 /* ProtocolIAP.mm in Sources */, + FAB6DF961755D7E500C90D89 /* PluginParam.cpp in Sources */, + FAB6DF981755D82F00C90D89 /* PluginFactory.mm in Sources */, + FAB6DF9A1755D93600C90D89 /* PluginProtocol.mm in Sources */, + FAB6DFD31756EA4D00C90D89 /* ProtocolSocial.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 01ca1805e8809295397b4fa28adcdbd65a803c0d Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 30 May 2013 14:57:39 +0800 Subject: [PATCH 09/18] issue #2224 : Modify the implementation of plugin flurry & umeng on iOS for the new framework. --- .../flurry/platform/ios/AnalyticsFlurry.mm | 221 ---------- .../flurry/platform/ios/FlurryWrapper.m | 129 ------ .../org/cocos2dx/plugin/AnalyticsFlurry.java | 2 +- .../AnalyticsFlurry.h} | 16 +- .../plugins/flurry/proj.ios/AnalyticsFlurry.m | 166 ++++++++ .../{platform/ios => proj.ios}/Flurry.h | 0 .../PluginFlurry.xcodeproj/project.pbxproj | 50 +-- .../libFlurry.a.REMOVED.git-id | 0 .../umeng/platform/ios/AnalyticsUmeng.mm | 380 ------------------ .../plugins/umeng/platform/ios/UmengWrapper.h | 61 --- .../plugins/umeng/platform/ios/UmengWrapper.m | 170 -------- .../plugins/umeng/proj.ios/AnalyticsUmeng.h | 131 ++++++ .../plugins/umeng/proj.ios/AnalyticsUmeng.m | 236 +++++++++++ .../{platform/ios => proj.ios}/MobClick.h | 0 .../PluginUmeng.xcodeproj/project.pbxproj | 48 +-- .../libMobClickLibrary.a.REMOVED.git-id | 0 .../Classes/HelloWorldScene.cpp | 2 +- 17 files changed, 571 insertions(+), 1041 deletions(-) delete mode 100644 plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm delete mode 100644 plugin/plugins/flurry/platform/ios/FlurryWrapper.m rename plugin/plugins/flurry/{platform/ios/FlurryWrapper.h => proj.ios/AnalyticsFlurry.h} (79%) create mode 100644 plugin/plugins/flurry/proj.ios/AnalyticsFlurry.m rename plugin/plugins/flurry/{platform/ios => proj.ios}/Flurry.h (100%) rename plugin/plugins/flurry/{platform/ios => proj.ios}/libFlurry.a.REMOVED.git-id (100%) delete mode 100644 plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm delete mode 100644 plugin/plugins/umeng/platform/ios/UmengWrapper.h delete mode 100644 plugin/plugins/umeng/platform/ios/UmengWrapper.m create mode 100644 plugin/plugins/umeng/proj.ios/AnalyticsUmeng.h create mode 100644 plugin/plugins/umeng/proj.ios/AnalyticsUmeng.m rename plugin/plugins/umeng/{platform/ios => proj.ios}/MobClick.h (100%) rename plugin/plugins/umeng/{platform/ios => proj.ios}/libMobClickLibrary.a.REMOVED.git-id (100%) diff --git a/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm b/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm deleted file mode 100644 index b9fbdf7ad8..0000000000 --- a/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "AnalyticsFlurry.h" -#include "Flurry.h" -#include "PluginUtilsIOS.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(AnalyticsFlurry) - -#define LOG_MAX_LENGTH (16 * 1024) - -static bool s_bDebugable = false; -void FlurryLogD(const char * pszFormat, ...) -{ - if (s_bDebugable) { - printf("AnalyticsFlurry : "); - char szBuf[LOG_MAX_LENGTH]; - - va_list ap; - va_start(ap, pszFormat); - vsnprintf(szBuf, LOG_MAX_LENGTH, pszFormat, ap); - va_end(ap); - printf("%s", szBuf); - printf("\n"); - } -} - -AnalyticsFlurry::~AnalyticsFlurry() -{ -} - -bool AnalyticsFlurry::init() -{ - return PluginUtilsIOS::initOCPlugin(this, "FlurryWrapper"); -} - -/** override methods of base class */ -/** Start a new session. */ -void AnalyticsFlurry::startSession(const char* appKey) -{ - ProtocolAnalytics::startSession(appKey); -} - -/** Stop a session. - only worked on android -*/ -void AnalyticsFlurry::stopSession() -{ - ProtocolAnalytics::stopSession(); -} - -/** Set whether needs to output logs to console.*/ -void AnalyticsFlurry::setDebugMode(bool debug) -{ - s_bDebugable = debug; - ProtocolAnalytics::setDebugMode(debug); -} - -/** Set the timeout for expiring a session. */ -void AnalyticsFlurry::setSessionContinueMillis(long millis) -{ - ProtocolAnalytics::setSessionContinueMillis(millis); -} - -/** log an error */ -void AnalyticsFlurry::logError(const char* errorId, const char* message) -{ - ProtocolAnalytics::logError(errorId, message); -} - -/** log an event. */ -void AnalyticsFlurry::logEvent(const char* eventId, LogEventParamMap* paramMap) -{ - ProtocolAnalytics::logEvent(eventId, paramMap); -} - -void AnalyticsFlurry::logTimedEventBegin(const char* eventId) -{ - ProtocolAnalytics::logTimedEventBegin(eventId); -} - -/** end a timed event */ -void AnalyticsFlurry::logTimedEventEnd(const char* eventId) -{ - ProtocolAnalytics::logTimedEventEnd(eventId); -} - -/** Whether to catch uncaught exceptions to server. - only worked on android - */ -void AnalyticsFlurry::setCaptureUncaughtException(bool enabled) -{ - ProtocolAnalytics::setCaptureUncaughtException(enabled); -} - -const char* AnalyticsFlurry::getSDKVersion() -{ - return ProtocolAnalytics::getSDKVersion(); -} - -void AnalyticsFlurry::setAge(int age) -{ - NSNumber* numAge = [NSNumber numberWithInt:age]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setAge:", numAge); -} - -void AnalyticsFlurry::setGender(Gender gender) -{ - NSString* ret = @"m"; - if (gender == FEMALE) { - ret = @"f"; - } - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setGender:", ret); -} - -void AnalyticsFlurry::setUserId(const char* userId) -{ - if (NULL == userId || strlen(userId) == 0) { - FlurryLogD("userId is invalid"); - return; - } - NSString* pUserID = [NSString stringWithUTF8String:userId]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setUserId:", pUserID); -} - -void AnalyticsFlurry::logPageView() -{ - PluginUtilsIOS::callOCFunctionWithName(this, "logPageView"); -} - -void AnalyticsFlurry::setVersionName(const char* versionName) -{ - NSString* pVer = [NSString stringWithUTF8String:versionName]; - PluginUtilsIOS::callOCFunctionWithName_Object(this, "setVersionName:", pVer); -} - -/** - @warning only worked on android - */ -void AnalyticsFlurry::setUseHttps(bool useHttps) -{ - FlurryLogD("setUseHttps in flurry not available on iOS"); -} - -/** - @warning only worked on android - */ -void AnalyticsFlurry::setReportLocation(bool enabled) -{ - FlurryLogD("setReportLocation in flurry not available on iOS"); -} - -void AnalyticsFlurry::logTimedEventBegin(const char* eventId, LogEventParamMap* paramMap) -{ - if (NULL == eventId || strlen(eventId) == 0) { - FlurryLogD("eventId is invalid!"); - return; - } - - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == paramMap) { - this->logTimedEventBegin(eventId); - } else { - NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logTimedEventBegin:withParam:"); - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:pId withObject:dict]; - } - } - } -} - -void AnalyticsFlurry::logTimedEventEnd(const char* eventId, LogEventParamMap* paramMap) -{ - if (NULL == eventId || strlen(eventId) == 0) { - FlurryLogD("eventId is invalid!"); - return; - } - - NSString* pId = [NSString stringWithUTF8String:eventId]; - if (NULL == paramMap) { - this->logTimedEventEnd(eventId); - } else { - NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logTimedEventEnd:withParam:"); - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:pId withObject:dict]; - } - } - } -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/flurry/platform/ios/FlurryWrapper.m b/plugin/plugins/flurry/platform/ios/FlurryWrapper.m deleted file mode 100644 index 14ba8bda1b..0000000000 --- a/plugin/plugins/flurry/platform/ios/FlurryWrapper.m +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#import "FlurryWrapper.h" -#import "Flurry.h" - -@implementation FlurryWrapper - -- (void) startSession: (NSString*) appKey -{ - [Flurry startSession:appKey]; -} - -- (void) stopSession -{ - NSLog(@"stopSession in flurry not available on iOS"); -} - -- (void) setSessionContinueMillis: (NSNumber*) millis -{ - long lMillis = [millis longValue]; - int seconds = (int)(lMillis / 1000); - [Flurry setSessionContinueSeconds:seconds]; -} - -- (void) setCaptureUncaughtException: (NSNumber*) isEnabled -{ - NSLog(@"setCaptureUncaughtException in flurry not available on iOS"); -} - -- (void) setDebugMode: (NSNumber*) isDebugMode -{ - BOOL bDebug = [isDebugMode boolValue]; - [Flurry setDebugLogEnabled:bDebug]; -} - -- (void) logError: (NSString*) errorId withMsg:(NSString*) message -{ - NSString* msg = nil; - if (nil == message) { - msg = @""; - } else { - msg = message; - } - [Flurry logError:errorId message:msg exception:nil]; -} - -- (void) logEvent: (NSString*) eventId -{ - [Flurry logEvent:eventId]; -} - -- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap -{ - [Flurry logEvent:eventId withParameters:paramMap]; -} - -- (void) logTimedEventBegin: (NSString*) eventId -{ - [Flurry logEvent:eventId timed:YES]; -} - -- (void) logTimedEventEnd: (NSString*) eventId -{ - [Flurry endTimedEvent:eventId withParameters:nil]; -} - -- (NSString*) getSDKVersion -{ - return [Flurry getFlurryAgentVersion]; -} - -- (void) setAge: (NSNumber*) age -{ - int nAge = [age integerValue]; - [Flurry setAge:nAge]; -} - -- (void) setGender: (NSString*) gender -{ - [Flurry setGender:gender]; -} - -- (void) setUserId: (NSString*) userId -{ - [Flurry setUserID:userId]; -} - -- (void) logPageView -{ - [Flurry logPageView]; -} - -- (void) setVersionName: (NSString*) versionName -{ - [Flurry setAppVersion:versionName]; -} - -- (void) logTimedEventBegin: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap -{ - [Flurry logEvent:eventId withParameters:paramMap timed:YES]; -} - -- (void) logTimedEventEnd: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap -{ - [Flurry endTimedEvent:eventId withParameters:paramMap]; -} - -@end diff --git a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java index 4019f25192..851dc32cc9 100644 --- a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java +++ b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java @@ -130,7 +130,7 @@ public class AnalyticsFlurry implements InterfaceAnalytics { return ret; } - protected void logTimedEventBegin(JSONObject eventInfo) { + protected void logTimedEventBeginWithParams(JSONObject eventInfo) { LogD("logTimedEventBegin invoked!"); try{ String eventId = eventInfo.getString("Param1"); diff --git a/plugin/plugins/flurry/platform/ios/FlurryWrapper.h b/plugin/plugins/flurry/proj.ios/AnalyticsFlurry.h similarity index 79% rename from plugin/plugins/flurry/platform/ios/FlurryWrapper.h rename to plugin/plugins/flurry/proj.ios/AnalyticsFlurry.h index 3a9da52a6f..43686919da 100644 --- a/plugin/plugins/flurry/platform/ios/FlurryWrapper.h +++ b/plugin/plugins/flurry/proj.ios/AnalyticsFlurry.h @@ -23,25 +23,28 @@ THE SOFTWARE. ****************************************************************************/ #import "InterfaceAnalytics.h" -@interface FlurryWrapper : NSObject +@interface AnalyticsFlurry : NSObject { } +@property BOOL debug; + /** interfaces of protocol : InterfaceAnalytics */ - (void) startSession: (NSString*) appKey; - (void) stopSession; -- (void) setSessionContinueMillis: (NSNumber*) millis; -- (void) setCaptureUncaughtException: (NSNumber*) isEnabled; -- (void) setDebugMode: (NSNumber*) isDebugMode; +- (void) setSessionContinueMillis: (long) millis; +- (void) setCaptureUncaughtException: (BOOL) isEnabled; +- (void) setDebugMode: (BOOL) isDebugMode; - (void) logError: (NSString*) errorId withMsg:(NSString*) message; - (void) logEvent: (NSString*) eventId; - (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; - (void) logTimedEventBegin: (NSString*) eventId; - (void) logTimedEventEnd: (NSString*) eventId; - (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; /** interfaces of flurry SDK @@ -49,9 +52,10 @@ THE SOFTWARE. - (void) setAge: (NSNumber*) age; - (void) setGender: (NSString*) gender; - (void) setUserId: (NSString*) userId; +- (void) setUseHttps: (NSNumber*) enabled; - (void) logPageView; - (void) setVersionName: (NSString*) versionName; -- (void) logTimedEventBegin: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; -- (void) logTimedEventEnd: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventBeginWithParams: (NSMutableDictionary*) params; +- (void) logTimedEventEndWithParams: (NSMutableDictionary*) params; @end diff --git a/plugin/plugins/flurry/proj.ios/AnalyticsFlurry.m b/plugin/plugins/flurry/proj.ios/AnalyticsFlurry.m new file mode 100644 index 0000000000..1ce6df0b9c --- /dev/null +++ b/plugin/plugins/flurry/proj.ios/AnalyticsFlurry.m @@ -0,0 +1,166 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "AnalyticsFlurry.h" +#import "Flurry.h" + +#define OUTPUT_LOG(...) if (self.debug) NSLog(__VA_ARGS__); + +@implementation AnalyticsFlurry + +@synthesize debug = __debug; + +- (void) startSession: (NSString*) appKey +{ + [Flurry startSession:appKey]; +} + +- (void) stopSession +{ + OUTPUT_LOG(@"Flurry stopSession in flurry not available on iOS"); +} + +- (void) setSessionContinueMillis: (long) millis +{ + OUTPUT_LOG(@"Flurry setSessionContinueMillis invoked(%ld)", millis); + int seconds = (int)(millis / 1000); + [Flurry setSessionContinueSeconds:seconds]; +} + +- (void) setCaptureUncaughtException: (BOOL) isEnabled +{ + OUTPUT_LOG(@"Flurry setCaptureUncaughtException in flurry not available on iOS"); +} + +- (void) setDebugMode: (BOOL) isDebugMode +{ + OUTPUT_LOG(@"Flurry setDebugMode invoked(%d)", isDebugMode); + self.debug = isDebugMode; + [Flurry setDebugLogEnabled:isDebugMode]; +} + +- (void) logError: (NSString*) errorId withMsg:(NSString*) message +{ + OUTPUT_LOG(@"Flurry logError invoked(%@, %@)", errorId, message); + NSString* msg = nil; + if (nil == message) { + msg = @""; + } else { + msg = message; + } + [Flurry logError:errorId message:msg exception:nil]; +} + +- (void) logEvent: (NSString*) eventId +{ + OUTPUT_LOG(@"Flurry logEvent invoked(%@)", eventId); + [Flurry logEvent:eventId]; +} + +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap +{ + OUTPUT_LOG(@"Flurry logEventWithParams invoked (%@, %@)", eventId, [paramMap debugDescription]); + [Flurry logEvent:eventId withParameters:paramMap]; +} + +- (void) logTimedEventBegin: (NSString*) eventId +{ + OUTPUT_LOG(@"Flurry logTimedEventBegin invoked (%@)", eventId); + [Flurry logEvent:eventId timed:YES]; +} + +- (void) logTimedEventEnd: (NSString*) eventId +{ + OUTPUT_LOG(@"Flurry logTimedEventEnd invoked (%@)", eventId); + [Flurry endTimedEvent:eventId withParameters:nil]; +} + +- (NSString*) getSDKVersion +{ + return [Flurry getFlurryAgentVersion]; +} + +- (NSString*) getPluginVersion +{ + return @"0.2.0"; +} + +- (void) setAge: (NSNumber*) age +{ + int nAge = [age integerValue]; + OUTPUT_LOG(@"Flurry setAge invoked (%d)", nAge); + [Flurry setAge:nAge]; +} + +- (void) setGender: (NSString*) gender +{ + OUTPUT_LOG(@"Flurry setGender invoked (%@)", gender); + [Flurry setGender:gender]; +} + +- (void) setUserId: (NSString*) userId +{ + OUTPUT_LOG(@"Flurry setUserId invoked (%@)", userId); + [Flurry setUserID:userId]; +} + +- (void) setUseHttps: (NSNumber*) enabled +{ + BOOL bEnabled = [enabled boolValue]; + OUTPUT_LOG(@"Flurry setUseHttps invoked (%@)", enabled); + [Flurry setSecureTransportEnabled:bEnabled]; +} + +- (void) logPageView +{ + OUTPUT_LOG(@"Flurry logPageView invoked"); + [Flurry logPageView]; +} + +- (void) setVersionName: (NSString*) versionName +{ + OUTPUT_LOG(@"Flurry setVersionName invoked (%@)", versionName); + [Flurry setAppVersion:versionName]; +} + +- (void) logTimedEventBeginWithParams: (NSMutableDictionary*) paramMap +{ + OUTPUT_LOG(@"Flurry logTimedEventBeginWithParams invoked (%@)", [paramMap debugDescription]); + NSString* eventId = (NSString*) [paramMap objectForKey:@"Param1"]; + NSMutableDictionary* params = (NSMutableDictionary*) [paramMap objectForKey:@"Param2"]; + if (params) { + [Flurry logEvent:eventId withParameters:paramMap timed:YES]; + } else { + [Flurry logEvent:eventId timed:YES]; + } +} + +- (void) logTimedEventEndWithParams: (NSMutableDictionary*) paramMap +{ + OUTPUT_LOG(@"Flurry logTimedEventEndWithParams invoked (%@)", [paramMap debugDescription]); + NSString* eventId = (NSString*) [paramMap objectForKey:@"Param1"]; + NSMutableDictionary* params = (NSMutableDictionary*) [paramMap objectForKey:@"Param2"]; + [Flurry endTimedEvent:eventId withParameters:params]; +} + +@end diff --git a/plugin/plugins/flurry/platform/ios/Flurry.h b/plugin/plugins/flurry/proj.ios/Flurry.h similarity index 100% rename from plugin/plugins/flurry/platform/ios/Flurry.h rename to plugin/plugins/flurry/proj.ios/Flurry.h diff --git a/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj b/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj index eb8e0bdb3b..ddeb98acd6 100644 --- a/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj +++ b/plugin/plugins/flurry/proj.ios/PluginFlurry.xcodeproj/project.pbxproj @@ -8,9 +8,8 @@ /* Begin PBXBuildFile section */ FA09A376168AFD41008C1C7B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA09A375168AFD41008C1C7B /* Foundation.framework */; }; - FA09A394168B00D4008C1C7B /* AnalyticsFlurry.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA09A393168B00D4008C1C7B /* AnalyticsFlurry.mm */; }; - FA866509168BE0980073E055 /* libFlurry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FA866508168BE0980073E055 /* libFlurry.a */; }; - FA8CC2241739EFF200464206 /* FlurryWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = FA8CC2231739EFF200464206 /* FlurryWrapper.m */; }; + FAB6DFDD1756F22200C90D89 /* libFlurry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FAB6DFDB1756F22200C90D89 /* libFlurry.a */; }; + FAB6DFE01756F29800C90D89 /* AnalyticsFlurry.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB6DFDF1756F29800C90D89 /* AnalyticsFlurry.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -28,13 +27,11 @@ /* Begin PBXFileReference section */ FA09A372168AFD41008C1C7B /* libPluginFlurry.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPluginFlurry.a; sourceTree = BUILT_PRODUCTS_DIR; }; FA09A375168AFD41008C1C7B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - FA09A391168AFD79008C1C7B /* AnalyticsFlurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnalyticsFlurry.h; sourceTree = ""; }; - FA09A393168B00D4008C1C7B /* AnalyticsFlurry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnalyticsFlurry.mm; sourceTree = ""; }; - FA866507168BE0980073E055 /* Flurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Flurry.h; sourceTree = ""; }; - FA866508168BE0980073E055 /* libFlurry.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libFlurry.a; sourceTree = ""; }; FA86650E168BE22D0073E055 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; - FA8CC2221739EFF200464206 /* FlurryWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlurryWrapper.h; sourceTree = ""; }; - FA8CC2231739EFF200464206 /* FlurryWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlurryWrapper.m; sourceTree = ""; }; + FAB6DFD81756F22200C90D89 /* Flurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Flurry.h; sourceTree = ""; }; + FAB6DFDB1756F22200C90D89 /* libFlurry.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libFlurry.a; sourceTree = ""; }; + FAB6DFDE1756F29800C90D89 /* AnalyticsFlurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnalyticsFlurry.h; sourceTree = ""; }; + FAB6DFDF1756F29800C90D89 /* AnalyticsFlurry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnalyticsFlurry.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -43,7 +40,7 @@ buildActionMask = 2147483647; files = ( FA09A376168AFD41008C1C7B /* Foundation.framework in Frameworks */, - FA866509168BE0980073E055 /* libFlurry.a in Frameworks */, + FAB6DFDD1756F22200C90D89 /* libFlurry.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -53,9 +50,11 @@ FA09A367168AFD41008C1C7B = { isa = PBXGroup; children = ( + FAB6DFDE1756F29800C90D89 /* AnalyticsFlurry.h */, + FAB6DFDF1756F29800C90D89 /* AnalyticsFlurry.m */, + FAB6DFD81756F22200C90D89 /* Flurry.h */, + FAB6DFDB1756F22200C90D89 /* libFlurry.a */, FA86650E168BE22D0073E055 /* SystemConfiguration.framework */, - FA09A392168AFD96008C1C7B /* ios */, - FA09A390168AFD79008C1C7B /* include */, FA09A374168AFD41008C1C7B /* Frameworks */, FA09A373168AFD41008C1C7B /* Products */, ); @@ -77,28 +76,6 @@ name = Frameworks; sourceTree = ""; }; - FA09A390168AFD79008C1C7B /* include */ = { - isa = PBXGroup; - children = ( - FA09A391168AFD79008C1C7B /* AnalyticsFlurry.h */, - ); - name = include; - path = ../include; - sourceTree = ""; - }; - FA09A392168AFD96008C1C7B /* ios */ = { - isa = PBXGroup; - children = ( - FA8CC2221739EFF200464206 /* FlurryWrapper.h */, - FA8CC2231739EFF200464206 /* FlurryWrapper.m */, - FA866507168BE0980073E055 /* Flurry.h */, - FA866508168BE0980073E055 /* libFlurry.a */, - FA09A393168B00D4008C1C7B /* AnalyticsFlurry.mm */, - ); - name = ios; - path = ../platform/ios; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -150,8 +127,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - FA09A394168B00D4008C1C7B /* AnalyticsFlurry.mm in Sources */, - FA8CC2241739EFF200464206 /* FlurryWrapper.m in Sources */, + FAB6DFE01756F29800C90D89 /* AnalyticsFlurry.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -215,6 +191,7 @@ LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/../platform/ios\"", + "\"$(SRCROOT)\"", ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = PluginFlurry; @@ -235,6 +212,7 @@ LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)/../platform/ios\"", + "\"$(SRCROOT)\"", ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = PluginFlurry; diff --git a/plugin/plugins/flurry/platform/ios/libFlurry.a.REMOVED.git-id b/plugin/plugins/flurry/proj.ios/libFlurry.a.REMOVED.git-id similarity index 100% rename from plugin/plugins/flurry/platform/ios/libFlurry.a.REMOVED.git-id rename to plugin/plugins/flurry/proj.ios/libFlurry.a.REMOVED.git-id diff --git a/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm b/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm deleted file mode 100644 index e4cd9d3ba4..0000000000 --- a/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm +++ /dev/null @@ -1,380 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "AnalyticsUmeng.h" -#include "MobClick.h" -#include "PluginUtilsIOS.h" - -namespace cocos2d { namespace plugin { - -PLUGIN_REGISTER_IMPL(AnalyticsUmeng) - -#define LOG_MAX_LENGTH (16 * 1024) - -static bool s_bDebugable = false; -void UmengLogD(const char * pszFormat, ...) { - if (s_bDebugable) { - printf("AnalyticsUmeng : "); - char szBuf[LOG_MAX_LENGTH]; - - va_list ap; - va_start(ap, pszFormat); - vsnprintf(szBuf, LOG_MAX_LENGTH, pszFormat, ap); - va_end(ap); - printf("%s", szBuf); - printf("\n"); - } -} - -AnalyticsUmeng::~AnalyticsUmeng() -{ -} - -bool AnalyticsUmeng::init() -{ - return PluginUtilsIOS::initOCPlugin(this, "UmengWrapper"); -} - -/** Start a new session. */ -void AnalyticsUmeng::startSession(const char* appKey) -{ - ProtocolAnalytics::startSession(appKey); -} - -/** Stop a session. only worked on android */ -void AnalyticsUmeng::stopSession() -{ - ProtocolAnalytics::stopSession(); -} - -/** Set whether needs to output logs to console.*/ -void AnalyticsUmeng::setDebugMode(bool debug) -{ - s_bDebugable = debug; - ProtocolAnalytics::setDebugMode(debug); -} - -/** Set the timeout for expiring a session. */ -void AnalyticsUmeng::setSessionContinueMillis(long millis) -{ - ProtocolAnalytics::setSessionContinueMillis(millis); -} - -/** log an error */ -void AnalyticsUmeng::logError(const char* errorId, const char* message) -{ - ProtocolAnalytics::logError(errorId, message); -} - -/** log an event. */ -void AnalyticsUmeng::logEvent(const char* eventId, LogEventParamMap* paramMap) -{ - ProtocolAnalytics::logEvent(eventId, paramMap); -} - -/** begin to log a timed event */ -void AnalyticsUmeng::logTimedEventBegin(const char* eventId) -{ - ProtocolAnalytics::logTimedEventBegin(eventId); -} - -/** end a timed event */ -void AnalyticsUmeng::logTimedEventEnd(const char* eventId) -{ - ProtocolAnalytics::logTimedEventEnd(eventId); -} - -/** Whether to catch uncaught exceptions to server.*/ -void AnalyticsUmeng::setCaptureUncaughtException(bool enabled) -{ - ProtocolAnalytics::setCaptureUncaughtException(enabled); -} - -const char* AnalyticsUmeng::getSDKVersion() -{ - return ProtocolAnalytics::getSDKVersion(); -} - -void AnalyticsUmeng::updateOnlineConfig() -{ - PluginUtilsIOS::callOCFunctionWithName(this, "updateOnlineConfig"); -} - -const char* AnalyticsUmeng::getConfigParams(const char* key) -{ - NSString* strKey = [NSString stringWithUTF8String:key]; - return [[MobClick getConfigParams:strKey] UTF8String]; - - - if (NULL == key || strlen(key) == 0) { - UmengLogD("The key is invalid!"); - return ""; - } - - NSString* pKey = [NSString stringWithUTF8String:key]; - NSString* ret = nil; - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"getConfigParams:"); - if ([pOCObj respondsToSelector:selector]) { - ret = [pOCObj performSelector:selector withObject:pKey]; - } - } - - const char* pRet = (nil == ret) ? NULL : [ret UTF8String]; - return pRet; -} - -static AnalyticsUmeng::UmengReportPolicy s_defaultPolicy = AnalyticsUmeng::UmengReportPolicy::REALTIME; -void AnalyticsUmeng::setDefaultReportPolicy(UmengReportPolicy ePolicy) -{ - s_defaultPolicy = ePolicy; -} - -void AnalyticsUmeng::logEventWithLabel(const char* eventId, const char* label) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - NSString* strEvent = [NSString stringWithUTF8String:eventId]; - NSString* strLabel = [NSString stringWithUTF8String:label]; - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logEvent:withLabel:"); - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; - } - } -} - -void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, const char* label) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - do { - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - - if (! pData) break; - - id pOCObj = pData->obj; - NSString* className = [NSString stringWithUTF8String:pData->className.c_str()]; - SEL selector = NSSelectorFromString(@"logEvent:withDuration:withLabel:"); - - if (! [pOCObj respondsToSelector:selector]) { - break; - } - - NSString* strEventId = [NSString stringWithUTF8String:eventId]; - NSString* strLabel = [NSString stringWithUTF8String:label]; - NSNumber* numDur = [NSNumber numberWithLong:duration]; - - NSMethodSignature *sig= [NSClassFromString(className) instanceMethodSignatureForSelector:selector]; - NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:sig]; - [invocation setTarget:pOCObj]; - [invocation setSelector:selector]; - [invocation setArgument:&strEventId atIndex:2]; - [invocation setArgument:&numDur atIndex:3]; - [invocation setArgument:&strLabel atIndex:4]; - [invocation retainArguments]; - [invocation invoke]; - } while (0); -} - -void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, LogEventParamMap* paramMap) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - do { - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - - if (! pData) break; - - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logEvent:withDuration:withParam:"); - - if (! [pOCObj respondsToSelector:selector]) { - break; - } - - NSString* strEventId = [NSString stringWithUTF8String:eventId]; - NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); - NSNumber* numDur = [NSNumber numberWithLong:duration]; - - NSMethodSignature *sig = [[pOCObj class] instanceMethodSignatureForSelector:selector]; - NSInvocation *invocation =[NSInvocation invocationWithMethodSignature:sig]; - - [invocation setSelector:selector]; - [invocation setTarget:pOCObj]; - [invocation setArgument:&strEventId atIndex:2]; - [invocation setArgument:&numDur atIndex:3]; - [invocation setArgument:&dict atIndex:4]; - [invocation retainArguments]; - [invocation invoke]; - } while (0); -} - -void AnalyticsUmeng::logTimedEventWithLabelBegin(const char* eventId, const char* label) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - NSString* strEvent = [NSString stringWithUTF8String:eventId]; - NSString* strLabel = [NSString stringWithUTF8String:label]; - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logTimedEventBegin:withLabel:"); - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; - } - } -} - -void AnalyticsUmeng::logTimedEventWithLabelEnd(const char* eventId, const char* label) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - NSString* strEvent = [NSString stringWithUTF8String:eventId]; - NSString* strLabel = [NSString stringWithUTF8String:label]; - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logTimedEventEnd:withLabel:"); - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; - } - } -} - -void AnalyticsUmeng::logTimedKVEventBegin(const char* eventId, const char* label, LogEventParamMap* paramMap) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - do { - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - - if (! pData) break; - - id pOCObj = pData->obj; - NSString* className = [NSString stringWithUTF8String:pData->className.c_str()]; - SEL selector = NSSelectorFromString(@"logTimedKVEventBegin:withLabel:withParam:"); - - if (! [pOCObj respondsToSelector:selector]) { - break; - } - - NSString* strEventId = [NSString stringWithUTF8String:eventId]; - NSMutableDictionary* dict = PluginUtilsIOS::createDictFromMap(paramMap); - NSString* strLabel = [NSString stringWithUTF8String:label]; - - NSMethodSignature *sig= [NSClassFromString(className) instanceMethodSignatureForSelector:selector]; - NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:sig]; - [invocation setTarget:pOCObj]; - [invocation setSelector:selector]; - [invocation setArgument:&strEventId atIndex:2]; - [invocation setArgument:&strLabel atIndex:3]; - [invocation setArgument:&dict atIndex:4]; - [invocation retainArguments]; - [invocation invoke]; - } while (0); -} - -void AnalyticsUmeng::logTimedKVEventEnd(const char* eventId, const char* label) -{ - if (NULL == eventId || strlen(eventId) == 0) { - UmengLogD("eventId is invalid"); - return; - } - - NSString* strEvent = [NSString stringWithUTF8String:eventId]; - NSString* strLabel = [NSString stringWithUTF8String:label]; - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - if (pData) { - id pOCObj = pData->obj; - SEL selector = NSSelectorFromString(@"logTimedKVEventEnd:withLabel:"); - if ([pOCObj respondsToSelector:selector]) { - [pOCObj performSelector:selector withObject:strEvent withObject:strLabel]; - } - } -} - -void AnalyticsUmeng::startSession(const char* appKey, UmengReportPolicy policy, const char* channelId) -{ - if (NULL == appKey || strlen(appKey) == 0) { - UmengLogD("appKey is invalid"); - return; - } - - do { - PluginOCData* pData = PluginUtilsIOS::getPluginOCData(this); - - if (! pData) break; - - id pOCObj = pData->obj; - NSString* className = [NSString stringWithUTF8String:pData->className.c_str()]; - SEL selector = NSSelectorFromString(@"logTimedKVEventBegin:withLabel:withParam:"); - - if (! [pOCObj respondsToSelector:selector]) { - break; - } - - NSString* strKey = [NSString stringWithUTF8String:appKey]; - NSNumber* numPolicy = [NSNumber numberWithInt:policy]; - NSString* strChannel = [NSString stringWithUTF8String:channelId]; - - NSMethodSignature *sig= [NSClassFromString(className) instanceMethodSignatureForSelector:selector]; - NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:sig]; - [invocation setTarget:pOCObj]; - [invocation setSelector:selector]; - [invocation setArgument:&strKey atIndex:2]; - [invocation setArgument:&numPolicy atIndex:3]; - [invocation setArgument:&strChannel atIndex:4]; - [invocation retainArguments]; - [invocation invoke]; - } while (0); -} - -void AnalyticsUmeng::checkUpdate() -{ - PluginUtilsIOS::callOCFunctionWithName(this, "checkUpdate"); -} - -}} // namespace cocos2d { namespace plugin { diff --git a/plugin/plugins/umeng/platform/ios/UmengWrapper.h b/plugin/plugins/umeng/platform/ios/UmengWrapper.h deleted file mode 100644 index e44671079d..0000000000 --- a/plugin/plugins/umeng/platform/ios/UmengWrapper.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#import "InterfaceAnalytics.h" - -@interface UmengWrapper : NSObject -{ - -} - -/** - interfaces of protocol : InterfaceAnalytics - */ -- (void) startSession: (NSString*) appKey; -- (void) stopSession; -- (void) setSessionContinueMillis: (NSNumber*) millis; -- (void) setCaptureUncaughtException: (NSNumber*) isEnabled; -- (void) setDebugMode: (NSNumber*) isDebugMode; -- (void) logError: (NSString*) errorId withMsg:(NSString*) message; -- (void) logEvent: (NSString*) eventId; -- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; -- (void) logTimedEventBegin: (NSString*) eventId; -- (void) logTimedEventEnd: (NSString*) eventId; -- (NSString*) getSDKVersion; - -/** - interfaces of umeng SDK - */ -- (void) updateOnlineConfig; -- (NSString*) getConfigParams: (NSString*) key; -- (void) logEvent: (NSString*) eventId withLabel:(NSString*) label; -- (void) logEvent: (NSString*) eventId withDuration: (NSNumber*) duration withLabel:(NSString*) label; -- (void) logEvent: (NSString*) eventId withDuration: (NSNumber*) duration withParam:(NSMutableDictionary*) paramMap; -- (void) logTimedEventBegin: (NSString*) eventId withLabel:(NSString*) label; -- (void) logTimedEventEnd: (NSString*) eventId withLabel:(NSString*) label; -- (void) logTimedKVEventBegin: (NSString*) eventId withLabel:(NSString*) label withParam:(NSMutableDictionary*) paramMap; -- (void) logTimedKVEventEnd: (NSString*) eventId withLabel:(NSString*) label; -- (void) startSession: (NSString*) appKey withPolicy:(NSNumber*) policy withChannel:(NSString*) channelId; -- (void) checkUpdate; - -@end diff --git a/plugin/plugins/umeng/platform/ios/UmengWrapper.m b/plugin/plugins/umeng/platform/ios/UmengWrapper.m deleted file mode 100644 index d01990a15f..0000000000 --- a/plugin/plugins/umeng/platform/ios/UmengWrapper.m +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012-2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#import "UmengWrapper.h" -#import "MobClick.h" - -@implementation UmengWrapper - -- (void) startSession: (NSString*) appKey -{ - [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; - [MobClick startWithAppkey:appKey]; -} - -- (void) stopSession -{ - NSLog(@"stopSession in umeng not available on iOS"); -} - -- (void) setSessionContinueMillis: (NSNumber*) millis -{ - NSLog(@"setSessionContinueMillis in umeng not available on iOS"); -} - -- (void) setCaptureUncaughtException: (NSNumber*) isEnabled -{ - BOOL bEnabled = [isEnabled boolValue]; - [MobClick setCrashReportEnabled:bEnabled]; -} - -- (void) setDebugMode: (NSNumber*) isDebugMode -{ - BOOL bDebug = [isDebugMode boolValue]; - [MobClick setLogEnabled:bDebug]; -} - -- (void) logError: (NSString*) errorId withMsg:(NSString*) message -{ - NSLog(@"logError in umeng not available on iOS"); -} - -- (void) logEvent: (NSString*) eventId -{ - [MobClick event:eventId]; -} - -- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap -{ - [MobClick event:eventId attributes:paramMap]; -} - -- (void) logTimedEventBegin: (NSString*) eventId -{ - [MobClick beginEvent:eventId]; -} - -- (void) logTimedEventEnd: (NSString*) eventId -{ - [MobClick endEvent:eventId]; -} - -- (NSString*) getSDKVersion -{ - return @"UMeng no version info"; -} - -- (void) updateOnlineConfig -{ - [MobClick updateOnlineConfig]; -} - -- (NSString*) getConfigParams: (NSString*) key -{ - return [MobClick getConfigParams:key]; -} - -- (void) logEvent: (NSString*) eventId withLabel:(NSString*) label -{ - [MobClick event:eventId label:label]; -} - -- (void) logEvent: (NSString*) eventId withDuration: (NSNumber*) duration withLabel:(NSString*) label -{ - long numDur = [duration longValue]; - if (! label) { - [MobClick event:eventId durations:numDur]; - } else { - [MobClick event:eventId label:label durations:numDur]; - } -} - -- (void) logEvent: (NSString*) eventId withDuration:(NSNumber*) duration withParam:(NSMutableDictionary*) paramMap -{ - long numDur = [duration longValue]; - if (! paramMap) { - [MobClick event:eventId durations:(int)numDur]; - } else { - [MobClick event:eventId attributes:paramMap durations:(int)numDur]; - } -} - -- (void) logTimedEventBegin: (NSString*) eventId withLabel:(NSString*) label -{ - if (! label) { - [MobClick beginEvent:eventId]; - } else { - [MobClick beginEvent:eventId label:label]; - } -} - -- (void) logTimedEventEnd: (NSString*) eventId withLabel:(NSString*) label -{ - if (! label) { - [MobClick endEvent:eventId]; - } else { - [MobClick endEvent:eventId label:label]; - } -} - -- (void) logTimedKVEventBegin: (NSString*) eventId withLabel:(NSString*) label withParam:(NSMutableDictionary*) paramMap -{ - if (! label || ! paramMap) { - [MobClick beginEvent:eventId]; - } else { - [MobClick beginEvent:eventId primarykey:label attributes:paramMap]; - } -} - -- (void) logTimedKVEventEnd: (NSString*) eventId withLabel:(NSString*) label -{ - if (! label) { - [MobClick endEvent:eventId]; - } else { - [MobClick endEvent:eventId primarykey:label]; - } -} - -- (void) startSession: (NSString*) appKey withPolicy:(NSNumber*) policy withChannel:(NSString*) channelId -{ - int nPolicy = [policy intValue]; - [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; - [MobClick startWithAppkey:appKey reportPolicy:(ReportPolicy)nPolicy channelId:channelId]; -} - -- (void) checkUpdate -{ - [MobClick checkUpdate]; -} - -@end diff --git a/plugin/plugins/umeng/proj.ios/AnalyticsUmeng.h b/plugin/plugins/umeng/proj.ios/AnalyticsUmeng.h new file mode 100644 index 0000000000..5f4cfa1cf9 --- /dev/null +++ b/plugin/plugins/umeng/proj.ios/AnalyticsUmeng.h @@ -0,0 +1,131 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "InterfaceAnalytics.h" + +@interface AnalyticsUmeng : NSObject +{ +} + +@property BOOL debug; + +/** + interfaces of protocol : InterfaceAnalytics + */ +- (void) startSession: (NSString*) appKey; +- (void) stopSession; +- (void) setSessionContinueMillis: (long) millis; +- (void) setCaptureUncaughtException: (BOOL) isEnabled; +- (void) setDebugMode: (BOOL) isDebugMode; +- (void) logError: (NSString*) errorId withMsg:(NSString*) message; +- (void) logEvent: (NSString*) eventId; +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap; +- (void) logTimedEventBegin: (NSString*) eventId; +- (void) logTimedEventEnd: (NSString*) eventId; +- (NSString*) getSDKVersion; +- (NSString*) getPluginVersion; + +/** + interfaces of umeng SDK + */ +- (void) updateOnlineConfig; +- (NSString*) getConfigParams: (NSString*) key; + +/** + @brief logEvent with label. + @param params The dictionary include eventId & label + get eventId with key 'Param1' from dictionary + get label with key 'Param2' from dictionary + */ +- (void) logEventWithLabel: (NSMutableDictionary*) params; + +/** + @brief logEvent with duration. + @param params The dictionary include eventId & duration + get eventId with key 'Param1' from dictionary + get duration with key 'Param2' from dictionary + */ +- (void) logEventWithDuration: (NSMutableDictionary*) params; + +/** + @brief logEvent with duration & label. + @param params The dictionary include eventId & duration & label + get eventId with key 'Param1' from dictionary + get duration with key 'Param2' from dictionary + get label with key 'Param3' from dictionary + */ +- (void) logEventWithDurationLabel: (NSMutableDictionary*) params; + +/** + @brief logEvent with duration & attributes. + @param params The dictionary include eventId & duration & attributes + get eventId with key 'Param1' from dictionary + get duration with key 'Param2' from dictionary + get attributes with key 'Param3' from dictionary + */ +- (void) logEventWithDurationParams: (NSMutableDictionary*) params; + +/** + @brief log timed event begin with label. + @param params The dictionary include eventId & label + get eventId with key 'Param1' from dictionary + get label with key 'Param2' from dictionary + */ +- (void) logTimedEventWithLabelBegin: (NSMutableDictionary*) params; + +/** + @brief log timed event end with label. + @param params The dictionary include eventId & label + get eventId with key 'Param1' from dictionary + get label with key 'Param2' from dictionary + */ +- (void) logTimedEventWithLabelEnd: (NSMutableDictionary*) params; + +/** + @brief log timed KV event with label & attributes. + @param params The dictionary include eventId & label & attributes + get eventId with key 'Param1' from dictionary + get label with key 'Param2' from dictionary + get attributes with key 'Param3' from dictionary + */ +- (void) logTimedKVEventBegin: (NSMutableDictionary*) params; + +/** + @brief log timed KV event end with label. + @param params The dictionary include eventId & label + get eventId with key 'Param1' from dictionary + get label with key 'Param2' from dictionary + */ +- (void) logTimedKVEventEnd: (NSMutableDictionary*) params; + +/** + @brief start session with policy & channelId. + @param params The dictionary include appKey & policy & channelId + get appKey with key 'Param1' from dictionary + get policy(NSNumber*) with key 'Param2' from dictionary + get channelId with key 'Param3' from dictionary + */ +- (void) startSessionWithParams: (NSMutableDictionary*) params; +- (void) checkUpdate; + +@end diff --git a/plugin/plugins/umeng/proj.ios/AnalyticsUmeng.m b/plugin/plugins/umeng/proj.ios/AnalyticsUmeng.m new file mode 100644 index 0000000000..7805586e6b --- /dev/null +++ b/plugin/plugins/umeng/proj.ios/AnalyticsUmeng.m @@ -0,0 +1,236 @@ +/**************************************************************************** +Copyright (c) 2012-2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +#import "AnalyticsUmeng.h" +#import "MobClick.h" + +#define OUTPUT_LOG(...) if (self.debug) NSLog(__VA_ARGS__); + +@implementation AnalyticsUmeng + +@synthesize debug = __debug; + +- (void) startSession: (NSString*) appKey +{ + OUTPUT_LOG(@"Umeng startSession invoked"); + [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; + [MobClick startWithAppkey:appKey]; +} + +- (void) stopSession +{ + OUTPUT_LOG(@"Umeng stopSession in umeng not available on iOS"); +} + +- (void) setSessionContinueMillis: (long) millis +{ + OUTPUT_LOG(@"Umeng setSessionContinueMillis in umeng not available on iOS"); +} + +- (void) setCaptureUncaughtException: (BOOL) isEnabled +{ + OUTPUT_LOG(@"Umeng setCaptureUncaughtException invoked"); + [MobClick setCrashReportEnabled:isEnabled]; +} + +- (void) setDebugMode: (BOOL) isDebugMode +{ + OUTPUT_LOG(@"Umeng setDebugMode invoked"); + self.debug = isDebugMode; + [MobClick setLogEnabled:isDebugMode]; +} + +- (void) logError: (NSString*) errorId withMsg:(NSString*) message +{ + OUTPUT_LOG(@"logError in umeng not available on iOS"); +} + +- (void) logEvent: (NSString*) eventId +{ + OUTPUT_LOG(@"Umeng logEvent invoked"); + [MobClick event:eventId]; +} + +- (void) logEvent: (NSString*) eventId withParam:(NSMutableDictionary*) paramMap +{ + OUTPUT_LOG(@"Umeng logEventWithParam invoked"); + [MobClick event:eventId attributes:paramMap]; +} + +- (void) logTimedEventBegin: (NSString*) eventId +{ + OUTPUT_LOG(@"Umeng logTimedEventBegin invoked"); + [MobClick beginEvent:eventId]; +} + +- (void) logTimedEventEnd: (NSString*) eventId +{ + OUTPUT_LOG(@"Umeng logTimedEventEnd invoked"); + [MobClick endEvent:eventId]; +} + +- (NSString*) getSDKVersion +{ + return @"2.2.0"; +} + +- (NSString*) getPluginVersion +{ + return @"0.2.0"; +} + +- (void) updateOnlineConfig +{ + OUTPUT_LOG(@"Umeng updateOnlineConfig invoked"); + [MobClick updateOnlineConfig]; +} + +- (NSString*) getConfigParams: (NSString*) key +{ + OUTPUT_LOG(@"Umeng getConfigParams invoked (%@)", key); + return [MobClick getConfigParams:key]; +} + +- (void) logEventWithLabel: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logEventWithLabel invoked (%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSString* label = (NSString*) [params objectForKey:@"Param2"]; + if (label) { + [MobClick event:eventId label:label]; + } else { + [MobClick event:eventId]; + } +} + +- (void) logEventWithDuration: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logEventWithDuration invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSNumber* duration = (NSNumber*) [params objectForKey:@"Param2"]; + long numDur = [duration longValue]; + [MobClick event:eventId durations:numDur]; +} + +- (void) logEventWithDurationLabel:(NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logEventWithDurationLabel invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSNumber* duration = (NSNumber*) [params objectForKey:@"Param2"]; + NSString* label = (NSString*) [params objectForKey:@"Param3"]; + long numDur = [duration longValue]; + + if (! label) { + [MobClick event:eventId durations:numDur]; + } else { + [MobClick event:eventId label:label durations:numDur]; + } +} + +- (void) logEventWithDurationParams: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logEventWithDurationParams invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSNumber* duration = (NSNumber*) [params objectForKey:@"Param2"]; + NSMutableDictionary* paramMap = (NSMutableDictionary*) [params objectForKey:@"Param3"]; + long numDur = [duration longValue]; + + if (! paramMap) { + [MobClick event:eventId durations:numDur]; + } else { + [MobClick event:eventId attributes:paramMap durations:numDur]; + } +} + +- (void) logTimedEventWithLabelBegin: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logTimedEventWithLabelBegin invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSString* label = (NSString*) [params objectForKey:@"Param2"]; + + if (! label) { + [MobClick beginEvent:eventId]; + } else { + [MobClick beginEvent:eventId label:label]; + } +} + +- (void) logTimedEventWithLabelEnd: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logTimedEventWithLabelEnd invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSString* label = (NSString*) [params objectForKey:@"Param2"]; + + if (! label) { + [MobClick endEvent:eventId]; + } else { + [MobClick endEvent:eventId label:label]; + } +} + +- (void) logTimedKVEventBegin: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logTimedKVEventBegin invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSString* label = (NSString*) [params objectForKey:@"Param2"]; + NSMutableDictionary* paramMap = (NSMutableDictionary*) [params objectForKey:@"Param3"]; + + if (! label || ! paramMap) { + [MobClick beginEvent:eventId]; + } else { + [MobClick beginEvent:eventId primarykey:label attributes:paramMap]; + } +} + +- (void) logTimedKVEventEnd: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng logTimedKVEventEnd invoked(%@)", [params debugDescription]); + NSString* eventId = (NSString*) [params objectForKey:@"Param1"]; + NSString* label = (NSString*) [params objectForKey:@"Param2"]; + + if (! label) { + [MobClick endEvent:eventId]; + } else { + [MobClick endEvent:eventId primarykey:label]; + } +} + +- (void) startSessionWithParams: (NSMutableDictionary*) params +{ + OUTPUT_LOG(@"Umeng startSessionWithParams invoked(%@)", [params debugDescription]); + NSString* appKey = (NSString*) [params objectForKey:@"Param1"]; + NSNumber* policy = (NSNumber*) [params objectForKey:@"Param2"]; + NSString* channelId = (NSString*) [params objectForKey:@"Param3"]; + + int nPolicy = [policy intValue]; + [[MobClick class] performSelector:@selector(setWrapperType:wrapperVersion:) withObject:@"Cocos2d-x" withObject:@"1.0"]; + [MobClick startWithAppkey:appKey reportPolicy:(ReportPolicy)nPolicy channelId:channelId]; +} + +- (void) checkUpdate +{ + OUTPUT_LOG(@"Umeng checkUpdate invoked"); + [MobClick checkUpdate]; +} + +@end diff --git a/plugin/plugins/umeng/platform/ios/MobClick.h b/plugin/plugins/umeng/proj.ios/MobClick.h similarity index 100% rename from plugin/plugins/umeng/platform/ios/MobClick.h rename to plugin/plugins/umeng/proj.ios/MobClick.h diff --git a/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj b/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj index c3ce573636..3500b4499c 100644 --- a/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj +++ b/plugin/plugins/umeng/proj.ios/PluginUmeng.xcodeproj/project.pbxproj @@ -8,9 +8,8 @@ /* Begin PBXBuildFile section */ FA09A305168ADAEC008C1C7B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA09A304168ADAEC008C1C7B /* Foundation.framework */; }; - FA09A352168ADCA6008C1C7B /* AnalyticsUmeng.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA09A350168ADCA6008C1C7B /* AnalyticsUmeng.mm */; }; - FA42959E173A4B6500462EF7 /* UmengWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = FA42959D173A4B6500462EF7 /* UmengWrapper.m */; }; - FA866506168BE06A0073E055 /* libMobClickLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FA866505168BE06A0073E055 /* libMobClickLibrary.a */; }; + FAB6DFE91756F3B600C90D89 /* AnalyticsUmeng.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB6DFE61756F3B600C90D89 /* AnalyticsUmeng.m */; }; + FAB6DFEA1756F3B600C90D89 /* libMobClickLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FAB6DFE71756F3B600C90D89 /* libMobClickLibrary.a */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -28,12 +27,10 @@ /* Begin PBXFileReference section */ FA09A301168ADAEC008C1C7B /* libPluginUmeng.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPluginUmeng.a; sourceTree = BUILT_PRODUCTS_DIR; }; FA09A304168ADAEC008C1C7B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - FA09A34E168ADC97008C1C7B /* AnalyticsUmeng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnalyticsUmeng.h; sourceTree = ""; }; - FA09A350168ADCA6008C1C7B /* AnalyticsUmeng.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AnalyticsUmeng.mm; sourceTree = ""; }; - FA09A351168ADCA6008C1C7B /* MobClick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MobClick.h; sourceTree = ""; }; - FA42959C173A4B6500462EF7 /* UmengWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UmengWrapper.h; sourceTree = ""; }; - FA42959D173A4B6500462EF7 /* UmengWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UmengWrapper.m; sourceTree = ""; }; - FA866505168BE06A0073E055 /* libMobClickLibrary.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMobClickLibrary.a; sourceTree = ""; }; + FAB6DFE51756F3B600C90D89 /* AnalyticsUmeng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnalyticsUmeng.h; sourceTree = ""; }; + FAB6DFE61756F3B600C90D89 /* AnalyticsUmeng.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnalyticsUmeng.m; sourceTree = ""; }; + FAB6DFE71756F3B600C90D89 /* libMobClickLibrary.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMobClickLibrary.a; sourceTree = ""; }; + FAB6DFE81756F3B600C90D89 /* MobClick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MobClick.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -42,7 +39,7 @@ buildActionMask = 2147483647; files = ( FA09A305168ADAEC008C1C7B /* Foundation.framework in Frameworks */, - FA866506168BE06A0073E055 /* libMobClickLibrary.a in Frameworks */, + FAB6DFEA1756F3B600C90D89 /* libMobClickLibrary.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -52,8 +49,10 @@ FA09A2F6168ADAEC008C1C7B = { isa = PBXGroup; children = ( - FA09A34F168ADCA6008C1C7B /* ios */, - FA09A34D168ADC97008C1C7B /* include */, + FAB6DFE51756F3B600C90D89 /* AnalyticsUmeng.h */, + FAB6DFE61756F3B600C90D89 /* AnalyticsUmeng.m */, + FAB6DFE71756F3B600C90D89 /* libMobClickLibrary.a */, + FAB6DFE81756F3B600C90D89 /* MobClick.h */, FA09A303168ADAEC008C1C7B /* Frameworks */, FA09A302168ADAEC008C1C7B /* Products */, ); @@ -75,28 +74,6 @@ name = Frameworks; sourceTree = ""; }; - FA09A34D168ADC97008C1C7B /* include */ = { - isa = PBXGroup; - children = ( - FA09A34E168ADC97008C1C7B /* AnalyticsUmeng.h */, - ); - name = include; - path = ../include; - sourceTree = ""; - }; - FA09A34F168ADCA6008C1C7B /* ios */ = { - isa = PBXGroup; - children = ( - FA42959C173A4B6500462EF7 /* UmengWrapper.h */, - FA42959D173A4B6500462EF7 /* UmengWrapper.m */, - FA866505168BE06A0073E055 /* libMobClickLibrary.a */, - FA09A350168ADCA6008C1C7B /* AnalyticsUmeng.mm */, - FA09A351168ADCA6008C1C7B /* MobClick.h */, - ); - name = ios; - path = ../platform/ios; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -148,8 +125,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - FA09A352168ADCA6008C1C7B /* AnalyticsUmeng.mm in Sources */, - FA42959E173A4B6500462EF7 /* UmengWrapper.m in Sources */, + FAB6DFE91756F3B600C90D89 /* AnalyticsUmeng.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/plugin/plugins/umeng/platform/ios/libMobClickLibrary.a.REMOVED.git-id b/plugin/plugins/umeng/proj.ios/libMobClickLibrary.a.REMOVED.git-id similarity index 100% rename from plugin/plugins/umeng/platform/ios/libMobClickLibrary.a.REMOVED.git-id rename to plugin/plugins/umeng/proj.ios/libMobClickLibrary.a.REMOVED.git-id diff --git a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp index f44d597140..2f24e66294 100644 --- a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp @@ -198,7 +198,7 @@ void HelloWorld::eventMenuCallback(CCObject* pSender) g_pAnalytics->callFuncWithParam("logTimedKVEventBegin", &event2, &label2, &mapValue, NULL); PluginParam event3("music-kv"); - g_pAnalytics->callFuncWithParam("logTimedEventBegin", &event3, &mapValue, NULL); + g_pAnalytics->callFuncWithParam("logTimedEventBeginWithParams", &event3, &mapValue, NULL); } break; case TAG_LOG_EVENT_END: From cedb427a6e25a7f736dd5dd0abc9557818e1b26e Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 31 May 2013 23:13:03 +0800 Subject: [PATCH 10/18] fixed #1647: Adding WebSocket support for Cpp and JSB. Conflicts: extensions/proj.win32/libExtensions.vcxproj extensions/proj.win32/libExtensions.vcxproj.filters --- cocos2dx/platform/win32/CCStdC.cpp | 4 + cocos2dx/platform/win32/CCStdC.h | 3 + extensions/Android.mk | 3 + extensions/network/WebSocket.cpp | 658 ++++++++++++ extensions/network/WebSocket.h | 154 +++ extensions/proj.win32/libExtensions.vcxproj | 6 +- .../proj.win32/libExtensions.vcxproj.filters | 20 +- external/libwebsockets/android/Android.mk | 10 + .../android/include/libwebsockets.h | 993 ++++++++++++++++++ .../libwebsockets/ios/include/libwebsockets.h | 993 ++++++++++++++++++ .../ios/lib/libwebsockets.a.REMOVED.git-id | 1 + .../win32/include/libwebsockets.h | 993 ++++++++++++++++++ .../win32/include/win32helpers/gettimeofday.h | 28 + .../win32/include/win32helpers/websock-w32.h | 62 ++ licenses/LICENSE_libwebsockets.txt | 526 ++++++++++ samples/Cpp/TestCpp/Android.mk | 1 + .../Classes/ExtensionsTest/ExtensionsTest.cpp | 17 + .../NetworkTest/WebSocketTest.cpp | 241 +++++ .../NetworkTest/WebSocketTest.h | 50 + .../project.pbxproj.REMOVED.git-id | 2 +- .../Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 10 +- .../proj.win32/TestCpp.vcxproj.filters | 6 + .../TestJavascript/Classes/AppDelegate.cpp | 3 + .../project.pbxproj.REMOVED.git-id | 2 +- scripting/javascript/bindings/Android.mk | 3 +- .../bindings/proj.win32/libJSBinding.vcxproj | 6 +- .../proj.win32/libJSBinding.vcxproj.filters | 6 + 27 files changed, 4783 insertions(+), 18 deletions(-) create mode 100644 extensions/network/WebSocket.cpp create mode 100644 extensions/network/WebSocket.h create mode 100644 external/libwebsockets/android/Android.mk create mode 100644 external/libwebsockets/android/include/libwebsockets.h create mode 100644 external/libwebsockets/ios/include/libwebsockets.h create mode 100644 external/libwebsockets/ios/lib/libwebsockets.a.REMOVED.git-id create mode 100644 external/libwebsockets/win32/include/libwebsockets.h create mode 100644 external/libwebsockets/win32/include/win32helpers/gettimeofday.h create mode 100644 external/libwebsockets/win32/include/win32helpers/websock-w32.h create mode 100644 licenses/LICENSE_libwebsockets.txt create mode 100644 samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp create mode 100644 samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h diff --git a/cocos2dx/platform/win32/CCStdC.cpp b/cocos2dx/platform/win32/CCStdC.cpp index 426234c3ca..8368194f76 100644 --- a/cocos2dx/platform/win32/CCStdC.cpp +++ b/cocos2dx/platform/win32/CCStdC.cpp @@ -26,6 +26,8 @@ THE SOFTWARE. #ifndef __MINGW32__ +NS_CC_BEGIN + int gettimeofday(struct timeval * val, struct timezone *) { if (val) @@ -39,4 +41,6 @@ int gettimeofday(struct timeval * val, struct timezone *) return 0; } +NS_CC_END + #endif // __MINGW32__ diff --git a/cocos2dx/platform/win32/CCStdC.h b/cocos2dx/platform/win32/CCStdC.h index 5b90c0824b..28e574a98e 100644 --- a/cocos2dx/platform/win32/CCStdC.h +++ b/cocos2dx/platform/win32/CCStdC.h @@ -87,6 +87,7 @@ THE SOFTWARE. #include +NS_CC_BEGIN struct timezone { @@ -96,6 +97,8 @@ struct timezone int CC_DLL gettimeofday(struct timeval *, struct timezone *); +NS_CC_END + #else #include diff --git a/extensions/Android.mk b/extensions/Android.mk index 7053bc5866..c0536fffa4 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -49,6 +49,7 @@ GUI/CCScrollView/CCSorting.cpp \ GUI/CCEditBox/CCEditBox.cpp \ GUI/CCEditBox/CCEditBoxImplAndroid.cpp \ network/HttpClient.cpp \ +network/WebSocket.cpp \ physics_nodes/CCPhysicsDebugNode.cpp \ physics_nodes/CCPhysicsSprite.cpp \ LocalStorage/LocalStorageAndroid.cpp \ @@ -77,6 +78,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_curl_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static +LOCAL_WHOLE_STATIC_LIBRARIES += libwebsockets_static LOCAL_CFLAGS += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 LOCAL_EXPORT_CFLAGS += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 @@ -95,3 +97,4 @@ $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) $(call import-module,external/Box2D) $(call import-module,external/chipmunk) +$(call import-module,external/libwebsockets/android) diff --git a/extensions/network/WebSocket.cpp b/extensions/network/WebSocket.cpp new file mode 100644 index 0000000000..844fd9ed99 --- /dev/null +++ b/extensions/network/WebSocket.cpp @@ -0,0 +1,658 @@ +/**************************************************************************** + Copyright (c) 2010-2013 cocos2d-x.org + Copyright (c) 2013 James Chen + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "WebSocket.h" +#include +#include +#include + +NS_CC_EXT_BEGIN + +class WsMessage +{ +public: + WsMessage() : what(0), obj(NULL){} + unsigned int what; // message type + void* obj; +}; + +/** + * @brief Websocket thread helper, it's used for sending message between UI thread and websocket thread. + */ +class WsThreadHelper : public cocos2d::CCObject +{ +public: + WsThreadHelper(); + ~WsThreadHelper(); + + // Creates a new thread + bool createThread(const WebSocket& ws); + // Quits sub-thread (websocket thread). + void quitSubThread(); + + // Schedule callback function + virtual void update(float dt); + + // Sends message to UI thread. It's needed to be invoked in sub-thread. + void sendMessageToUIThread(WsMessage *msg); + + // Sends message to sub-thread(websocket thread). It's needs to be invoked in UI thread. + void sendMessageToSubThread(WsMessage *msg); + + // Waits the sub-thread (websocket thread) to exit, + void joinSubThread(); + + +protected: + friend class WsThreadEntry; + void* wsThreadEntryFunc(void* arg); + +private: + std::list* _UIWsMessageQueue; + std::list* _subThreadWsMessageQueue; + pthread_mutex_t _UIWsMessageQueueMutex; + pthread_mutex_t _subThreadWsMessageQueueMutex; + pthread_t _subThreadInstance; + WebSocket* _ws; + bool _needQuit; + friend class WebSocket; +}; + +// Wrapper for converting websocket callback from static function to member function of WebSocket class. +class WebSocketCallbackWrapper { +public: + + static int onSocketCallback(struct libwebsocket_context *ctx, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len) + { + // Gets the user data from context. We know that it's a 'WebSocket' instance. + WebSocket* wsInstance = (WebSocket*)libwebsocket_context_user(ctx); + if (wsInstance) + { + return wsInstance->onSocketCallback(ctx, wsi, reason, user, in, len); + } + return 0; + } +}; + +// Implementation of WsThreadHelper +WsThreadHelper::WsThreadHelper() +: _ws(NULL) +, _needQuit(false) +{ + _UIWsMessageQueue = new std::list(); + pthread_mutex_init(&_UIWsMessageQueueMutex, NULL); + _subThreadWsMessageQueue = new std::list(); + pthread_mutex_init(&_subThreadWsMessageQueueMutex, NULL); + + CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(this, 0, false); +} + +WsThreadHelper::~WsThreadHelper() +{ + CCDirector::sharedDirector()->getScheduler()->unscheduleAllForTarget(this); + pthread_mutex_destroy(&_UIWsMessageQueueMutex); + pthread_mutex_destroy(&_subThreadWsMessageQueueMutex); + delete _UIWsMessageQueue; + delete _subThreadWsMessageQueue; +} + +// For converting static function to member function +class WsThreadEntry +{ +public: + static void* entry(void* arg) + { + WsThreadHelper* self = static_cast(arg); + return self->wsThreadEntryFunc(arg); + } +}; + +bool WsThreadHelper::createThread(const WebSocket& ws) +{ + _ws = const_cast(&ws); + pthread_attr_t attr; + pthread_attr_init (&attr); +// pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + + // Creates websocket thread + if (0 == pthread_create(&_subThreadInstance, &attr, WsThreadEntry::entry, this)) + { + return true; + } + return false; +} + +void WsThreadHelper::quitSubThread() +{ + _needQuit = true; +} + +void* WsThreadHelper::wsThreadEntryFunc(void* arg) +{ + _ws->onSubThreadStarted(); + + while (!_needQuit) + { + if (_ws->onSubThreadLoop()) + { + break; + } + } + + _ws->onSubThreadEnded(); + + return (void*)0; +} + +void WsThreadHelper::sendMessageToUIThread(WsMessage *msg) +{ + pthread_mutex_lock(&_UIWsMessageQueueMutex); + _UIWsMessageQueue->push_back(msg); + pthread_mutex_unlock(&_UIWsMessageQueueMutex); +} + +void WsThreadHelper::sendMessageToSubThread(WsMessage *msg) +{ + pthread_mutex_lock(&_subThreadWsMessageQueueMutex); + _subThreadWsMessageQueue->push_back(msg); + pthread_mutex_unlock(&_subThreadWsMessageQueueMutex); +} + +void WsThreadHelper::joinSubThread() +{ + void* ret = NULL; + pthread_join(_subThreadInstance, &ret); +} + +void WsThreadHelper::update(float dt) +{ + WsMessage *msg = NULL; + + // Returns quickly if no message + pthread_mutex_lock(&_UIWsMessageQueueMutex); + if (0 == _UIWsMessageQueue->size()) + { + pthread_mutex_unlock(&_UIWsMessageQueueMutex); + return; + } + + // Gets message + msg = *(_UIWsMessageQueue->begin()); + _UIWsMessageQueue->pop_front(); + pthread_mutex_unlock(&_UIWsMessageQueueMutex); + + if (_ws) + { + _ws->onUIThreadReceiveMessage(msg); + } + + CC_SAFE_DELETE(msg); +} + +enum WS_MSG { + WS_MSG_TO_SUBTRHEAD_SENDING_STRING = 0, + WS_MSG_TO_SUBTRHEAD_SENDING_BINARY, + WS_MSG_TO_SUBTRHEAD_CLOSING, + WS_MSG_TO_UITHREAD_OPEN, + WS_MSG_TO_UITHREAD_MESSAGE, + WS_MSG_TO_UITHREAD_ERROR, + WS_MSG_TO_UITHREAD_CLOSE +}; + +WebSocket::WebSocket() +: _readyState(WS_STATE_CONNECTING) +, _port(80) +, _wsHelper(NULL) +, _wsInstance(NULL) +, _wsContext(NULL) +, _delegate(NULL) +, _SSLConnection(0) +, _wsProtocols(NULL) +{ +} + +WebSocket::~WebSocket() +{ + close(); + CC_SAFE_RELEASE_NULL(_wsHelper); + + for (int i = 0; _wsProtocols[i].callback != NULL; ++i) { + CC_SAFE_DELETE_ARRAY(_wsProtocols[i].name); + } + CC_SAFE_DELETE_ARRAY(_wsProtocols); +} + +bool WebSocket::init(const Delegate& delegate, + const std::string& url, + const std::vector* protocols/* = NULL*/) +{ + bool ret = false; + bool useSSL = false; + std::string host = url; + int pos = 0; + int port = 80; + + _delegate = const_cast(&delegate); + + //ws:// + pos = host.find("ws://"); + if (pos == 0){ + host.erase(0,5); + } + + pos = host.find("wss://"); + if (pos == 0) + { + host.erase(0,6); + useSSL = true; + } + + pos = host.find(":"); + if(pos >= 0){ + port = atoi(host.substr(pos+1, host.size()).c_str()); + } + + pos = host.find("/", pos); + std::string path = "/"; + if(pos >= 0){ + path += host.substr(pos + 1, host.size()); + } + + pos = host.find(":"); + if(pos >= 0){ + host.erase(pos, host.size()); + } + + + _host = host; + _port = port; + _path = path; + _SSLConnection = useSSL ? 1 : 0; + + int protocolCount = 0; + if (protocols && protocols->size() > 0) + { + protocolCount = protocols->size(); + } + else + { + protocolCount = 1; + } + + _wsProtocols = new libwebsocket_protocols[protocolCount+1]; + memset(_wsProtocols, 0, sizeof(libwebsocket_protocols)*(protocolCount+1)); + + if (protocols) + { + int i = 0; + for (std::vector::const_iterator iter = protocols->begin(); iter != protocols->end(); ++iter, ++i) { + char* name = new char[(*iter).length()+1]; + strcpy(name, (*iter).c_str()); + _wsProtocols[i].name = name; + _wsProtocols[i].callback = WebSocketCallbackWrapper::onSocketCallback; + } + } + else + { + char* name = new char[20]; + strcpy(name, "default-protocol"); + _wsProtocols[0].name = name; + _wsProtocols[0].callback = WebSocketCallbackWrapper::onSocketCallback; + } + + + // WebSocket thread needs to be invoked at the end of this method. + _wsHelper = new WsThreadHelper(); + ret = _wsHelper->createThread(*this); + + return ret; +} + +void WebSocket::send(const std::string& message) +{ + if (_readyState == WS_STATE_OPEN) + { + // In main thread + WsMessage* msg = new WsMessage(); + msg->what = WS_MSG_TO_SUBTRHEAD_SENDING_STRING; + Data* data = new Data(); + data->bytes = new char[message.length()+1]; + strcpy(data->bytes, message.c_str()); + data->len = message.length(); + msg->obj = data; + _wsHelper->sendMessageToSubThread(msg); + } +} + +void WebSocket::send(const unsigned char* binaryMsg, unsigned int len) +{ + CCAssert(binaryMsg != NULL && len > 0, "parameter invalid."); + + if (_readyState == WS_STATE_OPEN) + { + // In main thread + WsMessage* msg = new WsMessage(); + msg->what = WS_MSG_TO_SUBTRHEAD_SENDING_BINARY; + Data* data = new Data(); + data->bytes = new char[len]; + memcpy((void*)data->bytes, (void*)binaryMsg, len); + data->len = len; + msg->obj = data; + _wsHelper->sendMessageToSubThread(msg); + } +} + +void WebSocket::close() +{ + CCDirector::sharedDirector()->getScheduler()->unscheduleAllForTarget(_wsHelper); + + if (_readyState == WS_STATE_CLOSING || _readyState == WS_STATE_CLOSED) + return; + + CCLOG("websocket (%p) connection closed by client", this); + _readyState = WS_STATE_CLOSED; + + WsMessage* msg = new WsMessage(); + msg->what = WS_MSG_TO_SUBTRHEAD_CLOSING; + + _wsHelper->sendMessageToSubThread(msg); + _wsHelper->joinSubThread(); + + // onClose callback needs to be invoked at the end of this method + // since websocket instance may be deleted in 'onClose'. + _delegate->onClose(this); +} + +WebSocket::WS_STATE WebSocket::getReadyState() +{ + return _readyState; +} + +int WebSocket::onSubThreadLoop() +{ + if (_readyState == WS_STATE_CLOSED || _readyState == WS_STATE_CLOSING) + { + libwebsocket_context_destroy(_wsContext); + // return 1 to exit the loop. + return 1; + } + + if (_wsContext && _readyState != WS_STATE_CLOSED && _readyState != WS_STATE_CLOSING) + { + libwebsocket_service(_wsContext, 0); + } + + // Sleep 50 ms +#ifdef WIN32 + Sleep(50); +#else + usleep(50000); +#endif + // return 0 to continue the loop. + return 0; +} + +void WebSocket::onSubThreadStarted() +{ + struct lws_context_creation_info info; + memset(&info, 0, sizeof info); + + /* + * create the websocket context. This tracks open connections and + * knows how to route any traffic and which protocol version to use, + * and if each connection is client or server side. + * + * For this client-only demo, we tell it to not listen on any port. + */ + + info.port = CONTEXT_PORT_NO_LISTEN; + info.protocols = _wsProtocols; +#ifndef LWS_NO_EXTENSIONS + info.extensions = libwebsocket_get_internal_extensions(); +#endif + info.gid = -1; + info.uid = -1; + info.user = (void*)this; + + _wsContext = libwebsocket_create_context(&info); + + if(NULL != _wsContext){ + _readyState = WS_STATE_CONNECTING; + std::string name; + for (int i = 0; _wsProtocols[i].callback != NULL; ++i) { + name += (_wsProtocols[i].name); + if (_wsProtocols[i+1].callback != NULL) + { + name += ", "; + } + } + _wsInstance = libwebsocket_client_connect(_wsContext, _host.c_str(), _port, _SSLConnection, + _path.c_str(), _host.c_str(), _host.c_str(), + name.c_str(), -1); + } +} + +void WebSocket::onSubThreadEnded() +{ + +} + + +int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len) +{ + //CCLOG("socket callback for %d reason", reason); + CCAssert(_wsContext == NULL || ctx == _wsContext, "Invalid context."); + CCAssert(_wsInstance == NULL || wsi == NULL || wsi == _wsInstance, "Invaild websocket instance."); + + switch (reason) + { + case LWS_CALLBACK_DEL_POLL_FD: + case LWS_CALLBACK_PROTOCOL_DESTROY: + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + { + WsMessage* msg = new WsMessage(); + if (reason == LWS_CALLBACK_CLIENT_CONNECTION_ERROR + || (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == WS_STATE_CONNECTING) + || (reason == LWS_CALLBACK_DEL_POLL_FD && _readyState == WS_STATE_CONNECTING) + ) + { + msg->what = WS_MSG_TO_UITHREAD_ERROR; + _readyState = WS_STATE_CLOSING; + } + else if (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == WS_STATE_CLOSING) + { + msg->what = WS_MSG_TO_UITHREAD_CLOSE; + } + _wsHelper->sendMessageToUIThread(msg); + } + break; + case LWS_CALLBACK_CLIENT_ESTABLISHED: + { + WsMessage* msg = new WsMessage(); + msg->what = WS_MSG_TO_UITHREAD_OPEN; + _readyState = WS_STATE_OPEN; + /* + * start the ball rolling, + * LWS_CALLBACK_CLIENT_WRITEABLE will come next service + */ + libwebsocket_callback_on_writable(ctx, wsi); + _wsHelper->sendMessageToUIThread(msg); + } + break; + + case LWS_CALLBACK_CLIENT_WRITEABLE: + { + pthread_mutex_lock(&_wsHelper->_subThreadWsMessageQueueMutex); + std::list::iterator iter = _wsHelper->_subThreadWsMessageQueue->begin(); + + int bytesWrite = 0; + for (; iter != _wsHelper->_subThreadWsMessageQueue->end(); ++iter) { + + WsMessage* subThreadMsg = *iter; + + if ( WS_MSG_TO_SUBTRHEAD_SENDING_STRING == subThreadMsg->what + || WS_MSG_TO_SUBTRHEAD_SENDING_BINARY == subThreadMsg->what) + { + Data* data = (Data*)subThreadMsg->obj; + + unsigned char* buf = new unsigned char[LWS_SEND_BUFFER_PRE_PADDING + + data->len + LWS_SEND_BUFFER_POST_PADDING]; + + memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, data->len); + memcpy((char*)&buf[LWS_SEND_BUFFER_PRE_PADDING], data->bytes, data->len); + + enum libwebsocket_write_protocol writeProtocol; + + if (WS_MSG_TO_SUBTRHEAD_SENDING_STRING == subThreadMsg->what) + { + writeProtocol = LWS_WRITE_TEXT; + } + else + { + writeProtocol = LWS_WRITE_BINARY; + } + + bytesWrite = libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], data->len, writeProtocol); + + if (bytesWrite < 0) { + CCLOGERROR("%s", "libwebsocket_write error..."); + } + if (bytesWrite < data->len) { + CCLOGERROR("Partial write LWS_CALLBACK_CLIENT_WRITEABLE\n"); + } + + CC_SAFE_DELETE_ARRAY(data->bytes); + CC_SAFE_DELETE(data); + CC_SAFE_DELETE_ARRAY(buf); + } + } + + _wsHelper->_subThreadWsMessageQueue->clear(); + + pthread_mutex_unlock(&_wsHelper->_subThreadWsMessageQueueMutex); + + /* get notified as soon as we can write again */ + + libwebsocket_callback_on_writable(ctx, wsi); + } + break; + + case LWS_CALLBACK_CLOSED: + { + + CCLOG("%s", "connection closing.."); + + _wsHelper->quitSubThread(); + + if (_readyState != WS_STATE_CLOSED) + { + WsMessage* msg = new WsMessage(); + _readyState = WS_STATE_CLOSED; + msg->what = WS_MSG_TO_UITHREAD_CLOSE; + _wsHelper->sendMessageToUIThread(msg); + } + } + break; + + case LWS_CALLBACK_CLIENT_RECEIVE: + { + if (in && len > 0) + { + WsMessage* msg = new WsMessage(); + msg->what = WS_MSG_TO_UITHREAD_MESSAGE; + + char* bytes = NULL; + Data* data = new Data(); + + if (lws_frame_is_binary(wsi)) + { + + bytes = new char[len]; + data->isBinary = true; + } + else + { + bytes = new char[len+1]; + bytes[len] = '\0'; + data->isBinary = false; + } + + memcpy(bytes, in, len); + + data->bytes = bytes; + data->len = len; + msg->obj = (void*)data; + + _wsHelper->sendMessageToUIThread(msg); + } + } + break; + default: + break; + + } + + return 0; +} + +void WebSocket::onUIThreadReceiveMessage(WsMessage* msg) +{ + switch (msg->what) { + case WS_MSG_TO_UITHREAD_OPEN: + { + _delegate->onOpen(this); + } + break; + case WS_MSG_TO_UITHREAD_MESSAGE: + { + Data* data = (Data*)msg->obj; + _delegate->onMessage(this, *data); + CC_SAFE_DELETE_ARRAY(data->bytes); + CC_SAFE_DELETE(data); + } + break; + case WS_MSG_TO_UITHREAD_CLOSE: + { + _delegate->onClose(this); + } + break; + case WS_MSG_TO_UITHREAD_ERROR: + { + WebSocket::WS_ERROR err = WS_ERROR_CONNECTION_FAILS; + _delegate->onError(this, err); + } + break; + default: + break; + } +} + +NS_CC_EXT_END diff --git a/extensions/network/WebSocket.h b/extensions/network/WebSocket.h new file mode 100644 index 0000000000..021e4e4395 --- /dev/null +++ b/extensions/network/WebSocket.h @@ -0,0 +1,154 @@ +/**************************************************************************** + Copyright (c) 2010-2013 cocos2d-x.org + Copyright (c) 2013 James Chen + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __CC_WEBSOCKET_H__ +#define __CC_WEBSOCKET_H__ + +#include "ExtensionMacros.h" +#include +#include "cocos2d.h" +#include "libwebsockets.h" +#include + +NS_CC_EXT_BEGIN + +class WsThreadHelper; +class WsMessage; + +class WebSocket +{ +public: + WebSocket(); + virtual ~WebSocket(); + + /** + * @brief Data structure for message + */ + struct Data + { + Data():bytes(NULL), len(0), isBinary(false){} + char* bytes; + int len; + bool isBinary; + }; + + /** + * @brief Errors in websocket + */ + enum WS_ERROR + { + WS_ERROR_TIMEOUT=0, + WS_ERROR_CONNECTION_FAILS, + WS_ERROR_UNKNOWN + }; + + /** + * @brief The delegate class to process websocket events. + */ + class Delegate + { + public: + virtual ~Delegate() {} + virtual void onOpen(WebSocket* ws) = 0; + virtual void onMessage(WebSocket* ws, const Data& data) = 0; + virtual void onClose(WebSocket* ws) = 0; + virtual void onError(WebSocket* ws, const WS_ERROR& error) = 0; + }; + + + /** + * @brief The initialized method for websocket. + * It needs to be invoked right after websocket instance is allocated. + * @param delegate The delegate which want to receive event from websocket. + * @param url The URL of websocket server. + * @return true: Success, false: Failure + */ + bool init(const Delegate& delegate, + const std::string& url, + const std::vector* protocols = NULL); + + /** + * @brief Sends string data to websocket server. + */ + void send(const std::string& message); + + /** + * @brief Sends binary data to websocket server. + */ + void send(const unsigned char* binaryMsg, unsigned int len); + + /** + * @brief Closes the connection to server. + */ + void close(); + + /** + * Websocket state + */ + enum WS_STATE + { + WS_STATE_CONNECTING = 0, + WS_STATE_OPEN, + WS_STATE_CLOSING, + WS_STATE_CLOSED + }; + + /** + * @brief Gets current state of connection. + */ + WS_STATE getReadyState(); + +private: + virtual void onSubThreadStarted(); + virtual int onSubThreadLoop(); + virtual void onSubThreadEnded(); + virtual void onUIThreadReceiveMessage(WsMessage* msg); + + + friend class WebSocketCallbackWrapper; + int onSocketCallback(struct libwebsocket_context *ctx, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len); + +private: + WS_STATE _readyState; + std::string _host; + unsigned int _port; + std::string _path; + + friend class WsThreadHelper; + WsThreadHelper* _wsHelper; + + struct libwebsocket* _wsInstance; + struct libwebsocket_context* _wsContext; + Delegate* _delegate; + int _SSLConnection; + libwebsocket_protocols* _wsProtocols; +}; + +NS_CC_EXT_END + +#endif /* defined(__CC_JSB_WEBSOCKET_H__) */ diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index ce8d93a383..d09282a53e 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -63,7 +63,7 @@ Disabled - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\external\sqlite3\include;$(ProjectDir)..\..\external;$(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\zlib;$(ProjectDir)..\..\CocosDenshion\include;..\;%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\external\sqlite3\include;$(ProjectDir)..\..\external;$(ProjectDir)..\..\external\libwebsockets\win32\include;$(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\zlib;$(ProjectDir)..\..\CocosDenshion\include;..\;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_DEBUG;_LIB;COCOS2D_DEBUG=1;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -79,7 +79,7 @@ MaxSpeed true - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\external\sqlite3\include;$(ProjectDir)..\..\external;$(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\zlib;$(ProjectDir)..\..\CocosDenshion\include;..\;%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\external\sqlite3\include;$(ProjectDir)..\..\external;$(ProjectDir)..\..\external\libwebsockets\win32\include;$(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\zlib;$(ProjectDir)..\..\CocosDenshion\include;..\;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;NDEBUG;_LIB;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -136,6 +136,7 @@ + @@ -215,6 +216,7 @@ + diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 58e8f949d7..99c9b8c8a2 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -13,9 +13,6 @@ {46797895-f71d-4ddb-b381-d0884e678d39} - - {2a7741ff-87a5-41c8-8e51-d7a1cf0c8e4d} - {d5806151-7ae1-4fef-af5a-2fa1d1c7377b} @@ -31,13 +28,16 @@ {ff4b5934-99d4-4ea7-9f50-a774192d9ca9} + + {2a7741ff-87a5-41c8-8e51-d7a1cf0c8e4d} + GUI\CCScrollView - GUI\network + network GUI\CCScrollView @@ -234,6 +234,9 @@ spine + + network + @@ -242,13 +245,13 @@ - GUI\network + network - GUI\network + network - GUI\network + network GUI\CCScrollView @@ -466,5 +469,8 @@ spine + + network + \ No newline at end of file diff --git a/external/libwebsockets/android/Android.mk b/external/libwebsockets/android/Android.mk new file mode 100644 index 0000000000..158211b64c --- /dev/null +++ b/external/libwebsockets/android/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := libwebsockets_static +LOCAL_MODULE_FILENAME := libwebsockets_static +LOCAL_SRC_FILES := ./lib/$(TARGET_ARCH_ABI)/libwebsockets.a +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include +LOCAL_CPPFLAGS := -D__STDC_LIMIT_MACROS=1 +LOCAL_EXPORT_CPPFLAGS := -D__STDC_LIMIT_MACROS=1 +include $(PREBUILT_STATIC_LIBRARY) diff --git a/external/libwebsockets/android/include/libwebsockets.h b/external/libwebsockets/android/include/libwebsockets.h new file mode 100644 index 0000000000..65bae14534 --- /dev/null +++ b/external/libwebsockets/android/include/libwebsockets.h @@ -0,0 +1,993 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010-2013 Andy Green + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation: + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef __LIBWEBSOCKET_H__ +#define __LIBWEBSOCKET_H__ + +#ifdef __cplusplus +extern "C" { +#include +#endif + +#ifdef WIN32 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include +#include +#include "../win32port/win32helpers/websock-w32.h" + +#include "../win32port/win32helpers/gettimeofday.h" + +#define strcasecmp stricmp +#define getdtablesize() 30000 + +typedef int ssize_t; + +#define LWS_VISIBLE + +#ifdef LWS_DLL +#ifdef LWS_INTERNAL +#define LWS_EXTERN extern __declspec(dllexport) +#else +#define LWS_EXTERN extern __declspec(dllimport) +#endif +#else +#define LWS_EXTERN +#endif + +#else // NOT WIN32 +#include +#include + +#if defined(__GNUC__) +#define LWS_VISIBLE __attribute__((visibility("default"))) +#else +#define LWS_VISIBLE +#endif + +#endif + +#include + +#ifndef LWS_EXTERN +#define LWS_EXTERN extern +#endif + +#define CONTEXT_PORT_NO_LISTEN 0 +#define MAX_MUX_RECURSION 2 + +enum lws_log_levels { + LLL_ERR = 1 << 0, + LLL_WARN = 1 << 1, + LLL_NOTICE = 1 << 2, + LLL_INFO = 1 << 3, + LLL_DEBUG = 1 << 4, + LLL_PARSER = 1 << 5, + LLL_HEADER = 1 << 6, + LLL_EXT = 1 << 7, + LLL_CLIENT = 1 << 8, + LLL_LATENCY = 1 << 9, + + LLL_COUNT = 10 /* set to count of valid flags */ +}; + +LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...); + +/* notice, warn and log are always compiled in */ +#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) +#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) +/* + * weaker logging can be deselected at configure time using --disable-debug + * that gets rid of the overhead of checking while keeping _warn and _err + * active + */ +#ifdef _DEBUG + +#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) +#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) +#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) +#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) +#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) +#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) +#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) +LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); + +#else /* no debug */ + +#define lwsl_info(...) +#define lwsl_debug(...) +#define lwsl_parser(...) +#define lwsl_header(...) +#define lwsl_ext(...) +#define lwsl_client(...) +#define lwsl_latency(...) +#define lwsl_hexdump(a, b) + +#endif + +enum libwebsocket_context_options { + LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2, + LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4, +}; + +enum libwebsocket_callback_reasons { + LWS_CALLBACK_ESTABLISHED, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, + LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, + LWS_CALLBACK_CLIENT_ESTABLISHED, + LWS_CALLBACK_CLOSED, + LWS_CALLBACK_RECEIVE, + LWS_CALLBACK_CLIENT_RECEIVE, + LWS_CALLBACK_CLIENT_RECEIVE_PONG, + LWS_CALLBACK_CLIENT_WRITEABLE, + LWS_CALLBACK_SERVER_WRITEABLE, + LWS_CALLBACK_HTTP, + LWS_CALLBACK_HTTP_FILE_COMPLETION, + LWS_CALLBACK_HTTP_WRITEABLE, + LWS_CALLBACK_FILTER_NETWORK_CONNECTION, + LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, + LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, + LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, + LWS_CALLBACK_CONFIRM_EXTENSION_OKAY, + LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, + LWS_CALLBACK_PROTOCOL_INIT, + LWS_CALLBACK_PROTOCOL_DESTROY, + /* external poll() management support */ + LWS_CALLBACK_ADD_POLL_FD, + LWS_CALLBACK_DEL_POLL_FD, + LWS_CALLBACK_SET_MODE_POLL_FD, + LWS_CALLBACK_CLEAR_MODE_POLL_FD, +}; + +#ifndef LWS_NO_EXTENSIONS +enum libwebsocket_extension_callback_reasons { + LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, + LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, + LWS_EXT_CALLBACK_CONSTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONSTRUCT, + LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, + LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION, + LWS_EXT_CALLBACK_DESTROY, + LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, + LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED, + LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, + LWS_EXT_CALLBACK_PACKET_TX_PRESEND, + LWS_EXT_CALLBACK_PACKET_TX_DO_SEND, + LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX, + LWS_EXT_CALLBACK_FLUSH_PENDING_TX, + LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX, + LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION, + LWS_EXT_CALLBACK_1HZ, + LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, + LWS_EXT_CALLBACK_IS_WRITEABLE, + LWS_EXT_CALLBACK_PAYLOAD_TX, + LWS_EXT_CALLBACK_PAYLOAD_RX, +}; +#endif + +enum libwebsocket_write_protocol { + LWS_WRITE_TEXT, + LWS_WRITE_BINARY, + LWS_WRITE_CONTINUATION, + LWS_WRITE_HTTP, + + /* special 04+ opcodes */ + + LWS_WRITE_CLOSE, + LWS_WRITE_PING, + LWS_WRITE_PONG, + + /* flags */ + + LWS_WRITE_NO_FIN = 0x40, + /* + * client packet payload goes out on wire unmunged + * only useful for security tests since normal servers cannot + * decode the content if used + */ + LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80 +}; + +/* + * you need these to look at headers that have been parsed if using the + * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum + * list below is absent, .token = NULL and token_len = 0. Otherwise .token + * points to .token_len chars containing that header content. + */ + +struct lws_tokens { + char *token; + int token_len; +}; + +enum lws_token_indexes { + WSI_TOKEN_GET_URI, + WSI_TOKEN_HOST, + WSI_TOKEN_CONNECTION, + WSI_TOKEN_KEY1, + WSI_TOKEN_KEY2, + WSI_TOKEN_PROTOCOL, + WSI_TOKEN_UPGRADE, + WSI_TOKEN_ORIGIN, + WSI_TOKEN_DRAFT, + WSI_TOKEN_CHALLENGE, + + /* new for 04 */ + WSI_TOKEN_KEY, + WSI_TOKEN_VERSION, + WSI_TOKEN_SWORIGIN, + + /* new for 05 */ + WSI_TOKEN_EXTENSIONS, + + /* client receives these */ + WSI_TOKEN_ACCEPT, + WSI_TOKEN_NONCE, + WSI_TOKEN_HTTP, + WSI_TOKEN_MUXURL, + + /* use token storage to stash these */ + + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + _WSI_TOKEN_CLIENT_PEER_ADDRESS, + _WSI_TOKEN_CLIENT_URI, + _WSI_TOKEN_CLIENT_HOST, + _WSI_TOKEN_CLIENT_ORIGIN, + + /* always last real token index*/ + WSI_TOKEN_COUNT, + /* parser state additions */ + WSI_TOKEN_NAME_PART, + WSI_TOKEN_SKIPPING, + WSI_TOKEN_SKIPPING_SAW_CR, + WSI_PARSING_COMPLETE, + WSI_INIT_TOKEN_MUXURL, +}; + +/* + * From RFC 6455 + 1000 + + 1000 indicates a normal closure, meaning that the purpose for + which the connection was established has been fulfilled. + + 1001 + + 1001 indicates that an endpoint is "going away", such as a server + going down or a browser having navigated away from a page. + + 1002 + + 1002 indicates that an endpoint is terminating the connection due + to a protocol error. + + 1003 + + 1003 indicates that an endpoint is terminating the connection + because it has received a type of data it cannot accept (e.g., an + endpoint that understands only text data MAY send this if it + receives a binary message). + + 1004 + + Reserved. The specific meaning might be defined in the future. + + 1005 + + 1005 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that no status + code was actually present. + + 1006 + + 1006 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed abnormally, e.g., without sending or + receiving a Close control frame. + + 1007 + + 1007 indicates that an endpoint is terminating the connection + because it has received data within a message that was not + consistent with the type of the message (e.g., non-UTF-8 [RFC3629] + data within a text message). + + 1008 + + 1008 indicates that an endpoint is terminating the connection + because it has received a message that violates its policy. This + is a generic status code that can be returned when there is no + other more suitable status code (e.g., 1003 or 1009) or if there + is a need to hide specific details about the policy. + + 1009 + + 1009 indicates that an endpoint is terminating the connection + because it has received a message that is too big for it to + process. + + 1010 + + 1010 indicates that an endpoint (client) is terminating the + connection because it has expected the server to negotiate one or + more extension, but the server didn't return them in the response + message of the WebSocket handshake. The list of extensions that + are needed SHOULD appear in the /reason/ part of the Close frame. + Note that this status code is not used by the server, because it + can fail the WebSocket handshake instead. + + 1011 + + 1011 indicates that a server is terminating the connection because + it encountered an unexpected condition that prevented it from + fulfilling the request. + + 1015 + + 1015 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed due to a failure to perform a TLS handshake + (e.g., the server certificate can't be verified). +*/ + +enum lws_close_status { + LWS_CLOSE_STATUS_NOSTATUS = 0, + LWS_CLOSE_STATUS_NORMAL = 1000, + LWS_CLOSE_STATUS_GOINGAWAY = 1001, + LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002, + LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003, + LWS_CLOSE_STATUS_RESERVED = 1004, + LWS_CLOSE_STATUS_NO_STATUS = 1005, + LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006, + LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007, + LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008, + LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009, + LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010, + LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011, + LWS_CLOSE_STATUS_TLS_FAILURE = 1015, +}; + +struct libwebsocket; +struct libwebsocket_context; +/* needed even with extensions disabled for create context */ +struct libwebsocket_extension; + +/** + * callback_function() - User server actions + * @context: Websockets context + * @wsi: Opaque websocket instance pointer + * @reason: The reason for the call + * @user: Pointer to per-session user data allocated by library + * @in: Pointer used for some callback reasons + * @len: Length set for some callback reasons + * + * This callback is the way the user controls what is served. All the + * protocol detail is hidden and handled by the library. + * + * For each connection / session there is user data allocated that is + * pointed to by "user". You set the size of this user data area when + * the library is initialized with libwebsocket_create_server. + * + * You get an opportunity to initialize user data when called back with + * LWS_CALLBACK_ESTABLISHED reason. + * + * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with + * an incoming client + * + * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has + * been unable to complete a handshake with the remote server + * + * LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for the + * client user code to examine the http headers + * and decide to reject the connection. If the + * content in the headers is interesting to the + * client (url, etc) it needs to copy it out at + * this point since it will be destroyed before + * the CLIENT_ESTABLISHED call + * + * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed + * a handshake with the remote server + * + * LWS_CALLBACK_CLOSED: when the websocket session ends + * + * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a + * remote client, it can be found at *in and is + * len bytes long + * + * LWS_CALLBACK_CLIENT_RECEIVE_PONG: if you elected to see PONG packets, + * they appear with this callback reason. PONG + * packets only exist in 04+ protocol + * + * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for the + * client connection, it can be found at *in and + * is len bytes long + * + * LWS_CALLBACK_HTTP: an http request has come from a client that is not + * asking to upgrade the connection to a websocket + * one. This is a chance to serve http content, + * for example, to send a script to the client + * which will then open the websockets connection. + * @in points to the URI path requested and + * libwebsockets_serve_http_file() makes it very + * simple to send back a file to the client. + * Normally after sending the file you are done + * with the http connection, since the rest of the + * activity will come by websockets from the script + * that was delivered by http, so you will want to + * return 1; to close and free up the connection. + * That's important because it uses a slot in the + * total number of client connections allowed set + * by MAX_CLIENTS. + * + * LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protocol + * link now. + * + * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down + * http link has completed. + * + * LWS_CALLBACK_CLIENT_WRITEABLE: + * LWS_CALLBACK_SERVER_WRITEABLE: If you call + * libwebsocket_callback_on_writable() on a connection, you will + * get one of these callbacks coming when the connection socket + * is able to accept another write packet without blocking. + * If it already was able to take another packet without blocking, + * you'll get this callback at the next call to the service loop + * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE + * and servers get LWS_CALLBACK_SERVER_WRITEABLE. + * + * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connects to + * the server at network level; the connection is accepted but then + * passed to this callback to decide whether to hang up immediately + * or not, based on the client IP. @in contains the connection + * socket's descriptor. Return non-zero to terminate + * the connection before sending or receiving anything. + * Because this happens immediately after the network connection + * from the client, there's no websocket protocol selected yet so + * this callback is issued only to protocol 0. + * + * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has + * been received and parsed from the client, but the response is + * not sent yet. Return non-zero to disallow the connection. + * @user is a pointer to an array of struct lws_tokens, you can + * use the header enums lws_token_indexes from libwebsockets.h + * to check for and read the supported header presence and + * content before deciding to allow the handshake to proceed or + * to kill the connection. + * + * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: if configured for + * including OpenSSL support, this callback allows your user code + * to perform extra SSL_CTX_load_verify_locations() or similar + * calls to direct OpenSSL where to find certificates the client + * can use to confirm the remote server identity. @user is the + * OpenSSL SSL_CTX* + * + * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: if configured for + * including OpenSSL support, this callback allows your user code + * to load extra certifcates into the server which allow it to + * verify the validity of certificates returned by clients. @user + * is the server's OpenSSL SSL_CTX* + * + * LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: if the + * libwebsockets context was created with the option + * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this + * callback is generated during OpenSSL verification of the cert + * sent from the client. It is sent to protocol[0] callback as + * no protocol has been negotiated on the connection yet. + * Notice that the libwebsockets context and wsi are both NULL + * during this callback. See + * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html + * to understand more detail about the OpenSSL callback that + * generates this libwebsockets callback and the meanings of the + * arguments passed. In this callback, @user is the x509_ctx, + * @in is the ssl pointer and @len is preverify_ok + * Notice that this callback maintains libwebsocket return + * conventions, return 0 to mean the cert is OK or 1 to fail it. + * This also means that if you don't handle this callback then + * the default callback action of returning 0 allows the client + * certificates. + * + * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: this callback happens + * when a client handshake is being compiled. @user is NULL, + * @in is a char **, it's pointing to a char * which holds the + * next location in the header buffer where you can add + * headers, and @len is the remaining space in the header buffer, + * which is typically some hundreds of bytes. So, to add a canned + * cookie, your handler code might look similar to: + * + * char **p = (char **)in; + * + * if (len < 100) + * return 1; + * + * *p += sprintf(*p, "Cookie: a=b\x0d\x0a"); + * + * return 0; + * + * Notice if you add anything, you just have to take care about + * the CRLF on the line you added. Obviously this callback is + * optional, if you don't handle it everything is fine. + * + * Notice the callback is coming to protocols[0] all the time, + * because there is no specific protocol handshook yet. + * + * LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: When the server handshake code + * sees that it does support a requested extension, before + * accepting the extension by additing to the list sent back to + * the client it gives this callback just to check that it's okay + * to use that extension. It calls back to the requested protocol + * and with @in being the extension name, @len is 0 and @user is + * valid. Note though at this time the ESTABLISHED callback hasn't + * happened yet so if you initialize @user content there, @user + * content during this callback might not be useful for anything. + * Notice this callback comes to protocols[0]. + * + * LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: When a client + * connection is being prepared to start a handshake to a server, + * each supported extension is checked with protocols[0] callback + * with this reason, giving the user code a chance to suppress the + * claim to support that extension by returning non-zero. If + * unhandled, by default 0 will be returned and the extension + * support included in the header to the server. Notice this + * callback comes to protocols[0]. + * + * LWS_CALLBACK_PROTOCOL_INIT: One-time call per protocol so it can + * do initial setup / allocations etc + * + * LWS_CALLBACK_PROTOCOL_DESTROY: One-time call per protocol indicating + * this protocol won't get used at all after this callback, the + * context is getting destroyed. Take the opportunity to + * deallocate everything that was allocated by the protocol. + * + * The next four reasons are optional and only need taking care of if you + * will be integrating libwebsockets sockets into an external polling + * array. + * + * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop + * internally, but in the case you are integrating with another + * server you will need to have libwebsocket sockets share a + * polling array with the other server. This and the other + * POLL_FD related callbacks let you put your specialized + * poll array interface code in the callback for protocol 0, the + * first protocol you support, usually the HTTP protocol in the + * serving case. This callback happens when a socket needs to be + * added to the polling loop: @in contains the fd, and + * @len is the events bitmap (like, POLLIN). If you are using the + * internal polling loop (the "service" callback), you can just + * ignore these callbacks. + * + * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descriptor + * needs to be removed from an external polling array. @in is + * the socket desricptor. If you are using the internal polling + * loop, you can just ignore it. + * + * LWS_CALLBACK_SET_MODE_POLL_FD: This callback happens when libwebsockets + * wants to modify the events for the socket descriptor in @in. + * The handler should OR @len on to the events member of the pollfd + * struct for this socket descriptor. If you are using the + * internal polling loop, you can just ignore it. + * + * LWS_CALLBACK_CLEAR_MODE_POLL_FD: This callback occurs when libwebsockets + * wants to modify the events for the socket descriptor in @in. + * The handler should AND ~@len on to the events member of the + * pollfd struct for this socket descriptor. If you are using the + * internal polling loop, you can just ignore it. + */ +LWS_VISIBLE LWS_EXTERN int callback(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len); + +typedef int (callback_function)(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len); + +#ifndef LWS_NO_EXTENSIONS +/** + * extension_callback_function() - Hooks to allow extensions to operate + * @context: Websockets context + * @ext: This extension + * @wsi: Opaque websocket instance pointer + * @reason: The reason for the call + * @user: Pointer to per-session user data allocated by library + * @in: Pointer used for some callback reasons + * @len: Length set for some callback reasons + * + * Each extension that is active on a particular connection receives + * callbacks during the connection lifetime to allow the extension to + * operate on websocket data and manage itself. + * + * Libwebsockets takes care of allocating and freeing "user" memory for + * each active extension on each connection. That is what is pointed to + * by the @user parameter. + * + * LWS_EXT_CALLBACK_CONSTRUCT: called when the server has decided to + * select this extension from the list provided by the client, + * just before the server will send back the handshake accepting + * the connection with this extension active. This gives the + * extension a chance to initialize its connection context found + * in @user. + * + * LWS_EXT_CALLBACK_CLIENT_CONSTRUCT: same as LWS_EXT_CALLBACK_CONSTRUCT + * but called when client is instantiating this extension. Some + * extensions will work the same on client and server side and then + * you can just merge handlers for both CONSTRUCTS. + * + * LWS_EXT_CALLBACK_DESTROY: called when the connection the extension was + * being used on is about to be closed and deallocated. It's the + * last chance for the extension to deallocate anything it has + * allocated in the user data (pointed to by @user) before the + * user data is deleted. This same callback is used whether you + * are in client or server instantiation context. + * + * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE: when this extension was active on + * a connection, and a packet of data arrived at the connection, + * it is passed to this callback to give the extension a chance to + * change the data, eg, decompress it. @user is pointing to the + * extension's private connection context data, @in is pointing + * to an lws_tokens struct, it consists of a char * pointer called + * token, and an int called token_len. At entry, these are + * set to point to the received buffer and set to the content + * length. If the extension will grow the content, it should use + * a new buffer allocated in its private user context data and + * set the pointed-to lws_tokens members to point to its buffer. + * + * LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as + * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the + * extension a chance to change websocket data just before it will + * be sent out. Using the same lws_token pointer scheme in @in, + * the extension can change the buffer and the length to be + * transmitted how it likes. Again if it wants to grow the + * buffer safely, it should copy the data into its own buffer and + * set the lws_tokens token pointer to it. + */ +LWS_VISIBLE LWS_EXTERN int extension_callback(struct libwebsocket_context *context, + struct libwebsocket_extension *ext, + struct libwebsocket *wsi, + enum libwebsocket_extension_callback_reasons reason, + void *user, void *in, size_t len); + +typedef int (extension_callback_function)(struct libwebsocket_context *context, + struct libwebsocket_extension *ext, + struct libwebsocket *wsi, + enum libwebsocket_extension_callback_reasons reason, + void *user, void *in, size_t len); +#endif + +/** + * struct libwebsocket_protocols - List of protocols and handlers server + * supports. + * @name: Protocol name that must match the one given in the client + * Javascript new WebSocket(url, 'protocol') name + * @callback: The service callback used for this protocol. It allows the + * service action for an entire protocol to be encapsulated in + * the protocol-specific callback + * @per_session_data_size: Each new connection using this protocol gets + * this much memory allocated on connection establishment and + * freed on connection takedown. A pointer to this per-connection + * allocation is passed into the callback in the 'user' parameter + * @rx_buffer_size: if you want atomic frames delivered to the callback, you + * should set this to the size of the biggest legal frame that + * you support. If the frame size is exceeded, there is no + * error, but the buffer will spill to the user callback when + * full, which you can detect by using + * libwebsockets_remaining_packet_payload(). Notice that you + * just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING + * and post-padding are automatically also allocated on top. + * @owning_server: the server init call fills in this opaque pointer when + * registering this protocol with the server. + * @protocol_index: which protocol we are starting from zero + * + * This structure represents one protocol supported by the server. An + * array of these structures is passed to libwebsocket_create_server() + * allows as many protocols as you like to be handled by one server. + */ + +struct libwebsocket_protocols { + const char *name; + callback_function *callback; + size_t per_session_data_size; + size_t rx_buffer_size; + + /* + * below are filled in on server init and can be left uninitialized, + * no need for user to use them directly either + */ + + struct libwebsocket_context *owning_server; + int protocol_index; +}; + +#ifndef LWS_NO_EXTENSIONS +/** + * struct libwebsocket_extension - An extension we know how to cope with + * + * @name: Formal extension name, eg, "deflate-stream" + * @callback: Service callback + * @per_session_data_size: Libwebsockets will auto-malloc this much + * memory for the use of the extension, a pointer + * to it comes in the @user callback parameter + * @per_context_private_data: Optional storage for this extension that + * is per-context, so it can track stuff across + * all sessions, etc, if it wants + */ + +struct libwebsocket_extension { + const char *name; + extension_callback_function *callback; + size_t per_session_data_size; + void *per_context_private_data; +}; +#endif + +/** + * struct lws_context_creation_info: parameters to create context with + * + * @port: Port to listen on... you can use 0 to suppress listening on + * any port, that's what you want if you are not running a + * websocket server at all but just using it as a client + * @iface: NULL to bind the listen socket to all interfaces, or the + * interface name, eg, "eth2" + * @protocols: Array of structures listing supported protocols and a protocol- + * specific callback for each one. The list is ended with an + * entry that has a NULL callback pointer. + * It's not const because we write the owning_server member + * @extensions: NULL or array of libwebsocket_extension structs listing the + * extensions this context supports. If you configured with + * --without-extensions, you should give NULL here. + * @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want + * to listen using SSL, set to the filepath to fetch the + * server cert from, otherwise NULL for unencrypted + * @ssl_private_key_filepath: filepath to private key if wanting SSL mode, + * else ignored + * @ssl_ca_filepath: CA certificate filepath or NULL + * @ssl_cipher_list: List of valid ciphers to use (eg, + * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" + * or you can leave it as NULL to get "DEFAULT" + * @gid: group id to change to after setting listen socket, or -1. + * @uid: user id to change to after setting listen socket, or -1. + * @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK + * @user: optional user pointer that can be recovered via the context + * pointer using libwebsocket_context_user + * @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout to + * all libwebsocket sockets, client or server + * @ka_probes: if ka_time was nonzero, after the timeout expires how many + * times to try to get a response from the peer before giving up + * and killing the connection + * @ka_interval: if ka_time was nonzero, how long to wait before each ka_probes + * attempt + */ + +struct lws_context_creation_info { + int port; + const char *iface; + struct libwebsocket_protocols *protocols; + struct libwebsocket_extension *extensions; + const char *ssl_cert_filepath; + const char *ssl_private_key_filepath; + const char *ssl_ca_filepath; + const char *ssl_cipher_list; + int gid; + int uid; + unsigned int options; + void *user; + int ka_time; + int ka_probes; + int ka_interval; + +}; + +LWS_VISIBLE LWS_EXTERN +void lws_set_log_level(int level, + void (*log_emit_function)(int level, const char *line)); + +LWS_VISIBLE LWS_EXTERN void +lwsl_emit_syslog(int level, const char *line); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket_context * +libwebsocket_create_context(struct lws_context_creation_info *info); + +LWS_VISIBLE LWS_EXTERN void +libwebsocket_context_destroy(struct libwebsocket_context *context); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service(struct libwebsocket_context *context, int timeout_ms); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service_fd(struct libwebsocket_context *context, + struct pollfd *pollfd); + +LWS_VISIBLE LWS_EXTERN void * +libwebsocket_context_user(struct libwebsocket_context *context); + +/* + * IMPORTANT NOTICE! + * + * When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY) + * the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE + * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len). + * + * This allows us to add protocol info before and after the data, and send as + * one packet on the network without payload copying, for maximum efficiency. + * + * So for example you need this kind of code to use libwebsocket_write with a + * 128-byte payload + * + * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING]; + * + * // fill your part of the buffer... for example here it's all zeros + * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128); + * + * libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, + * LWS_WRITE_TEXT); + * + * When sending LWS_WRITE_HTTP, there is no protocol addition and you can just + * use the whole buffer without taking care of the above. + */ + +/* + * this is the frame nonce plus two header plus 8 length + * there's an additional two for mux extension per mux nesting level + * 2 byte prepend on close will already fit because control frames cannot use + * the big length style + */ + +#define LWS_SEND_BUFFER_PRE_PADDING (4 + 10 + (2 * MAX_MUX_RECURSION)) +#define LWS_SEND_BUFFER_POST_PADDING 4 + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len, + enum libwebsocket_write_protocol protocol); + +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file(struct libwebsocket_context *context, + struct libwebsocket *wsi, const char *file, + const char *content_type); +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file_fragment(struct libwebsocket_context *context, + struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN const struct libwebsocket_protocols * +libwebsockets_get_protocol(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable(struct libwebsocket_context *context, + struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable_all_protocol( + const struct libwebsocket_protocols *protocol); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_get_socket_fd(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_is_final_fragment(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN unsigned char +libwebsocket_get_reserved_bits(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable); + +LWS_VISIBLE LWS_EXTERN void +libwebsocket_rx_flow_allow_all_protocol( + const struct libwebsocket_protocols *protocol); + +LWS_VISIBLE LWS_EXTERN size_t +libwebsockets_remaining_packet_payload(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect_extended(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one, + void *userdata); + +LWS_VISIBLE LWS_EXTERN const char * +libwebsocket_canonical_hostname(struct libwebsocket_context *context); + + +LWS_VISIBLE LWS_EXTERN void +libwebsockets_get_peer_addresses(struct libwebsocket_context *context, + struct libwebsocket *wsi, int fd, char *name, int name_len, + char *rip, int rip_len); + +LWS_VISIBLE LWS_EXTERN int +libwebsockets_get_random(struct libwebsocket_context *context, + void *buf, int len); + +LWS_VISIBLE LWS_EXTERN int +lws_daemonize(const char *_lock_path); + +LWS_VISIBLE LWS_EXTERN int +lws_send_pipe_choked(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +lws_frame_is_binary(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN unsigned char * +libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_encode_string(const char *in, int in_len, char *out, int out_size); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_decode_string(const char *in, char *out, int out_size); + +LWS_VISIBLE LWS_EXTERN const char * +lws_get_library_version(void); + +/* access to headers... only valid while headers valid */ + +LWS_VISIBLE LWS_EXTERN int +lws_hdr_total_length(struct libwebsocket *wsi, enum lws_token_indexes h); + +LWS_VISIBLE LWS_EXTERN int +lws_hdr_copy(struct libwebsocket *wsi, char *dest, int len, + enum lws_token_indexes h); + +/* + * Note: this is not normally needed as a user api. It's provided in case it is + * useful when integrating with other app poll loop service code. + */ + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_read(struct libwebsocket_context *context, + struct libwebsocket *wsi, + unsigned char *buf, size_t len); + +#ifndef LWS_NO_EXTENSIONS +LWS_VISIBLE LWS_EXTERN struct libwebsocket_extension *libwebsocket_get_internal_extensions(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/external/libwebsockets/ios/include/libwebsockets.h b/external/libwebsockets/ios/include/libwebsockets.h new file mode 100644 index 0000000000..65bae14534 --- /dev/null +++ b/external/libwebsockets/ios/include/libwebsockets.h @@ -0,0 +1,993 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010-2013 Andy Green + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation: + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef __LIBWEBSOCKET_H__ +#define __LIBWEBSOCKET_H__ + +#ifdef __cplusplus +extern "C" { +#include +#endif + +#ifdef WIN32 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include +#include +#include "../win32port/win32helpers/websock-w32.h" + +#include "../win32port/win32helpers/gettimeofday.h" + +#define strcasecmp stricmp +#define getdtablesize() 30000 + +typedef int ssize_t; + +#define LWS_VISIBLE + +#ifdef LWS_DLL +#ifdef LWS_INTERNAL +#define LWS_EXTERN extern __declspec(dllexport) +#else +#define LWS_EXTERN extern __declspec(dllimport) +#endif +#else +#define LWS_EXTERN +#endif + +#else // NOT WIN32 +#include +#include + +#if defined(__GNUC__) +#define LWS_VISIBLE __attribute__((visibility("default"))) +#else +#define LWS_VISIBLE +#endif + +#endif + +#include + +#ifndef LWS_EXTERN +#define LWS_EXTERN extern +#endif + +#define CONTEXT_PORT_NO_LISTEN 0 +#define MAX_MUX_RECURSION 2 + +enum lws_log_levels { + LLL_ERR = 1 << 0, + LLL_WARN = 1 << 1, + LLL_NOTICE = 1 << 2, + LLL_INFO = 1 << 3, + LLL_DEBUG = 1 << 4, + LLL_PARSER = 1 << 5, + LLL_HEADER = 1 << 6, + LLL_EXT = 1 << 7, + LLL_CLIENT = 1 << 8, + LLL_LATENCY = 1 << 9, + + LLL_COUNT = 10 /* set to count of valid flags */ +}; + +LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...); + +/* notice, warn and log are always compiled in */ +#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) +#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) +/* + * weaker logging can be deselected at configure time using --disable-debug + * that gets rid of the overhead of checking while keeping _warn and _err + * active + */ +#ifdef _DEBUG + +#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) +#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) +#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) +#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) +#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) +#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) +#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) +LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); + +#else /* no debug */ + +#define lwsl_info(...) +#define lwsl_debug(...) +#define lwsl_parser(...) +#define lwsl_header(...) +#define lwsl_ext(...) +#define lwsl_client(...) +#define lwsl_latency(...) +#define lwsl_hexdump(a, b) + +#endif + +enum libwebsocket_context_options { + LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2, + LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4, +}; + +enum libwebsocket_callback_reasons { + LWS_CALLBACK_ESTABLISHED, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, + LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, + LWS_CALLBACK_CLIENT_ESTABLISHED, + LWS_CALLBACK_CLOSED, + LWS_CALLBACK_RECEIVE, + LWS_CALLBACK_CLIENT_RECEIVE, + LWS_CALLBACK_CLIENT_RECEIVE_PONG, + LWS_CALLBACK_CLIENT_WRITEABLE, + LWS_CALLBACK_SERVER_WRITEABLE, + LWS_CALLBACK_HTTP, + LWS_CALLBACK_HTTP_FILE_COMPLETION, + LWS_CALLBACK_HTTP_WRITEABLE, + LWS_CALLBACK_FILTER_NETWORK_CONNECTION, + LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, + LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, + LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, + LWS_CALLBACK_CONFIRM_EXTENSION_OKAY, + LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, + LWS_CALLBACK_PROTOCOL_INIT, + LWS_CALLBACK_PROTOCOL_DESTROY, + /* external poll() management support */ + LWS_CALLBACK_ADD_POLL_FD, + LWS_CALLBACK_DEL_POLL_FD, + LWS_CALLBACK_SET_MODE_POLL_FD, + LWS_CALLBACK_CLEAR_MODE_POLL_FD, +}; + +#ifndef LWS_NO_EXTENSIONS +enum libwebsocket_extension_callback_reasons { + LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, + LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, + LWS_EXT_CALLBACK_CONSTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONSTRUCT, + LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, + LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION, + LWS_EXT_CALLBACK_DESTROY, + LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, + LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED, + LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, + LWS_EXT_CALLBACK_PACKET_TX_PRESEND, + LWS_EXT_CALLBACK_PACKET_TX_DO_SEND, + LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX, + LWS_EXT_CALLBACK_FLUSH_PENDING_TX, + LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX, + LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION, + LWS_EXT_CALLBACK_1HZ, + LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, + LWS_EXT_CALLBACK_IS_WRITEABLE, + LWS_EXT_CALLBACK_PAYLOAD_TX, + LWS_EXT_CALLBACK_PAYLOAD_RX, +}; +#endif + +enum libwebsocket_write_protocol { + LWS_WRITE_TEXT, + LWS_WRITE_BINARY, + LWS_WRITE_CONTINUATION, + LWS_WRITE_HTTP, + + /* special 04+ opcodes */ + + LWS_WRITE_CLOSE, + LWS_WRITE_PING, + LWS_WRITE_PONG, + + /* flags */ + + LWS_WRITE_NO_FIN = 0x40, + /* + * client packet payload goes out on wire unmunged + * only useful for security tests since normal servers cannot + * decode the content if used + */ + LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80 +}; + +/* + * you need these to look at headers that have been parsed if using the + * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum + * list below is absent, .token = NULL and token_len = 0. Otherwise .token + * points to .token_len chars containing that header content. + */ + +struct lws_tokens { + char *token; + int token_len; +}; + +enum lws_token_indexes { + WSI_TOKEN_GET_URI, + WSI_TOKEN_HOST, + WSI_TOKEN_CONNECTION, + WSI_TOKEN_KEY1, + WSI_TOKEN_KEY2, + WSI_TOKEN_PROTOCOL, + WSI_TOKEN_UPGRADE, + WSI_TOKEN_ORIGIN, + WSI_TOKEN_DRAFT, + WSI_TOKEN_CHALLENGE, + + /* new for 04 */ + WSI_TOKEN_KEY, + WSI_TOKEN_VERSION, + WSI_TOKEN_SWORIGIN, + + /* new for 05 */ + WSI_TOKEN_EXTENSIONS, + + /* client receives these */ + WSI_TOKEN_ACCEPT, + WSI_TOKEN_NONCE, + WSI_TOKEN_HTTP, + WSI_TOKEN_MUXURL, + + /* use token storage to stash these */ + + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + _WSI_TOKEN_CLIENT_PEER_ADDRESS, + _WSI_TOKEN_CLIENT_URI, + _WSI_TOKEN_CLIENT_HOST, + _WSI_TOKEN_CLIENT_ORIGIN, + + /* always last real token index*/ + WSI_TOKEN_COUNT, + /* parser state additions */ + WSI_TOKEN_NAME_PART, + WSI_TOKEN_SKIPPING, + WSI_TOKEN_SKIPPING_SAW_CR, + WSI_PARSING_COMPLETE, + WSI_INIT_TOKEN_MUXURL, +}; + +/* + * From RFC 6455 + 1000 + + 1000 indicates a normal closure, meaning that the purpose for + which the connection was established has been fulfilled. + + 1001 + + 1001 indicates that an endpoint is "going away", such as a server + going down or a browser having navigated away from a page. + + 1002 + + 1002 indicates that an endpoint is terminating the connection due + to a protocol error. + + 1003 + + 1003 indicates that an endpoint is terminating the connection + because it has received a type of data it cannot accept (e.g., an + endpoint that understands only text data MAY send this if it + receives a binary message). + + 1004 + + Reserved. The specific meaning might be defined in the future. + + 1005 + + 1005 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that no status + code was actually present. + + 1006 + + 1006 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed abnormally, e.g., without sending or + receiving a Close control frame. + + 1007 + + 1007 indicates that an endpoint is terminating the connection + because it has received data within a message that was not + consistent with the type of the message (e.g., non-UTF-8 [RFC3629] + data within a text message). + + 1008 + + 1008 indicates that an endpoint is terminating the connection + because it has received a message that violates its policy. This + is a generic status code that can be returned when there is no + other more suitable status code (e.g., 1003 or 1009) or if there + is a need to hide specific details about the policy. + + 1009 + + 1009 indicates that an endpoint is terminating the connection + because it has received a message that is too big for it to + process. + + 1010 + + 1010 indicates that an endpoint (client) is terminating the + connection because it has expected the server to negotiate one or + more extension, but the server didn't return them in the response + message of the WebSocket handshake. The list of extensions that + are needed SHOULD appear in the /reason/ part of the Close frame. + Note that this status code is not used by the server, because it + can fail the WebSocket handshake instead. + + 1011 + + 1011 indicates that a server is terminating the connection because + it encountered an unexpected condition that prevented it from + fulfilling the request. + + 1015 + + 1015 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed due to a failure to perform a TLS handshake + (e.g., the server certificate can't be verified). +*/ + +enum lws_close_status { + LWS_CLOSE_STATUS_NOSTATUS = 0, + LWS_CLOSE_STATUS_NORMAL = 1000, + LWS_CLOSE_STATUS_GOINGAWAY = 1001, + LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002, + LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003, + LWS_CLOSE_STATUS_RESERVED = 1004, + LWS_CLOSE_STATUS_NO_STATUS = 1005, + LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006, + LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007, + LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008, + LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009, + LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010, + LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011, + LWS_CLOSE_STATUS_TLS_FAILURE = 1015, +}; + +struct libwebsocket; +struct libwebsocket_context; +/* needed even with extensions disabled for create context */ +struct libwebsocket_extension; + +/** + * callback_function() - User server actions + * @context: Websockets context + * @wsi: Opaque websocket instance pointer + * @reason: The reason for the call + * @user: Pointer to per-session user data allocated by library + * @in: Pointer used for some callback reasons + * @len: Length set for some callback reasons + * + * This callback is the way the user controls what is served. All the + * protocol detail is hidden and handled by the library. + * + * For each connection / session there is user data allocated that is + * pointed to by "user". You set the size of this user data area when + * the library is initialized with libwebsocket_create_server. + * + * You get an opportunity to initialize user data when called back with + * LWS_CALLBACK_ESTABLISHED reason. + * + * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with + * an incoming client + * + * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has + * been unable to complete a handshake with the remote server + * + * LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for the + * client user code to examine the http headers + * and decide to reject the connection. If the + * content in the headers is interesting to the + * client (url, etc) it needs to copy it out at + * this point since it will be destroyed before + * the CLIENT_ESTABLISHED call + * + * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed + * a handshake with the remote server + * + * LWS_CALLBACK_CLOSED: when the websocket session ends + * + * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a + * remote client, it can be found at *in and is + * len bytes long + * + * LWS_CALLBACK_CLIENT_RECEIVE_PONG: if you elected to see PONG packets, + * they appear with this callback reason. PONG + * packets only exist in 04+ protocol + * + * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for the + * client connection, it can be found at *in and + * is len bytes long + * + * LWS_CALLBACK_HTTP: an http request has come from a client that is not + * asking to upgrade the connection to a websocket + * one. This is a chance to serve http content, + * for example, to send a script to the client + * which will then open the websockets connection. + * @in points to the URI path requested and + * libwebsockets_serve_http_file() makes it very + * simple to send back a file to the client. + * Normally after sending the file you are done + * with the http connection, since the rest of the + * activity will come by websockets from the script + * that was delivered by http, so you will want to + * return 1; to close and free up the connection. + * That's important because it uses a slot in the + * total number of client connections allowed set + * by MAX_CLIENTS. + * + * LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protocol + * link now. + * + * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down + * http link has completed. + * + * LWS_CALLBACK_CLIENT_WRITEABLE: + * LWS_CALLBACK_SERVER_WRITEABLE: If you call + * libwebsocket_callback_on_writable() on a connection, you will + * get one of these callbacks coming when the connection socket + * is able to accept another write packet without blocking. + * If it already was able to take another packet without blocking, + * you'll get this callback at the next call to the service loop + * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE + * and servers get LWS_CALLBACK_SERVER_WRITEABLE. + * + * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connects to + * the server at network level; the connection is accepted but then + * passed to this callback to decide whether to hang up immediately + * or not, based on the client IP. @in contains the connection + * socket's descriptor. Return non-zero to terminate + * the connection before sending or receiving anything. + * Because this happens immediately after the network connection + * from the client, there's no websocket protocol selected yet so + * this callback is issued only to protocol 0. + * + * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has + * been received and parsed from the client, but the response is + * not sent yet. Return non-zero to disallow the connection. + * @user is a pointer to an array of struct lws_tokens, you can + * use the header enums lws_token_indexes from libwebsockets.h + * to check for and read the supported header presence and + * content before deciding to allow the handshake to proceed or + * to kill the connection. + * + * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: if configured for + * including OpenSSL support, this callback allows your user code + * to perform extra SSL_CTX_load_verify_locations() or similar + * calls to direct OpenSSL where to find certificates the client + * can use to confirm the remote server identity. @user is the + * OpenSSL SSL_CTX* + * + * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: if configured for + * including OpenSSL support, this callback allows your user code + * to load extra certifcates into the server which allow it to + * verify the validity of certificates returned by clients. @user + * is the server's OpenSSL SSL_CTX* + * + * LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: if the + * libwebsockets context was created with the option + * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this + * callback is generated during OpenSSL verification of the cert + * sent from the client. It is sent to protocol[0] callback as + * no protocol has been negotiated on the connection yet. + * Notice that the libwebsockets context and wsi are both NULL + * during this callback. See + * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html + * to understand more detail about the OpenSSL callback that + * generates this libwebsockets callback and the meanings of the + * arguments passed. In this callback, @user is the x509_ctx, + * @in is the ssl pointer and @len is preverify_ok + * Notice that this callback maintains libwebsocket return + * conventions, return 0 to mean the cert is OK or 1 to fail it. + * This also means that if you don't handle this callback then + * the default callback action of returning 0 allows the client + * certificates. + * + * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: this callback happens + * when a client handshake is being compiled. @user is NULL, + * @in is a char **, it's pointing to a char * which holds the + * next location in the header buffer where you can add + * headers, and @len is the remaining space in the header buffer, + * which is typically some hundreds of bytes. So, to add a canned + * cookie, your handler code might look similar to: + * + * char **p = (char **)in; + * + * if (len < 100) + * return 1; + * + * *p += sprintf(*p, "Cookie: a=b\x0d\x0a"); + * + * return 0; + * + * Notice if you add anything, you just have to take care about + * the CRLF on the line you added. Obviously this callback is + * optional, if you don't handle it everything is fine. + * + * Notice the callback is coming to protocols[0] all the time, + * because there is no specific protocol handshook yet. + * + * LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: When the server handshake code + * sees that it does support a requested extension, before + * accepting the extension by additing to the list sent back to + * the client it gives this callback just to check that it's okay + * to use that extension. It calls back to the requested protocol + * and with @in being the extension name, @len is 0 and @user is + * valid. Note though at this time the ESTABLISHED callback hasn't + * happened yet so if you initialize @user content there, @user + * content during this callback might not be useful for anything. + * Notice this callback comes to protocols[0]. + * + * LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: When a client + * connection is being prepared to start a handshake to a server, + * each supported extension is checked with protocols[0] callback + * with this reason, giving the user code a chance to suppress the + * claim to support that extension by returning non-zero. If + * unhandled, by default 0 will be returned and the extension + * support included in the header to the server. Notice this + * callback comes to protocols[0]. + * + * LWS_CALLBACK_PROTOCOL_INIT: One-time call per protocol so it can + * do initial setup / allocations etc + * + * LWS_CALLBACK_PROTOCOL_DESTROY: One-time call per protocol indicating + * this protocol won't get used at all after this callback, the + * context is getting destroyed. Take the opportunity to + * deallocate everything that was allocated by the protocol. + * + * The next four reasons are optional and only need taking care of if you + * will be integrating libwebsockets sockets into an external polling + * array. + * + * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop + * internally, but in the case you are integrating with another + * server you will need to have libwebsocket sockets share a + * polling array with the other server. This and the other + * POLL_FD related callbacks let you put your specialized + * poll array interface code in the callback for protocol 0, the + * first protocol you support, usually the HTTP protocol in the + * serving case. This callback happens when a socket needs to be + * added to the polling loop: @in contains the fd, and + * @len is the events bitmap (like, POLLIN). If you are using the + * internal polling loop (the "service" callback), you can just + * ignore these callbacks. + * + * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descriptor + * needs to be removed from an external polling array. @in is + * the socket desricptor. If you are using the internal polling + * loop, you can just ignore it. + * + * LWS_CALLBACK_SET_MODE_POLL_FD: This callback happens when libwebsockets + * wants to modify the events for the socket descriptor in @in. + * The handler should OR @len on to the events member of the pollfd + * struct for this socket descriptor. If you are using the + * internal polling loop, you can just ignore it. + * + * LWS_CALLBACK_CLEAR_MODE_POLL_FD: This callback occurs when libwebsockets + * wants to modify the events for the socket descriptor in @in. + * The handler should AND ~@len on to the events member of the + * pollfd struct for this socket descriptor. If you are using the + * internal polling loop, you can just ignore it. + */ +LWS_VISIBLE LWS_EXTERN int callback(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len); + +typedef int (callback_function)(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len); + +#ifndef LWS_NO_EXTENSIONS +/** + * extension_callback_function() - Hooks to allow extensions to operate + * @context: Websockets context + * @ext: This extension + * @wsi: Opaque websocket instance pointer + * @reason: The reason for the call + * @user: Pointer to per-session user data allocated by library + * @in: Pointer used for some callback reasons + * @len: Length set for some callback reasons + * + * Each extension that is active on a particular connection receives + * callbacks during the connection lifetime to allow the extension to + * operate on websocket data and manage itself. + * + * Libwebsockets takes care of allocating and freeing "user" memory for + * each active extension on each connection. That is what is pointed to + * by the @user parameter. + * + * LWS_EXT_CALLBACK_CONSTRUCT: called when the server has decided to + * select this extension from the list provided by the client, + * just before the server will send back the handshake accepting + * the connection with this extension active. This gives the + * extension a chance to initialize its connection context found + * in @user. + * + * LWS_EXT_CALLBACK_CLIENT_CONSTRUCT: same as LWS_EXT_CALLBACK_CONSTRUCT + * but called when client is instantiating this extension. Some + * extensions will work the same on client and server side and then + * you can just merge handlers for both CONSTRUCTS. + * + * LWS_EXT_CALLBACK_DESTROY: called when the connection the extension was + * being used on is about to be closed and deallocated. It's the + * last chance for the extension to deallocate anything it has + * allocated in the user data (pointed to by @user) before the + * user data is deleted. This same callback is used whether you + * are in client or server instantiation context. + * + * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE: when this extension was active on + * a connection, and a packet of data arrived at the connection, + * it is passed to this callback to give the extension a chance to + * change the data, eg, decompress it. @user is pointing to the + * extension's private connection context data, @in is pointing + * to an lws_tokens struct, it consists of a char * pointer called + * token, and an int called token_len. At entry, these are + * set to point to the received buffer and set to the content + * length. If the extension will grow the content, it should use + * a new buffer allocated in its private user context data and + * set the pointed-to lws_tokens members to point to its buffer. + * + * LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as + * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the + * extension a chance to change websocket data just before it will + * be sent out. Using the same lws_token pointer scheme in @in, + * the extension can change the buffer and the length to be + * transmitted how it likes. Again if it wants to grow the + * buffer safely, it should copy the data into its own buffer and + * set the lws_tokens token pointer to it. + */ +LWS_VISIBLE LWS_EXTERN int extension_callback(struct libwebsocket_context *context, + struct libwebsocket_extension *ext, + struct libwebsocket *wsi, + enum libwebsocket_extension_callback_reasons reason, + void *user, void *in, size_t len); + +typedef int (extension_callback_function)(struct libwebsocket_context *context, + struct libwebsocket_extension *ext, + struct libwebsocket *wsi, + enum libwebsocket_extension_callback_reasons reason, + void *user, void *in, size_t len); +#endif + +/** + * struct libwebsocket_protocols - List of protocols and handlers server + * supports. + * @name: Protocol name that must match the one given in the client + * Javascript new WebSocket(url, 'protocol') name + * @callback: The service callback used for this protocol. It allows the + * service action for an entire protocol to be encapsulated in + * the protocol-specific callback + * @per_session_data_size: Each new connection using this protocol gets + * this much memory allocated on connection establishment and + * freed on connection takedown. A pointer to this per-connection + * allocation is passed into the callback in the 'user' parameter + * @rx_buffer_size: if you want atomic frames delivered to the callback, you + * should set this to the size of the biggest legal frame that + * you support. If the frame size is exceeded, there is no + * error, but the buffer will spill to the user callback when + * full, which you can detect by using + * libwebsockets_remaining_packet_payload(). Notice that you + * just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING + * and post-padding are automatically also allocated on top. + * @owning_server: the server init call fills in this opaque pointer when + * registering this protocol with the server. + * @protocol_index: which protocol we are starting from zero + * + * This structure represents one protocol supported by the server. An + * array of these structures is passed to libwebsocket_create_server() + * allows as many protocols as you like to be handled by one server. + */ + +struct libwebsocket_protocols { + const char *name; + callback_function *callback; + size_t per_session_data_size; + size_t rx_buffer_size; + + /* + * below are filled in on server init and can be left uninitialized, + * no need for user to use them directly either + */ + + struct libwebsocket_context *owning_server; + int protocol_index; +}; + +#ifndef LWS_NO_EXTENSIONS +/** + * struct libwebsocket_extension - An extension we know how to cope with + * + * @name: Formal extension name, eg, "deflate-stream" + * @callback: Service callback + * @per_session_data_size: Libwebsockets will auto-malloc this much + * memory for the use of the extension, a pointer + * to it comes in the @user callback parameter + * @per_context_private_data: Optional storage for this extension that + * is per-context, so it can track stuff across + * all sessions, etc, if it wants + */ + +struct libwebsocket_extension { + const char *name; + extension_callback_function *callback; + size_t per_session_data_size; + void *per_context_private_data; +}; +#endif + +/** + * struct lws_context_creation_info: parameters to create context with + * + * @port: Port to listen on... you can use 0 to suppress listening on + * any port, that's what you want if you are not running a + * websocket server at all but just using it as a client + * @iface: NULL to bind the listen socket to all interfaces, or the + * interface name, eg, "eth2" + * @protocols: Array of structures listing supported protocols and a protocol- + * specific callback for each one. The list is ended with an + * entry that has a NULL callback pointer. + * It's not const because we write the owning_server member + * @extensions: NULL or array of libwebsocket_extension structs listing the + * extensions this context supports. If you configured with + * --without-extensions, you should give NULL here. + * @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want + * to listen using SSL, set to the filepath to fetch the + * server cert from, otherwise NULL for unencrypted + * @ssl_private_key_filepath: filepath to private key if wanting SSL mode, + * else ignored + * @ssl_ca_filepath: CA certificate filepath or NULL + * @ssl_cipher_list: List of valid ciphers to use (eg, + * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" + * or you can leave it as NULL to get "DEFAULT" + * @gid: group id to change to after setting listen socket, or -1. + * @uid: user id to change to after setting listen socket, or -1. + * @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK + * @user: optional user pointer that can be recovered via the context + * pointer using libwebsocket_context_user + * @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout to + * all libwebsocket sockets, client or server + * @ka_probes: if ka_time was nonzero, after the timeout expires how many + * times to try to get a response from the peer before giving up + * and killing the connection + * @ka_interval: if ka_time was nonzero, how long to wait before each ka_probes + * attempt + */ + +struct lws_context_creation_info { + int port; + const char *iface; + struct libwebsocket_protocols *protocols; + struct libwebsocket_extension *extensions; + const char *ssl_cert_filepath; + const char *ssl_private_key_filepath; + const char *ssl_ca_filepath; + const char *ssl_cipher_list; + int gid; + int uid; + unsigned int options; + void *user; + int ka_time; + int ka_probes; + int ka_interval; + +}; + +LWS_VISIBLE LWS_EXTERN +void lws_set_log_level(int level, + void (*log_emit_function)(int level, const char *line)); + +LWS_VISIBLE LWS_EXTERN void +lwsl_emit_syslog(int level, const char *line); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket_context * +libwebsocket_create_context(struct lws_context_creation_info *info); + +LWS_VISIBLE LWS_EXTERN void +libwebsocket_context_destroy(struct libwebsocket_context *context); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service(struct libwebsocket_context *context, int timeout_ms); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service_fd(struct libwebsocket_context *context, + struct pollfd *pollfd); + +LWS_VISIBLE LWS_EXTERN void * +libwebsocket_context_user(struct libwebsocket_context *context); + +/* + * IMPORTANT NOTICE! + * + * When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY) + * the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE + * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len). + * + * This allows us to add protocol info before and after the data, and send as + * one packet on the network without payload copying, for maximum efficiency. + * + * So for example you need this kind of code to use libwebsocket_write with a + * 128-byte payload + * + * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING]; + * + * // fill your part of the buffer... for example here it's all zeros + * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128); + * + * libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, + * LWS_WRITE_TEXT); + * + * When sending LWS_WRITE_HTTP, there is no protocol addition and you can just + * use the whole buffer without taking care of the above. + */ + +/* + * this is the frame nonce plus two header plus 8 length + * there's an additional two for mux extension per mux nesting level + * 2 byte prepend on close will already fit because control frames cannot use + * the big length style + */ + +#define LWS_SEND_BUFFER_PRE_PADDING (4 + 10 + (2 * MAX_MUX_RECURSION)) +#define LWS_SEND_BUFFER_POST_PADDING 4 + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len, + enum libwebsocket_write_protocol protocol); + +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file(struct libwebsocket_context *context, + struct libwebsocket *wsi, const char *file, + const char *content_type); +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file_fragment(struct libwebsocket_context *context, + struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN const struct libwebsocket_protocols * +libwebsockets_get_protocol(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable(struct libwebsocket_context *context, + struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable_all_protocol( + const struct libwebsocket_protocols *protocol); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_get_socket_fd(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_is_final_fragment(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN unsigned char +libwebsocket_get_reserved_bits(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable); + +LWS_VISIBLE LWS_EXTERN void +libwebsocket_rx_flow_allow_all_protocol( + const struct libwebsocket_protocols *protocol); + +LWS_VISIBLE LWS_EXTERN size_t +libwebsockets_remaining_packet_payload(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect_extended(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one, + void *userdata); + +LWS_VISIBLE LWS_EXTERN const char * +libwebsocket_canonical_hostname(struct libwebsocket_context *context); + + +LWS_VISIBLE LWS_EXTERN void +libwebsockets_get_peer_addresses(struct libwebsocket_context *context, + struct libwebsocket *wsi, int fd, char *name, int name_len, + char *rip, int rip_len); + +LWS_VISIBLE LWS_EXTERN int +libwebsockets_get_random(struct libwebsocket_context *context, + void *buf, int len); + +LWS_VISIBLE LWS_EXTERN int +lws_daemonize(const char *_lock_path); + +LWS_VISIBLE LWS_EXTERN int +lws_send_pipe_choked(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +lws_frame_is_binary(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN unsigned char * +libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_encode_string(const char *in, int in_len, char *out, int out_size); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_decode_string(const char *in, char *out, int out_size); + +LWS_VISIBLE LWS_EXTERN const char * +lws_get_library_version(void); + +/* access to headers... only valid while headers valid */ + +LWS_VISIBLE LWS_EXTERN int +lws_hdr_total_length(struct libwebsocket *wsi, enum lws_token_indexes h); + +LWS_VISIBLE LWS_EXTERN int +lws_hdr_copy(struct libwebsocket *wsi, char *dest, int len, + enum lws_token_indexes h); + +/* + * Note: this is not normally needed as a user api. It's provided in case it is + * useful when integrating with other app poll loop service code. + */ + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_read(struct libwebsocket_context *context, + struct libwebsocket *wsi, + unsigned char *buf, size_t len); + +#ifndef LWS_NO_EXTENSIONS +LWS_VISIBLE LWS_EXTERN struct libwebsocket_extension *libwebsocket_get_internal_extensions(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/external/libwebsockets/ios/lib/libwebsockets.a.REMOVED.git-id b/external/libwebsockets/ios/lib/libwebsockets.a.REMOVED.git-id new file mode 100644 index 0000000000..08dc34e960 --- /dev/null +++ b/external/libwebsockets/ios/lib/libwebsockets.a.REMOVED.git-id @@ -0,0 +1 @@ +ee4ee6cc26274f6d3138d08d429d6ba49b629f53 \ No newline at end of file diff --git a/external/libwebsockets/win32/include/libwebsockets.h b/external/libwebsockets/win32/include/libwebsockets.h new file mode 100644 index 0000000000..2203f53b4c --- /dev/null +++ b/external/libwebsockets/win32/include/libwebsockets.h @@ -0,0 +1,993 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010-2013 Andy Green + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation: + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef __LIBWEBSOCKET_H__ +#define __LIBWEBSOCKET_H__ + +#ifdef __cplusplus +extern "C" { +#include +#endif + +#ifdef WIN32 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include +#include +#include "win32helpers/websock-w32.h" + +//#include "win32helpers/gettimeofday.h" + +#define strcasecmp stricmp +#define getdtablesize() 30000 + +typedef int ssize_t; + +#define LWS_VISIBLE + +#ifdef LWS_DLL +#ifdef LWS_INTERNAL +#define LWS_EXTERN extern __declspec(dllexport) +#else +#define LWS_EXTERN extern __declspec(dllimport) +#endif +#else +#define LWS_EXTERN +#endif + +#else // NOT WIN32 +#include +#include + +#if defined(__GNUC__) +#define LWS_VISIBLE __attribute__((visibility("default"))) +#else +#define LWS_VISIBLE +#endif + +#endif + +#include + +#ifndef LWS_EXTERN +#define LWS_EXTERN extern +#endif + +#define CONTEXT_PORT_NO_LISTEN 0 +#define MAX_MUX_RECURSION 2 + +enum lws_log_levels { + LLL_ERR = 1 << 0, + LLL_WARN = 1 << 1, + LLL_NOTICE = 1 << 2, + LLL_INFO = 1 << 3, + LLL_DEBUG = 1 << 4, + LLL_PARSER = 1 << 5, + LLL_HEADER = 1 << 6, + LLL_EXT = 1 << 7, + LLL_CLIENT = 1 << 8, + LLL_LATENCY = 1 << 9, + + LLL_COUNT = 10 /* set to count of valid flags */ +}; + +LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...); + +/* notice, warn and log are always compiled in */ +#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) +#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) +/* + * weaker logging can be deselected at configure time using --disable-debug + * that gets rid of the overhead of checking while keeping _warn and _err + * active + */ +#ifdef _DEBUG + +#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) +#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) +#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) +#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) +#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) +#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) +#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) +LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); + +#else /* no debug */ + +#define lwsl_info(...) +#define lwsl_debug(...) +#define lwsl_parser(...) +#define lwsl_header(...) +#define lwsl_ext(...) +#define lwsl_client(...) +#define lwsl_latency(...) +#define lwsl_hexdump(a, b) + +#endif + +enum libwebsocket_context_options { + LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2, + LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4, +}; + +enum libwebsocket_callback_reasons { + LWS_CALLBACK_ESTABLISHED, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, + LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, + LWS_CALLBACK_CLIENT_ESTABLISHED, + LWS_CALLBACK_CLOSED, + LWS_CALLBACK_RECEIVE, + LWS_CALLBACK_CLIENT_RECEIVE, + LWS_CALLBACK_CLIENT_RECEIVE_PONG, + LWS_CALLBACK_CLIENT_WRITEABLE, + LWS_CALLBACK_SERVER_WRITEABLE, + LWS_CALLBACK_HTTP, + LWS_CALLBACK_HTTP_FILE_COMPLETION, + LWS_CALLBACK_HTTP_WRITEABLE, + LWS_CALLBACK_FILTER_NETWORK_CONNECTION, + LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, + LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, + LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, + LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, + LWS_CALLBACK_CONFIRM_EXTENSION_OKAY, + LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, + LWS_CALLBACK_PROTOCOL_INIT, + LWS_CALLBACK_PROTOCOL_DESTROY, + /* external poll() management support */ + LWS_CALLBACK_ADD_POLL_FD, + LWS_CALLBACK_DEL_POLL_FD, + LWS_CALLBACK_SET_MODE_POLL_FD, + LWS_CALLBACK_CLEAR_MODE_POLL_FD, +}; + +#ifndef LWS_NO_EXTENSIONS +enum libwebsocket_extension_callback_reasons { + LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, + LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, + LWS_EXT_CALLBACK_CONSTRUCT, + LWS_EXT_CALLBACK_CLIENT_CONSTRUCT, + LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, + LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION, + LWS_EXT_CALLBACK_DESTROY, + LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, + LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED, + LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, + LWS_EXT_CALLBACK_PACKET_TX_PRESEND, + LWS_EXT_CALLBACK_PACKET_TX_DO_SEND, + LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX, + LWS_EXT_CALLBACK_FLUSH_PENDING_TX, + LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX, + LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION, + LWS_EXT_CALLBACK_1HZ, + LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, + LWS_EXT_CALLBACK_IS_WRITEABLE, + LWS_EXT_CALLBACK_PAYLOAD_TX, + LWS_EXT_CALLBACK_PAYLOAD_RX, +}; +#endif + +enum libwebsocket_write_protocol { + LWS_WRITE_TEXT, + LWS_WRITE_BINARY, + LWS_WRITE_CONTINUATION, + LWS_WRITE_HTTP, + + /* special 04+ opcodes */ + + LWS_WRITE_CLOSE, + LWS_WRITE_PING, + LWS_WRITE_PONG, + + /* flags */ + + LWS_WRITE_NO_FIN = 0x40, + /* + * client packet payload goes out on wire unmunged + * only useful for security tests since normal servers cannot + * decode the content if used + */ + LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80 +}; + +/* + * you need these to look at headers that have been parsed if using the + * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum + * list below is absent, .token = NULL and token_len = 0. Otherwise .token + * points to .token_len chars containing that header content. + */ + +struct lws_tokens { + char *token; + int token_len; +}; + +enum lws_token_indexes { + WSI_TOKEN_GET_URI, + WSI_TOKEN_HOST, + WSI_TOKEN_CONNECTION, + WSI_TOKEN_KEY1, + WSI_TOKEN_KEY2, + WSI_TOKEN_PROTOCOL, + WSI_TOKEN_UPGRADE, + WSI_TOKEN_ORIGIN, + WSI_TOKEN_DRAFT, + WSI_TOKEN_CHALLENGE, + + /* new for 04 */ + WSI_TOKEN_KEY, + WSI_TOKEN_VERSION, + WSI_TOKEN_SWORIGIN, + + /* new for 05 */ + WSI_TOKEN_EXTENSIONS, + + /* client receives these */ + WSI_TOKEN_ACCEPT, + WSI_TOKEN_NONCE, + WSI_TOKEN_HTTP, + WSI_TOKEN_MUXURL, + + /* use token storage to stash these */ + + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + _WSI_TOKEN_CLIENT_PEER_ADDRESS, + _WSI_TOKEN_CLIENT_URI, + _WSI_TOKEN_CLIENT_HOST, + _WSI_TOKEN_CLIENT_ORIGIN, + + /* always last real token index*/ + WSI_TOKEN_COUNT, + /* parser state additions */ + WSI_TOKEN_NAME_PART, + WSI_TOKEN_SKIPPING, + WSI_TOKEN_SKIPPING_SAW_CR, + WSI_PARSING_COMPLETE, + WSI_INIT_TOKEN_MUXURL, +}; + +/* + * From RFC 6455 + 1000 + + 1000 indicates a normal closure, meaning that the purpose for + which the connection was established has been fulfilled. + + 1001 + + 1001 indicates that an endpoint is "going away", such as a server + going down or a browser having navigated away from a page. + + 1002 + + 1002 indicates that an endpoint is terminating the connection due + to a protocol error. + + 1003 + + 1003 indicates that an endpoint is terminating the connection + because it has received a type of data it cannot accept (e.g., an + endpoint that understands only text data MAY send this if it + receives a binary message). + + 1004 + + Reserved. The specific meaning might be defined in the future. + + 1005 + + 1005 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that no status + code was actually present. + + 1006 + + 1006 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed abnormally, e.g., without sending or + receiving a Close control frame. + + 1007 + + 1007 indicates that an endpoint is terminating the connection + because it has received data within a message that was not + consistent with the type of the message (e.g., non-UTF-8 [RFC3629] + data within a text message). + + 1008 + + 1008 indicates that an endpoint is terminating the connection + because it has received a message that violates its policy. This + is a generic status code that can be returned when there is no + other more suitable status code (e.g., 1003 or 1009) or if there + is a need to hide specific details about the policy. + + 1009 + + 1009 indicates that an endpoint is terminating the connection + because it has received a message that is too big for it to + process. + + 1010 + + 1010 indicates that an endpoint (client) is terminating the + connection because it has expected the server to negotiate one or + more extension, but the server didn't return them in the response + message of the WebSocket handshake. The list of extensions that + are needed SHOULD appear in the /reason/ part of the Close frame. + Note that this status code is not used by the server, because it + can fail the WebSocket handshake instead. + + 1011 + + 1011 indicates that a server is terminating the connection because + it encountered an unexpected condition that prevented it from + fulfilling the request. + + 1015 + + 1015 is a reserved value and MUST NOT be set as a status code in a + Close control frame by an endpoint. It is designated for use in + applications expecting a status code to indicate that the + connection was closed due to a failure to perform a TLS handshake + (e.g., the server certificate can't be verified). +*/ + +enum lws_close_status { + LWS_CLOSE_STATUS_NOSTATUS = 0, + LWS_CLOSE_STATUS_NORMAL = 1000, + LWS_CLOSE_STATUS_GOINGAWAY = 1001, + LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002, + LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003, + LWS_CLOSE_STATUS_RESERVED = 1004, + LWS_CLOSE_STATUS_NO_STATUS = 1005, + LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006, + LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007, + LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008, + LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009, + LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010, + LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011, + LWS_CLOSE_STATUS_TLS_FAILURE = 1015, +}; + +struct libwebsocket; +struct libwebsocket_context; +/* needed even with extensions disabled for create context */ +struct libwebsocket_extension; + +/** + * callback_function() - User server actions + * @context: Websockets context + * @wsi: Opaque websocket instance pointer + * @reason: The reason for the call + * @user: Pointer to per-session user data allocated by library + * @in: Pointer used for some callback reasons + * @len: Length set for some callback reasons + * + * This callback is the way the user controls what is served. All the + * protocol detail is hidden and handled by the library. + * + * For each connection / session there is user data allocated that is + * pointed to by "user". You set the size of this user data area when + * the library is initialized with libwebsocket_create_server. + * + * You get an opportunity to initialize user data when called back with + * LWS_CALLBACK_ESTABLISHED reason. + * + * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with + * an incoming client + * + * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has + * been unable to complete a handshake with the remote server + * + * LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for the + * client user code to examine the http headers + * and decide to reject the connection. If the + * content in the headers is interesting to the + * client (url, etc) it needs to copy it out at + * this point since it will be destroyed before + * the CLIENT_ESTABLISHED call + * + * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed + * a handshake with the remote server + * + * LWS_CALLBACK_CLOSED: when the websocket session ends + * + * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a + * remote client, it can be found at *in and is + * len bytes long + * + * LWS_CALLBACK_CLIENT_RECEIVE_PONG: if you elected to see PONG packets, + * they appear with this callback reason. PONG + * packets only exist in 04+ protocol + * + * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for the + * client connection, it can be found at *in and + * is len bytes long + * + * LWS_CALLBACK_HTTP: an http request has come from a client that is not + * asking to upgrade the connection to a websocket + * one. This is a chance to serve http content, + * for example, to send a script to the client + * which will then open the websockets connection. + * @in points to the URI path requested and + * libwebsockets_serve_http_file() makes it very + * simple to send back a file to the client. + * Normally after sending the file you are done + * with the http connection, since the rest of the + * activity will come by websockets from the script + * that was delivered by http, so you will want to + * return 1; to close and free up the connection. + * That's important because it uses a slot in the + * total number of client connections allowed set + * by MAX_CLIENTS. + * + * LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protocol + * link now. + * + * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down + * http link has completed. + * + * LWS_CALLBACK_CLIENT_WRITEABLE: + * LWS_CALLBACK_SERVER_WRITEABLE: If you call + * libwebsocket_callback_on_writable() on a connection, you will + * get one of these callbacks coming when the connection socket + * is able to accept another write packet without blocking. + * If it already was able to take another packet without blocking, + * you'll get this callback at the next call to the service loop + * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE + * and servers get LWS_CALLBACK_SERVER_WRITEABLE. + * + * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connects to + * the server at network level; the connection is accepted but then + * passed to this callback to decide whether to hang up immediately + * or not, based on the client IP. @in contains the connection + * socket's descriptor. Return non-zero to terminate + * the connection before sending or receiving anything. + * Because this happens immediately after the network connection + * from the client, there's no websocket protocol selected yet so + * this callback is issued only to protocol 0. + * + * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has + * been received and parsed from the client, but the response is + * not sent yet. Return non-zero to disallow the connection. + * @user is a pointer to an array of struct lws_tokens, you can + * use the header enums lws_token_indexes from libwebsockets.h + * to check for and read the supported header presence and + * content before deciding to allow the handshake to proceed or + * to kill the connection. + * + * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: if configured for + * including OpenSSL support, this callback allows your user code + * to perform extra SSL_CTX_load_verify_locations() or similar + * calls to direct OpenSSL where to find certificates the client + * can use to confirm the remote server identity. @user is the + * OpenSSL SSL_CTX* + * + * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: if configured for + * including OpenSSL support, this callback allows your user code + * to load extra certifcates into the server which allow it to + * verify the validity of certificates returned by clients. @user + * is the server's OpenSSL SSL_CTX* + * + * LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: if the + * libwebsockets context was created with the option + * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this + * callback is generated during OpenSSL verification of the cert + * sent from the client. It is sent to protocol[0] callback as + * no protocol has been negotiated on the connection yet. + * Notice that the libwebsockets context and wsi are both NULL + * during this callback. See + * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html + * to understand more detail about the OpenSSL callback that + * generates this libwebsockets callback and the meanings of the + * arguments passed. In this callback, @user is the x509_ctx, + * @in is the ssl pointer and @len is preverify_ok + * Notice that this callback maintains libwebsocket return + * conventions, return 0 to mean the cert is OK or 1 to fail it. + * This also means that if you don't handle this callback then + * the default callback action of returning 0 allows the client + * certificates. + * + * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: this callback happens + * when a client handshake is being compiled. @user is NULL, + * @in is a char **, it's pointing to a char * which holds the + * next location in the header buffer where you can add + * headers, and @len is the remaining space in the header buffer, + * which is typically some hundreds of bytes. So, to add a canned + * cookie, your handler code might look similar to: + * + * char **p = (char **)in; + * + * if (len < 100) + * return 1; + * + * *p += sprintf(*p, "Cookie: a=b\x0d\x0a"); + * + * return 0; + * + * Notice if you add anything, you just have to take care about + * the CRLF on the line you added. Obviously this callback is + * optional, if you don't handle it everything is fine. + * + * Notice the callback is coming to protocols[0] all the time, + * because there is no specific protocol handshook yet. + * + * LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: When the server handshake code + * sees that it does support a requested extension, before + * accepting the extension by additing to the list sent back to + * the client it gives this callback just to check that it's okay + * to use that extension. It calls back to the requested protocol + * and with @in being the extension name, @len is 0 and @user is + * valid. Note though at this time the ESTABLISHED callback hasn't + * happened yet so if you initialize @user content there, @user + * content during this callback might not be useful for anything. + * Notice this callback comes to protocols[0]. + * + * LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: When a client + * connection is being prepared to start a handshake to a server, + * each supported extension is checked with protocols[0] callback + * with this reason, giving the user code a chance to suppress the + * claim to support that extension by returning non-zero. If + * unhandled, by default 0 will be returned and the extension + * support included in the header to the server. Notice this + * callback comes to protocols[0]. + * + * LWS_CALLBACK_PROTOCOL_INIT: One-time call per protocol so it can + * do initial setup / allocations etc + * + * LWS_CALLBACK_PROTOCOL_DESTROY: One-time call per protocol indicating + * this protocol won't get used at all after this callback, the + * context is getting destroyed. Take the opportunity to + * deallocate everything that was allocated by the protocol. + * + * The next four reasons are optional and only need taking care of if you + * will be integrating libwebsockets sockets into an external polling + * array. + * + * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop + * internally, but in the case you are integrating with another + * server you will need to have libwebsocket sockets share a + * polling array with the other server. This and the other + * POLL_FD related callbacks let you put your specialized + * poll array interface code in the callback for protocol 0, the + * first protocol you support, usually the HTTP protocol in the + * serving case. This callback happens when a socket needs to be + * added to the polling loop: @in contains the fd, and + * @len is the events bitmap (like, POLLIN). If you are using the + * internal polling loop (the "service" callback), you can just + * ignore these callbacks. + * + * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descriptor + * needs to be removed from an external polling array. @in is + * the socket desricptor. If you are using the internal polling + * loop, you can just ignore it. + * + * LWS_CALLBACK_SET_MODE_POLL_FD: This callback happens when libwebsockets + * wants to modify the events for the socket descriptor in @in. + * The handler should OR @len on to the events member of the pollfd + * struct for this socket descriptor. If you are using the + * internal polling loop, you can just ignore it. + * + * LWS_CALLBACK_CLEAR_MODE_POLL_FD: This callback occurs when libwebsockets + * wants to modify the events for the socket descriptor in @in. + * The handler should AND ~@len on to the events member of the + * pollfd struct for this socket descriptor. If you are using the + * internal polling loop, you can just ignore it. + */ +LWS_VISIBLE LWS_EXTERN int callback(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len); + +typedef int (callback_function)(struct libwebsocket_context *context, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len); + +#ifndef LWS_NO_EXTENSIONS +/** + * extension_callback_function() - Hooks to allow extensions to operate + * @context: Websockets context + * @ext: This extension + * @wsi: Opaque websocket instance pointer + * @reason: The reason for the call + * @user: Pointer to per-session user data allocated by library + * @in: Pointer used for some callback reasons + * @len: Length set for some callback reasons + * + * Each extension that is active on a particular connection receives + * callbacks during the connection lifetime to allow the extension to + * operate on websocket data and manage itself. + * + * Libwebsockets takes care of allocating and freeing "user" memory for + * each active extension on each connection. That is what is pointed to + * by the @user parameter. + * + * LWS_EXT_CALLBACK_CONSTRUCT: called when the server has decided to + * select this extension from the list provided by the client, + * just before the server will send back the handshake accepting + * the connection with this extension active. This gives the + * extension a chance to initialize its connection context found + * in @user. + * + * LWS_EXT_CALLBACK_CLIENT_CONSTRUCT: same as LWS_EXT_CALLBACK_CONSTRUCT + * but called when client is instantiating this extension. Some + * extensions will work the same on client and server side and then + * you can just merge handlers for both CONSTRUCTS. + * + * LWS_EXT_CALLBACK_DESTROY: called when the connection the extension was + * being used on is about to be closed and deallocated. It's the + * last chance for the extension to deallocate anything it has + * allocated in the user data (pointed to by @user) before the + * user data is deleted. This same callback is used whether you + * are in client or server instantiation context. + * + * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE: when this extension was active on + * a connection, and a packet of data arrived at the connection, + * it is passed to this callback to give the extension a chance to + * change the data, eg, decompress it. @user is pointing to the + * extension's private connection context data, @in is pointing + * to an lws_tokens struct, it consists of a char * pointer called + * token, and an int called token_len. At entry, these are + * set to point to the received buffer and set to the content + * length. If the extension will grow the content, it should use + * a new buffer allocated in its private user context data and + * set the pointed-to lws_tokens members to point to its buffer. + * + * LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as + * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the + * extension a chance to change websocket data just before it will + * be sent out. Using the same lws_token pointer scheme in @in, + * the extension can change the buffer and the length to be + * transmitted how it likes. Again if it wants to grow the + * buffer safely, it should copy the data into its own buffer and + * set the lws_tokens token pointer to it. + */ +LWS_VISIBLE LWS_EXTERN int extension_callback(struct libwebsocket_context *context, + struct libwebsocket_extension *ext, + struct libwebsocket *wsi, + enum libwebsocket_extension_callback_reasons reason, + void *user, void *in, size_t len); + +typedef int (extension_callback_function)(struct libwebsocket_context *context, + struct libwebsocket_extension *ext, + struct libwebsocket *wsi, + enum libwebsocket_extension_callback_reasons reason, + void *user, void *in, size_t len); +#endif + +/** + * struct libwebsocket_protocols - List of protocols and handlers server + * supports. + * @name: Protocol name that must match the one given in the client + * Javascript new WebSocket(url, 'protocol') name + * @callback: The service callback used for this protocol. It allows the + * service action for an entire protocol to be encapsulated in + * the protocol-specific callback + * @per_session_data_size: Each new connection using this protocol gets + * this much memory allocated on connection establishment and + * freed on connection takedown. A pointer to this per-connection + * allocation is passed into the callback in the 'user' parameter + * @rx_buffer_size: if you want atomic frames delivered to the callback, you + * should set this to the size of the biggest legal frame that + * you support. If the frame size is exceeded, there is no + * error, but the buffer will spill to the user callback when + * full, which you can detect by using + * libwebsockets_remaining_packet_payload(). Notice that you + * just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING + * and post-padding are automatically also allocated on top. + * @owning_server: the server init call fills in this opaque pointer when + * registering this protocol with the server. + * @protocol_index: which protocol we are starting from zero + * + * This structure represents one protocol supported by the server. An + * array of these structures is passed to libwebsocket_create_server() + * allows as many protocols as you like to be handled by one server. + */ + +struct libwebsocket_protocols { + const char *name; + callback_function *callback; + size_t per_session_data_size; + size_t rx_buffer_size; + + /* + * below are filled in on server init and can be left uninitialized, + * no need for user to use them directly either + */ + + struct libwebsocket_context *owning_server; + int protocol_index; +}; + +#ifndef LWS_NO_EXTENSIONS +/** + * struct libwebsocket_extension - An extension we know how to cope with + * + * @name: Formal extension name, eg, "deflate-stream" + * @callback: Service callback + * @per_session_data_size: Libwebsockets will auto-malloc this much + * memory for the use of the extension, a pointer + * to it comes in the @user callback parameter + * @per_context_private_data: Optional storage for this extension that + * is per-context, so it can track stuff across + * all sessions, etc, if it wants + */ + +struct libwebsocket_extension { + const char *name; + extension_callback_function *callback; + size_t per_session_data_size; + void *per_context_private_data; +}; +#endif + +/** + * struct lws_context_creation_info: parameters to create context with + * + * @port: Port to listen on... you can use 0 to suppress listening on + * any port, that's what you want if you are not running a + * websocket server at all but just using it as a client + * @iface: NULL to bind the listen socket to all interfaces, or the + * interface name, eg, "eth2" + * @protocols: Array of structures listing supported protocols and a protocol- + * specific callback for each one. The list is ended with an + * entry that has a NULL callback pointer. + * It's not const because we write the owning_server member + * @extensions: NULL or array of libwebsocket_extension structs listing the + * extensions this context supports. If you configured with + * --without-extensions, you should give NULL here. + * @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want + * to listen using SSL, set to the filepath to fetch the + * server cert from, otherwise NULL for unencrypted + * @ssl_private_key_filepath: filepath to private key if wanting SSL mode, + * else ignored + * @ssl_ca_filepath: CA certificate filepath or NULL + * @ssl_cipher_list: List of valid ciphers to use (eg, + * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" + * or you can leave it as NULL to get "DEFAULT" + * @gid: group id to change to after setting listen socket, or -1. + * @uid: user id to change to after setting listen socket, or -1. + * @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK + * @user: optional user pointer that can be recovered via the context + * pointer using libwebsocket_context_user + * @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout to + * all libwebsocket sockets, client or server + * @ka_probes: if ka_time was nonzero, after the timeout expires how many + * times to try to get a response from the peer before giving up + * and killing the connection + * @ka_interval: if ka_time was nonzero, how long to wait before each ka_probes + * attempt + */ + +struct lws_context_creation_info { + int port; + const char *iface; + struct libwebsocket_protocols *protocols; + struct libwebsocket_extension *extensions; + const char *ssl_cert_filepath; + const char *ssl_private_key_filepath; + const char *ssl_ca_filepath; + const char *ssl_cipher_list; + int gid; + int uid; + unsigned int options; + void *user; + int ka_time; + int ka_probes; + int ka_interval; + +}; + +LWS_VISIBLE LWS_EXTERN +void lws_set_log_level(int level, + void (*log_emit_function)(int level, const char *line)); + +LWS_VISIBLE LWS_EXTERN void +lwsl_emit_syslog(int level, const char *line); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket_context * +libwebsocket_create_context(struct lws_context_creation_info *info); + +LWS_VISIBLE LWS_EXTERN void +libwebsocket_context_destroy(struct libwebsocket_context *context); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service(struct libwebsocket_context *context, int timeout_ms); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_service_fd(struct libwebsocket_context *context, + struct pollfd *pollfd); + +LWS_VISIBLE LWS_EXTERN void * +libwebsocket_context_user(struct libwebsocket_context *context); + +/* + * IMPORTANT NOTICE! + * + * When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY) + * the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE + * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len). + * + * This allows us to add protocol info before and after the data, and send as + * one packet on the network without payload copying, for maximum efficiency. + * + * So for example you need this kind of code to use libwebsocket_write with a + * 128-byte payload + * + * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING]; + * + * // fill your part of the buffer... for example here it's all zeros + * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128); + * + * libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, + * LWS_WRITE_TEXT); + * + * When sending LWS_WRITE_HTTP, there is no protocol addition and you can just + * use the whole buffer without taking care of the above. + */ + +/* + * this is the frame nonce plus two header plus 8 length + * there's an additional two for mux extension per mux nesting level + * 2 byte prepend on close will already fit because control frames cannot use + * the big length style + */ + +#define LWS_SEND_BUFFER_PRE_PADDING (4 + 10 + (2 * MAX_MUX_RECURSION)) +#define LWS_SEND_BUFFER_POST_PADDING 4 + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len, + enum libwebsocket_write_protocol protocol); + +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file(struct libwebsocket_context *context, + struct libwebsocket *wsi, const char *file, + const char *content_type); +LWS_VISIBLE LWS_EXTERN int +libwebsockets_serve_http_file_fragment(struct libwebsocket_context *context, + struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN const struct libwebsocket_protocols * +libwebsockets_get_protocol(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable(struct libwebsocket_context *context, + struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_callback_on_writable_all_protocol( + const struct libwebsocket_protocols *protocol); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_get_socket_fd(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_is_final_fragment(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN unsigned char +libwebsocket_get_reserved_bits(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable); + +LWS_VISIBLE LWS_EXTERN void +libwebsocket_rx_flow_allow_all_protocol( + const struct libwebsocket_protocols *protocol); + +LWS_VISIBLE LWS_EXTERN size_t +libwebsockets_remaining_packet_payload(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one); + +LWS_VISIBLE LWS_EXTERN struct libwebsocket * +libwebsocket_client_connect_extended(struct libwebsocket_context *clients, + const char *address, + int port, + int ssl_connection, + const char *path, + const char *host, + const char *origin, + const char *protocol, + int ietf_version_or_minus_one, + void *userdata); + +LWS_VISIBLE LWS_EXTERN const char * +libwebsocket_canonical_hostname(struct libwebsocket_context *context); + + +LWS_VISIBLE LWS_EXTERN void +libwebsockets_get_peer_addresses(struct libwebsocket_context *context, + struct libwebsocket *wsi, int fd, char *name, int name_len, + char *rip, int rip_len); + +LWS_VISIBLE LWS_EXTERN int +libwebsockets_get_random(struct libwebsocket_context *context, + void *buf, int len); + +LWS_VISIBLE LWS_EXTERN int +lws_daemonize(const char *_lock_path); + +LWS_VISIBLE LWS_EXTERN int +lws_send_pipe_choked(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN int +lws_frame_is_binary(struct libwebsocket *wsi); + +LWS_VISIBLE LWS_EXTERN unsigned char * +libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_encode_string(const char *in, int in_len, char *out, int out_size); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_decode_string(const char *in, char *out, int out_size); + +LWS_VISIBLE LWS_EXTERN const char * +lws_get_library_version(void); + +/* access to headers... only valid while headers valid */ + +LWS_VISIBLE LWS_EXTERN int +lws_hdr_total_length(struct libwebsocket *wsi, enum lws_token_indexes h); + +LWS_VISIBLE LWS_EXTERN int +lws_hdr_copy(struct libwebsocket *wsi, char *dest, int len, + enum lws_token_indexes h); + +/* + * Note: this is not normally needed as a user api. It's provided in case it is + * useful when integrating with other app poll loop service code. + */ + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_read(struct libwebsocket_context *context, + struct libwebsocket *wsi, + unsigned char *buf, size_t len); + +#ifndef LWS_NO_EXTENSIONS +LWS_VISIBLE LWS_EXTERN struct libwebsocket_extension *libwebsocket_get_internal_extensions(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/external/libwebsockets/win32/include/win32helpers/gettimeofday.h b/external/libwebsockets/win32/include/win32helpers/gettimeofday.h new file mode 100644 index 0000000000..223ceeed8b --- /dev/null +++ b/external/libwebsockets/win32/include/win32helpers/gettimeofday.h @@ -0,0 +1,28 @@ +#ifndef _GET_TIME_OF_DAY_H +#define _GET_TIME_OF_DAY_H + +#ifdef __MINGW64__ +#else +#ifdef __MINGW32__ +#else +#include < time.h > +#endif +#endif + +#include //I've ommited context line. +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) + #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#else + #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#endif + +struct timezone +{ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +int gettimeofday(struct timeval *tv, struct timezone *tz); + + +#endif diff --git a/external/libwebsockets/win32/include/win32helpers/websock-w32.h b/external/libwebsockets/win32/include/win32helpers/websock-w32.h new file mode 100644 index 0000000000..72a4f5c6b6 --- /dev/null +++ b/external/libwebsockets/win32/include/win32helpers/websock-w32.h @@ -0,0 +1,62 @@ +#ifndef __WEB_SOCK_W32_H__ +#define __WEB_SOCK_W32_H__ + +// Windows uses _DEBUG and NDEBUG +#ifdef _DEBUG +#undef DEBUG +#define DEBUG 1 +#endif + +#pragma warning(disable : 4996) + +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) + +#define MSG_NOSIGNAL 0 +#define SHUT_RDWR SD_BOTH + +#define SOL_TCP IPPROTO_TCP + +#define random rand +#define usleep _sleep + +#ifdef __MINGW64__ +#define DEF_POLL_STUFF +#endif +#ifdef __MINGW32__ +#define DEF_POLL_STUFF +#endif + +#ifdef DEF_POLL_STUFF + +#include + +typedef struct pollfd { + SOCKET fd; + short events; + short revents; +} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD; + +#define POLLIN 0x0001 /* any readable data available */ +#define POLLOUT 0x0004 /* file descriptor is writeable */ +#define POLLERR 0x0008 /* some poll error occurred */ +#define POLLHUP 0x0010 /* file descriptor was "hung up" */ +#define POLLNVAL 0x0020 /* requested events "invalid" */ + +#endif + +typedef INT (WSAAPI *PFNWSAPOLL)(LPWSAPOLLFD fdarray, ULONG nfds, INT timeout); +extern PFNWSAPOLL poll; + +extern INT WSAAPI emulated_poll(LPWSAPOLLFD fdarray, ULONG nfds, INT timeout); + +/* override configure because we are not using Makefiles */ + +#define LWS_NO_FORK + +/* windows can't cope with this idea, needs assets in cwd */ + +#ifndef INSTALL_DATADIR +#define INSTALL_DATADIR "." +#endif + +#endif diff --git a/licenses/LICENSE_libwebsockets.txt b/licenses/LICENSE_libwebsockets.txt new file mode 100644 index 0000000000..7c8986558c --- /dev/null +++ b/licenses/LICENSE_libwebsockets.txt @@ -0,0 +1,526 @@ +Libwebsockets and included programs are provided under the terms of the GNU +Library General Public License (LGPL) 2.1, with the following exceptions: + +1) Static linking of programs with the libwebsockets library does not +constitute a derivative work and does not require the author to provide +source code for the program, use the shared libwebsockets libraries, or +link their program against a user-supplied version of libwebsockets. + +If you link the program to a modified version of libwebsockets, then the +changes to libwebsockets must be provided under the terms of the LGPL in +sections 1, 2, and 4. + +2) You do not have to provide a copy of the libwebsockets license with +programs that are linked to the libwebsockets library, nor do you have to +identify the libwebsockets license in your program or documentation as +required by section 6 of the LGPL. + +However, programs must still identify their use of libwebsockets. The +following example statement can be included in user documentation to +satisfy this requirement: + +"[program] is based in part on the work of the libwebsockets project +(http://libwebsockets.org)" + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index eb24e345da..8a64ef5a18 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -55,6 +55,7 @@ Classes/ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.cpp \ Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp \ Classes/ExtensionsTest/CocosBuilderTest/TimelineCallbackTest/TimelineCallbackTestLayer.cpp \ Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \ +Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp \ Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp \ Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp \ Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.cpp \ diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp index cefd147aaf..f1c3003bf3 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp @@ -8,6 +8,10 @@ #endif #include "TableViewTest/TableViewTestScene.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#include "NetworkTest/WebSocketTest.h" +#endif + #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) #include "EditBoxTest/EditBoxTest.h" #endif @@ -24,6 +28,9 @@ enum TEST_CCCONTROLBUTTON, TEST_COCOSBUILDER, TEST_HTTPCLIENT, +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + TEST_WEBSOCKET, +#endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) TEST_EDITBOX, #endif @@ -39,6 +46,9 @@ static const std::string testsName[TEST_MAX_COUNT] = #if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN) "HttpClientTest", #endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + "WebSocketTest", +#endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) "EditBoxTest", #endif @@ -109,6 +119,13 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender) } break; #endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + case TEST_WEBSOCKET: + { + runWebSocketTest(); + } + break; +#endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) case TEST_EDITBOX: { diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp new file mode 100644 index 0000000000..a06681e71a --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp @@ -0,0 +1,241 @@ +// +// WebSocketTest.cpp +// TestCpp +// +// Created by James Chen on 5/31/13. +// +// + +#include "WebSocketTest.h" +#include "../ExtensionsTest.h" + +USING_NS_CC; +USING_NS_CC_EXT; + +WebSocketTestLayer::WebSocketTestLayer() +: _wsiSendText(NULL) +, _wsiSendBinary(NULL) +, _wsiError(NULL) +, _sendTextStatus(NULL) +, _sendBinaryStatus(NULL) +, _errorStatus(NULL) +, _sendTextTimes(0) +, _sendBinaryTimes(0) +{ + CCSize winSize = CCDirector::sharedDirector()->getWinSize(); + + const int MARGIN = 40; + const int SPACE = 35; + + CCLabelTTF *label = CCLabelTTF::create("WebSocket Test", "Arial", 28); + label->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN)); + addChild(label, 0); + + CCMenu *menuRequest = CCMenu::create(); + menuRequest->setPosition(CCPointZero); + addChild(menuRequest); + + // Send Text + CCLabelTTF *labelSendText = CCLabelTTF::create("Send Text", "Arial", 22); + CCMenuItemLabel *itemSendText = CCMenuItemLabel::create(labelSendText, this, menu_selector(WebSocketTestLayer::onMenuSendTextClicked)); + itemSendText->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - SPACE)); + menuRequest->addChild(itemSendText); + + // Send Binary + CCLabelTTF *labelSendBinary = CCLabelTTF::create("Send Binary", "Arial", 22); + CCMenuItemLabel *itemSendBinary = CCMenuItemLabel::create(labelSendBinary, this, menu_selector(WebSocketTestLayer::onMenuSendBinaryClicked)); + itemSendBinary->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 2 * SPACE)); + menuRequest->addChild(itemSendBinary); + + + // Send Text Status Label + _sendTextStatus = CCLabelTTF::create("Send Text WS is waiting...", "Arial", 14, CCSizeMake(160, 100), kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop); + _sendTextStatus->setAnchorPoint(ccp(0, 0)); + _sendTextStatus->setPosition(ccp(VisibleRect::left().x, VisibleRect::rightBottom().y + 25)); + this->addChild(_sendTextStatus); + + // Send Binary Status Label + _sendBinaryStatus = CCLabelTTF::create("Send Binary WS is waiting...", "Arial", 14, CCSizeMake(160, 100), kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop); + _sendBinaryStatus->setAnchorPoint(ccp(0, 0)); + _sendBinaryStatus->setPosition(ccp(VisibleRect::left().x + 160, VisibleRect::rightBottom().y + 25)); + this->addChild(_sendBinaryStatus); + + // Error Label + _errorStatus = CCLabelTTF::create("Error WS is waiting...", "Arial", 14, CCSizeMake(160, 100), kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop); + _errorStatus->setAnchorPoint(ccp(0, 0)); + _errorStatus->setPosition(ccp(VisibleRect::left().x + 320, VisibleRect::rightBottom().y + 25)); + this->addChild(_errorStatus); + + // Back Menu + CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(WebSocketTestLayer::toExtensionsMainLayer)); + itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); + CCMenu *menuBack = CCMenu::create(itemBack, NULL); + menuBack->setPosition(CCPointZero); + addChild(menuBack); + + _wsiSendText = new WebSocket(); + _wsiSendBinary = new WebSocket(); + _wsiError = new WebSocket(); + + if (!_wsiSendText->init(*this, "ws://echo.websocket.org")) + { + CC_SAFE_DELETE(_wsiSendText); + } + + if (!_wsiSendBinary->init(*this, "ws://echo.websocket.org")) + { + CC_SAFE_DELETE(_wsiSendBinary); + } + + if (!_wsiError->init(*this, "ws://invalid.url.com")) + { + CC_SAFE_DELETE(_wsiError); + } +} + + +WebSocketTestLayer::~WebSocketTestLayer() +{ + if (_wsiSendText) + _wsiSendText->close(); + + if (_wsiSendBinary) + _wsiSendBinary->close(); + + if (_wsiError) + _wsiError->close(); +} + +// Delegate methods +void WebSocketTestLayer::onOpen(cocos2d::extension::WebSocket* ws) +{ + CCLog("Websocket (%p) opened", ws); + if (ws == _wsiSendText) + { + _sendTextStatus->setString("Send Text WS was opened."); + } + else if (ws == _wsiSendBinary) + { + _sendBinaryStatus->setString("Send Binary WS was opened."); + } + else if (ws == _wsiError) + { + CCAssert(0, "error test will never go here."); + } +} + +void WebSocketTestLayer::onMessage(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::Data& data) +{ + if (!data.isBinary) + { + _sendTextTimes++; + char times[100] = {0}; + sprintf(times, "%d", _sendTextTimes); + std::string textStr = std::string("response text msg: ")+data.bytes+", "+times; + CCLog("%s", textStr.c_str()); + + _sendTextStatus->setString(textStr.c_str()); + } + else + { + _sendBinaryTimes++; + char times[100] = {0}; + sprintf(times, "%d", _sendBinaryTimes); + + std::string binaryStr = "response bin msg: "; + + for (int i = 0; i < data.len; ++i) { + if (data.bytes[i] != '\0') + { + binaryStr += data.bytes[i]; + } + else + { + binaryStr += "\'\\0\'"; + } + } + + binaryStr += std::string(", ")+times; + CCLog("%s", binaryStr.c_str()); + _sendBinaryStatus->setString(binaryStr.c_str()); + } +} + +void WebSocketTestLayer::onClose(cocos2d::extension::WebSocket* ws) +{ + CCLog("websocket instance (%p) closed.", ws); + if (ws == _wsiSendText) + { + _wsiSendText = NULL; + } + else if (ws == _wsiSendBinary) + { + _wsiSendBinary = NULL; + } + else if (ws == _wsiError) + { + _wsiError = NULL; + } + // Delete websocket instance. + CC_SAFE_DELETE(ws); +} + +void WebSocketTestLayer::onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::WS_ERROR& error) +{ + CCLog("Error was fired, error code: %d", error); + if (ws == _wsiError) + { + char buf[100] = {0}; + sprintf(buf, "an error was fired, code: %d", error); + _errorStatus->setString(buf); + } +} + +void WebSocketTestLayer::toExtensionsMainLayer(cocos2d::CCObject *sender) +{ + ExtensionsTestScene *pScene = new ExtensionsTestScene(); + pScene->runThisTest(); + pScene->release(); +} + +// Menu Callbacks +void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::CCObject *sender) +{ + if (_wsiSendText->getReadyState() == WebSocket::WS_STATE_OPEN) + { + _sendTextStatus->setString("Send Text WS is waiting..."); + _wsiSendText->send("Hello WebSocket, I'm a text message."); + } + else + { + std::string warningStr = "send text websocket instance wasn't ready..."; + CCLog("%s", warningStr.c_str()); + _sendTextStatus->setString(warningStr.c_str()); + } +} + +void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::CCObject *sender) +{ + if (_wsiSendBinary->getReadyState() == WebSocket::WS_STATE_OPEN) + { + _sendBinaryStatus->setString("Send Binary WS is waiting..."); + char buf[] = "Hello WebSocket,\0 I'm\0 a\0 binary\0 message\0."; + _wsiSendBinary->send((unsigned char*)buf, sizeof(buf)); + } + else + { + std::string warningStr = "send binary websocket instance wasn't ready..."; + CCLog("%s", warningStr.c_str()); + _sendBinaryStatus->setString(warningStr.c_str()); + } +} + +void runWebSocketTest() +{ + CCScene *pScene = CCScene::create(); + WebSocketTestLayer *pLayer = new WebSocketTestLayer(); + pScene->addChild(pLayer); + + CCDirector::sharedDirector()->replaceScene(pScene); + pLayer->release(); +} diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h new file mode 100644 index 0000000000..1070ce750a --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h @@ -0,0 +1,50 @@ +// +// WebSocketTest.h +// TestCpp +// +// Created by James Chen on 5/31/13. +// +// + +#ifndef __TestCpp__WebSocketTest__ +#define __TestCpp__WebSocketTest__ + +#include "cocos2d.h" +#include "cocos-ext.h" +#include "WebSocket.h" + +class WebSocketTestLayer +: public cocos2d::CCLayer +, public cocos2d::extension::WebSocket::Delegate +{ +public: + WebSocketTestLayer(); + virtual ~WebSocketTestLayer(); + + virtual void onOpen(cocos2d::extension::WebSocket* ws); + virtual void onMessage(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::Data& data); + virtual void onClose(cocos2d::extension::WebSocket* ws); + virtual void onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::WS_ERROR& error); + + void toExtensionsMainLayer(cocos2d::CCObject *sender); + + // Menu Callbacks + void onMenuSendTextClicked(cocos2d::CCObject *sender); + void onMenuSendBinaryClicked(cocos2d::CCObject *sender); + +private: + cocos2d::extension::WebSocket* _wsiSendText; + cocos2d::extension::WebSocket* _wsiSendBinary; + cocos2d::extension::WebSocket* _wsiError; + + cocos2d::CCLabelTTF* _sendTextStatus; + cocos2d::CCLabelTTF* _sendBinaryStatus; + cocos2d::CCLabelTTF* _errorStatus; + + int _sendTextTimes; + int _sendBinaryTimes; +}; + +void runWebSocketTest(); + +#endif /* defined(__TestCpp__WebSocketTest__) */ diff --git a/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id index 340e0d6e96..4ae6853675 100644 --- a/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -55285e0eccaf3807a3e3f232f528c2a4ff80a6be \ No newline at end of file +b95526a387e924fd628b7408ad3b7da4814a1f11 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index 11594b910a..e080de91cb 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -65,7 +65,7 @@ Disabled - $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\external;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\..\extensions;..\Classes;..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\..\external;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\extensions\network;..\Classes;..;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -77,7 +77,7 @@ 4267;4251;4244;%(DisableSpecificWarnings) - libExtensions.lib;libcocos2d.lib;libCocosDenshion.lib;opengl32.lib;glew32.lib;libBox2d.lib;libchipmunk.lib;libcurl_imp.lib;pthreadVCE2.lib;%(AdditionalDependencies) + libExtensions.lib;libcocos2d.lib;libCocosDenshion.lib;opengl32.lib;glew32.lib;libBox2d.lib;libchipmunk.lib;libcurl_imp.lib;websockets.lib;pthreadVCE2.lib;%(AdditionalDependencies) $(OutDir)$(ProjectName).exe $(OutDir);%(AdditionalLibraryDirectories) true @@ -93,7 +93,7 @@ MaxSpeed true - $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\external;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\..\extensions;..\Classes;..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\..\external;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\extensions\network;..\Classes;..;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -104,7 +104,7 @@ 4267;4251;4244;%(DisableSpecificWarnings) - libcocos2d.lib;libCocosDenshion.lib;opengl32.lib;glew32.lib;libBox2d.lib;libchipmunk.lib;libcurl_imp.lib;libExtensions.lib;pthreadVCE2.lib;%(AdditionalDependencies) + libExtensions.lib;libcocos2d.lib;libCocosDenshion.lib;opengl32.lib;glew32.lib;libBox2d.lib;libchipmunk.lib;libcurl_imp.lib;websockets.lib;pthreadVCE2.lib;%(AdditionalDependencies) $(OutDir)$(ProjectName).exe $(OutDir);%(AdditionalLibraryDirectories) true @@ -129,6 +129,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index 5af8f8f44f..68a799d585 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -510,6 +510,9 @@ Classes\ConfigurationTest + + Classes\ExtensionsTest\NetworkTest + @@ -974,5 +977,8 @@ Classes\ConfigurationTest + + Classes\ExtensionsTest\NetworkTest + \ No newline at end of file diff --git a/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp b/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp index fb3c8521e7..1724dadf42 100644 --- a/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp +++ b/samples/Javascript/TestJavascript/Classes/AppDelegate.cpp @@ -11,8 +11,10 @@ #include "js_bindings_system_registration.h" #include "jsb_opengl_registration.h" #include "XMLHTTPRequest.h" +#include "jsb_websocket.h" USING_NS_CC; +USING_NS_CC_EXT; using namespace CocosDenshion; AppDelegate::AppDelegate() @@ -45,6 +47,7 @@ bool AppDelegate::applicationDidFinishLaunching() sc->addRegisterCallback(JSB_register_opengl); sc->addRegisterCallback(jsb_register_system); sc->addRegisterCallback(MinXmlHttpRequest::_js_register); + sc->addRegisterCallback(register_jsb_websocket); sc->start(); diff --git a/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id index 4112c1477e..9090e64bd0 100644 --- a/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/Javascript/TestJavascript/proj.ios/TestJavascript.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -3562e7408ca15bab5add211b185257205a8a5d10 \ No newline at end of file +11063b9c336ce93557a2d4bbd383ee729825b91f \ No newline at end of file diff --git a/scripting/javascript/bindings/Android.mk b/scripting/javascript/bindings/Android.mk index 08ebbdfd1a..cff6760a99 100644 --- a/scripting/javascript/bindings/Android.mk +++ b/scripting/javascript/bindings/Android.mk @@ -25,7 +25,8 @@ LOCAL_SRC_FILES := ScriptingCore.cpp \ jsb_opengl_registration.cpp \ generated/jsb_cocos2dx_auto.cpp \ generated/jsb_cocos2dx_extension_auto.cpp \ - XMLHTTPRequest.cpp + XMLHTTPRequest.cpp \ + jsb_websocket.cpp LOCAL_CFLAGS := -DCOCOS2D_JAVASCRIPT diff --git a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj index 99dcca009e..59164d2b19 100644 --- a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj +++ b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj @@ -19,6 +19,7 @@ + @@ -41,6 +42,7 @@ + @@ -125,7 +127,7 @@ Level3 Disabled WIN32;_WINDOWS;_DEBUG;_LIB;DEBUG;COCOS2D_DEBUG=1;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_JAVASCRIPT=1;CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) - $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..;$(ProjectDir)..\..\spidermonkey-win32\include;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\extensions\LocalStorage;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..;$(ProjectDir)..\..\spidermonkey-win32\include;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\extensions\LocalStorage;$(ProjectDir)..\..\..\..\extensions\network;%(AdditionalIncludeDirectories) 4068;4101;4800;4251;4996;4244;%(DisableSpecificWarnings) @@ -146,7 +148,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\sqlite3\libraries\win32\*.*" "$(O true true WIN32;_WINDOWS;NDEBUG;_LIB;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_JAVASCRIPT=1;CC_ENABLE_CHIPMUNK_INTEGRATION=1;%(PreprocessorDefinitions) - $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..;$(ProjectDir)..\..\spidermonkey-win32\include;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\extensions\LocalStorage;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\..\CocosDenshion\include;$(ProjectDir)..;$(ProjectDir)..\..\spidermonkey-win32\include;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\..\external\libwebsockets\win32\include;$(ProjectDir)..\..\..\..\extensions;$(ProjectDir)..\..\..\..\extensions\LocalStorage;$(ProjectDir)..\..\..\..\extensions\network;%(AdditionalIncludeDirectories) 4068;4101;4800;4251;4996;4244;%(DisableSpecificWarnings) diff --git a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters index 43a979dcc4..f49e00a20f 100644 --- a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters +++ b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters @@ -74,6 +74,9 @@ manual + + manual + @@ -154,6 +157,9 @@ manual + + manual + From 2218d70826bad76e87527367683b1b67c63e7e9c Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 31 May 2013 23:25:01 +0800 Subject: [PATCH 11/18] fixed #1647: Adding missing files. --- .../javascript/bindings/XMLHTTPRequest.h | 2 +- .../{XMLHTTPHelper.h => jsb_helper.h} | 0 .../javascript/bindings/jsb_websocket.cpp | 388 ++++++++++++++++++ scripting/javascript/bindings/jsb_websocket.h | 34 ++ 4 files changed, 423 insertions(+), 1 deletion(-) rename scripting/javascript/bindings/{XMLHTTPHelper.h => jsb_helper.h} (100%) create mode 100644 scripting/javascript/bindings/jsb_websocket.cpp create mode 100644 scripting/javascript/bindings/jsb_websocket.h diff --git a/scripting/javascript/bindings/XMLHTTPRequest.h b/scripting/javascript/bindings/XMLHTTPRequest.h index b70331866b..8994da9cdb 100644 --- a/scripting/javascript/bindings/XMLHTTPRequest.h +++ b/scripting/javascript/bindings/XMLHTTPRequest.h @@ -35,7 +35,7 @@ #include "jstypes.h" #include "jsapi.h" #include "jsfriendapi.h" -#include "XMLHTTPHelper.h" +#include "jsb_helper.h" enum MinXmlHttpRequestResponseType { kRequestResponseTypeString, diff --git a/scripting/javascript/bindings/XMLHTTPHelper.h b/scripting/javascript/bindings/jsb_helper.h similarity index 100% rename from scripting/javascript/bindings/XMLHTTPHelper.h rename to scripting/javascript/bindings/jsb_helper.h diff --git a/scripting/javascript/bindings/jsb_websocket.cpp b/scripting/javascript/bindings/jsb_websocket.cpp new file mode 100644 index 0000000000..e346bba5cb --- /dev/null +++ b/scripting/javascript/bindings/jsb_websocket.cpp @@ -0,0 +1,388 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org +Copyright (c) 2013 James Chen + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "jsb_websocket.h" +#include "cocos2d.h" +#include "Websocket.h" +#include "spidermonkey_specifics.h" +#include "ScriptingCore.h" +#include "cocos2d_specifics.hpp" + +USING_NS_CC_EXT; + +/* + [Constructor(in DOMString url, in optional DOMString protocols)] + [Constructor(in DOMString url, in optional DOMString[] protocols)] + interface WebSocket { + readonly attribute DOMString url; + + // ready state + const unsigned short CONNECTING = 0; + const unsigned short OPEN = 1; + const unsigned short CLOSING = 2; + const unsigned short CLOSED = 3; + readonly attribute unsigned short readyState; + readonly attribute unsigned long bufferedAmount; + + // networking + attribute Function onopen; + attribute Function onmessage; + attribute Function onerror; + attribute Function onclose; + readonly attribute DOMString protocol; + void send(in DOMString data); + void close(); + }; + WebSocket implements EventTarget; + */ + +class JSB_WebSocketDelegate : public WebSocket::Delegate +{ +public: + + virtual void onOpen(WebSocket* ws) + { + js_proxy_t * p; + JS_GET_PROXY(p, ws); + if (!p) return; + + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + jsval vp = c_string_to_jsval(cx, "open"); + JS_SetProperty(cx, jsobj, "type", &vp); + + jsval args = OBJECT_TO_JSVAL(jsobj); + + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(m_pJSDelegate), "onopen", 1, &args); + } + + virtual void onMessage(WebSocket* ws, const WebSocket::Data& data) + { + js_proxy_t * p; + JS_GET_PROXY(p, ws); + if (!p) return; + + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + jsval vp = c_string_to_jsval(cx, "message"); + JS_SetProperty(cx, jsobj, "type", &vp); + + jsval args = OBJECT_TO_JSVAL(jsobj); + + if (data.isBinary) + {// data is binary + JSObject* buffer = JS_NewArrayBuffer(cx, data.len); + uint8_t* bufdata = JS_GetArrayBufferData(buffer); + memcpy((void*)bufdata, (void*)data.bytes, data.len); + jsval dataVal = OBJECT_TO_JSVAL(buffer); + JS_SetProperty(cx, jsobj, "data", &dataVal); + } + else + {// data is string + jsval dataVal = c_string_to_jsval(cx, data.bytes); + JS_SetProperty(cx, jsobj, "data", &dataVal); + } + + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(m_pJSDelegate), "onmessage", 1, &args); + } + + virtual void onClose(WebSocket* ws) + { + js_proxy_t * p; + JS_GET_PROXY(p, ws); + if (!p) return; + + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + jsval vp = c_string_to_jsval(cx, "close"); + JS_SetProperty(cx, jsobj, "type", &vp); + + jsval args = OBJECT_TO_JSVAL(jsobj); + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(m_pJSDelegate), "onclose", 1, &args); + + js_proxy_t* jsproxy; + JS_GET_NATIVE_PROXY(jsproxy, p->obj); + JS_RemoveObjectRoot(cx, &jsproxy->obj); + JS_REMOVE_PROXY(p, jsproxy); + CC_SAFE_DELETE(ws); + } + + virtual void onError(WebSocket* ws, const WebSocket::WS_ERROR& error) + { + js_proxy_t * p; + JS_GET_PROXY(p, ws); + if (!p) return; + + JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); + JSObject* jsobj = JS_NewObject(cx, NULL, NULL, NULL); + jsval vp = c_string_to_jsval(cx, "error"); + JS_SetProperty(cx, jsobj, "type", &vp); + + jsval args = OBJECT_TO_JSVAL(jsobj); + + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(m_pJSDelegate), "onerror", 1, &args); + } + + void setJSDelegate(JSObject* pJSDelegate) + { + m_pJSDelegate = pJSDelegate; + } +private: + JSObject* m_pJSDelegate; +}; + +JSClass *js_cocos2dx_websocket_class; +JSObject *js_cocos2dx_websocket_prototype; + +void js_cocos2dx_WebSocket_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOG("jsbindings: finalizing JS object %p (WebSocket)", obj); +} + +JSBool js_cocos2dx_extension_WebSocket_send(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj); + WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object"); + + if(argc == 1){ + do + { + if (JSVAL_IS_STRING(argv[0])) + { + std::string data; + jsval_to_std_string(cx, argv[0], &data); + cobj->send(data); + break; + } + + if (argv[0].isObject()) + { + uint8_t *bufdata = NULL; + uint32_t len = 0; + + JSObject* jsobj = JSVAL_TO_OBJECT(argv[0]); + if (JS_IsArrayBufferObject(jsobj)) + { + bufdata = JS_GetArrayBufferData(jsobj); + len = JS_GetArrayBufferByteLength(jsobj); + } + else if (JS_IsArrayBufferViewObject(jsobj)) + { + bufdata = (uint8_t*)JS_GetArrayBufferViewData(jsobj); + len = JS_GetArrayBufferViewByteLength(jsobj); + } + + if (bufdata && len > 0) + { + cobj->send(bufdata, len); + break; + } + } + + JS_ReportError(cx, "data type to be sent is unsupported."); + + } while (0); + + JS_SET_RVAL(cx, vp, JSVAL_VOID); + + return JS_TRUE; + } + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); + return JS_TRUE; +} + +JSBool js_cocos2dx_extension_WebSocket_close(JSContext *cx, uint32_t argc, jsval *vp){ + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj); + WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object"); + + if(argc == 0){ + cobj->close(); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return JS_TRUE; + } + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); + return JS_FALSE; +} + +JSBool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + + if (argc == 1 || argc == 2) + { + + std::string url; + + do { + JSBool ok = jsval_to_std_string(cx, argv[0], &url); + JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments"); + } while (0); + + JSObject *obj = JS_NewObject(cx, js_cocos2dx_websocket_class, js_cocos2dx_websocket_prototype, NULL); + + + cocos2d::extension::WebSocket* cobj = new cocos2d::extension::WebSocket(); + JSB_WebSocketDelegate* delegate = new JSB_WebSocketDelegate(); + delegate->setJSDelegate(obj); + + if (argc == 2) + { + std::vector protocols; + + if (JSVAL_IS_STRING(argv[1])) + { + std::string protocol; + do { + JSBool ok = jsval_to_std_string(cx, argv[1], &protocol); + JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments"); + } while (0); + protocols.push_back(protocol); + } + else if (argv[1].isObject()) + { + JSBool ok = JS_TRUE; + JSObject* arg2 = JSVAL_TO_OBJECT(argv[1]); + JSB_PRECONDITION(JS_IsArrayObject( cx, arg2 ), "Object must be an array"); + + uint32_t len = 0; + JS_GetArrayLength(cx, arg2, &len); + + for( uint32_t i=0; i< len;i++ ) + { + jsval valarg; + JS_GetElement(cx, arg2, i, &valarg); + std::string protocol; + do { + ok = jsval_to_std_string(cx, valarg, &protocol); + JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error processing arguments"); + } while (0); + + protocols.push_back(protocol); + } + } + cobj->init(*delegate, url, &protocols); + } + else + { + cobj->init(*delegate, url); + } + + + JS_DefineProperty(cx, obj, "URL", argv[0] + , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + + //protocol not support yet (always return "") + JS_DefineProperty(cx, obj, "protocol", c_string_to_jsval(cx, "") + , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + + // link the native object with the javascript object + js_proxy_t *p; + JS_NEW_PROXY(p, cobj, obj); + JS_AddNamedObjectRoot(cx, &p->obj, "WebSocket"); + + JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); + return JS_TRUE; + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); + return JS_FALSE; +} + +static JSBool js_cocos2dx_extension_WebSocket_get_readyState(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) +{ + JSObject* jsobj = obj.get(); + js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, jsobj); + WebSocket* cobj = (WebSocket *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object"); + + if (cobj) { + vp.set(INT_TO_JSVAL((int)cobj->getReadyState())); + return JS_TRUE; + } else { + JS_ReportError(cx, "Error: WebSocket instance is invalid."); + return JS_FALSE; + } +} + +void register_jsb_websocket(JSContext *cx, JSObject *global) { + + js_cocos2dx_websocket_class = (JSClass *)calloc(1, sizeof(JSClass)); + js_cocos2dx_websocket_class->name = "WebSocket"; + js_cocos2dx_websocket_class->addProperty = JS_PropertyStub; + js_cocos2dx_websocket_class->delProperty = JS_PropertyStub; + js_cocos2dx_websocket_class->getProperty = JS_PropertyStub; + js_cocos2dx_websocket_class->setProperty = JS_StrictPropertyStub; + js_cocos2dx_websocket_class->enumerate = JS_EnumerateStub; + js_cocos2dx_websocket_class->resolve = JS_ResolveStub; + js_cocos2dx_websocket_class->convert = JS_ConvertStub; + js_cocos2dx_websocket_class->finalize = js_cocos2dx_WebSocket_finalize; + js_cocos2dx_websocket_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + {"readyState", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_SHARED, JSOP_WRAPPER(js_cocos2dx_extension_WebSocket_get_readyState), NULL}, + {0, 0, 0, 0, 0} + }; + + static JSFunctionSpec funcs[] = { + JS_FN("send",js_cocos2dx_extension_WebSocket_send, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("close",js_cocos2dx_extension_WebSocket_close, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FS_END + }; + + js_cocos2dx_websocket_prototype = JS_InitClass( + cx, global, + NULL, + js_cocos2dx_websocket_class, + js_cocos2dx_extension_WebSocket_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + + JSObject* jsclassObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return WebSocket; })()")); + + JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::WS_STATE_CONNECTING) + , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::WS_STATE_OPEN) + , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::WS_STATE_CLOSING) + , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::WS_STATE_CLOSED) + , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); + + // make the class enumerable in the registered namespace + JSBool found; + JS_SetPropertyAttributes(cx, global, "WebSocket", JSPROP_ENUMERATE | JSPROP_READONLY, &found); +} + + diff --git a/scripting/javascript/bindings/jsb_websocket.h b/scripting/javascript/bindings/jsb_websocket.h new file mode 100644 index 0000000000..cde0f40b2e --- /dev/null +++ b/scripting/javascript/bindings/jsb_websocket.h @@ -0,0 +1,34 @@ +/**************************************************************************** +Copyright (c) 2013 cocos2d-x.org +Copyright (c) 2013 James Chen + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __jsb_websocket__ +#define __jsb_websocket__ + +#include "jsapi.h" +#include "jsfriendapi.h" + +void register_jsb_websocket(JSContext* cx, JSObject* global); + +#endif /* defined(__jsb_websocket__) */ From 68d0ebfec5784a1a8795ee27a6b8cd039866759d Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 31 May 2013 23:27:59 +0800 Subject: [PATCH 12/18] fixed #1647: Updating JS-test. --- samples/Javascript/Shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Javascript/Shared b/samples/Javascript/Shared index 91d853f5c7..3e05297014 160000 --- a/samples/Javascript/Shared +++ b/samples/Javascript/Shared @@ -1 +1 @@ -Subproject commit 91d853f5c72df3137e2f3eb68229b426a3252e5d +Subproject commit 3e05297014a89a01218e15ad18d5ebdf75b0b7b4 From 85d2ccbf65d6c1a68db5e8e95f92ba766fa6690e Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 1 Jun 2013 07:58:23 +0800 Subject: [PATCH 13/18] issue # 1647: Fix include, 'Websocket.h' -> 'WebSocket.h' since linux is case sensitive. --- scripting/javascript/bindings/jsb_websocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/javascript/bindings/jsb_websocket.cpp b/scripting/javascript/bindings/jsb_websocket.cpp index e346bba5cb..5768be58eb 100644 --- a/scripting/javascript/bindings/jsb_websocket.cpp +++ b/scripting/javascript/bindings/jsb_websocket.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. #include "jsb_websocket.h" #include "cocos2d.h" -#include "Websocket.h" +#include "WebSocket.h" #include "spidermonkey_specifics.h" #include "ScriptingCore.h" #include "cocos2d_specifics.hpp" From 4b8f76c90305ff62ca98634b34c9fd0a1ce864a1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 1 Jun 2013 19:51:10 +0800 Subject: [PATCH 14/18] WS_ERROR -> ERROR, WS_STATE -> STATE. --- extensions/network/WebSocket.cpp | 34 +++++++++---------- extensions/network/WebSocket.h | 24 ++++++------- .../NetworkTest/WebSocketTest.cpp | 6 ++-- .../NetworkTest/WebSocketTest.h | 2 +- .../javascript/bindings/jsb_websocket.cpp | 10 +++--- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/extensions/network/WebSocket.cpp b/extensions/network/WebSocket.cpp index 844fd9ed99..a2a2516620 100644 --- a/extensions/network/WebSocket.cpp +++ b/extensions/network/WebSocket.cpp @@ -225,7 +225,7 @@ enum WS_MSG { }; WebSocket::WebSocket() -: _readyState(WS_STATE_CONNECTING) +: _readyState(STATE_CONNECTING) , _port(80) , _wsHelper(NULL) , _wsInstance(NULL) @@ -335,7 +335,7 @@ bool WebSocket::init(const Delegate& delegate, void WebSocket::send(const std::string& message) { - if (_readyState == WS_STATE_OPEN) + if (_readyState == STATE_OPEN) { // In main thread WsMessage* msg = new WsMessage(); @@ -353,7 +353,7 @@ void WebSocket::send(const unsigned char* binaryMsg, unsigned int len) { CCAssert(binaryMsg != NULL && len > 0, "parameter invalid."); - if (_readyState == WS_STATE_OPEN) + if (_readyState == STATE_OPEN) { // In main thread WsMessage* msg = new WsMessage(); @@ -371,11 +371,11 @@ void WebSocket::close() { CCDirector::sharedDirector()->getScheduler()->unscheduleAllForTarget(_wsHelper); - if (_readyState == WS_STATE_CLOSING || _readyState == WS_STATE_CLOSED) + if (_readyState == STATE_CLOSING || _readyState == STATE_CLOSED) return; CCLOG("websocket (%p) connection closed by client", this); - _readyState = WS_STATE_CLOSED; + _readyState = STATE_CLOSED; WsMessage* msg = new WsMessage(); msg->what = WS_MSG_TO_SUBTRHEAD_CLOSING; @@ -388,21 +388,21 @@ void WebSocket::close() _delegate->onClose(this); } -WebSocket::WS_STATE WebSocket::getReadyState() +WebSocket::STATE WebSocket::getReadyState() { return _readyState; } int WebSocket::onSubThreadLoop() { - if (_readyState == WS_STATE_CLOSED || _readyState == WS_STATE_CLOSING) + if (_readyState == STATE_CLOSED || _readyState == STATE_CLOSING) { libwebsocket_context_destroy(_wsContext); // return 1 to exit the loop. return 1; } - if (_wsContext && _readyState != WS_STATE_CLOSED && _readyState != WS_STATE_CLOSING) + if (_wsContext && _readyState != STATE_CLOSED && _readyState != STATE_CLOSING) { libwebsocket_service(_wsContext, 0); } @@ -442,7 +442,7 @@ void WebSocket::onSubThreadStarted() _wsContext = libwebsocket_create_context(&info); if(NULL != _wsContext){ - _readyState = WS_STATE_CONNECTING; + _readyState = STATE_CONNECTING; std::string name; for (int i = 0; _wsProtocols[i].callback != NULL; ++i) { name += (_wsProtocols[i].name); @@ -480,14 +480,14 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, { WsMessage* msg = new WsMessage(); if (reason == LWS_CALLBACK_CLIENT_CONNECTION_ERROR - || (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == WS_STATE_CONNECTING) - || (reason == LWS_CALLBACK_DEL_POLL_FD && _readyState == WS_STATE_CONNECTING) + || (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == STATE_CONNECTING) + || (reason == LWS_CALLBACK_DEL_POLL_FD && _readyState == STATE_CONNECTING) ) { msg->what = WS_MSG_TO_UITHREAD_ERROR; - _readyState = WS_STATE_CLOSING; + _readyState = STATE_CLOSING; } - else if (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == WS_STATE_CLOSING) + else if (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == STATE_CLOSING) { msg->what = WS_MSG_TO_UITHREAD_CLOSE; } @@ -498,7 +498,7 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, { WsMessage* msg = new WsMessage(); msg->what = WS_MSG_TO_UITHREAD_OPEN; - _readyState = WS_STATE_OPEN; + _readyState = STATE_OPEN; /* * start the ball rolling, * LWS_CALLBACK_CLIENT_WRITEABLE will come next service @@ -572,10 +572,10 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, _wsHelper->quitSubThread(); - if (_readyState != WS_STATE_CLOSED) + if (_readyState != STATE_CLOSED) { WsMessage* msg = new WsMessage(); - _readyState = WS_STATE_CLOSED; + _readyState = STATE_CLOSED; msg->what = WS_MSG_TO_UITHREAD_CLOSE; _wsHelper->sendMessageToUIThread(msg); } @@ -646,7 +646,7 @@ void WebSocket::onUIThreadReceiveMessage(WsMessage* msg) break; case WS_MSG_TO_UITHREAD_ERROR: { - WebSocket::WS_ERROR err = WS_ERROR_CONNECTION_FAILS; + WebSocket::ERROR err = ERROR_CONNECTION_FAILS; _delegate->onError(this, err); } break; diff --git a/extensions/network/WebSocket.h b/extensions/network/WebSocket.h index 021e4e4395..f7698fff60 100644 --- a/extensions/network/WebSocket.h +++ b/extensions/network/WebSocket.h @@ -57,11 +57,11 @@ public: /** * @brief Errors in websocket */ - enum WS_ERROR + enum ERROR { - WS_ERROR_TIMEOUT=0, - WS_ERROR_CONNECTION_FAILS, - WS_ERROR_UNKNOWN + ERROR_TIMEOUT = 0, + ERROR_CONNECTION_FAILS, + ERROR_UNKNOWN }; /** @@ -74,7 +74,7 @@ public: virtual void onOpen(WebSocket* ws) = 0; virtual void onMessage(WebSocket* ws, const Data& data) = 0; virtual void onClose(WebSocket* ws) = 0; - virtual void onError(WebSocket* ws, const WS_ERROR& error) = 0; + virtual void onError(WebSocket* ws, const ERROR& error) = 0; }; @@ -107,18 +107,18 @@ public: /** * Websocket state */ - enum WS_STATE + enum STATE { - WS_STATE_CONNECTING = 0, - WS_STATE_OPEN, - WS_STATE_CLOSING, - WS_STATE_CLOSED + STATE_CONNECTING = 0, + STATE_OPEN, + STATE_CLOSING, + STATE_CLOSED }; /** * @brief Gets current state of connection. */ - WS_STATE getReadyState(); + STATE getReadyState(); private: virtual void onSubThreadStarted(); @@ -134,7 +134,7 @@ private: void *user, void *in, size_t len); private: - WS_STATE _readyState; + STATE _readyState; std::string _host; unsigned int _port; std::string _path; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp index a06681e71a..e80a0a8dae 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp @@ -180,7 +180,7 @@ void WebSocketTestLayer::onClose(cocos2d::extension::WebSocket* ws) CC_SAFE_DELETE(ws); } -void WebSocketTestLayer::onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::WS_ERROR& error) +void WebSocketTestLayer::onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ERROR& error) { CCLog("Error was fired, error code: %d", error); if (ws == _wsiError) @@ -201,7 +201,7 @@ void WebSocketTestLayer::toExtensionsMainLayer(cocos2d::CCObject *sender) // Menu Callbacks void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::CCObject *sender) { - if (_wsiSendText->getReadyState() == WebSocket::WS_STATE_OPEN) + if (_wsiSendText->getReadyState() == WebSocket::STATE_OPEN) { _sendTextStatus->setString("Send Text WS is waiting..."); _wsiSendText->send("Hello WebSocket, I'm a text message."); @@ -216,7 +216,7 @@ void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::CCObject *sender) void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::CCObject *sender) { - if (_wsiSendBinary->getReadyState() == WebSocket::WS_STATE_OPEN) + if (_wsiSendBinary->getReadyState() == WebSocket::STATE_OPEN) { _sendBinaryStatus->setString("Send Binary WS is waiting..."); char buf[] = "Hello WebSocket,\0 I'm\0 a\0 binary\0 message\0."; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h index 1070ce750a..dd4d1991cd 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h @@ -24,7 +24,7 @@ public: virtual void onOpen(cocos2d::extension::WebSocket* ws); virtual void onMessage(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::Data& data); virtual void onClose(cocos2d::extension::WebSocket* ws); - virtual void onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::WS_ERROR& error); + virtual void onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ERROR& error); void toExtensionsMainLayer(cocos2d::CCObject *sender); diff --git a/scripting/javascript/bindings/jsb_websocket.cpp b/scripting/javascript/bindings/jsb_websocket.cpp index 5768be58eb..eea1ad41ff 100644 --- a/scripting/javascript/bindings/jsb_websocket.cpp +++ b/scripting/javascript/bindings/jsb_websocket.cpp @@ -129,7 +129,7 @@ public: CC_SAFE_DELETE(ws); } - virtual void onError(WebSocket* ws, const WebSocket::WS_ERROR& error) + virtual void onError(WebSocket* ws, const WebSocket::ERROR& error) { js_proxy_t * p; JS_GET_PROXY(p, ws); @@ -371,13 +371,13 @@ void register_jsb_websocket(JSContext *cx, JSObject *global) { JSObject* jsclassObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return WebSocket; })()")); - JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::WS_STATE_CONNECTING) + JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::STATE_CONNECTING) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::WS_STATE_OPEN) + JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::STATE_OPEN) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::WS_STATE_CLOSING) + JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::STATE_CLOSING) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::WS_STATE_CLOSED) + JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::STATE_CLOSED) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // make the class enumerable in the registered namespace From c29e434ead767212a9b647ac371d432f4bd2714e Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 1 Jun 2013 19:51:59 +0800 Subject: [PATCH 15/18] Updating JS-Test. --- samples/Javascript/Shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Javascript/Shared b/samples/Javascript/Shared index 3e05297014..568f0addf9 160000 --- a/samples/Javascript/Shared +++ b/samples/Javascript/Shared @@ -1 +1 @@ -Subproject commit 3e05297014a89a01218e15ad18d5ebdf75b0b7b4 +Subproject commit 568f0addf94b132938892a33eb83dc5e7149110b From f2f0f031c7d768c09a3a4221257e1461194ed0a3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 3 Jun 2013 09:55:43 +0800 Subject: [PATCH 16/18] fixed #1647: Renaming enumerations to Cocos2d-x style. ERROR and ERROR_TIMEOUT is defined as macros on Windows, fuck it. --- extensions/network/WebSocket.cpp | 35 ++++++++++--------- extensions/network/WebSocket.h | 26 +++++++------- .../NetworkTest/WebSocketTest.cpp | 6 ++-- .../NetworkTest/WebSocketTest.h | 2 +- .../javascript/bindings/jsb_websocket.cpp | 10 +++--- 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/extensions/network/WebSocket.cpp b/extensions/network/WebSocket.cpp index a2a2516620..93ecea4157 100644 --- a/extensions/network/WebSocket.cpp +++ b/extensions/network/WebSocket.cpp @@ -225,7 +225,7 @@ enum WS_MSG { }; WebSocket::WebSocket() -: _readyState(STATE_CONNECTING) +: _readyState(kStateConnecting) , _port(80) , _wsHelper(NULL) , _wsInstance(NULL) @@ -335,7 +335,7 @@ bool WebSocket::init(const Delegate& delegate, void WebSocket::send(const std::string& message) { - if (_readyState == STATE_OPEN) + if (_readyState == kStateOpen) { // In main thread WsMessage* msg = new WsMessage(); @@ -353,7 +353,7 @@ void WebSocket::send(const unsigned char* binaryMsg, unsigned int len) { CCAssert(binaryMsg != NULL && len > 0, "parameter invalid."); - if (_readyState == STATE_OPEN) + if (_readyState == kStateOpen) { // In main thread WsMessage* msg = new WsMessage(); @@ -371,11 +371,11 @@ void WebSocket::close() { CCDirector::sharedDirector()->getScheduler()->unscheduleAllForTarget(_wsHelper); - if (_readyState == STATE_CLOSING || _readyState == STATE_CLOSED) + if (_readyState == kStateClosing || _readyState == kStateClosed) return; CCLOG("websocket (%p) connection closed by client", this); - _readyState = STATE_CLOSED; + _readyState = kStateClosed; WsMessage* msg = new WsMessage(); msg->what = WS_MSG_TO_SUBTRHEAD_CLOSING; @@ -388,21 +388,21 @@ void WebSocket::close() _delegate->onClose(this); } -WebSocket::STATE WebSocket::getReadyState() +WebSocket::State WebSocket::getReadyState() { return _readyState; } int WebSocket::onSubThreadLoop() { - if (_readyState == STATE_CLOSED || _readyState == STATE_CLOSING) + if (_readyState == kStateClosed || _readyState == kStateClosing) { libwebsocket_context_destroy(_wsContext); // return 1 to exit the loop. return 1; } - if (_wsContext && _readyState != STATE_CLOSED && _readyState != STATE_CLOSING) + if (_wsContext && _readyState != kStateClosed && _readyState != kStateClosing) { libwebsocket_service(_wsContext, 0); } @@ -442,7 +442,7 @@ void WebSocket::onSubThreadStarted() _wsContext = libwebsocket_create_context(&info); if(NULL != _wsContext){ - _readyState = STATE_CONNECTING; + _readyState = kStateConnecting; std::string name; for (int i = 0; _wsProtocols[i].callback != NULL; ++i) { name += (_wsProtocols[i].name); @@ -480,14 +480,14 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, { WsMessage* msg = new WsMessage(); if (reason == LWS_CALLBACK_CLIENT_CONNECTION_ERROR - || (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == STATE_CONNECTING) - || (reason == LWS_CALLBACK_DEL_POLL_FD && _readyState == STATE_CONNECTING) + || (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == kStateConnecting) + || (reason == LWS_CALLBACK_DEL_POLL_FD && _readyState == kStateConnecting) ) { msg->what = WS_MSG_TO_UITHREAD_ERROR; - _readyState = STATE_CLOSING; + _readyState = kStateClosing; } - else if (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == STATE_CLOSING) + else if (reason == LWS_CALLBACK_PROTOCOL_DESTROY && _readyState == kStateClosing) { msg->what = WS_MSG_TO_UITHREAD_CLOSE; } @@ -498,7 +498,7 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, { WsMessage* msg = new WsMessage(); msg->what = WS_MSG_TO_UITHREAD_OPEN; - _readyState = STATE_OPEN; + _readyState = kStateOpen; /* * start the ball rolling, * LWS_CALLBACK_CLIENT_WRITEABLE will come next service @@ -572,10 +572,10 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, _wsHelper->quitSubThread(); - if (_readyState != STATE_CLOSED) + if (_readyState != kStateClosed) { WsMessage* msg = new WsMessage(); - _readyState = STATE_CLOSED; + _readyState = kStateClosed; msg->what = WS_MSG_TO_UITHREAD_CLOSE; _wsHelper->sendMessageToUIThread(msg); } @@ -646,7 +646,8 @@ void WebSocket::onUIThreadReceiveMessage(WsMessage* msg) break; case WS_MSG_TO_UITHREAD_ERROR: { - WebSocket::ERROR err = ERROR_CONNECTION_FAILS; + // FIXME: The exact error needs to be checked. + WebSocket::ErrorCode err = kErrorConnectionFailure; _delegate->onError(this, err); } break; diff --git a/extensions/network/WebSocket.h b/extensions/network/WebSocket.h index f7698fff60..068f341d60 100644 --- a/extensions/network/WebSocket.h +++ b/extensions/network/WebSocket.h @@ -57,11 +57,11 @@ public: /** * @brief Errors in websocket */ - enum ERROR + enum ErrorCode { - ERROR_TIMEOUT = 0, - ERROR_CONNECTION_FAILS, - ERROR_UNKNOWN + kErrorTimeout = 0, + kErrorConnectionFailure, + kErrorUnknown }; /** @@ -74,7 +74,7 @@ public: virtual void onOpen(WebSocket* ws) = 0; virtual void onMessage(WebSocket* ws, const Data& data) = 0; virtual void onClose(WebSocket* ws) = 0; - virtual void onError(WebSocket* ws, const ERROR& error) = 0; + virtual void onError(WebSocket* ws, const ErrorCode& error) = 0; }; @@ -107,18 +107,18 @@ public: /** * Websocket state */ - enum STATE + enum State { - STATE_CONNECTING = 0, - STATE_OPEN, - STATE_CLOSING, - STATE_CLOSED + kStateConnecting = 0, + kStateOpen, + kStateClosing, + kStateClosed }; /** * @brief Gets current state of connection. */ - STATE getReadyState(); + State getReadyState(); private: virtual void onSubThreadStarted(); @@ -134,7 +134,7 @@ private: void *user, void *in, size_t len); private: - STATE _readyState; + State _readyState; std::string _host; unsigned int _port; std::string _path; @@ -142,7 +142,7 @@ private: friend class WsThreadHelper; WsThreadHelper* _wsHelper; - struct libwebsocket* _wsInstance; + struct libwebsocket* _wsInstance; struct libwebsocket_context* _wsContext; Delegate* _delegate; int _SSLConnection; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp index e80a0a8dae..c568c521aa 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp @@ -180,7 +180,7 @@ void WebSocketTestLayer::onClose(cocos2d::extension::WebSocket* ws) CC_SAFE_DELETE(ws); } -void WebSocketTestLayer::onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ERROR& error) +void WebSocketTestLayer::onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ErrorCode& error) { CCLog("Error was fired, error code: %d", error); if (ws == _wsiError) @@ -201,7 +201,7 @@ void WebSocketTestLayer::toExtensionsMainLayer(cocos2d::CCObject *sender) // Menu Callbacks void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::CCObject *sender) { - if (_wsiSendText->getReadyState() == WebSocket::STATE_OPEN) + if (_wsiSendText->getReadyState() == WebSocket::kStateOpen) { _sendTextStatus->setString("Send Text WS is waiting..."); _wsiSendText->send("Hello WebSocket, I'm a text message."); @@ -216,7 +216,7 @@ void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::CCObject *sender) void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::CCObject *sender) { - if (_wsiSendBinary->getReadyState() == WebSocket::STATE_OPEN) + if (_wsiSendBinary->getReadyState() == WebSocket::kStateOpen) { _sendBinaryStatus->setString("Send Binary WS is waiting..."); char buf[] = "Hello WebSocket,\0 I'm\0 a\0 binary\0 message\0."; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h index dd4d1991cd..087c0bedaa 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h @@ -24,7 +24,7 @@ public: virtual void onOpen(cocos2d::extension::WebSocket* ws); virtual void onMessage(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::Data& data); virtual void onClose(cocos2d::extension::WebSocket* ws); - virtual void onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ERROR& error); + virtual void onError(cocos2d::extension::WebSocket* ws, const cocos2d::extension::WebSocket::ErrorCode& error); void toExtensionsMainLayer(cocos2d::CCObject *sender); diff --git a/scripting/javascript/bindings/jsb_websocket.cpp b/scripting/javascript/bindings/jsb_websocket.cpp index eea1ad41ff..12c97b5e57 100644 --- a/scripting/javascript/bindings/jsb_websocket.cpp +++ b/scripting/javascript/bindings/jsb_websocket.cpp @@ -129,7 +129,7 @@ public: CC_SAFE_DELETE(ws); } - virtual void onError(WebSocket* ws, const WebSocket::ERROR& error) + virtual void onError(WebSocket* ws, const WebSocket::ErrorCode& error) { js_proxy_t * p; JS_GET_PROXY(p, ws); @@ -371,13 +371,13 @@ void register_jsb_websocket(JSContext *cx, JSObject *global) { JSObject* jsclassObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return WebSocket; })()")); - JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::STATE_CONNECTING) + JS_DefineProperty(cx, jsclassObj, "CONNECTING", INT_TO_JSVAL((int)WebSocket::kStateConnecting) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::STATE_OPEN) + JS_DefineProperty(cx, jsclassObj, "OPEN", INT_TO_JSVAL((int)WebSocket::kStateOpen) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::STATE_CLOSING) + JS_DefineProperty(cx, jsclassObj, "CLOSING", INT_TO_JSVAL((int)WebSocket::kStateClosing) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); - JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::STATE_CLOSED) + JS_DefineProperty(cx, jsclassObj, "CLOSED", INT_TO_JSVAL((int)WebSocket::kStateClosed) , NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); // make the class enumerable in the registered namespace From d0680258c628197bc88610badf70b9f856a7177e Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 3 Jun 2013 10:03:38 +0800 Subject: [PATCH 17/18] fixed #1647: [WebSocket] Fixing compilation errors on win32. --- samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 10 ++++++++++ .../TestJavascript/proj.win32/TestJavascript.vcxproj | 6 ++++-- .../bindings/proj.win32/libJSBinding.vcxproj | 2 +- .../bindings/proj.win32/libJSBinding.vcxproj.filters | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index e080de91cb..3a4146d74a 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -88,6 +88,11 @@ + + if not exist "$(OutDir)" mkdir "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(OutDir)" + + @@ -117,6 +122,11 @@ + + if not exist "$(OutDir)" mkdir "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(OutDir)" + + diff --git a/samples/Javascript/TestJavascript/proj.win32/TestJavascript.vcxproj b/samples/Javascript/TestJavascript/proj.win32/TestJavascript.vcxproj index 2a9a2f02ab..2aa3f0ac5c 100644 --- a/samples/Javascript/TestJavascript/proj.win32/TestJavascript.vcxproj +++ b/samples/Javascript/TestJavascript/proj.win32/TestJavascript.vcxproj @@ -94,10 +94,11 @@ if not exist "$(OutDir)" mkdir "$(OutDir)" xcopy /Y /Q "$(ProjectDir)..\..\..\..\scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(OutDir)" - libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;libJSBinding.lib;libcurl_imp.lib;mozjs.lib;ws2_32.lib;sqlite3.lib;pthreadVCE2.lib;%(AdditionalDependencies) + libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;libJSBinding.lib;libcurl_imp.lib;mozjs.lib;ws2_32.lib;sqlite3.lib;pthreadVCE2.lib;websockets.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) true Windows @@ -148,10 +149,11 @@ xcopy "$(ProjectDir)..\..\Shared\tests" "$(OutDir)\TestJavascriptRes\" /e /Y if not exist "$(OutDir)" mkdir "$(OutDir)" xcopy /Y /Q "$(ProjectDir)..\..\..\..\scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(OutDir)" - libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;libJSBinding.lib;libcurl_imp.lib;mozjs.lib;ws2_32.lib;sqlite3.lib;pthreadVCE2.lib;%(AdditionalDependencies) + libcocos2d.lib;libExtensions.lib;opengl32.lib;glew32.lib;libCocosDenshion.lib;libchipmunk.lib;libJSBinding.lib;libcurl_imp.lib;mozjs.lib;ws2_32.lib;sqlite3.lib;pthreadVCE2.lib;websockets.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) Windows MachineX86 diff --git a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj index 59164d2b19..9813d7722f 100644 --- a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj +++ b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj @@ -39,6 +39,7 @@ + @@ -59,7 +60,6 @@ - diff --git a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters index f49e00a20f..28046317c8 100644 --- a/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters +++ b/scripting/javascript/bindings/proj.win32/libJSBinding.vcxproj.filters @@ -154,10 +154,10 @@ manual - + manual - + manual From 66e6630f3726850399d09c1b9db3e05ce5d4a2e7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 3 Jun 2013 11:39:18 +0800 Subject: [PATCH 18/18] fixed #2243: XMLHttpRequest don't support non-ascii characters. --- scripting/javascript/bindings/XMLHTTPRequest.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripting/javascript/bindings/XMLHTTPRequest.cpp b/scripting/javascript/bindings/XMLHTTPRequest.cpp index e40ed78299..2e69bea25b 100644 --- a/scripting/javascript/bindings/XMLHTTPRequest.cpp +++ b/scripting/javascript/bindings/XMLHTTPRequest.cpp @@ -628,7 +628,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) { JSString *str = NULL; - char *data = NULL; + std::string data; // Clean up header map. New request, new headers! http_header.clear(); @@ -636,12 +636,13 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &str)) { return JS_FALSE; }; - data = JS_EncodeString(cx, str); + JSStringWrapper strWrap(str); + data = strWrap.get(); } - if (data != NULL && meth.compare("post") == 0 || meth.compare("POST") == 0) { - cc_request->setRequestData(data, strlen(data)); + if (data.length() > 0 && (meth.compare("post") == 0 || meth.compare("POST") == 0)) { + cc_request->setRequestData(data.c_str(), data.length()); } _setHttpRequestHeader(); @@ -700,7 +701,10 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getResponseHeader) return JS_FALSE; }; - char *data = JS_EncodeString(cx, header_value); + std::string data; + JSStringWrapper strWrap(header_value); + data = strWrap.get(); + stringstream streamdata; streamdata << data;