2
%% <year>2008-2008</year>
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
17
%% The Initial Developer of the Original Code is Ericsson AB.
20
%%----------------------------------------------------------------------
21
%% Purpose: The ssh subsystem supervisor
22
%%----------------------------------------------------------------------
24
-module(ssh_subsystem_sup).
26
-behaviour(supervisor).
28
-export([start_link/1, connection_supervisor/1, channel_supervisor/1,
29
connection_manager/1]).
31
%% Supervisor callback
34
%%%=========================================================================
36
%%%=========================================================================
38
supervisor:start_link(?MODULE, [Opts]).
40
connection_manager(SubSystemSup) ->
41
ConnectionSup = connection_supervisor(SubSystemSup),
42
ssh_connection_sup:connection_manager(ConnectionSup).
44
connection_supervisor(SupPid) ->
45
Children = supervisor:which_children(SupPid),
46
ssh_connection_sup(Children).
48
channel_supervisor(SupPid) ->
49
Children = supervisor:which_children(SupPid),
50
ssh_channel_sup(Children).
52
%%%=========================================================================
53
%%% Supervisor callback
54
%%%=========================================================================
56
RestartStrategy = one_for_all,
59
Children = child_specs(Opts),
60
{ok, {{RestartStrategy, MaxR, MaxT}, Children}}.
62
%%%=========================================================================
63
%%% Internal functions
64
%%%=========================================================================
66
case proplists:get_value(role, Opts) of
68
[ssh_connectinon_child_spec(Opts)];
70
[ssh_connectinon_child_spec(Opts), ssh_channel_child_spec(Opts)]
73
ssh_connectinon_child_spec(Opts) ->
74
Address = proplists:get_value(address, Opts),
75
Port = proplists:get_value(port, Opts),
76
Role = proplists:get_value(role, Opts),
77
Name = id(Role, ssh_connection_sup, Address, Port),
78
StartFunc = {ssh_connection_sup, start_link, [Opts]},
81
Modules = [ssh_connection_sup],
83
{Name, StartFunc, Restart, Shutdown, Type, Modules}.
85
ssh_channel_child_spec(Opts) ->
86
Address = proplists:get_value(address, Opts),
87
Port = proplists:get_value(port, Opts),
88
Role = proplists:get_value(role, Opts),
89
Name = id(Role, ssh_channel_sup, Address, Port),
90
StartFunc = {ssh_channel_sup, start_link, [Opts]},
93
Modules = [ssh_channel_sup],
95
{Name, StartFunc, Restart, Shutdown, Type, Modules}.
97
id(Role, Sup, Address, Port) ->
98
{Role, Sup, Address, Port}.
100
ssh_connection_sup([{_, Child, _, [ssh_connection_sup]} | _]) ->
102
ssh_connection_sup([_ | Rest]) ->
103
ssh_connection_sup(Rest).
105
ssh_channel_sup([{_, Child, _, [ssh_channel_sup]} | _]) ->
107
ssh_channel_sup([_ | Rest]) ->
108
ssh_channel_sup(Rest).