H3D API  2.4.1
SpiderMonkeySAI.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
28 //
30 #ifndef __SPIDERMONKEYSAI_H__
31 #define __SPIDERMONKEYSAI_H__
32 #include <H3D/Field.h>
33 #include <H3D/X3DTypes.h>
34 #include <H3D/X3DFieldConversion.h>
35 #include <H3D/X3DTypeFunctions.h>
36 #include <H3D/PeriodicUpdate.h>
37 
38 #ifdef HAVE_SPIDERMONKEY
39 
40 // forward declarations
41 struct JSRuntime;
42 struct JSContext;
43 struct JSObject;
44 
45 namespace H3D {
46  // forward declaration
47  class Script;
48 
53  public:
56 
60  bool initializeScriptEngine( Script *s );
61 
66  string loadScript( const string &s, const string &filename );
67 
70 
72  inline bool isInitialized() { return rt != NULL; }
73 
77  virtual bool addField( Field *field );
78 
79  protected:
81  JSRuntime *rt;
82 
84  JSContext *cx;
85 
88  JSObject *global;
89 
92 
96  public PeriodicUpdate< EventCollectingField<Field> > {
97  virtual void update();
98  };
99 
106  string fieldNameToCallbackName( const string &n );
107 
110  H3DUniquePtr< CallbackFunctionDispatcher > callbackFunctionDispatcher;
111  };
112 }
113 
114 #endif // HAVE_SPIDERMONKEY
115 #endif
Contains the Field class.
Header file for PeriodicUpdate, template field modifier.
This file contains functions for convertion from a string to a value of an X3D field type.
Header file containing useful functions for conversions of different representations of X3D types.
Header file containing all X3D types enumerated.
The Field class.
Definition: Field.h:46
The PeriodicUpdate is a template modifier that changes the way the field is updated.
Definition: PeriodicUpdate.h:74
No scripting is supported with the Script node yet.
Definition: Script.h:43
The CallbackFunctionDispatcher class handles the calls of the ecmascript callback functions for the f...
Definition: SpiderMonkeySAI.h:96
The SpiderMonkeySAI class is an implementation of the X3D Ecmascript SAI specification using SpiderMo...
Definition: SpiderMonkeySAI.h:52
bool initializeScriptEngine(Script *s)
Initialize the script engine for the given script, adding all types, attributes, functions etc .
Definition: SpiderMonkeySAI.cpp:73
string loadScript(const string &s, const string &filename)
Run the script specified by s.
Definition: SpiderMonkeySAI.cpp:151
JSObject * global
The global object including all global properties and functions.
Definition: SpiderMonkeySAI.h:88
JSContext * cx
The script engine context used.
Definition: SpiderMonkeySAI.h:84
void uninitializeScriptEngine()
Release all resources allocated for the script engine.
Definition: SpiderMonkeySAI.cpp:216
JSRuntime * rt
The script engine runtime used.
Definition: SpiderMonkeySAI.h:81
H3DUniquePtr< CallbackFunctionDispatcher > callbackFunctionDispatcher
Field that handles calling of callback functions as events are received.
Definition: SpiderMonkeySAI.h:110
string fieldNameToCallbackName(const string &n)
Given a field name it returns the name used for the callback function in the global namespace.
Definition: SpiderMonkeySAI.cpp:212
bool isInitialized()
Returns true if the script engine has been initialized.
Definition: SpiderMonkeySAI.h:72
virtual bool addField(Field *field)
Add an interface to a field to the script engine.
Definition: SpiderMonkeySAI.cpp:223
SpiderMonkeySAI()
Constructor.
Definition: SpiderMonkeySAI.cpp:42
Script * script_node
The Script node this script engine is used for,.
Definition: SpiderMonkeySAI.h:91
H3D API namespace.
Definition: Anchor.h:38