1/* 2 * Copyright 2016, Rene Gollent, rene@gollent.com. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef TARGET_HOST_INTERFACE_H 6#define TARGET_HOST_INTERFACE_H 7 8#include <OS.h> 9#include <Looper.h> 10 11#include <ObjectList.h> 12 13#include <util/DoublyLinkedList.h> 14 15#include "controllers/TeamDebugger.h" 16 17 18class DebuggerInterface; 19class Settings; 20class SettingsManager; 21class TargetHost; 22struct TeamDebuggerOptions; 23class UserInterface; 24 25 26class TargetHostInterface : public BLooper, private TeamDebugger::Listener { 27public: 28 class Listener; 29 TargetHostInterface(); 30 virtual ~TargetHostInterface(); 31 32 status_t StartTeamDebugger(const TeamDebuggerOptions& options); 33 34 int32 CountTeamDebuggers() const; 35 TeamDebugger* TeamDebuggerAt(int32 index) const; 36 TeamDebugger* FindTeamDebugger(team_id team) const; 37 status_t AddTeamDebugger(TeamDebugger* debugger); 38 void RemoveTeamDebugger(TeamDebugger* debugger); 39 40 virtual status_t Init(Settings* settings) = 0; 41 virtual void Close() = 0; 42 43 virtual bool IsLocal() const = 0; 44 virtual bool Connected() const = 0; 45 46 virtual TargetHost* GetTargetHost() = 0; 47 48 virtual status_t Attach(team_id id, thread_id threadID, 49 DebuggerInterface*& _interface) const = 0; 50 virtual status_t CreateTeam(int commandLineArgc, 51 const char* const* arguments, 52 team_id& _teamID) const = 0; 53 virtual status_t LoadCore(const char* coreFilePath, 54 DebuggerInterface*& _interface, 55 thread_id& _thread) const = 0; 56 57 virtual status_t FindTeamByThread(thread_id thread, 58 team_id& _teamID) const = 0; 59 60 61 void AddListener(Listener* listener); 62 void RemoveListener(Listener* listener); 63 64 // BLooper 65 virtual void Quit(); 66 virtual void MessageReceived(BMessage* message); 67 68private: 69 // TeamDebugger::Listener 70 virtual void TeamDebuggerStarted(TeamDebugger* debugger); 71 virtual void TeamDebuggerRestartRequested( 72 TeamDebugger* debugger); 73 virtual void TeamDebuggerQuit(TeamDebugger* debugger); 74 75private: 76 status_t _StartTeamDebugger(team_id teamID, 77 const TeamDebuggerOptions& options, 78 bool stopInMain); 79 80 void _NotifyTeamDebuggerStarted( 81 TeamDebugger* debugger); 82 void _NotifyTeamDebuggerQuit( 83 TeamDebugger* debugger); 84 85 static int _CompareDebuggers(const TeamDebugger* a, 86 const TeamDebugger* b); 87private: 88 typedef DoublyLinkedList<Listener> ListenerList; 89 typedef BObjectList<TeamDebugger> TeamDebuggerList; 90 91private: 92 ListenerList fListeners; 93 TeamDebuggerList fTeamDebuggers; 94}; 95 96 97class TargetHostInterface::Listener 98 : public DoublyLinkedListLinkImpl<Listener> { 99public: 100 virtual ~Listener(); 101 virtual void TeamDebuggerStarted(TeamDebugger* debugger); 102 virtual void TeamDebuggerQuit(TeamDebugger* debugger); 103 virtual void TargetHostInterfaceQuit( 104 TargetHostInterface* interface); 105}; 106 107 108enum { 109 TEAM_DEBUGGER_REQUEST_UNKNOWN = 0, 110 TEAM_DEBUGGER_REQUEST_CREATE, 111 TEAM_DEBUGGER_REQUEST_ATTACH, 112 TEAM_DEBUGGER_REQUEST_LOAD_CORE 113}; 114 115 116struct TeamDebuggerOptions { 117 TeamDebuggerOptions(); 118 int requestType; 119 int commandLineArgc; 120 const char* const* commandLineArgv; 121 team_id team; 122 thread_id thread; 123 SettingsManager* settingsManager; 124 UserInterface* userInterface; 125 const char* coreFilePath; 126}; 127 128 129#endif // TARGET_HOST_INTERFACE_H 130