1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2008-2020. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%% 22 23-module(ssh_channel). 24 25-include("ssh.hrl"). 26-include("ssh_connect.hrl"). 27 28-callback init(Args :: term()) -> 29 {ok, State :: term()} | {ok, State :: term(), timeout() | hibernate} | 30 {stop, Reason :: term()} | ignore. 31-callback handle_call(Request :: term(), From :: {pid(), Tag :: term()}, 32 State :: term()) -> 33 {reply, Reply :: term(), NewState :: term()} | 34 {reply, Reply :: term(), NewState :: term(), timeout() | hibernate} | 35 {noreply, NewState :: term()} | 36 {noreply, NewState :: term(), timeout() | hibernate} | 37 {stop, Reason :: term(), Reply :: term(), NewState :: term()} | 38 {stop, Reason :: term(), NewState :: term()}. 39-callback handle_cast(Request :: term(), State :: term()) -> 40 {noreply, NewState :: term()} | 41 {noreply, NewState :: term(), timeout() | hibernate} | 42 {stop, Reason :: term(), NewState :: term()}. 43 44-callback terminate(Reason :: (normal | shutdown | {shutdown, term()} | 45 term()), 46 State :: term()) -> 47 term(). 48-callback code_change(OldVsn :: (term() | {down, term()}), State :: term(), 49 Extra :: term()) -> 50 {ok, NewState :: term()} | {error, Reason :: term()}. 51 52-callback handle_msg(Msg ::term(), State :: term()) -> 53 {ok, State::term()} | {stop, ChannelId::ssh:channel_id(), State::term()}. 54 55-callback handle_ssh_msg({ssh_cm, ConnectionRef::ssh:connection_ref(), SshMsg::term()}, 56 State::term()) -> {ok, State::term()} | 57 {stop, ChannelId::ssh:channel_id(), 58 State::term()}. 59%%% API 60-export([start/4, start/5, start_link/4, start_link/5, call/2, call/3, 61 init/1, 62 cast/2, reply/2, enter_loop/1]). 63 64%%==================================================================== 65%% API 66%%==================================================================== 67 68call(ChannelPid, Msg) -> 69 ssh_client_channel:call(ChannelPid, Msg). 70 71call(ChannelPid, Msg, TimeOute) -> 72 ssh_client_channel:call(ChannelPid, Msg, TimeOute). 73 74cast(ChannelPid, Msg) -> 75 ssh_client_channel:cast(ChannelPid, Msg). 76 77reply(From, Msg) -> 78 ssh_client_channel:reply(From, Msg). 79 80init(Args) -> 81 ssh_client_channel:init(Args). 82 83start(ConnectionManager, ChannelId, CallBack, CbInitArgs) -> 84 ssh_client_channel:start(ConnectionManager, ChannelId, CallBack, CbInitArgs). 85 86start(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec) -> 87 ssh_client_channel:start(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec). 88 89start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs) -> 90 ssh_client_channel:start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs). 91 92start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec) -> 93 ssh_client_channel:start_link(ConnectionManager, ChannelId, CallBack, CbInitArgs, Exec). 94 95enter_loop(State) -> 96 ssh_client_channel:enter_loop(State). 97