Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / p2p / base / portproxy.h
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
28 #ifndef TALK_P2P_BASE_PORTPROXY_H_
29 #define TALK_P2P_BASE_PORTPROXY_H_
30
31 #include "talk/base/sigslot.h"
32 #include "talk/p2p/base/portinterface.h"
33
34 namespace talk_base {
35 class Network;
36 }
37
38 namespace cricket {
39
40 class PortProxy : public PortInterface, public sigslot::has_slots<> {
41  public:
42   PortProxy() {}
43   virtual ~PortProxy() {}
44
45   PortInterface* impl() { return impl_; }
46   void set_impl(PortInterface* port);
47
48   virtual const std::string& Type() const;
49   virtual talk_base::Network* Network() const;
50
51   virtual void SetIceProtocolType(IceProtocolType protocol);
52   virtual IceProtocolType IceProtocol() const;
53
54   // Methods to set/get ICE role and tiebreaker values.
55   virtual void SetIceRole(IceRole role);
56   virtual IceRole GetIceRole() const;
57
58   virtual void SetIceTiebreaker(uint64 tiebreaker);
59   virtual uint64 IceTiebreaker() const;
60
61   virtual bool SharedSocket() const;
62
63   // Forwards call to the actual Port.
64   virtual void PrepareAddress();
65   virtual Connection* CreateConnection(const Candidate& remote_candidate,
66                                        CandidateOrigin origin);
67   virtual Connection* GetConnection(
68       const talk_base::SocketAddress& remote_addr);
69
70   virtual int SendTo(const void* data, size_t size,
71                      const talk_base::SocketAddress& addr,
72                      const talk_base::PacketOptions& options,
73                      bool payload);
74   virtual int SetOption(talk_base::Socket::Option opt, int value);
75   virtual int GetOption(talk_base::Socket::Option opt, int* value);
76   virtual int GetError();
77
78   virtual const std::vector<Candidate>& Candidates() const;
79
80   virtual void SendBindingResponse(StunMessage* request,
81                                    const talk_base::SocketAddress& addr);
82   virtual void SendBindingErrorResponse(
83         StunMessage* request, const talk_base::SocketAddress& addr,
84         int error_code, const std::string& reason);
85
86   virtual void EnablePortPackets();
87   virtual std::string ToString() const;
88
89  private:
90   void OnUnknownAddress(PortInterface *port,
91                         const talk_base::SocketAddress &addr,
92                         ProtocolType proto,
93                         IceMessage *stun_msg,
94                         const std::string &remote_username,
95                         bool port_muxed);
96   void OnRoleConflict(PortInterface* port);
97   void OnPortDestroyed(PortInterface* port);
98
99   PortInterface* impl_;
100 };
101
102 }  // namespace cricket
103
104 #endif  // TALK_P2P_BASE_PORTPROXY_H_