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_SCTP_TRANSPORT_INTERFACE_H_ 12 #define API_SCTP_TRANSPORT_INTERFACE_H_ 13 14 #include "absl/types/optional.h" 15 #include "api/dtls_transport_interface.h" 16 #include "api/rtc_error.h" 17 #include "api/scoped_refptr.h" 18 #include "rtc_base/ref_count.h" 19 20 namespace webrtc { 21 22 // States of a SCTP transport, corresponding to the JS API specification. 23 // http://w3c.github.io/webrtc-pc/#dom-rtcsctptransportstate 24 enum class SctpTransportState { 25 kNew, // Has not started negotiating yet. Non-standard state. 26 kConnecting, // In the process of negotiating an association. 27 kConnected, // Completed negotiation of an association. 28 kClosed, // Closed by local or remote party. 29 kNumValues 30 }; 31 32 // This object gives snapshot information about the changeable state of a 33 // SctpTransport. 34 // It reflects the readonly attributes of the object in the specification. 35 // http://w3c.github.io/webrtc-pc/#rtcsctptransport-interface 36 class RTC_EXPORT SctpTransportInformation { 37 public: 38 SctpTransportInformation() = default; 39 SctpTransportInformation(const SctpTransportInformation&) = default; 40 explicit SctpTransportInformation(SctpTransportState state); 41 SctpTransportInformation( 42 SctpTransportState state, 43 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport, 44 absl::optional<double> max_message_size, 45 absl::optional<int> max_channels); 46 ~SctpTransportInformation(); 47 // The DTLS transport that supports this SCTP transport. dtls_transport()48 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const { 49 return dtls_transport_; 50 } state()51 SctpTransportState state() const { return state_; } MaxMessageSize()52 absl::optional<double> MaxMessageSize() const { return max_message_size_; } MaxChannels()53 absl::optional<int> MaxChannels() const { return max_channels_; } 54 55 private: 56 SctpTransportState state_; 57 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_; 58 absl::optional<double> max_message_size_; 59 absl::optional<int> max_channels_; 60 }; 61 62 class SctpTransportObserverInterface { 63 public: 64 // This callback carries information about the state of the transport. 65 // The argument is a pass-by-value snapshot of the state. 66 // The callback will be called on the network thread. 67 virtual void OnStateChange(SctpTransportInformation info) = 0; 68 69 protected: 70 virtual ~SctpTransportObserverInterface() = default; 71 }; 72 73 // A SCTP transport, as represented to the outside world. 74 // This object is created on the network thread, and can only be 75 // accessed on that thread, except for functions explicitly marked otherwise. 76 // References can be held by other threads, and destruction can therefore 77 // be initiated by other threads. 78 class SctpTransportInterface : public rtc::RefCountInterface { 79 public: 80 // This function can be called from other threads. 81 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0; 82 // Returns information on the state of the SctpTransport. 83 // This function can be called from other threads. 84 virtual SctpTransportInformation Information() const = 0; 85 // Observer management. 86 virtual void RegisterObserver(SctpTransportObserverInterface* observer) = 0; 87 virtual void UnregisterObserver() = 0; 88 }; 89 90 } // namespace webrtc 91 92 #endif // API_SCTP_TRANSPORT_INTERFACE_H_ 93