Skip to content

Commit 6daa619

Browse files
committed
UsrInfo field is now also handed in to is_enabled/3.
1 parent c4d0204 commit 6daa619

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/gen_pnet.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144

145145
-callback preset( Trsn :: atom() ) -> [atom()].
146146

147-
-callback is_enabled( Trsn :: atom(), Mode :: #{ atom() => [_]} ) -> boolean().
147+
-callback is_enabled( Trsn :: atom(), Mode :: #{ atom() => [_]}, UsrInfo :: _ ) ->
148+
boolean().
148149

149150
-callback fire( Trsn :: atom(), Mode :: #{ atom() => [_] }, UsrInfo :: _ ) ->
150151
abort | {produce, #{ atom() => [_] }}.
@@ -589,7 +590,7 @@ progress( #net_state{ marking = Marking,
589590
F = fun( T, Acc ) ->
590591
Preset = NetMod:preset( T ),
591592
MLst = enum_mode( Preset, Marking ),
592-
IsEnabled = fun( M ) -> NetMod:is_enabled( T, M ) end,
593+
IsEnabled = fun( M ) -> NetMod:is_enabled( T, M, UsrInfo ) end,
593594
EnabledMLst = lists:filter( IsEnabled, MLst ),
594595
case EnabledMLst of
595596
[] -> Acc;

src/gen_pnet_struct.erl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
%% <li>`trsn_lst/0' returns the names of the transitions in the net</li>
3131
%% <li>`init_marking/2' returns the initial marking for a given place</li>
3232
%% <li>`preset/1' returns the preset places of a given transition</li>
33-
%% <li>`is_enabled/2' determines whether a given transition is enabled in a
33+
%% <li>`is_enabled/3' determines whether a given transition is enabled in a
3434
%% given mode</li>
3535
%% <li>`fire/3' returns which tokens are produced on what places if a given
3636
%% transition is fired in a given mode that enables this transition</li>
@@ -90,16 +90,17 @@
9090
%% Here, we initialize the storage place with three `cookie_box' tokens. All
9191
%% other places are left empty.
9292
%%
93-
%% <h4>is_enabled/2</h4>
93+
%% <h4>is_enabled/3</h4>
9494
%%
95-
%% The `is_enabled/2' function is a predicate determining whether a given
96-
%% transition is enabled in a given mode.
95+
%% The `is_enabled/3' function is a predicate determining whether a given
96+
%% transition is enabled in a given mode. The `UsrInfo' argument is the user
97+
%% info field that has been created with `init/1'.
9798
%%
9899
%% Example:
99100
%% ```
100-
%% is_enabled( a, #{ coin_slot := [coin] } ) -> true;
101-
%% is_enabled( b, #{ signal := [sig], storage := [cookie_box] } ) -> true;
102-
%% is_enabled( _, _ ) -> false.
101+
%% is_enabled( a, #{ coin_slot := [coin] }, _UsrInfo ) -> true;
102+
%% is_enabled( b, #{ signal := [sig], storage := [cookie_box] }, _UsrInfo ) -> true;
103+
%% is_enabled( _Trsn, _Mode, _UsrInfo ) -> false.
103104
%% '''
104105
%% Here, we state that the transition `a' is enabled if it can consume a single
105106
%% `coin' from the `coin_slot' place. Similarly, the transition `b' is enabled
@@ -114,7 +115,7 @@
114115
%% transition fires in a given mode. As arguments it takes the name of the
115116
%% transition, and a firing mode in the form of a hash map mapping place names
116117
%% to token lists. The `fire/3' function is called only on modes for which
117-
%% `is_enabled/2' returns `true'. The `fire/3' function is expected to return
118+
%% `is_enabled/3' returns `true'. The `fire/3' function is expected to return
118119
%% either a `{produce, ProduceMap}' tuple or the term `abort'. If `abort' is
119120
%% returned, the firing is aborted. Nothing is produced or consumed.
120121
%%
@@ -146,7 +147,8 @@
146147

147148
-callback preset( Trsn :: atom() ) -> [atom()].
148149

149-
-callback is_enabled( Trsn :: atom(), Mode :: #{ atom() => [_]} ) -> boolean().
150+
-callback is_enabled( Trsn :: atom(), Mode :: #{ atom() => [_]}, UsrInfo :: _ ) ->
151+
boolean().
150152

151153
-callback fire( Trsn :: atom(), Mode :: #{ atom() => [_] }, UsrInfo :: _ ) ->
152154
abort | {produce, #{ atom() => [_] }}.

0 commit comments

Comments
 (0)