buffer_manager.h

Go to the documentation of this file.
00001 #ifndef BUFFER_MANAGER_CLASS
00002 #define BUFFER_MANAGER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : buffer_manager                                                    *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "buffer_base.h"
00019 
00020 // forward.
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 

Generated on Wed Nov 19 04:28:36 2008 for HOOPLE Libraries by  doxygen 1.5.1