Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_ICE_TRANSPORT_INTERFACE_H_ |
| 12 | #define API_ICE_TRANSPORT_INTERFACE_H_ |
| 13 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame^] | 14 | #include <string> |
| 15 | |
| 16 | #include "api/async_resolver_factory.h" |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 17 | #include "api/rtc_error.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame^] | 18 | #include "api/rtc_event_log/rtc_event_log.h" |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
| 20 | #include "rtc_base/ref_count.h" |
| 21 | |
| 22 | namespace cricket { |
| 23 | class IceTransportInternal; |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame^] | 24 | class PortAllocator; |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 25 | } // namespace cricket |
| 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | // An ICE transport, as represented to the outside world. |
| 30 | // This object is refcounted, and is therefore alive until the |
| 31 | // last holder has released it. |
| 32 | class IceTransportInterface : public rtc::RefCountInterface { |
| 33 | public: |
| 34 | // Accessor for the internal representation of an ICE transport. |
| 35 | // The returned object can only be safely used on the signalling thread. |
| 36 | // TODO(crbug.com/907849): Add API calls for the functions that have to |
| 37 | // be exposed to clients, and stop allowing access to the |
| 38 | // cricket::IceTransportInternal API. |
| 39 | virtual cricket::IceTransportInternal* internal() = 0; |
| 40 | }; |
| 41 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame^] | 42 | struct IceTransportInit final { |
| 43 | public: |
| 44 | IceTransportInit() = default; |
| 45 | IceTransportInit(const IceTransportInit&) = delete; |
| 46 | IceTransportInit(IceTransportInit&&) = default; |
| 47 | IceTransportInit& operator=(const IceTransportInit&) = delete; |
| 48 | IceTransportInit& operator=(IceTransportInit&&) = default; |
| 49 | |
| 50 | cricket::PortAllocator* port_allocator() { return port_allocator_; } |
| 51 | void set_port_allocator(cricket::PortAllocator* port_allocator) { |
| 52 | port_allocator_ = port_allocator; |
| 53 | } |
| 54 | |
| 55 | AsyncResolverFactory* async_resolver_factory() { |
| 56 | return async_resolver_factory_; |
| 57 | } |
| 58 | void set_async_resolver_factory( |
| 59 | AsyncResolverFactory* async_resolver_factory) { |
| 60 | async_resolver_factory_ = async_resolver_factory; |
| 61 | } |
| 62 | |
| 63 | RtcEventLog* event_log() { return event_log_; } |
| 64 | void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; } |
| 65 | |
| 66 | private: |
| 67 | cricket::PortAllocator* port_allocator_ = nullptr; |
| 68 | AsyncResolverFactory* async_resolver_factory_ = nullptr; |
| 69 | RtcEventLog* event_log_ = nullptr; |
| 70 | }; |
| 71 | |
| 72 | // TODO(qingsi): The factory interface is defined in this file instead of its |
| 73 | // namesake file ice_transport_factory.h to avoid the extra dependency on p2p/ |
| 74 | // introduced there by the p2p/-dependent factory methods. Move the factory |
| 75 | // methods to a different file or rename it. |
| 76 | class IceTransportFactory { |
| 77 | public: |
| 78 | virtual ~IceTransportFactory() = default; |
| 79 | // As a refcounted object, the returned ICE transport may outlive the host |
| 80 | // construct into which its reference is given, e.g. a peer connection. As a |
| 81 | // result, the returned ICE transport should not hold references to any object |
| 82 | // that the transport does not own and that has a lifetime bound to the host |
| 83 | // construct. Also, assumptions on the thread safety of the returned transport |
| 84 | // should be clarified by implementations. For example, a peer connection |
| 85 | // requires the returned transport to be constructed and destroyed on the |
| 86 | // network thread and an ICE transport factory that intends to work with a |
| 87 | // peer connection should offer transports compatible with these assumptions. |
| 88 | virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 89 | const std::string& transport_name, |
| 90 | int component, |
| 91 | IceTransportInit init) = 0; |
| 92 | }; |
| 93 | |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 94 | } // namespace webrtc |
| 95 | #endif // API_ICE_TRANSPORT_INTERFACE_H_ |