Skip to content

Commit

Permalink
inets: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
kikofernandez committed Aug 24, 2023
1 parent ada798a commit cb617dc
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions lib/inets/src/inets_app/inets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
%% Description: Starts the inets application. Default type
%% is temporary. see application(3)
%%--------------------------------------------------------------------
start() ->
start() ->
application:ensure_all_started(ssl),
application:start(inets).

start(Type) ->
start(Type) ->
application:ensure_all_started(ssl),
application:start(inets, Type).


Expand Down Expand Up @@ -92,7 +94,7 @@ start(Service, ServiceConfig, How) ->
%%
%% Description: Stops the inets application.
%%--------------------------------------------------------------------
stop() ->
stop() ->
application:stop(inets).


Expand All @@ -104,12 +106,15 @@ stop() ->
%% Description: Stops a started service of the inets application or takes
%% down a stand alone "service" gracefully.
%%--------------------------------------------------------------------
stop(stand_alone, Pid) ->
true = exit(Pid, shutdown),
ok;

stop(Service, Pid) ->
call_service(Service, stop_service, Pid).
application:stop(ssl),
case Service of
stand_alone ->
true = exit(Pid, shutdown),
ok;
_ ->
call_service(Service, stop_service, Pid)
end.


%%--------------------------------------------------------------------
Expand All @@ -119,16 +124,13 @@ stop(Service, Pid) ->
%% Note: Services started with the stand alone option will not be listed
%%--------------------------------------------------------------------
services() ->
try lists:flatten(lists:map(fun(Module) ->
Module:services()
end, service_names())) of
Result ->
Result
catch
exit:{noproc, _} ->
try
lists:flatmap(fun(Module) -> Module:services() end, service_names())
catch
exit:{noproc, _} ->
{error, inets_not_started}
end.


%%--------------------------------------------------------------------
%% Function: services_info() -> [{Service, Pid, Info}]
Expand All @@ -138,20 +140,20 @@ services() ->
%%--------------------------------------------------------------------
services_info() ->
case services() of
{error, inets_not_started} ->
{error, inets_not_started};
Services ->
Fun = fun({Service, Pid}) ->
Info =
case Service:service_info(Pid) of
{ok, PropList} ->
PropList;
{error, Reason} ->
Reason
end,
{Service, Pid, Info}
end,
lists:flatten(lists:map(Fun, Services))
{error, inets_not_started} ->
{error, inets_not_started};
Services ->
Fun = fun({Service, Pid}) ->
Info =
case Service:service_info(Pid) of
{ok, PropList} ->
PropList;
{error, Reason} ->
Reason
end,
{Service, Pid, Info}
end,
lists:flatmap(Fun, Services)
end.


Expand Down Expand Up @@ -434,10 +436,12 @@ report_event(Severity, Label, Service, Content) ->
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
start_service(Service, Args, stand_alone) ->
Service:start_standalone(Args);
start_service(Service, Args, inets) ->
call_service(Service, start_service, Args).
start_service(Service, Args, How) ->
application:ensure_all_started(ssl),
case How of
stand_alone -> Service:start_standalone(Args);
inets -> call_service(Service, start_service, Args)
end.

call_service(Service, Call, Args) ->
try Service:Call(Args) of
Expand Down

0 comments on commit cb617dc

Please sign in to comment.