You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2011, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  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.
  15. *
  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.
  26. */
  27. #ifndef TALK_P2P_BASE_PORTALLOCATORSESSIONPROXY_H_
  28. #define TALK_P2P_BASE_PORTALLOCATORSESSIONPROXY_H_
  29. #include <string>
  30. #include "talk/p2p/base/candidate.h"
  31. #include "talk/p2p/base/portallocator.h"
  32. namespace cricket {
  33. class PortAllocator;
  34. class PortAllocatorSessionProxy;
  35. class PortProxy;
  36. // This class maintains the list of cricket::Port* objects. Ports will be
  37. // deleted upon receiving SignalDestroyed signal. This class is used when
  38. // PORTALLOCATOR_ENABLE_BUNDLE flag is set.
  39. class PortAllocatorSessionMuxer : public talk_base::MessageHandler,
  40. public sigslot::has_slots<> {
  41. public:
  42. explicit PortAllocatorSessionMuxer(PortAllocatorSession* session);
  43. virtual ~PortAllocatorSessionMuxer();
  44. void RegisterSessionProxy(PortAllocatorSessionProxy* session_proxy);
  45. void OnPortReady(PortAllocatorSession* session, PortInterface* port);
  46. void OnPortDestroyed(PortInterface* port);
  47. void OnCandidatesAllocationDone(PortAllocatorSession* session);
  48. const std::vector<PortInterface*>& ports() { return ports_; }
  49. sigslot::signal1<PortAllocatorSessionMuxer*> SignalDestroyed;
  50. private:
  51. virtual void OnMessage(talk_base::Message *pmsg);
  52. void OnSessionProxyDestroyed(PortAllocatorSession* proxy);
  53. void SendAllocationDone_w(PortAllocatorSessionProxy* proxy);
  54. void SendAllocatedPorts_w(PortAllocatorSessionProxy* proxy);
  55. // Port will be deleted when SignalDestroyed received, otherwise delete
  56. // happens when PortAllocatorSession dtor is called.
  57. talk_base::Thread* worker_thread_;
  58. std::vector<PortInterface*> ports_;
  59. talk_base::scoped_ptr<PortAllocatorSession> session_;
  60. std::vector<PortAllocatorSessionProxy*> session_proxies_;
  61. bool candidate_done_signal_received_;
  62. };
  63. class PortAllocatorSessionProxy : public PortAllocatorSession {
  64. public:
  65. PortAllocatorSessionProxy(const std::string& content_name,
  66. int component,
  67. uint32 flags)
  68. // Use empty string as the ufrag and pwd because the proxy always uses
  69. // the ufrag and pwd from the underlying implementation.
  70. : PortAllocatorSession(content_name, component, "", "", flags),
  71. impl_(NULL) {
  72. }
  73. virtual ~PortAllocatorSessionProxy();
  74. PortAllocatorSession* impl() { return impl_; }
  75. void set_impl(PortAllocatorSession* session);
  76. // Forwards call to the actual PortAllocatorSession.
  77. virtual void GetInitialPorts();
  78. virtual void StartGetAllPorts();
  79. virtual void StopGetAllPorts();
  80. virtual bool IsGettingAllPorts();
  81. virtual void set_generation(uint32 generation) {
  82. ASSERT(impl_ != NULL);
  83. impl_->set_generation(generation);
  84. }
  85. virtual uint32 generation() {
  86. ASSERT(impl_ != NULL);
  87. return impl_->generation();
  88. }
  89. private:
  90. void OnPortReady(PortAllocatorSession* session, PortInterface* port);
  91. void OnCandidatesReady(PortAllocatorSession* session,
  92. const std::vector<Candidate>& candidates);
  93. void OnPortDestroyed(PortInterface* port);
  94. void OnCandidatesAllocationDone(PortAllocatorSession* session);
  95. // This is the actual PortAllocatorSession, owned by PortAllocator.
  96. PortAllocatorSession* impl_;
  97. std::map<PortInterface*, PortProxy*> proxy_ports_;
  98. friend class PortAllocatorSessionMuxer;
  99. };
  100. } // namespace cricket
  101. #endif // TALK_P2P_BASE_PORTALLOCATORSESSIONPROXY_H_