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