LoFireWireBus.H

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/io/LoFireWireBus.H
00003    \brief Quick wrapper around libdc1394's handles, camera nodes, etc.
00004 */
00005 
00006 // //////////////////////////////////////////////////////////////////// //
00007 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00008 // by the University of Southern California (USC) and the iLab at USC.  //
00009 // See http://iLab.usc.edu for information about this project.          //
00010 // //////////////////////////////////////////////////////////////////// //
00011 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00012 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00013 // in Visual Environments, and Applications'' by Christof Koch and      //
00014 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00015 // pending; application number 09/912,225 filed July 23, 2001; see      //
00016 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00017 // //////////////////////////////////////////////////////////////////// //
00018 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00019 //                                                                      //
00020 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00021 // redistribute it and/or modify it under the terms of the GNU General  //
00022 // Public License as published by the Free Software Foundation; either  //
00023 // version 2 of the License, or (at your option) any later version.     //
00024 //                                                                      //
00025 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00026 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00027 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00028 // PURPOSE.  See the GNU General Public License for more details.       //
00029 //                                                                      //
00030 // You should have received a copy of the GNU General Public License    //
00031 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00032 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00033 // Boston, MA 02111-1307 USA.                                           //
00034 // //////////////////////////////////////////////////////////////////// //
00035 //
00036 // Primary maintainer for this file: Manu Viswanathan <mviswana at usc dot edu>
00037 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoFireWireBus.H $
00038 // $Id: LoFireWireBus.H 11256 2009-05-30 01:46:10Z mviswana $
00039 //
00040 
00041 #ifndef LOBOT_FIREWIRE_BUS_DOT_H
00042 #define LOBOT_FIREWIRE_BUS_DOT_H
00043 
00044 //------------------------------ HEADERS --------------------------------
00045 
00046 // lobot headers
00047 #include "Robots/LoBot/misc/singleton.hh"
00048 
00049 // 1394 headers
00050 #ifdef HAVE_IEEE1394
00051 
00052 #include <libdc1394/dc1394_control.h>
00053 
00054 #else // fake 1394 API just to let this class compile
00055 
00056 typedef int raw1394handle_t ;
00057 typedef int nodeid_t ;
00058 
00059 inline void dc1394_free_camera_nodes(nodeid_t*){}
00060 
00061 #endif
00062 
00063 //----------------------------- NAMESPACE -------------------------------
00064 
00065 namespace lobot {
00066 
00067 //------------------------- CLASS DEFINITION ----------------------------
00068 
00069 /**
00070    \class lobot::FireWireBus
00071    \brief Encapsulation of libdc1394 initialization, handles, etc.
00072 
00073    This class provides a wrapper around libdc1394's handles, camera
00074    nodes, bus initialization functions, and so on. It is implemented as a
00075    singleton so that any other part of Lobot/Robolocust can access it
00076    conveniently.
00077 
00078    Ideally, this wouldn't be a singleton because there could be multiple
00079    FireWire buses on the host system. But for the purposes of the
00080    Robolocust project, this amount of abstraction is more than
00081    sufficient.
00082 */
00083 class FireWireBus : public singleton<FireWireBus> {
00084    // Quick wrapper around raw1394 handles
00085    class raw1394_handle {
00086       raw1394handle_t handle ;
00087    public :
00088       raw1394_handle(int card_number = 0) ;
00089       ~raw1394_handle() ;
00090 
00091       // conversion operator to allow instances of this class to be used
00092       // directly in APIs requiring a raw1394handle_t
00093       operator const raw1394handle_t&() const {return handle ;}
00094    } ;
00095 
00096    // Quick wrapper around the camera node list returned by
00097    // dc1394_get_camera_nodes()
00098    class dc_node_list {
00099       nodeid_t* cameras ;
00100       int       num_cameras ;
00101    public :
00102       dc_node_list(const raw1394_handle&) ;
00103       ~dc_node_list() ;
00104       void release() {dc1394_free_camera_nodes(cameras) ; cameras = 0 ;}
00105 
00106       int size() const {return num_cameras ;}
00107       const nodeid_t& operator[](int i) const ;
00108    } ;
00109 
00110    // Bus handles, camera nodes, etc.
00111    raw1394_handle m_handle ;
00112    dc_node_list   m_cameras ;
00113 
00114    // Initialization
00115    FireWireBus() ; // private because this is a singleton
00116    friend class singleton<FireWireBus> ;
00117 
00118 public:
00119    /// Return the raw 1394 bus handle
00120    const raw1394handle_t& handle() const {return m_handle ;}
00121 
00122    /// Return the number of cameras currently connected to the 1394 bus
00123    int num_cameras() const {return m_cameras.size() ;}
00124 
00125    /// Return the camera node corresponding the the i-th camera on the bus
00126    const nodeid_t& get_camera_node(int i) const {return m_cameras[i] ;}
00127 
00128    /// Return the i-th camera node using the subscript operator rather
00129    /// than an explicit function call.
00130    const nodeid_t& operator[](int i) const {return get_camera_node(i) ;}
00131 
00132    /// Camera nodes can be released after the camera devices have been
00133    /// initialized. This allows clients to free up memory associated with
00134    /// these nodes if they feel they won't set camera parameters (or call
00135    /// other functions that require the camera nodes) during the
00136    /// remainder of their lives.
00137    ///
00138    /// NOTE: This method should not be called without due consideration
00139    /// has been given to the matter. That is: call it only if you're
00140    /// really sure you know what you're doing.
00141    void release_camera_nodes() {m_cameras.release() ;}
00142 
00143    /// Destroy 1394 bus handle, camera nodes, etc.
00144    ~FireWireBus() ;
00145 } ;
00146 
00147 //-----------------------------------------------------------------------
00148 
00149 } // end of namespace encapsulating this file's definitions
00150 
00151 #endif // #ifndef LOBOT_FIREWIRE_BUS_DOT_H
00152 
00153 /* So things look consistent in everyone's emacs... */
00154 /* Local Variables: */
00155 /* indent-tabs-mode: nil */
00156 /* End: */
Generated on Sun May 8 08:41:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3