|
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 #include "logging.h" |
|
9 #include "transportflow.h" |
|
10 #include "transportlayer.h" |
|
11 #include "nsThreadUtils.h" |
|
12 |
|
13 // Logging context |
|
14 namespace mozilla { |
|
15 |
|
16 MOZ_MTLOG_MODULE("mtransport") |
|
17 |
|
18 nsresult TransportLayer::Init() { |
|
19 if (state_ != TS_NONE) |
|
20 return state_ == TS_ERROR ? NS_ERROR_FAILURE : NS_OK; |
|
21 |
|
22 nsresult rv = InitInternal(); |
|
23 |
|
24 if (!NS_SUCCEEDED(rv)) { |
|
25 state_ = TS_ERROR; |
|
26 return rv; |
|
27 } |
|
28 state_ = TS_INIT; |
|
29 |
|
30 return NS_OK; |
|
31 } |
|
32 |
|
33 void TransportLayer::Inserted(TransportFlow *flow, TransportLayer *downward) { |
|
34 downward_ = downward; |
|
35 flow_id_ = flow->id(); |
|
36 MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Inserted: downward='" << |
|
37 (downward ? downward->id(): "none") << "'"); |
|
38 |
|
39 WasInserted(); |
|
40 } |
|
41 |
|
42 void TransportLayer::SetState(State state, const char *file, unsigned line) { |
|
43 if (state != state_) { |
|
44 MOZ_MTLOG(state == TS_ERROR ? ML_ERROR : ML_DEBUG, |
|
45 file << ":" << line << ": " << |
|
46 LAYER_INFO << "state " << state_ << "->" << state); |
|
47 state_ = state; |
|
48 SignalStateChange(this, state); |
|
49 } |
|
50 } |
|
51 |
|
52 nsresult TransportLayer::RunOnThread(nsIRunnable *event) { |
|
53 if (target_) { |
|
54 nsIThread *thr; |
|
55 |
|
56 DebugOnly<nsresult> rv = NS_GetCurrentThread(&thr); |
|
57 MOZ_ASSERT(NS_SUCCEEDED(rv)); |
|
58 |
|
59 if (target_ != thr) { |
|
60 return target_->Dispatch(event, NS_DISPATCH_SYNC); |
|
61 } |
|
62 } |
|
63 |
|
64 return event->Run(); |
|
65 } |
|
66 |
|
67 } // close namespace |