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

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