Browse Source

Merge branch 'develop-pid' into develop

develop-optional_stats
Pedram Nimreezi 8 years ago
parent
commit
d35c6a675f
2 changed files with 28 additions and 1 deletions
  1. +25
    -1
      src/glc.erl
  2. +3
    -0
      src/glc_code.erl

+ 25
- 1
src/glc.erl View File

@ -322,6 +322,13 @@ reset_counters(Module) ->
reset_counters(Module, Counter) -> reset_counters(Module, Counter) ->
Module:reset_counters(Counter). Module:reset_counters(Counter).
prepare_store(Store) when not is_list(Store) -> Store;
prepare_store(Store) ->
lists:map(fun({K, V}) when is_pid(V); is_port(V); is_reference(V)
-> {K, {other, binary_to_list(term_to_binary(V))}} ;
({K, V}) -> {K, V}
end, Store).
%% @private Map a query to a module data term. %% @private Map a query to a module data term.
-spec module_data(atom(), term(), term()) -> {ok, #module{}}. -spec module_data(atom(), term(), term()) -> {ok, #module{}}.
module_data(Module, Query, Store) -> module_data(Module, Query, Store) ->
@ -337,7 +344,8 @@ module_data(Module, Query, Store) ->
%% function maps names to registered processes response for those tables. %% function maps names to registered processes response for those tables.
Tables = module_tables(Module), Tables = module_tables(Module),
Query2 = glc_lib:reduce(Query), Query2 = glc_lib:reduce(Query),
{ok, #module{'query'=Query, tables=Tables, qtree=Query2, store=Store}}.
Store2 = prepare_store(Store),
{ok, #module{'query'=Query, tables=Tables, qtree=Query2, store=Store2}}.
%% @private Create a data managed supervised process for params, counter tables %% @private Create a data managed supervised process for params, counter tables
module_tables(Module) -> module_tables(Module) ->
@ -1023,6 +1031,22 @@ events_test_() ->
?assertEqual(1, Mod:info(job_error)), ?assertEqual(1, Mod:info(job_error)),
?assertEqual(b, receive {b=Msg, _Store} -> Msg after 0 -> notcalled end) ?assertEqual(b, receive {b=Msg, _Store} -> Msg after 0 -> notcalled end)
end end
},
{"with pid storage test",
fun() ->
Self = self(),
XPid = spawn(fun() -> receive {msg, Msg, Pid} -> Self ! {Msg, Pid} end end),
Store = [{stored, XPid}],
{compiled, Mod} = setup_query(testmod27,
glc:with(glc:eq(a, 1), fun(Event, _EStore) ->
{ok, Pid} = glc:get(testmod27, stored),
Pid ! {msg, gre:fetch(a, Event), Self}
end),
Store),
glc:handle(Mod, gre:make([{a,1}], [list])),
?assertEqual(1, Mod:info(output)),
?assertEqual(1, receive {Msg, Pid} -> Pid ! Msg after 2 -> notcalled end)
end
} }
] ]
}. }.

+ 3
- 0
src/glc_code.erl View File

@ -203,6 +203,9 @@ abstract_query({any, [{with, _Q, _A}|_] = I}) ->
abstract_query({all, [{with, _Q, _A}|_] = I}) -> abstract_query({all, [{with, _Q, _A}|_] = I}) ->
Queries = glc_lib:reduce(glc:all([Q || {with, Q, _} <- I])), Queries = glc_lib:reduce(glc:all([Q || {with, Q, _} <- I])),
[?erl:abstract(Queries)]; [?erl:abstract(Queries)];
abstract_query({ok, {other, Other}}) ->
SpcBin = abstract_apply(erlang, 'list_to_binary', [?erl:abstract(Other)]),
[?erl:tuple([?erl:atom(ok), abstract_apply(erlang, 'binary_to_term', [SpcBin])])];
abstract_query(Query) -> abstract_query(Query) ->
[?erl:abstract(Query)]. [?erl:abstract(Query)].

Loading…
Cancel
Save