00001 /* 00002 * LogSelector.h : part of the Mace toolkit for building distributed systems 00003 * 00004 * Copyright (c) 2007, Charles Killian, Dejan Kostic, Ryan Braud, James W. Anderson, John Fisher-Ogden, Calvin Hubble, Duy Nguyen, Justin Burke, David Oppenheimer, Amin Vahdat, Adolfo Rodriguez, Sooraj Bhat 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the names of Duke University nor The University of 00017 * California, San Diego, nor the names of the authors or contributors 00018 * may be used to endorse or promote products derived from 00019 * this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00030 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 * ----END-OF-LEGAL-STUFF---- */ 00033 // #include <stdio.h> 00034 #include <string> 00035 #include "mhash_map.h" 00036 00042 #ifndef LOG_SELECTOR_H 00043 #define LOG_SELECTOR_H 00044 00046 enum LogSelectorTimestamp { LOG_TIMESTAMP_DISABLED, 00047 LOG_TIMESTAMP_EPOCH, 00048 LOG_TIMESTAMP_HUMAN 00049 }; 00051 enum LogSelectorThreadId { LOG_THREADID_DISABLED, 00052 LOG_THREADID_ENABLED 00053 }; 00055 enum LogSelectorName { LOG_NAME_DISABLED, 00056 LOG_NAME_ENABLED 00057 }; 00059 enum LogSelectorOutput { LOG_FPRINTF, 00060 LOG_PIP, 00061 LOG_BINARY 00062 }; 00063 00064 class Sim; 00065 00089 class LogSelector { 00090 friend class Sim; 00091 00092 public: 00094 LogSelector(const std::string& name, 00095 FILE* fp, 00096 LogSelectorTimestamp logTimestamp, 00097 LogSelectorName logSelectorName, 00098 LogSelectorThreadId logSelectorThreadId, 00099 LogSelectorOutput logSelectorOutput); 00100 ~LogSelector(); 00101 00102 std::string getSelectorHeader() const; 00103 std::string getSerializedSelectorHeader() const; 00104 std::string getName() const; 00105 FILE* getFile() const; 00106 LogSelectorTimestamp getLogTimestamp() const; 00107 LogSelectorName getLogName() const; 00108 LogSelectorThreadId getLogThreadId() const; 00109 LogSelectorOutput getLogSelectorOutput() const; 00110 00111 private: 00112 const std::string name; 00113 FILE* fp; 00114 LogSelectorTimestamp logTimestamp; 00115 LogSelectorName logName; 00116 LogSelectorThreadId logThreadId; 00117 LogSelectorOutput logOutput; 00118 00119 typedef mace::hash_map<unsigned long, int, mace::SoftState> ThreadIdMap; 00120 static ThreadIdMap threadIds; 00121 static const std::string* prefix; 00122 }; 00123 00124 #endif // LOG_SELECTOR_H