1 /* 2 * Copyright 2011-2013, 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 thread_id reportTargetThread); 26 virtual ~CommandLineUserInterface(); 27 28 virtual const char* ID() const; 29 30 virtual status_t Init(Team* team, 31 UserInterfaceListener* listener); 32 virtual void Show(); 33 virtual void Terminate(); 34 // shut down the UI *now* -- no more user 35 // feedback 36 37 virtual status_t LoadSettings(const TeamUiSettings* settings); 38 virtual status_t SaveSettings(TeamUiSettings*& settings) const; 39 40 virtual void NotifyUser(const char* title, 41 const char* message, 42 user_notification_type type); 43 virtual int32 SynchronouslyAskUser(const char* title, 44 const char* message, const char* choice1, 45 const char* choice2, const char* choice3); 46 47 void Run(); 48 // Called by the main thread, when 49 // everything has been set up. Enters the 50 // input loop. 51 52 // Team::Listener 53 virtual void ThreadStateChanged( 54 const Team::ThreadEvent& event); 55 virtual void DebugReportChanged( 56 const Team::DebugReportEvent& event); 57 58 private: 59 struct CommandEntry; 60 typedef BObjectList<CommandEntry> CommandList; 61 62 struct HelpCommand; 63 64 // GCC 2 support 65 friend struct HelpCommand; 66 67 private: 68 static status_t _InputLoopEntry(void* data); 69 status_t _InputLoop(); 70 71 status_t _RegisterCommands(); 72 bool _RegisterCommand(const BString& name, 73 CliCommand* command); 74 void _ExecuteCommand(int argc, 75 const char* const* argv); 76 CommandEntry* _FindCommand(const char* commandName); 77 void _PrintHelp(const char* commandName); 78 static int _CompareCommandEntries( 79 const CommandEntry* command1, 80 const CommandEntry* command2); 81 82 bool _ReportTargetThreadStopNeeded() const; 83 void _SubmitSaveReport(); 84 85 private: 86 CliContext fContext; 87 CommandList fCommands; 88 const char* fReportPath; 89 bool fSaveReport; 90 thread_id fReportTargetThread; 91 sem_id fShowSemaphore; 92 bool fShown; 93 volatile bool fTerminating; 94 }; 95 96 97 #endif // COMMAND_LINE_USER_INTERFACE_H 98