00001 /** 00002 \file Robots/LoBot/io/LoFireWireBus.C 00003 00004 \brief Quick wrapper around libdc1394's handles, camera nodes, etc. 00005 */ 00006 00007 // //////////////////////////////////////////////////////////////////// // 00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00009 // by the University of Southern California (USC) and the iLab at USC. // 00010 // See http://iLab.usc.edu for information about this project. // 00011 // //////////////////////////////////////////////////////////////////// // 00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00014 // in Visual Environments, and Applications'' by Christof Koch and // 00015 // Laurent Itti, California Institute of Technology, 2001 (patent // 00016 // pending; application number 09/912,225 filed July 23, 2001; see // 00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00018 // //////////////////////////////////////////////////////////////////// // 00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00022 // redistribute it and/or modify it under the terms of the GNU General // 00023 // Public License as published by the Free Software Foundation; either // 00024 // version 2 of the License, or (at your option) any later version. // 00025 // // 00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00029 // PURPOSE. See the GNU General Public License for more details. // 00030 // // 00031 // You should have received a copy of the GNU General Public License // 00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00034 // Boston, MA 02111-1307 USA. // 00035 // //////////////////////////////////////////////////////////////////// // 00036 // 00037 // Primary maintainer for this file: Manu Viswanathan <mviswana at usc dot edu> 00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoFireWireBus.C $ 00039 // $Id: LoFireWireBus.C 11256 2009-05-30 01:46:10Z mviswana $ 00040 // 00041 00042 //------------------------------ HEADERS -------------------------------- 00043 00044 // lobot headers 00045 #include "Robots/LoBot/io/LoFireWireBus.H" 00046 #include "Robots/LoBot/misc/LoExcept.H" 00047 00048 //---------------------- ALTERNATIVE DEFINITION ------------------------- 00049 00050 // In case libdc1394 and other IEEE-1394 libraries are missing 00051 #ifndef HAVE_IEEE1394 00052 00053 namespace lobot { 00054 00055 // Constructors 00056 FireWireBus::raw1394_handle::raw1394_handle(int) 00057 : handle(0) 00058 {} 00059 00060 FireWireBus::dc_node_list::dc_node_list(const FireWireBus::raw1394_handle&) 00061 : cameras(0), num_cameras(0) 00062 {} 00063 00064 FireWireBus::FireWireBus() 00065 : m_handle(0), m_cameras(m_handle) 00066 { 00067 throw missing_libs(MISSING_LIBDC1394) ; 00068 } 00069 00070 // Destructors 00071 FireWireBus::raw1394_handle::~raw1394_handle(){} 00072 FireWireBus::dc_node_list::~dc_node_list(){} 00073 FireWireBus::~FireWireBus(){} 00074 00075 } // end of namespace encapsulating above empty definition 00076 00077 #else 00078 00079 //----------------------------- NAMESPACE ------------------------------- 00080 00081 namespace lobot { 00082 00083 //-------------------------- INITIALIZATION ----------------------------- 00084 00085 // Initializing raw 1394 handles 00086 FireWireBus::raw1394_handle::raw1394_handle(int card_number) 00087 : handle(dc1394_create_handle(card_number)) 00088 { 00089 if (handle == NULL) 00090 throw bus_error(INIT_PROBLEM) ; 00091 } 00092 00093 // Retrieving the IDs of the cameras currently connected to the FireWire 00094 // bus. 00095 FireWireBus::dc_node_list::dc_node_list(const FireWireBus::raw1394_handle& H) 00096 : cameras(0), num_cameras(0) 00097 { 00098 cameras = dc1394_get_camera_nodes(H, & num_cameras, 0) ; 00099 if (num_cameras < 1) 00100 throw bus_error(NO_CAMERAS) ; 00101 00102 int highest_node_id = raw1394_get_nodecount(H) - 1 ; 00103 for (int i = 0; i < num_cameras; ++i) 00104 if (cameras[i] == highest_node_id) { // prevent ISO transfer bug 00105 release() ; 00106 throw bus_error(HIGHEST_NODE) ; 00107 } 00108 } 00109 00110 // Bus initialization simply involves obtaining a raw 1394 handle and 00111 // retrieving the camera IDs. 00112 FireWireBus::FireWireBus() 00113 : m_handle(0), m_cameras(m_handle) 00114 {} 00115 00116 //------------------------ CAMERA NODE ACCESS --------------------------- 00117 00118 const nodeid_t& FireWireBus::dc_node_list::operator[](int i) const 00119 { 00120 if (! cameras) 00121 throw bus_error(CAMERA_NODES_FREED) ; 00122 if (i < 0 || i >= num_cameras) 00123 throw bus_error(BAD_CAMERA_NODE_INDEX) ; 00124 return cameras[i] ; 00125 } 00126 00127 //----------------------------- CLEAN-UP -------------------------------- 00128 00129 FireWireBus::raw1394_handle::~raw1394_handle() 00130 { 00131 dc1394_destroy_handle(handle) ; 00132 } 00133 00134 FireWireBus::dc_node_list::~dc_node_list() 00135 { 00136 release() ; 00137 } 00138 00139 FireWireBus::~FireWireBus(){} 00140 00141 //----------------------------------------------------------------------- 00142 00143 } // end of namespace encapsulating this file's definitions 00144 00145 #endif // #ifndef HAVE_IEEE1394 00146 00147 /* So things look consistent in everyone's emacs... */ 00148 /* Local Variables: */ 00149 /* indent-tabs-mode: nil */ 00150 /* End: */