LCOV - code coverage report
Current view: top level - src/jamidht - channeled_transport.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 2 2 100.0 %
Date: 2024-12-21 08:56:24 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : #pragma once
      18             : 
      19             : #include "noncopyable.h"
      20             : #include "scheduled_executor.h"
      21             : #include "jamidht/abstract_sip_transport.h"
      22             : 
      23             : #include <dhtnet/multiplexed_socket.h>
      24             : 
      25             : #include <atomic>
      26             : #include <condition_variable>
      27             : #include <chrono>
      28             : #include <list>
      29             : #include <memory>
      30             : #include <thread>
      31             : #include <type_traits>
      32             : #include <utility>
      33             : 
      34             : namespace jami {
      35             : 
      36             : using onShutdownCb = std::function<void(void)>;
      37             : 
      38             : namespace tls {
      39             : 
      40             : /**
      41             :  * ChanneledSIPTransport
      42             :  *
      43             :  * Implements a pjsip_transport on top of a ChannelSocket
      44             :  */
      45             : class ChanneledSIPTransport : public AbstractSIPTransport
      46             : {
      47             : public:
      48             :     ChanneledSIPTransport(pjsip_endpoint* endpt,
      49             :                           const std::shared_ptr<dhtnet::ChannelSocket>& socket,
      50             :                           onShutdownCb&& cb);
      51             :     ~ChanneledSIPTransport();
      52             : 
      53             :     /**
      54             :      * Connect callbacks for channeled socket, must be done when the channel is ready to be used
      55             :      */
      56             :     void start();
      57             : 
      58        2736 :     pjsip_transport* getTransportBase() override { return &trData_.base; }
      59             : 
      60         194 :     dhtnet::IpAddr getLocalAddress() const override { return local_; }
      61             : 
      62             : private:
      63             :     NON_COPYABLE(ChanneledSIPTransport);
      64             : 
      65             :     // The SIP transport uses a ChannelSocket to send and receive datas
      66             :     std::shared_ptr<dhtnet::ChannelSocket> socket_ {};
      67             :     onShutdownCb shutdownCb_ {};
      68             :     dhtnet::IpAddr local_ {};
      69             :     dhtnet::IpAddr remote_ {};
      70             : 
      71             :     // PJSIP transport backend
      72             :     TransportData trData_ {}; // uplink to "this" (used by PJSIP called C-callbacks)
      73             : 
      74             :     std::unique_ptr<pj_pool_t, decltype(pj_pool_release)*> pool_;
      75             :     std::unique_ptr<pj_pool_t, decltype(pj_pool_release)*> rxPool_;
      76             :     pjsip_rx_data rdata_ {};
      77             : 
      78             :     pj_status_t send(pjsip_tx_data*, const pj_sockaddr_t*, int, void*, pjsip_transport_callback);
      79             : 
      80             :     // Handle disconnected event
      81             :     std::atomic_bool disconnected_ {false};
      82             : };
      83             : 
      84             : } // namespace tls
      85             : } // namespace jami

Generated by: LCOV version 1.14