• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef WEBKIT_GLUE_P2P_TRANSPORT_H_
6 #define WEBKIT_GLUE_P2P_TRANSPORT_H_
7 
8 #include <string>
9 
10 namespace net {
11 class Socket;
12 }  // namespace net
13 
14 namespace webkit_glue {
15 
16 // Interface for P2P transport.
17 class P2PTransport {
18  public:
19   enum State {
20     STATE_NONE = 0,
21     STATE_WRITABLE = 1,
22     STATE_READABLE = 2,
23   };
24 
25   class EventHandler {
26    public:
~EventHandler()27     virtual ~EventHandler() {}
28 
29     // Called for each local candidate.
30     virtual void OnCandidateReady(const std::string& address) = 0;
31 
32     // Called when readable of writable state of the stream changes.
33     virtual void OnStateChange(State state) = 0;
34   };
35 
~P2PTransport()36   virtual ~P2PTransport() {}
37 
38   // Initialize transport using specified configuration. Returns true
39   // if initialization succeeded.
40   virtual bool Init(const std::string& name,
41                     const std::string& config,
42                     EventHandler* event_handler) = 0;
43 
44   // Add candidate received from the remote peer. Returns false if the
45   // provided address is not in a valid format.
46   virtual bool AddRemoteCandidate(const std::string& address) = 0;
47 
48   // Returns socket interface that can be used to send/receive
49   // data. Returned object is owned by the transport. Pending calls on
50   // the socket are canceled when the transport is destroyed.
51   virtual net::Socket* GetChannel() = 0;
52 };
53 
54 }  // namespace webkit_glue
55 
56 #endif  // WEBKIT_GLUE_P2P_TRANSPORT_H_
57