n2z.hrl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. -ifndef(N2Z_HRL).
  2. -define(N2Z_HRL, true).
  3. -define(FORMAT(F),
  4. case F of
  5. F when erlang:is_binary(F) ->
  6. erlang:binary_to_list(F);
  7. F when erlang:is_atom(F) ->
  8. erlang:atom_to_list(F);
  9. F when erlang:is_list(F) ->
  10. F
  11. end).
  12. -ifdef(OTP_RELEASE).
  13. -include_lib("kernel/include/logger.hrl").
  14. -else.
  15. -define(LOG_INFO(F), io:format(?FORMAT(F)) end).
  16. -define(LOG_INFO(F, X), io:format(?FORMAT(F), X)).
  17. -define(LOG_ERROR(F), io:format("{~p,~p}: ~p~n", [?MODULE, ?LINE, F])).
  18. -define(LOG_ERROR(F, X), io:format(?FORMAT(F), X)).
  19. -endif.
  20. -define(LOG_EXCEPTION(E, R, S), ?LOG_ERROR(#{exception => E, reason => R, stack => S})).
  21. -record(pi, { name :: term(),
  22. table :: atom(),
  23. sup :: atom(),
  24. module :: atom(),
  25. state :: term() }).
  26. -record(cx, { handlers = [] :: list({atom(),atom()}),
  27. actions = [] :: list(tuple()),
  28. req = [] :: [] | term(),
  29. module = [] :: [] | atom() | list(),
  30. lang = [] :: [] | atom(),
  31. path = [] :: [] | binary(),
  32. session = [] :: [] | binary(),
  33. token = [] :: [] | binary(),
  34. formatter = bert :: bert | json | atom(),
  35. params = [] :: [] | list(tuple()) | binary() | list(),
  36. 'node' = [] :: [] | atom() | list(),
  37. client_pid= [] :: [] | term(),
  38. state = [] :: [] | term(),
  39. from = [] :: [] | binary(),
  40. vsn = [] :: [] | binary() }).
  41. -define(CTX(ClientId), n2z:cache(ClientId)).
  42. -define(REQ(ClientId), (n2z:cache(ClientId))#cx.req).
  43. % Nitrogen Protocol
  44. -include_lib("nitro/include/proto.hrl").
  45. -endif.