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