Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

LogState.h

Go to the documentation of this file.
00001 /*** 00002 * Copyright (C) 2004-2005 BoilerPlate.org 00003 * All rights reserved 00004 * 00005 * This file is part of BoilerPlate. 00006 * 00007 * BoilerPlate is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation version 2 00010 * 00011 * BoilerPlate is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with BoilerPlate; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 **/ 00020 00032 #ifndef LOGSTATE_H 00033 #define LOGSTATE_H 00034 00035 #include <string> 00036 #include <iostream> 00037 #include <fstream> 00038 #include <map> 00039 #include <pthread.h> 00040 #include <sys/time.h> 00041 00042 #include "BP_CosLw_Log.h" 00043 #include "CorbaServer.h" 00044 #include "IdxRecordId.h" 00045 #include "LevelMap.h" 00046 00060 class LogState 00061 { 00062 public: 00064 LogState(std::string log_name, unsigned long maxsize) 00065 throw(OrbInit::InitializationError); 00066 00068 LogState(std::string log_name, 00069 std::string log_dir, 00070 unsigned long maxsize 00071 ) 00072 throw(OrbInit::InitializationError); 00073 00074 ~LogState(); 00075 00077 CosLwLog::LogFullAction getFullAction() 00078 { return(_running_state.full_action); } 00079 00081 CosLwLog::AvailabilityStatus getAvailStatus() 00082 { return(_running_state.avail_status); } 00083 00085 CosLwLog::OperationalState getOpState() 00086 { return(_running_state.op_state); } 00087 00089 CosLwLog::AdministrativeState getAdminState() 00090 { return(_running_state.admin_state);} 00091 00096 void write_record(CosLwLog::LogRecord& recd); 00097 00099 unsigned long get_max_size() 00100 { return(_running_state.max_size); } 00101 00110 void set_max_size(const unsigned long& max_size); 00111 00119 void setLogFullAction(const CosLwLog::LogFullAction& new_full_action); 00120 00128 void setAdminState(const CosLwLog::AdministrativeState& new_state); 00129 00130 00141 void clearLog(); 00142 00150 void destroyLog(); 00151 00152 00154 unsigned long get_current_size(); 00156 unsigned long get_current_numb_records() 00157 { return(_current_record.stop_rcd_id); } 00158 00169 const IdxRecordId::IdxRecord find_log(const CosLwLog::LogTime& log_time); 00170 00181 const IdxRecordId::IdxRecord find_log(const CosLwLog::RecordId& recid); 00182 00193 const std::string get_log_file_name( 00194 const unsigned long& start_secs, 00195 const unsigned long& start_nanos 00196 ); 00197 00203 const bool future_id(const CosLwLog::RecordId& recid) const; 00204 00210 CosLwLog::RecordId future_id(); 00211 00212 CosLwLog::LogTime init_logtime(); 00213 00214 bool is_enabled() { return(_running_state.op_state == CosLwLog::enabled);} 00215 00216 00217 private: 00219 const std::string _log_file_name; 00220 00222 const std::string _log_dir; 00223 00225 std::fstream _log; 00226 00227 00235 struct LogRunningState 00236 { 00238 CosLwLog::LogFullAction full_action; 00240 CosLwLog::AvailabilityStatus avail_status; 00242 CosLwLog::OperationalState op_state; 00244 CosLwLog::AdministrativeState admin_state; 00246 unsigned long max_size; 00247 }; 00248 00250 LogRunningState _running_state; 00251 00254 void _open_running_state(const unsigned long& max_size); 00257 void _save_running_state(); 00258 00260 unsigned long _current_records; 00261 00263 IdxRecordId::IdxRecord _current_record; 00264 00266 IdxRecordId _recdid_idx; 00267 00268 00270 pthread_mutex_t _state_mutex; 00271 00273 pthread_cond_t _full_state; 00274 00280 bool _open_file(std::ios_base::openmode mode); 00281 00287 bool _init(const unsigned long& max_size); 00293 void _revise_state(); 00294 00302 bool _check_state_for_write(); 00303 00312 std::string _make_log_name(std::string& log_name, std::string& log_dir); 00313 00321 std::string _make_log_name(std::string& log_name); 00322 00323 void _log_msg( 00324 const std::string& producername, 00325 const std::string& msg, 00326 const CosLwLog::LogLevel& leve 00327 ); 00328 }; 00329 00330 #endif