xref: /haiku/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h (revision 93e30a47bed879ad448b3e2d9e10333d3f2e60ae)
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:
22 								CommandLineUserInterface();
23 	virtual						~CommandLineUserInterface();
24 
25 	virtual	const char*			ID() const;
26 
27 	virtual	status_t			Init(Team* team,
28 									UserInterfaceListener* listener);
29 	virtual	void				Show();
30 	virtual	void				Terminate();
31 									// shut down the UI *now* -- no more user
32 									// feedback
33 
34 	virtual status_t			LoadSettings(const TeamUiSettings* settings);
35 	virtual status_t			SaveSettings(TeamUiSettings*& settings)	const;
36 
37 	virtual	void				NotifyUser(const char* title,
38 									const char* message,
39 									user_notification_type type);
40 	virtual	int32				SynchronouslyAskUser(const char* title,
41 									const char* message, const char* choice1,
42 									const char* choice2, const char* choice3);
43 
44 			void				Run();
45 									// Called by the main thread, when
46 									// everything has been set up. Enters the
47 									// input loop.
48 
49 private:
50 			struct CommandEntry;
51 			typedef BObjectList<CommandEntry> CommandList;
52 
53 			struct HelpCommand;
54 
55 			// GCC 2 support
56 			friend struct HelpCommand;
57 
58 private:
59 	static	status_t			_InputLoopEntry(void* data);
60 			status_t			_InputLoop();
61 
62 			status_t			_RegisterCommands();
63 			bool				_RegisterCommand(const BString& name,
64 									CliCommand* command);
65 			void				_ExecuteCommand(int argc,
66 									const char* const* argv);
67 			CommandEntry*		_FindCommand(const char* commandName);
68 			void				_PrintHelp(const char* commandName);
69 
70 private:
71 			CliContext			fContext;
72 			CommandList			fCommands;
73 			sem_id				fShowSemaphore;
74 			bool				fShown;
75 	volatile bool				fTerminating;
76 };
77 
78 
79 #endif	// COMMAND_LINE_USER_INTERFACE_H
80