81
81
%%----------------------------------------------------------------------
83
parse(DigitMapBody) when list(DigitMapBody) ->
83
parse(DigitMapBody) when is_list(DigitMapBody) ->
84
84
?d("parse -> entry with"
85
85
"~n DigitMapBody: ~p", [DigitMapBody]),
86
86
case parse_digit_map(DigitMapBody) of
115
115
"~n DS: ~p", [Chars, DS]),
116
116
case megaco_text_scanner:skip_sep_chars(Chars, Line) of
117
{[], _Line2} when DS /= [] ->
117
{[], _Line2} when (DS =/= []) ->
118
118
case parse_digit_string(DS) of
120
120
ST = #state_transition{mode = state_dependent,
128
128
{[Char | Chars2], Line2} ->
130
$( when DS == [], STL == [] ->
130
$( when (DS =:= []) andalso (STL =:= []) ->
131
131
parse_digit_map(Chars2, Line2, DS, STL);
132
$) when (DS =/= []) ->
133
133
case megaco_text_scanner:skip_sep_chars(Chars2, Line2) of
135
135
case parse_digit_string(DS) of
146
146
Trash = lists:reverse(Chars3),
147
147
{error, {round_bracket_mismatch, Trash, Line3}}
149
$| when (DS =/= []) ->
150
150
case parse_digit_string(DS) of
152
152
ST = #state_transition{mode = state_dependent,
156
156
{error, Reason} ->
159
_ when Char /= $(, Char /= $|, Char /= $) ->
159
_ when ( Char =/= $( ) andalso
160
( Char =/= $| ) andalso
160
162
parse_digit_map(Chars2, Line2, [Char | DS], STL);
162
164
{error, {round_bracket_mismatch, Line2}}
186
188
parse_digit_string(Chars, [zero_or_more | DS]);
188
I when I >= $0, I =< $9 ->
190
I when (I >= $0) andalso (I =< $9) ->
189
191
parse_digit_string(Chars, [{single, I} | DS]);
191
A when A >= $a, A =< $k ->
193
A when (A >= $a) andalso (A =< $k) ->
192
194
parse_digit_string(Chars, [{single, A} | DS]);
193
A when A >= $A, A =< $K ->
195
A when (A >= $A) andalso (A =< $K) ->
194
196
parse_digit_string(Chars, [{single, A} | DS]);
230
232
"~n DS: ~p", [[Char], Chars, DL, DS]),
233
parse_digit_string(Chars, [DL | DS]);
235
parse_digit_string(Chars, [{letter, DL} | DS]);
235
237
{error, square_bracket_mismatch};
236
To when To >= $0, To =< $9 ->
238
To when (To >= $0) andalso (To =< $9) ->
238
[$-, From | Chars2] when From >= $0, From =< $9 ->
240
[$-, From | Chars2] when (From >= $0) andalso (From =< $9) ->
239
241
parse_digit_letter(Chars2, [{range, From, To} | DL], DS);
241
243
parse_digit_letter(Chars, [{single, To} | DL], DS)
244
A when A >= $a, A =< $k ->
246
A when (A >= $a) andalso (A =< $k) ->
245
247
parse_digit_letter(Chars, [{single, A} | DL], DS);
246
A when A >= $A, A =< $K ->
248
A when (A >= $A) andalso (A =< $K) ->
247
249
parse_digit_letter(Chars, [{single, A} | DL], DS);
273
275
%% Returns {ok, Letters} | {error, Reason}
274
276
%%----------------------------------------------------------------------
276
eval(DMV) when record(DMV, 'DigitMapValue') ->
278
eval(DMV) when is_record(DMV, 'DigitMapValue') ->
277
279
case parse(DMV#'DigitMapValue'.digitMapBody) of
278
280
{ok, DigitMapBody} ->
279
281
eval(DigitMapBody, DMV);
280
282
{error, Reason} ->
283
eval(STL) when list(STL) ->
285
eval(STL) when is_list(STL) ->
284
286
eval(STL, #timers{}).
286
288
eval(STL, #'DigitMapValue'{startTimer = Start,
312
314
duration = duration_to_millis(Duration),
313
315
unexpected = reject},
314
316
eval(STL, Timers);
315
eval(STL, Timers) when list(STL),
316
record(hd(STL), state_transition),
317
record(Timers, timers) ->
317
eval(STL, Timers) when is_list(STL) andalso
318
is_record(hd(STL), state_transition) andalso
319
is_record(Timers, timers) ->
318
320
?d("eval -> entry with"
320
322
"~n Timers: ~p", [STL, Timers]),
458
460
"~n STL2: ~p", [Collect, KeepDur, STL2]),
460
[] when State == optional_event -> % 7.1.14.5 5
462
[] when (State =:= optional_event) -> % 7.1.14.5 5
461
463
?d("handle_event -> complete-full with event - 7.1.14.5 5", []),
462
464
{completed_full, Timers, [], {Letters, Event}};
463
[] when Timers#timers.unexpected == ignore ->
465
[] when (Timers#timers.unexpected =:= ignore) ->
464
466
ok = io:format("<WARNING> Ignoring unexpected event: ~p~n"
465
467
"Expected: ~p~n",
467
469
{State, Timers, STL, Letters};
468
[] when Timers#timers.unexpected == reject ->
470
[] when (Timers#timers.unexpected =:= reject) ->
469
471
?d("handle_event -> unexpected (reject)", []),
470
472
unexpected_event(Event, STL, Letters);
476
478
"~n STL3: ~p", [State3, Timers2, STL3]),
478
true when KeepDur == true ->
480
true when (KeepDur =:= true) ->
479
481
{State3, Timers2, STL3, [Event | Letters]};
494
496
match_event(Event, STL, [], false, false, MatchingDuration).
496
498
match_event(Event, [ST | OldSTL], NewSTL, Collect, KeepDur, MatchingDuration)
497
when record(ST, state_transition) ->
499
when is_record(ST, state_transition) ->
498
500
?d("match_event -> entry with"
508
510
?d("match_event -> keep ST (1)", []),
509
511
match_event(Event, OldSTL, [ST | NewSTL], true, KeepDur,
510
512
MatchingDuration);
511
{single, Single} when (Event == {long, Single}) and
512
(MatchingDuration == false) ->
514
{single, Single} when (Event =:= {long, Single}) andalso
515
(MatchingDuration =:= false) ->
513
516
%% Chap 7.1.14.5 point 4
514
517
?d("match_event -> keep ST - change to ordinary event (2)", []),
515
518
match_event(Event, OldSTL, [ST | NewSTL], true, KeepDur,
516
519
MatchingDuration);
518
{range, From, To} when Event >= From, Event =< To ->
521
{range, From, To} when (Event >= From) andalso (Event =< To) ->
519
522
?d("match_event -> keep ST (3)", []),
520
523
ST2 = ST#state_transition{next = {single, Event}},
521
524
match_event(Event, OldSTL, [ST2 | NewSTL], true, KeepDur,
524
527
{range, From, To} ->
526
{long, R} when (R >= From) and (R =< To) and (MatchingDuration == false) ->
529
{long, R} when (R >= From) andalso
531
(MatchingDuration =:= false) ->
527
532
?d("match_event -> keep ST (4)", []),
528
533
ST2 = ST#state_transition{next = {single, R}},
529
534
match_event(Event, OldSTL, [ST2 | NewSTL], true, true,
530
535
MatchingDuration);
532
?d("match_event -> drop ST - change to ordinary event (5)", []),
537
?d("match_event -> drop ST - "
538
"change to ordinary event (5)", []),
533
539
match_event(Event, OldSTL, NewSTL, Collect, KeepDur,
534
540
MatchingDuration)
537
{duration_event, {single, Single}} when Event == {long, Single} ->
543
{duration_event, {single, Single}} when (Event =:= {long, Single}) ->
538
544
?d("match_event -> keep ST (5)", []),
539
545
match_event(Event, OldSTL, [ST | NewSTL], true, true,
540
546
MatchingDuration);
542
548
{duration_event, {range, From, To}} ->
544
{long, R} when R >= From, R =< To ->
550
{long, R} when (R >= From) andalso (R =< To) ->
545
551
?d("match_event -> keep ST (6)", []),
546
552
match_event(Event, OldSTL, [ST | NewSTL], true, true,
547
553
MatchingDuration);
556
562
match_event(Event, OldSTL, [ST | NewSTL], Collect, KeepDur,
557
563
MatchingDuration);
566
case match_letter(Event, Letters, MatchingDuration) of
567
{true, ChangedEvent} ->
568
?d("match_event -> keep ST (9)", []),
569
ST2 = ST#state_transition{next = ChangedEvent},
570
match_event(Event, OldSTL, [ST2 | NewSTL], true, KeepDur,
573
?d("match_event -> keep ST (10)", []),
574
match_event(Event, OldSTL, [ST | NewSTL], true, KeepDur,
577
?d("match_event -> drop ST (11)", []),
578
match_event(Event, OldSTL, NewSTL, Collect, KeepDur,
560
?d("match_event -> drop ST (9)", []),
583
?d("match_event -> drop ST (12)", []),
561
584
match_event(Event, OldSTL, NewSTL, Collect, KeepDur,
562
585
MatchingDuration)
564
587
match_event(Event, [H | T], NewSTL, Collect, KeepDur0, MatchingDuration)
566
589
?d("match_event -> entry with"
573
596
[Event, H, NewSTL, Collect, KeepDur0, MatchingDuration]),
574
597
{NewSTL2, _Letters, KeepDur} =
575
598
match_event(Event, H, NewSTL, Collect, KeepDur0, MatchingDuration),
577
600
"~n NewSTLs: ~p", [NewSTL2]),
578
601
match_event(Event, T, NewSTL2, Collect, KeepDur,
579
602
MatchingDuration);
585
608
{lists:reverse(NewSTL), Collect, KeepDur}.
611
match_letter(_Event, [], _MatchingDuration) ->
613
match_letter(Event, [Letter | Letters], MatchingDuration) ->
614
?d("match_letter -> entry with"
620
?d("match_letter -> keep ST (1)", []),
623
{single, Single} when (Event =:= {long, Single}) andalso
624
(MatchingDuration =:= false) ->
625
%% Chap 7.1.14.5 point 4
626
?d("match_letter -> keep ST - change to ordinary event (2)", []),
629
{range, From, To} when (Event >= From) andalso (Event =< To) ->
630
?d("match_letter -> keep ST (3)", []),
631
{true, {single, Event}};
635
{long, R} when (R >= From) andalso
637
(MatchingDuration =:= false) ->
638
?d("match_letter -> keep ST (4)", []),
641
?d("match_letter -> drop ST - "
642
"change to ordinary event (5)", []),
643
match_letter(Event, Letters, MatchingDuration)
646
{duration_event, {single, Single}} when (Event =:= {long, Single}) ->
647
?d("match_letter -> keep ST (5)", []),
650
{duration_event, {range, From, To}} ->
652
{long, R} when (R >= From) andalso (R =< To) ->
653
?d("match_letter -> keep ST (6)", []),
656
?d("match_letter -> drop ST (7)", []),
657
match_letter(Event, Letters, MatchingDuration)
661
?d("match_letter -> drop ST (8)", []),
662
match_letter(Event, Letters, MatchingDuration)
588
669
matching_duration_event({long, Event}, STL) ->
589
670
Nexts = [Next || #state_transition{next = Next} <- STL],
590
671
mde(Event, Nexts);
623
704
{State, Timers2, NewSTL}.
625
706
compute(State, GlobalMode, [ST | OldSTL], NewSTL)
626
when record(ST, state_transition) ->
707
when is_record(ST, state_transition) ->
627
708
?d("compute(~w) -> entry with"
628
709
"~n GlobalMode: ~p"
633
714
{State2, GlobalMode2, NewSTL2} =
634
715
compute_cont(Cont, Mode, GlobalMode, State, NewSTL),
635
716
compute(State2, GlobalMode2, OldSTL, NewSTL2);
636
compute(State, GlobalMode, [H | T], NewSTL) when list(H) ->
717
compute(State, GlobalMode, [H | T], NewSTL) when is_list(H) ->
637
718
?d("compute(~w) -> entry with"
638
719
"~n GlobalMode: ~p"
656
737
"~n GlobalMode: ~p", [Next, Mode, GlobalMode]),
658
739
%% Retain long timer if that has already been choosen
659
use_short_timer when GlobalMode == use_long_timer ->
740
use_short_timer when GlobalMode =:= use_long_timer ->
660
741
compute_cont(Cont, Mode, GlobalMode, State, STL);
661
742
use_short_timer ->
662
743
Mode2 = use_short_timer,
717
798
report(_Pid, [])->
719
report(Pid, Event) when pid(Pid) ->
800
report(Pid, Event) when is_pid(Pid) ->
721
802
I when I >= $0, I =< $9 -> cast(Pid, Event);
722
803
A when A >= $a, A =< $k -> cast(Pid, Event);