src/node/socket.cc
changeset 1264 577875bb5a65
parent 1186 909e9eb2124e
child 1265 7d9bdec626a1
--- a/src/node/socket.cc	Wed Aug 01 17:24:55 2007 +0200
+++ b/src/node/socket.cc	Wed Aug 01 18:48:24 2007 +0200
@@ -1,79 +1,150 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 Georgia Tech Research Corporation
+ *               2007 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: George F. Riley<riley@ece.gatech.edu>
+ *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
 #include "socket.h"
+#include "ns3/packet.h"
 
 namespace ns3 {
 
 Socket::~Socket ()
 {}
 
-int
-Socket::Close(Callback<void, Ptr<Socket> > closeCompleted)
+void 
+Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
+{
+  m_closeCompleted = closeCompleted;
+}
+void 
+Socket::SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
+			    Callback<void, Ptr<Socket> > connectionFailed,
+			    Callback<void, Ptr<Socket> > halfClose)
 {
-  return DoClose (closeCompleted);
+  m_connectionSucceeded = connectionSucceeded;
+  m_connectionFailed = connectionFailed;
+  m_halfClose = halfClose;
+}
+void 
+Socket::SetAcceptCallback (Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
+			   Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
+			   Callback<void, Ptr<Socket> > closeRequested)
+{
+  m_connectionRequest = connectionRequest;
+  m_newConnectionCreated = newConnectionCreated;
+  m_closeRequested = closeRequested;
+}
+void 
+Socket::SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent)
+{
+  m_dataSent = dataSent;
+}
+void 
+Socket::SetRecvCallback (Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Address&> receivedData,
+			 Callback<void, Ptr<Socket>, uint32_t,const Address&> receivedDummyData)
+{
+  m_receivedData = receivedData;
+  m_receivedDummyData = receivedDummyData;
 }
 
-int
-Socket::Connect(const Address & address,
-               Callback<void, Ptr<Socket> > connectionSucceeded,
-               Callback<void, Ptr<Socket> > connectionFailed,
-               Callback<void, Ptr<Socket> > halfClose)
+void 
+Socket::NotifyCloseCompleted (void)
 {
-  return DoConnect (address, connectionSucceeded, connectionFailed, halfClose);
-}
-int
-Socket::Accept(Callback<bool, Ptr<Socket>, const Address&> connectionRequest,
-	       Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
-	       Callback<void, Ptr<Socket> > closeRequested)
-{
-  return DoAccept (connectionRequest, newConnectionCreated, closeRequested);
+  if (!m_closeCompleted.IsNull ())
+    {
+      m_closeCompleted (this);
+    }
 }
-int 
-Socket::Send (const uint8_t* buffer,
-	      uint32_t size,
-	      Callback<void, Ptr<Socket>, uint32_t> dataSent)
+void 
+Socket::NotifyConnectionSucceeded (void)
 {
-  return DoSend (buffer, size, dataSent);
+  if (!m_connectionSucceeded.IsNull ())
+    {
+      m_connectionSucceeded (this);
+    }
 }
-int 
-Socket::SendTo(const Address &address,
-	       const uint8_t *buffer,
-	       uint32_t size,
-	       Callback<void, Ptr<Socket>, uint32_t> dataSent)
+void 
+Socket::NotifyConnectionFailed (void)
 {
-  return DoSendTo (address, buffer, size, dataSent);
+  if (!m_connectionFailed.IsNull ())
+    {
+      m_connectionFailed (this);
+    }
 }
 void 
-Socket::Recv(Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Address&> callback)
+Socket::NotifyHalfClose (void)
+{
+  if (!m_halfClose.IsNull ())
+    {
+      m_halfClose (this);
+    }
+}
+bool 
+Socket::NotifyConnectionRequest (const Address &from)
 {
-  DoRecv (callback);
+  if (!m_connectionRequest.IsNull ())
+    {
+      return m_connectionRequest (this, from);
+    }
+  else
+    {
+      // refuse all incomming connections by default.
+      return false;
+    }
 }
 void 
-Socket::RecvDummy(Callback<void, Ptr<Socket>, uint32_t,const Address&> callback)
+Socket::NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from)
+{
+  if (!m_newConnectionCreated.IsNull ())
+    {
+      m_newConnectionCreated (socket, from);
+    }
+}
+void 
+Socket::NotifyCloseRequested (void)
 {
-  DoRecvDummy (callback);
+  if (!m_closeRequested.IsNull ())
+    {
+      m_closeRequested (this);
+    }
+}
+void 
+Socket::NotifyDataSent (uint32_t size)
+{
+  if (!m_dataSent.IsNull ())
+    {
+      m_dataSent (this, size);
+    }
+}
+void 
+Socket::NotifyDataReceived (const Packet &p, const Address &from)
+{
+  if (!m_receivedData.IsNull ())
+    {
+      m_receivedData (this, p.PeekData (), p.GetSize (), from);
+    }
+  if (!m_receivedDummyData.IsNull ())
+    {
+      m_receivedDummyData (this, p.GetSize (), from);
+    }
 }
 
 
-bool 
-Socket::RefuseAllConnections (Ptr<Socket> socket, const Address& address)
-{
-  return false;
-}
-void 
-Socket::DummyCallbackVoidSocket (Ptr<Socket> socket)
-{}
-void
-Socket::DummyCallbackVoidSocketUi32 (Ptr<Socket> socket, uint32_t)
-{}
-void 
-Socket::DummyCallbackVoidSocketUi32Address (Ptr<Socket> socket, uint32_t, const Address &)
-{}
-void 
-Socket::DummyCallbackVoidSocketBufferUi32Address (Ptr<Socket> socket, const uint8_t *, uint32_t,
-						  const Address &)
-{}
-void 
-Socket::DummyCallbackVoidSocketAddress (Ptr<Socket> socket, const Address &)
-{}
-
 
 }//namespace ns3