transportlayer.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. // Original author: ekr@rtfm.com
  6. #include "logging.h"
  7. #include "transportflow.h"
  8. #include "transportlayer.h"
  9. #include "nsThreadUtils.h"
  10. // Logging context
  11. namespace mozilla {
  12. MOZ_MTLOG_MODULE("mtransport")
  13. nsresult TransportLayer::Init() {
  14. if (state_ != TS_NONE)
  15. return state_ == TS_ERROR ? NS_ERROR_FAILURE : NS_OK;
  16. nsresult rv = InitInternal();
  17. if (!NS_SUCCEEDED(rv)) {
  18. state_ = TS_ERROR;
  19. return rv;
  20. }
  21. state_ = TS_INIT;
  22. return NS_OK;
  23. }
  24. void TransportLayer::Inserted(TransportFlow *flow, TransportLayer *downward) {
  25. downward_ = downward;
  26. flow_id_ = flow->id();
  27. MOZ_MTLOG(ML_DEBUG, LAYER_INFO << "Inserted: downward='" <<
  28. (downward ? downward->id(): "none") << "'");
  29. WasInserted();
  30. }
  31. void TransportLayer::SetState(State state, const char *file, unsigned line) {
  32. if (state != state_) {
  33. MOZ_MTLOG(state == TS_ERROR ? ML_ERROR : ML_DEBUG,
  34. file << ":" << line << ": " <<
  35. LAYER_INFO << "state " << state_ << "->" << state);
  36. state_ = state;
  37. SignalStateChange(this, state);
  38. }
  39. }
  40. } // close namespace