00001 // -*- C++ -*- 00002 // 00003 00012 // ***** BEGIN LICENSE BLOCK ***** 00013 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00014 // 00015 // The contents of this file are subject to the Mozilla Public License 00016 // Version 1.1 (the "License"); you may not use this file except in 00017 // compliance with the License. You may obtain a copy of the License at 00018 // http://www.mozilla.org/MPL/ 00019 // 00020 // Software distributed under the License is distributed on an "AS IS" 00021 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00022 // the License for the specific language governing rights and limitations 00023 // under the License. 00024 // 00025 // The Original Code is the consmgr network/serial-line monitoring package. 00026 // 00027 // The Initial Developer of the Original Code is Chris P. Ross. 00028 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00029 // the Initial Developer. All Rights Reserved. 00030 // 00031 // Contributor(s): 00032 // 00033 // Alternatively, the contents of this file may be used under the terms of 00034 // either the GNU General Public License Version 2 or later (the "GPL"), or 00035 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00036 // in which case the provisions of the GPL or the LGPL are applicable instead 00037 // of those above. If you wish to allow use of your version of this file only 00038 // under the terms of either the GPL or the LGPL, and not to allow others to 00039 // use your version of this file under the terms of the MPL, indicate your 00040 // decision by deleting the provisions above and replace them with the notice 00041 // and other provisions required by the GPL or the LGPL. If you do not delete 00042 // the provisions above, a recipient may use your version of this file under 00043 // the terms of any one of the MPL, the GPL or the LGPL. 00044 // 00045 // ***** END LICENSE BLOCK ***** 00046 00047 #ifndef __HISTORY_H 00048 #define __HISTORY_H 00049 00050 extern "C" { 00051 #include <pthread.h> 00052 #include <sys/types.h> 00053 } 00054 00055 #include <string> 00056 #include <vector> 00057 00058 #include "connector.h" 00059 00066 template <class _Tp> 00067 class CircBuffer : public std::vector<_Tp> { 00068 public: 00071 CircBuffer(u_int16_t n) : circ_size(n) { } 00072 00075 void push_back(const _Tp &e) { 00076 std::vector<_Tp>::push_back(e); 00077 if (this->size() > circ_size) 00078 this->erase(this->begin()); 00079 } 00080 00083 typename std::vector<_Tp>::size_type max_size() const 00084 { return circ_size; } 00085 00086 private: 00087 u_int16_t circ_size; 00088 }; 00089 00097 class History : public Connector { 00098 public: 00099 History(const int size); 00100 virtual ~History(); 00101 00102 std::string get_id(void) const; 00103 00104 #if 0 00105 void notify_on_disconnect(const Messageable *owner); 00106 #endif 00107 00108 Data *read(); 00109 ssize_t write(const Data&); 00110 00113 virtual bool connected(void) const { return(true); } 00114 00115 // XXX - handle_message(Message&) 00116 private: 00119 void connect(void) { }; 00121 void disconnect(void); 00122 00125 CircBuffer<std::string> lines; 00126 pthread_mutex_t buf_mutex; 00127 00129 bool start_a_new_line; 00130 }; 00131 00132 #endif /* __HISTORY_H */