Home | History | Annotate | Download | only in app
      1 //
      2 // Copyright 2005 The Android Open Source Project
      3 //
      4 // Pool of log messages.  Not thread safe -- operations on the log pool
      5 // should only happen in the main UI thread.
      6 //
      7 #ifndef _SIM_LOG_POOL_H
      8 #define _SIM_LOG_POOL_H
      9 
     10 #include "LogMessage.h"
     11 
     12 /*
     13  * This contains the pool of log messages.  The messages themselves are
     14  * allocated individually and reference counted.  We add new messages to
     15  * the head and, when the total "footprint" exceeds our stated max, we
     16  * delete one or more from the tail.
     17  *
     18  * To support pause/resume, we allow a "bookmark" to be set.  This is
     19  * just a pointer to a message in the pool.  If the bookmarked message
     20  * is deleted, we discard the bookmark.
     21  */
     22 class LogPool {
     23 public:
     24     LogPool(void)
     25         : mpHead(NULL), mpTail(NULL), mpBookmark(NULL),
     26           mCurrentSize(0), mMaxSize(10240)
     27         {}
     28     ~LogPool(void) { Clear(); }
     29 
     30     void Clear(void);
     31 
     32     /* add a new message to the pool */
     33     void Add(LogMessage* pLogMessage);
     34 
     35     /* resize the pool, removing excess messages */
     36     void Resize(long maxSize);
     37 
     38     /* return the current limit, in bytes */
     39     long GetMaxSize(void) const { return mMaxSize; }
     40 
     41     LogMessage* GetHead(void) const { return mpHead; }
     42 
     43     void SetBookmark(void) { mpBookmark = mpHead; }
     44     LogMessage* GetBookmark(void) const { return mpBookmark; }
     45 
     46 private:
     47     void RemoveOldest(void);
     48 
     49     LogMessage*     mpHead;
     50     LogMessage*     mpTail;
     51     LogMessage*     mpBookmark;
     52     long            mCurrentSize;       // current size, in bytes
     53     long            mMaxSize;           // maximum size, in bytes
     54 };
     55 
     56 #endif // _SIM_LOG_POOL_H
     57