Harald Alvestrand | c85328f | 2019-02-28 06:51:00 | [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_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 |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 36 | class RTC_EXPORT SctpTransportInformation { |
Harald Alvestrand | c85328f | 2019-02-28 06:51:00 | [diff] [blame] | 37 | public: |
| 38 | explicit SctpTransportInformation(SctpTransportState state); |
| 39 | SctpTransportInformation( |
| 40 | SctpTransportState state, |
| 41 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport, |
| 42 | absl::optional<double> max_message_size, |
| 43 | absl::optional<int> max_channels); |
| 44 | ~SctpTransportInformation(); |
| 45 | // The DTLS transport that supports this SCTP transport. |
| 46 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const { |
| 47 | return dtls_transport_; |
| 48 | } |
| 49 | SctpTransportState state() const { return state_; } |
| 50 | absl::optional<double> MaxMessageSize() const { return max_message_size_; } |
| 51 | absl::optional<int> MaxChannels() const { return max_channels_; } |
| 52 | |
| 53 | private: |
| 54 | SctpTransportState state_; |
| 55 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_; |
| 56 | absl::optional<double> max_message_size_; |
| 57 | absl::optional<int> max_channels_; |
| 58 | }; |
| 59 | |
| 60 | class SctpTransportObserverInterface { |
| 61 | public: |
| 62 | // This callback carries information about the state of the transport. |
| 63 | // The argument is a pass-by-value snapshot of the state. |
| 64 | // The callback will be called on the network thread. |
| 65 | virtual void OnStateChange(SctpTransportInformation info) = 0; |
| 66 | |
| 67 | protected: |
| 68 | virtual ~SctpTransportObserverInterface() = default; |
| 69 | }; |
| 70 | |
| 71 | // A SCTP transport, as represented to the outside world. |
| 72 | // This object is created on the network thread, and can only be |
| 73 | // accessed on that thread, except for functions explicitly marked otherwise. |
| 74 | // References can be held by other threads, and destruction can therefore |
| 75 | // be initiated by other threads. |
| 76 | class SctpTransportInterface : public rtc::RefCountInterface { |
| 77 | public: |
| 78 | // This function can be called from other threads. |
| 79 | virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0; |
| 80 | // Returns information on the state of the SctpTransport. |
| 81 | // This function can be called from other threads. |
| 82 | virtual SctpTransportInformation Information() const = 0; |
| 83 | // Observer management. |
| 84 | virtual void RegisterObserver(SctpTransportObserverInterface* observer) = 0; |
| 85 | virtual void UnregisterObserver() = 0; |
| 86 | }; |
| 87 | |
| 88 | } // namespace webrtc |
| 89 | |
| 90 | #endif // API_SCTP_TRANSPORT_INTERFACE_H_ |