cinterface.cpp

Engine/source/cinterface/cinterface.cpp

More...

Public Functions

TORQUE_API void
SetCallbacks(void * ptr, void * methodPtr, void * isMethodPtr, void * mainPtr)

Detailed Description

Public Functions

SetCallbacks(void * ptr, void * methodPtr, void * isMethodPtr, void * mainPtr)

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