src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/plugins/ip-faces/ndn-tcp-face.cpp b/plugins/ip-faces/ndn-tcp-face.cpp
index 27e58b8..701ad64 100644
--- a/plugins/ip-faces/ndn-tcp-face.cpp
+++ b/plugins/ip-faces/ndn-tcp-face.cpp
@@ -34,73 +34,70 @@
using namespace std;
-NS_LOG_COMPONENT_DEFINE ("ndn.TcpFace");
+NS_LOG_COMPONENT_DEFINE("ndn.TcpFace");
namespace ns3 {
namespace ndn {
-class TcpBoundaryHeader : public Header
-{
+class TcpBoundaryHeader : public Header {
public:
- static TypeId GetTypeId (void)
+ static TypeId
+ GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::TcpFace::BoundaryHeader")
- .SetGroupName ("Ndn")
- .SetParent<Header> ()
- ;
+ static TypeId tid =
+ TypeId("ns3::ndn::TcpFace::BoundaryHeader").SetGroupName("Ndn").SetParent<Header>();
return tid;
}
- TcpBoundaryHeader ()
- : m_length (0)
+ TcpBoundaryHeader()
+ : m_length(0)
{
}
-
- TcpBoundaryHeader (Ptr<Packet> packet)
- : m_length (packet->GetSize ())
- {
-
- }
- TcpBoundaryHeader (uint32_t length)
- : m_length (length)
+ TcpBoundaryHeader(Ptr<Packet> packet)
+ : m_length(packet->GetSize())
+ {
+ }
+
+ TcpBoundaryHeader(uint32_t length)
+ : m_length(length)
{
}
uint32_t
- GetLength () const
+ GetLength() const
{
return m_length;
}
-
+
virtual TypeId
- GetInstanceTypeId (void) const
+ GetInstanceTypeId(void) const
{
- return TcpBoundaryHeader::GetTypeId ();
+ return TcpBoundaryHeader::GetTypeId();
}
-
+
virtual void
- Print (std::ostream &os) const
+ Print(std::ostream& os) const
{
os << "[" << m_length << "]";
}
-
+
virtual uint32_t
- GetSerializedSize (void) const
+ GetSerializedSize(void) const
{
return 4;
}
-
+
virtual void
- Serialize (Buffer::Iterator start) const
+ Serialize(Buffer::Iterator start) const
{
- start.WriteU32 (m_length);
+ start.WriteU32(m_length);
}
-
+
virtual uint32_t
- Deserialize (Buffer::Iterator start)
+ Deserialize(Buffer::Iterator start)
{
- m_length = start.ReadU32 ();
+ m_length = start.ReadU32();
return 4;
}
@@ -108,15 +105,12 @@
uint32_t m_length;
};
-NS_OBJECT_ENSURE_REGISTERED (TcpFace);
+NS_OBJECT_ENSURE_REGISTERED(TcpFace);
TypeId
-TcpFace::GetTypeId ()
+TcpFace::GetTypeId()
{
- static TypeId tid = TypeId ("ns3::ndn::TcpFace")
- .SetParent<Face> ()
- .SetGroupName ("Ndn")
- ;
+ static TypeId tid = TypeId("ns3::ndn::TcpFace").SetParent<Face>().SetGroupName("Ndn");
return tid;
}
@@ -124,18 +118,18 @@
* By default, Ndn face are created in the "down" state. Before
* becoming useable, the user must invoke SetUp on the face
*/
-TcpFace::TcpFace (Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address)
- : Face (node)
- , m_socket (socket)
- , m_address (address)
- , m_pendingPacketLength (0)
+TcpFace::TcpFace(Ptr<Node> node, Ptr<Socket> socket, Ipv4Address address)
+ : Face(node)
+ , m_socket(socket)
+ , m_address(address)
+ , m_pendingPacketLength(0)
{
- SetMetric (1); // default metric
+ SetMetric(1); // default metric
}
-TcpFace::~TcpFace ()
+TcpFace::~TcpFace()
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION_NOARGS();
}
TcpFace& TcpFace::operator= (const TcpFace &)
@@ -144,143 +138,137 @@
}
void
-TcpFace::RegisterProtocolHandlers (const InterestHandler &interestHandler, const DataHandler &dataHandler)
+TcpFace::RegisterProtocolHandlers(const InterestHandler& interestHandler,
+ const DataHandler& dataHandler)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
- Face::RegisterProtocolHandlers (interestHandler, dataHandler);
- m_socket->SetRecvCallback (MakeCallback (&TcpFace::ReceiveFromTcp, this));
+ Face::RegisterProtocolHandlers(interestHandler, dataHandler);
+ m_socket->SetRecvCallback(MakeCallback(&TcpFace::ReceiveFromTcp, this));
}
void
-TcpFace::UnRegisterProtocolHandlers ()
+TcpFace::UnRegisterProtocolHandlers()
{
- m_socket->SetRecvCallback (MakeNullCallback< void, Ptr<Socket> > ());
- Face::UnRegisterProtocolHandlers ();
+ m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket>>());
+ Face::UnRegisterProtocolHandlers();
}
bool
-TcpFace::Send (Ptr<Packet> packet)
+TcpFace::Send(Ptr<Packet> packet)
{
- if (!Face::Send (packet))
- {
- return false;
- }
-
- NS_LOG_FUNCTION (this << packet);
+ if (!Face::Send(packet)) {
+ return false;
+ }
- Ptr<Packet> boundary = Create<Packet> ();
- TcpBoundaryHeader hdr (packet);
- boundary->AddHeader (hdr);
-
- m_socket->Send (boundary);
- m_socket->Send (packet);
+ NS_LOG_FUNCTION(this << packet);
+
+ Ptr<Packet> boundary = Create<Packet>();
+ TcpBoundaryHeader hdr(packet);
+ boundary->AddHeader(hdr);
+
+ m_socket->Send(boundary);
+ m_socket->Send(packet);
return true;
}
void
-TcpFace::ReceiveFromTcp (Ptr< Socket > clientSocket)
+TcpFace::ReceiveFromTcp(Ptr<Socket> clientSocket)
{
- NS_LOG_FUNCTION (this << clientSocket);
+ NS_LOG_FUNCTION(this << clientSocket);
TcpBoundaryHeader hdr;
- if (m_pendingPacketLength > 0)
- {
- if (clientSocket->GetRxAvailable () >= m_pendingPacketLength)
- {
- Ptr<Packet> realPacket = clientSocket->Recv (m_pendingPacketLength, 0);
- NS_LOG_DEBUG ("+++ Expected " << m_pendingPacketLength << " bytes, got " << realPacket->GetSize () << " bytes");
- if (realPacket == 0)
- return;
-
- Receive (realPacket);
- }
- else
- return; // still not ready
+ if (m_pendingPacketLength > 0) {
+ if (clientSocket->GetRxAvailable() >= m_pendingPacketLength) {
+ Ptr<Packet> realPacket = clientSocket->Recv(m_pendingPacketLength, 0);
+ NS_LOG_DEBUG("+++ Expected " << m_pendingPacketLength << " bytes, got "
+ << realPacket->GetSize() << " bytes");
+ if (realPacket == 0)
+ return;
+
+ Receive(realPacket);
}
-
+ else
+ return; // still not ready
+ }
+
m_pendingPacketLength = 0;
-
- while (clientSocket->GetRxAvailable () >= hdr.GetSerializedSize ())
- {
- Ptr<Packet> boundary = clientSocket->Recv (hdr.GetSerializedSize (), 0);
- if (boundary == 0)
- return; // no idea why it would happen...
- NS_LOG_DEBUG ("Expected 4 bytes, got " << boundary->GetSize () << " bytes");
-
- boundary->RemoveHeader (hdr);
- NS_LOG_DEBUG ("Header specifies length: " << hdr.GetLength ());
- m_pendingPacketLength = hdr.GetLength ();
-
- if (clientSocket->GetRxAvailable () >= hdr.GetLength ())
- {
- Ptr<Packet> realPacket = clientSocket->Recv (hdr.GetLength (), 0);
- if (realPacket == 0)
- {
- NS_LOG_DEBUG ("Got nothing, but requested at least " << hdr.GetLength ());
- return;
- }
-
- NS_LOG_DEBUG ("Receiving data " << hdr.GetLength () << " bytes, got " << realPacket->GetSize () << " bytes");
+ while (clientSocket->GetRxAvailable() >= hdr.GetSerializedSize()) {
+ Ptr<Packet> boundary = clientSocket->Recv(hdr.GetSerializedSize(), 0);
+ if (boundary == 0)
+ return; // no idea why it would happen...
- Receive (realPacket);
- m_pendingPacketLength = 0;
- }
- else
- {
- return;
- }
+ NS_LOG_DEBUG("Expected 4 bytes, got " << boundary->GetSize() << " bytes");
+
+ boundary->RemoveHeader(hdr);
+ NS_LOG_DEBUG("Header specifies length: " << hdr.GetLength());
+ m_pendingPacketLength = hdr.GetLength();
+
+ if (clientSocket->GetRxAvailable() >= hdr.GetLength()) {
+ Ptr<Packet> realPacket = clientSocket->Recv(hdr.GetLength(), 0);
+ if (realPacket == 0) {
+ NS_LOG_DEBUG("Got nothing, but requested at least " << hdr.GetLength());
+ return;
+ }
+
+ NS_LOG_DEBUG("Receiving data " << hdr.GetLength() << " bytes, got " << realPacket->GetSize()
+ << " bytes");
+
+ Receive(realPacket);
+ m_pendingPacketLength = 0;
}
+ else {
+ return;
+ }
+ }
}
void
-TcpFace::OnTcpConnectionClosed (Ptr<Socket> socket)
+TcpFace::OnTcpConnectionClosed(Ptr<Socket> socket)
{
- NS_LOG_FUNCTION (this << socket);
- GetNode ()->GetObject<IpFaceStack> ()->DestroyTcpFace (this);
+ NS_LOG_FUNCTION(this << socket);
+ GetNode()->GetObject<IpFaceStack>()->DestroyTcpFace(this);
}
Ipv4Address
-TcpFace::GetAddress () const
+TcpFace::GetAddress() const
{
return m_address;
}
void
-TcpFace::SetCreateCallback (Callback< void, Ptr<Face> > callback)
+TcpFace::SetCreateCallback(Callback<void, Ptr<Face>> callback)
{
m_onCreateCallback = callback;
}
void
-TcpFace::OnConnect (Ptr<Socket> socket)
+TcpFace::OnConnect(Ptr<Socket> socket)
{
- NS_LOG_FUNCTION (this << socket);
+ NS_LOG_FUNCTION(this << socket);
- Ptr<L3Protocol> ndn = GetNode ()->GetObject<L3Protocol> ();
-
- ndn->AddFace (this);
- this->SetUp (true);
+ Ptr<L3Protocol> ndn = GetNode()->GetObject<L3Protocol>();
- socket->SetCloseCallbacks (MakeCallback (&TcpFace::OnTcpConnectionClosed, this),
- MakeCallback (&TcpFace::OnTcpConnectionClosed, this));
+ ndn->AddFace(this);
+ this->SetUp(true);
- if (!m_onCreateCallback.IsNull ())
- {
- m_onCreateCallback (this);
- m_onCreateCallback = IpFaceStack::NULL_CREATE_CALLBACK;
- }
+ socket->SetCloseCallbacks(MakeCallback(&TcpFace::OnTcpConnectionClosed, this),
+ MakeCallback(&TcpFace::OnTcpConnectionClosed, this));
+
+ if (!m_onCreateCallback.IsNull()) {
+ m_onCreateCallback(this);
+ m_onCreateCallback = IpFaceStack::NULL_CREATE_CALLBACK;
+ }
}
-
+
std::ostream&
-TcpFace::Print (std::ostream& os) const
+TcpFace::Print(std::ostream& os) const
{
- os << "dev=tcp(" << GetId () << ", " << m_address << ")";
+ os << "dev=tcp(" << GetId() << ", " << m_address << ")";
return os;
}
} // namespace ndn
} // namespace ns3
-