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 59 private: 60 struct CommandEntry; 61 typedef BObjectList<CommandEntry> CommandList; 62 63 struct HelpCommand; 64 65 // GCC 2 support 66 friend struct HelpCommand; 67 68 private: 69 static status_t _InputLoopEntry(void* data); 70 status_t _InputLoop(); 71 72 status_t _RegisterCommands(); 73 bool _RegisterCommand(const BString& name, 74 CliCommand* command); 75 void _ExecuteCommand(int argc, 76 const char* const* argv); 77 CommandEntry* _FindCommand(const char* commandName); 78 void _PrintHelp(const char* commandName); 79 static int _CompareCommandEntries( 80 const CommandEntry* command1, 81 const CommandEntry* command2); 82 83 bool _ReportTargetThreadStopNeeded() const; 84 void _SubmitSaveReport(); 85 86 private: 87 CliContext fContext; 88 CommandList fCommands; 89 const char* fReportPath; 90 bool fSaveReport; 91 thread_id fReportTargetThread; 92 sem_id fShowSemaphore; 93 bool fShown; 94 volatile bool fTerminating; 95 }; 96 97 98 #endif // COMMAND_LINE_USER_INTERFACE_H 99