n2o.hrl 1.8 KB

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