sctp_transport_interface.h 3.4 KB

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