3 * Copyright 2004--2011, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef WEBRTC_P2P_BASE_PORTALLOCATORSESSIONPROXY_H_
29 #define WEBRTC_P2P_BASE_PORTALLOCATORSESSIONPROXY_H_
33 #include "webrtc/p2p/base/candidate.h"
34 #include "webrtc/p2p/base/portallocator.h"
38 class PortAllocatorSessionProxy;
41 // This class maintains the list of cricket::Port* objects. Ports will be
42 // deleted upon receiving SignalDestroyed signal. This class is used when
43 // PORTALLOCATOR_ENABLE_BUNDLE flag is set.
45 class PortAllocatorSessionMuxer : public rtc::MessageHandler,
46 public sigslot::has_slots<> {
48 explicit PortAllocatorSessionMuxer(PortAllocatorSession* session);
49 virtual ~PortAllocatorSessionMuxer();
51 void RegisterSessionProxy(PortAllocatorSessionProxy* session_proxy);
53 void OnPortReady(PortAllocatorSession* session, PortInterface* port);
54 void OnPortDestroyed(PortInterface* port);
55 void OnCandidatesAllocationDone(PortAllocatorSession* session);
57 const std::vector<PortInterface*>& ports() { return ports_; }
59 sigslot::signal1<PortAllocatorSessionMuxer*> SignalDestroyed;
62 virtual void OnMessage(rtc::Message *pmsg);
63 void OnSessionProxyDestroyed(PortAllocatorSession* proxy);
64 void SendAllocationDone_w(PortAllocatorSessionProxy* proxy);
65 void SendAllocatedPorts_w(PortAllocatorSessionProxy* proxy);
67 // Port will be deleted when SignalDestroyed received, otherwise delete
68 // happens when PortAllocatorSession dtor is called.
69 rtc::Thread* worker_thread_;
70 std::vector<PortInterface*> ports_;
71 rtc::scoped_ptr<PortAllocatorSession> session_;
72 std::vector<PortAllocatorSessionProxy*> session_proxies_;
73 bool candidate_done_signal_received_;
76 class PortAllocatorSessionProxy : public PortAllocatorSession {
78 PortAllocatorSessionProxy(const std::string& content_name,
81 // Use empty string as the ufrag and pwd because the proxy always uses
82 // the ufrag and pwd from the underlying implementation.
83 : PortAllocatorSession(content_name, component, "", "", flags),
87 virtual ~PortAllocatorSessionProxy();
89 PortAllocatorSession* impl() { return impl_; }
90 void set_impl(PortAllocatorSession* session);
92 // Forwards call to the actual PortAllocatorSession.
93 virtual void StartGettingPorts();
94 virtual void StopGettingPorts();
95 virtual bool IsGettingPorts();
97 virtual void set_generation(uint32 generation) {
98 ASSERT(impl_ != NULL);
99 impl_->set_generation(generation);
102 virtual uint32 generation() {
103 ASSERT(impl_ != NULL);
104 return impl_->generation();
108 void OnPortReady(PortAllocatorSession* session, PortInterface* port);
109 void OnCandidatesReady(PortAllocatorSession* session,
110 const std::vector<Candidate>& candidates);
111 void OnPortDestroyed(PortInterface* port);
112 void OnCandidatesAllocationDone(PortAllocatorSession* session);
114 // This is the actual PortAllocatorSession, owned by PortAllocator.
115 PortAllocatorSession* impl_;
116 std::map<PortInterface*, PortProxy*> proxy_ports_;
118 friend class PortAllocatorSessionMuxer;
121 } // namespace cricket
123 #endif // WEBRTC_P2P_BASE_PORTALLOCATORSESSIONPROXY_H_