00001 /** 00002 \file Robots/LoBot/misc/LoMetlogList.H 00003 \brief An object to store the list of metrics logs to be analyzed and 00004 provide thread-safe access to this list. 00005 00006 This file defines a class that implements a simple object for storing 00007 the list of metrics logs to be analyzed and providing thread-safe 00008 access to this list. 00009 00010 The Robolocust metrics log analyzer program enumerates the list of log 00011 files in the individual directories specified as command line 00012 arguments to it. Then, it creates multiple threads to load and parse 00013 all these log files in parallel. These loader threads need to know the 00014 next log file to load. To ensure that different threads pick different 00015 log files, we use the lobot::MetlogList object to keep track of the 00016 next one in the list that should be loaded. 00017 00018 Obviously, since multiple threads can access this list and update the 00019 next field, we need to protect simultaneous accesses. The 00020 lobot::MetlogList object encapsulates all of that functionality, 00021 providing a straightforward interface to the loader threads. 00022 */ 00023 00024 // //////////////////////////////////////////////////////////////////// // 00025 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00026 // by the University of Southern California (USC) and the iLab at USC. // 00027 // See http://iLab.usc.edu for information about this project. // 00028 // //////////////////////////////////////////////////////////////////// // 00029 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00030 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00031 // in Visual Environments, and Applications'' by Christof Koch and // 00032 // Laurent Itti, California Institute of Technology, 2001 (patent // 00033 // pending; application number 09/912,225 filed July 23, 2001; see // 00034 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00035 // //////////////////////////////////////////////////////////////////// // 00036 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00037 // // 00038 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00039 // redistribute it and/or modify it under the terms of the GNU General // 00040 // Public License as published by the Free Software Foundation; either // 00041 // version 2 of the License, or (at your option) any later version. // 00042 // // 00043 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00044 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00045 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00046 // PURPOSE. See the GNU General Public License for more details. // 00047 // // 00048 // You should have received a copy of the GNU General Public License // 00049 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00050 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00051 // Boston, MA 02111-1307 USA. // 00052 // //////////////////////////////////////////////////////////////////// // 00053 // 00054 // Primary maintainer for this file: mviswana usc edu 00055 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/metlog/LoMetlogList.H $ 00056 // $Id: LoMetlogList.H 13923 2010-09-11 09:27:03Z mviswana $ 00057 // 00058 00059 #ifndef LOBOT_METLOG_LIST_DOT_H 00060 #define LOBOT_METLOG_LIST_DOT_H 00061 00062 //------------------------------ HEADERS -------------------------------- 00063 00064 // lobot headers 00065 #include "Robots/LoBot/thread/LoMutex.H" 00066 00067 // Standard C++ headers 00068 #include <string> 00069 #include <vector> 00070 00071 //----------------------------- NAMESPACE ------------------------------- 00072 00073 namespace lobot { 00074 00075 //------------------------- CLASS DEFINITION ---------------------------- 00076 00077 /** 00078 \class lobot::MetlogList 00079 \brief An object to help keep track of which metrics log should be 00080 loaded next. 00081 00082 This class implements a thread-safe interface for lobot::LoaderThread 00083 objects so they can figure out which metrics log should be loaded and 00084 parsed next. When all the metlogs have been processed, further 00085 attempts at retrieving the name of the next one for loading will 00086 result in an exception. The loader threads can use the exception as a 00087 signal to wind up their work. 00088 */ 00089 class MetlogList { 00090 // Prevent copy and assignment 00091 MetlogList(const MetlogList&) ; 00092 MetlogList& operator=(const MetlogList&) ; 00093 00094 /// The whole idea behind this class is to keep track of a list of 00095 /// metrics log file names that need to be loaded and parsed. These 00096 /// data members take care of the details. 00097 //@{ 00098 typedef std::vector<std::string> List ; 00099 typedef List::iterator Iter ; 00100 List m_list ; 00101 mutable Iter m_next ; 00102 //@} 00103 00104 /// When a loader thread is done processing one metlog, it will 00105 /// request the next one in the queue from this object. Since multiple 00106 /// loader threads can use this object, we need a mutex to ensure that 00107 /// they don't step on each others' toes. 00108 Mutex m_mutex ; 00109 00110 public: 00111 /// When this object is created, it should be passed the list of names 00112 /// of metrics logs that have to be loaded. 00113 /// 00114 /// NOTE: It is important that the loader threads not yet be active 00115 /// when this class is instantiated. 00116 MetlogList(const std::vector<std::string>& metlog_list) ; 00117 00118 /// This method retrieves the next name on the list. When all the 00119 /// names have been retrieved, it will throw an end-of-line exception 00120 /// to indicate to the loader threads that it's time for them to wind 00121 /// up their business. 00122 std::string next() const ; 00123 00124 /// This is the exception object thrown when we reach the end of the 00125 /// list. 00126 struct eol {} ; 00127 } ; 00128 00129 //----------------------------------------------------------------------- 00130 00131 } // end of namespace encapsulating this file's definitions 00132 00133 #endif 00134 00135 /* So things look consistent in everyone's emacs... */ 00136 /* Local Variables: */ 00137 /* indent-tabs-mode: nil */ 00138 /* End: */