3
* Copyright 2004--2005, 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 TALK_P2P_BASE_TRANSPORTCHANNEL_H_
29
#define TALK_P2P_BASE_TRANSPORTCHANNEL_H_
32
#include "talk/base/basictypes.h"
33
#include "talk/base/sigslot.h"
34
#include "talk/base/socket.h"
39
class P2PTransportChannel;
41
// A TransportChannel represents one logical stream of packets that are sent
42
// between the two sides of a session.
43
class TransportChannel: public sigslot::has_slots<> {
45
TransportChannel(const std::string& name, const std::string &content_type)
46
: name_(name), content_type_(content_type),
47
readable_(false), writable_(false) {}
48
virtual ~TransportChannel() {}
50
// Returns the session id of this channel.
51
const std::string& session_id() const { return session_id_; }
52
// Returns the name of this channel.
53
const std::string& name() const { return name_; }
54
const std::string& content_type() const { return content_type_; }
56
// Returns the readable and states of this channel. Each time one of these
57
// states changes, a signal is raised. These states are aggregated by the
59
bool readable() const { return readable_; }
60
bool writable() const { return writable_; }
61
sigslot::signal1<TransportChannel*> SignalReadableState;
62
sigslot::signal1<TransportChannel*> SignalWritableState;
64
// Attempts to send the given packet. The return value is < 0 on failure.
65
virtual int SendPacket(const char *data, size_t len) = 0;
67
// Sets a socket option on this channel. Note that not all options are
68
// supported by all transport types.
69
virtual int SetOption(talk_base::Socket::Option opt, int value) = 0;
71
// Sets session id which created this transport channel.
72
// This is called from TransportProxy::GetOrCreateImpl.
73
void set_session_id(const std::string& session_id) {
74
session_id_ = session_id;
77
// Returns the most recent error that occurred on this channel.
78
virtual int GetError() = 0;
80
// This hack is here to allow the SocketMonitor to downcast to the
81
// P2PTransportChannel safely.
82
// TODO: Generalize network monitoring.
83
virtual P2PTransportChannel* GetP2PChannel() { return NULL; }
85
// Signalled each time a packet is received on this channel.
86
sigslot::signal3<TransportChannel*, const char*, size_t> SignalReadPacket;
88
// This signal occurs when there is a change in the way that packets are
89
// being routed, i.e. to a different remote location. The candidate
90
// indicates where and how we are currently sending media.
91
sigslot::signal2<TransportChannel*, const Candidate&> SignalRouteChange;
93
// Invoked when the channel is being destroyed.
94
sigslot::signal1<TransportChannel*> SignalDestroyed;
96
// Debugging description of this transport channel.
97
std::string ToString() const;
100
// Sets the readable state, signaling if necessary.
101
void set_readable(bool readable);
103
// Sets the writable state, signaling if necessary.
104
void set_writable(bool writable);
108
std::string session_id_;
110
std::string content_type_;
114
DISALLOW_EVIL_CONSTRUCTORS(TransportChannel);
117
} // namespace cricket
119
#endif // TALK_P2P_BASE_TRANSPORTCHANNEL_H_