Optimize the interface & type names in plugin.

This commit is contained in:
zhangbin 2013-04-26 17:12:51 +08:00
parent 73f0b6df04
commit 0b08d88f27
19 changed files with 80 additions and 80 deletions

View File

@ -40,7 +40,7 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@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
@ -51,7 +51,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TDeveloperInfo devInfo);
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product

View File

@ -41,7 +41,7 @@ bool IAPAlipay::init()
}
/**
@brief initialize the developer info
@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
@ -52,9 +52,9 @@ bool IAPAlipay::init()
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void IAPAlipay::initDeveloperInfo(TDeveloperInfo devInfo)
void IAPAlipay::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
ProtocolIAP::initDeveloperInfo(devInfo);
ProtocolIAP::configDeveloperInfo(devInfo);
}
/**

View File

@ -74,7 +74,7 @@ public class IAPAlipay implements IAPAdapter {
}
@Override
public void initDeveloperInfo(Hashtable<String, String> cpInfo) {
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
LogD("initDeveloperInfo invoked " + cpInfo.toString());
try {
PartnerConfig.PARTNER = cpInfo.get("AlipayPartner");
@ -335,7 +335,7 @@ public class IAPAlipay implements IAPAdapter {
}
private static void payResult(int ret, String msg) {
InterfaceIAP.payResult(mAdapter, ret, msg);
InterfaceIAP.onPayResult(mAdapter, ret, msg);
LogD("Alipay result : " + ret + " msg : " + msg);
}
}

View File

@ -40,7 +40,7 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@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
@ -49,7 +49,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TDeveloperInfo devInfo);
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product

View File

@ -41,7 +41,7 @@ bool IAPNd91::init()
}
/**
@brief initialize the developer info
@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
@ -50,9 +50,9 @@ bool IAPNd91::init()
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void IAPNd91::initDeveloperInfo(TDeveloperInfo devInfo)
void IAPNd91::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
ProtocolIAP::initDeveloperInfo(devInfo);
ProtocolIAP::configDeveloperInfo(devInfo);
}
/**

View File

@ -65,7 +65,7 @@ public class IAPNd91 implements IAPAdapter {
}
@Override
public void initDeveloperInfo(Hashtable<String, String> cpInfo) {
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
LogD("initDeveloperInfo invoked " + cpInfo.toString());
final Hashtable<String, String> curCPInfo = cpInfo;
PluginWrapper.runOnMainThread(new Runnable() {
@ -150,7 +150,7 @@ public class IAPNd91 implements IAPAdapter {
}
private static void payResult(int ret, String msg) {
InterfaceIAP.payResult(mNd91, ret, msg);
InterfaceIAP.onPayResult(mNd91, ret, msg);
LogD("Nd91 result : " + ret + " msg : " + msg);
}

View File

@ -40,14 +40,14 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@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 initDeveloperInfo(TSocialDevInfo devInfo);
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief pay for product

View File

@ -18,7 +18,7 @@ bool SocialTwitter::init()
}
/**
@brief initialize the developer info
@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
@ -26,9 +26,9 @@ bool SocialTwitter::init()
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void SocialTwitter::initDeveloperInfo(TSocialDevInfo devInfo)
void SocialTwitter::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
ProtocolSocial::initDeveloperInfo(devInfo);
ProtocolSocial::configDeveloperInfo(devInfo);
}
/**

View File

@ -68,7 +68,7 @@ public class SocialTwitter implements ShareAdapter {
@Override
public void initDeveloperInfo(Hashtable<String, String> cpInfo) {
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
LogD("initDeveloperInfo invoked " + cpInfo.toString());
try {
SocialTwitter.CONSUMER_KEY = cpInfo.get("TwitterKey");
@ -153,7 +153,7 @@ public class SocialTwitter implements ShareAdapter {
}
private static void shareResult(int ret, String msg) {
InterfaceSocial.shareResult(mSocialAdapter, ret, msg);
InterfaceSocial.onShareResult(mSocialAdapter, ret, msg);
LogD("SocialTwitter result : " + ret + " msg : " + msg);
}

View File

@ -30,21 +30,21 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
typedef std::map<std::string, std::string> TDeveloperInfo;
typedef std::map<std::string, std::string> TIAPDeveloperInfo;
typedef std::map<std::string, std::string> TProductInfo;
typedef enum
{
ePaySuccess = 0,
ePayFail,
ePayCancel,
ePayTimeOut,
} EPayResult;
kPaySuccess = 0,
kPayFail,
kPayCancel,
kPayTimeOut,
} PayResultCode;
class PayResultListener
{
public:
virtual void payResult(EPayResult ret, const char* msg, TProductInfo info) = 0;
virtual void onPayResult(PayResultCode ret, const char* msg, TProductInfo info) = 0;
};
class ProtocolIAP : public PluginProtocol
@ -57,13 +57,13 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@brief config the developer info
@param devInfo This parameter is the info of developer,
different plugin have different format
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TDeveloperInfo devInfo);
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product
@ -87,12 +87,12 @@ public:
@param pListener The callback object for pay result
@wraning Must invoke this interface before payForProduct.
*/
virtual void setResultListener(PayResultListener* pListener);
void setResultListener(PayResultListener* pListener);
/**
@brief pay result callback
*/
virtual void payResult(EPayResult ret, const char* msg);
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();

View File

@ -30,21 +30,21 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
typedef std::map<std::string, std::string> TSocialDevInfo;
typedef std::map<std::string, std::string> TSocialDeveloperInfo;
typedef std::map<std::string, std::string> TShareInfo;
typedef enum
{
eShareSuccess = 0,
eShareFail,
eShareCancel,
eShareTimeOut,
} EShareResult;
kShareSuccess = 0,
kShareFail,
kShareCancel,
kShareTimeOut,
} ShareResultCode;
class ShareResultListener
{
public:
virtual void shareResult(EShareResult ret, const char* msg) = 0;
virtual void onShareResult(ShareResultCode ret, const char* msg) = 0;
};
class ProtocolSocial : public PluginProtocol
@ -57,13 +57,13 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@brief config the social developer info
@param devInfo This parameter is the info of developer,
different plugin have different format
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TSocialDevInfo devInfo);
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief share information
@ -86,12 +86,12 @@ public:
@param pListener The callback object for share result
@wraning Must invoke this interface before share
*/
virtual void setResultListener(ShareResultListener* pListener);
void setResultListener(ShareResultListener* pListener);
/**
@brief share result callback
*/
virtual void shareResult(EShareResult ret, const char* msg);
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();

View File

@ -37,18 +37,18 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativePayResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
{
std::string strMsg = PluginJniHelper::jstring2string(msg);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
LOGD("nativePayResult(), Get plugin ptr : %p", pPlugin);
LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativePayResult(), Get plugin name : %s", pPlugin->getPluginName());
LOGD("nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);
if (pIAP != NULL)
{
pIAP->payResult((EPayResult) ret, strMsg.c_str());
pIAP->onPayResult((PayResultCode) ret, strMsg.c_str());
}
}
}
@ -71,7 +71,7 @@ bool ProtocolIAP::init()
return true;
}
void ProtocolIAP::initDeveloperInfo(TDeveloperInfo devInfo)
void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
if (devInfo.empty())
{
@ -84,7 +84,7 @@ void ProtocolIAP::initDeveloperInfo(TDeveloperInfo devInfo)
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "initDeveloperInfo"
, "configDeveloperInfo"
, "(Ljava/util/Hashtable;)V"))
{
// generate the hashtable from map
@ -110,7 +110,7 @@ void ProtocolIAP::payForProduct(TProductInfo info)
{
if (NULL != m_pListener)
{
payResult(ePayFail, "Product info error");
onPayResult(kPayFail, "Product info error");
}
LOGD("The product info is empty!");
return;
@ -143,12 +143,12 @@ void ProtocolIAP::setResultListener(PayResultListener* pListener)
m_pListener = pListener;
}
void ProtocolIAP::payResult(EPayResult ret, const char* msg)
void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg)
{
m_bPaying = false;
if (m_pListener)
{
m_pListener->payResult(ret, msg, m_curInfo);
m_pListener->onPayResult(ret, msg, m_curInfo);
}
else
{

View File

@ -37,18 +37,18 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeShareResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
{
std::string strMsg = PluginJniHelper::jstring2string(msg);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
LOGD("nativeShareResult(), Get plugin ptr : %p", pPlugin);
LOGD("nativeOnShareResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeShareResult(), Get plugin name : %s", pPlugin->getPluginName());
LOGD("nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolSocial* pSocial = dynamic_cast<ProtocolSocial*>(pPlugin);
if (pSocial != NULL)
{
pSocial->shareResult((EShareResult) ret, strMsg.c_str());
pSocial->onShareResult((ShareResultCode) ret, strMsg.c_str());
}
}
}
@ -69,7 +69,7 @@ bool ProtocolSocial::init()
return true;
}
void ProtocolSocial::initDeveloperInfo(TSocialDevInfo devInfo)
void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
if (devInfo.empty())
{
@ -82,7 +82,7 @@ void ProtocolSocial::initDeveloperInfo(TSocialDevInfo devInfo)
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "initDeveloperInfo"
, "configDeveloperInfo"
, "(Ljava/util/Hashtable;)V"))
{
// generate the hashtable from map
@ -102,7 +102,7 @@ void ProtocolSocial::share(TShareInfo info)
{
if (NULL != m_pListener)
{
shareResult(eShareFail, "Share info error");
onShareResult(kShareFail, "Share info error");
}
LOGD("The Share info is empty!");
return;
@ -132,11 +132,11 @@ void ProtocolSocial::setResultListener(ShareResultListener* pListener)
m_pListener = pListener;
}
void ProtocolSocial::shareResult(EShareResult ret, const char* msg)
void ProtocolSocial::onShareResult(ShareResultCode ret, const char* msg)
{
if (m_pListener)
{
m_pListener->shareResult(ret, msg);
m_pListener->onShareResult(ret, msg);
}
else
{

View File

@ -32,22 +32,22 @@ public class InterfaceIAP {
public static final int PAYRESULT_TIMEOUT = 3;
public interface IAPAdapter {
public void initDeveloperInfo(Hashtable<String, String> cpInfo);
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void payForProduct(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void payResult(IAPAdapter obj, int ret, String msg) {
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() {
nativePayResult(curObj, curRet, curMsg);
nativeOnPayResult(curObj, curRet, curMsg);
}
});
}
private static native void nativePayResult(Object obj, int ret, String msg);
private static native void nativeOnPayResult(Object obj, int ret, String msg);
}

View File

@ -32,22 +32,22 @@ public class InterfaceSocial {
public static final int SHARERESULT_TIMEOUT = 3;
public interface ShareAdapter {
public void initDeveloperInfo(Hashtable<String, String> cpInfo);
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void share(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void shareResult(ShareAdapter obj, int ret, String msg) {
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() {
nativeShareResult(curAdapter, curRet, curMsg);
nativeOnShareResult(curAdapter, curRet, curMsg);
}
});
}
private static native void nativeShareResult(Object obj, int ret, String msg);
private static native void nativeOnShareResult(Object obj, int ret, String msg);
}

View File

@ -76,7 +76,7 @@ void MyPurchase::loadIAPPlugin()
{
// init alipay plugin
s_pAlipay = dynamic_cast<IAPAlipay*>(PluginManager::getInstance()->loadPlugin("IAPAlipay"));
TDeveloperInfo pAlipayInfo;
TIAPDeveloperInfo pAlipayInfo;
if (pAlipayInfo.empty())
{
char msg[256] = { 0 };
@ -84,12 +84,12 @@ void MyPurchase::loadIAPPlugin()
CCMessageBox(msg, "Alipay Warning");
}
s_pAlipay->setDebugMode(true);
s_pAlipay->initDeveloperInfo(pAlipayInfo);
s_pAlipay->configDeveloperInfo(pAlipayInfo);
s_pAlipay->setResultListener(s_pRetListener);
}
{
TDeveloperInfo pNdInfo;
TIAPDeveloperInfo pNdInfo;
pNdInfo["Nd91AppId"] = "100010";
pNdInfo["Nd91AppKey"] = "C28454605B9312157C2F76F27A9BCA2349434E546A6E9C75";
pNdInfo["Nd91Orientation"] = "landscape";
@ -100,7 +100,7 @@ void MyPurchase::loadIAPPlugin()
}
s_pNd91 = dynamic_cast<IAPNd91*>(PluginManager::getInstance()->loadPlugin("IAPNd91"));
s_pNd91->setDebugMode(true);
s_pNd91->initDeveloperInfo(pNdInfo);
s_pNd91->configDeveloperInfo(pNdInfo);
s_pNd91->setResultListener(s_pRetListener);
}
}
@ -140,7 +140,7 @@ void MyPurchase::payByMode(TProductInfo info, MyPayMode mode)
}
}
void MyPurchaseResult::payResult(EPayResult ret, const char* msg, TProductInfo info)
void MyPurchaseResult::onPayResult(PayResultCode ret, const char* msg, TProductInfo info)
{
char goodInfo[1024] = { 0 };
sprintf(goodInfo, "商品名称:%s\n商品价格:%s\n商品描述:%s",

View File

@ -30,7 +30,7 @@ THE SOFTWARE.
class MyPurchaseResult : public cocos2d::plugin::PayResultListener
{
public:
virtual void payResult(cocos2d::plugin::EPayResult ret, const char* msg, cocos2d::plugin::TProductInfo info);
virtual void onPayResult(cocos2d::plugin::PayResultCode ret, const char* msg, cocos2d::plugin::TProductInfo info);
};
class MyPurchase

View File

@ -75,7 +75,7 @@ void MySocialManager::loadSocialPlugin()
{
// init twitter plugin
s_pTwitter = dynamic_cast<SocialTwitter*>(PluginManager::getInstance()->loadPlugin("SocialTwitter"));
TSocialDevInfo pTwitterInfo;
TSocialDeveloperInfo pTwitterInfo;
/* Warning: must set your twiiter dev info here */
// pTwitterInfo["TwitterKey"] = "your consumerkey";
@ -88,7 +88,7 @@ void MySocialManager::loadSocialPlugin()
CCMessageBox(msg, "Twitter Warning");
}
s_pTwitter->setDebugMode(true);
s_pTwitter->initDeveloperInfo(pTwitterInfo);
s_pTwitter->configDeveloperInfo(pTwitterInfo);
s_pTwitter->setResultListener(s_pRetListener);
}
}
@ -119,9 +119,9 @@ void MySocialManager::shareByMode(TShareInfo info, MyShareMode mode)
}
}
void MyShareResult::shareResult(EShareResult ret, const char* msg)
void MyShareResult::onShareResult(ShareResultCode ret, const char* msg)
{
char shareStatus[1024] = { 0 };
sprintf(shareStatus, "Share %s", (ret == eShareSuccess)? "Successed" : "Failed");
sprintf(shareStatus, "Share %s", (ret == kShareSuccess)? "Successed" : "Failed");
CCMessageBox(msg, shareStatus);
}

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
class MyShareResult : public cocos2d::plugin::ShareResultListener
{
public:
virtual void shareResult(cocos2d::plugin::EShareResult ret, const char* msg);
virtual void onShareResult(cocos2d::plugin::ShareResultCode ret, const char* msg);
};
class MySocialManager