emqttd_internal.hrl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. %% Internal Header File
  17. -define(GPROC_POOL(JoinOrLeave, Pool, Id),
  18. (begin
  19. case JoinOrLeave of
  20. join -> gproc_pool:connect_worker(Pool, {Pool, Id});
  21. leave -> gproc_pool:disconnect_worker(Pool, {Pool, Id})
  22. end
  23. end)).
  24. -define(PROC_NAME(M, I), (list_to_atom(lists:concat([M, "_", I])))).
  25. -define(record_to_proplist(Def, Rec),
  26. lists:zip(record_info(fields, Def), tl(tuple_to_list(Rec)))).
  27. -define(record_to_proplist(Def, Rec, Fields),
  28. [{K, V} || {K, V} <- ?record_to_proplist(Def, Rec),
  29. lists:member(K, Fields)]).
  30. -define(UNEXPECTED_REQ(Req, State),
  31. (begin
  32. lager:error("Unexpected Request: ~p", [Req]),
  33. {reply, {error, unexpected_request}, State}
  34. end)).
  35. -define(UNEXPECTED_MSG(Msg, State),
  36. (begin
  37. lager:error("Unexpected Message: ~p", [Msg]),
  38. {noreply, State}
  39. end)).
  40. -define(UNEXPECTED_INFO(Info, State),
  41. (begin
  42. lager:error("Unexpected Info: ~p", [Info]),
  43. {noreply, State}
  44. end)).
  45. -define(IF(Cond, TrueFun, FalseFun),
  46. (case (Cond) of
  47. true -> (TrueFun);
  48. false-> (FalseFun)
  49. end)).
  50. -define(FULLSWEEP_OPTS, [{fullsweep_after, 10}]).