n2o.hrl 1.7 KB

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