UserWrapper.mm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /****************************************************************************
  2. Copyright (c) 2012+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. #import "UserWrapper.h"
  21. #include "PluginUtilsIOS.h"
  22. #include "ProtocolUser.h"
  23. #include "FacebookAgent.h"
  24. using namespace cocos2d::plugin;
  25. @implementation UserWrapper
  26. + (void) onActionResult:(id) obj withRet:(UserActionResult) ret withMsg:(NSString*) msg
  27. {
  28. PluginProtocol* pPlugin = PluginUtilsIOS::getPluginPtr(obj);
  29. ProtocolUser* pUser = dynamic_cast<ProtocolUser*>(pPlugin);
  30. if (pUser) {
  31. UserActionListener* listener = pUser->getActionListener();
  32. ProtocolUser::ProtocolUserCallback callback = pUser->getCallback();
  33. const char* chMsg = [msg UTF8String];
  34. if (NULL != listener)
  35. {
  36. listener->onActionResult(pUser, (UserActionResultCode) ret, chMsg);
  37. }else if(callback){
  38. std::string stdmsg(chMsg);
  39. callback((UserActionResultCode) ret, stdmsg);
  40. }else{
  41. PluginUtilsIOS::outputLog("Can't find the listener of plugin %s", pPlugin->getPluginName());
  42. }
  43. } else {
  44. PluginUtilsIOS::outputLog("Can't find the C++ object of the User plugin");
  45. }
  46. }
  47. + (void) onGraphResult:(id)obj withRet:(GraphResult)ret withMsg:(NSString *)msg withCallback:(int)cbid{
  48. const char* chMsg = [msg UTF8String];
  49. FacebookAgent::FBCallback callback = FacebookAgent::getInstance()->getRequestCallback(cbid);
  50. if(callback){
  51. std::string stdmsg(chMsg);
  52. callback((GraphResult) ret, stdmsg);
  53. }else{
  54. PluginUtilsIOS::outputLog("an't find the C++ object of the requestCallback");
  55. }
  56. }
  57. + (void) onPermissionsResult:(id)obj withRet:(int)ret withMsg:(NSString *)msg{
  58. PluginProtocol* pPlugin = PluginUtilsIOS::getPluginPtr(obj);
  59. ProtocolUser* pUser = dynamic_cast<ProtocolUser*>(pPlugin);
  60. if (pUser) {
  61. ProtocolUser::ProtocolUserCallback callback = pUser->getCallback();
  62. const char* chMsg = [msg UTF8String];
  63. if(callback){
  64. std::string stdmsg(chMsg);
  65. callback(ret, stdmsg);
  66. }else{
  67. PluginUtilsIOS::outputLog("Can't find the listener of plugin %s", pPlugin->getPluginName());
  68. }
  69. } else {
  70. PluginUtilsIOS::outputLog("Can't find the C++ object of the User plugin");
  71. }
  72. }
  73. + (void)onPermissionListResult:(id)obj withRet:(PermissionListResult )ret withMsg:(NSString *)msg{
  74. PluginProtocol* pPlugin = PluginUtilsIOS::getPluginPtr(obj);
  75. ProtocolUser* pUser = dynamic_cast<ProtocolUser*>(pPlugin);
  76. if (pUser) {
  77. ProtocolUser::ProtocolUserCallback callback = pUser->getCallback();
  78. const char* chMsg = [msg UTF8String];
  79. if(callback){
  80. std::string stdmsg(chMsg);
  81. callback(ret, stdmsg);
  82. }else{
  83. PluginUtilsIOS::outputLog("Can't find the listener of plugin %s", pPlugin->getPluginName());
  84. }
  85. } else {
  86. PluginUtilsIOS::outputLog("Can't find the C++ object of the User plugin");
  87. }
  88. }
  89. @end