commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8552 - usrp2/trunk/host-ng/lib


From: eb
Subject: [Commit-gnuradio] r8552 - usrp2/trunk/host-ng/lib
Date: Wed, 4 Jun 2008 18:51:15 -0600 (MDT)

Author: eb
Date: 2008-06-04 18:51:14 -0600 (Wed, 04 Jun 2008)
New Revision: 8552

Added:
   usrp2/trunk/host-ng/lib/eth_buffer.cc
   usrp2/trunk/host-ng/lib/eth_buffer.h
Modified:
   usrp2/trunk/host-ng/lib/Makefile.am
Log:
work-in-progress

Modified: usrp2/trunk/host-ng/lib/Makefile.am
===================================================================
--- usrp2/trunk/host-ng/lib/Makefile.am 2008-06-04 18:19:50 UTC (rev 8551)
+++ usrp2/trunk/host-ng/lib/Makefile.am 2008-06-05 00:51:14 UTC (rev 8552)
@@ -23,6 +23,7 @@
        libusrp2ng.la
 
 libusrp2ng_la_SOURCES = \
+       eth_buffer.cc \
        ethernet.cc \
        find.cc \
        pktfilter.cc \
@@ -33,6 +34,7 @@
 
 # Private headers not needed for above the API development
 noinst_HEADERS = \
+       eth_buffer.h \
        ethernet.h \
        pktfilter.h \
        usrp2_thread.h

Added: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc                               (rev 0)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc       2008-06-05 00:51:14 UTC (rev 
8552)
@@ -0,0 +1,34 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "eth_buffer.h"
+
+namespace usrp2 {
+
+  eth_buffer::handler::~handler()
+  {
+    // default nop destructor
+  }
+  
+};


Property changes on: usrp2/trunk/host-ng/lib/eth_buffer.cc
___________________________________________________________________
Name: svn:eol-style
   + native

Added: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h                                (rev 0)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h        2008-06-05 00:51:14 UTC (rev 
8552)
@@ -0,0 +1,126 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_USRP2_ETH_BUFFER_H
+#define INCLUDED_USRP2_ETH_BUFFER_H
+
+#include <boost/utility.hpp>
+#include <stdint.h>
+#include "pktfilter.h"
+
+
+namespace usrp2 {
+
+  /*!
+   * \brief high-performance interface to send and receive raw
+   * ethernet frames with out-of-order retirement of received frames.
+   *
+   * On many systems it should be possible to implement this on top of libpcap
+   *
+   * \internal
+   */
+  class eth_buffer : boost::noncopyable {
+    
+    int                d_fd;           // socket file descriptor
+    uint8_t    d_mac[6];       // our mac address
+
+  public:
+
+    // 
----------------------------------------------------------------------------
+
+    /*!
+     * \brief abstract function object called to handle received ethernet 
frames.
+     */
+    class handler {
+    public:
+      enum result {
+       FREE_FRAME,     // I'm done with the frame, please free it.
+       KEEP_FRAME,     // Hold onto the frame for the next call to rx_frames
+      };
+
+      /*!
+       * \param base points to the beginning of the frame (the 14-byte 
ethernet header).
+       * \param len is the length in bytes of the frame.
+       */
+      virtual result operator()(void *base, size_t len) = 0;
+      virtual ~handler();
+    };
+
+    // 
----------------------------------------------------------------------------
+
+    /*!
+     * \param rx_bufsize is a hint as to the number of bytes of memory
+     * to allocate for received ethernet frames (0 -> reasonable default)
+     */
+    eth_buffer(size_t rx_bufsize = 0);
+    ~eth_buffer();
+    
+    /*!
+     * \brief open the specified interface
+     *
+     * \param ifname ethernet interface name, e.g., "eth0"
+     * \param protocol is the ethertype protocol number in network order.
+     *    Use 0 to receive all protocols.
+     */
+    bool open(const std::string &ifname, int protocol);
+
+    /*!
+     * \brief close the interface
+     */
+    bool close();
+
+    /*!
+     * \brief attach packet filter to socket to restrict which packets read 
sees.
+     * \param pf       the packet filter
+     */
+    bool attach_pktfilter(pktfilter *pf);
+
+    /*!
+     * \brief return 6 byte string containing our MAC address
+     */
+    const uint8_t *mac() const { return d_mac; }
+
+    /*!
+     * \brief Return the read file descriptor associated with socket
+     * (for use with select/poll only)
+     */
+    int read_fd() const { return d_fd; }
+
+    /*!
+     * \brief Return the write file descriptor associated with socket
+     * (for use with select/poll only)
+     */
+    int write_fd() const { return d_fd; }
+
+
+    //! Are there received frames available?
+    bool rx_frames_available_p();
+
+    /*!
+     * \brief Call \p f for each frame in the receive buffer.
+     * \param f is the frame handler
+     * \param ok_to_block indicates whether it is OK to block until at least 
one frame is received.
+     */
+    void rx_frames(handler *f, bool ok_to_block=true);
+  };
+
+};  // namespace usrp2
+
+#endif /* INCLUDED_USRP2_ETH_BUFFER_H */


Property changes on: usrp2/trunk/host-ng/lib/eth_buffer.h
___________________________________________________________________
Name: svn:eol-style
   + native





reply via email to

[Prev in Thread] Current Thread [Next in Thread]