n2o.hrl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. -ifndef(N2O_HRL).
  2. -define(N2O_HRL, true).
  3. -define(FORMAT(F), case F of F when is_binary(F) -> binary_to_list(F);
  4. F when is_atom(F) -> atom_to_list(F);
  5. F when is_list(F) -> F end).
  6. -ifdef(OTP_RELEASE).
  7. -include_lib("kernel/include/logger.hrl").
  8. -else.
  9. -define(LOG_INFO(F), io:format(?FORMAT(F)) end).
  10. -define(LOG_INFO(F,X), io:format(?FORMAT(F),X)).
  11. -define(LOG_ERROR(F), io:format("{~p,~p}: ~p~n", [?MODULE,?LINE,F])).
  12. -define(LOG_ERROR(F,X), io:format(?FORMAT(F),X)).
  13. -endif.
  14. -define(LOG_EXCEPTION(E,R,S), ?LOG_ERROR(#{exception => E, reason => R, stack => S})).
  15. -record(pi, { name :: term(),
  16. table :: atom(),
  17. sup :: atom(),
  18. module :: atom(),
  19. timeout = 5000 :: integer(),
  20. restart = transient :: 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. -define(CTX(ClientId), n2o:cache(ClientId)).
  38. -define(REQ(ClientId), (n2o:cache(ClientId))#cx.req).
  39. % Nitrogen Protocol
  40. -include_lib("nitro/include/proto.hrl").
  41. -endif.