ice_transport.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 PC_ICE_TRANSPORT_H_
  11. #define PC_ICE_TRANSPORT_H_
  12. #include "api/ice_transport_interface.h"
  13. #include "rtc_base/thread.h"
  14. #include "rtc_base/thread_checker.h"
  15. namespace webrtc {
  16. // Implementation of IceTransportInterface that does not take ownership
  17. // of its underlying IceTransport. It depends on its creator class to
  18. // ensure that Clear() is called before the underlying IceTransport
  19. // is deallocated.
  20. class IceTransportWithPointer : public IceTransportInterface {
  21. public:
  22. explicit IceTransportWithPointer(cricket::IceTransportInternal* internal)
  23. : creator_thread_(rtc::Thread::Current()), internal_(internal) {
  24. RTC_DCHECK(internal_);
  25. }
  26. IceTransportWithPointer() = delete;
  27. IceTransportWithPointer(const IceTransportWithPointer&) = delete;
  28. IceTransportWithPointer& operator=(const IceTransportWithPointer&) = delete;
  29. cricket::IceTransportInternal* internal() override;
  30. // This call will ensure that the pointer passed at construction is
  31. // no longer in use by this object. Later calls to internal() will return
  32. // null.
  33. void Clear();
  34. protected:
  35. ~IceTransportWithPointer() override;
  36. private:
  37. const rtc::Thread* creator_thread_;
  38. cricket::IceTransportInternal* internal_ RTC_GUARDED_BY(creator_thread_);
  39. };
  40. } // namespace webrtc
  41. #endif // PC_ICE_TRANSPORT_H_