forked from ValckenaersPaul/TAGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
location.erl
46 lines (37 loc) · 1.26 KB
/
location.erl
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
-module(location).
-export([create/2, get_ResInst/1, get_Visitor/1, get_Type/1, arrival/2, departure/1, dispose/1]).
-export([init/2]).
create(ResInst_Pid, LocationTyp_Pid) ->
spawn(?MODULE, init, [ResInst_Pid, LocationTyp_Pid]).
init(ResInst_Pid, LocationTyp_Pid) ->
loop(ResInst_Pid, LocationTyp_Pid, vacant).
get_ResInst(Location_Pid) ->
msg:get(Location_Pid, get_ResInst).
get_Visitor(Location_Pid) ->
msg:get(Location_Pid, get_Visitor).
get_Type(Location_Pid) ->
msg:get(Location_Pid, get_Type).
arrival(Location_Pid, Visitor_Pid) ->
Location_Pid ! {arrived, Visitor_Pid}.
departure(Location_Pid) ->
Location_Pid ! departed.
dispose(Location_Pid) ->
Location_Pid ! remove.
loop(ResInst_Pid, LocationTyp_Pid, Visitor_Pid) ->
receive
{get_ResInst, ReplyFn} ->
ReplyFn(ResInst_Pid),
loop(ResInst_Pid, LocationTyp_Pid, Visitor_Pid);
{get_Visitor, ReplyFn} ->
ReplyFn(Visitor_Pid),
loop(ResInst_Pid, LocationTyp_Pid, Visitor_Pid);
{get_Type, ReplyFn} ->
ReplyFn(LocationTyp_Pid),
loop(ResInst_Pid, LocationTyp_Pid, Visitor_Pid);
{arrived, V_Pid} ->
loop(ResInst_Pid, LocationTyp_Pid, V_Pid);
departed ->
loop(ResInst_Pid, LocationTyp_Pid, vacant);
remove ->
stopped
end.