| |
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| |
2 /* vim: set ts=2 et sw=2 tw=80: */ |
| |
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
| |
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| |
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| |
6 |
| |
7 // Original author: ekr@rtfm.com |
| |
8 |
| |
9 #include "logging.h" |
| |
10 #include "transportflow.h" |
| |
11 #include "transportlayerlog.h" |
| |
12 |
| |
13 namespace mozilla { |
| |
14 |
| |
15 MOZ_MTLOG_MODULE("mtransport") |
| |
16 |
| |
17 void TransportLayerLogging::WasInserted() { |
| |
18 if (downward_) { |
| |
19 downward_->SignalStateChange.connect( |
| |
20 this, &TransportLayerLogging::StateChange); |
| |
21 downward_->SignalPacketReceived.connect( |
| |
22 this, &TransportLayerLogging::PacketReceived); |
| |
23 TL_SET_STATE(downward_->state()); |
| |
24 } |
| |
25 } |
| |
26 |
| |
27 TransportResult |
| |
28 TransportLayerLogging::SendPacket(const unsigned char *data, size_t len) { |
| |
29 MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "SendPacket(" << len << ")"); |
| |
30 |
| |
31 if (downward_) { |
| |
32 return downward_->SendPacket(data, len); |
| |
33 } |
| |
34 else { |
| |
35 return static_cast<TransportResult>(len); |
| |
36 } |
| |
37 } |
| |
38 |
| |
39 void TransportLayerLogging::StateChange(TransportLayer *layer, State state) { |
| |
40 MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Received StateChange to " << state); |
| |
41 |
| |
42 TL_SET_STATE(state); |
| |
43 } |
| |
44 |
| |
45 void TransportLayerLogging::PacketReceived(TransportLayer* layer, |
| |
46 const unsigned char *data, |
| |
47 size_t len) { |
| |
48 MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "PacketReceived(" << len << ")"); |
| |
49 |
| |
50 SignalPacketReceived(this, data, len); |
| |
51 } |
| |
52 |
| |
53 |
| |
54 |
| |
55 } // close namespace |