![]() |
http://www.sim.no/ http://www.coin3d.org/ |
00001 #ifndef COIN_SOJAVASCRIPTENGINE_H 00002 #define COIN_SOJAVASCRIPTENGINE_H 00003 00004 /**************************************************************************\ 00005 * 00006 * This file is part of the Coin 3D visualization library. 00007 * Copyright (C) by Kongsberg Oil & Gas Technologies. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * ("GPL") version 2 as published by the Free Software Foundation. 00012 * See the file LICENSE.GPL at the root directory of this source 00013 * distribution for additional information about the GNU GPL. 00014 * 00015 * For using Coin with software that can not be combined with the GNU 00016 * GPL, and for taking advantage of the additional benefits of our 00017 * support services, please contact Kongsberg Oil & Gas Technologies 00018 * about acquiring a Coin Professional Edition License. 00019 * 00020 * See http://www.coin3d.org/ for more information. 00021 * 00022 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY. 00023 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org 00024 * 00025 \**************************************************************************/ 00026 00027 #include <Inventor/misc/SoScriptEngine.h> 00028 #include <Inventor/C/glue/spidermonkey.h> 00029 #include <Inventor/lists/SbList.h> 00030 00031 // ************************************************************************* 00032 00033 #define COIN_JAVASCRIPT_RUNTIME_MAXBYTES 4194304 00034 00035 // ************************************************************************* 00036 00037 typedef void SoJSfield2jsvalFunc(JSContext *, const SoField *, jsval *); 00038 typedef SbBool SoJSjsval2field2Func(JSContext *, const jsval, SoField *); 00039 typedef JSObject * SoJSWrapperInitFunc(JSContext *, JSObject * obj); 00040 00041 // ************************************************************************* 00042 00043 class COIN_DLL_API SoJavaScriptEngine : public SoScriptEngine { 00044 00045 public: 00046 SoJavaScriptEngine(); 00047 virtual ~SoJavaScriptEngine(); 00048 00049 virtual SbBool executeScript(const SbName & name, 00050 const SbString & script) const; 00051 virtual SbBool executeFile(const SbName & filename) const; 00052 virtual SbBool executeFunction(const SbName &name, int argc, 00053 const SoField * argv, 00054 SoField * rval = NULL) const; 00055 00056 virtual SbBool setScriptField(const SbName & name, const SoField * f) const; 00057 virtual SbBool unsetScriptField(const SbName & name) const; 00058 virtual SbBool getScriptField(const SbName & name, SoField * f) const; 00059 virtual SbBool hasScriptField(const SbName & name) const; 00060 00061 // Everything under here is javascript specific 00062 00063 static SoJavaScriptEngine *getEngine(JSContext * cx); 00064 00065 SbBool field2jsval(const SoField * f, jsval * v) const; 00066 SbBool jsval2field(const jsval v, SoField * f) const; 00067 void enableAutoNodeUnref(SbBool onoff); 00068 SbBool getAutoNodeUnrefState(void) const; 00069 00070 static SbBool init(uint32_t maxbytes = COIN_JAVASCRIPT_RUNTIME_MAXBYTES); 00071 static void shutdown(void); 00072 static SbBool debug(void); 00073 00074 static JSRuntime * getRuntime(void); 00075 JSContext * getContext(void) const; 00076 JSObject * getGlobal(void) const; 00077 00078 void addHandler(const SoType & type, SoJSWrapperInitFunc * init, 00079 SoJSfield2jsvalFunc * field2jsval, 00080 SoJSjsval2field2Func * jsval2field); 00081 00082 protected: 00083 static void setRuntime(JSRuntime * runtime); 00084 void setContext(JSContext * context); 00085 void setGlobal(JSObject * global); 00086 00087 private: 00088 class SoJavaScriptEngineP * pimpl; 00089 friend class SoJavaScriptEngineP; 00090 }; 00091 00092 #endif // !COIN_SOJAVASCRIPTENGINE_H
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated for Coin by Doxygen 1.7.5.1.