forked from gfwilliams/tiny-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactorRuntime.h
104 lines (80 loc) · 2.79 KB
/
actorRuntime.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* File: actorRuntime.h
* Author: ghernan
*
* Actor system runtime support.
*
* Created on December 24, 2016, 11:50 AM
*/
#ifndef ACTORRUNTIME_H
#define ACTORRUNTIME_H
#pragma once
#include "asActors.h"
#include "jsArray.h"
#include <deque>
struct MvmRoutine;
class FunctionScope;
class CScriptException;
std::pair<ASValue, ASValue > asBlockingExec(Ref<MvmRoutine> code,
Ref<GlobalScope> globals,
CodeMap* pMap);
ASValue actorChildStoppedDefaultHandler(ExecutionContext* ec);
ASValue inputEpCall(Ref<AsEndPointRef> endPoint, Ref<FunctionScope> scope);
ASValue outputEpCall(Ref<AsEndPointRef> endPoint, Ref<FunctionScope> scope);
ASValue actorConstructor(Ref<AsActorClass> actorClass, Ref<FunctionScope> scope);
/**
* Keeps shared state of the actor system.
* It contains the message queue. It only supports single-threaded dispatching
* at this time.
*
* @param rootActor
* @return
*/
class ActorRuntime : public JSObject
{
public:
static Ref<ActorRuntime> create(Ref<AsActorRef> rootActor);
static Ref<ActorRuntime> getRuntime(FunctionScope* fnScope);
//void connectMessages (Ref<AsMessageRef> dst, Ref<AsMessageRef> src);
void sendMessage0(Ref<AsActorRef> dstActor, const std::string& msgName);
void sendMessage1(Ref<AsActorRef> dstActor,
const std::string& msgName,
ASValue p1);
void sendMessage2(Ref<AsActorRef> dstActor,
const std::string& msgName,
ASValue p1,
ASValue p2);
void sendMessage3(Ref<AsActorRef> dstActor,
const std::string& msgName,
ASValue p1,
ASValue p2,
ASValue p3);
void sendMessage(Ref<AsActorRef> dstActor,
const std::string& msgName,
Ref<JSArray> params);
void sendMessage(Ref<AsEndPointRef> dstMessage, Ref<JSArray> params);
void stopActor (Ref<AsActorRef> actorRef, ASValue value, ASValue error);
bool dispatchMessage(CodeMap* pMap);
protected:
void actorCrashed(Ref<AsActorRef> actor, const char* msg);
virtual Ref<JSObject> clone (bool _mutable);
private:
struct SMessage
{
Ref<AsEndPointRef> destination;
Ref<JSArray> params;
SMessage(Ref<AsEndPointRef> _dest, Ref<JSArray> _params) :
destination(_dest), params(_params)
{
}
};
typedef std::deque<SMessage> MessageQueue;
ActorRuntime(Ref<AsActorRef> rootActor)
: JSObject(DefaultClass, MT_DEEPFROZEN)
, m_rootActor(rootActor)
{
}
Ref<AsActorRef> m_rootActor;
MessageQueue m_messageQueue;
};
#endif /* ACTORRUNTIME_H */