Debugger: Implement host interface roster listener.
TargetHostInterfaceRoster: - Add Listener interface. For now, this simply notifies the listener of changes to the active debugger count. - Adjust show new team window command to automatically fall back to the local interface window if one isn't specified. Fixes the Start New Team menu item in the TeamWindow. The latter will later be expanded to show the available interfaces to start a new team on in a submenu. Debugger: - Implement roster listener interface in order to know when to attempt application quit. With this commit, all necessary work to isolate the application from the target host is complete, and work on the actual remote interface and protocol can begin.
This commit is contained in:
@@ -208,7 +208,7 @@ parse_arguments(int argc, const char* const* argv, bool noOutput,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
global_init()
|
global_init(TargetHostInterfaceRoster::Listener* listener)
|
||||||
{
|
{
|
||||||
status_t error = TypeHandlerRoster::CreateDefault();
|
status_t error = TypeHandlerRoster::CreateDefault();
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
@@ -222,7 +222,7 @@ global_init()
|
|||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
error = TargetHostInterfaceRoster::CreateDefault();
|
error = TargetHostInterfaceRoster::CreateDefault(listener);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -242,7 +242,8 @@ global_init()
|
|||||||
// #pragma mark - Debugger application class
|
// #pragma mark - Debugger application class
|
||||||
|
|
||||||
|
|
||||||
class Debugger : public BApplication {
|
class Debugger : public BApplication,
|
||||||
|
private TargetHostInterfaceRoster::Listener {
|
||||||
public:
|
public:
|
||||||
Debugger();
|
Debugger();
|
||||||
~Debugger();
|
~Debugger();
|
||||||
@@ -256,6 +257,9 @@ private:
|
|||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
|
|
||||||
|
// TargetHostInterfaceRoster::Listener
|
||||||
|
virtual void TeamDebuggerCountChanged(int32 count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _StartNewTeam(TargetHostInterface* interface,
|
status_t _StartNewTeam(TargetHostInterface* interface,
|
||||||
const char* teamPath, const char* args);
|
const char* teamPath, const char* args);
|
||||||
@@ -270,7 +274,7 @@ private:
|
|||||||
// #pragma mark - CliDebugger
|
// #pragma mark - CliDebugger
|
||||||
|
|
||||||
|
|
||||||
class CliDebugger {
|
class CliDebugger : private TargetHostInterfaceRoster::Listener {
|
||||||
public:
|
public:
|
||||||
CliDebugger();
|
CliDebugger();
|
||||||
~CliDebugger();
|
~CliDebugger();
|
||||||
@@ -279,7 +283,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ReportDebugger {
|
class ReportDebugger : private TargetHostInterfaceRoster::Listener {
|
||||||
public:
|
public:
|
||||||
ReportDebugger();
|
ReportDebugger();
|
||||||
~ReportDebugger();
|
~ReportDebugger();
|
||||||
@@ -293,6 +297,7 @@ public:
|
|||||||
Debugger::Debugger()
|
Debugger::Debugger()
|
||||||
:
|
:
|
||||||
BApplication(kDebuggerSignature),
|
BApplication(kDebuggerSignature),
|
||||||
|
TargetHostInterfaceRoster::Listener(),
|
||||||
fTeamsWindow(NULL),
|
fTeamsWindow(NULL),
|
||||||
fStartTeamWindow(NULL)
|
fStartTeamWindow(NULL)
|
||||||
{
|
{
|
||||||
@@ -311,7 +316,7 @@ Debugger::~Debugger()
|
|||||||
status_t
|
status_t
|
||||||
Debugger::Init()
|
Debugger::Init()
|
||||||
{
|
{
|
||||||
status_t error = global_init();
|
status_t error = global_init(this);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -351,8 +356,12 @@ Debugger::MessageReceived(BMessage* message)
|
|||||||
TargetHostInterface* hostInterface;
|
TargetHostInterface* hostInterface;
|
||||||
if (message->FindPointer("interface",
|
if (message->FindPointer("interface",
|
||||||
reinterpret_cast<void**>(&hostInterface)) != B_OK) {
|
reinterpret_cast<void**>(&hostInterface)) != B_OK) {
|
||||||
break;
|
// if an interface isn't explicitly supplied, fall back to
|
||||||
|
// the default local interface.
|
||||||
|
hostInterface = TargetHostInterfaceRoster::Default()
|
||||||
|
->ActiveInterfaceAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessenger messenger(fStartTeamWindow);
|
BMessenger messenger(fStartTeamWindow);
|
||||||
if (!messenger.IsValid()) {
|
if (!messenger.IsValid()) {
|
||||||
fStartTeamWindow = StartTeamWindow::Create(hostInterface);
|
fStartTeamWindow = StartTeamWindow::Create(hostInterface);
|
||||||
@@ -473,6 +482,16 @@ Debugger::Quit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Debugger::TeamDebuggerCountChanged(int32 count)
|
||||||
|
{
|
||||||
|
if (count == 0) {
|
||||||
|
AutoLocker<Debugger> lock(this);
|
||||||
|
Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Debugger::_StartNewTeam(TargetHostInterface* interface, const char* path,
|
Debugger::_StartNewTeam(TargetHostInterface* interface, const char* path,
|
||||||
const char* args)
|
const char* args)
|
||||||
@@ -529,7 +548,7 @@ CliDebugger::Run(const Options& options)
|
|||||||
SignalSet(SIGINT).BlockInCurrentThread();
|
SignalSet(SIGINT).BlockInCurrentThread();
|
||||||
|
|
||||||
// initialize global objects and settings manager
|
// initialize global objects and settings manager
|
||||||
status_t error = global_init();
|
status_t error = global_init(this);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
fprintf(stderr, "Error: Global initialization failed: %s\n",
|
fprintf(stderr, "Error: Global initialization failed: %s\n",
|
||||||
strerror(error));
|
strerror(error));
|
||||||
@@ -596,7 +615,7 @@ bool
|
|||||||
ReportDebugger::Run(const Options& options)
|
ReportDebugger::Run(const Options& options)
|
||||||
{
|
{
|
||||||
// initialize global objects and settings manager
|
// initialize global objects and settings manager
|
||||||
status_t error = global_init();
|
status_t error = global_init(this);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
fprintf(stderr, "Error: Global initialization failed: %s\n",
|
fprintf(stderr, "Error: Global initialization failed: %s\n",
|
||||||
strerror(error));
|
strerror(error));
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ TargetHostInterfaceRoster::TargetHostInterfaceRoster()
|
|||||||
fLock(),
|
fLock(),
|
||||||
fRunningTeamDebuggers(0),
|
fRunningTeamDebuggers(0),
|
||||||
fInterfaceInfos(20, false),
|
fInterfaceInfos(20, false),
|
||||||
fActiveInterfaces(20, false)
|
fActiveInterfaces(20, false),
|
||||||
|
fListener(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ TargetHostInterfaceRoster::Default()
|
|||||||
|
|
||||||
|
|
||||||
/*static*/ status_t
|
/*static*/ status_t
|
||||||
TargetHostInterfaceRoster::CreateDefault()
|
TargetHostInterfaceRoster::CreateDefault(Listener* listener)
|
||||||
{
|
{
|
||||||
if (sDefaultInstance != NULL)
|
if (sDefaultInstance != NULL)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -52,7 +53,7 @@ TargetHostInterfaceRoster::CreateDefault()
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
ObjectDeleter<TargetHostInterfaceRoster> rosterDeleter(roster);
|
ObjectDeleter<TargetHostInterfaceRoster> rosterDeleter(roster);
|
||||||
|
|
||||||
status_t error = roster->Init();
|
status_t error = roster->Init(listener);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -75,8 +76,9 @@ TargetHostInterfaceRoster::DeleteDefault()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TargetHostInterfaceRoster::Init()
|
TargetHostInterfaceRoster::Init(Listener* listener)
|
||||||
{
|
{
|
||||||
|
fListener = listener;
|
||||||
return fLock.InitCheck();
|
return fLock.InitCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +163,7 @@ void
|
|||||||
TargetHostInterfaceRoster::TeamDebuggerStarted(TeamDebugger* debugger)
|
TargetHostInterfaceRoster::TeamDebuggerStarted(TeamDebugger* debugger)
|
||||||
{
|
{
|
||||||
fRunningTeamDebuggers++;
|
fRunningTeamDebuggers++;
|
||||||
|
fListener->TeamDebuggerCountChanged(fRunningTeamDebuggers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,6 +171,7 @@ void
|
|||||||
TargetHostInterfaceRoster::TeamDebuggerQuit(TeamDebugger* debugger)
|
TargetHostInterfaceRoster::TeamDebuggerQuit(TeamDebugger* debugger)
|
||||||
{
|
{
|
||||||
fRunningTeamDebuggers--;
|
fRunningTeamDebuggers--;
|
||||||
|
fListener->TeamDebuggerCountChanged(fRunningTeamDebuggers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,3 +182,17 @@ TargetHostInterfaceRoster::TargetHostInterfaceQuit(
|
|||||||
AutoLocker<TargetHostInterfaceRoster> locker(this);
|
AutoLocker<TargetHostInterfaceRoster> locker(this);
|
||||||
fActiveInterfaces.RemoveItem(interface);
|
fActiveInterfaces.RemoveItem(interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - TargetHostInterfaceRoster::Listener
|
||||||
|
|
||||||
|
|
||||||
|
TargetHostInterfaceRoster::Listener::~Listener()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TargetHostInterfaceRoster::Listener::TeamDebuggerCountChanged(int32 count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,17 +19,18 @@ class TargetHostInterfaceInfo;
|
|||||||
|
|
||||||
class TargetHostInterfaceRoster : private TargetHostInterface::Listener {
|
class TargetHostInterfaceRoster : private TargetHostInterface::Listener {
|
||||||
public:
|
public:
|
||||||
|
class Listener;
|
||||||
TargetHostInterfaceRoster();
|
TargetHostInterfaceRoster();
|
||||||
virtual ~TargetHostInterfaceRoster();
|
virtual ~TargetHostInterfaceRoster();
|
||||||
|
|
||||||
static TargetHostInterfaceRoster* Default();
|
static TargetHostInterfaceRoster* Default();
|
||||||
static status_t CreateDefault();
|
static status_t CreateDefault(Listener* listener);
|
||||||
static void DeleteDefault();
|
static void DeleteDefault();
|
||||||
|
|
||||||
bool Lock() { return fLock.Lock(); }
|
bool Lock() { return fLock.Lock(); }
|
||||||
void Unlock() { fLock.Unlock(); }
|
void Unlock() { fLock.Unlock(); }
|
||||||
|
|
||||||
status_t Init();
|
status_t Init(Listener* listener);
|
||||||
status_t RegisterInterfaceInfos();
|
status_t RegisterInterfaceInfos();
|
||||||
|
|
||||||
int32 CountInterfaceInfos() const;
|
int32 CountInterfaceInfos() const;
|
||||||
@@ -63,6 +64,15 @@ private:
|
|||||||
int32 fRunningTeamDebuggers;
|
int32 fRunningTeamDebuggers;
|
||||||
InfoList fInterfaceInfos;
|
InfoList fInterfaceInfos;
|
||||||
InterfaceList fActiveInterfaces;
|
InterfaceList fActiveInterfaces;
|
||||||
|
Listener* fListener;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TargetHostInterfaceRoster::Listener {
|
||||||
|
public:
|
||||||
|
virtual ~Listener();
|
||||||
|
|
||||||
|
virtual void TeamDebuggerCountChanged(int32 newCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user