source: trunk/FACT++/src/InterpreterV8.h@ 14538

Last change on this file since 14538 was 14527, checked in by tbretz, 12 years ago
Added missing include of list
File size: 5.8 KB
Line 
1#ifndef FACT_InterpreterV8
2#define FACT_InterpreterV8
3
4#include <map>
5#include <list>
6#include <string>
7
8#ifdef HAVE_V8
9#include <v8.h>
10#endif
11
12#include "Description.h"
13#include "EventImp.h"
14
15class Database;
16
17class InterpreterV8
18{
19 static InterpreterV8 *This;
20
21 int fThreadId;
22
23#ifdef HAVE_SQL
24 std::list<Database*> fDatabases;
25#endif
26
27#ifdef HAVE_V8
28 bool ReportException(v8::TryCatch* try_catch);
29 bool ExecuteStringNT(const v8::Handle<v8::String> &code, const v8::Handle<v8::Value> &file);
30 bool ExecuteCode(const v8::Handle<v8::String> &code, const v8::Handle<v8::Value> &file);
31 bool ExecuteCode(const std::string &code, const std::string &file="");
32 bool ExecuteFile(const std::string &name);
33
34 v8::Handle<v8::Value> FuncWait(const v8::Arguments& args);
35 v8::Handle<v8::Value> FuncSend(const v8::Arguments& args);
36 v8::Handle<v8::Value> FuncSleep(const v8::Arguments& args);
37 v8::Handle<v8::Value> FuncPrint(const v8::Arguments& args);
38 v8::Handle<v8::Value> FuncAlarm(const v8::Arguments& args);
39 v8::Handle<v8::Value> FuncOut(const v8::Arguments& args);
40 v8::Handle<v8::Value> FuncInclude(const v8::Arguments& args);
41 v8::Handle<v8::Value> FuncExit(const v8::Arguments& args);
42 v8::Handle<v8::Value> FuncState(const v8::Arguments& args);
43 v8::Handle<v8::Value> FuncOpen(const v8::Arguments& args);
44 v8::Handle<v8::Value> FuncGetData(const v8::Arguments &args);
45 v8::Handle<v8::Value> FuncClose(const v8::Arguments &args);
46 v8::Handle<v8::Value> FuncQuery(const v8::Arguments &args);
47 v8::Handle<v8::Value> FuncDatabase(const v8::Arguments &args);
48 v8::Handle<v8::Value> FuncDbQuery(const v8::Arguments &args);
49 v8::Handle<v8::Value> FuncDbClose(const v8::Arguments &args);
50
51 static v8::Handle<v8::Value> FuncVersion(const v8::Arguments&);
52 static v8::Handle<v8::Value> WrapInclude(const v8::Arguments &args) { if (This) return This->FuncInclude(args); else return v8::Undefined(); }
53 static v8::Handle<v8::Value> WrapPrint(const v8::Arguments &args) { if (This) return This->FuncPrint(args); else return v8::Undefined(); }
54 static v8::Handle<v8::Value> WrapAlarm(const v8::Arguments &args) { if (This) return This->FuncAlarm(args); else return v8::Undefined(); }
55 static v8::Handle<v8::Value> WrapOut(const v8::Arguments &args) { if (This) return This->FuncOut(args); else return v8::Undefined(); }
56 static v8::Handle<v8::Value> WrapWait(const v8::Arguments &args) { if (This) return This->FuncWait(args); else return v8::Undefined(); }
57 static v8::Handle<v8::Value> WrapSend(const v8::Arguments &args) { if (This) return This->FuncSend(args); else return v8::Undefined(); }
58 static v8::Handle<v8::Value> WrapSleep(const v8::Arguments &args) { if (This) return This->FuncSleep(args); else return v8::Undefined(); }
59 static v8::Handle<v8::Value> WrapExit(const v8::Arguments &args) { if (This) return This->FuncExit(args); else return v8::Undefined(); }
60 static v8::Handle<v8::Value> WrapState(const v8::Arguments &args) { if (This) return This->FuncState(args); else return v8::Undefined(); }
61 static v8::Handle<v8::Value> WrapOpen(const v8::Arguments &args) { if (This) return This->FuncOpen(args); else return v8::Undefined(); }
62 static v8::Handle<v8::Value> WrapGetData(const v8::Arguments &args) { if (This) return This->FuncGetData(args); else return v8::Undefined(); }
63 static v8::Handle<v8::Value> WrapClose(const v8::Arguments &args) { if (This) return This->FuncClose(args); else return v8::Undefined(); }
64 static v8::Handle<v8::Value> WrapQuery(const v8::Arguments &args) { if (This) return This->FuncQuery(args); else return v8::Undefined(); }
65 static v8::Handle<v8::Value> WrapDatabase(const v8::Arguments &args) { if (This) return This->FuncDatabase(args); else return v8::Undefined(); }
66 static v8::Handle<v8::Value> WrapDbQuery(const v8::Arguments &args) { if (This) return This->FuncDbQuery(args); else return v8::Undefined(); }
67 static v8::Handle<v8::Value> WrapDbClose(const v8::Arguments &args) { if (This) return This->FuncDbClose(args); else return v8::Undefined(); }
68
69 static v8::Handle<v8::Value> Convert(char type, const char* &ptr);
70#endif
71
72public:
73 InterpreterV8() : fThreadId(-1)
74 {
75 This = this;
76 }
77 virtual ~InterpreterV8()
78 {
79 This = 0;
80#ifdef HAVE_V8
81 v8::V8::Dispose();
82#endif
83 }
84
85 virtual void JsLoad(const std::string &) { }
86 virtual void JsStart(const std::string &) { }
87 virtual void JsEnd(const std::string &) { }
88 virtual void JsPrint(const std::string &) { }
89 virtual void JsAlarm(const std::string & = "") { }
90 virtual void JsOut(const std::string &) { }
91 virtual void JsResult(const std::string &) { }
92 virtual void JsException(const std::string &) { }
93 virtual bool JsSend(const std::string &) { return true; }
94 virtual void JsSleep(uint32_t) { }
95 virtual int JsWait(const std::string &, int32_t, uint32_t) { return -1; };
96 virtual std::pair<int32_t, std::string> JsState(const std::string &) { return std::make_pair(-256, ""); };
97 virtual void *JsSubscribe(const std::string &) { return 0; };
98 virtual bool JsUnsubscribe(const std::string &) { return false; };
99 virtual std::vector<Description> JsDescription(const std::string &) { return std::vector<Description>(); };
100 virtual std::pair<uint64_t, EventImp *> JsGetEvent(const std::string &) { return std::make_pair(0, (EventImp*)0); };
101
102 bool JsRun(const std::string &, const std::map<std::string,std::string> & = std::map<std::string,std::string>());
103 static void JsStop();
104};
105
106#ifndef HAVE_V8
107inline bool InterpreterV8::JsRun(const std::string &, const std::map<std::string,std::string> &) { return false; }
108inline void InterpreterV8::JsStop() { }
109#endif
110
111#endif
Note: See TracBrowser for help on using the repository browser.