summaryrefslogtreecommitdiffstats
path: root/src/uscxml/datamodel/ecmascript/v8/V8DataModel.h
blob: 340b6eef099490edac602cb7f56c700d3ef54c7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef V8DATAMODEL_H_KN8TWG0V
#define V8DATAMODEL_H_KN8TWG0V

#include "uscxml/Interpreter.h"
#include <list>
#include <v8.h>

namespace uscxml {
   class Event;
   class Data;
}

namespace uscxml {

class V8DataModel : public DataModel {
public:
  V8DataModel();
  virtual ~V8DataModel();
  virtual DataModel* create(Interpreter* interpreter);
  
  virtual void initialize();
  virtual void setSessionId(const std::string& sessionId);
  virtual void setName(const std::string& name);
  virtual void setEvent(const Event& event);

  virtual bool validate(const std::string& location, const std::string& schema);

  virtual uint32_t getLength(const std::string& expr);
  virtual void pushContext();
  virtual void popContext();

  virtual void eval(const std::string& expr);
  virtual void assign(const std::string& location, const std::string& expr);
  virtual void assign(const std::string& location, const Data& data);

  virtual std::string evalAsString(const std::string& expr);
  virtual bool evalAsBool(const std::string& expr);

  static v8::Handle<v8::Value> jsGetEventName(v8::Local<v8::String> property,
                                            const v8::AccessorInfo &info);
  static v8::Handle<v8::Value> jsGetEventType(v8::Local<v8::String> property,
                                            const v8::AccessorInfo &info);
  static v8::Handle<v8::Value> jsGetEventSendId(v8::Local<v8::String> property,
                                              const v8::AccessorInfo &info);
  static v8::Handle<v8::Value> jsGetEventOrigin(v8::Local<v8::String> property,
                                              const v8::AccessorInfo &info);
  static v8::Handle<v8::Value> jsGetEventOriginType(v8::Local<v8::String> property,
                                                  const v8::AccessorInfo &info);
  static v8::Handle<v8::Value> jsGetEventInvokeId(v8::Local<v8::String> property,
                                                const v8::AccessorInfo &info);

  static v8::Handle<v8::Value> jsIn(const v8::Arguments& args);


protected:
  std::list<v8::Persistent<v8::Context> > _contexts;
  Interpreter* _interpreter;

	std::string _sessionId;
	std::string _name;
  
  Event _event;
  v8::Persistent<v8::ObjectTemplate> _globalTemplate;
  v8::Persistent<v8::ObjectTemplate> _eventTemplate;

  v8::Handle<v8::Value> evalAsValue(const std::string& expr);
  virtual v8::Handle<v8::Value> getDataAsValue(const Data& data);

};

}

#endif /* end of include guard: V8DATAMODEL_H_KN8TWG0V */