n2o.hrl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. state :: term() }).
  20. -record(cx, { handlers = [] :: list({atom(),atom()}),
  21. actions = [] :: list(tuple()),
  22. req = [] :: [] | term(),
  23. module = [] :: [] | atom() | list(),
  24. lang = [] :: [] | atom(),
  25. path = [] :: [] | binary(),
  26. session = [] :: [] | binary(),
  27. token = [] :: [] | binary(),
  28. formatter = bert :: bert | json | atom(),
  29. params = [] :: [] | list(tuple()) | binary() | list(),
  30. node = [] :: [] | atom() | list(),
  31. client_pid= [] :: [] | term(),
  32. state = [] :: [] | term(),
  33. from = [] :: [] | binary(),
  34. vsn = [] :: [] | binary() }).
  35. -define(CTX(ClientId), n2o:cache(ClientId)).
  36. -define(REQ(ClientId), (n2o:cache(ClientId))#cx.req).
  37. % Nitrogen Protocol
  38. -record(client, { data=[] }).
  39. -record(server, { data=[] }).
  40. -record(init, { token=[] }).
  41. -record(pickle, { source=[], pickled=[], args=[] }).
  42. -record(flush, { data=[] }).
  43. -record(direct, { data=[] }).
  44. -record(ev, { module=[], msg=[], trigger=[], name=[] }).
  45. -endif.