xref: /haiku/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 /*
2  * Copyright 2011, Rene Gollent, rene@gollent.com.
3  * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef COMMAND_LINE_USER_INTERFACE_H
7 #define COMMAND_LINE_USER_INTERFACE_H
8 
9 
10 #include <ObjectList.h>
11 #include <String.h>
12 
13 #include "CliContext.h"
14 #include "UserInterface.h"
15 
16 
17 class CliCommand;
18 
19 
20 class CommandLineUserInterface : public UserInterface,
21 	public ::Team::Listener {
22 public:
23 								CommandLineUserInterface(bool saveReport,
24 									const char* reportPath);
25 	virtual						~CommandLineUserInterface();
26 
27 	virtual	const char*			ID() const;
28 
29 	virtual	status_t			Init(Team* team,
30 									UserInterfaceListener* listener);
31 	virtual	void				Show();
32 	virtual	void				Terminate();
33 									// shut down the UI *now* -- no more user
34 									// feedback
35 
36 	virtual status_t			LoadSettings(const TeamUiSettings* settings);
37 	virtual status_t			SaveSettings(TeamUiSettings*& settings)	const;
38 
39 	virtual	void				NotifyUser(const char* title,
40 									const char* message,
41 									user_notification_type type);
42 	virtual	int32				SynchronouslyAskUser(const char* title,
43 									const char* message, const char* choice1,
44 									const char* choice2, const char* choice3);
45 
46 			void				Run();
47 									// Called by the main thread, when
48 									// everything has been set up. Enters the
49 									// input loop.
50 
51 	// Team::Listener
52 	virtual	void				DebugReportChanged(
53 									const Team::DebugReportEvent& event);
54 
55 private:
56 			struct CommandEntry;
57 			typedef BObjectList<CommandEntry> CommandList;
58 
59 			struct HelpCommand;
60 
61 			// GCC 2 support
62 			friend struct HelpCommand;
63 
64 private:
65 	static	status_t			_InputLoopEntry(void* data);
66 			status_t			_InputLoop();
67 
68 			status_t			_RegisterCommands();
69 			bool				_RegisterCommand(const BString& name,
70 									CliCommand* command);
71 			void				_ExecuteCommand(int argc,
72 									const char* const* argv);
73 			CommandEntry*		_FindCommand(const char* commandName);
74 			void				_PrintHelp(const char* commandName);
75 	static	int					_CompareCommandEntries(
76 									const CommandEntry* command1,
77 									const CommandEntry* command2);
78 
79 private:
80 			CliContext			fContext;
81 			CommandList			fCommands;
82 			const char*			fReportPath;
83 			bool				fSaveReport;
84 			sem_id				fShowSemaphore;
85 			bool				fShown;
86 	volatile bool				fTerminating;
87 };
88 
89 
90 #endif	// COMMAND_LINE_USER_INTERFACE_H
91