1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/transportlayer.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +// Original author: ekr@rtfm.com 1.11 +#include "logging.h" 1.12 +#include "transportflow.h" 1.13 +#include "transportlayer.h" 1.14 +#include "nsThreadUtils.h" 1.15 + 1.16 +// Logging context 1.17 +namespace mozilla { 1.18 + 1.19 +MOZ_MTLOG_MODULE("mtransport") 1.20 + 1.21 +nsresult TransportLayer::Init() { 1.22 + if (state_ != TS_NONE) 1.23 + return state_ == TS_ERROR ? NS_ERROR_FAILURE : NS_OK; 1.24 + 1.25 + nsresult rv = InitInternal(); 1.26 + 1.27 + if (!NS_SUCCEEDED(rv)) { 1.28 + state_ = TS_ERROR; 1.29 + return rv; 1.30 + } 1.31 + state_ = TS_INIT; 1.32 + 1.33 + return NS_OK; 1.34 +} 1.35 + 1.36 +void TransportLayer::Inserted(TransportFlow *flow, TransportLayer *downward) { 1.37 + downward_ = downward; 1.38 + flow_id_ = flow->id(); 1.39 + MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Inserted: downward='" << 1.40 + (downward ? downward->id(): "none") << "'"); 1.41 + 1.42 + WasInserted(); 1.43 +} 1.44 + 1.45 +void TransportLayer::SetState(State state, const char *file, unsigned line) { 1.46 + if (state != state_) { 1.47 + MOZ_MTLOG(state == TS_ERROR ? ML_ERROR : ML_DEBUG, 1.48 + file << ":" << line << ": " << 1.49 + LAYER_INFO << "state " << state_ << "->" << state); 1.50 + state_ = state; 1.51 + SignalStateChange(this, state); 1.52 + } 1.53 +} 1.54 + 1.55 +nsresult TransportLayer::RunOnThread(nsIRunnable *event) { 1.56 + if (target_) { 1.57 + nsIThread *thr; 1.58 + 1.59 + DebugOnly<nsresult> rv = NS_GetCurrentThread(&thr); 1.60 + MOZ_ASSERT(NS_SUCCEEDED(rv)); 1.61 + 1.62 + if (target_ != thr) { 1.63 + return target_->Dispatch(event, NS_DISPATCH_SYNC); 1.64 + } 1.65 + } 1.66 + 1.67 + return event->Run(); 1.68 +} 1.69 + 1.70 +} // close namespace