michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Original author: ekr@rtfm.com michael@0: #include "logging.h" michael@0: #include "transportflow.h" michael@0: #include "transportlayer.h" michael@0: #include "nsThreadUtils.h" michael@0: michael@0: // Logging context michael@0: namespace mozilla { michael@0: michael@0: MOZ_MTLOG_MODULE("mtransport") michael@0: michael@0: nsresult TransportLayer::Init() { michael@0: if (state_ != TS_NONE) michael@0: return state_ == TS_ERROR ? NS_ERROR_FAILURE : NS_OK; michael@0: michael@0: nsresult rv = InitInternal(); michael@0: michael@0: if (!NS_SUCCEEDED(rv)) { michael@0: state_ = TS_ERROR; michael@0: return rv; michael@0: } michael@0: state_ = TS_INIT; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: void TransportLayer::Inserted(TransportFlow *flow, TransportLayer *downward) { michael@0: downward_ = downward; michael@0: flow_id_ = flow->id(); michael@0: MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Inserted: downward='" << michael@0: (downward ? downward->id(): "none") << "'"); michael@0: michael@0: WasInserted(); michael@0: } michael@0: michael@0: void TransportLayer::SetState(State state, const char *file, unsigned line) { michael@0: if (state != state_) { michael@0: MOZ_MTLOG(state == TS_ERROR ? ML_ERROR : ML_DEBUG, michael@0: file << ":" << line << ": " << michael@0: LAYER_INFO << "state " << state_ << "->" << state); michael@0: state_ = state; michael@0: SignalStateChange(this, state); michael@0: } michael@0: } michael@0: michael@0: nsresult TransportLayer::RunOnThread(nsIRunnable *event) { michael@0: if (target_) { michael@0: nsIThread *thr; michael@0: michael@0: DebugOnly rv = NS_GetCurrentThread(&thr); michael@0: MOZ_ASSERT(NS_SUCCEEDED(rv)); michael@0: michael@0: if (target_ != thr) { michael@0: return target_->Dispatch(event, NS_DISPATCH_SYNC); michael@0: } michael@0: } michael@0: michael@0: return event->Run(); michael@0: } michael@0: michael@0: } // close namespace