gecko-dev/media/mtransport/transportlayer.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 строки
3.1 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// Original author: ekr@rtfm.com
#ifndef transportlayer_h__
#define transportlayer_h__
#include "sigslot.h"
#include "mozilla/DebugOnly.h"
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "nsIEventTarget.h"
#include "m_cpp_utils.h"
#include "mediapacket.h"
namespace mozilla {
class TransportFlow;
typedef int TransportResult;
enum { TE_WOULDBLOCK = -1, TE_ERROR = -2, TE_INTERNAL = -3 };
#define TRANSPORT_LAYER_ID(name) \
const std::string id() const override { return name; } \
static std::string ID() { return name; }
// Abstract base class for network transport layers.
class TransportLayer : public sigslot::has_slots<> {
public:
// The state of the transport flow
// We can't use "ERROR" because Windows has a macro named "ERROR"
enum State { TS_NONE, TS_INIT, TS_CONNECTING, TS_OPEN, TS_CLOSED, TS_ERROR };
// Is this a stream or datagram flow
TransportLayer() : state_(TS_NONE), flow_id_(), downward_(nullptr) {}
virtual ~TransportLayer() {}
// Called to initialize
nsresult Init(); // Called by Insert() to set up -- do not override
virtual nsresult InitInternal() { return NS_OK; } // Called by Init
void SetFlowId(const std::string& flow_id) { flow_id_ = flow_id; }
virtual void Chain(TransportLayer* downward);
// Downward interface
TransportLayer* downward() { return downward_; }
// Get the state
State state() const { return state_; }
// Must be implemented by derived classes
virtual TransportResult SendPacket(MediaPacket& packet) = 0;
// Get the thread.
const nsCOMPtr<nsIEventTarget> GetThread() const { return target_; }
// Event definitions that one can register for
// State has changed
sigslot::signal2<TransportLayer*, State> SignalStateChange;
// Data received on the flow
sigslot::signal2<TransportLayer*, MediaPacket&> SignalPacketReceived;
// Return the layer id for this layer
virtual const std::string id() const = 0;
// The id of the flow
const std::string& flow_id() const { return flow_id_; }
protected:
virtual void WasInserted() {}
virtual void SetState(State state, const char* file, unsigned line);
// Check if we are on the right thread
void CheckThread() const { MOZ_ASSERT(CheckThreadInt(), "Wrong thread"); }
State state_;
std::string flow_id_;
TransportLayer* downward_; // The next layer in the stack
nsCOMPtr<nsIEventTarget> target_;
private:
DISALLOW_COPY_ASSIGN(TransportLayer);
bool CheckThreadInt() const {
bool on;
if (!target_) // OK if no thread set.
return true;
NS_ENSURE_SUCCESS(target_->IsOnCurrentThread(&on), false);
NS_ENSURE_TRUE(on, false);
return true;
}
};
#define LAYER_INFO \
"Flow[" << flow_id() << "(none)" \
<< "]; Layer[" << id() << "]: "
#define TL_SET_STATE(x) SetState((x), __FILE__, __LINE__)
} // namespace mozilla
#endif