commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8399 - usrp2/branches/developers/jcorgan/u2/host/gr-u


From: jcorgan
Subject: [Commit-gnuradio] r8399 - usrp2/branches/developers/jcorgan/u2/host/gr-usrp2
Date: Sun, 11 May 2008 15:13:59 -0600 (MDT)

Author: jcorgan
Date: 2008-05-11 15:13:59 -0600 (Sun, 11 May 2008)
New Revision: 8399

Added:
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h
Modified:
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
   usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
Log:
WIP, added find or create mechanism.  I remember now why I hate C++ STL.

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am      
2008-05-11 19:56:35 UTC (rev 8398)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/Makefile.am      
2008-05-11 21:13:59 UTC (rev 8399)
@@ -26,7 +26,8 @@
        usrp2_sink_base.cc \
        usrp2_sink_c.cc \
        usrp2_source_base.cc \
-       usrp2_source_c.cc
+       usrp2_source_c.cc \
+       usrp2_table.cc
 
 libgr_usrp2_la_LIBADD = \
        ../lib/libusrp2.la
@@ -36,6 +37,9 @@
        usrp2_sink_c.h \
        usrp2_source_base.h \
        usrp2_source_c.h
+       
+noinst_HEADERS = \
+       usrp2_table.h
 
 # Export C++ GNU Radio driver to Python via SWIG
 ourpythondir = $(grpythondir)

Modified: 
usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc     
2008-05-11 19:56:35 UTC (rev 8398)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.cc     
2008-05-11 21:13:59 UTC (rev 8399)
@@ -25,6 +25,7 @@
 #endif
 
 #include <usrp2_source_base.h>
+#include <usrp2_table.h>
 #include <gr_io_signature.h>
 #include <iostream>
 
@@ -37,7 +38,8 @@
   throw (std::runtime_error)
   : gr_sync_block(name,
                  gr_make_io_signature(0, 0, 0),
-                 output_signature)
+                 output_signature),
+    d_u2(0)
 {
   op_id_reply_t id;
 
@@ -59,11 +61,14 @@
              << " mac=" << id.addr 
              << " hw_rev=" << id.hw_rev << std::endl;
 
-  // Now retrieve or make and return usrp2_basic object for selected USRP2
+  if (!(d_u2 = find_or_create_usrp2_basic(ifc, id.addr)))
+    throw std::runtime_error("Unable to create usrp2_basic!");
 }
 
 usrp2_source_base::~usrp2_source_base ()
 {
+  if (d_u2)
+    release_usrp2_basic(d_u2);
 }
 
 int

Modified: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h      
2008-05-11 19:56:35 UTC (rev 8398)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_source_base.h      
2008-05-11 21:13:59 UTC (rev 8399)
@@ -36,6 +36,8 @@
                    const std::string &mac = "")
     throw (std::runtime_error);
 
+  usrp2_basic *d_u2;
+
 public:
   ~usrp2_source_base();
   

Added: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc           
                (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.cc   
2008-05-11 21:13:59 UTC (rev 8399)
@@ -0,0 +1,73 @@
+/* -*- 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <usrp2_table.h>
+#include <omnithread.h>
+#include <stdexcept>
+
+static omni_mutex lock;
+
+typedef struct {
+  u2_mac_addr_t addr;
+  usrp2_basic *u2;
+} entry_t;
+
+typedef std::vector<entry_t> entry_vector_t;
+typedef entry_vector_t::iterator entry_viter_t;
+
+static entry_vector_t s_table;
+
+usrp2_basic *
+find_or_create_usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
+{
+  omni_mutex_lock l(lock);
+
+  for (entry_viter_t e = s_table.begin(); e != s_table.end(); e++) {
+    if (e->addr == addr)
+      return e->u2;
+  }
+
+  entry_t e;
+  e.addr = addr;
+  e.u2 = new usrp2_basic(); // In future will use ifc and addr
+  s_table.push_back(e);
+  return e.u2;
+}
+
+void
+release_usrp2_basic(usrp2_basic *u2)
+{
+  omni_mutex_lock l(lock);
+
+  for (entry_viter_t e = s_table.begin(); e != s_table.end(); e++) {
+    if (e->u2 == u2) {
+      s_table.erase(e);
+      return;
+    }
+  }
+
+  throw std::runtime_error("Attempt to release non-existent usrp2_basic");
+}

Added: usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h            
                (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/gr-usrp2/usrp2_table.h    
2008-05-11 21:13:59 UTC (rev 8399)
@@ -0,0 +1,31 @@
+/* -*- 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_USRP2_TABLE_H
+#define INCLUDED_USRP2_TABLE_H
+
+#include <usrp2_basic.h>
+
+usrp2_basic *find_or_create_usrp2_basic(const std::string &ifc, const 
u2_mac_addr_t &addr);
+void release_usrp2_basic(usrp2_basic *u2);
+
+#endif /* INCLUDED_USRP2_TABLE_H */





reply via email to

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