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