cinterface.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "cinterface.h"
  23. #include "windowManager/platformWindow.h"
  24. CInterface& CInterface::GetCInterface()
  25. {
  26. static CInterface INSTANCE;
  27. return INSTANCE;
  28. }
  29. bool CInterface::isMethod(const char* className, const char* methodName)
  30. {
  31. return GetCInterface()._isMethod(className, methodName);
  32. }
  33. const char* CInterface::CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result)
  34. {
  35. return GetCInterface()._CallFunction(nameSpace, name, argv, argc, result);
  36. }
  37. const char* CInterface::CallMethod(SimObject* obj, const char* name, const char **argv, int argc, bool *res)
  38. {
  39. return GetCInterface()._CallMethod(obj->getClassName(), obj->getClassNamespace(), obj->getId(), name, argv, argc, res);
  40. }
  41. void CInterface::CallMain(bool *res)
  42. {
  43. GetCInterface()._CallMain(res);
  44. }
  45. bool CInterface::_isMethod(const char* className, const char* methodName) const
  46. {
  47. if (mIsMethodCallback)
  48. return mIsMethodCallback(className, methodName);
  49. return false;
  50. }
  51. const char* CInterface::_CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result) const
  52. {
  53. if (mFunctionCallback)
  54. return mFunctionCallback(nameSpace, name, argv, argc, result);
  55. *result = false;
  56. return NULL;
  57. }
  58. const char* CInterface::_CallMethod(const char* className, const char* classNamespace, U32 object, const char* name, const char **argv, int argc, bool *res) const
  59. {
  60. if (mMethodCallback)
  61. return mMethodCallback(className, classNamespace, object, name, argv, argc, res);
  62. *res = false;
  63. return NULL;
  64. }
  65. void CInterface::_CallMain(bool *res) const
  66. {
  67. if (mMainCallback)
  68. {
  69. *res = true;
  70. mMainCallback();
  71. return;
  72. }
  73. *res = false;
  74. }
  75. TORQUE_API void SetCallbacks(void* ptr, void* methodPtr, void* isMethodPtr, void* mainPtr) {
  76. CInterface::GetCInterface().SetCallFunctionCallback(ptr);
  77. CInterface::GetCInterface().SetCallMethodCallback(methodPtr);
  78. CInterface::GetCInterface().SetCallIsMethodCallback(isMethodPtr);
  79. CInterface::GetCInterface().SetMainCallback(mainPtr);
  80. }