• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 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 #include "test/peer_scenario/sdp_callbacks.h"
11 
12 #include <utility>
13 
14 namespace webrtc {
15 namespace test {
16 
SdpSetObserver(std::function<void ()> callback)17 webrtc_sdp_obs_impl::SdpSetObserversInterface* SdpSetObserver(
18     std::function<void()> callback) {
19   class SdpSetObserver : public webrtc_sdp_obs_impl::SdpSetObserversInterface {
20    public:
21     explicit SdpSetObserver(std::function<void()> callback)
22         : callback_(std::move(callback)) {}
23     void OnSuccess() override { callback_(); }
24     void OnFailure(RTCError error) override {
25       RTC_NOTREACHED() << error.message();
26     }
27     void OnSetRemoteDescriptionComplete(RTCError error) override {
28       RTC_CHECK(error.ok()) << error.message();
29       callback_();
30     }
31     std::function<void()> callback_;
32   };
33   return new rtc::RefCountedObject<SdpSetObserver>(std::move(callback));
34 }
35 
SdpCreateObserver(std::function<void (SessionDescriptionInterface *)> callback)36 CreateSessionDescriptionObserver* SdpCreateObserver(
37     std::function<void(SessionDescriptionInterface*)> callback) {
38   class SdpCreateObserver : public CreateSessionDescriptionObserver {
39    public:
40     explicit SdpCreateObserver(decltype(callback) callback)
41         : callback_(std::move(callback)) {}
42     void OnSuccess(SessionDescriptionInterface* desc) override {
43       callback_(desc);
44     }
45     void OnFailure(RTCError error) override {
46       RTC_NOTREACHED() << error.message();
47     }
48     decltype(callback) callback_;
49   };
50   return new rtc::RefCountedObject<SdpCreateObserver>(std::move(callback));
51 }
52 
53 }  // namespace test
54 }  // namespace webrtc
55