add reg_name/2 function

This commit is contained in:
Feng 2016-01-17 19:59:05 +08:00
parent 2544786c56
commit 0a29c8760e
1 changed files with 8 additions and 3 deletions

View File

@ -30,6 +30,9 @@
load_all_mods/0, is_mod_enabled/1,
is_running/1]).
%% Utility functions.
-export([reg_name/2]).
-define(MQTT_SOCKOPTS, [
binary,
{packet, raw},
@ -122,10 +125,8 @@ load_mod({Name, Opts}) ->
is_mod_enabled(Name) ->
env(modules, Name) =/= undefined.
%%------------------------------------------------------------------------------
%% @doc Is running?
%% @end
%%------------------------------------------------------------------------------
-spec is_running(node()) -> boolean().
is_running(Node) ->
case rpc:call(Node, erlang, whereis, [?APP]) of
{badrpc, _} -> false;
@ -133,3 +134,7 @@ is_running(Node) ->
Pid when is_pid(Pid) -> true
end.
-spec reg_name(module(), pos_integer()) -> atom().
reg_name(M, Id) when is_atom(M), is_integer(Id) ->
list_to_atom(lists:concat([M, "_", Id])).