blob: ca9f133e47c5b3844cf4bdf5fb55f2b3798d0268 [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001//
2// Copyright 2005 The Android Open Source Project
3//
4// Window with log output.
5//
6#ifndef _SIM_LOG_WINDOW_H
7#define _SIM_LOG_WINDOW_H
8
9#include "PhoneData.h"
10#include "UserEvent.h"
11#include "LogMessage.h"
12#include "LogPool.h"
13#include "LogPrefsDialog.h"
14
15
16/*
17 * Display log output from runtime process.
18 *
19 * We receive the messages broken into components (date, log level, tag,
20 * function name, etc.) and do the formatting ourselves. We receive all
21 * messages regardless of log level, and provide filter controls in the
22 * window.
23 *
24 * Messages are stored in a "log pool", which has a fixed memory footprint.
25 * The messages that are currently visible in the log output window are
26 * also pointed at from a fixed-size display array. Changes to output
27 * format cause us to clear the display and re-show everything in the
28 * display array, while changes to the output filter cause us to
29 * re-evaluate the contents of the display pool.
30 */
31class LogWindow : public wxDialog {
32public:
33 LogWindow(wxWindow* parent);
34 virtual ~LogWindow(void);
35
36 /* we override this, to cope with annoying GTK behavior */
37 virtual bool Show(bool show = true);
38
39 /* return preferred size and position */
40 static wxRect GetPrefWindowRect(void);
41
42 /* handle a log message "user event" */
43 void AddLogMessage(LogMessage* pLogMessage);
44
45 /* resize the display messages array */
46 void SetMaxDisplayMsgs(int max);
47
48 /* post a message to the log; may be called from non-main thread */
49 static void PostLogMsg(const android_LogBundle* pBundle);
50 static void PostLogMsg(const wxString& msg);
51 static void PostLogMsg(const char* msg);
52
53private:
54 void OnMove(wxMoveEvent& event);
55 void OnClose(wxCloseEvent& event);
56 void OnLogLevel(wxCommandEvent& event);
57 void OnLogClear(wxCommandEvent& event);
58 void OnLogPause(wxCommandEvent& event);
59 void OnLogPrefs(wxCommandEvent& event);
60
61 /* handle incoming log message */
62 void OnUserEvent(UserEvent& event);
63
64 void SaveWindowPrefs(void);
65 void ConstructControls(void);
66
67 void AddToDisplay(LogMessage* pLogMessage);
68 void ClearDisplay(void);
69 void Redisplay(void);
70 void SetTextStyle(void);
71
72 bool FilterMatches(const LogMessage* pLogMessage);
73
74 void FormatMessage(const LogMessage* pLogMessage,
75 wxTextCtrl* pTextCtrl);
76
77 void LogToFile(const LogMessage* pLogMessage);
78 void PrepareLogFile(void);
79 static void SendToWindow(LogMessage* pMessage);
80
81 /*
82 * Message pool.
83 */
84 LogPool mPool;
85
86 /*
87 * Display array. This is a fixed-size circular array that holds
88 * pointers to the log messages currently displayed on screen.
89 */
90 LogMessage** mDisplayArray; // ptrs to messages currently displayed
91 int mMaxDisplayMsgs; // max #of messages
92 int mTopPtr; // index of top message
93 int mNextPtr; // index of next empty slot
94
95 bool mPaused; // is output paused for review?
96
97 /*
98 * Current filter.
99 */
100 android_LogPriority mMinPriority; // messages at or above are shown
101
102 /* format options */
103 LogPrefsDialog::HeaderFormat mHeaderFormat;
104 bool mSingleLine; // put whole message on one line?
105 int mExtraSpacing; // double/triple-space messages?
106 int mPointSize; // text point size;
107 bool mUseColor; // colorful messages?
108 bool mFontMonospace; // use monospace font?
109
110 /* log file options */
111 bool mWriteFile;
112 wxString mFileName;
113 bool mTruncateOld;
114
115 FILE* mLogFp;
116
117 /*
118 * Window position stuff.
119 */
120 bool mNewlyShown;
121 wxPoint mLastPosition;
122 bool mVisible;
123
124 DECLARE_EVENT_TABLE()
125};
126
127#endif // _SIM_LOG_WINDOW_H