blob: fe77dc0aa61481c0710e491387408115034f7cb0 [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001//
2// Copyright 2005 The Android Open Source Project
3//
4// Class to hold a single log message. Not thread safe.
5//
6#ifndef _SIM_LOG_MESSAGE_H
7#define _SIM_LOG_MESSAGE_H
8
9#include "utils.h"
10#include "LogBundle.h"
11
12/*
13 * Hold a single log message.
14 *
15 * To reduce malloc strain we could over-allocate the object and tuck the
16 * message text into the object storage. On this off chance this becomes
17 * important, the implementation keeps its constructor private.
18 */
19class LogMessage {
20public:
21 ~LogMessage(void);
22
23 static LogMessage* Create(const android_LogBundle* pBundle);
24 static LogMessage* Create(const char* msg);
25
26 /* the total length of text added to the text ctrl */
27 int GetTextCtrlLen(void) const { return mTextCtrlLen; }
28 void SetTextCtrlLen(int len) { mTextCtrlLen = len; }
29
30 /* log pool */
31 LogMessage* GetPrev(void) const { return mpPrev; }
32 void SetPrev(LogMessage* pPrev) { mpPrev = pPrev; }
33 LogMessage* GetNext(void) const { return mpNext; }
34 void SetNext(LogMessage* pNext) { mpNext = pNext; }
35 int GetFootprint(void) const { return mFootprint; }
36
37 /* message contents */
38 time_t GetWhen(void) const { return mWhen; }
39 android_LogPriority GetPriority(void) const { return mPriority; }
40 pid_t GetPid(void) const { return mPid; }
41 const char* GetTag(void) const { return mTag; }
42 const char* GetMsg(void) const { return mMsg; }
43
44 bool GetInternal(void) const { return mInternal; }
45
46 void Acquire(void) { mRefCnt++; }
47 void Release(void) {
48 if (!--mRefCnt)
49 delete this;
50 }
51
52private:
53 LogMessage(void);
54 LogMessage(const LogMessage& src); // not implemented
55 LogMessage& operator=(const LogMessage& src); // not implemented
56
57 /* log message contents */
58 time_t mWhen;
59 android_LogPriority mPriority;
60 pid_t mPid;
61 char* mTag;
62 char* mMsg;
63
64 /* additional goodies */
65 int mRefCnt; // reference count
66 bool mInternal; // message generated internally by us?
67 int mFootprint; // approx. size of this object in memory
68 int mTextCtrlLen; // #of characters req'd in text ctrl
69 LogMessage* mpPrev; // link to previous item in log pool
70 LogMessage* mpNext; // link to next item in log pool
71};
72
73#endif // _SIM_LOG_MESSAGE_H