emqttd_internal.hrl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2012-2016 Feng Lee <feng@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, I),
  18. (begin
  19. case JoinOrLeave of
  20. join -> gproc_pool:connect_worker(Pool, {Pool, Id});
  21. leave -> gproc_pool:disconnect_worker(Pool, {Pool, I})
  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),
  27. tl(tuple_to_list(Rec)))).
  28. -define(record_to_proplist(Def, Rec, Fields),
  29. [{K, V} || {K, V} <- ?record_to_proplist(Def, Rec),
  30. lists:member(K, Fields)]).
  31. -define(UNEXPECTED_REQ(Req, State),
  32. (begin
  33. lager:error("Unexpected Request: ~p", [Req]),
  34. {reply, {error, unexpected_request}, State}
  35. end)).
  36. -define(UNEXPECTED_MSG(Msg, State),
  37. (begin
  38. lager:error("Unexpected Message: ~p", [Msg]),
  39. {noreply, State}
  40. end)).
  41. -define(UNEXPECTED_INFO(Info, State),
  42. (begin
  43. lager:error("Unexpected Info: ~p", [Info]),
  44. {noreply, State}
  45. end)).
  46. -define(IF(Cond, TrueFun, FalseFun),
  47. (case (Cond) of
  48. true -> (TrueFun);
  49. false-> (FalseFun)
  50. end)).