script_ecma.H

Go to the documentation of this file.
00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
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

Generated on Sun Jul 30 22:55:50 2006 for Archon by  doxygen 1.4.4