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
#include "talk/p2p/base/transportchannelproxy.h"
29
#include "talk/base/common.h"
30
#include "talk/p2p/base/transport.h"
31
#include "talk/p2p/base/transportchannelimpl.h"
35
TransportChannelProxy::TransportChannelProxy(const std::string& name,
36
const std::string& content_type)
37
: TransportChannel(name, content_type), impl_(NULL) {
40
TransportChannelProxy::~TransportChannelProxy() {
42
impl_->GetTransport()->DestroyChannel(impl_->name());
45
void TransportChannelProxy::SetImplementation(TransportChannelImpl* impl) {
46
// Destroy any existing impl_
48
impl_->GetTransport()->DestroyChannel(impl_->name());
52
impl_->SignalReadableState.connect(
53
this, &TransportChannelProxy::OnReadableState);
54
impl_->SignalWritableState.connect(
55
this, &TransportChannelProxy::OnWritableState);
56
impl_->SignalReadPacket.connect(this, &TransportChannelProxy::OnReadPacket);
57
impl_->SignalRouteChange.connect(this, &TransportChannelProxy::OnRouteChange);
58
for (OptionList::iterator it = pending_options_.begin();
59
it != pending_options_.end();
61
impl_->SetOption(it->first, it->second);
63
pending_options_.clear();
66
int TransportChannelProxy::SendPacket(const char* data, size_t len) {
67
// Fail if we don't have an impl yet.
68
return (impl_) ? impl_->SendPacket(data, len) : -1;
71
int TransportChannelProxy::SetOption(talk_base::Socket::Option opt, int value) {
73
return impl_->SetOption(opt, value);
74
pending_options_.push_back(OptionPair(opt, value));
78
int TransportChannelProxy::GetError() {
79
ASSERT(impl_ != NULL); // should not be used until channel is writable
80
return impl_->GetError();
83
P2PTransportChannel* TransportChannelProxy::GetP2PChannel() {
85
return impl_->GetP2PChannel();
90
void TransportChannelProxy::OnReadableState(TransportChannel* channel) {
91
ASSERT(channel == impl_);
92
set_readable(impl_->readable());
93
// Note: SignalReadableState fired by set_readable.
96
void TransportChannelProxy::OnWritableState(TransportChannel* channel) {
97
ASSERT(channel == impl_);
98
set_writable(impl_->writable());
99
// Note: SignalWritableState fired by set_writable.
102
void TransportChannelProxy::OnReadPacket(TransportChannel* channel,
103
const char* data, size_t size) {
104
ASSERT(channel == impl_);
105
SignalReadPacket(this, data, size);
108
void TransportChannelProxy::OnRouteChange(TransportChannel* channel,
109
const Candidate& candidate) {
110
ASSERT(channel == impl_);
111
SignalRouteChange(this, candidate);
114
} // namespace cricket