Line data Source code
1 : /* 2 : * Copyright (C) 2021-2024 Savoir-faire Linux Inc. 3 : * 4 : * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> 5 : * 6 : * This program is free software; you can redistribute it and/or modify 7 : * it under the terms of the GNU General Public License as published by 8 : * the Free Software Foundation; either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * This program is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU General Public License 17 : * along with this program; if not, write to the Free Software 18 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 : */ 20 : 21 : #pragma once 22 : 23 : #include <dhtnet/multiplexed_socket.h> 24 : 25 : namespace jami { 26 : 27 : using DeviceId = dht::PkId; 28 : using ConnectCb = std::function<void(std::shared_ptr<dhtnet::ChannelSocket>, const DeviceId&)>; 29 : 30 : /** 31 : * A Channel handler is used to make the link between JamiAccount and ConnectionManager 32 : * Its role is to manage channels for a protocol (git/sip/etc) 33 : */ 34 : class ChannelHandlerInterface 35 : { 36 : public: 37 1844 : virtual ~ChannelHandlerInterface() {}; 38 : 39 : /** 40 : * Ask for a new channel 41 : * @param deviceId The device to connect 42 : * @param name The name of the channel 43 : * @param cb The callback to call when connected (can be immediate if already connected) 44 : */ 45 : virtual void connect(const DeviceId& deviceId, const std::string& name, ConnectCb&& cb) 46 : = 0; 47 : 48 : /** 49 : * Determine if we accept or not the request. Called when ConnectionManager receives a request 50 : * @param peer Peer who asked 51 : * @param name The name of the channel 52 : * @return if we accept or not 53 : */ 54 : virtual bool onRequest(const std::shared_ptr<dht::crypto::Certificate>& peer, const std::string& name) = 0; 55 : 56 : /** 57 : * Called when ConnectionManager has a new channel ready 58 : * @param peer Connected peer 59 : * @param name The name of the channel 60 : * @param channel Channel to handle 61 : */ 62 : virtual void onReady(const std::shared_ptr<dht::crypto::Certificate>& peer, 63 : const std::string& name, 64 : std::shared_ptr<dhtnet::ChannelSocket> channel) 65 : = 0; 66 : }; 67 : 68 : } // namespace jami