emqttd_sup.erl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. %% @doc emqttd top supervisor.
  17. -module(emqttd_sup).
  18. -behaviour(supervisor).
  19. -include("emqttd.hrl").
  20. %% API
  21. -export([start_link/0, start_child/1, start_child/2]).
  22. %% Supervisor callbacks
  23. -export([init/1]).
  24. %% Helper macro for declaring children of supervisor
  25. -define(CHILD(Mod, Type), {Mod, {Mod, start_link, []},
  26. permanent, 5000, Type, [Mod]}).
  27. %%--------------------------------------------------------------------
  28. %% API
  29. %%--------------------------------------------------------------------
  30. start_link() ->
  31. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  32. start_child(ChildSpec) when is_tuple(ChildSpec) ->
  33. supervisor:start_child(?MODULE, ChildSpec).
  34. -spec(start_child(Mod::atom(), Type :: worker | supervisor) -> {ok, pid()}).
  35. start_child(Mod, Type) when is_atom(Mod) and is_atom(Type) ->
  36. supervisor:start_child(?MODULE, ?CHILD(Mod, Type)).
  37. %%--------------------------------------------------------------------
  38. %% Supervisor callbacks
  39. %%--------------------------------------------------------------------
  40. init([]) ->
  41. {ok, {{one_for_all, 10, 3600}, []}}.