00001 #ifndef BUFFER_MANAGER_CLASS
00002 #define BUFFER_MANAGER_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "buffer_base.h"
00019
00020
00021 class internal_buffer_list;
00022 class memory_limiter;
00023
00025
00031 class BUFFERS_CLASS_STYLE buffer_manager
00032 {
00033 public:
00034 buffer_manager(int total_memory, int connection_memory);
00036
00041 virtual ~buffer_manager();
00042
00043 IMPLEMENT_CLASS_NAME("buffer_manager");
00044
00045 int buffers() const;
00047
00048 int total_memory_allowed() const;
00050 int total_allocated() const;
00052 inline int space_left() const
00053 { return total_memory_allowed() - total_allocated(); }
00055
00056 outcome add_buffer(buffer_base *to_add);
00058
00068 outcome extract(buffer_key &key, byte_array &to_fill,
00069 byte_array &attachment, int offset = 0, bool remove_buffer = true);
00071
00077 buffer_base *disengage(buffer_key &key);
00079
00082 void show_buffers(istring &dump, int indentation = 0);
00084
00086 buffer_base *lock_buffer(int &start, const buffer_key &key);
00088
00095 void unlock_buffer(buffer_base *to_unlock);
00097
00098 bool zap(buffer_id to_whack);
00100
00101 bool zap_match(int &start, const buffer_key &key);
00103
00106 bool zap_all_matches(const buffer_key &key);
00108
00109 void zap_all();
00111
00112 enum kind_to_find { EITHER, WHOLE, NON_WHOLE };
00113 bool zap_expired(istring &text_form, buffer_key &dead_key, int &start,
00114 int age, kind_to_find which);
00116
00122 private:
00123 mutex *_buffer_lock;
00124 internal_buffer_list *_buffer_list;
00125 memory_limiter *_space_minder;
00126
00127 buffer_base *locked_locate(int &start, const buffer_key &key);
00129
00135 int locked_find(int &start, const buffer_key &key);
00137
00140 bool okay_addition(buffer_base &to_check);
00142 void record_subtraction(buffer_base &check_out);
00144 void find_space();
00146 };
00147
00148 #endif
00149