00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00033 #ifndef ARCHON_X3D_SCRIPT_ECMA_H
00034 #define ARCHON_X3D_SCRIPT_ECMA_H
00035
00036 #define XP_UNIX
00037 #define DEBUG
00038 #include <jsapi.h>
00039
00040 #include <archon/x3d/server/custom_field.H>
00041 #include <archon/x3d/server/script.H>
00042
00043 namespace Archon
00044 {
00045 namespace X3D
00046 {
00047 namespace ECMA
00048 {
00049 struct Engine: Script::Engine
00050 {
00054 Engine(Script *containingNode, string sourceCode,
00055 string sourceName, int sourceLine);
00056 ~Engine();
00057
00058 struct ValueConverterBase
00059 {
00060 virtual bool fieldWrite(JSContext *, jsval, NodeBase *,
00061 const FieldBase *, Time) const = 0;
00062 virtual void fieldRead(NodeBase *, const FieldBase *,
00063 JSContext *, jsval *) const = 0;
00064 virtual ~ValueConverterBase() {}
00065 };
00066
00067 Script *const containingNode;
00068
00069 string getSourceName() const { return sourceName; }
00070
00071 struct Field
00072 {
00073 const ValueConverterBase *valueConverter;
00074 jsval handler;
00075 Field(const ValueConverterBase *valueConverter):
00076 valueConverter(valueConverter), handler(JSVAL_NULL) {}
00077 };
00078
00079 Field *getField(int i) { return &fields[i]; }
00080
00081 private:
00082 string sourceName;
00083 JSRuntime *spiderMonkeyRuntime;
00084 JSContext *spiderMonkeyContext;
00085
00086 vector<Field> fields;
00087
00088 static JSBool getCustomField(JSContext *, JSObject *, jsval, jsval *);
00089 static JSBool setCustomField(JSContext *, JSObject *, jsval, jsval *);
00090
00091 void handleEvent(int fieldIndex, Time timestamp);
00092 };
00093 }
00094 }
00095 }
00096
00097 #endif // ARCHON_X3D_SCRIPT_ECMA_H