ProtocolUser.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /****************************************************************************
  2. Copyright (c) 2013 cocos2d-x.org
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCX_PROTOCOL_USER_H__
  21. #define __CCX_PROTOCOL_USER_H__
  22. #include "PluginProtocol.h"
  23. #include <map>
  24. #include <string>
  25. #include <functional>
  26. namespace cocos2d { namespace plugin {
  27. typedef std::map<std::string, std::string> TUserDeveloperInfo;
  28. typedef enum
  29. {
  30. kLoginSucceed = 0,
  31. kLoginFailed,
  32. kLogoutSucceed,
  33. } UserActionResultCode;
  34. class ProtocolUser;
  35. class UserActionListener
  36. {
  37. public:
  38. virtual void onActionResult(ProtocolUser* pPlugin, UserActionResultCode code, const char* msg) = 0;
  39. };
  40. class ProtocolUser : public PluginProtocol
  41. {
  42. public:
  43. ProtocolUser();
  44. virtual ~ProtocolUser();
  45. typedef std::function<void(int, std::string&)> ProtocolUserCallback;
  46. /**
  47. @brief config the application info
  48. @param devInfo This parameter is the info of aplication,
  49. different plugin have different format
  50. @warning Must invoke this interface before other interfaces.
  51. And invoked only once.
  52. */
  53. void configDeveloperInfo(TUserDeveloperInfo devInfo);
  54. /**
  55. @brief User login
  56. */
  57. void login();
  58. void login(ProtocolUserCallback &cb);
  59. /**
  60. @brief User logout
  61. */
  62. void logout();
  63. void logout(ProtocolUserCallback &cb);
  64. /**
  65. @brief Check whether the user logined or not
  66. */
  67. CC_DEPRECATED_ATTRIBUTE bool isLogined() {return isLoggedIn();}
  68. bool isLoggedIn();
  69. /**
  70. @brief Get session ID
  71. @return If user logined, return value is session ID;
  72. else return value is empty string.
  73. */
  74. std::string getSessionID();
  75. /**
  76. @brief get Access Token
  77. */
  78. std::string getAccessToken();
  79. /*
  80. @deprecated
  81. @brief set login callback function
  82. */
  83. CC_DEPRECATED_ATTRIBUTE inline void setActionListener(UserActionListener* listener)
  84. {
  85. _listener = listener;
  86. }
  87. /*
  88. @deprecated
  89. @brief get login callback function
  90. */
  91. CC_DEPRECATED_ATTRIBUTE inline UserActionListener* getActionListener()
  92. {
  93. return _listener;
  94. }
  95. /**
  96. @brief set login callback function
  97. */
  98. inline void setCallback(const ProtocolUserCallback &cb)
  99. {
  100. _callback = cb;
  101. }
  102. /**
  103. @brief get login callback function
  104. */
  105. inline ProtocolUserCallback& getCallback()
  106. {
  107. return _callback;
  108. }
  109. protected:
  110. UserActionListener* _listener;
  111. ProtocolUserCallback _callback;
  112. };
  113. }} // namespace cocos2d { namespace plugin {
  114. #endif /* __CCX_PROTOCOL_USER_H__ */